#include <bits/stdc++.h> n using namespace std; n char bb[111][111]; n int in[111][111]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) scanf( %s , bb[i]); n   vector<pair<pair<int, int>, int>> stars; n   for (int i = 1; i < n - 1; i++) { n     for (int j = 1; j < m - 1; j++) { n       if (bb[i][j] !=  * ) continue; n       int l, r, u, d; n       l = r = i; n       u = d = j; n       for (int k = i; k < n; k++) n         if (bb[k][j] ==  * ) n           r = k; n         else n           break; n       for (int k = i; k >= 0; k--) n         if (bb[k][j] ==  * ) n           l = k; n         else n           break; n       for (int k = j; k < m; k++) n         if (bb[i][k] ==  * ) n           d = k; n         else n           break; n       for (int k = j; k >= 0; k--) n         if (bb[i][k] ==  * ) n           u = k; n         else n           break; n       int starLevel = min(min(r - i, i - l), min(d - j, j - u)); n       if (starLevel) { n         for (int k = i - starLevel; k <= i + starLevel; k++) in[k][j] = 1; n         for (int k = j - starLevel; k <= j + starLevel; k++) in[i][k] = 1; n         stars.push_back({{i + 1, j + 1}, starLevel}); n       } n     } n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if ((bb[i][j] ==  *  && in[i][j] == 0) || n           (in[i][j] == 1 && bb[i][j] ==  . )) n         return puts( -1 ); n   cout << stars.size() << endl; n   for (auto u : stars) { n     printf( %d %d %d n , u.first.first, u.first.second, u.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 500; n const int LN = 21; n const long long mod = 1e9 + 7; n const long long INF = 1LL << 57; n long long n, m, u, v, k, t, q, a, x, d; n int tree[4 * N]; n int sum[4 * N]; n int lim = 1e6 + 2; n int arr[N], brr[N]; n bool print = false; n void modify(int i, int l, int r, int index, int val) { n   if (l == r) { n     tree[i] += val; n     sum[i] = tree[i]; n     return; n   } n   int mid = (l + r) / 2; n   if (index <= mid) n     modify(i + 1 + i, l, mid, index, val); n   else n     modify(i + 2 + i, mid + 1, r, index, val); n   tree[i] = max(tree[i + 2 + i], tree[i + 1 + i] + sum[i + 2 + i]); n   sum[i] = sum[i + 1 + i] + sum[i + 2 + i]; n } n int find(int i, int l, int r, int sumx) { n   if (l == r) return l; n   int mid = (l + r) / 2; n   if (tree[i + 2 + i] + sumx > 0) { n     return find(i + 2 + i, mid + 1, r, sumx); n   } else n     return find(i + 1 + i, l, mid, sumx + sum[i + 2 + i]); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) { n     cin >> arr[i]; n   } n   for (int i = 1; i <= m; ++i) cin >> brr[i]; n   for (int i = 1; i <= n; ++i) { n     modify(0, 0, lim, arr[i], 1); n   } n   for (int i = 1; i <= m; ++i) { n     modify(0, 0, lim, brr[i], -1); n   } n   cin >> q; n   while (q--) { n     int type; n     cin >> type; n     if (type == 1) { n       int i, x; n       cin >> i >> x; n       modify(0, 0, lim, arr[i], -1); n       modify(0, 0, lim, x, 1); n       arr[i] = x; n       int price = find(0, 0, lim, 0); n       if (price == 0) n         cout << -1 <<   n ; n       else n         cout << price <<   n ; n     } else { n       int i, x; n       cin >> i >> x; n       modify(0, 0, lim, brr[i], 1); n       modify(0, 0, lim, x, -1); n       brr[i] = x; n       int price = find(0, 0, lim, 0); n       if (price == 0) n         cout << -1 <<   n ; n       else n         cout << price <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void read(T &a) { n   T 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 << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   a = x * f; n } n template <typename T, typename... Args> n void read(T &t, Args &...args) { n   read(t); n   read(args...); n } n long long n, k, a[100005]; n struct node { n   long long len, k; n   bool operator<(const node &x) const { n     long long tmp1 = (len / k) * (len / k) * (k - len % k) + n                      (len / k + 1) * (len / k + 1) * (len % k); n     long long tmp2 = (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) + n                      (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k); n     long long kk = k + 1; n     long long tmpp1 = (len / kk) * (len / kk) * (kk - len % kk) + n                       (len / kk + 1) * (len / kk + 1) * (len % kk); n     kk = x.k + 1; n     long long tmpp2 = (x.len / kk) * (x.len / kk) * (kk - x.len % kk) + n                       (x.len / kk + 1) * (x.len / kk + 1) * (x.len % kk); n     tmp1 -= tmpp1; n     tmp2 -= tmpp2; n     if (k == len) tmp1 = 0; n     if (x.k == x.len) tmp2 = 0; n     return tmp1 < tmp2; n   } n }; n priority_queue<node> q; n void update(long long &ans, node &x) { n   ans -= (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) + n          (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k); n   x.k++; n   ans += (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) + n          (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k); n } n signed main() { n   read(n, k); n   long long ans = 0; n   for (long long i = 1; i <= n; i++) { n     read(a[i]); n     node tmp; n     tmp.len = a[i]; n     tmp.k = 1; n     q.push(tmp); n   } n   for (long long i = 1; i <= n; i++) ans += a[i] * a[i]; n   k -= n; n   while (k) { n     k += 19260817; n     node x = q.top(); n     q.pop(); n     update(ans, x); n     q.push(x); n     k -= 19260818; n   } n   printf( %lld n , ans +  O  -  O ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, l, v1, v2, k; n long double dn, dl, dv1, dv2, dk; n long long times; n long double x; n double T; n int main() { n   scanf( %lld%lld%lld%lld%lld , &n, &l, &v1, &v2, &k); n   dn = n; n   dl = l; n   dv1 = v1; n   dv2 = v2; n   dk = k; n   times = (n - 1) / k + 1; n   x = l / (v2 * times - (dv2 - dv1) / (dv2 + dv1) * dv2 * (times - 1)); n   T = x * (times + (dv2 - dv1) / (dv2 + dv1) * (times - 1)); n   printf( %lf n , T); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 3e5; n int n, p1[N], p2[N], p3[N], num1[N], num2[N], F[N][2], T[N * 4]; n void buildT(int v, int tl, int tr) { n   if (tl == tr) { n     T[v] = 1; n   } else { n     int tm = (tl + tr) / 2; n     buildT(v * 2, tl, tm); n     buildT(v * 2 + 1, tm + 1, tr); n     T[v] = T[v * 2] + T[v * 2 + 1]; n   } n } n void updT(int v, int tl, int tr, int p) { n   if (tl == tr) { n     T[v] = 0; n   } else { n     int tm = (tl + tr) / 2; n     if (tm >= p) n       updT(v * 2, tl, tm, p); n     else n       updT(v * 2 + 1, tm + 1, tr, p); n     T[v] = T[v * 2] + T[v * 2 + 1]; n   } n } n int getT(int v, int tl, int tr, int k) { n   if (tl == tr) { n     return tl; n   } else { n     int tm = (tl + tr) / 2; n     if (T[v * 2] >= k) n       return getT(v * 2, tl, tm, k); n     else n       return getT(v * 2 + 1, tm + 1, tr, k - T[v * 2]); n   } n } n void upd(int x, int t) { n   while (x < n) { n     ++F[x][t]; n     x |= (x + 1); n   } n } n int get(int x, int t) { n   int r = 0; n   while (x >= 0) { n     r += F[x][t]; n     x = (x & (x + 1)) - 1; n   } n   return r; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d , &p1[i]); n   for (int i = 0; i < n; ++i) scanf( %d , &p2[i]); n   for (int i = 0; i < n; ++i) { n     num1[i] = p1[i] - get(p1[i], 0); n     upd(p1[i] + 1, 0); n     num2[i] = p2[i] - get(p2[i], 1); n     upd(p2[i] + 1, 1); n   } n   for (int i = n - 1; i >= 0; --i) { n     num1[i] += num2[i]; n     if (i) num1[i - 1] += num1[i] / (n - i); n     num1[i] %= (n - i); n   } n   buildT(1, 0, n - 1); n   for (int i = 0; i < n; ++i) { n     int need = num1[i] + 1; n     int val = getT(1, 0, n - 1, need); n     p3[i] = val; n     updT(1, 0, n - 1, val); n   } n   for (int i = 0; i < n; ++i) printf( %d  , p3[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v; n long long x, y, z, a, b, c, sum, ans, total, t, cnt, n, m, k, p, kase; n string s1, s2; n map<long long, long long> mp; n set<long long> s; n map<long long, long long>::iterator itr1, ptr1; n set<long long>::iterator itr, ptr; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> t; n   while (t--) { n     long long x1, x2, y1, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     ans = abs(x1 - x2); n     ans *= abs(y1 - y2); n     cout << ans + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10; n long long n, sum, n1, pick, ans, t, a[N], b[N], f[N], f1[N], m, t1; n int main() { n   scanf( %lld , &n); n   for (int i = 1; i <= 8; i++) { n     scanf( %lld , &a[i]); n     sum = sum + a[i] * i; n   } n   if (sum <= n) return printf( %lld n , sum), 0; n   n1 = std::max((long long)0, n - 840), n = n - n1; n   for (int i = 1; i <= 8; i++) { n     if (a[i] < n1 / i) n       pick = a[i]; n     else n       pick = n1 / i; n     if (a[i] - pick < 10) pick = std::max((long long)0, a[i] - 10); n     ans = ans + pick * i, n1 = n1 - pick * i, a[i] = a[i] - pick; n   } n   n += n1; n   for (int i = 1; i <= 8; i++) { n     t = 1; n     while (a[i] > 0) { n       t1 = std::min(t, a[i]); n       a[i] = a[i] - t1; n       f[++m] = t1 * i; n       t <<= 1; n     } n   } n   for (long long i = 1; i <= m; i++) n     for (long long j = n; j >= f[i]; j--) n       f1[j] = std::max(f1[j], f1[j - f[i]] + f[i]); n   printf( %lld n , ans + f1[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string st[5050]; n int fr[27]; n int main() { n   memset(fr, 0, sizeof(fr)); n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> k >> n; n   for (int i = 0; i < k; i++) { n     cin >> st[i]; n   } n   string res = st[0]; n   memset(fr, 0, sizeof(fr)); n   bool du = false; n   for (int i = 0; i < n; i++) { n     fr[res[i] -  a ]++; n     if (fr[res[i] -  a ] > 1) { n       du = true; n     } n   } n   int ma = 0; n   int mi = 0; n   bool po = true; n   for (int i = 1; i < k; i++) { n     int df = 0; n     int ct[27] = {0}; n     for (int j = 0; j < n; j++) { n       ct[st[i][j] -  a ]++; n       if (st[i][j] != res[j]) { n         df++; n       } n     } n     if (df > 4) { n       po = false; n       break; n     } n     for (int j = 0; j < 27; j++) { n       if (ct[j] != fr[j]) { n         po = false; n         break; n       } n     } n     if (df > ma) { n       ma = df; n       mi = i; n     } n   } n   if (!po) { n     cout << -1 <<   n ; n     return 0; n   } n   if (ma == 0) { n     swap(res[0], res[1]); n     cout << res <<   n ; n     return 0; n   } n   if (ma == 2) { n     if (!du) { n       cout << -1 <<   n ; n       return 0; n       cout << -1 <<   n ; n       return 0; n     } n     cout << res <<   n ; n     return 0; n   } n   int q[4]; n   int ctr = 0; n   for (int i = 0; i < n; i++) { n     if (res[i] != st[mi][i]) { n       q[ctr++] = i; n     } n   } n   po = false; n   int tr[2] = {0, 0}; n   for (int id = 0; id < 3; id++) { n     if (ma < 4) { n       q[3] = q[id]; n     } else if (id > 0) n       break; n     for (int i = 0; i < 4; i++) { n       for (int j = 0; j < 4; j++) { n         if (po) break; n         int md = 0; n         swap(res[q[i]], res[q[j]]); n         for (int c = 1; c < k; c++) { n           int df = 0; n           for (int l = 0; l < n; l++) { n             if (res[l] != st[c][l]) { n               df++; n             } n           } n           md = max(md, df); n         } n         swap(res[q[i]], res[q[j]]); n         if (md == 2) { n           po = true; n           tr[0] = i; n           tr[1] = j; n         } n       } n     } n   } n   if (po) { n     swap(res[q[tr[0]]], res[q[tr[1]]]); n     cout << res <<   n ; n   } else { n     cout << -1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string multiply(string num1, string num2) { n   int len1 = num1.size(); n   int len2 = num2.size(); n   if (len1 == 0 || len2 == 0) return  0 ; n   vector<int> result(len1 + len2, 0); n   int i_n1 = 0; n   int i_n2 = 0; n   for (int i = len1 - 1; i >= 0; i--) { n     int carry = 0; n     int n1 = num1[i] -  0 ; n     i_n2 = 0; n     for (int j = len2 - 1; j >= 0; j--) { n       int n2 = num2[j] -  0 ; n       int sum = n1 * n2 + result[i_n1 + i_n2] + carry; n       carry = sum / 10; n       result[i_n1 + i_n2] = sum % 10; n       i_n2++; n     } n     if (carry > 0) result[i_n1 + i_n2] += carry; n     i_n1++; n   } n   int i = result.size() - 1; n   while (i >= 0 && result[i] == 0) i--; n   if (i == -1) return  0 ; n   string s =   ; n   while (i >= 0) s += std::to_string(result[i--]); n   return s; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int T; n   cin >> T; n   while (T--) { n     long int n; n     cin >> n; n     n = n / 2; n     string n1, n2, n3, ans1, ans; n     int temp; n     if (n % 3 == 0) { n       temp = 4 * n / 3; n       n1 = to_string(temp); n       n2 = to_string(n + 1); n       n3 = to_string(2 * n + 1); n       ans1 = multiply(n1, n2); n       ans = multiply(ans1, n3); n     } else if (n % 3 == 2) { n       temp = 4 * (n + 1) / 3; n       n1 = to_string(temp); n       n2 = to_string(n); n       n3 = to_string(2 * n + 1); n       ans1 = multiply(n1, n2); n       ans = multiply(ans1, n3); n     } else { n       temp = 4 * (2 * n + 1) / 3; n       n1 = to_string(temp); n       n2 = to_string(n + 1); n       n3 = to_string(n); n       ans1 = multiply(n1, n2); n       ans = multiply(ans1, n3); n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int n, x[N], y[N], xs[N], ys[N], cnt[2][2]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &x[i], &y[i]); n     xs[i] = x[i], ys[i] = y[i]; n   } n   sort(xs + 1, xs + n + 1); n   sort(ys + 1, ys + n + 1); n   int m = (n + 1) / 2; n   int cx = xs[m], cy = ys[m]; n   int dx = xs[m + 1] - xs[m], dy = ys[m + 1] - ys[m]; n   if (n & 1) { n     dx = min(dx, xs[m] - xs[m - 1]); n     dy = min(dy, ys[m] - ys[m - 1]); n   } n   long long ans = 0; n   bool flag = 0; n   for (int i = 1; i <= n; i++) { n     ans += abs(x[i] - cx) + abs(y[i] - cy); n     ++cnt[x[i] <= cx][y[i] <= cy]; n     if (x[i] == cx && y[i] == cy) flag = 1; n   } n   if (cnt[0][0] && cnt[0][1] && cnt[1][1] && cnt[1][0]) { n     if (n % 2 == 0 || flag) ans -= min(dx, dy); n   } n   printf( %lld n , ans * 2); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cout << fixed; n   double d, L, v1, v2; n   cin >> d >> L >> v1 >> v2; n   cout << setprecision(8) << (L - d) / (v1 + v2) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long scan_d() { n   char t = getchar(); n   long long you = 0; n   while (t >  9  || t <  0 ) t = getchar(); n   while (t <=  9  && t >=  0 ) { n     you *= 10; n     you += t -  0 ; n     t = getchar(); n   } n   return you; n } n long long dp[1050][1050]; n long long op[1001]; n int main() { n   for (int i = 0; i <= 1010; i++) dp[1][i] = 1; n   for (int i = 2; i <= 1010; i++) n     for (int o = i - 1; o <= 1010; o++) { n       dp[i][o] = dp[i - 1][o - 1] + dp[i][o - 1]; n       dp[i][o] %= 1000000007; n     } n   long long y; n   y = scan_d(); n   long long sum = 0; n   for (int i = 1; i <= y; i++) { n     op[i] = scan_d(); n   } n   long long ans = 1; n   for (int i = 1; i <= y; i++) { n     sum += op[i]; n     ans *= dp[op[i]][sum - 1]; n     ans %= 1000000007; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(T &x) { n   int f = 0; n   x = 0; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) f |= (ch ==  - ); n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   if (f) x = -x; n } n const int N = 20, mod = 998244353; n int f[N][N][N][N][2][2]; n int g[N][N][N][N][2][2]; n int x[N], y[N], n, m; n void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); } n int main() { n   read(n), read(m); n   for (int i = (1); i <= (n); i++) read(x[i]), read(y[i]); n   f[0][0][0][0][0][0] = 1; n   for (; m; m >>= 1) { n     memset(g, 0, sizeof g); n     for (int px = 0; px < (N); px++) n       for (int nx = 0; nx < (N); nx++) n         for (int py = 0; py < (N); py++) n           for (int ny = 0; ny < (N); ny++) n             for (int fx = 0; fx < (2); fx++) n               for (int fy = 0; fy < (2); fy++) { n                 int t = f[px][nx][py][ny][fx][fy]; n                 if (!t) continue; n                 for (int s = 0; s < (1 << n); s++) { n                   int Px = px, Nx = nx, Py = py, Ny = ny; n                   for (int i = (1); i <= (n); i++) n                     if (s >> (i - 1) & 1) { n                       Px += max(x[i], 0); n                       Nx -= min(x[i], 0); n                       Py += max(y[i], 0); n                       Ny -= min(y[i], 0); n                     } n                   if ((Px & 1) != (Nx & 1) || (Py & 1) != (Ny & 1)) continue; n                   int gx = n                       ((Px & 1) < (m & 1) ? 0 : ((Px & 1) > (m & 1) ? 1 : fx)); n                   int gy = n                       ((Py & 1) < (m & 1) ? 0 : ((Py & 1) > (m & 1) ? 1 : fy)); n                   Px >>= 1, Nx >>= 1, Py >>= 1, Ny >>= 1; n                   add(g[Px][Nx][Py][Ny][gx][gy], t); n                 } n               } n     swap(f, g); n   } n   cout << ((f[0][0][0][0][0][0] + mod - 1) % mod) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const long long mod = 1e9 + 7; n const long long N = 1e5 + 10; n inline long long add(long long x, long long y) { n   x += y; n   if (x >= mod) x -= mod; n   return x; n } n inline long long mul(long long x, long long y) { n   x = (1LL * x * y) % mod; n   return x; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long n; n   cin >> n; n   n--; n   cout <<  0 0  << endl; n   fflush(stdout); n   if (n == 0) { n     cout <<  1 0 1 1 ; n     fflush(stdout); n     return 0; n   } n   string prev; n   cin >> prev; n   long long l = 0; n   long long r = 1e9; n   long long i = 1; n   while (i <= n) { n     long long m = (l + r) / 2; n     cout << m <<     n          <<  0  << endl; n     fflush(stdout); n     string s; n     cin >> s; n     if (s == prev) { n       l = m; n     } else { n       r = m; n     } n     i++; n   } n   if (r - l < 2) { n     cout << r <<   1   << (r + 1) <<     << (2 * (r + 1) - 2 * l - 1); n     fflush(stdout); n     return 0; n   } n   long long m = (l + r) / 2; n   cout << m <<   0   << m <<   1 ; n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> c; n vector<bool> used; n void dfs(int u, vector<vector<int>>& v) { n   used[u] = 1; n   for (int i = 0; i < v[u].size(); i++) { n     if (c[u] == c[v[u][i]] && !used[v[u][i]]) { n       dfs(v[u][i], v); n     } n   } n } n int main() { n   int n; n   cin >> n; n   vector<vector<int>> v(n); n   c.resize(n); n   used.resize(n, 0); n   vector<int> cnt(110000); n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     v[a].push_back(b); n     v[b].push_back(a); n   } n   for (int i = 0; i < n; i++) { n     cin >> c[i]; n   } n   for (int i = 0; i < n; i++) { n     if (!used[i]) { n       cnt[c[i]]++; n       dfs(i, v); n     } n   } n   multiset<int> data; n   for (int i = 0; i < 100010; i++) { n     for (int j = 0; j < cnt[i]; j++) { n       data.insert(i); n     } n   } n   for (int i = 0; i < n; i++) { n     bool check = 0; n     multiset<int> tmp; n     for (int j = 0; j < v[i].size(); j++) { n       if (c[v[i][j]] == c[i]) { n         check = 1; n       } n       tmp.insert(c[v[i][j]]); n     } n     if (!check) { n       tmp.insert(c[i]); n     } n     if (tmp == data) { n       cout <<  YES  << endl; n       cout << i + 1 << endl; n       return 0; n     } n   } n   cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void fastio() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n long long power(long long a, long long b) { n   if (b == 0) { n     return 1; n   } else { n     if (b % 2 == 0) { n       return (a * power((a * a) % 1000000007, b / 2)) % 1000000007; n     } else { n       return power((a * a) % 1000000007, b / 2); n     } n   } n } n int main() { n   fastio(); n   long long l, r; n   cin >> l >> r; n   long long even1 = 0, odd1 = 0; n   long long p = 0; n   l--; n   while (l > 0) { n     long long t = min((long long)pow(2LL, p), l); n     if (p % 2 == 0) { n       odd1 += t; n       odd1 %= 1000000007; n     } else { n       even1 += t; n       even1 %= 1000000007; n     } n     p++; n     l -= t; n   } n   long long even2 = 0, odd2 = 0; n   p = 0; n   while (r > 0) { n     long long t = min((long long)pow(2LL, p), r); n     if (p % 2 == 0) { n       odd2 += t; n       odd2 %= 1000000007; n     } else { n       even2 += t; n       even2 %= 1000000007; n     } n     p++; n     r -= t; n   } n   long long sum1 = (even1 * (even1 + 1)) % 1000000007; n   sum1 = (sum1 + (odd1 * odd1) % 1000000007) % 1000000007; n   long long sum2 = (even2 * (even2 + 1)) % 1000000007; n   sum2 = (sum2 + (odd2 * odd2) % 1000000007) % 1000000007; n   cout << (sum2 - sum1 + 1000000007) % 1000000007; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n struct node { n   double x, y; n } po[1010]; n double dis(node a, node b) { n   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n } n node mark; n double cha(node a, node b, node c) { n   return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y); n } n double get(node a, node b, node c) { n   return abs(cha(a, b, c)) / dis(a, b) / 2.0; n } n int main() { n   int n; n   cin >> n; n   double ans = 1e9; n   for (int i = (0); i < (n); ++i) cin >> po[i].x >> po[i].y; n   for (int i = (0); i < (n); ++i) { n     ans = min(ans, get(po[(i - 1 + n) % n], po[(i + 1) % n], po[i])); n   } n   cout << fixed << setprecision(10) << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, x, c, cnt; n vector<long long> v1, v2; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   while (n--) { n     cin >> x; n     if (x > 0) n       v1.push_back(x), c += x; n     else n       v2.push_back(abs(x)), cnt += abs(x); n   } n   if (c > cnt) { n     cout <<  first n ; n     return 0; n   } n   if (cnt > c) { n     cout <<  second n ; n     return 0; n   } n   bool a = 0; n   for (int i = 0; i < min(v1.size(), v2.size()); i++) { n     if (v1[i] > v2[i]) { n       cout <<  first n ; n       return 0; n     } else if (v1[i] < v2[i]) { n       cout <<  second n ; n       return 0; n     } n   } n   if (x < 0) n     cout <<  second  << endl; n   else n     cout <<  first  << endl; n   return 0; n } n


#include <bits/stdc++.h> n long long n, t, ans; n short i, j, k; n char cnt, l; n long long C[43][43]; n int main() { n   scanf( %I64d %I64d , &n, &t); n   for (i = 0; (1ll << i) < t; ++i) n     ; n   if ((1ll << i) ^ t) { n     puts( 0 ); n     return 0; n   } n   k = i + 1; n   for (i = 0; i < 43; ++i) C[0][i] = 1ll; n   for (i = 1; i < 43; ++i) n     for (j = 1; j <= i; ++j) C[j][i] = C[j - 1][i - 1] + C[j][i - 1]; n   ++n; n   for (cnt = i = 0; (1ll << i) <= n; ++i) n     if ((1ll << i) & n) ++cnt; n   for (l = i = 0; (1ll << i) <= n; ++i) n     if (n & (1ll << i)) { n       ++l; n       if (k - cnt + l >= 0) ans += C[k - cnt + l][i]; n     } n   if (cnt == k) ++ans; n   if (k == 1) --ans; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1001; n int dp2[MAX_N][MAX_N], dp5[MAX_N][MAX_N]; n int n; n string findPath(int (*p)[MAX_N]) { n   int i = n - 1, j = n - 1; n   string path =   ; n   while (i != 0 && j != 0) { n     if (p[i - 1][j] > p[i][j - 1]) { n       path.insert(0,  R ); n       j--; n     } else { n       path.insert(0,  D ); n       i--; n     } n   } n   if (i == 0) { n     while (j != 0) { n       path.insert(0,  R ); n       j--; n     } n   } else { n     while (i != 0) { n       path.insert(0,  D ); n       i--; n     } n   } n   return path; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin >> n; n   int temp1, temp2, zeroI = -1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) { n       cin >> temp1; n       if (!temp1) { n         zeroI = i; n         continue; n       } n       temp2 = temp1; n       while (!(temp1 & 1)) { n         dp2[i][j]++; n         temp1 >>= 1; n       } n       while (!(temp2 % 5)) { n         dp5[i][j]++; n         temp2 /= 5; n       } n     } n   for (int i = 1; i < n; i++) { n     dp2[i][0] += dp2[i - 1][0]; n     dp5[i][0] += dp5[i - 1][0]; n     dp2[0][i] += dp2[0][i - 1]; n     dp5[0][i] += dp5[0][i - 1]; n   } n   for (int i = 1; i < n; i++) { n     for (int j = 1; j < n; j++) { n       dp2[i][j] += min(dp2[i - 1][j], dp2[i][j - 1]); n       dp5[i][j] += min(dp5[i - 1][j], dp5[i][j - 1]); n     } n   } n   int(*p)[MAX_N] = (dp2[n - 1][n - 1] < dp5[n - 1][n - 1]) ? dp2 : dp5; n   if ((~zeroI) && p[n - 1][n - 1] > 1) { n     cout <<  1  << endl; n     for (int i = 0; i < zeroI; i++) cout <<  D  << flush; n     for (int j = 1; j < n; j++) cout <<  R  << flush; n     for (int i = zeroI + 1; i < n; i++) cout <<  D  << flush; n     return 0; n   } else { n     cout << p[n - 1][n - 1] << endl; n     cout << findPath(p) << flush; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int B, n, m; n int li[500008], ri[500008], mx[500008], tag[500008]; n short g[480][100008]; n int bel[500008], de[500008], ai[500008], pa[500008]; n short size[500008]; n int find(int x) { n   if (pa[x] == x) return x; n   return pa[x] = find(pa[x]); n } n void link(int x, int y) { n   if (x == y) return; n   if (size[x] > size[y]) swap(x, y); n   pa[x] = y; n   size[y] += size[x]; n } n int tot; n int lst[500008], stamp[500008]; n void makeup(int id) { n   ++tot; n   mx[id] = 0; n   for (int i = li[id]; i <= ri[id]; i++) pa[i] = i, size[i] = 1; n   for (int i = li[id]; i <= ri[id]; i++) { n     int x = ai[i]; n     mx[id] = max(mx[id], x); n     if (stamp[x] != tot) n       stamp[x] = tot, g[id][x] = lst[x] = i - li[id]; n     else n       link(i, g[id][x] + li[id]), g[id][x] = find(g[id][x] + li[id]) - li[id]; n   } n } n void pushdown(int id) { n   for (int i = li[id]; i <= ri[id]; i++) g[id][ai[i]] = -1; n   for (int i = li[id]; i <= ri[id]; i++) { n     g[id][ai[i] + de[i]] = -1; n     if (find(i) == i) ai[i] = ai[i] + de[i] - tag[id]; n     de[i] = 0; n   } n   for (int i = li[id]; i <= ri[id]; i++) ai[i] = ai[find(i)]; n   tag[id] = 0; n } n void refresh(int id) { n   while (-1 == g[id][mx[id]]) mx[id]--; n } n int cnt = 0; n void subtract(int id, int x) { n   if (mx[id] - tag[id] <= x) return; n   if (mx[id] - tag[id] > x * 2 + 1 and 1) { n     for (int i = tag[id] + 1; i <= x + tag[id]; i++) n       if (g[id][i] != -1) { n         int j = i + x; n         de[g[id][i] + li[id]] += x; n         if (g[id][j] != -1) n           link(g[id][i] + li[id], g[id][j] + li[id]), n               g[id][j] = find(g[id][j] + li[id]) - li[id]; n         else n           g[id][j] = g[id][i]; n         g[id][i] = -1; n       } n     tag[id] += x; n   } else { n     for (int i = x + 1 + tag[id]; i <= mx[id]; i++) n       if (g[id][i] != -1) { n         int j = i - x; n         de[g[id][i] + li[id]] -= x; n         if (g[id][j] != -1) n           link(g[id][j] + li[id], g[id][i] + li[id]), n               g[id][j] = find(g[id][j] + li[id]) - li[id]; n         else n           g[id][j] = g[id][i]; n         g[id][i] = -1; n       } n     refresh(id); n   } n } n int ask(int id, int x) { n   if (x + tag[id] > 100001) return 0; n   if (g[id][x + tag[id]] == -1) return 0; n   g[id][x + tag[id]] = find(g[id][x + tag[id]] + li[id]) - li[id]; n   return size[g[id][x + tag[id]] + li[id]]; n } n signed main() { n   memset(g, -1, sizeof g); n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &ai[i]); n   B = sqrt(n); n   B = max(B, n / 475); n   memset(li, 0x3f, sizeof li); n   for (int i = 1; i <= n; i++) { n     bel[i] = i / B; n     li[bel[i]] = min(li[bel[i]], i); n     ri[bel[i]] = i; n   } n   for (int i = 0; i <= n / B; i++) makeup(i); n   while (m--) { n     int op, l, r, x; n     scanf( %d%d%d%d , &op, &l, &r, &x); n     if (op == 1) { n       if (bel[l] == bel[r]) { n         pushdown(bel[l]); n         for (int i = l; i <= r; i++) n           if (ai[i] > x) ai[i] -= x; n         makeup(bel[l]); n       } else { n         pushdown(bel[l]); n         for (int i = l; i <= ri[bel[l]]; i++) n           if (ai[i] > x) ai[i] -= x; n         pushdown(bel[r]); n         for (int i = li[bel[r]]; i <= r; i++) n           if (ai[i] > x) ai[i] -= x; n         makeup(bel[l]); n         makeup(bel[r]); n         for (int i = bel[l] + 1; i < bel[r]; i++) subtract(i, x); n       } n     } else { n       int ans = 0; n       if (bel[l] == bel[r]) { n         pushdown(bel[l]); n         for (int i = l; i <= r; i++) n           if (ai[i] == x) ans++; n         makeup(bel[l]); n         printf( %d n , ans); n       } else { n         pushdown(bel[l]); n         for (int i = l; i <= ri[bel[l]]; i++) ans += (ai[i] == x); n         pushdown(bel[r]); n         for (int i = li[bel[r]]; i <= r; i++) ans += (ai[i] == x); n         makeup(bel[l]); n         makeup(bel[r]); n         for (int i = bel[l] + 1; i < bel[r]; i++) ans += ask(i, x); n         printf( %d n , ans); n       } n     } n     ++cnt; n     if (cnt < -7) { n       for (int i = 0; i <= n / B; i++) pushdown(i); n       for (int i = 1; i <= n; i++) cout << ai[i] <<    ; n       cout << g[2][30] <<  : n n ; n       for (int i = 0; i <= n / B; i++) makeup(i); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n long long a[N]; n int n; n bool check(long long x) { n   long long sum = 0; n   for (int i = 2; i <= n; ++i) { n     if (x - a[i] < 0) return false; n     sum += x - a[i]; n   } n   return (sum >= a[1]); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]); n   sort(a + 1, a + n + 1); n   long long l = 0, r = (long long)1e14 + 1; n   while (l + 1 < r) { n     long long mid = (l + r) / 2; n     if (check(mid)) n       r = mid; n     else n       l = mid; n   } n   if (check(l)) n     printf( %I64d , l); n   else n     printf( %I64d , r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isPowerOfTwo(int n) { n   if (n == 0) return false; n   return (ceil(log2(n)) == floor(log2(n))); n } n void asquare() { n   long long n, c = 0, ans = LONG_LONG_MAX; n   cin >> n; n   string sn; n   if (isPowerOfTwo(n) == true) n     cout <<  0 n ; n   else { n     long long j = 0, k = 0, nn = 1; n     string s = to_string(n); n     for (int i = 0; i <= 60; i++) { n       nn = (long long)pow(2, i); n       sn = to_string(nn); n       c = 0, j = 0, k = 0; n       bool bb; n       while (j != s.length() && k != sn.length()) { n         if (s[j] == sn[k]) { n           j++; n           k++; n           bb = true; n         } else { n           j++; n           c++; n           bb = false; n         } n       } n       if (bb = true) { n         if (j == s.length()) { n           k--; n           c += sn.length() - k - 1; n         } else if (k == sn.length()) { n           j--; n           c += s.length() - j - 1; n         } n       } else { n         k--; n         c += sn.length() - k - 1; n       } n       if (c == 1) { n         ans = 1; n         break; n       } else n         ans = min(ans, c); n     } n     cout << ans <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     asquare(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int x, y; n   cin >> x >> y; n   int ans = 0; n   int d = max(abs(x), abs(y)); n   if (d == 0) { n     cout << 0 <<   n ; n     return 0; n   } else n     ans = (d - 1) * 4; n   if (x == d && y != -1 * (d - 1) && y != -1 * (d)) ans++; n   if (y == d && x != d) ans += 2; n   if (x == -1 * d && y != d) ans += 3; n   if (y == -1 * d && x != -1 * d) ans += 4; n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct Aho { n   Aho *son[26]; n   Aho *fail; n   int cntstr, faildp; n   Aho() { n     for (int i = 0; i < 26; ++i) son[i] = NULL; n     fail = NULL; n     cntstr = 0; n     faildp = -1; n   } n }; n void insert(Aho *x, int i, const string &str) { n   if (i < str.size()) { n     if (x->son[str[i] -  a ] == NULL) { n       x->son[str[i] -  a ] = new Aho(); n     } n     insert(x->son[str[i] -  a ], i + 1, str); n   } else { n     x->cntstr++; n   } n } n void calcFailEdges(Aho *root) { n   deque<Aho *> q; n   root->fail = root; n   q.push_back(root); n   while (!q.empty()) { n     Aho *x = q.front(); n     q.pop_front(); n     for (int i = 0; i < 26; ++i) { n       if (x->son[i] != NULL) { n         q.push_back(x->son[i]); n         Aho *pnt = x->fail; n         if (x == root) n           x->son[i]->fail = root; n         else { n           while (pnt != root && pnt->son[i] == NULL) { n             pnt = pnt->fail; n           } n           if (pnt->son[i] != NULL) n             x->son[i]->fail = pnt->son[i]; n           else n             x->son[i]->fail = root; n         } n       } n     } n   } n } n int getDp(Aho *t) { n   if (t->faildp == -1) { n     t->faildp = t->cntstr; n     t->faildp += getDp(t->fail); n   } n   return t->faildp; n } n const int MAX_N = 200000; n Aho *state[1 + MAX_N]; n Aho *advance(Aho *t, char ch) { n   while (t->fail != t && t->son[ch -  a ] == NULL) t = t->fail; n   if (t->son[ch -  a ] == NULL) return t; n   return t->son[ch -  a ]; n } n Aho *state1[MAX_N], *state2[MAX_N]; n void doStuff(int n, Aho **state, const string &str, const vector<string> &vec) { n   Aho *T = new Aho(); n   for (int i = 0; i < n; ++i) insert(T, 0, vec[i]); n   T->faildp = T->cntstr; n   calcFailEdges(T); n   Aho *pnt = T; n   for (int i = 1; i <= str.size(); ++i) { n     pnt = advance(pnt, str[i - 1]); n     state[i] = pnt; n   } n } n int main() { n   int n; n   string str; n   cin >> str >> n; n   vector<string> vec; n   for (int i = 0; i < n; ++i) { n     string p; n     cin >> p; n     vec.push_back(p); n   } n   doStuff(n, state1, str, vec); n   for (int i = 0; i < n; ++i) reverse(vec[i].begin(), vec[i].end()); n   reverse(str.begin(), str.end()); n   doStuff(n, state2, str, vec); n   long long rez = 0LL; n   for (int i = 1; i < str.size(); ++i) n     rez = (long long)getDp(state1[i]) * getDp(state2[str.size() - i]) + rez; n   printf( %lld , rez); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n const int base = 101; n inline void chmax(int& x, int y) { n   if (x < y) x = y; n } n inline void chmin(int& x, int y) { n   if (x > y) x = y; n } n inline int LSB(int i) { return (i & -i); } n int n, m, dp[10005]; n char s[10005], str[10005]; n map<long long, string> mp; n vector<string> v; n inline long long Hash(int a, int b) { return (1LL * a * base + b) % MOD; } n int main() { n   scanf( %d%s%d , &n, &s, &m); n   for (int i = 0; i < m; i++) { n     scanf( %s , &str); n     long long h = 1; n     for (int j = 0; j < strlen(str); j++) { n       h = Hash(h, tolower(str[j])); n     } n     mp[h] = str; n   } n   fill(dp, dp + n, -1); n   dp[0] = 0; n   for (int i = 0; i < n; i++) { n     long long h = 1; n     for (int j = i; j >= 0; j--) { n       h = Hash(h, s[j]); n       if (dp[j] != -1 && mp.find(h) != mp.end()) { n         dp[i + 1] = h; n         break; n       } n     } n   } n   int p = n; n   while (p > 0) { n     v.push_back(mp[dp[p]]); n     p -= mp[dp[p]].length(); n   } n   reverse(v.begin(), v.end()); n   for (string& i : v) printf( %s  , &i[0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long p = 1e9 + 7; n int mk[705][705][3][3]; n char s[705]; n long long ck(int l, int r, int lc, int rc) { n   if (l > r) return !lc || !rc || lc != rc; n   if (mk[l][r][lc][rc]) return mk[l][r][lc][rc]; n   for (int i = l, cnt = 0;; i++) { n     if (s[i] ==  ) ) n       cnt++; n     else n       cnt--; n     if (!cnt) { n       long long m = ck(l + 1, i - 1, 0, 1) * ck(i + 1, r, 1, rc) % p + n                     ck(l + 1, i - 1, 0, 2) * ck(i + 1, r, 2, rc); n       if (lc != 1) m += ck(l + 1, i - 1, 1, 0) * ck(i + 1, r, 0, rc); n       if (lc != 2) m += ck(l + 1, i - 1, 2, 0) * ck(i + 1, r, 0, rc); n       return mk[l][r][lc][rc] = m % p; n     } n   } n } n int main() { n   scanf( %s , s + 1); n   printf( %lld , ck(1, strlen(s + 1), 0, 0)); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n using ll = long long; n using ull = unsigned long long; n template <typename T> n void print(vector<T> v) { n   for (T i : v) cout << i <<    ; n   cout <<   n ; n } n template <typename T> n void print(vector<vector<T>>& v) { n   for (vector<T>& vv : v) { n     for (T& i : vv) cout << i <<    ; n     cout <<   n ; n   } n } n template <typename T> n void print(T&& t) { n   cout << t <<   n ; n } n template <typename T, typename... Args> n void print(T&& t, Args&&... args) { n   cout << t <<    ; n   print(forward<Args>(args)...); n } n template <typename T> n istream& operator>>(istream& is, vector<T>& v) { n   for (auto& i : v) is >> i; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, vector<T>& v) { n   for (auto& i : v) os << i <<    ; n   return os; n } n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char* x) { cerr <<     << x <<    ; } n void __print(const string& x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V>& x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T& x) { n   int f = 0; n   cerr <<  { ; n   for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void loop() { n   ll n; n   cin >> n; n   vector<ll> a(n); n   cin >> a; n   if (n == 1) { n     print( Alice ); n     return; n   } n   vector<ll> inc, dec; n   inc.push_back(a[0]); n   for (ll i = 0; i < n - 1; i++) { n     if (a[i] < a[i + 1]) { n       inc.push_back(a[i + 1]); n     } else n       break; n   } n   dec.push_back(a[n - 1]); n   for (ll i = n - 1; i > 0; i--) { n     if (a[i] < a[i - 1]) { n       dec.push_back(a[i - 1]); n     } else n       break; n   } n   if (dec.size() % 2) { n     print( Alice ); n     return; n   } else if ((inc.size() - 1 + dec.size()) % 2 == 0) { n     print( Alice ); n     return; n   } n   print( Bob ); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ll t; n   t = 1; n   while (t--) { n     loop(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n const int INF = 0x3f3f3f3f; n int n, m, a[maxn], b[maxn], f[maxn], g[maxn], l[maxn], p[maxn], ans[maxn]; n bool vis[maxn]; n int main() { n   scanf( %d , &n); n   for (int i = (1), _end_ = (n); i <= _end_; ++i) scanf( %d , &a[i]); n   a[++n] = INF; n   scanf( %d , &m); n   for (int i = (1), _end_ = (m); i <= _end_; ++i) scanf( %d , &b[i]); n   sort(b + 1, b + m + 1); n   for (int i = (1), _end_ = (n + 1); i <= _end_; ++i) f[i] = INF; n   for (int i = (1), _end_ = (n); i <= _end_; ++i) n     if (a[i] != -1) { n       int L = 1, R = n, pos = 0; n       while (L <= R) { n         int Mid = L + R >> 1; n         if (f[Mid] < a[i]) { n           pos = Mid; n           L = Mid + 1; n         } else n           R = Mid - 1; n       } n       f[pos + 1] = a[i]; n       g[pos + 1] = i; n       l[i] = pos + 1; n       p[i] = g[pos]; n     } else { n       int pos = n; n       for (int j = m; j >= 1; --j) { n         while (f[pos] >= b[j]) --pos; n         f[pos + 1] = b[j]; n         g[pos + 1] = i; n       } n     } n   for (int len = l[n], pos = n, val = a[n]; len >= 1; --len) n     if (a[pos] != -1) { n       if (a[p[pos]] != -1) { n         pos = p[pos]; n         val = a[pos]; n       } else { n         int t = lower_bound(b + 1, b + m + 1, val) - b - 1; n         vis[t] = true; n         pos = p[pos]; n         val = ans[pos] = b[t]; n       } n     } else { n       for (int i = pos - 1; i >= 1; --i) n         if (a[i] != -1 && l[i] == len - 1 && a[i] < val) { n           pos = i; n           val = a[i]; n           goto Next; n         } n       for (int i = pos - 1; i >= 1; --i) n         if (a[i] == -1) { n           int t = lower_bound(b + 1, b + m + 1, val) - b - 1; n           vis[t] = true; n           pos = i; n           val = ans[pos] = b[t]; n           goto Next; n         } n     Next:; n     } n   int pos = 1; n   for (int i = (1), _end_ = (n - 1); i <= _end_; ++i) n     if (a[i] != -1) n       ans[i] = a[i]; n     else if (!ans[i]) { n       while (vis[pos]) ++pos; n       ans[i] = b[pos]; n       ++pos; n     } n   for (int i = (1), _end_ = (n - 1); i <= _end_; ++i) printf( %d  , ans[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int getChar(char c) { n   if (c ==  + ) return 1; n   return 0; n } n string s; n stack<int> mystack; n int main() { n   cin >> s; n   int n = s.size(); n   int temp; n   for (int i = 0; i < n; i++) { n     temp = getChar(s[i]); n     if (mystack.empty()) n       mystack.push(temp); n     else { n       if (mystack.top() == temp) n         mystack.pop(); n       else n         mystack.push(temp); n     } n   } n   if (mystack.empty()) { n     cout <<  Yes  << endl; n     return 0; n   } n   cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2000000000; n const double eps = 1e-9, Pi = 2 * acos(0); n int main() { n   ifstream fin( input.txt ); n   ofstream fout( output.txt ); n   string s; n   cin >> s; n   map<string, int> make_pair; n   for (int i = 0; i <= 9; i++) { n     string x; n     cin >> x; n     make_pair[x] = i; n   } n   for (int i = 0; i < 8; i++) { n     string x =   ; n     for (int j = i * 10; j < (i + 1) * 10; j++) x += s[j]; n     cout << make_pair[x]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, memo[1 << 25]; n pair<int, int> arr[30]; n int dist(int a, int n) { n   int k1 = arr[n].first - arr[a].first; n   int k2 = arr[n].second - arr[a].second; n   return k1 * k1 + k2 * k2; n } n int dp(int mask) { n   if (__builtin_popcount(mask) == N) { n     return 0; n   } n   if (memo[mask] != 0) return memo[mask]; n   int res = 1e9; n   for (int i = 1; i <= N; i++) { n     if (!((mask >> (i - 1) & 1))) { n       res = min(res, dp(mask | (1 << (i - 1))) + 2 * dist(i, 0)); n       for (int j = i + 1; j <= N; j++) { n         if (!(mask >> (j - 1) & 1) and i != j) { n           res = min(res, dp(mask | (1 << (i - 1)) | (1 << (j - 1))) + n                              dist(i, 0) + dist(i, j) + dist(j, 0)); n         } n       } n       break; n     } n   } n   memo[mask] = res; n   return res; n } n void backtrack(int mask) { n   if (__builtin_popcount(mask) == N) { n     return; n   } n   for (int i = 1; i <= N; i++) { n     if (!((mask >> (i - 1) & 1))) { n       if (dp(mask | (1 << (i - 1))) + 2 * dist(i, 0) == dp(mask)) { n         cout << 0 <<     << i <<    ; n         backtrack(mask | (1 << (i - 1))); n         return; n       } n       for (int j = i + 1; j <= N; j++) { n         if (!(mask >> (j - 1) & 1) and i != j) { n           if (dp(mask | (1 << (i - 1)) | (1 << (j - 1))) + dist(i, 0) + n                   dist(i, j) + dist(j, 0) == n               dp(mask)) { n             cout << 0 <<     << i <<     << j <<    ; n             backtrack(mask | (1 << (i - 1)) | (1 << (j - 1))); n             return; n           } n         } n       } n       break; n     } n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   cin >> arr[0].first >> arr[0].second; n   cin >> N; n   for (int i = 1; i <= N; i++) cin >> arr[i].first >> arr[i].second; n   cout << dp(0) << endl; n   backtrack(0); n   cout << 0 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char a[51][51]; n int main() { n   memset(a,  0 , sizeof(a)); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) cin >> a[i][j]; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) { n       int x = a[i][j] -  0 ; n       if (x != 0) { n         if (a[i - 1][j - 1] !=  0 ) x--; n         if (a[i - 1][j + 1] !=  0 ) x--; n         if (a[i + 1][j - 1] !=  0 ) x--; n         if (a[i + 1][j + 1] !=  0 ) x--; n         if (x != 0) return cout <<  No , 0; n       } n     } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[2][400000 + 10]; n int n; n void sortstr(int t, int l, int r) { n   if ((r - l + 1) & 1) return; n   int md = (l + r) / 2; n   sortstr(t, l, (l + r) / 2), sortstr(t, (l + r) / 2 + 1, r); n   bool needswap = false; n   for (int i = l, j = md + 1; i <= md; i++, j++) { n     if (str[t][i] < str[t][j]) break; n     if (str[t][i] > str[t][j]) { n       needswap = true; n       break; n     } n   } n   if (needswap) { n     for (int i = l, j = md + 1; i <= md; i++, j++) swap(str[t][i], str[t][j]); n   } n } n int main() { n   for (int i = 0; i < 2; i++) n     scanf( %s , str[i]), n = strlen(str[i]), sortstr(i, 0, n - 1); n   bool equ = true; n   for (int i = 0; i < n; i++) n     if (str[0][i] != str[1][i]) equ = false; n   printf( %s n , equ ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, gxx; n pair<int, int> a[411111]; n int p[411111]; n int Gxx[411111], bb[411111]; n int degree[411111]; n int h, t; n void make_ans(int x, int y, int tot) { n   int now_x = degree[x] - 1 - tot; n   int need_x = max(h - now_x, 0); n   int now_y = degree[y] - 1 - tot; n   int need_y = max(t - now_y, 0); n   for (int i = p[x]; i < p[x + 1]; i++) Gxx[a[i].second] = 1; n   for (int i = p[y]; i < p[y + 1]; i++) n     if (Gxx[a[i].second] == 1) bb[a[i].second] = 1; n   printf( YES n ); n   printf( %d %d n , x, y); n   bool bo = false; n   for (int i = p[x]; i < p[x + 1]; i++) n     if ((bb[a[i].second] == 0 || need_x) && a[i].second != y && h) { n       h--; n       if (bb[a[i].second]) { n         bb[a[i].second] = -1; n         need_x--; n       } n       if (bo) printf(   ); n       bo = true; n       printf( %d , a[i].second); n     } n   printf(  n ); n   bo = false; n   for (int i = p[y]; i < p[y + 1]; i++) n     if ((bb[a[i].second] == 0 || need_y) && a[i].second != x && t && n         bb[a[i].second] != -1) { n       t--; n       if (bb[a[i].second]) need_y--; n       if (bo) printf(   ); n       bo = true; n       printf( %d , a[i].second); n     } n   printf(  n ); n } n int find(int x, int y) { n   int ans = 0; n   for (int i = p[x]; i < p[x + 1]; i++) n     if (a[i].second != y) { n       int t = n           lower_bound(a + p[y], a + p[y + 1], make_pair(y, a[i].second)) - a; n       if (a[t].second == a[i].second) ans++; n     } n   return ans; n } n int main() { n   scanf( %d%d%d%d , &n, &m, &h, &t); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &a[i].first, &a[i].second); n     degree[a[i].first]++; n     degree[a[i].second]++; n     a[i + m].second = a[i].first; n     a[i + m].first = a[i].second; n   } n   int M = m * 2; n   sort(a + 1, a + M + 1); n   a[0].first = 0; n   a[M + 1].first = n + 1; n   int now = 0; n   for (int i = 1; i <= M + 1; i++) n     while (now != a[i].first) { n       now++; n       p[now] = i; n     } n   p[0] = 0; n   for (int i = 1; i <= M; i++) n     if (degree[a[i].first] > h && degree[a[i].second] > t) { n       int t1 = a[i].first; n       int t2 = a[i].second; n       int tot = 0; n       if (t1 < t2) n         tot = find(t1, t2); n       else n         tot = find(t2, t1); n       if (degree[t1] + degree[t2] - 2 - tot >= h + t) { n         make_ans(t1, t2, tot); n         return 0; n       } n     } n   printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int v[100000 + 1]; n int mx, rez; n pair<int, int> rz[100000 + 1]; n int stkLen; n int stkLen2; n int stk[100000 + 1]; n int stk2[100000 + 1]; n int s, s2; n void readFile() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> v[i]; n } n int cautBin(int nr, int stk[], int stkLen) { n   int i = 0; n   int pas = 1 << 16; n   while (pas != 0) { n     if (i + pas <= stkLen && abs(v[stk[i + pas]] - nr) > k) i += pas; n     pas >>= 1; n   } n   return stk[i] + 1; n } n bool verif(int st, int dr) { n   while (s < stkLen && stk[s] < st) s++; n   while (s2 < stkLen2 && stk2[s2] < st) s2++; n   return (abs(v[stk[s]] - v[stk2[s2]]) <= k); n } n void solve() { n   stkLen = 0; n   int st = 1; n   s = s2 = 1; n   for (int i = 1; i <= n; i++) { n     while (stkLen >= s && v[i] >= v[stk[stkLen]]) stkLen--; n     stk[++stkLen] = i; n     while (stkLen2 >= s2 && v[i] <= v[stk2[stkLen2]]) stkLen2--; n     stk2[++stkLen2] = i; n     while (st < i && verif(st, i) == 0) st++; n     int len = i - st + 1; n     if (len > mx) { n       mx = len; n       rez = 0; n     } n     if (len == mx) rz[++rez] = {st, i}; n   } n } n void printFile() { n   cout << mx <<     << rez <<   n ; n   for (int i = 1; i <= rez; i++) n     cout << rz[i].first <<     << rz[i].second <<   n ; n } n int main() { n   readFile(); n   solve(); n   printFile(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ar[200010]; n void solve() { n   long long a, b, c = 0, i, j, t, k, lie, m, n, o, x, y, z; n   long long p = 0, sm = 0, cnt = 0; n   scanf( %lld , &n); n   string s; n   cin >> s; n   if (n == 1) { n     printf( Yes n ); n     return; n   } n   for (i = 0; i < n; i++) ar[s[i] -  a ]++; n   for (i = 0; i < 26; i++) { n     if (ar[i] > 1) { n       printf( Yes n ); n       return; n     } n   } n   printf( No n ); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const int mod = 1e9 + 7; n const int N = 1e6 + 10; n const int inf = 1e9; n int t, n, k; n char s[N]; n int cnt[N]; n int a[N], b[N]; n int main() { n   ios::sync_with_stdio(false); n   cin >> t; n   while (t--) { n     cin >> n >> k; n     cin >> s + 1; n     for (int i = 1; i <= n; i++) { n       cnt[i] = cnt[i - 1]; n       if (s[i] ==  1 ) cnt[i]++; n     } n     int ans = inf; n     for (int i = 1; i <= k; i++) { n       int ret = 0, mn = inf, tp = inf, l = 0; n       vector<int> q; n       q.push_back(0); n       for (int j = i; j <= n; j += k) { n         int tmp = cnt[j - 1] - cnt[l]; n         ret += tmp; n         q.push_back(cnt[j] - cnt[j - 1]); n         l = j; n       } n       ret += cnt[n] - cnt[l]; n       int sz = q.size() - 1; n       for (int i = 1; i <= sz; i++) { n         a[i] = a[i - 1]; n         b[i] = b[i - 1]; n         if (q[i] == 1) n           a[i]++; n         else n           b[i]++; n       } n       tp = a[sz]; n       for (int i = sz; i >= 1; i--) { n         mn = min(mn, b[i] - a[i] + a[sz]); n         tp = min(tp, a[i - 1] - b[i - 1] + mn); n       } n       ans = min(ans, ret + tp); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::string; n using std::vector; n namespace Template { n struct IN { n   template <class T> n   void fr(T& a) { n     T s = 0; n     int w = 1; n     char ch = getchar(); n     while (ch <  0  || ch >  9 ) { n       if (ch ==  - ) w = -1; n       ch = getchar(); n     } n     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar(); n     a = w * s; n   } n   template <class T> n   T fr() { n     T a; n     fr(a); n     return a; n   } n   IN& operator>>(long long& x) { return fr(x), *this; } n   IN& operator>>(signed& x) { return fr(x), *this; } n   IN& operator>>(unsigned& x) { return fr(x), *this; } n   IN& operator>>(char& c) { n     while (isspace(c = getchar())) n       ; n     return *this; n   } n   IN& operator>>(string& str) { n     char ch; n     while (isspace(ch = getchar())) n       ; n     str = ch; n     while (!isspace(ch = getchar())) str += ch; n     return *this; n   } n } cin; n struct OUT { n   char D[1 << 27], *A = D - 1; n   ~OUT() { fwrite(D, 1, A - D + 1, stdout); } n   template <class T> n   void fw(T x) { n     static char C[20]; n     static int f; n     x < 0 ? * ++A =  - , x = -x : 0; n     while (C[++f] = 48 + x % 10, x /= 10) n       ; n     while (*++A = C[f], --f) n       ; n   } n   OUT& operator<<(char c) { return *++A = c, *this; } n   OUT& operator<<(string str) { n     int len = str.length(); n     for (int i = 0; i < len; i++) *++A = str[i]; n     return *this; n   } n   OUT& operator<<(long long x) { return fw(x), *this; } n   OUT& operator<<(signed x) { return fw(x), *this; } n   OUT& operator<<(unsigned x) { return fw(x), *this; } n } cout; n char endl =   n ; n int DEBUG = 0; n template <class T> n T sqr(T a) { n   return a * a; n } n template <class T> n T abs(T a) { n   return a < 0 ? -a : a; n } n template <class T> n T cmin(T a, T b) { n   return a < b ? a : b; n } n template <class T> n T cmax(T a, T b) { n   return a > b ? a : b; n } n template <class T> n void cswp(T& a, T& b) { n   T t = a; n   a = b; n   b = t; n } n }  // namespace Template n using namespace Template; n const int N = 1e5; n int n, blo, tot = 0, fa[N + 10], len[N + 10], arr[N + 10]; n vector<int> E[N + 10]; n void adde(int u, int v) { E[u].push_back(v); } n void dfs(int u, int f) { n   fa[u] = f, arr[++tot] = u; n   for (int v : E[u]) n     if (v != f) dfs(v, u); n } n int calc(int k) { n   int ret = 0; n   for (int i = 1; i <= n; i++) len[i] = 1; n   for (int i = n; i > 1; i--) { n     int u = arr[i], f = fa[u]; n     if (len[f] != -1 && len[u] != -1) { n       if (len[f] + len[u] >= k) n         ret++, len[f] = -1; n       else n         len[f] = cmax(len[f], len[u] + 1); n     } n   } n   return ret; n } n int main() { n   cin >> n; n   blo = sqrt(n * log2(n)); n   for (int i = 1; i < n; ++i) { n     int u, v; n     cin >> u >> v; n     adde(u, v), adde(v, u); n   } n   dfs(1, 0), cout << n << endl; n   for (int i = 2; i <= blo; i++) cout << calc(i) << endl; n   for (int i = blo + 1; i <= n;) { n     int f = calc(i), l = i, r = n, pos = 0; n     while (l <= r) { n       int mid = (l + r) >> 1; n       if (calc(mid) == f) n         l = mid + 1, pos = mid; n       else n         r = mid - 1; n     } n     for (; i <= pos; i++) cout << f << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n void MACRO_VAR_Scan(T& t) { n   std::cin >> t; n } n template <typename First, typename... Rest> n void MACRO_VAR_Scan(First& first, Rest&... rest) { n   std::cin >> first; n   MACRO_VAR_Scan(rest...); n } n template <typename T> n void MACRO_VEC_ROW_Init(int n, T& t) { n   t.resize(n); n } n template <typename First, typename... Rest> n void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) { n   first.resize(n); n   MACRO_VEC_ROW_Init(n, rest...); n } n template <typename T> n void MACRO_VEC_ROW_Scan(int p, T& t) { n   std::cin >> t[p]; n } n template <typename First, typename... Rest> n void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) { n   std::cin >> first[p]; n   MACRO_VEC_ROW_Scan(p, rest...); n } n template <class T> n inline T CHMAX(T& a, const T b) { n   return a = (a < b) ? b : a; n } n template <class T> n inline T CHMIN(T& a, const T b) { n   return a = (a > b) ? b : a; n } n template <class T> n using V = std::vector<T>; n template <class T> n using VV = V<V<T>>; n template <typename S, typename T> n std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) { n   os <<  (  << p.first <<  ,   << p.second <<  ) ; n   return os; n } n using ll = long long; n using ull = unsigned long long; n using ld = long double; n using PAIR = std::pair<ll, ll>; n using PAIRLL = std::pair<ll, ll>; n constexpr ll INFINT = 1 << 30; n constexpr ll INFINT_LIM = (1LL << 31) - 1; n constexpr ll INFLL = 1LL << 60; n constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); n constexpr double EPS = 1e-6; n constexpr ll MOD = 1000000007; n constexpr double PI = 3.141592653589793238462643383279; n template <class T, size_t N> n void FILL(T (&a)[N], const T& val) { n   for (auto& x : a) x = val; n } n template <class ARY, size_t N, size_t M, class T> n void FILL(ARY (&a)[N][M], const T& val) { n   for (auto& b : a) FILL(b, val); n } n template <class T> n void FILL(std::vector<T>& a, const T& val) { n   for (auto& x : a) x = val; n } n template <class ARY, class T> n void FILL(std::vector<std::vector<ARY>>& a, const T& val) { n   for (auto& b : a) FILL(b, val); n } n struct Trie { n   std::vector<std::vector<ll>> g; n   ll p; n   Trie() : p(0) { n     g.emplace_back(std::vector<ll>(2, -1)); n     ++p; n   } n   void add(const std::string& s) { n     size_t par = 0; n     for (size_t i = 0; i < s.size(); ++i) { n       ll t = s[i] -  0 ; n       if (g[par][t] == -1) { n         g.emplace_back(std::vector<ll>(2, -1)); n         g[par][t] = p++; n       } n       par = g[par][t]; n     } n   } n   ll next(size_t par, char c) { n     ll t = c -  0 ; n     return g[par][t]; n   } n }; n bool ng(std::string s) { n   return s ==  1100  || s ==  1010  || s ==  0111  || s ==  1111 ; n } n signed main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   ; n   ll n; n   MACRO_VAR_Scan(n); n   ; n   std::string s; n   for (ll i = 0; i < ll(n); ++i) { n     char c; n     MACRO_VAR_Scan(c); n     ; n     s += c; n   } n   Trie tr; n   std::vector<ll> c(n, 0); n   for (ll i = 0; i < ll(n); ++i) { n     auto S = s.substr(0, i + 1); n     std::reverse((S).begin(), (S).end()); n     std::vector<ll> dp(S.size() + 1, 0); n     dp[0] = 1; n     for (ll j = 0; j < ll(S.size()); ++j) { n       for (ll k = 0; k < ll(4); ++k) { n         if (j < k) break; n         if (k == 3) { n           if (ng(S.substr(j - 3, 4))) continue; n         } n         (dp[j + 1] += dp[j - k]) %= MOD; n       } n     } n     ll p = 0; n     ll len = 0; n     for (ll j = 0; j < ll(S.size()); ++j) { n       ll ne = tr.next(p, S[j]); n       if (ne == -1) break; n       p = ne; n       dp[++len] = 0; n     } n     tr.add(S); n     for (ll j = (1); j < (S.size() + 1); ++j) { n       (c[i] += dp[j]) %= MOD; n     } n   } n   for (ll i = 0; i < ll(n - 1); ++i) (c[i + 1] += c[i]) %= MOD; n   for (ll i = 0; i < ll(n); ++i) { n     std::cout << (c[i]); n     std::cout <<   n ; n     ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B, typename C> n struct triple { n   A X; n   B Y; n   C Z; n   triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {} n }; n template <typename A, typename B, typename C> n triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) { n   return triple<A, B, C>(a, b, c); n } n template <typename A, typename B, typename C> n bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) { n   if (a.X != b.X) return a.X < b.X; n   if (a.Y != b.Y) return a.Y < b.Y; n   return a.Z < b.Z; n } n template <typename T, typename SS> n ostream& operator<<(ostream& ofs, const pair<T, SS>& p) { n   ofs <<  (   << p.first <<   ,   << p.second <<   ) ; n   return ofs; n } n template <typename T> n void print(T a) { n   for (auto i : a) cout << i <<    ; n   cout <<   n ; n } n template <typename T> n T max(T a, T b, T c) { n   return max(a, max(b, c)); n } n template <typename T> n T min(T a, T b, T c) { n   return min(a, min(b, c)); n } n template <typename T, typename D> n D min(T a) { n   return *min_element(a.begin(), a.end()); n } n template <typename T, typename D> n D max(T a) { n   return *max_element(a.begin(), a.end()); n } n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n void solve() { n   string s; n   cin >> s; n   if ((long long)(s.size()) & 1) s =  0  + s; n   long long n = (long long)(s.size()); n   for (long long i = 0; i < (n); i++) s[i] -=  0 ; n   reverse(s.begin(), s.end()); n   vector<vector<long long> > dp(n / 2 + 1, vector<long long>(4)); n   dp[0][0] = 1; n   for (long long i = 0; i < (n / 2); i++) n     for (long long j = 0; j < (4); j++) { n       long long x = 2 * i, y = x + 1; n       long long dx = j & 1, dy = j >> 1; n       for (long long d11 = 0; d11 < (10); d11++) n         for (long long d12 = 0; d12 < (10); d12++) { n           long long sx = d11 + d12 + dx; n           if (sx % 10 != s[x]) continue; n           long long nmask = (sx >= 10); n           for (long long d21 = 0; d21 < (10); d21++) n             for (long long d22 = 0; d22 < (10); d22++) { n               long long sy = d21 + d22 + dy; n               if (sy % 10 != s[y]) continue; n               if (sy >= 10) nmask |= 2; n               dp[i + 1][nmask] += dp[i][j]; n             } n         } n     } n   cout << dp[n / 2][0] - 2 <<   n ; n }; n signed main() { n   if (0) { n     freopen( n          a  n          .in , n          r , stdin); n     freopen( n          a  n          .out , n          w , stdout); n   } n   srand(time(NULL)); n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   long long t = 1; n   cin >> t; n   for (long long _ = 0; _ < (t); _++) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000 + 7; n const int N = 1000006; n int n, a[305], ar[6], s, aa, bb, cc, mn = inf, x, t; n int main() { n   cin >> n >> s; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     ar[x]++; n   } n   for (int i = s / n; i >= 0; i--) { n     for (int j = (s - i * ar[3]) / (ar[4] + ar[5]); j >= i; j--) { n       t = (s - i * ar[3] - j * ar[4]) / ar[5]; n       if (t * ar[5] - j * ar[4] >= mn) break; n       if (i * ar[3] + j * ar[4] + t * ar[5] == s && j <= t) { n         if (mn > abs(i * ar[3] - j * ar[4]) + abs(j * ar[4] - t * ar[5])) { n           aa = i; n           bb = j; n           cc = t; n           mn = abs(i * ar[3] - j * ar[4]) + abs(j * ar[4] - t * ar[5]); n         } n       } n     } n   } n   if (mn == inf) n     cout << -1 << endl; n   else n     cout << aa <<     << bb <<     << cc << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const int MAXN = 200005; n int n, x[MAXN]; n long long a[MAXN], t; n long long b[MAXN]; n void solve() { n   for (int i = 0; i + 1 < n; i++) { n     if (x[i] > x[i + 1]) { n       cout <<  No  << endl; n       return; n     } n   } n   for (int i = 0; i < n; i++) { n     if (i > x[i]) { n       cout <<  No  << endl; n       return; n     } n   } n   for (int i = 0; i < n;) { n     int pos = x[i]; n     int j = i; n     while (j < n && x[j] == pos) { n       j++; n     } n     if (j < x[i] + 1) { n       cout <<  No  << endl; n       return; n     } n     long long num = a[j - 1]; n     for (int k = i; k + 1 < j; k++) { n       b[k] = a[k + 1] + t; n     } n     b[j - 1] = a[j - 1] + t + (j - i > 1); n     if (j < n && b[j - 1] >= a[j] + t) { n       cout <<  No  << endl; n       return; n     } n     i = j; n   } n   cout <<  Yes  << endl; n   for (int i = 0; i < n; i++) { n     cout << b[i] <<    ; n   } n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   while (cin >> n >> t) { n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     for (int i = 0; i < n; i++) { n       cin >> x[i]; n       x[i]--; n     } n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N, Q, C, Rt, L[200005], R[200005], G[200005], F[200005], ch[200005][2]; n struct Nod { n   int Now, Max, Min, Laz; n   Nod() { n     Min = 1 << 30; n     Max = -Min; n   } n } T[200005]; n vector<int> son[200005]; n void Upd(int x, int k) { n   if (x) T[x].Now += k, T[x].Max += k, T[x].Min += k, T[x].Laz += k; n } n void Up(int x) { n   int l = ch[x][0], r = ch[x][1]; n   T[x].Max = max(T[x].Now, max(T[l].Max, T[r].Max)); n   T[x].Min = min(T[x].Now, min(T[l].Min, T[r].Min)); n } n void Dn(int x) { n   int k = T[x].Laz; n   if (k) Upd(ch[x][0], k), Upd(ch[x][1], k), T[x].Laz = 0; n } n void Rot(int x) { n   int y = F[x], z = F[y], k = ch[y][0] == x, t; n   if (t = ch[y][!k] = ch[x][k]) F[t] = y; n   if (F[x] = z) ch[z][ch[z][1] == y] = x; n   ch[F[y] = x][k] = y; n   Up(y); n } n void Splay(int x, int Aim) { n   for (Dn(x); F[x] ^ Aim; Rot(x)) { n     int y = F[x], z = F[y]; n     Dn(z); n     Dn(y); n     Dn(x); n     if (F[y] ^ Aim) (ch[z][0] == y ^ ch[y][0] == x) ? Rot(x) : Rot(y); n   } n   Up(x); n   if (!Aim) Rt = x; n } n void DFS(int u, int d) { n   L[u] = ++C; n   G[C] = u; n   T[C].Now = d; n   for (int i = 1, lim = son[u].size(); i <= lim; i++) DFS(son[u][i - 1], d + 1); n   R[u] = ++C; n   G[C] = u; n   T[C].Now = d; n } n void Build(int& u, int l, int r, int fa) { n   F[u = l + r >> 1] = fa; n   if (l < u) Build(ch[u][0], l, u - 1, u); n   if (u < r) Build(ch[u][1], u + 1, r, u); n   Up(u); n } n int Find(int x, int k) { n   int l = ch[x][0], r = ch[x][1]; n   Dn(x); n   if (T[r].Min <= k && k <= T[r].Max) return Find(r, k); n   return T[x].Now == k ? x : Find(l, k); n } n int Pre(int x) { n   Splay(x, 0); n   x = ch[x][0]; n   for (; ch[x][1]; x = ch[x][1]) Dn(x); n   return x; n } n int Suf(int x) { n   Splay(x, 0); n   x = ch[x][1]; n   for (; ch[x][0]; x = ch[x][0]) Dn(x); n   return x; n } n void Get(int x, int y) { n   Splay(x, 0); n   Splay(y, x); n } n int main() { n   scanf( %d%d , &N, &Q); n   for (int i = 1, lim = N; i <= lim; i++) { n     int x, t; n     scanf( %d , &x); n     for (; x--;) scanf( %d , &t), son[i].push_back(t); n   } n   C++; n   DFS(1, 1); n   C++; n   Build(Rt, 1, C, 0); n   for (int k, x, y, z, l, r, w, t; Q--;) { n     scanf( %d , &k); n     if (k == 1) { n       scanf( %d%d , &x, &y); n       if (x == y) n         puts( 0 ); n       else { n         x = L[x]; n         y = L[y]; n         Get(x, y); n         z = (ch[x][0] == y ? T[ch[y][1]] : T[ch[y][0]]).Min; n         printf( %d n , n                T[x].Now + T[y].Now - 2 * min(z - 1, min(T[x].Now, T[y].Now))); n       } n     } else if (k == 2) { n       scanf( %d%d , &x, &y); n       Get(1, L[x]); n       w = G[Find(ch[L[x]][0], T[L[x]].Now - y)]; n       l = Pre(L[x]); n       r = Suf(R[x]); n       Get(l, r); n       t = ch[r][0]; n       ch[r][0] = 0; n       Up(r); n       Up(l); n       r = R[w]; n       l = Pre(r); n       Get(l, r); n       ch[r][0] = t; n       F[t] = r; n       Upd(t, -y + 1); n       Splay(t, 0); n     } else n       scanf( %d , &x), printf( %d n , G[Find(Rt, x + 1)]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 112, INF = 1e18; n long long t, n, m, a[N]; n long long B10(string s) { n   reverse(s.begin(), s.end()); n   long long ret = 0; n   for (long long i = 0; i < s.size(); i++) { n     if (s[i] ==  1 ) ret += (1ll << i); n   } n   return ret; n } n string B2(long long a) { n   string ret; n   for (long long i = 0; i < m; i++) { n     if (a & (1ll << i)) n       ret +=  1 ; n     else n       ret +=  0 ; n   } n   reverse(ret.begin(), ret.end()); n   return ret; n } n long long BS() { n   long long low = 0, high = (1ll << m); n   while (high - low > 1) { n     long long mid = (low + high) >> 1; n     long long v1 = mid - (lower_bound(a, a + n, mid) - a); n     long long v2 = ((1ll << m) - n - 1) / 2; n     if (v1 <= v2) n       low = mid; n     else n       high = mid; n   } n   return low; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   while (t--) { n     cin >> n >> m; n     for (long long i = 0; i < n; i++) { n       string s; n       cin >> s; n       a[i] = B10(s); n     } n     sort(a, a + n); n     cout << B2(BS()) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[100100]; n int main() { n   int n, a, b, t, cn = 1; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a; n     p[i] = a; n   } n   sort(p, p + n); n   int ans = 0; n   vector<int> v; n   for (int i = 0; i < n; i++) { n     int j = 0; n     for (j = 0; j < v.size(); j++) { n       if (p[i] >= v[j]) { n         v[j]++; n         break; n       } n     } n     if (j == v.size()) { n       v.push_back(1); n     } n   } n   cout << v.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2100; n char mp[N][N]; n int n, m, lp, rp, dis[N][N]; n bool vis[N][N]; n struct poi { n   int x, y; n } q[N * N], st; n void expan(int x, int y, int di) { n   int i; n   for (i = x; mp[i][y] !=  * ; i--) { n     q[++rp] = (poi){i, y}; n     dis[i][y] = di; n     vis[i][y] = 1; n   } n   for (i = x + 1; mp[i][y] !=  * ; i++) { n     q[++rp] = (poi){i, y}; n     dis[i][y] = di; n     vis[i][y] = 1; n   } n } n int main() { n   int i, j, k, le, ri, x, y; n   scanf( %d%d%d%d%d%d , &n, &m, &st.x, &st.y, &le, &ri); n   for (i = 1; i <= n; i++) scanf( %s , mp[i] + 1); n   for (i = 0; i <= m + 1; i++) mp[0][i] = mp[n + 1][i] =  * ; n   for (i = 0; i <= n + 1; i++) mp[i][0] = mp[i][m + 1] =  * ; n   lp = 1; n   rp = 0; n   expan(st.x, st.y, 0); n   while (lp <= rp) { n     poi now = q[lp++]; n     x = now.x; n     y = now.y; n     if ((!vis[x][y - 1]) && (mp[x][y - 1] !=  * )) n       expan(x, y - 1, dis[x][y] + 1); n     if ((!vis[x][y + 1]) && (mp[x][y + 1] !=  * )) n       expan(x, y + 1, dis[x][y] + 1); n   } n   int ans = 0; n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) { n       int fix = st.y - j; n       if ((vis[i][j]) && (mp[i][j] !=  * ) && n           (le >= ((dis[i][j] + fix) >> 1)) && (ri >= ((dis[i][j] - fix) >> 1))) n         ans++; n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char buf[25]; n struct node { n   long long x, y; n   bool operator<(node tp) const { n     if (x != tp.x) return x < tp.x; n     return y < tp.y; n   } n }; n map<long long, long long> h1, h2; n map<node, long long> t, q; n const long long inf = 1e17; n const long long maxn = 200010; n long long L1[maxn], R1[maxn], l1[maxn], r1[maxn], s1[maxn], a[maxn]; n long long L2[maxn], R2[maxn], l2[maxn], r2[maxn], s2[maxn]; n long long n, m, sum1, sum2; n long long ans; n long long read() { n   long long x = 0, f = 0; n   char ch; n   do { n     ch = getchar(); n     if (ch ==  - ) f = 1; n   } while (ch <  0  || ch >  9 ); n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return f ? -x : x; n } n void write(long long x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (!x) { n     putchar( 0 ); n     return; n   } n   long long cnt = 0; n   while (x) { n     buf[++cnt] =  0  + x % 10; n     x /= 10; n   } n   for (long long i = cnt; i >= 1; --i) putchar(buf[i]); n } n signed main() { n   srand(19267180); n   n = read(); n   m = read(); n   for (long long i = 1; i <= n; ++i) { n     h1[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf; n     h2[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf; n     sum1 = h1[i] ^ sum1; n     sum2 = h2[i] ^ sum2; n   } n   for (long long i = 1; i <= n; ++i) { n     long long l = read(), r = read(); n     ++a[l]; n     --a[r + 1]; n     s1[l] ^= h1[i]; n     s1[r + 1] ^= h1[i]; n     L1[l - 1] ^= h1[i]; n     R1[r + 1] ^= h1[i]; n     s2[l] ^= h2[i]; n     s2[r + 1] ^= h2[i]; n     L2[l - 1] ^= h2[i]; n     R2[r + 1] ^= h2[i]; n   } n   for (long long i = m - 1; i >= 1; --i) L1[i] ^= L1[i + 1], L2[i] ^= L2[i + 1]; n   for (long long i = 2; i <= m; ++i) { n     R1[i] ^= R1[i - 1], s1[i] ^= s1[i - 1]; n     R2[i] ^= R2[i - 1], s2[i] ^= s2[i - 1]; n   } n   for (long long i = 2; i <= m; ++i) s1[i] ^= s1[i - 1], s2[i] ^= s2[i - 1]; n   for (long long i = 1; i <= m; ++i) { n     l1[i] = s1[i - 1] ^ R1[i], r1[i] = s1[i] ^ L1[i]; n     l2[i] = s2[i - 1] ^ R2[i], r2[i] = s2[i] ^ L2[i]; n   } n   for (long long i = m; i >= 1; --i) { n     t[(node){r1[i], r2[i]}] += 1; n     q[(node){r1[i], r2[i]}] += i; n     long long x_1 = sum1 ^ l1[i], x_2 = sum2 ^ l2[i]; n     ans += q[(node){x_1, x_2}] - 1ll * t[(node){x_1, x_2}] * (i - 1); n   } n   for (long long i = 1; i <= m; ++i) a[i] += a[i - 1]; n   long long x = 0; n   for (long long i = 1; i <= m; ++i) { n     if (a[i] == 0) n       ++x; n     else n       x = 0; n     if (x) n       if (i == m || a[i + 1] != 0) n         for (long long j = 1; j <= x; ++j) ans -= 1ll * j * (x - j + 1); n   } n   write(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void RI() {} n template <typename... T> n void RI(int& head, T&... tail) { n   scanf( %d , &head); n   RI(tail...); n } n template <typename T> n void _dump(const char* s, T&& head) { n   cerr << s <<  =  << head << endl; n } n template <typename T, typename... Args> n void _dump(const char* s, T&& head, Args&&... tail) { n   int c = 0; n   while (*s !=  ,  || c != 0) { n     if (*s ==  (  || *s ==  [  || *s ==  { ) c++; n     if (*s ==  )  || *s ==  ]  || *s ==  } ) c--; n     cerr << *s++; n   } n   cerr <<  =  << head <<  ,  ; n   _dump(s + 1, tail...); n } n template <typename Iter> n ostream& _out(ostream& s, Iter b, Iter e) { n   s <<  [ ; n   for (auto it = b; it != e; it++) s << (it == b ?    :    ) << *it; n   s <<  ] ; n   return s; n } n template <typename A, typename B> n ostream& operator<<(ostream& s, const pair<A, B>& p) { n   return s <<  (  << p.first <<  ,  << p.second <<  ) ; n } n template <typename T> n ostream& operator<<(ostream& s, const vector<T>& c) { n   return _out(s, begin(c), end(c)); n } n template <typename T> n ostream& operator<<(ostream& s, const set<T>& c) { n   return _out(s, begin(c), end(c)); n } n template <typename A, typename B> n ostream& operator<<(ostream& s, const map<A, B>& c) { n   return _out(s, begin(c), end(c)); n } n vector<int> app[1000010]; n int ask(int l, int r, int v) { n   auto it = lower_bound(begin(app[v]), end(app[v]), l); n   auto jt = upper_bound(begin(app[v]), end(app[v]), r); n   return jt - it; n } n int n, m, a[300010], sa[300010], ord[300010], l[300010], r[300010]; n bool vis[300010]; n bool cmp(int x, int y) { return a[x] < a[y]; } n long long calc(int l1, int r1, int l2, int r2, int mx) { n   long long ans = 0; n   mx %= m; n   if (r1 - l1 <= r2 - l2) { n     for (int i = (l1 - 1); i <= int(r1 - 1); i++) { n       int x = sa[i] + mx; n       if (x >= m) x -= m; n       int now = ask(l2, r2, x); n       ans += now; n     } n   } else { n     for (int i = (l2); i <= int(r2); i++) { n       int x = sa[i] - mx; n       if (x < 0) x += m; n       int now = ask(l1 - 1, r1 - 1, x); n       ans += now; n     } n   } n   return ans; n } n int main() { n   RI(n, m); n   for (int i = (1); i <= int(n); i++) RI(a[i]); n   for (int i = (1); i <= int(n); i++) l[i] = r[i] = i; n   for (int i = (1); i <= int(n); i++) ord[i] = i; n   for (int i = (1); i <= int(n); i++) sa[i] = (sa[i - 1] + a[i]) % m; n   for (int i = (0); i <= int(n); i++) app[sa[i]].push_back(i); n   sort(ord + 1, ord + n + 1, cmp); n   long long ans = 0; n   for (int ii = (1); ii <= int(n); ii++) { n     int i = ord[ii]; n     vis[i] = 1; n     if (i > 1 && vis[i - 1]) { n       ans += calc(l[i - 1], i - 1, i, i, a[i]); n       l[i] = l[i - 1]; n       r[l[i - 1]] = i; n     } n     if (i < n && vis[i + 1]) { n       ans += calc(l[i], i, i + 1, r[i + 1], a[i]); n       r[l[i]] = r[i + 1]; n       l[r[i + 1]] = l[i]; n     } n   } n   cout << ans << endl; 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 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++) cin >> b[i]; n   for (int i = 1; i <= m; i++) cin >> p[i]; n   sort(b + 1, b + n + 1); n   sort(p + 1, p + m + 1); n   int le = -1, ri = min(n, m) + 1; n   while (le + 1 < ri) { n     int mi = (le + ri) / 2; n     long long cnt = 0; n     for (int i = 1; i <= mi; i++) { n       cnt += max(0LL, p[mi + 1 - i] - b[n + 1 - i]); n     } n     if (cnt > a) { n       ri = mi; n     } else { n       le = 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 int n, a[100000], outpalsz, inn, b[100000]; n long long result; n int inicount[100001], iniodd; n int ccount[100001], codd; n int main() { n   cin.sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n - 1 - i && a[i] == a[n - 1 - i]; i++) outpalsz++; n   for (int i = outpalsz; i < n - outpalsz; i++) { n     inicount[a[i]]++; n     if (inicount[a[i]] % 2) n       iniodd++; n     else n       iniodd--; n     b[inn++] = a[i]; n   } n   if (inn <= 1) { n     cout << 1LL * n * (n + 1) / 2 <<   n ; n     return 0; n   } n   if (iniodd <= 1) result = 1LL * (outpalsz + 1) * (outpalsz + 1); n   for (int i = 0; i <= 100000; i++) ccount[i] = inicount[i]; n   codd = iniodd; n   for (int i = 0; i < inn; i++) { n     ccount[b[i]] -= 2; n     if (i * 2 + 1 == inn) ccount[b[i]]++; n     if (i > inn - 1 - i && b[i] == b[inn - 1 - i]) ccount[b[i]] += 2; n     if (ccount[b[i]] < 0) break; n     if (codd <= 1) result += outpalsz + 1; n   } n   for (int i = 0; i <= 100000; i++) ccount[i] = inicount[i]; n   codd = iniodd; n   for (int i = inn - 1; i >= 0; i--) { n     ccount[b[i]] -= 2; n     if (i * 2 + 1 == inn) ccount[b[i]]++; n     if (i < inn - 1 - i && b[i] == b[inn - 1 - i]) ccount[b[i]] += 2; n     if (ccount[b[i]] < 0) break; n     if (codd <= 1) result += outpalsz + 1; n   } n   cout << result <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long get(string a) { n   long long len = a.length(); n   long long b = 0; n   long long cnt = 1; n   for (int i = len - 1; i >= 0; i--) { n     b += ((a[i] -  0 ) % 2) * cnt; n     cnt *= 2; n   } n   return b; n } n int p[262150]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     char c; n     cin >> c; n     string a; n     cin >> a; n     long long b = get(a); n     switch (c) { n       case  + : { n         p[b]++; n         break; n       } n       case  - : { n         p[b]--; n         break; n       } n       case  ? : { n         cout << p[b] << endl; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int INF = (int)1e9; n const long long LINF = (long long)1e18; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n template <class T> n inline int chkmin(T& a, const T& val) { n   return val < a ? a = val, 1 : 0; n } n template <class T> n inline int chkmax(T& a, const T& val) { n   return a < val ? a = val, 1 : 0; n } n template <class T> n inline T isqrt(T k) { n   T r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n template <class T> n inline T icbrt(T k) { n   T r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n const int maxn = 2000 + 10; n const int maxm = 500000 + 10; n int n, m; n int a[maxm]; n int b[maxm]; n bitset<maxn << 1> mat[maxn]; n void solve() { n   cin >> n >> m; n   for (int i = (0); i < (m); i++) { n     cin >> a[i] >> b[i], a[i]--, b[i]--; n     mat[b[i]][a[i]] = 1; n   } n   for (int i = (0); i < (n); i++) n     for (int j = (0); j < (n); j++) mat[i][j + n] = i == j; n   for (int i = (0); i < (n); i++) { n     if (!mat[i][i]) { n       for (int j = (i + 1); j < (n); j++) n         if (mat[j][i]) { n           mat[i] ^= mat[j]; n           break; n         } n     } n     for (int j = (0); j < (n); j++) { n       if (j == i) continue; n       if (mat[j][i]) { n         mat[j] ^= mat[i]; n       } n     } n   } n   for (int i = (0); i < (m); i++) { n     if (!mat[a[i]][b[i] + n]) { n       cout <<  YES n ; n     } else { n       cout <<  NO n ; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string str; n   cin >> str; n   int ans(0); n   for (int i = 0; i < str.size(); ++i) n     if (str[i] != str[str.size() - 1 - i]) ++ans; n   if (ans == 2 || (ans == 0 && str.size() % 2 == 1)) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n int main() { n   srand(1373737); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, t, k, d, q; n   cin >> n >> q; n   vector<int> arr(n); n   for (int i = 0; i < (int)q; i++) { n     cin >> t >> k >> d; n     int free = 0; n     for (int j = 0; j < (int)n; j++) { n       if (arr[j] <= t) free++; n     } n     if (free < k) { n       cout << -1 <<   n ; n       continue; n     } n     int res = 0; n     for (int j = 0; j < n && k; j++) { n       if (arr[j] <= t) { n         arr[j] = t + d; n         k--; n         res += j + 1; n       } n     } n     cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool uin(T& a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n inline bool uax(T& a, T b) { n   return a < b ? (a = b, true) : false; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long N, K; n   cin >> N >> K; n   if (K == 1) { n     cout << N <<   n ; n     return 0; n   } n   string be, en; n   cin >> be >> en; n   long long ans = 0, cur = 1; n   for (int i = 0; i < N; ++i) { n     cur *= 2LL; n     if (be[i] ==  b ) --cur; n     if (en[i] ==  a ) --cur; n     uin(cur, K); n     ans += cur; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( O2 ) n #pragma GCC optimize( unroll-loops ) n struct POINT { n   int x, y; n   POINT() : x(0), y(0) {} n   POINT(int x, int y) : x(x), y(y) {} n   POINT operator+(const POINT &t) const { return POINT(x + t.x, y + t.y); } n   POINT operator-(const POINT &t) const { return POINT(x - t.x, y - t.y); } n   POINT operator!() const { return POINT(-y, x); } n }; n inline long long dot(const POINT &a, const POINT &b) { n   return (long long)a.x * b.x + (long long)a.y * b.y; n } n inline long long cross(const POINT &a, const POINT &b) { n   return (long long)a.x * b.y - (long long)a.y * b.x; n } n inline long long cross(const POINT &a, const POINT &b, const POINT &c) { n   return cross(a - c, b - c); n } n inline bool halfPlane(const POINT &p) { n   if (p.y == 0) return p.x < 0; n   return p.y < 0; n } n inline bool angSortCmp(const POINT &a, const POINT &b) { n   bool ha = halfPlane(a); n   bool hb = halfPlane(b); n   if (ha != hb) return ha < hb; n   return cross(a, b) > 0; n } n const int N = 2000; n int n; n long long S; n POINT tab[N + 7]; n int poz[N + 7]; n POINT stab[N + 7]; n struct kierunek { n   POINT wek; n   int p, q; n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> S; n   S *= 2; n   for (int i = 1; i <= n; ++i) cin >> tab[i].x >> tab[i].y; n   sort(tab + 1, tab + n + 1, [](const POINT &a, const POINT &b) -> bool { n     if (a.x == b.x) return a.y > b.y; n     return a.x < b.x; n   }); n   for (int i = 1; i <= n; ++i) { n     poz[i] = i; n     stab[i] = tab[i]; n   } n   vector<kierunek> kol((n * (n - 1)) / 2); n   int it = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = i + 1; j <= n; ++j) { n       kol[it].wek = !(tab[j] - tab[i]); n       kol[it].p = i; n       kol[it].q = j; n       it++; n     } n   } n   sort(kol.begin(), kol.end(), n        [](const kierunek &a, const kierunek &b) -> bool { n          return angSortCmp(a.wek, b.wek); n        }); n   for (kierunek u : kol) { n     int p = u.p; n     int q = u.q; n     swap(stab[poz[p]], stab[poz[q]]); n     swap(poz[p], poz[q]); n     int l = 1; n     int r = n; n     while (l <= r) { n       int s = (l + r) / 2; n       long long ww = cross(tab[q], stab[s], tab[p]); n       if (ww == S) { n         cout <<  Yes  << endl; n         cout << tab[p].x <<     << tab[p].y << endl; n         cout << tab[q].x <<     << tab[q].y << endl; n         cout << stab[s].x <<     << stab[s].y << endl; n         exit(0); n       } n       if (ww > S) n         r = s - 1; n       else n         l = s + 1; n     } n     l = 1; n     r = n; n     while (l <= r) { n       int s = (l + r) / 2; n       long long ww = cross(tab[q], stab[s], tab[p]); n       if (ww == -S) { n         cout <<  Yes  << endl; n         cout << tab[p].x <<     << tab[p].y << endl; n         cout << tab[q].x <<     << tab[q].y << endl; n         cout << stab[s].x <<     << stab[s].y << endl; n         exit(0); n       } n       if (ww > -S) n         r = s - 1; n       else n         l = s + 1; n     } n   } n   cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   int i, j, n, m, k, l, r; n   cin >> n >> m; n   int a[n][m]; n   pair<int, int> start_end[n][m]; n   for (i = 0; i < n; i += 1) n     for (j = 0; j < m; j += 1) { n       cin >> a[i][j]; n       start_end[i][j].first = i; n       start_end[i][j].second = i; n     } n   for (j = 0; j < m; j += 1) n     for (i = 1; i < n; i += 1) n       if (a[i][j] >= a[i - 1][j]) n         start_end[i][j].first = start_end[i - 1][j].first; n   int min_l[n]; n   for (i = 0; i < n; i++) min_l[i] = 100010; n   for (i = 0; i < n; i += 1) n     for (j = 0; j < m; j += 1) n       if (start_end[i][j].first < min_l[i]) min_l[i] = start_end[i][j].first; n   cin >> k; n   while (k--) { n     cin >> l >> r; n     cout << ((min_l[r - 1] <= l - 1) ?  Yes n  :  No n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void read(T &x) { n   x = 0; n   char ch = getchar(); n   long long fh = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) fh = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   x *= fh; n } n template <typename T> n void write(T x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n template <typename T> n void writeln(T x) { n   write(x); n   puts(  ); n } n long long n, a[100005]; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     cin >> n; n     for (long long i = 1; i <= n; i++) cin >> a[i]; n     long long x = 0; n     for (long long i = n; i >= 1; i--) n       if (a[i] < 0) n         x += -a[i]; n       else if (x >= a[i]) n         x -= a[i]; n       else n         x = 0; n     cout << x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m, h; n   cin >> n >> m >> h; n   vector<int> ms(m), ns(n); n   vector<vector<int> > ok(n, vector<int>(m)); n   for (int i = 0; i < m; i++) { n     cin >> ms[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> ns[i]; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> ok[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (ok[i][j] == 0) { n         cout << 0 <<    ; n       } else { n         cout << min(ms[j], ns[i]) <<    ; n       } n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int r, g, j, f[200001], sc, kq, mod = round(1e9) + 7; n long long i, h; n int main() { n   cin >> r >> g; n   f[0] = 1; n   for (i = 1; i * (i + 1) / 2 <= r + g; i++) { n     for (j = r; j >= 0; j--) { n       if (j >= i) f[j] = (f[j] + f[j - i]) % mod; n     } n   } n   h = i - 1; n   for (i = 0; i <= r; i++) n     if (h * (h + 1) / 2 - i <= g) kq = (kq + f[i]) % mod; n   cout << kq; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 7; n vector<pair<int, int> > s; n int co[maxn], deg[maxn]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     pair<int, int> q; n     cin >> q.first >> q.second; n     s.push_back(q); n   } n   for (int i = 1; i <= n; i++) { n     cin >> co[i]; n   } n   int x = 0; n   for (auto i : s) { n     if (co[i.first] != co[i.second]) { n       deg[i.first]++; n       deg[i.second]++; n       x++; n     } n   } n   int flag = 0; n   for (int i = 1; i <= n; i++) { n     if (deg[i] == x) { n       flag = i; n     } n   } n   if (flag) { n     printf( YES n%d n , flag); n   } else { n     printf( NO n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, k, kol = 0; n   cin >> n >> k; n   string s; n   cin >> s; n   vector<long long> a(n); n   for (long long i = 0; i < n; i++) { n     a[i] = s[i] -  0 ; n   } n   for (long long i = 0; i < n - 1 && k; i++) { n     if (a[i] == 4 && a[i + 1] == 7) { n       if (i % 2 == 0) { n         a[i + 1] = 4; n         k--; n       } else { n         if (i > 0 && a[i - 1] == 4) { n           if (k % 2 == 1) { n             a[i] = 7; n           } n           break; n         } n         a[i] = a[i + 1] = 7; n         k--; n       } n     } n   } n   for (long long i = 0; i < n; i++) { n     cout << a[i]; n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int n, l; n long long a[300000][3]; n long long b[300000][3]; n long long t[300000][2]; n vector<int> c[3000000]; n vector<pair<long long, long long> > g; n long long p[3000000]; n long long dab[3000000][2]; n void sayno() { n   printf( NO ); n   exit(0); n } n void calc() { n   int i, j, k; n   long long d = -1; n   for (i = 0; i < l; i++) { n     if (c[i].size() >= 2) { n       d = (t[c[i][1]][1] - t[c[i][0]][1]) / n           ((t[c[i][1]][0] - t[c[i][0]][0]) / l); n       break; n     } n   } n   if (d == -1) { n     int past = 0; n     g.clear(); n     for (i = 1; i <= l; i++) { n       if (!c[i % l].size()) continue; n       int x = c[past][0], y = c[i % l][0]; n       if (t[x][0] < t[y][0]) { n         long long u = (t[y][0] - t[x][0]) / l; n         long long v = t[y][1] - t[x][1]; n         long long w = (t[y][0] - t[x][0]) % l; n         if (u != 0) n           g.push_back(pair<long long, long long>((v - w + u - 1) / u, v / u)); n       } else { n         long long u = (t[x][0] - t[y][0]) / l + 1; n         long long v = t[x][1] - t[y][1]; n         long long w = t[y][0] + u * l - t[x][0]; n         if (u != 0) n           g.push_back(pair<long long, long long>((v + u - 1) / u, (v + w) / u)); n       } n       past = i; n     } n     sort(g.begin(), g.end()); n     for (auto e : g) { n       if (e.second < g.back().first) sayno(); n     } n     d = g.back().first; n   } n   memset(p, -1, sizeof(p)); n   for (i = 0; i < n; i++) { n     long long u = t[i][1] - d * (t[i][0] / l); n     long long v = t[i][0] % l; n     if (p[v] == -1) n       p[v] = u; n     else if (p[v] != u) n       sayno(); n   } n   p[l] = d; n   int past = 0; n   for (i = 1; i <= l; i++) { n     if (p[i] == -1) continue; n     if (p[i] - p[past] < 0 || p[i] - p[past] > i - past) sayno(); n     for (j = 0; j < p[i] - p[past]; j++) { n       dab[past + j][1] = 1; n     } n     for (j = p[i] - p[past]; j < i - past; j++) { n       dab[past + j][1] = -1; n     } n     past = i; n   } n } n int main() { n   int i, j, k; n   cin >> n >> l; n   for (i = 0; i <= n; i++) { n     if (i != 0) scanf( %I64d%I64d%I64d , &a[i][0], &a[i][1], &a[i][2]); n     b[i][0] = a[i][0], b[i][1] = a[i][1] + a[i][2], b[i][2] = a[i][1] - a[i][2]; n     if ((b[i][1] + b[i][0]) % 2 == 1 || (b[i][2] + b[i][0]) % 2 == 1) sayno(); n     b[i][1] = (b[i][1] + b[i][0]) / 2, b[i][2] = (b[i][2] + b[i][0]) / 2; n     c[b[i][0] % l].push_back(i); n   } n   n++; n   for (i = 0; i < n; i++) t[i][0] = b[i][0], t[i][1] = b[i][1]; n   calc(); n   for (i = 0; i < l; i++) dab[i][0] = dab[i][1]; n   for (i = 0; i < n; i++) t[i][0] = b[i][0], t[i][1] = b[i][2]; n   calc(); n   for (i = 0; i < l; i++) { n     if (dab[i][0] == -1 & dab[i][1] == -1) n       printf( L ); n     else if (dab[i][0] == 1 && dab[i][1] == 1) n       printf( R ); n     else if (dab[i][0] == -1 && dab[i][1] == 1) n       printf( D ); n     else n       printf( U ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<long long> > matmul(vector<vector<long long> > &a, n                                   vector<vector<long long> > &b) { n   int i, j, k, n = a.size(); n   vector<vector<long long> > ans(n, vector<long long>(n)); n   for (i = 0; i < n; i++) n     for (j = 0; j < n; j++) { n       long long temp = 0; n       for (k = 0; k < n; k++) n         temp = (temp + a[i][k] * b[k][j]) % (1000000007LL); n       ans[i][j] = temp; n     } n   return ans; n } n vector<vector<long long> > matpwr(vector<vector<long long> > &a, long long p) { n   int n = a.size(); n   vector<vector<long long> > ans(n, vector<long long>(n)); n   for (int i = 0; i < n; i++) ans[i][i] = 1; n   while (p) { n     if (p & 1) ans = matmul(ans, a); n     a = matmul(a, a); n     p >>= 1; n   } n   return ans; n } n long long pwr(long long base, long long p, long long mod = (1000000007LL)) { n   long long ans = 1; n   while (p) { n     if (p & 1) ans = (ans * base) % mod; n     base = (base * base) % mod; n     p /= 2; n   } n   return ans; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long invMod(long long n, long long mod = (1000000007LL)) { n   return pwr(n, mod - 2); n } n int n, arr[2000003]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; i++) arr[i] = i; n   int start = 1; n   for (int iter = 2; iter <= n; iter++) { n     int last = arr[start]; n     for (int j = start + iter; j < start + n; j += iter) { n       int temp = last; n       last = arr[j]; n       arr[j] = temp; n     } n     arr[start + n] = last; n     start++; n   } n   for (int i = start; i < start + n; i++) cout << arr[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[110], b[110], sum = 0; n pair<int, int> dp[110][11000], q = {-1, -1}; n pair<int, int> Rec(int i, int W) { n   if (i == n) { n     if (W >= sum) n       return {0, 0}; n     else n       return {1e9, 1e9}; n   } n   if (dp[i][W] != q) return dp[i][W]; n   pair<int, int> Res1 = {1e9, 1e9}, Res2 = {1e9, 1e9}; n   Res1 = {0 + Rec(i + 1, W).first, a[i] + Rec(i + 1, W).second}; n   Res2 = {1 + Rec(i + 1, W + b[i]).first, 0 + Rec(i + 1, W + b[i]).second}; n   return dp[i][W] = min(Res1, Res2); n } n int main() { n   memset(dp, -1, sizeof(dp)); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i], sum += a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   cout << Rec(0, 0).first <<     << Rec(0, 0).second; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[200005]; n int n; n int mem[200005][27]; n int dirr[200005][27]; n bool vis[200005][27]; n char other(char c, char d) { n   if ( a  != c &&  a  != d) return  a ; n   if ( b  != c &&  b  != d) return  b ; n   return  c ; n } n int solve(int ind, int lst) { n   if (ind >= n) return 0; n   if (vis[ind][lst]) return mem[ind][lst]; n   vis[ind][lst] = 1; n   int ans1 = -1, ans2 = -1, ans = -1, dir = -1; n   if (s[ind] -  a  != lst) ans1 = solve(ind + 1, s[ind] -  a ); n   ans2 = 1 + solve(ind + 1, other(s[ind + 1], lst +  a ) -  a ); n   if (ans1 == -1 || ans2 <= ans1) n     dir = 1, ans = ans2; n   else n     dir = 0, ans = ans1; n   dirr[ind][lst] = dir; n   return mem[ind][lst] = ans; n } n int main() { n   ios::sync_with_stdio(false); n   scanf( %s , s); n   n = strlen(s); n   solve(0, 26); n   int lst = 26; n   for (int i = 0; i < n; i++) n     if (dirr[i][lst] == 0) n       lst = s[i] -  a ; n     else n       s[i] = lst = other(s[i + 1], lst +  a ), lst -=  a ; n   puts(s); n   return 0; n } n