#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   scanf( %lld , &n); n   scanf( %lld , &k); n   long long a[k + 5], mn = -1, ans1, ans2, flag = 0; n   for (long long i = 1; i <= k; i++) { n     scanf( %lld , &a[i]); n     if (a[i] > n) { n       continue; n     } n     flag = 1; n     long long r = n % a[i]; n     if (mn == -1) { n       mn = r; n       ans1 = i; n       ans2 = n / a[i]; n       continue; n     } n     if (mn > r) { n       mn = r; n       ans1 = i; n       ans2 = n / a[i]; n     } n   } n   if (flag == 0) { n     cout <<  1 0 n ; n     return 0; n   } n   cout << ans1 <<     << ans2 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n vector<int> adj[N]; n int n, st[N], sz[N], flat[N], tim = 1; n int dfs(int u) { n   int s = 1; n   st[u] = tim; n   flat[tim] = u; n   for (int v : adj[u]) { n     tim++; n     s += dfs(v); n   } n   return sz[u] = s; n } n int main(int argc, char const *argv[]) { n   int q; n   cin >> n >> q; n   for (int i = 2; i <= n; ++i) { n     int p; n     cin >> p; n     adj[p].push_back(i); n   } n   for (int i = 1; i <= n; ++i) { n     sort(adj[i].begin(), adj[i].end()); n   } n   dfs(1); n   while (q--) { n     int u, k; n     cin >> u >> k; n     if (k > sz[u]) n       cout << -1 <<   n ; n     else n       cout << flat[st[u] + k - 1] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, d; n   cin >> n >> d; n   int in[n]; n   vector<pair<int, int>> c; n   in[0] = in[n - 1] = 0; n   for (int i = 1; i < n - 1; i++) cin >> in[i]; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     c.push_back({x, y}); n   } n   long long dis[n][n]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       dis[i][j] = n           d * (abs(c[i].first - c[j].first) + abs(c[i].second - c[j].second)); n       if (i != 0 && i != n - 1 && i != j) dis[i][j] -= in[i]; n     } n   } n   for (int k = 0; k < n; k++) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         if (dis[i][k] + dis[k][j] < dis[i][j]) n           dis[i][j] = dis[i][k] + dis[k][j]; n       } n     } n   } n   cout << dis[0][n - 1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int r, c, w; n char a[1005][1005]; n int rows[1005], columns[1005]; n int main() { n   scanf( %d%d , &r, &c); n   for (int i = 1; i <= r; i++) n     for (int j = 1; j <= c; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  * ) { n         w++; n         rows[i]++; n         columns[j]++; n       } n     } n   for (int i = 1; i <= r; i++) n     for (int j = 1; j <= c; j++) { n       if (rows[i] + columns[j] - (a[i][j] ==  * ) == w) { n         printf( YES n%d %d , i, j); n         return 0; n       } n     } n   printf( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n int n; n vector<int> id; n int a[N]; n int tr[N]; n int find(int u) { n   return lower_bound(id.begin(), id.end(), u) - id.begin() + 1; n } n int lowbit(int x) { return x & -x; } n void add(int x, int c) { n   for (int i = x; i <= n; i += lowbit(i)) tr[i] += c; n } n int sum(int x) { n   int res = 0; n   for (int i = x; i; i -= lowbit(i)) res += tr[i]; n   return res; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> n; n     id.clear(); n     memset(tr, 0, sizeof tr); n     for (int i = 0; i < n; i++) { n       scanf( %d , &a[i]); n       id.push_back(a[i]); n     } n     sort(id.begin(), id.end()); n     id.erase(unique(id.begin(), id.end()), id.end()); n     int tot = id.size(); n     long long res = 0; n     for (int i = 0; i < n; i++) { n       int id = find(a[i]); n       int q1 = sum(tot) - sum(id); n       int q2 = sum(id - 1); n       add(id, 1); n       res += (long long)min(q1, q2); n     } n     cout << res << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[110]; n int n, k; n double p[110]; n double dp[110][110]; n int was[110][110]; n double dist(pair<int, int> a, pair<int, int> b) { n   double x = a.first - b.first; n   double y = a.second - b.second; n   return sqrt(x * x + y * y); n } n double rec(int pos, int kol) { n   if (pos == n) { n     if (kol >= k) return 1; n     return 0; n   } n   if (was[pos][kol]) return dp[pos][kol]; n   was[pos][kol] = 1; n   double res = p[pos] * rec(pos + 1, kol + 1); n   res += (1 - p[pos]) * rec(pos + 1, kol); n   return dp[pos][kol] = res; n } n int main() { n   scanf( %d , &n); n   int x, y, e; n   scanf( %d%d , &k, &e); n   scanf( %d%d , &x, &y); n   e = 1000 - e; n   for (int i = (0); i < (n); ++i) scanf( %d%d , &a[i].first, &a[i].second); n   double l = 0, r = 1e40; n   double best = -1; n   for (int i = (0); i < (1000); ++i) { n     double m = (l + r) / 2; n     for (int i = (0); i < (n); ++i) { n       double d = dist(make_pair(x, y), a[i]); n       if (d <= m) n         p[i] = 1; n       else { n         double k = d * d / m / m; n         p[i] = exp(1.0 - k); n       } n     } n     memset(was, 0, sizeof(was)); n     double prob = rec(0, 0); n     if (prob * 1000 >= e) { n       best = m; n       r = m; n     } else n       l = m; n   } n   printf( %.10lf n , best); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int m; n struct st { n   int go; n   long long int a; n   long long int b; n   st() { n     go = -1; n     a = 0; n     b = 0; n   } n   st(int a_, long long int b_, long long int c_) { n     go = a_; n     a = b_; n     b = c_; n   } n }; n vector<st> v[300002]; n vector<st> g[300002]; n int lim; n st p[300002]; n inline void trans(int b, int pr = -1) { n   if (pr == -1) { n     lim = n; n   } n   for (int j = 0; j < v[b].size(); j++) { n     if (v[b][j].go == pr) continue; n     if (g[b].size() == 2) { n       swap(g[b], g[lim]); n       lim++; n       g[b].push_back({lim - 1, 0, 0}); n     } n     g[b].push_back(v[b][j]); n   } n   for (int j = 0; j < v[b].size(); j++) { n     if (v[b][j].go == pr) continue; n     trans(v[b][j].go, b); n   } n } n bool used[300002]; n int dp[300002]; n pair<int, int> cent(int b, int whole, int pr = -1) { n   pair<int, int> ret = make_pair(INT_MAX, -1); n   dp[b] = 1; n   int deg = 0; n   for (int i = 0; i < g[b].size(); i++) { n     int go = g[b][i].go; n     if (go == pr) continue; n     if (used[go]) continue; n     ret = min(ret, cent(go, whole, b)); n     dp[b] += dp[go]; n     deg = max(deg, dp[go]); n   } n   deg = max(deg, whole - dp[b]); n   ret = min(ret, make_pair(deg, b)); n   return ret; n } n struct line { n   long long int a; n   long long int b; n   line(long long int A = 0, long long int B = 0) { n     a = A; n     b = B; n   } n   long long int at(long long int x) { return a * x + b; } n }; n inline bool enu(int b, vector<line> &lis, int pr = -1, n                 line propagate = line()) { n   bool leaf = true; n   for (int i = 0; i < g[b].size(); i++) { n     int go = g[b][i].go; n     if (go == pr) continue; n     if (used[go]) continue; n     leaf = false; n     propagate.a += g[b][i].a; n     propagate.b += g[b][i].b; n     enu(go, lis, b, propagate); n     propagate.a -= g[b][i].a; n     propagate.b -= g[b][i].b; n   } n   if (leaf) lis.emplace_back(propagate); n   return true; n } n vector<line> all; n bool cmp(line a, line b) { n   if (a.a == b.a) { n     return a.b < b.b; n   } n   return a.a < b.a; n } n vector<line> v2; n void clean(vector<line> &v1) { n   v2.clear(); n   sort(v1.begin(), v1.end(), cmp); n   for (int i = 0; i < v1.size(); i++) { n     while (v2.size()) { n       if (v2.back().a == v1[i].a) { n         v2.pop_back(); n         continue; n       } n       if (v2.size() > 1) { n         auto a = v2[v2.size() - 2]; n         auto b = v2[v2.size() - 1]; n         auto c = v1[i]; n         if ((c.b - a.b) * (a.a - b.a) <= (b.b - a.b) * (a.a - c.a)) { n           v2.pop_back(); n           continue; n         } n       } n       break; n     } n     v2.push_back(v1[i]); n   } n   v1 = v2; n } n inline void init(int b) { n   cent(b, -1); n   b = cent(b, dp[b]).second; n   used[b] = true; n   vector<vector<line> > vv; n   for (int i = 0; i < g[b].size(); i++) { n     if (used[g[b][i].go]) continue; n     vv.push_back(vector<line>()); n     if (!enu(g[b][i].go, vv.back(), b, line(g[b][i].a, g[b][i].b))) n       vv.pop_back(); n   } n   while (1) { n     if (vv.size() == 0) break; n     if (vv.size() == 1) { n       for (auto el : vv[0]) { n         all.push_back(el); n       } n       vv.clear(); n       break; n     } n     for (int i = 0; i < vv.size(); i++) { n       clean(vv[i]); n     } n     for (int i1 = 0; i1 < vv.size(); i1++) { n       for (int j1 = i1 + 1; j1 < vv.size(); j1++) { n         int i = 0; n         int j = 0; n         while (i < vv[i1].size() && j < vv[j1].size()) { n           all.push_back( n               line(vv[i1][i].a + vv[j1][j].a, vv[i1][i].b + vv[j1][j].b)); n           if (i == vv[i1].size() - 1 && j == vv[j1].size() - 1) break; n           if (i == vv[i1].size() - 1) { n             j++; n             continue; n           } n           if (j == vv[j1].size() - 1) { n             i++; n             continue; n           } n           if (vv[i1][i].a == vv[i1][i + 1].a) { n             i++; n             continue; n           } n           if (vv[j1][j].a == vv[j1][j + 1].a) { n             j++; n             continue; n           } n           if ((vv[i1][i + 1].b - vv[i1][i].b) * n                   (vv[j1][j].a - vv[j1][j + 1].a) <= n               (vv[i1][i].a - vv[i1][i + 1].a) * n                   (vv[j1][j + 1].b - vv[j1][j].b)) { n             i++; n           } else { n             j++; n           } n         } n       } n     } n     break; n   } n   for (int i = 0; i < g[b].size(); i++) { n     if (used[g[b][i].go] == false) { n       init(g[b][i].go); n     } n   } n } n int main() { n   cin >> n >> m; n   for (int i = 1; i < n; i++) { n     int a, b; n     long long int c, d; n     scanf( %d%d%lld%lld , &a, &b, &c, &d); n     a--; n     b--; n     v[a].push_back(st(b, c, d)); n     v[b].push_back(st(a, c, d)); n   } n   trans(0); n   n = lim; n   for (int i = 0; i < n; i++) p[i].go = -1; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < g[i].size(); j++) { n       p[g[i][j].go] = g[i][j]; n       p[g[i][j].go].go = i; n     } n   } n   for (int i = 0; i < n; i++) { n     if (p[i].go == -1) continue; n     g[i].push_back(p[i]); n   } n   init(0); n   int idx = 0; n   all.push_back(line()); n   clean(all); n   for (int t = 0; t <= m - 1; t++) { n     if (t) { n       printf(   ); n     } n     long long int mx = 0; n     int pos = -1; n     while (idx + 1 < all.size() && all[idx].at(t) <= all[idx + 1].at(t)) { n       idx++; n     } n     printf( %lld , all[idx].at(t)); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300500; n int T[N], L[N], C[N]; n int m; n int len = 0; n const int inf = 100500; n int A[N]; n int fs = -1, pos = -1; n void apply() { n   for (int i = 0; i < m; i++) { n     if (i == m - 1) { n       pos = len; n       fs = m - 1; n       goto end; n     } n     if (T[i] == 1) { n       A[len++] = L[i]; n       if (len >= inf) { n         fs = i + 1; n         pos = len; n         goto end; n       } n     } else { n       assert(L[i] <= len); n       for (int q = 0; q < C[i]; q++) { n         for (int j = 0; j < L[i]; j++) { n           A[len++] = A[j]; n         } n         if (len >= inf) { n           for (int u = m - 1; u >= i; u--) n             T[u + 1] = T[u], L[u + 1] = L[u], C[u + 1] = C[u]; n           ++m; n           C[i + 1] = C[i] - q - 1; n           C[i] = q + 1; n           fs = i + 1; n           pos = len; n           goto end; n         } n       } n     } n   } n end:; n } n inline int blen(int o) { n   if (T[o] == 1) n     return 1; n   else n     return L[o] * C[o]; n } n int main() { n   scanf( %d , &m); n   for (int i = 0; i < m; i++) { n     scanf( %d , &T[i]); n     if (T[i] == 1) n       scanf( %d , &L[i]); n     else n       scanf( %d %d , &L[i], &C[i]); n   } n   T[m] = 0; n   L[m] = -42; n   m++; n   apply(); n   int n; n   scanf( %d , &n); n   int curg = fs; n   long long l = pos, r = pos + blen(fs); n   for (int i = 0; i < n; i++) { n     long long x; n     scanf( %I64d , &x); n     --x; n     int ans = -1; n     if (x < len) n       ans = A[(int)x]; n     else { n       while (r <= x && curg < m - 1) l = r, r += blen(++curg); n       assert(l <= x && x < r); n       if (T[curg] == 1) n         ans = L[curg]; n       else n         ans = A[(x - l) % L[curg]]; n     } n     printf( %d%c , ans,    n [i + 1 == n]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   string s1, s2, s3; n   cin >> t; n   map<string, int> mp; n   mp[ polycarp ] = 1; n   while (t--) { n     cin >> s1 >> s2 >> s3; n     transform(s1.begin(), s1.end(), s1.begin(), ::tolower); n     transform(s3.begin(), s3.end(), s3.begin(), ::tolower); n     mp[s1] = mp[s3] + 1; n   } n   map<string, int>::iterator it; n   int ans = 0; n   for (it = mp.begin(); it != mp.end(); ++it) n     if (it->second > ans) ans = it->second; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int vp, vd, t, f, c, ans = 0; n   double tempt; n   double curs = 0; n   cin >> vp >> vd >> t >> f >> c; n   curs = vp * t; n   if (vp >= vd) { n     cout << 0 << endl; n     return 0; n   } n   while (curs < c) { n     tempt = curs / (vd - vp); n     curs += tempt * vp; n     if (curs >= c) n       break; n     else n       curs += (tempt + f) * vp; n     ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const long long INFL = 1e18 + 123; n const double PI = atan2(0, -1); n mt19937 tw(960172); n long long rnd(long long x, long long y) { n   static uniform_int_distribution<long long> d; n   return d(tw) % (y - x + 1) + x; n } n bool check(string s) { n   string tmp = s; n   reverse(tmp.begin(), tmp.end()); n   return tmp != s; n } n void solve() { n   string s; n   cin >> s; n   int ans = 0; n   for (int i = 0; i < ((int)(s).size()); ++i) { n     string cur =   ; n     for (int j = i; j < ((int)(s).size()); ++j) { n       cur += s[j]; n       if (check(cur)) { n         ans = max(ans, j - i + 1); n       } n     } n   } n   cout << ans <<   n ; n } n int main() { n   cerr << fixed << setprecision(15); n   cout << fixed << setprecision(15); n   ios::sync_with_stdio(false); n   int tests = 1; n   for (int it = 1; it <= tests; ++it) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   int n; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> n; n     int arr[2 * n]; n     for (int j = 0; j < 2 * n; j++) { n       cin >> arr[j]; n     } n     sort(arr, arr + 2 * n); n     vector<int> left, right; n     for (int j = 0; j < 2 * n; j++) { n       if (j == 2 * n - 1) { n         if (n % 2 == 0) { n           if (j % 2 != 0) n             left.push_back(arr[j]); n           else n             right.push_back(arr[j]); n         } else { n           if (j % 2 == 0) n             left.push_back(arr[j]); n           else n             right.push_back(arr[j]); n         } n       } else { n         if (j % 2 == 0) n           left.push_back(arr[j]); n         else n           right.push_back(arr[j]); n       } n     } n     cout << abs(left[left.size() / 2] - right[right.size() / 2]) <<   n ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q, n, x, y, f1, f2, f3, f4; n   cin >> q; n   for (int i = 0; i < q; ++i) { n     cin >> n; n     int minx = -100000, miny = -100000, maxx = 100000, maxy = 100000; n     for (int o = 0; o < n; ++o) { n       cin >> x >> y >> f1 >> f2 >> f3 >> f4; n       if (f1 == 0 && minx < x) { n         minx = x; n       } n       if (f2 == 0 && maxy > y) { n         maxy = y; n       } n       if (f3 == 0 && maxx > x) { n         maxx = x; n       } n       if (f4 == 0 && miny < y) { n         miny = y; n       } n     } n     if (minx > maxx || miny > maxy) { n       cout << 0 << endl; n     } else { n       cout << 1 <<     << minx <<     << miny << endl; n     } n   } n   cin >> n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long a, b; n     cin >> a >> b; n     int tmp = b + 1; n     long long len = -1; n     while (tmp != 0) { n       tmp /= 10; n       len++; n     } n     long long ans = a * len; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bitset<7000> bit; n int main() { n   int n, count = 0; n   cin >> n; n   while (n--) { n     int int1, int2; n     string stars; n     cin >> int1 >> int2; n     if (n >= 1) cin >> stars; n     int a = int1 / 10, b = int1 % 10, c = int2 % 10, d = int2 / 10; n     int i1 = 1000 * a + 100 * b + 10 * c + d, n         i2 = 1000 * d + 100 * a + 10 * b + c, n         i3 = 1000 * c + 100 * d + 10 * a + b, n         i4 = 1000 * b + 100 * c + 10 * d + a; n     if (!bit[i1] && !bit[i2] && !bit[i3] && !bit[i4]) { n       count++; n       bit.set(i1); n       bit.set(i2); n       bit.set(i3); n       bit.set(i4); n     } n   } n   cout << count << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = (int)3e5, maxM = (int)2e3, intMax = INT_MAX, n           maxValue = (int)1e4, intInf = (int)1e9, mod = (int)1e9 + 7, www = 97; n const long long llmax = LLONG_MAX, INF = (long long)1e9 + 1; n long long nod(long long a, long long b) { n   while (a != 0 && b != 0) { n     if (a < b) n       b %= a; n     else n       a %= b; n   } n   return a + b; n } n int nod(int a, int b) { n   while (a != 0 && b != 0) { n     if (a < b) n       b %= a; n     else n       a %= b; n   } n   return a + b; n } n long long nok(long long a, long long b) { return a * b / nod(a, b); } n int nok(int a, int b) { return a * b / nod(a, b); } n long long modPlus(long long a, long long b) { n   return ((a % mod) + (b % mod)) % mod; n } n int modPlus(int a, int b) { return ((a % mod) + (b % mod)) % mod; } n long long binPow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b % 2 == 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n double binPow(double a, long long b) { n   double res = 1; n   while (b) { n     if (b % 2 == 1) { n       res *= a; n       while (res >= mod) res -= mod; n     } n     a *= a; n     while (a >= mod) a -= mod; n     b >>= 1; n   } n   return res; n } n long long mulmod(long long a, long long b) { n   long long res = 0; n   a = a % mod; n   while (b > 0) { n     if (b % 2 == 1) res = (res + a) % mod; n     a = (a * 2) % mod; n     b /= 2; n   } n   return res % mod; n } n pair<int, int> max(pair<int, int> a, pair<int, int> b) { n   if (a.first > b.first) return a; n   if (a.first < b.first) return b; n   if (a.second > b.second) return a; n   return b; n } n pair<int, int> min(pair<int, int> a, pair<int, int> b) { n   if (a.first < b.first) return a; n   if (a.first != b.first) return b; n   if (a.second < b.second) return a; n   return b; n } n int n, k, Q[4][maxN]; n vector<tuple<int, int, int> > res; n int main() { n   scanf( %d%d , &n, &k); n   int x = -1, y = -1; n   int count = 0; n   for (int i = 0; i < 4; ++i) { n     for (int j = 0; j < n; ++j) { n       scanf( %d , &Q[i][j]); n       if (i && i < 3) { n         if (Q[i][j]) n           count++; n         else { n           x = j; n           y = i - 1; n         } n       } n       if ((i == 1 || i == 3) && Q[i - 1][j] == Q[i][j]) { n         x = j; n         if (i == 1) n           y = 0; n         else n           y = 1; n       } n     } n   } n   if (x == -1) { n     printf( %d n , -1); n     fflush(stdout); n     return 0; n   } n   while (count) { n     if (y) { n       if (Q[1 + y][x]) { n         res.emplace_back(Q[1 + y][x], 4, x + 1); n         Q[1 + y][x] = 0; n         count--; n       } else if (x) { n         if (Q[1 + y][x - 1] && Q[1 + y][x - 1] != Q[2 + y][x - 1]) { n           res.emplace_back(Q[1 + y][x - 1], 3, x + 1); n           Q[1 + y][x] = Q[1 + y][x - 1]; n           Q[1 + y][x - 1] = 0; n         } n         x--; n       } else { n         if (Q[1][0] && Q[1][0] != Q[0][0]) { n           res.emplace_back(Q[1][x], 3, 1); n           Q[2][0] = Q[1][0]; n           Q[1][0] = 0; n         } n         y = !y; n       } n     } else { n       if (Q[1 + y][x]) { n         res.emplace_back(Q[1 + y][x], 1, x + 1); n         Q[1 + y][x] = 0; n         count--; n       } else if (x < n - 1) { n         if (Q[1 + y][x + 1] && Q[1 + y][x + 1] != Q[0][x + 1]) { n           res.emplace_back(Q[1 + y][x + 1], 2, x + 1); n           Q[1 + y][x] = Q[1 + y][x + 1]; n           Q[1 + y][x + 1] = 0; n         } n         x++; n       } else { n         if (Q[2][n - 1] && Q[2][n - 1] != Q[3][n - 1]) { n           res.emplace_back(Q[2][n - 1], 2, n); n           Q[1][n - 1] = Q[2][n - 1]; n           Q[2][n - 1] = 0; n         } n         y = !y; n       } n     } n   } n   printf( %d n , (int)res.size()); n   fflush(stdout); n   int a, b, c; n   for (auto i : res) { n     tie(a, b, c) = i; n     printf( %d %d %d n , a, b, c); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   unsigned long long int n; n   scanf( %llu , &n); n   printf( %llu , (n / 2) + 1); n } n


#include <bits/stdc++.h> n using namespace std; n int cx[] = {-1, 0, 0, 1, -1, -1, 1, 1, 0}, n     cy[] = {0, -1, 1, 0, -1, 1, 1, -1, 0}; n int ingrid(int ii, int jj, int R, int C) { n   if (ii < 0 || jj < 0 || ii >= R || jj >= C) return 0; n   return 1; n } n int main() { n   long long n; n   cin >> n; n   long long maxx = -1, minn = (1LL << 60); n   for (int i = 1; i <= sqrt(n); i++) { n     long long a = i; n     if (n % a == 0) { n       long long c = n / a; n       for (int i = a; i <= sqrt(c); i++) { n         if (c % i == 0) { n           long long b = c / i; n           long long c = i; n           long long temp = (a + 1) * (b + 2) * (c + 2); n           minn = min(minn, temp); n           maxx = max(maxx, temp); n           temp = (b + 1) * (a + 2) * (c + 2); n           minn = min(minn, temp); n           maxx = max(maxx, temp); n           temp = (c + 1) * (a + 2) * (b + 2); n           minn = min(minn, temp); n           maxx = max(maxx, temp); n         } n       } n     } n   } n   cout << minn - n <<     << maxx - n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100100; n const int INF = ~0U >> 1; n int N, idx[MAXN]; n map<int, int> mp, o_cnt, ls; n map<int, vector<int> > rs; n int main() { n   scanf( %d , &N); n   int a; n   for (int i = 1; i <= N; ++i) { n     scanf( %d , &a); n     mp[a] = i; n   } n   int o = INF; n   for (int i = 1; i <= N; ++i) { n     scanf( %d , &a); n     a = idx[i] = mp[a]; n     if (i <= a) { n       o_cnt[ls[i] = a - i] += 1; n     } else { n       rs[i - a].push_back(i); n     } n     o = min(o, abs(a - i)); n   } n   printf( %d n , o); n   for (int i = 1; i < N; ++i) { n     if ((o_cnt[ls[i]] -= 1) == 0) { n       o_cnt.erase(o_cnt.find(ls[i])); n     } n     ls.erase(ls.find(i)); n     rs[N + i - idx[i]].push_back(i); n     if (rs.count(i)) { n       for (vector<int>::iterator it = rs[i].begin(); it != rs[i].end(); ++it) { n         o_cnt[ls[*it] = -i] += 1; n       } n       rs.erase(rs.find(i)); n     } n     o = o_cnt.size() ? o_cnt.begin()->first + i : INF; n     o = min(o, rs.size() ? rs.begin()->first - i : INF); n     printf( %d n , o); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string s, t; n   cin >> n >> s >> t; n   vector<int> a(n + 1); n   for (int i = 0; i < n; ++i) n     a[i] = (s[n - i - 1] -  a ) + (t[n - i - 1] -  a ); n   for (int i = 0; i < n; ++i) { n     if (a[i] >= 26) { n       ++a[i + 1]; n       a[i] -= 26; n     } n   } n   vector<int> b(n + 1); n   b[0] = a[0] / 2; n   for (int i = 1; i <= n; ++i) { n     b[i] = a[i] / 2; n     if (a[i] & 1) b[i - 1] += 13; n   } n   for (int i = n - 1; i >= 0; --i) cout << char( a  + b[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, k, l; n   cin >> n >> m >> k >> l; n   if (m > n || n - k < l) return cout << -1, 0; n   long long ans = k / m; n   k %= m; n   while (k > 0) { n     k -= m; n     ans++; n   } n   l += k; n   ans += (l + m - 1) / m; n   if (ans * m > n) return cout << -1, 0; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:16777216 ) n const string debug_line =  yolo ; n const long long linf = 1e15 + 5; n const int BLOCK = 330; n struct answerType { n   int val; n   vector<int> edges; n  n  public: n   answerType() { n     val = INT_MAX; n     edges.clear(); n   }; n   answerType(int _val, vector<int> _edges) { n     val = _val; n     edges = _edges; n   }; n   void reset() { n     val = 0; n     edges.clear(); n   } n }; n struct solve { n   bool visited[1010]; n   int component[1010]; n   int arr[1010]; n   bool isbridge[30010]; n   vector<pair<pair<int, int>, int> > Adj[1010]; n   queue<int> Q[1010]; n   int comp2[1010]; n   vector<int> tree[1010]; n   int P[1010][36]; n   int level1[1010]; n   vector<pair<pair<pair<int, int>, int>, int> > edges; n   int s; n   int t; n   int ignoreEdge; n   int n; n   int m; n   answerType answer; n   int comcount; n   int countPairNodes; n   map<pair<int, int>, int> mp1; n   vector<int> edgeList[30010]; n   int dfs_timer; n   solve() { n     s = -1; n     t = -1; n     ignoreEdge = -1; n     edges.clear(); n     n = -1; n     m = -1; n     countPairNodes = 0; n     comcount = 0; n     dfs_timer = 0; n   }; n   solve(int _s, int _t, int _ignoreEdge, n         vector<pair<pair<pair<int, int>, int>, int> > _edges, int _n, int _m) { n     s = _s; n     t = _t; n     n = _n; n     m = _m; n     countPairNodes = 0; n     comcount = 0; n     ignoreEdge = _ignoreEdge; n     edges = _edges; n     dfs_timer = 0; n     for (int(i) = (0); (i) < (n + 1); ++(i)) { n       Adj[i].clear(); n       visited[i] = false; n     } n     for (int(i) = (0); (i) < (m + 1); ++(i)) { n       isbridge[i] = false; n     } n     for (auto &(t1) : (edges)) { n       if (t1.second != ignoreEdge) { n         Adj[t1.first.first.first].push_back(make_pair( n             make_pair(t1.first.first.second, t1.first.second), t1.second)); n         Adj[t1.first.first.second].push_back(make_pair( n             make_pair(t1.first.first.first, t1.first.second), t1.second)); n       } n     } n     answer.val = INT_MAX; n     answer.edges.clear(); n   }; n  n  public: n   int DFS(int u, int p, int edge) { n     visited[u] = true; n     component[u] = comcount; n     arr[u] = dfs_timer++; n     int dbe = arr[u]; n     for (auto &(t1) : (Adj[u])) { n       if (!visited[t1.first.first] && t1.first.first != p) { n         dbe = min(dbe, DFS(t1.first.first, u, t1.second)); n       } else if (edge != t1.second) { n         dbe = min(dbe, arr[t1.first.first]); n       } n     } n     if (dbe == arr[u] && edge != -1) { n       isbridge[edge] = true; n     } n     return dbe; n   }; n   void DFS1(int u) { n     int curcmp = comcount; n     Q[curcmp].push(u); n     visited[u] = true; n     while (!Q[curcmp].empty()) { n       int v = Q[curcmp].front(); n       comp2[v] = curcmp; n       Q[curcmp].pop(); n       for (auto &(t1) : (Adj[v])) { n         if (visited[t1.first.first]) { n           continue; n         } else if (isbridge[t1.second]) { n           comcount++; n           tree[curcmp].push_back(comcount); n           tree[comcount].push_back(curcmp); n           DFS1(t1.first.first); n         } else { n           Q[curcmp].push(t1.first.first); n           visited[t1.first.first] = true; n         } n       } n     } n   }; n   void DFS2(int u, int p) { n     visited[u] = true; n     P[u][0] = p; n     level1[u] = level1[p] + 1; n     for (int(i) = (1); (i) < (35); ++(i)) { n       P[u][i] = P[P[u][i - 1]][i - 1]; n     } n     for (auto &(t1) : (tree[u])) { n       if (!visited[t1]) { n         DFS2(t1, u); n       } n     } n   }; n   int LCA(int u, int v) { n     if (level1[u] < level1[v]) { n       swap(u, v); n     } n     for (int(i) = (34); (i) > (-1); --(i)) { n       if (level1[P[u][i]] >= level1[v]) { n         u = P[u][i]; n       } n     } n     if (u == v) { n       return u; n     } n     for (int(i) = (34); (i) > (-1); --(i)) { n       if (P[u][i] != P[v][i]) { n         u = P[u][i]; n         v = P[v][i]; n       } n     } n     return P[u][0]; n   }; n   void fillListNodes(vector<pair<int, int> > &listNodes, int s, int t) { n     int lca = LCA(s, t); n     if (lca == s) { n       int currNode = t; n       while (currNode != lca) { n         listNodes.push_back(make_pair(currNode, P[currNode][0])); n         currNode = P[currNode][0]; n       } n     } else if (lca == t) { n       int currNode = s; n       while (currNode != lca) { n         listNodes.push_back(make_pair(currNode, P[currNode][0])); n         currNode = P[currNode][0]; n       } n     } else { n       int currNode = s; n       while (currNode != lca) { n         listNodes.push_back(make_pair(currNode, P[currNode][0])); n         currNode = P[currNode][0]; n       } n       currNode = t; n       while (currNode != lca) { n         listNodes.push_back(make_pair(currNode, P[currNode][0])); n         currNode = P[currNode][0]; n       } n     } n   }; n   void findAnswer() { n     memset(visited, 0, sizeof(visited)); n     for (int(i) = (1); (i) < (n + 1); ++(i)) { n       if (!visited[i]) { n         DFS(i, 0, -1); n         comcount++; n       } n     } n     memset(visited, 0, sizeof(visited)); n     for (int(i) = (1); (i) < (n + 1); ++(i)) { n       if (!visited[i]) { n         DFS1(i); n       } n     } n     memset(visited, 0, sizeof(visited)); n     for (int(i) = (1); (i) < (n + 1); ++(i)) { n       if (!visited[i]) { n         level1[i] = 0; n         DFS2(i, i); n       } n     } n     for (int(i) = (1); (i) < (n + 1); ++(i)) { n     } n     for (auto &(t1) : (edges)) { n       if (isbridge[t1.second]) { n         if (level1[comp2[t1.first.first.first]] < n             level1[comp2[t1.first.first.second]]) { n           swap(t1.first.first.first, t1.first.first.second); n         } n         if (mp1.count(make_pair(comp2[t1.first.first.first], n                                 comp2[t1.first.first.second])) == 0) { n           mp1[make_pair(comp2[t1.first.first.first], n                         comp2[t1.first.first.second])] = countPairNodes++; n         } n         assert(level1[comp2[t1.first.first.first]] - n                    level1[comp2[t1.first.first.second]] == n                1); n         edgeList[mp1[make_pair(comp2[t1.first.first.first], n                                comp2[t1.first.first.second])]] n             .push_back(t1.second); n       } n     } n     if (component[s] != component[t]) { n       if (ignoreEdge == -1) { n         answer.val = 0; n         answer.edges.clear(); n       } else { n         answer.val = edges[ignoreEdge].first.second; n         answer.edges = {ignoreEdge + 1}; n       } n       return; n     } else { n       int s1 = s; n       int t1 = t; n       s1 = comp2[s1]; n       t1 = comp2[t1]; n       if (s1 == t1) { n         answer.val = INT_MAX; n         answer.edges.clear(); n         return; n       } n       int lca = LCA(s1, t1); n       vector<pair<int, int> > listNodes; n       fillListNodes(listNodes, s1, t1); n       answerType temp; n       bool poss = false; n       for (auto &(t1) : (listNodes)) { n         if (edgeList[mp1[t1]].size() == 1) { n           answerType currentAnswer; n           if (ignoreEdge == -1) { n             poss = true; n             currentAnswer.val = edges[edgeList[mp1[t1]][0]].first.second; n             currentAnswer.edges = {edgeList[mp1[t1]][0] + 1}; n           } else { n             poss = true; n             currentAnswer.val = edges[edgeList[mp1[t1]][0]].first.second + n                                 edges[ignoreEdge].first.second; n             currentAnswer.edges = {edgeList[mp1[t1]][0] + 1, ignoreEdge + 1}; n           } n           if (currentAnswer.val < answer.val) { n             answer = currentAnswer; n           } n         } n       } n       if (!poss) { n         answer.val = INT_MAX; n         answer.edges.clear(); n       } n     } n   }; n }; n vector<pair<pair<pair<int, int>, int>, int> > edges; n vector<pair<pair<int, int>, int> > Adj[1010]; n bool visited[1010]; n vector<int> answerPath; n answerType answer; n vector<int> path; n void DFSPath(int u, int p, int end1) { n   visited[u] = true; n   if (u == end1) { n     answerPath = path; n   } n   for (auto &(t1) : (Adj[u])) { n     if (!visited[t1.first.first] && t1.first.first != p) { n       path.push_back(t1.second); n       DFSPath(t1.first.first, u, end1); n       path.pop_back(); n     } n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int s, t; n   scanf( %d%d , &s, &t); n   for (int(i) = (0); (i) < (m); ++(i)) { n     int a, b, c; n     scanf( %d%d%d , &a, &b, &c); n     edges.push_back(make_pair(make_pair(make_pair(a, b), c), i)); n     Adj[a].push_back(make_pair(make_pair(b, c), i)); n     Adj[b].push_back(make_pair(make_pair(a, c), i)); n   } n   solve tryAll = solve(s, t, -1, edges, n, m); n   tryAll.findAnswer(); n   if (tryAll.answer.val < answer.val) { n     answer = tryAll.answer; n   } n   DFSPath(s, 0, t); n   for (auto &(t1) : (answerPath)) { n     solve tryAll = solve(s, t, t1, edges, n, m); n     tryAll.findAnswer(); n     if (tryAll.answer.val < answer.val) { n       answer = tryAll.answer; n     } n   } n   if (answer.val == INT_MAX) { n     printf( -1 n ); n   } else { n     printf( %d n , answer.val); n     printf( %d n , (int)answer.edges.size()); n     for (auto &(t1) : (answer.edges)) { n       printf( %d  , t1); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300 * 1000 + 9; n const int LOGN = 19; n const int M = 21; n const long long INF64 = 1e18; n int n, m, q; n vector<pair<int, int> > g[N]; n int p[LOGN][N]; n int tin[N], tout[N], T; n long long h[N]; n set<pair<int, int> > badEdges; n long long d[M + M][N]; n bool u[N]; n void dfs(int v, int pr) { n   tin[v] = T++; n   p[0][v] = pr; n   u[v] = true; n   for (int i = 1; i < LOGN; ++i) p[i][v] = p[i - 1][p[i - 1][v]]; n   for (auto e : g[v]) { n     int to = e.first, len = e.second; n     if (!u[to]) { n       h[to] = h[v] + len; n       dfs(to, v); n       if (v < to) n         badEdges.erase(make_pair(v, to)); n       else n         badEdges.erase(make_pair(to, v)); n     } n   } n   tout[v] = T; n } n bool isAncestor(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } n int getLCA(int a, int b) { n   if (isAncestor(a, b)) return a; n   if (isAncestor(b, a)) return b; n   for (int i = LOGN - 1; i >= 0; --i) n     if (!isAncestor(p[i][a], b)) a = p[i][a]; n   return p[0][a]; n } n void dij(int st, long long d[N]) { n   set<pair<long long, int> > q; n   for (int i = 0; i < n; ++i) d[i] = INF64; n   d[st] = 0; n   q.insert(make_pair(d[st], st)); n   while (!q.empty()) { n     int v = q.begin()->second; n     q.erase(q.begin()); n     for (auto e : g[v]) { n       int to = e.first, len = e.second; n       if (d[to] > d[v] + len) { n         q.erase(make_pair(d[to], to)); n         d[to] = d[v] + len; n         q.insert(make_pair(d[to], to)); n       } n     } n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; ++i) { n     int u, v, w; n     scanf( %d %d %d , &u, &v, &w); n     --u, --v; n     g[u].push_back(make_pair(v, w)); n     g[v].push_back(make_pair(u, w)); n   } n   for (int v = 0; v < n; ++v) n     for (auto e : g[v]) n       if (v < e.first) badEdges.insert(make_pair(v, e.first)); n   dfs(0, 0); n   int cpos = 0; n   for (auto e : badEdges) dij(e.first, d[cpos++]); n   scanf( %d , &q); n   for (int tc = 0; tc < q; ++tc) { n     int u, v; n     scanf( %d %d , &u, &v); n     --u, --v; n     int lca = getLCA(u, v); n     long long ans = h[u] + h[v] - 2 * h[lca]; n     for (int i = 0; i < badEdges.size(); ++i) ans = min(ans, d[i][u] + d[i][v]); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j; n   int n; n   scanf( %d , &n); n   if ((n * n) % 2 == 1) { n     printf( %d n , ((n * n) / 2) + 1); n   } else { n     printf( %d n , (n * n) / 2); n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) { n       if ((i + j) % 2 == 0) { n         printf( C ); n       } else { n         printf( . ); n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bitset<20> a; n vector<int> w; n int sol = 0; n void verific(int &l, int &r, int &x) { n   int sum = 0, i, minim = INT_MAX, maxim = INT_MIN; n   for (i = 0; i < w.size(); ++i) { n     if (a[i]) { n       sum += w[i]; n       minim = min(minim, w[i]); n       maxim = max(maxim, w[i]); n     } n   } n   if (sum >= l and sum <= r and maxim - minim >= x) ++sol; n } n int main() { n   int n, i, val, l, r, x; n   cin >> n >> l >> r >> x; n   for (i = 1; i <= n; ++i) { n     cin >> val; n     w.push_back(val); n   } n   for (i = 1; i <= 1 << n; ++i) { n     a = i; n     if (i & (i - 1) == 0) continue; n     verific(l, r, x); n   } n   cout << sol; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   string s; n   cin >> s; n   int arr[10] = {0}; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  L ) { n       int i = 0; n       for (; i < 10; i++) { n         if (arr[i] == 0) break; n       } n       arr[i] = 1; n     } else if (s[i] ==  R ) { n       int i = 9; n       for (; i >= 0; i--) { n         if (arr[i] == 0) break; n       } n       arr[i] = 1; n     } else { n       int t = s[i] - 48; n       arr[t] = 0; n     } n   } n   for (int i = 0; i < 10; i++) cout << arr[i]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int ok(double x, double a[]) { n   double z1 = 0, z2 = 0; n   for (int i = 0; i < n; i++) { n     if (x - a[i] > 0) { n       z1 += x - a[i]; n     } n     if (x - a[i] < 0) { n       double ans = 1 - (k * (double)1) / 100; n       z2 += (a[i] - x) * ans; n     } n   } n   if (z1 <= z2) { n     return 1; n   } n   return 0; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   double a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   double ans = 0, low = 0, high = 10000; n   int z = 0; n   while (low < high) { n     z++; n     double mid = (low + high) / 2; n     if (ok(mid, a) == 1) { n       low = mid; n       ans = mid; n     } else { n       high = mid; n     } n     if (z == 999) { n       break; n     } n   } n   cout << setprecision(12) << ans; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimize( O3 ) n bool FLAG = 0; n using namespace std; n const long long MOD = (long long)1e9 + 7, N = (long long)2e6 + 222; n const long long INF = (long long)1e18; n long long dx[] = {0, -1, 0, 1, 0}; n long long dy[] = {0, 0, 1, 0, -1}; n long long b[N]; n inline void solve() { n   long long n; n   cin >> n; n   long long k = 1; n   vector<long long> v; n   while (n != 0) { n     if (n < k) { n       v.push_back(n); n       n = 0; n       break; n     } n     n -= k; n     v.push_back(k); n     k += k; n   } n   sort(v.begin(), v.end()); n   cout << (long long)(v.size()) - 1 << endl; n   for (long long i = 1; i < (long long)(v.size()); ++i) { n     cout << v[i] - v[i - 1] <<    ; n   } n   cout << endl; 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   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[200005]; n int t1[200005], t2[200005]; n bool vis[200005]; n int n, x, a, b; n void dfs1(int step, int t) { n   t1[step] = t; n   vis[step] = true; n   for (int i = 0; i < v[step].size(); i++) { n     if (!vis[v[step][i]]) dfs1(v[step][i], t + 1); n   } n } n void dfs2(int step, int t) { n   t2[step] = t; n   vis[step] = true; n   for (int i = 0; i < v[step].size(); i++) { n     if (!vis[v[step][i]]) dfs2(v[step][i], t + 1); n   } n } n int main() { n   cin >> n >> x; n   for (int i = 1; i <= n - 1; i++) { n     cin >> a >> b; n     v[a].push_back(b); n     v[b].push_back(a); n   } n   memset(vis, false, sizeof(vis)); n   dfs1(1, 0); n   memset(vis, false, sizeof(vis)); n   dfs2(x, 0); n   int maxl = 0; n   for (int i = 1; i <= n; i++) { n     if (t1[i] > t2[i]) maxl = max(maxl, 2 * t1[i]); n   } n   cout << maxl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   while (q--) { n     int n, k, temp; n     cin >> n >> k; n     set<int> s; n     for (int i = 0; i < n; i++) { n       cin >> temp; n       s.insert(temp); n     } n     set<int>::reverse_iterator it; n     int count = 0; n     for (it = s.rbegin(); it != s.rend(); it++) { n       if ((*it - k * count) <= 0) break; n       count++; n     } n     cout << count <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #define int long long n using namespace std; n  n long long gcd(long long a, long long b) n { n     if(!b) n         return a; n     return gcd(b, a % b); n } n  n long long lcm(long long a, long long b) n { n     long long z = gcd(a, b); n     a /= z; n     if(a > 1e18 / b) n         return -1; n     return a * b; n } n const int MOD = 1e9 + 7; n int inv(int x) n { n     int y = MOD - 2, r = 1; n     while(y) n     { n         if(y&1) n             r=1LL*r*x%MOD; n         y>>=1; n         x=1LL*x*x%MOD; n     } n     return r; n } n int32_t main() n { n     long long n; n     int t; n     cin >> t; n     while(t--) n     { n        cin >> n; n         long long q = 1, ans = 0; n  n         for(int i = 1; i <= 1000; ++i) n         { n  n             long long p = lcm(q, i); n  n             if(p == -1) n                 break; n             else n                 q = p; n             long long mul = (i + 1) / gcd(q, (i + 1)); n             long long divI = n / q, t3 = divI / mul; n             long long pqr = divI - t3; n             long long qq = (1LL * pqr * (i + 1)) % MOD; n             ans = (ans + qq) % MOD; n         } n         cout << ans <<   n ; n  n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int Nmax = 1000005, Mod = 1e9 + 7; n const int Mod1 = 1e9 + 7, Mod2 = 1e9 + 9; n char A[Nmax], B[Nmax]; n int hash1[Nmax], hash2[Nmax]; n int inv_hash1[Nmax], inv_hash2[Nmax]; n int main() { n   ios::sync_with_stdio(false); n   int N, M; n   cin >> N >> M; n   cin >> (B + 1); n   int K = strlen(B + 1); n   for (int i = 1; i <= K; ++i) { n     hash1[i] = (27LL * hash1[i - 1] + B[i] -  a  + 1) % Mod1; n     hash2[i] = (27LL * hash2[i - 1] + B[i] -  a  + 1) % Mod2; n   } n   for (int i = K, pw1 = 1, pw2 = 1; i > 0; --i) { n     inv_hash1[i] = (inv_hash1[i + 1] + 1LL * (B[i] -  a  + 1) * pw1) % Mod1; n     inv_hash2[i] = (inv_hash2[i + 1] + 1LL * (B[i] -  a  + 1) * pw2) % Mod2; n     pw1 = 27LL * pw1 % Mod1; n     pw2 = 27LL * pw2 % Mod2; n   } n   set<int> insertions; n   bool goodSol = true; n   while (M-- > 0) { n     int left; n     cin >> left; n     int right = left + K - 1; n     auto it = insertions.upper_bound(left); n     if (it != insertions.begin()) { n       --it; n       int p = *it; n       if (p + K - 1 >= left) { n         int p1 = p + K - left, p2 = K - p1 + 1; n         if (hash1[p1] != inv_hash1[p2] || hash2[p1] != inv_hash2[p2]) { n           goodSol = false; n           break; n         } n       } n     } n     it = insertions.lower_bound(left); n     if (it != insertions.end()) { n       int p = *it; n       if (p <= right) { n         int p1 = right - p + 1, p2 = K - p1 + 1; n         if (hash1[p1] != inv_hash1[p2] || hash2[p1] != inv_hash2[p2]) { n           goodSol = false; n           break; n         } n       } n     } n     insertions.insert(left); n   } n   if (goodSol == false) n     cout <<  0 n ; n   else { n     int ans = 1; n     for (int i = 1; i <= N; ++i) { n       auto it = insertions.upper_bound(i); n       if (it != insertions.begin()) { n         --it; n         int p = *it; n         if (p + K - 1 < i) ans = 26LL * ans % Mod; n       } else { n         ans = 26LL * ans % Mod; n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   long long n, k; n   cin >> n >> k; n   vector<long long> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   long long ans = 0; n   unordered_map<int, int> m; n   for (int r = 0, l = 0; r < n; r++) { n     m[v[r]]++; n     while (m[v[r]] >= k) { n       m[v[l++]]--; n     } n     ans += l; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n void yash() { n   int arr[4], count = 1; n   for (int i = 0; i < 4; i++) { n     cin >> arr[i]; n   } n   sort(arr, arr + 4); n   for (int i = 0; i < 3; i++) { n     if (arr[i] != arr[i + 1]) { n       count++; n     } n   } n   cout << 4 - count <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   yash(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m, x; n   cin >> n >> m; n   x = m - n; n   if (x >= 2 && n % 2 == 0) n     cout << n <<     << n + 1 <<     << n + 2 << endl; n   else if (x >= 3 && n % 2 != 0) n     cout << n + 1 <<     << n + 2 <<     << n + 3 << endl; n   else n     cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3000 + 5; n int n, m; n int l[N][N], r[N][N], cnt[N], fen[N]; n char s[N][N]; n vector<int> del[N]; n void up(int x, int k) { n   cnt[x] += k; n   for (; x; x -= x & -x) fen[x] += k; n } n int get(int x) { n   int res = 0; n   for (; x < N; x += x & -x) res += fen[x]; n   return res; n } n long long start(int x, int y) { n   memset(fen, 0, sizeof(fen)); n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 1; i <= n; i++) del[i].clear(); n   long long ans = 0; n   int go = x; n   while (x <= n and y >= 1) { n     for (auto u : del[x]) up(u, -1); n     if (s[x][y] ==  . ) { n       for (int i = go; i < x; i++) n         if (cnt[i]) up(i, -1); n       go = x + 1; n       x++; n       y--; n       continue; n     } n     up(x, +1); n     if (x + l[x][y] <= n) del[x + l[x][y]].push_back(x); n     int len = min(r[x][y], x - go + 1); n     ans += get(x - len + 1); n     x++; n     y--; n   } n   return ans; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s[i] + 1); n     for (int j = 1; j <= m; j++) { n       l[i][j] = s[i][j] ==  z  ? l[i][j - 1] + 1 : 0; n     } n     for (int j = m; j >= 1; j--) { n       r[i][j] = s[i][j] ==  z  ? r[i][j + 1] + 1 : 0; n     } n   } n   long long ans = 0; n   for (int i = 1; i <= m; i++) { n     ans += start(1, i); n   } n   for (int i = 2; i <= n; i++) { n     ans += start(i, m); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[111111], b[111111]; n vector<int> v; n long long t[555][555]; n int main() { n   int n; n   cin >> n; n   int r, c; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> t[i][j]; n       if (t[i][j] == 0) { n         r = i; n         c = j; n       } n     } n   } n   if (n == 1) { n     cout <<  1  << endl; n     return 0; n   } n   long long sum = 0; n   if (r == 0) { n     for (int i = 0; i < n; i++) sum += t[1][i]; n   } else { n     for (int i = 0; i < n; i++) sum += t[0][i]; n   } n   long long lel = 0; n   for (int i = 0; i < n; i++) { n     lel += t[r][i]; n   } n   if (lel >= sum) { n     cout <<  -1 ; n     return 0; n   } n   t[r][c] = sum - lel; n   for (int i = 0; i < n; i++) { n     long long cur = 0; n     for (int j = 0; j < n; j++) { n       cur += t[i][j]; n     } n     if (cur != sum) { n       cout <<  -1 ; n       return 0; n     } n   } n   for (int i = 0; i < n; i++) { n     long long cur = 0; n     for (int j = 0; j < n; j++) { n       cur += t[j][i]; n     } n     if (cur != sum) { n       cout <<  -1 ; n       return 0; n     } n   } n   long long cur = 0; n   for (int i = 0; i < n; i++) { n     cur += t[i][i]; n   } n   if (cur != sum) { n     cout <<  -1 ; n     return 0; n   } n   cur = 0; n   for (int i = 0; i < n; i++) { n     cur += t[i][n - 1 - i]; n   } n   if (cur != sum) { n     cout <<  -1 ; n     return 0; n   } n   cout << t[r][c]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; n long long c[maxn][maxn], pw[2][maxn], f[maxn][maxn]; n inline int add(long long a, long long b) { n   a += b; n   return a >= mod ? a - mod : a; n } n inline int mul(long long a, long long b) { return a * b % mod; } n inline long long kpow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return res; n } n void init(int n, int m) { n   for (int i = 0; i <= n; ++i) c[i][0] = 1; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= i; ++j) n       c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; n   for (int i = 0; i <= n; ++i) { n     pw[0][i] = kpow(m - 1, i); n     pw[1][i] = kpow(m, i); n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   init(n, m); n   f[0][0] = 1; n   for (int i = 1; i <= n; ++i) n     for (int j = 0; j <= n; ++j) { n       for (int k = 1; k <= j; ++k) n         f[i][j] = n             add(f[i][j], n                 mul(mul(mul(f[i - 1][j - k], c[n - j + k][k]), pw[1][j - k]), n                     pw[0][n - j])); n       f[i][j] = n           add(f[i][j], mul(f[i - 1][j], mul((pw[1][j] - pw[0][j] + mod) % mod, n                                             kpow(m - 1, n - j)))); n     } n   cout << f[n][n]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INT_INF = 1e9; n const long long LL_INF = 1e18; n int getInt(char c) { return c -  0 ; } n int getDistance(int index, int y, int z, vector<vector<int>>& last) { n   int p = last[index][y]; n   if (p == -1) return INT_INF; n   int q = last[p][z]; n   if (q == -1) return INT_INF; n   return index - q + 1; n } n int main() { n   int tt; n   cin >> tt; n   while (tt--) { n     string s; n     cin >> s; n     int n = (int)s.size(); n     vector<vector<int>> last(n, vector<int>(3, -1)); n     last[0][getInt(s[0]) - 1] = 0; n     int ans = INT_INF; n     for (int i = 1; i < n; i++) { n       int u = getInt(s[i]) - 1; n       for (int j = 0; j < 3; j++) { n         if (u == j) n           last[i][u] = i; n         else n           last[i][j] = last[i - 1][j]; n       } n       if (u == 0) { n         ans = min(ans, getDistance(i, 1, 2, last)); n         ans = min(ans, getDistance(i, 2, 1, last)); n       } else if (u == 1) { n         ans = min(ans, getDistance(i, 0, 2, last)); n         ans = min(ans, getDistance(i, 2, 0, last)); n       } else { n         ans = min(ans, getDistance(i, 0, 1, last)); n         ans = min(ans, getDistance(i, 1, 0, last)); n       } n     } n     cout << (ans == INT_INF ? 0 : ans) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n, tmp, ans = 0, mx = -1; n   cin >> n; n   for (int i = 0; i < n && cin >> tmp; ++i) mx = max(tmp, mx); n   cout << (mx > 25 ? mx - 25 : 0); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 212345, LG = 21, mod = 1000000007; n const double eps = 1e-3, pi = acos(-1.0); n int in[N]; n vector<int> adj[N]; n map<pair<int, int>, int> mp; n set<pair<int, int>> s; n int main() { n   int n, m; n   scanf( %d , &n), scanf( %d , &m); n   for (int i = 1; i <= m; ++i) { n     int u, v; n     scanf( %d , &u), scanf( %d , &v); n     adj[u].push_back(v); n     mp[{u, v}] = i; n     in[v]++; n   } n   for (int i = 1; i <= n; ++i) s.insert({in[i], i}); n   int ans = -1; n   while (s.size() > 1) { n     int t = s.begin()->second; n     s.erase(s.begin()); n     if (in[t] != 0) { n       ans = -1; n       break; n     } n     if (s.begin()->first == 0) { n       ans = -1; n       break; n     } n     for (int i = 0; i < adj[t].size(); ++i) { n       int u = adj[t][i]; n       s.erase({in[u], u}); n       in[u]--; n       s.insert({in[u], u}); n     } n     ans = max(ans, mp[{t, s.begin()->second}]); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int A = 100000, MD = 998244353; n int kk[A + 1]; n int pp[A + 1][6][6], aa[6][6], tt[6][6]; n int uu_[6], vv_[6], *uu = uu_, *vv = vv_; n int kp[A + 1]; n bool sq[A + 1]; n void init(int *aa, int a0, int a1, int a2, int a3, int a4, int a5) { n   aa[0] = a0, aa[1] = a1, aa[2] = a2, aa[3] = a3, aa[4] = a4, aa[5] = a5; n } n void init(int aa[][6], int x) { n   int x2 = x * 2 % MD; n   int xx = (long long)x * x % MD; n   init(aa[0], 2, 1, x2, x2, xx, xx); n   init(aa[1], 0, 2, 0, x2, 0, xx); n   init(aa[2], 0, 0, 2, 1, x, x); n   init(aa[3], 0, 0, 0, 2, 0, x); n   init(aa[4], 0, 0, 0, 0, 2, 1); n   init(aa[5], 0, 0, 0, 0, 0, 2); n } n void mult(int aa[][6], int *uu, int *vv) { n   for (int i = 0; i < 6; i++) { n     long long v = 0; n     for (int j = 0; j < 6; j++) v += (long long)aa[i][j] * uu[j]; n     vv[i] = v % MD; n   } n } n void mult(int aa[][6], int bb[][6], int cc[][6]) { n   for (int i = 0; i < 6; i++) n     for (int j = 0; j < 6; j++) { n       long long c = 0; n       for (int k = 0; k < 6; k++) c += (long long)aa[i][k] * bb[k][j]; n       cc[i][j] = c % MD; n     } n } n void power(int aa[][6], int pp[][6], int tt[][6], int k) { n   if (k == 0) { n     for (int i = 0; i < 6; i++) { n       for (int j = 0; j < 6; j++) pp[i][j] = 0; n       pp[i][i] = 1; n     } n     return; n   } n   if (k & 1) { n     power(aa, pp, tt, k >> 1); n     mult(pp, pp, tt); n     mult(tt, aa, pp); n   } else { n     power(aa, tt, pp, k >> 1); n     mult(tt, tt, pp); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int m; n   cin >> m; n   while (m--) { n     int a, k; n     cin >> a >> k; n     kk[a] = k; n     init(aa, a); n     power(aa, pp[a], tt, k); n   } n   long long ans = 0; n   for (int a = 1; a <= A; a++) { n     if (sq[a]) continue; n     if (a > 1 && kp[a] == 0) { n       for (int b = a; b <= A; b += a) kp[b]++; n       if (a <= A / a) n         for (int s = a * a, t = s; t <= A; t += s) sq[t] = true; n     } n     fill(uu, uu + 6, 0); n     uu[5] = 1; n     for (int b = a; b <= A; b += a) n       if (kk[b] > 0) { n         mult(pp[b], uu, vv); n         swap(uu, vv); n       } n     int z = uu[0] - uu[1]; n     ans += kp[a] % 2 == 0 ? z : -z; n   } n   ans %= MD; n   if (ans < 0) ans += MD; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, K, p; n char s[11]; n int calc(int x, int y) { n   printf( 1 %d %d n , x, y); n   fflush(stdout); n   scanf( %s , s + 1); n   return s[1] ==  T ; n } n int find(int l, int r) { n   while (l < r) { n     int mid = (l + r) >> 1; n     if (calc(mid, mid + 1)) n       r = mid; n     else n       l = mid + 1; n   } n   return l; n } n int main() { n   scanf( %d%d , &n, &K); n   p = find(1, n); n   int l = 1, r = p; n   while (l < r) { n     int mid = (l + r + 1) >> 1; n     if (calc(mid - 1, mid)) return printf( 2 %d %d n , p, find(l, mid - 1)), 0; n     l = mid; n   } n   l = p; n   r = n; n   while (l < r) { n     int mid = (l + r) >> 1; n     if (calc(mid + 1, mid)) return printf( 2 %d %d n , p, find(mid + 1, r)), 0; n     r = mid; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e4 + 100; n int n, k; n char str[N]; n bool f[N]; n int main() { n   scanf( %s , str + 1), n = strlen(str + 1); n   while (1 << k < n) ++k; n   if (1 << k > n) --k; n   memset(f, 1, sizeof(f)); n   for (int i = 1; i <= n - (1 << k) + 1; ++i) { n     char ch =  z ; n     for (int s = 0; s < 1 << k; ++s) n       if (f[s]) n         for (int t = 0; t < k; ++t) f[s | (1 << t)] = 1; n     for (int s = 0; s < 1 << k; ++s) n       if (f[s]) ch = min(str[i + s], ch); n     for (int s = 0; s < 1 << k; ++s) n       if (str[i + s] != ch) f[s] = 0; n     putchar(ch); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l, r; n   cin >> l >> r; n   while (l <= r) { n     int arr[9] = {0}; n     int x = l; n     bool diff = 1; n     while (x) { n       int num = x % 10; n       x /= 10; n       if (arr[num]) { n         diff = 0; n         l++; n         break; n       } n       arr[num]++; n     } n     if (diff) { n       cout << l << endl; n       return 0; n     } n   } n   cout << -1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string s, str; n long long mns, all, pls, nom, maxi, mini, n, sum, otn; n vector<char> v; n vector<long long> ans; n int main() { n   getline(cin, s); n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  - ) mns++; n     if (s[i] ==  ? ) all++; n     if (s[i] ==  = ) nom = i; n   } n   pls = all - mns; n   string str; n   str = s.substr(nom + 2, s.size() - nom - 2); n   n = atoll(str.c_str()); n   maxi = n * pls - mns; n   mini = pls - mns * n; n   if (n < mini || n > maxi) { n     cout <<  Impossible ; n     return 0; n   } n   cout <<  Possible n ; n   v.push_back( + ); n   for (int i = 0; i < s.size(); i++) n     if (s[i] ==  + ) n       v.push_back( + ); n     else if (s[i] ==  - ) n       v.push_back( - ); n   for (int i = 0; i < v.size(); i++) n     if (v[i] ==  + ) n       ans.push_back(n); n     else n       ans.push_back(1); n   sum = maxi; n   for (int i = 0; i < ans.size(); i++) n     if (sum > n) n       if (v[i] ==  + ) { n         otn = min(n - 1, sum - n); n         ans[i] -= otn; n         sum -= otn; n       } else { n         otn = min(n - 1, sum - n); n         ans[i] += otn; n         sum -= otn; n       } n   cout << ans[0] <<    ; n   for (int i = 1; i < v.size(); i++) cout << v[i] <<     << ans[i] <<    ; n   cout <<  =   << n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; n   long a, b; n   cin >> a; n   cin >> b; n   int count = 0; n   int i; n   long x; n   do { n     x = a; n     while (x >= 10) { n       i = x % 10; n       count += m[i]; n       x /= 10; n     } n     count += m[x]; n     a++; n   } while (a <= b); n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n ll cnt_inv[30][2]; n void rec(vector<int>& a, int b) { n   if (b < 0 || a.empty()) return; n   vector<int> s, us; n   for (int& i : a) { n     int val = i & (1 << b); n     if (val) n       cnt_inv[b][1] += us.size(), s.push_back(i); n     else n       cnt_inv[b][0] += s.size(), us.push_back(i); n   } n   rec(s, b - 1); n   rec(us, b - 1); n } n void solve() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < int(n); i++) cin >> a[i]; n   memset(cnt_inv, 0, sizeof cnt_inv); n   rec(a, 29); n   ll inv = 0, x = 0; n   for (int b = 29; b >= 0; b--) { n     inv += min(cnt_inv[b][0], cnt_inv[b][1]); n     int val = 1; n     if (cnt_inv[b][0] <= cnt_inv[b][1]) val = 0; n     x += (val << b); n   } n   cout << inv <<     << x <<   n ; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n namespace LYYY { n int read() { n   int s = 0; n   char c = getchar(); n   int f = 1; n   while (c < 48 || c > 57) { n     if (c == 45) f = -1; n     c = getchar(); n   } n   while (c >= 48 && c <= 57) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); n   return s * f; n } n long long readl() { n   long long s = 0; n   char c = getchar(); n   int f = 1; n   while (c < 48 || c > 57) { n     if (c == 45) f = -1; n     c = getchar(); n   } n   while (c >= 48 && c <= 57) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); n   return s * f; n } n void write(int x) { n   if (x >= 10) write(x / 10); n   putchar(x % 10 + 48); n } n void W(int x) { n   if (x < 0) x = -x, putchar(45); n   write(x); n } n void writel(long long x) { n   if (x >= 10) write(x / 10); n   putchar(x % 10 + 48); n } n void Wl(long long x) { n   if (x < 0) x = -x, putchar(45); n   write(x); n } n }  // namespace LYYY n using namespace LYYY; n const int mod = 1000 * 1000 * 1000 + 7; n int mul(int x, long long k) { n   long long ans = 1, mid = x; n   while (k) { n     if (k & 1) ans = ans * mid % mod; n     mid = mid * mid % mod; n     k >>= 1; n   } n   return ans; n } n int Get(long long n, int x) { n   if (n < x) return 1; n   return (long long)mul(x, n / x) * Get(n / x, x) % mod; n } n int main() { n   int x = read(); n   long long n = readl(), ans = 1; n   for (int i = 2; i * i <= x; ++i) n     if (x % i == 0) { n       ans = ans * Get(n, i) % mod; n       while (x % i == 0) x /= i; n     } n   if (x > 1) ans = ans * Get(n, x) % mod; n   writel(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[111]; n int main() { n   int n; n   scanf( %d , &n); n   arr[0] = 0; n   for (int i = (1); i < (n + 1); ++i) scanf( %d , &arr[i]); n   int ans = 0; n   if (n % 2 == 0 || n == 1) { n     printf( -1 n ); n     return 0; n   } n   for (int i = n; i >= 1; i -= 2) { n     int tmp = max(arr[i], arr[i - 1]); n     ans += tmp; n     arr[i] = arr[i - 1] = 0; n     arr[(i - 1) / 2] = max(0, arr[(i - 1) / 2] - tmp); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct msg { n   long long lstl = 0; n   long long lstr = 0; n   long long num = 0; n }; n int32_t main() { n   long long n, k; n   cin >> n >> k; n   long long a[n]; n   msg ms[n]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (long long i = 0; i < n; i++) { n     if (a[i] == 0) { n       ms[i].lstl = max(i - k, 0LL); n       ms[i].lstr = min(i + k, n - 1); n       ms[i].num = 1 + ms[i].lstr - ms[i].lstl; n     } else { n       ms[i].lstl = max(i - k, 0LL); n       ms[i].lstr = min(i + k, n - 1); n       long long nmr, nml; n       if (ms[i].lstl <= ms[a[i] - 1].lstr) { n         if (ms[a[i] - 1].lstr < i) { n           nml = k - (ms[a[i] - 1].lstr - ms[i].lstl + 1); n         } else { n           nml = 0; n         } n       } else { n         nml = i - ms[i].lstl; n       } n       if (ms[a[i] - 1].lstr < i) { n         nmr = ms[i].lstr - i + 1; n       } else if (ms[a[i] - 1].lstr == i) { n         nmr = ms[i].lstr - i; n       } else { n         nmr = ms[i].lstr - ms[a[i] - 1].lstr; n       } n       ms[i].num = nmr + nml + ms[a[i] - 1].num; n     } n   } n   for (long long i = 0; i < n; i++) { n     cout << ms[i].num <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (1 << 11); n const int maxs = 27; n string s[maxn]; n vector<int> NextIn[maxn][maxs]; n int NextOut[maxn][maxs], First[maxn][maxs], a[maxn]; n pair<int, int> dp[maxn][maxn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   memset(First, 63, sizeof First); n   memset(NextOut, 63, sizeof NextOut); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n     int m = s[i].size(); n     for (int ch = 0; ch < maxs; ch++) NextIn[i][ch].resize(m); n     for (int j = m - 1; j >= 0; j--) n       for (int ch = 0; ch < maxs; ch++) { n         if (j + 1 < m && s[i][j + 1] == ch +  a ) n           NextIn[i][ch][j] = j + 1; n         else if (j + 1 < m) n           NextIn[i][ch][j] = NextIn[i][ch][j + 1]; n         else n           NextIn[i][ch][j] = 1e9; n       } n     for (int j = m - 1; j >= 0; j--) First[i][s[i][j] -  a ] = j; n   } n   int m; n   cin >> m; n   for (int i = 0; i < m; i++) cin >> a[i], a[i]--; n   for (int i = m - 1; i >= 0; i--) n     for (int ch = 0; ch < maxs; ch++) { n       if (i + 1 < m && First[a[i + 1]][ch] < 1e7) n         NextOut[i][ch] = i + 1; n       else n         NextOut[i][ch] = NextOut[i + 1][ch]; n     } n   string t; n   cin >> t; n   int k = t.size(); n   for (int i = 0; i < maxn; i++) n     for (int j = 0; j < maxn; j++) dp[i][j] = {1e9, 1e9}; n   dp[0][0] = {0, -1}; n   for (int i = 1; i <= k; i++) n     for (int j = 0; j <= k; j++) { n       int ch = t[i - 1] -  a ; n       dp[i][j] = dp[i - 1][j]; n       if (!j) continue; n       auto tmp = dp[i - 1][j - 1]; n       if (tmp.first >= m) continue; n       int ind = a[tmp.first]; n       if (tmp.second == -1 && First[ind][ch] < 1e7) n         dp[i][j] = min(dp[i][j], make_pair(tmp.first, First[ind][ch])); n       else if (tmp.second != -1 && NextIn[ind][ch][tmp.second] < 1e7) n         dp[i][j] = n             min(dp[i][j], make_pair(tmp.first, NextIn[ind][ch][tmp.second])); n       if (NextOut[tmp.first][ch] < m) { n         int pt = NextOut[tmp.first][ch]; n         dp[i][j] = min(dp[i][j], make_pair(pt, First[a[pt]][ch])); n       } n     } n   int ans = 0; n   while (ans + 1 <= k && dp[k][ans + 1].first < m) ans++; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, I; n vector<long long int> vec; n vector<long long int> comp; n long long int K; n int main() { n   scanf( %lld %lld , &n, &I); n   for (int i = 1; i <= n; i++) { n     long long int a; n     scanf( %lld , &a); n     vec.push_back(a); n   } n   K = 1 << min((long long int)20, 8 * I / n); n   sort(vec.begin(), vec.end()); n   long long int pre = -1; n   for (int i = 1; i <= n; i++) { n     if (vec[i - 1] != pre) { n       comp.push_back(i); n       pre = vec[i - 1]; n     } n   } n   if (8 * I / n >= 20) { n     printf( 0 ); n     return 0; n   } n   int ans = 1000000000; n   for (int i = 0; i < comp.size(); ++i) { n     int num = comp[i] - 1 + (i + K < comp.size() ? n + 1 - comp[i + K] : 0); n     ans = min(num, ans); n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const int inf = 0x3f3f3f3f; n const double eps = 1e-15; n const long long INF = (1LL << 60); n int cnt[1010]; n int a[1010]; n int M[1010]; n int m; n int dp[1010][1010][2]; n int main() { n   int n, m, x; n   scanf( %d%d , &n, &m); n   memset(dp, 0, sizeof(dp)); n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &x); n     x %= m; n     ++cnt[x]; n   } n   if (n > m) { n     printf( YES n ); n     return 0; n   } n   dp[0][0][0] = 1; n   for (int i = 0; i < m; ++i) { n     for (int j = 0; j < m; ++j) { n       if (dp[i][j][0]) { n         dp[i + 1][j][0] = 1; n       } n       if (dp[i][j][1]) { n         dp[i + 1][j][1] = 1; n       } n       for (int k = 1; k <= cnt[i]; ++k) { n         if (dp[i][j][0] || dp[i][j][1]) { n           dp[i + 1][(j + k * i) % m][1] = 1; n         } n       } n     } n   } n   bool flag = dp[m][0][1]; n   puts(flag ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); n const int N = 200005; n const int M = 1000000007; n long long ast(long long x, long long n) { n   x %= M; n   long long ans = 1; n   while (n) { n     if (n % 2 == 1) ans = (ans * x) % M; n     x = (x * x) % M; n     n /= 2; n   } n   return ans; n } n int n; n long long a[N]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]); n   long long u = 2; n   long long k = 1; n   for (int i = 1; i <= n; ++i) { n     u = ast(u, a[i]); n     if (a[i] % 2 == 0) k = 0; n   } n   u = (u * ast(2, M - 2)) % M; n   long long x; n   if (k == 0) n     x = ((u + 1) * ast(3, M - 2)) % M; n   else n     x = ((u - 1 + M) % M * ast(3, M - 2)) % M; n   printf( %lld/%lld n , x, u); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) { n       cout <<  1  ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, st[350005], dr[350005], grad[350005], bad[350005], l, order[350005], n     len; n bool used[350005], stare[350005]; n vector<int> L[350005]; n vector<int>::iterator it[350005]; n inline void add_edge(int x, int y) { n   ++m; n   L[x].push_back(m); n   L[y].push_back(m); n   st[m] = x; n   dr[m] = y; n } n inline void Dfs(int nod) { n   while (it[nod] != L[nod].end()) { n     if (used[*it[nod]]) { n       ++it[nod]; n       continue; n     } n     used[*it[nod]] = 1; n     Dfs(st[*it[nod]] + dr[*it[nod]] - nod); n   } n   order[++len] = nod; n } n int main() { n   int i, j, x, y; n   cin >> n >> m; n   for (i = 1; i <= m; ++i) { n     cin >> st[i] >> dr[i]; n     L[st[i]].push_back(i); n     L[dr[i]].push_back(i); n     ++grad[st[i]]; n     ++grad[dr[i]]; n   } n   for (i = 1; i <= n; ++i) n     if (grad[i] & 1) bad[++l] = i; n   for (i = 1; i < l; i += 2) add_edge(bad[i], bad[i + 1]); n   if (m & 1) add_edge(1, 1); n   for (i = 1; i <= n; ++i) it[i] = L[i].begin(); n   Dfs(1); n   cout << m <<   n ; n   for (i = 1; i < len; ++i) { n     x = order[i]; n     y = order[i + 1]; n     if (!stare[x]) { n       cout << y <<     << x <<   n ; n       stare[y] = 1; n     } else { n       cout << x <<     << y <<   n ; n       stare[y] = 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int R, C; n   cin >> R >> C; n   char m[R][C]; n   for (int i = 0; i < R; i++) n     for (int j = 0; j < C; j++) cin >> m[i][j]; n   for (int i = 0; i < R; i++) n     for (int j = 0; j < C; j++) { n       if (m[i][j] ==  S ) { n         if (i > 0) n           if (m[i - 1][j] ==  W ) { n             cout <<  No n ; n             return 0; n           } n         if (i < R - 1) n           if (m[i + 1][j] ==  W ) { n             cout <<  No n ; n             return 0; n           } n         if (j > 0) n           if (m[i][j - 1] ==  W ) { n             cout <<  No n ; n             return 0; n           } n         if (j < C - 1) n           if (m[i][j + 1] ==  W ) { n             cout <<  No n ; n             return 0; n           } n       } n     } n   cout <<  Yes n ; n   for (int i = 0; i < R; i++) n     for (int j = 0; j < C; j++) n       if (m[i][j] ==  . ) m[i][j] =  D ; n   for (int i = 0; i < R; i++) { n     for (int j = 0; j < C; j++) { n       cout << m[i][j]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n long long arr[200002], time_freq[101]; n void solve() { n   long long total_time = 0; n   for (long long i = 0; i < n; i++) { n     long long exam_start_time = total_time + arr[i] - m; n     int student_removed = 0; n     if (exam_start_time > 0) { n       for (int j = 100; j > 0; j--) { n         long long y = time_freq[j] * j; n         if (exam_start_time <= y) { n           student_removed += ((exam_start_time + j - 1) / j); n           break; n         } n         exam_start_time -= (time_freq[j] * j); n         student_removed += time_freq[j]; n       } n     } n     total_time += arr[i]; n     time_freq[arr[i]]++; n     cout << student_removed <<    ; n   } n   cout << endl; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   ; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n map<int, int> mp; n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, k, tmp = 1, mx = 0; n   cin >> n >> k; n   while (tmp <= k + 1) { n     int pos, x; n     cout <<  ?  <<    ; n     for (int i = 1; i <= k + 1; i++) { n       if (i != tmp) cout << i <<    ; n     } n     cout << endl; n     cout.flush(); n     tmp++; n     cin >> pos >> x; n     mp[x]++; n     mx = max(mx, x); n   } n   cout <<  !  <<     << mp[mx] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k[3]; n   while (cin >> k[0] >> k[1] >> k[2]) { n     bool flag = false; n     int one = 0, two = 0, three = 0, four = 0; n     for (int i = 0; i < 3; i++) { n       if (k[i] == 1) one++; n       if (k[i] == 2) two++; n       if (k[i] == 3) three++; n       if (k[i] == 4) four++; n     } n     if (one >= 1 || two >= 2 || three == 3 || two == 1 && four == 2) n       flag = true; n     if (flag) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> tc[30]; n bool dp[5][110][505]; n int vis[5][110][505], n, k, Trow[30], kase, stx, sty; n char mp[5][110]; n bool solve(int x, int y, int mv) { n   if (x < 1 || x > 3 || y < 1) return 0; n   if (y > n) return 1; n   bool oc1 = 0, oc2 = 0, oc3 = 0; n   if (vis[x][y][mv] == kase) return dp[x][y][mv]; n   for (int i = 1; i <= k; i++) { n     if (x == Trow[i]) { n       if (y >= (tc[i].first - mv * 2) && y <= (tc[i].second - mv * 2)) return 0; n       if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2)) n         oc1 = 1; n     } else if (x - Trow[i] == 1) { n       if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2)) n         oc2 = 1; n     } else if (Trow[i] - x == 1) { n       if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2)) n         oc3 = 1; n     } n   } n   bool op1 = 0, op2 = 0, op3 = 0; n   if (!oc1) op1 = solve(x, y + 1, mv + 1); n   if (!oc1 && !oc2) op2 = solve(x - 1, y + 1, mv + 1); n   if (!oc1 && !oc3) op3 = solve(x + 1, y + 1, mv + 1); n   vis[x][y][mv] = kase; n   return dp[x][y][mv] = (op1 || op2 || op3); n } n int main() { n   int ks; n   scanf( %d , &ks); n   for (kase = 1; kase <= ks; kase++) { n     scanf( %d %d , &n, &k); n     for (int i = 1; i <= 3; i++) scanf( %s , &mp[i][1]); n     int cnt = 1; n     for (int i = 1; i <= 3; i++) { n       for (int j = 1; j <= n; j++) { n         if (mp[i][j] ==  s ) n           stx = i, sty = j; n         else if (mp[i][j] !=  . ) { n           char S = mp[i][j]; n           int kk = j; n           while (kk <= n && mp[i][kk] == S) mp[i][kk] =  . , kk++; n           Trow[cnt] = i; n           tc[cnt].first = j; n           tc[cnt].second = kk - 1; n           cnt++; n         } n       } n     } n     printf( %s n , solve(stx, sty, 0) ?  YES  :  NO ); n   } n } n


#include <bits/stdc++.h> n #pragma GCC target( fma ) n #pragma GCC optimize( unroll-loops,-Ofast ) n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n long long a[500005]; n int n; n set<long long> buck[1000]; n long long c[1000]; n void fix(int v) { n   int l = v * 700; n   int r = (v + 1) * 700; n   r = min(r, n); n   buck[v].clear(); n   for (int i = l; i < r; ++i) { n     a[i] += c[v]; n     buck[v].insert(a[i]); n   } n   c[v] = 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int q; n   cin >> n >> q; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     buck[i / 700].insert(a[i]); n   } n   while (q--) { n     int t, l, r, x; n     cin >> t; n     if (t == 1) { n       cin >> l >> r >> x; n       --l; n       --r; n       if (l / 700 == r / 700) { n         for (int i = l; i <= r; i++) a[i] += x; n         fix(r / 700); n         continue; n       } n       if (l % 700 != 0) { n         for (; l % 700 != 0; ++l) { n           a[l] += x; n         } n         fix(l / 700 - 1); n       } n       l /= 700; n       if (r % 700 != 700 - 1) { n         for (; r % 700 != 700 - 1; --r) { n           a[r] += x; n         } n         fix(r / 700 + 1); n       } n       r /= 700; n       for (; l <= r; l++) c[l] += x; n     } else { n       cin >> x; n       l = r = -1; n       for (int i = 0; i <= n / 700; ++i) { n         if (buck[i].count(x - c[i])) { n           for (int j = i * 700; 1; ++j) { n             if (a[j] == x - c[i]) { n               l = j; n               break; n             } n           } n           break; n         } n       } n       for (int i = n / 700; i >= 0; --i) { n         if (buck[i].count(x - c[i])) { n           for (int j = i * 700 + 700 - 1; 1; --j) { n             if (a[j] == x - c[i]) { n               r = j; n               break; n             } n           } n           break; n         } n       } n       if (l == -1) { n         cout << -1 <<   n ; n       } else { n         cout << r - l <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (a % b == 0) n     return b; n   else n     return gcd(b, a % b); n } n int main() { n   int n, m, an[120], am[120], fa = -1, fb = -1, f = 0, a, b; n   cin >> n >> m; n   for (int i = 0; i < n + 1; i++) { n     cin >> an[i]; n     if (f == 0 && an[i] != 0) { n       f = 1; n       fa = n - i; n     } n   } n   f = 0; n   for (int i = 0; i < m + 1; i++) { n     cin >> am[i]; n     if (f == 0 && am[i] != 0) { n       f = 1; n       fb = m - i; n     } n   } n   a = an[n - fa]; n   b = am[m - fb]; n   if (fa < 0 && fb < 0) { n     cout <<  0/1  << endl; n   } n   if (fb == fa) { n     f = gcd(a, b); n     a /= f; n     b /= f; n     if (b < 0) { n       b = abs(b); n       a *= -1; n     } n     cout << a <<  /  << b << endl; n   } n   if (fa > fb) { n     if (a * b > 0) n       cout <<  Infinity  << endl; n     else n       cout <<  -Infinity  << endl; n   } else if (fa < fb) { n     cout <<  0/1  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1}, n                         {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; n template <class T> n inline T abs1(T a) { n   return a < 0 ? -a : a; n } n const int maxn = 100110; n template <class t> n struct segment_node { n   int be, en; n   t num, add; n }; n template <class t> n struct segment_tree { n   int l; n   segment_node<t> tree[maxn * 4]; n   inline int gleft(int no) { return no << 1; } n   inline int gright(int no) { return (no << 1) + 1; } n   inline int gfa(int no) { return no >> 1; } n   inline segment_tree() { l = 0; } n   void build(int no, int l, int r) { n     if (l == r) { n       tree[no].be = tree[no].en = l; n       tree[no].num = -1; n       tree[no].add = -1; n       return; n     } n     tree[no].be = l; n     tree[no].en = r; n     int mid = (l + r) / 2; n     build(gleft(no), l, mid); n     build(gright(no), mid + 1, r); n     tree[no].add = -1; n   } n   inline void relax(int no) { n     tree[gleft(no)].add = tree[no].add; n     tree[gright(no)].add = tree[no].add; n     tree[no].add = -1; n   } n   void down(int l, int r, int no, t ranadd) { n     if (tree[no].be != tree[no].en && tree[no].add != -1) relax(no); n     if (l <= tree[no].be && r >= tree[no].en) { n       tree[no].add = ranadd; n       return; n     } n     int mid = (tree[no].be + tree[no].en) / 2; n     if (r >= tree[no].be && l <= mid) down(l, r, gleft(no), ranadd); n     if (r >= mid + 1 && l <= tree[no].en) down(l, r, gright(no), ranadd); n   } n   t getnum(int loc, int no) { n     if (tree[no].add != -1) { n       int ans = tree[no].add; n       if (tree[no].be != tree[no].en) relax(no); n       return ans; n     } n     if (tree[no].be == tree[no].en) return tree[no].num; n     int mid = (tree[no].be + tree[no].en) / 2; n     if (loc <= mid) n       return getnum(loc, gleft(no)); n     else n       return getnum(loc, gright(no)); n   } n }; n segment_tree<int> sgt[4]; n struct segment { n   int from, to, no; n   segment(int a = 0, int b = 0, int no1 = 0) { n     from = min(a, b); n     to = max(a, b); n     no = no1; n   } n }; n vector<segment> orig[2][maxn]; n pair<int, int> orig1[maxn * 2], origto[maxn]; n long long origdir[maxn * 2], origstep[maxn]; n struct vec { n   int no, loc; n   vec(int a = 0, int b = 0) : no(a), loc(b) {} n }; n vector<vec> she[4][maxn]; n map<pair<int, int>, int> trans; n long long narrow, b, nq; n struct node { n   int fa, delta; n   long long dis; n   node(int a = 0, int b = 0, int c = 0) { fa = a, dis = b, delta = c; } n } fa[60][maxn * 2]; n inline int finddir(pair<int, int> from, pair<int, int> to) { n   to.first -= from.first; n   to.second -= from.second; n   if (to.first) to.first /= abs(to.first); n   if (to.second) to.second /= abs(to.second); n   for (int j = 0; j < 4; j++) n     if (to.first == step[j][0] && to.second == step[j][1]) return j; n   return 0; n } n inline long long cntdis(pair<int, int> co, pair<int, int> co1) { n   return abs(co.first - co1.first) + abs(co.second - co1.second); n } n inline pair<long long, long long> finddis(int from, int dir, int to) { n   pair<long long, long long> ans; n   if (to == -1) { n     ans = orig1[from]; n     if (dir > 1) swap(ans.first, ans.second); n     if (!(dir & 1)) ans.first = b - ans.first; n     ans.second = 0; n     return ans; n   } n   if ((origdir[to] ^ dir) < 2) { n     long long dis1 = orig1[from].first - orig1[to].first, n               dis2 = orig1[from].first - origto[to].first; n     if (orig1[to].first == orig1[from].first && n         orig1[to].first == origto[to].first) n       dis1 = orig1[from].second - orig1[to].second, n       dis2 = orig1[from].second - origto[to].second; n     if (dis1 * dis2 < 0) { n       ans.first = 0; n       ans.second = abs1(dis1); n     } else { n       ans.first = min(abs1(dis1), abs1(dis2)); n       ans.second = 0; n       if (abs1(dis1) > abs1(dis2)) ans.second = abs1(dis1) - abs1(dis2); n     } n     return ans; n   } n   ans = orig1[to]; n   ans.first -= orig1[from].first; n   ans.second -= orig1[from].second; n   if (dir > 1) swap(ans.first, ans.second); n   ans.first = abs1(ans.first); n   ans.second = abs1(ans.second); n   return ans; n } n int main() { n   scanf( %I64d%I64d , &narrow, &b); n   for (int i = 0; i < narrow; i++) { n     pair<int, int> from, to; n     scanf( %d%d%d%d , &from.first, &from.second, &to.first, &to.second); n     trans[from] = i; n     orig1[i] = from; n     origto[i] = to; n     if (from.first == to.first) { n       orig[0][from.first].push_back(segment(from.second, to.second, i)); n       orig[1][max(from.second, to.second)].push_back( n           segment(from.first, from.first, i)); n       orig[1][min(from.second, to.second)].push_back( n           segment(from.first, from.first, i)); n     } else { n       orig[1][from.second].push_back(segment(from.first, to.first, i)); n       orig[0][max(from.first, to.first)].push_back( n           segment(from.second, from.second, i)); n       orig[0][min(from.first, to.first)].push_back( n           segment(from.second, from.second, i)); n     } n     int randir = finddir(from, to); n     origdir[i] = randir; n     if (randir > 1) swap(to.first, to.second); n     she[randir][to.first].push_back(vec(i, to.second)); n   } n   scanf( %I64d , &nq); n   for (int i = 0; i < nq; i++) { n     pair<int, int> st; n     char randirc; n     long long step1, randir; n     scanf( %d %d %c %I64d , &st.first, &st.second, &randirc, &step1); n     orig1[i + narrow] = st; n     trans[st] = i + narrow; n     if (randirc ==  L ) randir = 1; n     if (randirc ==  R ) randir = 0; n     if (randirc ==  U ) randir = 2; n     if (randirc ==  D ) randir = 3; n     origdir[i + narrow] = randir, origstep[i] = step1; n     if (randir > 1) swap(st.first, st.second); n     she[randir][st.first].push_back(vec(i + narrow, st.second)); n   } n   for (int i = 0; i < 4; i++) { n     sgt[i].build(1, 0, b + 1); n     int from = 0, add = 1, to = b + 1; n     if (!(i & 1)) from = b, add = -1, to = -1; n     int biao = i / 2; n     for (int j = from; j != to; j += add) { n       for (int t = 0; t < (int)she[i][j].size(); t++) n         if (she[i][j][t].no < narrow) { n           fa[0][she[i][j][t].no].fa = sgt[i].getnum(she[i][j][t].loc, 1); n           pair<long long, long long> randis = n               finddis(she[i][j][t].no, i, fa[0][she[i][j][t].no].fa); n           fa[0][she[i][j][t].no].dis = randis.first; n           fa[0][she[i][j][t].no].delta = randis.second; n         } n       for (int t = 0; t < (int)orig[biao][j].size(); t++) n         sgt[i].down(orig[biao][j][t].from, orig[biao][j][t].to, 1, n                     orig[biao][j][t].no); n       for (int t = 0; t < (int)she[i][j].size(); t++) n         if (she[i][j][t].no >= narrow) { n           fa[0][she[i][j][t].no].fa = sgt[i].getnum(she[i][j][t].loc, 1); n           pair<long long, long long> randis = n               finddis(she[i][j][t].no, i, fa[0][she[i][j][t].no].fa); n           fa[0][she[i][j][t].no].dis = randis.first; n           fa[0][she[i][j][t].no].delta = randis.second; n         } n     } n   } n   for (int i = 1; i < 60; i++) { n     for (int j = 0; j < narrow + nq; j++) { n       if (fa[i - 1][j].fa != -1) { n         fa[i][j].fa = fa[i - 1][fa[i - 1][j].fa].fa; n         fa[i][j].delta = fa[i - 1][fa[i - 1][j].fa].delta; n         fa[i][j].dis = fa[i - 1][fa[i - 1][j].fa].dis + fa[i - 1][j].dis - n                        fa[i - 1][j].delta; n       } else n         fa[i][j] = fa[i - 1][j]; n       if (fa[i][j].dis > 1000000000000000ll) fa[i][j].dis = 1000000000000001ll; n     } n   } n   for (long long i1 = 0; i1 < nq; i1++) { n     long long no = i1 + narrow; n     int en = 59; n     for (; en != -1;) { n       int ranbe = -1, ranen = en; n       while (ranbe < ranen) { n         int mid = (ranbe + ranen + 1) / 2; n         if (fa[mid][no].dis > origstep[i1] || fa[mid][no].fa == -1) n           ranen = mid - 1; n         else n           ranbe = mid; n       } n       en = ranbe; n       if (en == -1) break; n       origstep[i1] -= fa[ranbe][no].dis - fa[ranbe][no].delta; n       no = fa[ranbe][no].fa; n     } n     printf( n          %I64d %I64d n , n         max(0ll, min(b, orig1[no].first + origstep[i1] * step[origdir[no]][0])), n         max(0ll, n             min(b, orig1[no].second + origstep[i1] * step[origdir[no]][1]))); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   n = (n * (n - 1)) / 2 + (((n * (n - 1)) / 2) * ((2 * n - 1))) / 3 - 2; n   cout << n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[100010]; n int main() { n   int val90, val1440, n; n   cin >> n; n   dp[0] = 0; n   unsigned int ar[n + 10]; n   for (int i = 1; i <= n; i++) { n     cin >> ar[i]; n   } n   val1440 = val90 = 1; n   for (int i = 1; i <= n; i++) { n     while (ar[i] - ar[val1440] >= 1440) { n       val1440++; n     } n     while (ar[i] - ar[val90] >= 90) { n       val90++; n     } n     dp[i] = min(dp[i - 1] + 20, dp[val90 - 1] + 50); n     dp[i] = min(dp[i], dp[val1440 - 1] + 120); n     int ans = dp[i] - dp[i - 1]; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n const int maxlog = 24; n int par[maxn][maxlog], h[maxn]; n int siz[maxn]; n bool mark[maxn]; n int n; n vector<int> adj[maxn]; n void dfs(int x) { n   mark[x] = 1; n   for (int i = 0; i < adj[x].size(); i++) { n     int child = adj[x][i]; n     if (!mark[child]) { n       par[child][0] = x; n       h[child] = h[x] + 1; n       dfs(child); n       siz[x] += siz[child] + 1; n     } n   } n } n int LCAH(int fi, int se) { n   for (int i = maxlog - 1; i >= 0; i--) n     if (par[fi][i] != par[se][i]) { n       fi = par[fi][i]; n       se = par[se][i]; n     } n   return n - siz[fi] - siz[se] - 2; n } n int LCA(int fi, int se) { n   for (int i = maxlog - 1; i >= 0; i--) n     if (h[par[fi][i]] >= h[se]) fi = par[fi][i]; n   if (fi == se) return fi; n   for (int i = maxlog - 1; i >= 0; i--) n     if (par[fi][i] != par[se][i]) { n       fi = par[fi][i]; n       se = par[se][i]; n     } n   return par[fi][0]; n } n int main() { n   cin >> n; n   for (int i = 1; i < n; i++) { n     int fi, se; n     cin >> fi >> se; n     adj[fi].push_back(se); n     adj[se].push_back(fi); n   } n   dfs(1); n   for (int j = 1; j < maxlog; j++) n     for (int i = 1; i <= n; i++) par[i][j] = par[par[i][j - 1]][j - 1]; n   int q; n   cin >> q; n   while (q--) { n     int fi, se; n     cin >> fi >> se; n     if (h[fi] < h[se]) swap(fi, se); n     int dis = h[fi] + h[se] - 2 * h[LCA(fi, se)]; n     if (fi == se) n       cout << n << endl; n     else if (dis % 2 == 1) n       cout << 0 << endl; n     else if (h[fi] == h[se]) { n       cout << LCAH(fi, se) << endl; n     } else { n       dis /= 2; n       se = fi; n       for (int i = maxlog - 1; i >= 0; i--) { n         if ((1 << i) & dis) { n           fi = par[fi][i]; n         } n       } n       int k = dis - 1; n       for (int i = maxlog - 1; i >= 0; i--) { n         if ((1 << i) & k) { n           se = par[se][i]; n         } n       } n       cout << siz[fi] - siz[se] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int ALPHABETS = 30; n const int maxN = 410; n bitset<maxN> orig[ALPHABETS][maxN], ans[maxN]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int N, M; n   cin >> N >> M; n   string s; n   for (int i = 0; i < N; i++) { n     cin >> s; n     for (int j = 0; j < M; j++) { n       orig[s[j] -  a ][i][j] = true; n       ans[i][j] = true; n     } n   } n   int R, C; n   cin >> R >> C; n   for (int i = 0; i < R; i++) { n     cin >> s; n     for (int j = 0; j < C; j++) { n       if (s[j] ==  ? ) continue; n       char ch = s[j] -  a ; n       int goForward = j % M; n       for (int k = 0; k < N; k++) { n         int origR = (((k - i) % N) + N) % N; n         ans[origR] &= n             (orig[ch][k] >> goForward) | (orig[ch][k] << (M - goForward)); n       } n     } n   } n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < M; j++) { n       if (ans[i][j]) n         cout <<  1 ; n       else n         cout <<  0 ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   std::cin >> n; n   int t, c; n   int max = 0, cur = 0, lt = -1; n   for (int i = 0; i < n; i++) { n     std::cin >> t >> c; n     if (lt != -1) { n       cur += lt - t; n     } n     if (cur < 0) cur = 0; n     cur += c; n     if (cur > max) max = cur; n     lt = t; n   } n   if (cur < c) cur = c; n   std::cout << lt + cur <<     << max; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 7; n const int N = 230; n const int M = 3500; n int m, n; n int a[N], b[N]; n long long dp[M][N]; n int main() { n   cin >> m >> n; n   memset(dp, 0, sizeof(dp)); n   for (int i = 0; i < m; ++i) { n     cin >> a[i] >> b[i]; n     dp[a[i]][i]++; n     if (a[i] != b[i]) { n       a[i + m] = b[i]; n       b[i + m] = a[i]; n       dp[a[i + m]][i + m]++; n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j < m * 2; ++j) { n       if (!dp[i][j]) continue; n       for (int k = 0; k < 2 * m; ++k) { n         if (j % m != k % m && a[k] == b[j]) n           dp[i + a[k]][k] = (dp[i + a[k]][k] + dp[i][j]) % inf; n       } n     } n   } n   long long ans = 0; n   for (int i = 0; i < 2 * m; ++i) ans = (ans + dp[n][i]) % inf; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200100; n int main() { n   int n = 0, u = 0, v = 0; n   int d[MAXN] = {0}; n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     scanf( %d %d , &u, &v); n     d[u] += 1; n     d[v] += 1; n   } n   for (int i = 1; i <= n; i++) { n     if (d[i] == 2) { n       printf( NO n ); n       return 0; n     } n   } n   printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long x, y, n, c; n bool check(long long t) { n   long long ans = 2 * t * t + 2 * t + 1; n   if (x + t > n) { n     long long m = x + t - n; n     ans -= m * m; n   } n   if (y + t > n) { n     long long m = y + t - n; n     ans -= m * m; n   } n   if (x <= t) { n     long long m = t - x + 1; n     ans -= m * m; n   } n   if (y - t <= 0) { n     long long m = t - y + 1; n     ans -= m * m; n   } n   if (x - 1 + y - 1 < t) { n     long long a = t - (x - 1 + y - 1) - 1; n     ans += a * (a + 1) / 2; n   } n   if (x - 1 + n - y < t) { n     long long a = t - (x - 1 + n - y) - 1; n     ans += a * (a + 1) / 2; n   } n   if (n - x + y - 1 < t) { n     long long a = t - (n - x + y - 1) - 1; n     ans += a * (a + 1) / 2; n   } n   if (n - x + n - y < t) { n     long long a = t - (n - x + n - y) - 1; n     ans += a * (a + 1) / 2; n   } n   return ans >= c; n } n int main() { n   while (cin >> n >> x >> y >> c) { n     long long low = 0, high = 2 * n, mid, ans = 0; n     while (low <= high) { n       mid = (low + high) / 2; n       if (check(mid)) { n         ans = mid; n         high = mid - 1; n       } else n         low = mid + 1; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void gk() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   std::cout.tie(0); n } n int64_t mul(int64_t a, int64_t b) { return (a * b) % (int64_t)1000000007; } n int64_t gcd(int64_t a, int64_t b) { n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n const int64_t sz = 2502; n const int64_t sz2 = 2e6 + 5; n int64_t row[4] = {1, -1, 0, 0}; n int64_t col[4] = {0, 0, -1, 1}; n int64_t val[sz]; n int64_t n; n void find() { n   int64_t n; n   cin >> n; n   vector<int64_t> ar(n); n   unordered_set<int64_t> ans; n   unordered_set<int64_t> curr; n   for (int64_t i = 0; i < n; i++) { n     cin >> ar[i]; n   } n   ans.insert(ar[0]); n   curr.insert(ar[0]); n   for (int64_t i = 1; i < n; i++) { n     unordered_set<int64_t> aux; n     for (int64_t j : curr) { n       aux.insert(j | ar[i]); n     } n     aux.insert(ar[i]); n     curr = aux; n     for (int64_t i : curr) { n       ans.insert(i); n     } n   } n   cout << ans.size(); n } n int32_t main() { n   int64_t t = 1; n   while (t--) { n     find(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, edge; n pair<int, int> E[2][200002]; n vector<int> V[2][200002]; n int in[2][200002], out[2][200002]; n bool S[2][200002], isdel[2][200002]; n vector<pair<pair<int, int>, int> > ARBf[2][4 * 200002], ARBs[2][4 * 200002]; n int Ap1, Ap2, Apv, Ax1, Ax2; n vector<int> auxst; n void updatef(int w, int nod, int i1, int i2) { n   ARBf[w][nod].push_back(make_pair(make_pair(Ap1, Ap2), Apv)); n   if (i1 == i2) return; n   int mid = (i1 + i2) / 2; n   if (Ap1 <= mid) n     updatef(w, nod * 2, i1, mid); n   else n     updatef(w, nod * 2 + 1, mid + 1, i2); n } n void erasef(int w, int nod, int i1, int i2) { n   if (Ax1 <= i1 && i2 <= Ax2) { n     while (!ARBf[w][nod].empty() && (ARBf[w][nod].back().first.second > Ax2 || n                                      isdel[w][ARBf[w][nod].back().second])) { n       if (!isdel[w][ARBf[w][nod].back().second]) { n         auxst.push_back(ARBf[w][nod].back().second); n         isdel[w][ARBf[w][nod].back().second] = true; n       } n       ARBf[w][nod].pop_back(); n     } n     return; n   } n   int mid = (i1 + i2) / 2; n   if (Ax1 <= mid) erasef(w, nod * 2, i1, mid); n   if (Ax2 > mid) erasef(w, nod * 2 + 1, mid + 1, i2); n } n void updates(int w, int nod, int i1, int i2) { n   ARBs[w][nod].push_back(make_pair(make_pair(Ap1, Ap2), Apv)); n   if (i1 == i2) return; n   int mid = (i1 + i2) / 2; n   if (Ap2 <= mid) n     updates(w, nod * 2, i1, mid); n   else n     updates(w, nod * 2 + 1, mid + 1, i2); n } n void erases(int w, int nod, int i1, int i2) { n   if (Ax1 <= i1 && i2 <= Ax2) { n     while (!ARBs[w][nod].empty() && (ARBs[w][nod].back().first.first < Ax1 || n                                      isdel[w][ARBs[w][nod].back().second])) { n       if (!isdel[w][ARBs[w][nod].back().second]) { n         auxst.push_back(ARBs[w][nod].back().second); n         isdel[w][ARBs[w][nod].back().second] = true; n       } n       ARBs[w][nod].pop_back(); n     } n     return; n   } n   int mid = (i1 + i2) / 2; n   if (Ax1 <= mid) erases(w, nod * 2, i1, mid); n   if (Ax2 > mid) erases(w, nod * 2 + 1, mid + 1, i2); n } n void Dfs(int w, int x) { n   S[w][x] = true; n   in[w][x] = ++in[w][0]; n   for (auto it = V[w][x].begin(); it != V[w][x].end(); ++it) n     if (!S[w][*it]) Dfs(w, *it); n   out[w][x] = in[w][0]; n } n int main() { n   cin.sync_with_stdio(false); n   cin >> N; n   for (int w = 0; w < 2; ++w) n     for (int i = 2, nod; i <= N; ++i) { n       cin >> nod; n       V[w][i].push_back(nod); n       V[w][nod].push_back(i); n       E[w][i - 1] = make_pair(min(i, nod), max(i, nod)); n     } n   cin >> edge; n   for (int w = 0; w < 2; ++w) Dfs(w, 1); n   for (int w = 0; w < 2; ++w) { n     vector<pair<pair<int, int>, int> > aux; n     for (int i = 1; i <= N - 1; ++i) { n       if (w == 0 && i == edge) continue; n       Ap1 = in[!w][E[w][i].first], Ap2 = in[!w][E[w][i].second], Apv = i; n       if (Ap1 > Ap2) swap(Ap1, Ap2); n       aux.push_back(make_pair(make_pair(Ap1, Ap2), Apv)); n     } n     sort(aux.begin(), aux.end()); n     for (int i = int(aux.size()) - 1; i >= 0; --i) { n       Ap1 = aux[i].first.first, Ap2 = aux[i].first.second, Apv = aux[i].second; n       updates(w, 1, 1, N); n       swap(aux[i].first.first, aux[i].first.second); n     } n     sort(aux.begin(), aux.end()); n     for (int i = 0; i < int(aux.size()); ++i) { n       swap(aux[i].first.first, aux[i].first.second); n       Ap1 = aux[i].first.first, Ap2 = aux[i].first.second, Apv = aux[i].second; n       updatef(w, 1, 1, N); n     } n   } n   vector<int> st; n   st.push_back(edge); n   for (int i = 0; !st.empty(); ++i) { n     if (i & 1) n       printf( Red n ); n     else n       printf( Blue n ); n     int w = i % 2; n     auxst.clear(); n     sort(st.begin(), st.end()); n     for (int j = 0; j < int(st.size()); ++j) { n       int e = st[j]; n       printf( %d  , e); n       if (in[w][E[w][e].first] < in[w][E[w][e].second]) { n         Ax1 = in[w][E[w][e].second]; n         Ax2 = out[w][E[w][e].second]; n       } else { n         Ax1 = in[w][E[w][e].first]; n         Ax2 = out[w][E[w][e].first]; n       } n       erasef(!w, 1, 1, N); n       erases(!w, 1, 1, N); n     } n     st = auxst; n     printf(  n ); n   } n } n