#include <bits/stdc++.h> n using namespace std; n int S[2][500005 * 4], pre[500005], suf[500005]; n long long hpr1[3][500005], hpr2[3][500005], hsf1[3][500005], hsf2[3][500005], n     pww[3][500005]; n int n, m, k; n long long pr[3] = {79, 103, 211}; n bool flag; n char a[500005], b[500005]; n vector<int> sss[500005], ppp[500005]; n int get(int node, int bas, int son, int x, int y, int w) { n   if (bas > y || son < x) return (w ? -1 : 1900000000); n   if (bas >= x && son <= y) { n     if (bas == son) { n       if (S[w][node]) { n         flag = true; n         return bas; n       } n       return 1900000000; n     } n     if (w) { n       if (S[w][node * 2 + 1]) n         return get(node * 2 + 1, ((bas + son) / 2) + 1, son, x, y, w); n       else if (S[w][node * 2]) n         return get(node * 2, bas, ((bas + son) / 2), x, y, w); n       else n         return -1; n     } else { n       if (S[w][node * 2]) n         return get(node * 2, bas, ((bas + son) / 2), x, y, w); n       else if (S[w][node * 2 + 1]) n         return get(node * 2 + 1, ((bas + son) / 2) + 1, son, x, y, w); n       else n         return 1900000000; n     } n   } n   if (w) { n     int res = get(node * 2 + 1, ((bas + son) / 2) + 1, son, x, y, w); n     if (flag) return res; n     return get(node * 2, bas, ((bas + son) / 2), x, y, w); n   } else { n     int res = get(node * 2, bas, ((bas + son) / 2), x, y, w); n     if (flag) return res; n     return get(node * 2 + 1, ((bas + son) / 2) + 1, son, x, y, w); n   } n } n void up(int node, int bas, int son, int x, int val, int w) { n   if (bas > x || son < x) return; n   if (bas == x && son == x) { n     S[w][node] = val; n     return; n   } n   up(node * 2, bas, ((bas + son) / 2), x, val, w); n   up(node * 2 + 1, ((bas + son) / 2) + 1, son, x, val, w); n   S[w][node] = S[w][node * 2] + S[w][node * 2 + 1]; n } n void build(int node, int bas, int son, int w) { n   if (bas == son) { n     S[w][node] = 1; n     return; n   } n   build(node * 2, bas, ((bas + son) / 2), w); n   build(node * 2 + 1, ((bas + son) / 2) + 1, son, w); n   S[w][node] = S[w][node * 2] + S[w][node * 2 + 1]; n } n pair<pair<long long, long long>, long long> suf2(int bas, int son) { n   return {{hsf2[0][son] - hsf2[0][bas + 1] * pww[0][bas - son + 1], n            hsf2[1][son] - hsf2[1][bas + 1] * pww[1][bas - son + 1]}, n           hsf2[2][son] - hsf2[2][bas + 1] * pww[2][bas - son + 1]}; n } n pair<pair<long long, long long>, long long> suf1(int bas, int son) { n   return {{hsf1[0][son] - hsf1[0][bas + 1] * pww[0][bas - son + 1], n            hsf1[1][son] - hsf1[1][bas + 1] * pww[1][bas - son + 1]}, n           hsf1[2][son] - hsf1[2][bas + 1] * pww[2][bas - son + 1]}; n } n pair<pair<long long, long long>, long long> pre2(int bas, int son) { n   return {{hpr2[0][son] - hpr2[0][bas - 1] * pww[0][son - bas + 1], n            hpr2[1][son] - hpr2[1][bas - 1] * pww[1][son - bas + 1]}, n           hpr2[2][son] - hpr2[2][bas - 1] * pww[2][son - bas + 1]}; n } n pair<pair<long long, long long>, long long> pre1(int bas, int son) { n   return {{hpr1[0][son] - hpr1[0][bas - 1] * pww[0][son - bas + 1], n            hpr1[1][son] - hpr1[1][bas - 1] * pww[1][son - bas + 1]}, n           hpr1[2][son] - hpr1[2][bas - 1] * pww[2][son - bas + 1]}; n } n void hashsuf() { n   for (int i = n; i >= 1; i--) { n     for (int j = 0; j < 3; j++) { n       hsf1[j][i] = hsf1[j][i + 1] * pr[j] + a[i] -  a  + 1; n     } n   } n   for (int i = m; i >= 1; i--) { n     for (int j = 0; j < 3; j++) { n       hsf2[j][i] = hsf2[j][i + 1] * pr[j] + b[i] -  a  + 1; n     } n   } n } n void hashpre() { n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 3; j++) { n       hpr1[j][i] = hpr1[j][i - 1] * pr[j] + a[i] -  a  + 1; n     } n   } n   for (int i = 1; i <= m; i++) { n     for (int j = 0; j < 3; j++) { n       hpr2[j][i] = hpr2[j][i - 1] * pr[j] + b[i] -  a  + 1; n     } n   } n } n pair<int, int> getsuf(int from, int len) { n   flag = false; n   int pos = get(1, 1, n, from + len - 1, n - (k - len), 1); n   int be = pos - len + 1; n   int en = pos + (k - len); n   if (be < from || en > n) return {1900000000, 1900000000}; n   return {be, en}; n } n int main() { n   scanf( %d %d %d , &n, &m, &k); n   scanf( %s , a + 1); n   scanf( %s , b + 1); n   hashpre(); n   hashsuf(); n   pww[0][0] = pww[1][0] = pww[2][0] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < 3; j++) pww[j][i] = pww[j][i - 1] * pr[j]; n   for (int i = 1; i <= n; i++) { n     int bas = 1, son = min(m, n - i + 1); n     while (bas <= son) { n       if (pre1(i, i + ((bas + son) / 2) - 1) == pre2(1, ((bas + son) / 2))) n         bas = ((bas + son) / 2) + 1; n       else n         son = ((bas + son) / 2) - 1; n     } n     pre[i] = son; n     ppp[son].push_back(i); n     bas = 1, son = min(m, i); n     while (bas <= son) { n       if (suf1(i, i - ((bas + son) / 2) + 1) == n           suf2(m, m - ((bas + son) / 2) + 1)) n         bas = ((bas + son) / 2) + 1; n       else n         son = ((bas + son) / 2) - 1; n     } n     suf[i] = son; n     sss[son].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     if (pre[i] == m && m <= k) { n       int mxen = min(n, i + k - 1); n       int mnbe = max(1, i - k + 1); n       if (mxen - 2 * k + 1 >= 1) { n         printf( Yes n%d %d , mxen - 2 * k + 1, mxen - k + 1); n         return 0; n       } n       if (mnbe + 2 * k - 1 <= n) { n         printf( Yes n%d %d , mnbe, mnbe + k); n         return 0; n       } n     } n   } n   build(1, 1, n, 0); n   for (int i = 0; i <= min(k, m); i++) { n     for (int j = 0; j < (int)sss[m - i].size(); j++) n       up(1, 1, n, sss[m - i][j], 1, 1); n     flag = false; n     int pos = get(1, 1, n, k - i + 1, n, 0); n     for (int j = 0; j < (int)ppp[i].size(); j++) up(1, 1, n, ppp[i][j], 0, 0); n     if (m - i > k) continue; n     int en = pos + i - 1; n     int be = en - k + 1; n     if (en > n || be < 1) continue; n     pair<int, int> res = getsuf(en + 1, m - i); n     if (res.first < en + 1 || res.second > n) continue; n     printf( Yes n%d %d , be, res.first); n     return 0; n   } n   printf( No ); n } n


#include <bits/stdc++.h> n int read() { n   int r = 0, t = 1, c = getchar(); n   while (c <  0  || c >  9 ) { n     t = c ==  -  ? -1 : 1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     r = (r << 3) + (r << 1) + (c ^ 48); n     c = getchar(); n   } n   return r * t; n } n const int N = 200010; n int n; n int c1, c2; n std::vector<int> e[N]; n int dfs(int u, int f) { n   int c = 0; n   for (auto v : e[u]) n     if (v != f) c += dfs(v, u); n   if (c) { n     c1++; n     c2 += c; n     return 0; n   } else n     return 1; n } n int main() { n   for (int T = (1), end_T = (read()); T <= end_T; T++) { n     n = read(); n     c1 = c2 = 0; n     for (int i = (1), end_i = (n); i <= end_i; i++) e[i].clear(); n     for (int i = (1), end_i = (n - 1); i <= end_i; i++) { n       int u = read(), v = read(); n       e[u].push_back(v); n       e[v].push_back(u); n     } n     dfs(1, 0); n     printf( %d n , c2 - (c1 - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   vector<pair<long long, char> > v; n   vector<long long> freq(27, 0); n   string s2(s.length(),  1 ); n   vector<long long> vis(s.length() + 1, 0); n   for (long long i = 0; i < s.length(); i++) { n     freq[s[i] -  a ]++; n   } n   for (long long i = 0; i < 27; i++) { n     char c = i +  a ; n     if (freq[i] > 0) v.push_back({freq[i], c}); n   } n   sort(v.begin(), v.end()); n   reverse(v.begin(), v.end()); n   long long n = s.length(); n   long long cnt = 0; n   for (long long i = 2; i <= n; i += 2) { n     vis[i] = 1; n     cnt++; n   } n   for (long long i = 2; i <= n; i += 1) { n     bool add = false; n     if (!vis[i]) n       for (long long j = i; j <= n; j += i) { n         if (vis[j]) add = true; n       } n     if (!add) continue; n     for (long long j = i; j <= n; j += i) { n       if (!vis[j]) cnt++; n       vis[j] = 1; n     } n   } n   if (v[0].first < (cnt)) { n     cout <<  NO ; n     return 0; n   } n   long long i; n   for (i = 2; i <= n; i++) { n     if (!vis[i]) continue; n     s2[i - 1] = v[0].second; n     v[0].first--; n     vis[i] = 1; n   } n   long long k = 0; n   for (i = 1; i <= n; i++) { n     if (!vis[i]) { n       if (v[k].first == 0) { n         k++; n       } n       s2[i - 1] = v[k].second; n       v[k].first--; n     } n   } n   cout <<  YES n ; n   cout << s2; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 405; n int a[MAXN], v[MAXN]; n int n; n void work(int x) { n   memset(v, 0, sizeof(v)); n   for (int i = 1; x != 0; i++) { n     v[i] = x / a[i]; n     x %= a[i]; n   } n } n int work2(int x) { n   int res = 0; n   for (int i = 1; x != 0; i++) { n     res += x / a[i]; n     x %= a[i]; n   } n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int ans = -1; n   for (int i = 1; i < n; i++) { n     work(a[i] - 1); n     for (int j = i + 1; j <= n; j++) { n       int s = 0, m = 0; n       for (int k = i; k < j; k++) { n         s += v[k] * a[k]; n         m += v[k]; n       } n       s += (v[j] + 1) * a[j]; n       m += (v[j] + 1); n       if (work2(s) > m) { n         if (ans == -1 || s < ans) ans = s; n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef int arr32[5000010]; n arr32 x, rk, l, r; n int n; n long long ans; n bool cmp(const int &a, const int &b) { return x[a] < x[b]; } n void erase(int x) { r[l[x]] = r[x], l[r[x]] = l[x]; } n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , x + i); n     rk[i] = i, l[i] = i - 1, r[i] = i + 1; n   } n   sort(rk + 1, rk + n + 1, cmp); n   for (int i = 1; i <= n - 2; ++i) { n     int p = rk[i]; n     if (l[p] == 0) n       ans += x[p], erase(p); n     else if (r[p] == n + 1) n       ans += x[p], erase(p); n     else n       ans += min(x[l[p]], x[r[p]]), erase(p); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n int main() { n   int ss, x, y, flag = 0, kk, flag2 = 1; n   scanf( %d%d%d , &ss, &x, &y); n   if (x == 1 || x == ss) flag++; n   if (y == 1 || y == ss) flag++; n   if (x >= ss / 2 && x <= ss / 2 + 1 && y >= ss / 2 && y <= ss / 2 + 1) n     flag2 = 0; n   if (flag == 0) kk = 9; n   if (flag == 1) kk = 6; n   if (flag == 2) kk = 4; n   printf( %s n , (ss * ss >= kk * 2 && flag2) ?  YES  :  NO ); n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 60 + 5; n char a[N][N]; n int l[N][N]; n int r[N][N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int m, n; n     cin >> n >> m; n     for (int i = 1; i <= n; i++) cin >> (a[i] + 1); n     int f1 = 0, f2 = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         if (a[i][j] ==  A ) f1 = 1; n         if (a[i][j] ==  P ) f2 = 1; n       } n     } n     if (!f2) { n       printf( 0 n ); n       continue; n     } n     if (!f1) { n       printf( MORTAL n ); n       continue; n     } n     int visl = 0, visb = 0, visj = 0; n     if (a[1][1] ==  A  || a[1][m] ==  A  || a[n][1] ==  A  || a[n][m] ==  A ) n       visj = 1; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         if (i == 1 || j == 1 || i == n || j == m) { n           if (a[i][j] ==  A ) visb = 1; n         } n         if (a[i][j] ==  A ) l[i][j] = l[i][j - 1] + 1; n       } n       if (l[i][m] == m) visl = 1; n     } n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         if (a[i][j] ==  A ) r[i][j] = r[i - 1][j] + 1; n         if (r[n][j] == n) visl = 1; n       } n     } n     int visjl = 0; n     if (r[n][m] == n || l[n][m] == m || r[n][1] == n || l[1][m] == m) visjl = 1; n     if (visjl) n       printf( 1 n ); n     else if (visj) n       printf( 2 n ); n     else if (visl && visb) n       printf( 2 n ); n     else if (visb) n       printf( 3 n ); n     else n       printf( 4 n ); n     memset(l, 0, sizeof l); n     memset(r, 0, sizeof r); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 2; n unsigned long long h[N]; n int p[N]; n bool ed[N], flg[N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count()); n   unordered_map<unsigned long long, int> mp; n   int n, m = 0, i, j, k; n   unsigned long long tot = 0; n   cin >> n; n   for (i = 2; i <= n; i++) { n     if (!ed[i]) p[m++] = i, h[i] = rnd(); n     for (j = 0; j < m && (k = i * p[j]) <= n; j++) { n       ed[k] = 1; n       h[k] = h[i] ^ h[p[j]]; n       if (i % p[j] == 0) break; n     } n     if (1 ^ n - i & 1) tot ^= h[i]; n   } n   for (i = 3; i <= n; i++) h[i] ^= h[i - 1]; n   fill(flg + 1, flg + n + 1, 1); n   if (tot == 0) goto out; n   for (i = 1; i <= n; i++) n     if (tot == h[i]) { n       flg[i] = 0; n       goto out; n     } n   for (i = 1; i <= n; i++) { n     auto it = mp.find(tot ^ h[i]); n     if (it != mp.end()) { n       flg[i] = flg[it->second] = 0; n       goto out; n     } n     mp[h[i]] = i; n   } n   flg[n >> 1] = flg[2] = flg[n] = 0; n out: n   cout << accumulate(flg + 1, flg + n + 1, 0) <<   n ; n   for (int i = 1; i <= n; i++) n     if (flg[i]) cout << i <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unsigned long long a, b; n   cin >> a >> b; n   while (a != 0 && b != 0) { n     if (a >= 2 * b) { n       a = a % (2 * b); n     } else if (b >= 2 * a) { n       b = b % (a * 2); n     } else n       break; n   } n   cout << a <<     << b << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = 3.1415926535897932384626433; n const int mod = 1000000007; n const long long inf = 3e18; n long long n, m, k; n long long dp[5001][5001]; n vector<long long> v; n long long mkc(long long i, long long j) { n   if (j == 0 or i >= v.size()) { n     return 0; n   } n   if (dp[i][j] != -1) return dp[i][j]; n   long long ans = 0; n   ans = max(mkc(i + 1, j), v[i] + mkc(i + m, j - 1)); n   return dp[i][j] = ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   memset(dp, -1, sizeof(dp)); n   cin >> n >> m >> k; n   vector<long long> a(n), pre(n); n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   pre[0] = a[0]; n   for (long long i = 1; i < n; i++) { n     pre[i] = pre[i - 1] + a[i]; n   } n   for (long long i = n - 1; i >= m; i--) { n     pre[i] = pre[i] - pre[i - m]; n   } n   for (long long i = m - 1; i < n; i++) { n     v.push_back(pre[i]); n   } n   cout << mkc(0, k); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 5; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) { n     long long x, y, n; n     cin >> x >> y >> n; n     long long rem = n % x; n     long long ans = n - rem; n     if (ans + y <= n) { n       cout << ans + y <<   n ; n     } else { n       ans -= (x - y); n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T0, typename T1> n bool chkmin(T0 &a, const T1 &b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T0, typename T1> n bool chkmax(T0 &a, const T1 &b) { n   return a < b ? a = b, 1 : 0; n } n const int oo = 0x3f3f3f3f, Max_val = 314000000; n const int maxn = 100000, maxm = 100000; n int deg[maxn + 5]; n pair<pair<int, int>, int> all[maxm + 5]; n int tmp[maxm + 5] = {0}; n vector<int> yyt[maxn + 5]; n bool vis[maxn + 5] = {0}; n int Min[maxn + 5]; n int Max[maxn + 5]; n vector<int> zzj[maxm + 5]; n vector<int> owaski[maxn + 5]; n int find(const int &first) { n   if (vis[first]) return -2; n   if (Max[first]) return Max[first]; n   vis[first] = 1; n   Max[first] = -2; n   for (int i = (0), _end_ = ((int((owaski[first]).size()))); i != _end_; ++i) { n     const int &second = owaski[first][i]; n     int tmp = ::tmp[second]; n     for (int j = (0), _end_ = ((int((zzj[second]).size()))); j != _end_; ++j) { n       const int &k = zzj[second][j]; n       int tmp0 = find(k); n       if (tmp0 == -1) n         goto yyt; n       else if (tmp0 == -2) n         tmp = -2; n       else if (tmp != -2) n         chkmin(tmp += tmp0, Max_val); n     } n     if (tmp == -2) { n       Max[first] = -2; n       vis[first] = 0; n       return Max[first]; n     } n     Max[first] = max(Max[first], tmp); n   yyt:; n   } n   vis[first] = 0; n   return Max[first]; n } n int m, n; n int main() { n   memset(Min, oo, sizeof Min); n   scanf( %d%d , &m, &n); n   for (int i = (0), _end_ = (m); i != _end_; ++i) { n     scanf( %d , &all[i].first.first), --all[i].first.first; n     static int nn; n     scanf( %d , &nn); n     all[i].first.second = tmp[i] = 0; n     owaski[all[i].first.first].push_back(i); n     for (int j = (0), _end_ = (nn); j != _end_; ++j) { n       static int first; n       scanf( %d , &first); n       if (first == -1) n         ++all[i].first.second, ++tmp[i]; n       else n         --first, ++all[i].second, yyt[first].push_back(i), n             zzj[i].push_back(first); n     } n   } n   for (int i = (0), _end_ = (m); i != _end_; ++i) n     if (!all[i].second) chkmin(Min[all[i].first.first], all[i].first.second); n   priority_queue<pair<int, int>, vector<pair<int, int> >, n                  greater<pair<int, int> > > n       q; n   for (int i = (0), _end_ = (n); i != _end_; ++i) n     if (Min[i] < oo) q.push(make_pair(Min[i], i)); n   while (!q.empty()) { n     int first = q.top().second; n     q.pop(); n     if (vis[first]) continue; n     vis[first] = 1; n     for (int i = (0), _end_ = ((int((yyt[first]).size()))); i != _end_; ++i) { n       const int &second = yyt[first][i]; n       all[second].first.second = n           min(all[second].first.second + Min[first], Max_val); n       if (!--all[second].second && n           chkmin(Min[all[second].first.first], all[second].first.second)) n         q.push( n             make_pair(Min[all[second].first.first], all[second].first.first)); n     } n   } n   memset(vis, 0, sizeof vis); n   memset(Max, 0, sizeof Max); n   for (int i = (0), _end_ = (n); i != _end_; ++i) n     if (Min[i] == oo) Min[i] = Max[i] = -1; n   for (int i = (0), _end_ = (n); i != _end_; ++i) { n     find(i); n     printf( %d %d n , Min[i], Max[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n int INF = 2147483647; n double INFD = 2147483647; n double PI = 3.14159265359; n using namespace std; n struct Child { n   Child(long long v_, long long d_, long long p_) { n     gone = false; n     v = v_; n     d = d_; n     p = p_; n   } n   bool gone; n   long long v; n   long long d; n   long long p; n }; n int Enter(vector<Child>& kids, int base) { n   long long v = kids[base].v, deduction = 0; n   int gone_kid = -1; n   kids[base].gone = true; n   base++; n   while (deduction < v && base < kids.size()) { n     if (!kids[base].gone) { n       kids[base].p -= v - deduction; n       if (kids[base].p < 0 && gone_kid == -1) { n         gone_kid = base; n       } n       deduction++; n     } n     base++; n   } n   return gone_kid; n } n void print(vector<Child>& kids) { n   int i = 0; n   while (i < kids.size()) { n     Child c = kids[i]; n     cout << i + 1 <<  :   << c.v <<     << c.d <<     << c.p; n     if (c.gone) { n       cout <<   -------- ; n     } n     cout << endl; n     i++; n   } n } n void Deduce(vector<Child>& kids, int base) { n   long long deduction = 0; n   int i = base; n   while (i < kids.size()) { n     if (!kids[i].gone) { n       kids[i].p -= deduction; n       if (kids[i].p < 0) { n         kids[i].gone = true; n         deduction += kids[i].d; n       } n     } n     i++; n   } n } n int main() { n   int n = 0; n   cin >> n; n   vector<Child> kids(n, Child(0, 0, 0)); n   vector<int> entered; n   int i = 0; n   while (i < n) { n     cin >> kids[i].v >> kids[i].d >> kids[i].p; n     i++; n   } n   i = 0; n   while (i < n) { n     if (!kids[i].gone) { n       entered.push_back(i); n       int gone_kid = Enter(kids, i); n       if (gone_kid != -1) { n         Deduce(kids, gone_kid); n       } n     } n     i++; n   } n   cout << entered.size() << endl; n   i = 0; n   while (i < entered.size()) { n     if (i) { n       cout <<    ; n     } n     cout << entered[i] + 1; n     i++; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 55; n int res[N][N][N][N]; n int tmp[N][N], dat[N][N]; n string s[N]; n int n, m, q, a, b, c, d; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> q; n   for (int i = 1; i <= n; i++) { n     cin >> s[i]; n     for (int j = 1; j <= m; j++) dat[i][j] = (s[i][j - 1] ==  1 ); n   } n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= m; j++) { n       if (i == 0 || j == 0) continue; n       tmp[i][j] = tmp[i - 1][j] + tmp[i][j - 1] - tmp[i - 1][j - 1] + dat[i][j]; n     } n   } n   for (int xa = 1; xa <= n; xa++) n     for (int ya = 1; ya <= m; ya++) n       for (int xb = 1; xb <= n; xb++) n         for (int yb = 1; yb <= m; yb++) { n           int sum = tmp[xb][yb] - tmp[xa - 1][yb] - tmp[xb][ya - 1] + n                     tmp[xa - 1][ya - 1]; n           res[xa][ya][xb][yb] = (sum == 0); n         } n   for (int xa = n; xa >= 2; xa--) n     for (int ya = 1; ya <= m; ya++) n       for (int xb = xa; xb <= n; xb++) n         for (int yb = ya; yb <= m; yb++) n           res[xa - 1][ya][xb][yb] += res[xa][ya][xb][yb]; n   for (int xa = 1; xa <= n; xa++) n     for (int ya = m; ya >= 2; ya--) n       for (int xb = xa; xb <= n; xb++) n         for (int yb = ya; yb <= m; yb++) n           res[xa][ya - 1][xb][yb] += res[xa][ya][xb][yb]; n   for (int xa = 1; xa <= n; xa++) n     for (int ya = 1; ya <= m; ya++) n       for (int xb = xa; xb <= n; xb++) n         for (int yb = ya; yb <= m; yb++) n           res[xa][ya][xb + 1][yb] += res[xa][ya][xb][yb]; n   for (int xa = 1; xa <= n; xa++) n     for (int ya = 1; ya <= m; ya++) n       for (int xb = xa; xb <= n; xb++) n         for (int yb = ya; yb <= m; yb++) n           res[xa][ya][xb][yb + 1] += res[xa][ya][xb][yb]; n   while (q--) { n     cin >> a >> b >> c >> d; n     cout << res[a][b][c][d] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, k, a[200005]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   while (t--) { n     cin >> n >> k; n     for (long long i = 0; i < n; i++) cin >> a[i]; n     long long Min = k; n     for (long long i = k; i < n; i++) n       if (a[i] - a[i - k] < a[Min] - a[Min - k]) Min = i; n     cout << (a[Min] + a[Min - k]) / 2 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long ax, ay, bx, by, cx, cy; n void check(long long xx, long long yy) { n   if (cx == 0 && cy == 0) { n     if (xx == 0 && yy == 0) { n       cout <<  YES ; n       exit(0); n     } else n       return; n   } n   if ((cx * (yy)-cy * (xx)) % (cx * cx + cy * cy) != 0 || n       (cx * (xx) + cy * (yy)) % (cx * cx + cy * cy) != 0) n     return; n   cout <<  YES ; n   exit(0); n } n int main() { n   cin >> ax >> ay >> bx >> by >> cx >> cy; n   check(bx - ax, by - ay); n   check(bx - ay, by + ax); n   check(bx + ax, by + ay); n   check(bx + ay, by - ax); n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 356438; n int from[N], to[N], limL, nextp[N], headp[N], p[N], Lcnt[N], chcnt[N], num, n     a[N], b[N], sz, c[N]; n bool taboo[N], boo[N]; n long long limW, W[N], Wcnt[N], ans; n inline int lowbit(int x) { return x & (-x); } n inline int ask(int x) { n   int ans = 0; n   while (x) { n     ans += c[x]; n     x -= lowbit(x); n   } n   return ans; n } n inline void add(int x, int y) { n   while (x < N) { n     c[x] += y; n     x += lowbit(x); n   } n } n inline void addedge(int x, int y, long long z, int &tot) { n   from[tot] = x; n   to[tot] = y; n   W[tot] = z; n   nextp[tot] = headp[x]; n   headp[x] = tot; n   ++tot; n } n void dfs(int x) { n   a[sz] = x; n   ++sz; n   chcnt[x] = 1; n   for (int i = headp[x]; i != -1; i = nextp[i]) { n     if (taboo[i]) continue; n     int y = to[i]; n     if (p[x] != -1 && from[p[x]] == y) continue; n     p[y] = i; n     dfs(y); n     chcnt[x] += chcnt[y]; n   } n } n void dfs2(int x, bool b) { n   boo[x] = b; n   for (int i = headp[x]; i != -1; i = nextp[i]) { n     if (taboo[i]) continue; n     int y = to[i]; n     if (p[x] != -1 && from[p[x]] == y) continue; n     p[y] = i; n     Lcnt[y] = Lcnt[x] + 1; n     Wcnt[y] = Wcnt[x] + W[i]; n     dfs2(y, b); n   } n } n inline bool cmpb(int x, int y) { n   if (Wcnt[x] != Wcnt[y]) return Wcnt[x] < Wcnt[y]; n   if (Lcnt[x] != Lcnt[y]) return Lcnt[x] < Lcnt[y]; n   return boo[x] < boo[y]; n } n void work(int root) { n   p[root] = -1; n   Lcnt[root] = 0; n   Wcnt[root] = 0; n   sz = 0; n   dfs(root); n   if (sz == 1) return; n   int tempsz = 0, tempedge = -1; n   for (int i = 1; i < sz; ++i) { n     int x = a[i]; n     if (min(chcnt[x], sz - chcnt[x]) > tempsz) { n       tempsz = min(chcnt[x], sz - chcnt[x]); n       tempedge = p[x]; n     } n   } n   taboo[tempedge] = taboo[tempedge ^ 1] = true; n   Lcnt[from[tempedge]] = 0; n   Wcnt[from[tempedge]] = 0; n   p[from[tempedge]] = -1; n   dfs2(from[tempedge], true); n   Lcnt[to[tempedge]] = 0; n   Wcnt[to[tempedge]] = 0; n   p[to[tempedge]] = -1; n   dfs2(to[tempedge], false); n   for (int i = 0; i < sz; ++i) { n     int x = a[i]; n     if (boo[x]) { n       Lcnt[x] = limL - Lcnt[x] - 1; n       Wcnt[x] = limW - Wcnt[x] - W[tempedge]; n     } n     b[i] = x; n   } n   sort(b, b + sz, cmpb); n   for (int i = 0; i < sz; ++i) { n     int x = b[i]; n     if (boo[x]) { n       if (Lcnt[x] < 0) continue; n       ans += ask(Lcnt[x] + 1); n     } else { n       add(Lcnt[x] + 1, 1); n     } n   } n   for (int i = 0; i < sz; ++i) { n     int x = b[i]; n     if (boo[x]) { n     } else { n       add(Lcnt[x] + 1, -1); n     } n   } n   work(to[tempedge]); n   work(from[tempedge]); n } n int main() { n   int n; n   scanf( %d%d%I64d , &n, &limL, &limW); n   int tot = 0; n   memset(headp, -1, sizeof(headp)); n   for (int i = 2; i <= n; ++i) { n     int j; n     long long temp; n     scanf( %d %I64d , &j, &temp); n     addedge(i, j, temp, tot); n     addedge(j, i, temp, tot); n   } n   work(1); n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int K = 7; n const int N = 2005; n int a[K][N]; n vector<int> s[N]; n int d[N], n, k, p; n void read() { n   cin >> n >> k; n   for (int i = 0; i < int(k); ++i) { n     for (int j = 0; j < int(n); ++j) { n       cin >> p; n       --p; n       if (i == 0) n         a[i][j] = p; n       else n         a[i][p] = j; n     } n   } n } n inline bool can_be_next(const vector<int>& a, const vector<int>& b) { n   assert(a.size() == b.size()); n   for (int i = 0; i < int(a.size()); ++i) { n     if (b[i] <= a[i]) return false; n   } n   return true; n } n void solve() { n   for (int i = 0; i < int(n); ++i) { n     s[i] = vector<int>(k - 1); n     for (int j = 1; j < k; ++j) s[i][j - 1] = a[j][a[0][i]]; n   } n   int res = 0; n   for (int i = 0; i < int(n); ++i) { n     d[i] = 1; n     for (int j = 0; j < int(i); ++j) n       if (can_be_next(s[j], s[i])) d[i] = max(d[j] + 1, d[i]); n     res = max(res, d[i]); n   } n   cout << res << endl; n } n int main() { n   read(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   long long ans = 0; n   for (int i = 1; i <= n; i++) ans += abs(a[i - 1] - i); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using point = pair<int, int>; n int D(point a, point b, point c) { n   return a.first * (b.second - c.second) - a.second * (b.first - c.first) + n          (b.first * c.second - b.second * c.first); n } n int main() { n   int n, d; n   cin >> n >> d; n   vector<point> poligon; n   poligon.push_back(make_pair(0, d)); n   poligon.push_back(make_pair(d, 0)); n   poligon.push_back(make_pair(n, n - d)); n   poligon.push_back(make_pair(n - d, n)); n   poligon.push_back(poligon[0]); n   int k; n   cin >> k; n   vector<point> points(k); n   for (auto &[x, y] : points) cin >> x >> y; n   for (auto each : points) { n     int s1 = 0, s2 = 0; n     for (int i = 0; i < poligon.size() - 1; ++i) { n       int test = D(each, poligon[i], poligon[i + 1]); n       if (test > 0) n         s1++; n       else if (test < 0) n         s2++; n     } n     if (s2 == 0 or s1 == 0) 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 vector<long long> prevSmall(vector<long long> &a, long long n) { n   vector<long long> res(n, -1); n   for (long long i = 1; i < n; ++i) { n     long long j = i - 1; n     while (j >= 0 && a[j] >= a[i]) j = res[j]; n     res[i] = j; n   } n   return res; n } n vector<long long> nextSmall(vector<long long> &a, long long n) { n   vector<long long> res(n, n); n   for (long long i = n - 2; i >= 0; --i) { n     long long j = i + 1; n     while (j < n && a[j] > a[i]) j = res[j]; n     res[i] = j; n   } n   return res; n } n vector<long long> prevLarge(vector<long long> &a, long long n) { n   vector<long long> res(n, -1); n   for (long long i = 1; i < n; ++i) { n     long long j = i - 1; n     while (j >= 0 && a[j] <= a[i]) j = res[j]; n     res[i] = j; n   } n   return res; n } n vector<long long> nextLarge(vector<long long> &a, long long n) { n   vector<long long> res(n, n); n   for (long long i = n - 2; i >= 0; --i) { n     long long j = i + 1; n     while (j < n && a[j] < a[i]) j = res[j]; n     res[i] = j; n   } n   return res; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   { n     long long n; n     cin >> n; n     vector<long long> a(n); n     for (long long i = 0; i < (n); ++i) cin >> a[i]; n     long long ans = 0; n     auto pl = prevLarge(a, n), ps = prevSmall(a, n); n     auto nl = nextLarge(a, n), ns = nextSmall(a, n); n     for (long long i = 0; i < (n); ++i) { n       long long lc = i - pl[i], rc = nl[i] - i; n       ; n       ans += lc * rc * a[i]; n       lc = i - ps[i], rc = ns[i] - i; n       ; n       ans -= lc * rc * a[i]; n     } n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[int(1e7 + 100)]; n void aum(int i) { n   if (i % 2) { n     arr[i / 2 + 1] += arr[i]; n     arr[i / 2] += arr[i]; n   } else n     arr[i / 2] += 2 * arr[i]; n } n int main() { n   ios_base::sync_with_stdio(0); n   set<int> conj; n   memset(arr, 0, sizeof arr); n   int n, m, l, ans = int(2 * 1e9 + 100), ptr = 0; n   cin >> n >> m; n   long long cnt = n, carry = 0, slices = m; n   for (int i = 0; i < n; ++i) { n     cin >> l; n     carry += l; n     ++arr[l]; n   } n   if (carry < m) { n     cout <<  -1 n ; n     return 0; n   } n   for (int i = int(1e7 + 100); cnt < m; --i) { n     if (arr[i]) { n       aum(i); n       cnt += arr[i]; n       arr[i] = 0; n     } n   } n   long long aux = 0; n   for (int i = int(1e7 + 100); i >= 1; --i) { n     if (arr[i]) { n       conj.insert(i); n       aux += arr[i]; n       if (aux >= m) { n         ans = i; n         break; n       } n     } n   } n   for (int i = int(1e7 + 100); i >= 1; --i) { n     if (arr[i]) { n       int go = (i % 2 == 1 ? 1 : 0); n       if (i / 2 + go <= *(conj.begin())) { n         break; n       } else { n         aum(i); n         if (i % 2) conj.insert(i / 2 + 1); n         conj.insert(i / 2); n         conj.erase(i); n         aux += arr[i]; n         while (1) { n           int val = (*conj.begin()); n           if (aux - arr[val] < m) break; n           aux -= arr[val]; n           conj.erase(conj.begin()); n         } n       } n     } n   } n   cout << max(1, *(conj.begin())) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int value, ans; n int bads[200010], maxDelay[200010], extraDelay[200010], a[200010], v[200010]; n vector<int> T[200010], val[200010], pre[200010], post[200010]; n void dfs(int x, int f) { n   bads[x] = 0; n   maxDelay[x] = 0; n   extraDelay[x] = 0; n   for (int i = 0; i < T[x].size(); ++i) { n     int y = T[x][i]; n     if (y != f) { n       dfs(y, x); n       bads[x] += bads[y]; n       if (bads[y] == 0) { n         maxDelay[x] += maxDelay[y]; n       } else { n         extraDelay[x] = max(extraDelay[x], maxDelay[y]); n       } n     } n   } n   if (a[x] < value) { n     bads[x]++; n     maxDelay[x] = 0; n   } else { n     maxDelay[x] += extraDelay[x] + 1; n   } n } n void dfs(int x, int f, int fBads, int fMaxDelay) { n   if (a[x] >= value) { n     int finalVal = maxDelay[x] - extraDelay[x]; n     finalVal += (fBads == 0 ? fMaxDelay + extraDelay[x] n                             : max(fMaxDelay, extraDelay[x])); n     ans = max(ans, finalVal); n   } n   for (int i = 0; i < T[x].size(); ++i) { n     int y = T[x][i]; n     if (y == f) { n       val[x][i] = (fBads > 0 ? fMaxDelay : 0); n     } else { n       val[x][i] = (bads[y] > 0 ? maxDelay[y] : 0); n     } n   } n   int sz = T[x].size(); n   pre[x][0] = val[x][0]; n   post[x][sz - 1] = val[x][sz - 1]; n   for (int i = 1; i < sz; ++i) pre[x][i] = max(val[x][i], pre[x][i - 1]); n   for (int i = sz - 2; i >= 0; --i) post[x][i] = max(val[x][i], post[x][i + 1]); n   for (int i = 0; i < T[x].size(); ++i) { n     int y = T[x][i]; n     if (y == f) continue; n     if (a[x] < value) { n       dfs(y, x, bads[x] - bads[y] + fBads, 0); n     } else { n       int newBads = bads[x] - bads[y] + fBads; n       int newMaxDelay = n           maxDelay[x] - extraDelay[x] - (bads[y] == 0 ? maxDelay[y] : 0) + n           (fBads == 0 ? fMaxDelay : 0) + n           max((i == 0 ? 0 : pre[x][i - 1]), (i == sz - 1 ? 0 : post[x][i + 1])); n       dfs(y, x, newBads, newMaxDelay); n     } n   } n } n void reset() {} n int check(int tval) { n   reset(); n   value = tval; n   ans = 0; n   dfs(1, 0); n   dfs(1, 0, 0, 0); n   return (ans >= k); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     v[i] = a[i]; n   } n   sort(v + 1, v + n + 1); n   for (int i = 1; i < n; ++i) { n     int a, b; n     cin >> a >> b; n     T[a].push_back(b); n     T[b].push_back(a); n   } n   for (int i = 1; i <= n; ++i) { n     val[i].resize(T[i].size(), 0); n     pre[i].resize(T[i].size(), 0); n     post[i].resize(T[i].size(), 0); n   } n   int lo = 0, hi = n + 1; n   while (hi - lo > 1) { n     int mid = (lo + hi) / 2; n     if (check(v[mid])) n       lo = mid; n     else n       hi = mid; n   } n   cout << v[lo]; n } n


#include <bits/stdc++.h> n using namespace std; n bool dbg = 0; n void bad(string mes =  Impossible ) { n   cout << mes; n   exit(0); n } n template <typename T> n string bin(T x, int st = 2) { n   string ans =   ; n   while (x > 0) { n     ans += char( 0  + x % st); n     x /= st; n   } n   reverse(ans.begin(), ans.end()); n   return ans.empty() ?  0  : ans; n } n template <typename T> n T input() { n   T ans = 0, m = 1; n   char c =    ; n   while (!((c >=  0  && c <=  9 ) || c ==  - )) { n     c = getchar(); n   } n   if (c ==  - ) m = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) { n     ans = ans * 10 + (c -  0 ), c = getchar(); n   } n   return ans * m; n } n template <typename T> n void read(T& a) { n   a = input<T>(); n } n template <typename T> n void read(T& a, T& b) { n   read(a), read(b); n } n template <typename T> n void read(T& a, T& b, T& c) { n   read(a, b), read(c); n } n template <typename T> n void read(T& a, T& b, T& c, T& d) { n   read(a, b), read(c, d); n } n void reads(string& second) { n   string ans =   ; n   char c =   n ; n   while (c ==   n  || c ==    ) c = getchar(); n   while (c !=   n  && c !=     && c) ans += c, c = getchar(); n   second = ans; n } n const int inf = 1e9; n const double eps = 1e-9; n const int maxn = 1e6 + 10, base = 1e9 + 7; n const long long llinf = 1e18 + 5; n template <typename T> n T binpow(T n, T second) { n   if (second <= 0) return 1LL; n   if (second % 2 == 0) { n     T b = binpow(n, second / 2); n     return (1LL * b * b) % base; n   } else { n     return (1LL * binpow(n, second - 1) * n) % base; n   } n } n int v[maxn], c[maxn]; n int lg[maxn]; n int mnSt[maxn][22]; n int n, k; n void buildMn() { n   for (int i = 0; i < n; i++) mnSt[i][0] = c[i]; n   for (int i = 1; i < 22; i++) n     for (int j = 0; j + (1 << i) <= n; j++) { n       mnSt[j][i] = min(mnSt[j][i - 1], mnSt[j + (1 << (i - 1))][i - 1]); n     } n } n int mxSt[maxn][22]; n void buildMx() { n   for (int i = 0; i < n; i++) mxSt[i][0] = v[i]; n   for (int i = 1; i < 22; i++) n     for (int j = 0; j + (1 << i) <= n; j++) { n       mxSt[j][i] = max(mxSt[j][i - 1], mxSt[j + (1 << (i - 1))][i - 1]); n     } n } n int get_min(int l, int r) { n   int j = lg[r - l + 1]; n   return min(mnSt[l][j], mnSt[r - (1 << j) + 1][j]); n } n int get_max(int l, int r) { n   int j = lg[r - l + 1]; n   return max(mxSt[l][j], mxSt[r - (1 << j) + 1][j]); n } n int main() { n   for (int i = 2; i < maxn; i++) { n     lg[i] = lg[i / 2] + 1; n   } n   read(n, k); n   for (int i = 0; i < n; i++) read(v[i]), v[i] *= 100; n   for (int i = 0; i < n; i++) read(c[i]); n   buildMn(); n   buildMx(); n   long double res = 0; n   vector<int> mda; n   for (int i = 0; i < n; i++) { n     int l = i, r = n - 1; n     while (r - l > 1) { n       int m = (l + r) >> 1; n       if (get_min(i, m) < get_max(i, m)) n         r = m; n       else n         l = m; n     } n     int kek = -inf; n     for (int j = max(i, l - 5); j <= min(n - 1, l + 5); j++) { n       kek = max(kek, min(get_min(i, j), get_max(i, j))); n     } n     mda.push_back(kek); n   } n   sort((mda).begin(), (mda).end()); n   long double cf = (long double)n / k; n   int first = n - 1; n   for (int i = 0; first >= k - 1; i++, first--) { n     res += (long double)mda[i] / cf; n     cf *= (long double)n - i - 1; n     cf /= (long double)n - k - i; n   } n   cout << fixed << setprecision(20) << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double _PI = 3.141592653589793; n double n, m, k, ans = 0; n signed main() { n   scanf( %lf %lf %lf , &n, &m, &k); n   ans += ((n * n * sqrt(3)) / 4) * (sqrt(n * n * 2 / 3)) / 3; n   ans += (m * m) / 3 * (sqrt(m * m / 2)); n   double S = (k * k * 5) / (4 * tan(_PI / 5)), r = S / (2.5 * k); n   ans += S * sqrt(3 * k * k / 4 - r * r) / 3; n   printf( %0.12lf , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long b, d, s, mx, sm = 0; n   cin >> b >> d >> s; n   mx = max(b, max(s, d)); n   if (mx != b) b++; n   if (mx != d) d++; n   if (mx != s) s++; n   sm += mx - b; n   sm += mx - d; n   sm += mx - s; n   cout << sm << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, h, x[2010], fall[2][2010]; n double p, dp[2010][2010][2][2]; n double solve(int l, int r, int fl, int fr) { n   if (l > r) return 0; n   if (dp[l][r][fl][fr] != -1) return dp[l][r][fl][fr]; n   dp[l][r][fl][fr] = 0; n   double res = 0; n   int nl = min(r, l + fall[0][l] - 1); n   if (nl == r) { n     if (!fr) n       res += (1 - p) * (x[r] - x[l] + min(h, x[r + 1] - x[r] - h)); n     else n       res += (1 - p) * (x[r] - x[l] + min(h, x[r + 1] - x[r])); n   } else { n     res += (1 - p) * solve(nl + 1, r, 1, fr); n     res += (1 - p) * (x[nl] - x[l] + h); n   } n   if (fl) n     res += p * min(h, x[l] - x[l - 1] - h); n   else n     res += p * min(h, x[l] - x[l - 1]); n   res += p * solve(l + 1, r, 0, fr); n   int nr = max(l, r - fall[1][r] + 1); n   if (nr == l) { n     if (fl) n       res += p * (x[r] - x[l] + min(h, x[l] - x[l - 1] - h)); n     else n       res += p * (x[r] - x[l] + min(h, x[l] - x[l - 1])); n   } else { n     res += p * solve(l, nr - 1, fl, 0); n     res += p * (x[r] - x[nr] + h); n   } n   if (!fr) n     res += (1 - p) * min(h, x[r + 1] - x[r] - h); n   else n     res += (1 - p) * min(h, x[r + 1] - x[r]); n   res += (1 - p) * solve(l, r - 1, fl, 1); n   res /= 2; n   return dp[l][r][fl][fr] = res; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   cin >> n >> h >> p; n   for (int i = (1); i <= (n); i++) cin >> x[i]; n   x[++n] = 1000000000; n   x[++n] = -1000000000; n   sort(x + 1, x + n + 1); n   fall[1][1] = 1; n   for (int i = (2); i <= (n); i++) { n     if (x[i] - x[i - 1] < h) n       fall[1][i] = fall[1][i - 1] + 1; n     else n       fall[1][i] = 1; n   } n   fall[0][n] = 1; n   for (int i = (n - 1); i >= (1); i--) { n     if (x[i + 1] - x[i] < h) n       fall[0][i] = fall[0][i + 1] + 1; n     else n       fall[0][i] = 1; n   } n   for (int i = (1); i <= (n); i++) n     for (int j = (1); j <= (n); j++) n       for (int k = (0); k <= (1); k++) n         for (int l = (0); l <= (1); l++) dp[i][j][k][l] = -1; n   cout << fixed << setprecision(9) << solve(2, n - 1, 0, 1); n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_N = 300000; n const int MAX_M = 300000; n std::vector<int> types[1 + MAX_N]; n std::vector<int> neighbours[1 + MAX_N]; n int c; n int colours[1 + MAX_M]; n bool used[1 + MAX_M]; n void dfs(int u = 1, int father = 0) { n   for (int type : types[u]) n     if (colours[type] != 0) used[colours[type]] = true; n   int i = 0, j = 1; n   while (i < (int)types[u].size()) { n     if (used[j]) { n       j++; n     } else { n       if (colours[types[u][i]] == 0) { n         colours[types[u][i]] = j; n         j++; n       } n       i++; n     } n   } n   for (int type : types[u]) used[colours[type]] = false; n   for (int v : neighbours[u]) n     if (v != father) { n       dfs(v, u); n     } n } n int main(void) { n   int n, m; n   scanf( %d%d , &n, &m); n   int c = 1; n   for (int i = 1; i <= n; i++) { n     int s; n     scanf( %d , &s); n     c = std::max(c, s); n     for (int j = 0; j < s; j++) { n       int type; n       scanf( %d , &type); n       types[i].push_back(type); n     } n   } n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     neighbours[u].push_back(v); n     neighbours[v].push_back(u); n   } n   dfs(); n   for (int i = 1; i <= m; i++) n     if (colours[i] == 0) colours[i] = 1; n   printf( %d n , c); n   for (int i = 1; i <= m; i++) printf( %d  , colours[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = (long int)3e5 + 5; n long long power(long long x, long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x) % 1000000007; n     y = y >> 1; n     x = (x * x) % 1000000007; n   } n   return res; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long a, b, prev; n   cin >> a >> b; n   long long n = (sqrt(1 + 8 * (a + b)) - 1) / 2; n   std::vector<long long> d1, d2; n   for (long long i = n; i > 0; i--) { n     if (a - i >= 0) { n       d1.push_back(i); n       a -= i; n     } else if (b - i >= 0) { n       d2.push_back(i); n       b -= i; n     } n   } n   cout << d1.size() << endl; n   for (auto i : d1) cout << i <<    ; n   cout << endl; n   cout << d2.size() << endl; n   for (auto i : d2) cout << i <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ni() { n   int a; n   scanf( %d , &a); n   return a; n } n double nf() { n   double a; n   scanf( %lf , &a); n   return a; n } n char sbuf[100005]; n string ns() { n   scanf( %s , sbuf); n   return sbuf; n } n long long nll() { n   long long a; n   scanf( %lld , &a); n   return a; n } n template <class T> n void out(T a, T b) { n   bool first = true; n   for (T i = a; i != b; ++i) { n     if (!first) printf(   ); n     first = false; n     cout << *i; n   } n   printf(  n ); n } n template <class T> n void outl(T a, T b) { n   for (T i = a; i != b; ++i) { n     cout << *i <<   n ; n   } n } n int n, m; n int moo(char c) { n   if (c <=  9  && c >=  0 ) return c -  0 ; n   return c -  A  + 10; n } n int a[6][6]; n bool inside(int a) { return a >= 0 && a < 6; } n char ss[1005]; n vector<string> ans; n void add(char c, int z, int num) { n   int j; n   sprintf(ss,  %c%d n , c, z + 1); n   while (num) { n     if (c ==  L ) { n       int t = a[z][0]; n       for (j = (0); j < (((5))); ++j) a[z][j] = a[z][j + 1]; n       a[z][5] = t; n     } n     if (c ==  R ) { n       int t = a[z][5]; n       for (j = (0); j < (((5))); ++j) a[z][5 - j] = a[z][4 - j]; n       a[z][0] = t; n     } n     if (c ==  U ) { n       int t = a[0][z]; n       for (j = (0); j < (((5))); ++j) a[j][z] = a[j + 1][z]; n       a[5][z] = t; n     } n     if (c ==  D ) { n       int t = a[5][z]; n       for (j = (0); j < (((5))); ++j) a[5 - j][z] = a[4 - j][z]; n       a[0][z] = t; n     } n     ans.push_back(ss); n     --num; n   } n } n int main() { n   int i, j, k; n   for (i = (0); i < (((6))); ++i) { n     string s = ns(); n     for (j = (0); j < (((6))); ++j) a[i][j] = moo(s[j]); n   } n startOver: n   int done = 0; n   for (i = (0); i < (((15))); ++i) { n     for (j = (0); j < (((15))); ++j) { n       int y = j; n       int x = i - j; n       if (inside(x) && inside(y)) { n         int xx = -1, yy = -1; n         int ii, jj; n         for (ii = (0); ii < ((6)); ++ii) n           for (jj = (0); jj < ((6)); ++jj) n             if (a[ii][jj] == y * 6 + x) xx = jj, yy = ii; n         ; n         if (x == 5 && y == 0) x = 5; n         if (xx == x && yy == y) { n         } else { n           bool needUp = 0; n           if (yy == 5 && xx == 5) { n             if (y == 5) { n               y = 4; n               add( U , x, 1); n               needUp = 1; n             } n             if (x < 4) n               add( L , 5, 4 - x); n             else if (x > 4) n               add( R , 5, 1); n             add( D , x, 5 - y); n             add( L , 5, 1); n             add( U , x, 5 - y); n             if (x != 5) add( R , 5, 5 - x); n             if (needUp) { n               add( D , x, 1); n               y = 5; n             } n           } else { n             if (yy == 5 && xx != 4) { n               yy = 4; n               add( U , xx, 1); n               needUp = 1; n             } n             if (xx < 4) n               add( L , 5, 4 - xx); n             else if (xx > 4) n               add( R , 5, 1); n             add( D , xx, 5 - yy); n             add( L , 5, 1); n             add( U , xx, 5 - yy); n             if (xx != 5) add( R , 5, 5 - xx); n             if (needUp) { n               add( D , xx, 1); n               yy = 5; n             } n             needUp = 0; n             if (y == 5) { n               y = 4; n               add( U , x, 1); n               needUp = 1; n             } n             if (x != 5) add( L , 5, 5 - x); n             add( D , x, 5 - y); n             add( R , 5, 1); n             add( U , x, 5 - y); n             if (x < 4) n               add( R , 5, 4 - x); n             else if (x > 4) n               add( L , 5, 1); n             if (needUp) { n               add( D , x, 1); n               y = 5; n             } n           } n         } n         if (a[y][x] != y * 6 + x) { n           printf( %d %d n , x, y); n           return 0; n         } n         ++done; n       } n       if (done == 34) { n         if (a[5][5] != 35) { n           add( L , 5, 3); n           goto startOver; n         } n         printf( %d n , ans.size()); n         for (i = (0); i < (((ans.size()))); ++i) printf( %s , ans[i].c_str()); n         return 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int n = 10, dir[4][2] = {{1, 0}, {0, 1}, {1, -1}, {1, 1}}; n int main() { n   char b[n][n]; n   for (int i = 0; i < 10; i++) n     for (int j = 0; j < n; j++) scanf(  %c , &b[i][j]); n   bool found = false; n   for (int i = 0; !found && i < n; i++) n     for (int j = 0; !found && j < n; j++) n       for (int k = 0; k < 4; k++) { n         int p = 0, q = 0; n         for (int l = 0; l < 5; l++) { n           int x = i + dir[k][0] * l, y = j + dir[k][1] * l; n           if (x < 0 || x >= n || y < 0 || y >= n) break; n           ; n           char c = b[x][y]; n           p += (c ==  X ), q += (c ==  . ); n         } n         if (p == 4 && q == 1) found = true; n       } n   if (found) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_ROW = 2000 + 7; n const int MAX_COLUMN = 200 + 7; n const int BASE = 2807; n const int MOD = 1e7 + 7; n int n, m; n char TableA[MAX_ROW][MAX_COLUMN], TableB[MAX_COLUMN][MAX_ROW]; n int HashA[MAX_ROW][MAX_COLUMN], HashB[MAX_COLUMN][MAX_ROW], Pow2807[MAX_ROW], n     HashFinding[MOD]; n int GetHash(const int& L, const int& R, const int H[]) { n   return (1LL * H[R] - 1LL * H[L - 1] * Pow2807[R - L + 1] + 1LL * MOD * MOD) % n          MOD; n } n int main() { n   ios::sync_with_stdio(false); n   cout.tie(0), cin.tie(0); n   Pow2807[0] = 1; n   for (int i = 1; i < MAX_ROW; ++i) n     Pow2807[i] = 1LL * Pow2807[i - 1] * BASE % MOD; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %s , TableA[i] + 1); n   for (int j = 1; j <= m; ++j) scanf( %s , TableB[j] + 1); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       HashA[i][j] = (1LL * HashA[i][j - 1] * BASE + TableA[i][j]) % MOD; n   for (int i = 1; i <= m; ++i) n     for (int j = 1; j <= n; ++j) n       HashB[i][j] = (1LL * HashB[i][j - 1] * BASE + TableB[i][j]) % MOD; n   for (int j = 1; j <= (n - m + 1); ++j) { n     int HashBase = 0; n     for (int k = j; k <= (j + m - 1); ++k) n       HashBase = (1LL * HashBase * Pow2807[m] + GetHash(1, m, HashA[k])) % MOD; n     HashFinding[HashBase] = j; n   } n   for (int j = 1; j <= (n - m + 1); ++j) { n     int HashTest = 0; n     for (int i = 1; i <= m; ++i) n       HashTest = n           (1LL * HashTest * Pow2807[m] + GetHash(j, j + m - 1, HashB[i])) % MOD; n     if (HashFinding[HashTest]) { n       cout << HashFinding[HashTest] <<     << j <<   n ; n       return 0; n     } n   } n   cout <<  Error 404! n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long aa[15]; n   long long bb[15]; n   for (int i = 0; i < 14; i++) { n     scanf( %lld , &aa[i]); n     bb[i] = aa[i]; n   } n   long long maxx = 0; n   for (int i = 0; i < 14; i++) { n     if (!aa[i]) continue; n     long long sum = 0; n     int c = aa[i] % 14; n     for (int k = 1; k <= c; k++) { n       if (i + k < 14) n         bb[k + i]++; n       else { n         bb[(i + k) % 14]++; n       } n     } n     for (int j = 0; j < 14; j++) { n       if (j != i) n         bb[j] += aa[i] / 14; n       else n         bb[j] = aa[i] / 14; n       if (bb[j] % 2 == 0) sum += bb[j]; n     } n     if (sum > maxx) maxx = sum; n     for (int j = 0; j < 14; j++) bb[j] = aa[j]; n   } n   cout << maxx << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimization( unroll-loops ) n const int N = 1e5 + 5; n const long long int mod = 1e9 + 7; n const long long int Mod = 998244353; n const long double Pi = acos(-1); n const long long int Inf = 4e18; n using namespace std; n int n, m; n vector<pair<int, int> > e; n bool Check(int k) { n   vector<bool> rem(n + 1, false); n   vector<int> in[n + 1], out[n + 1], rank(n + 1, -1); n   for (int i = 0; i <= k; i++) { n     in[e[i].second].push_back(e[i].first); n     out[e[i].first].push_back(e[i].second); n   } n   int cnt_in = 0, cnt_out = 0, one = -1, last = -1; n   for (int i = 1; i <= n; i++) { n     if ((int)in[i].size() == 0) { n       cnt_in++; n       one = i; n     } n     if ((int)out[i].size() == 0) { n       cnt_out++; n       last = i; n     } n   } n   if (cnt_in * cnt_out != 1) return false; n   rank[1] = one; n   rank[n] = last; n   int cur = one; n   for (int i = 2; i <= n; i++) { n     int fone = 0, nxt = -1; n     for (auto u : out[cur]) { n       int cnt = 0; n       for (auto t : in[u]) { n         if (rem[t] == false) cnt++; n       } n       if (cnt == 1) { n         fone++; n         nxt = u; n       } n     } n     if (fone != 1) n       return false; n     else { n       rem[cur] = true; n       cur = nxt; n       rank[i] = cur; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (rank[i] == -1) return false; n   } n   return true; n } n void TestCase() { n   cin >> n >> m; n   for (int i = 1, u, v; i <= m; i++) { n     cin >> u >> v; n     e.push_back({u, v}); n   } n   int lb = 0, ub = m - 1, ans = m; n   while (lb <= ub) { n     int mid = (lb + ub) / 2; n     if (Check(mid)) { n       ans = min(ans, mid); n       ub = mid - 1; n     } else n       lb = mid + 1; n   } n   ans == m ? cout << -1 : cout << ans + 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   int T = 1; n   while (T--) { n     TestCase(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   vector<long long int> v; n   long long int n, i; n   cin >> n; n   if (n == 1) { n     cout << 1; n     return 0; n   } n   for (long long int i = 1; i * i <= n; ++i) { n     if (n % i == 0) { n       if (i * i == n) n         v.push_back(i); n       else { n         v.push_back(i); n         v.push_back(n / i); n       } n     } n   } n   sort(v.begin(), v.end()); n   if (v.size() == 2) n     cout << n; n   else { n     long long int flag = 0; n     if (v.size() == 3) { n       if (v[1] / v[0] != v[2] / v[1]) { n         cout << 1; n       } else n         cout << v[1]; n     } else { n       long long int ans = v[1] / v[0]; n       for (i = 1; i < v.size() - 1; i++) { n         if (v[i + 1] != ans * v[i]) { n           flag = 1; n           break; n         } n       } n       if (flag == 1) n         cout << 1; n       else { n         cout << v[1]; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const int mod = 1e9 + 7; n long long qpow(long long a, long long b) { n   long long res = 1; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n struct graph { n   int head[maxn], nxt[maxn << 1], to[maxn << 1], w[maxn << 1], sz; n   void init() { memset(head, -1, sizeof(head)); } n   graph() { init(); } n   void push(int a, int b, int c) { n     nxt[sz] = head[a], to[sz] = b, w[sz] = c, head[a] = sz++; n   } n   int& operator[](const int a) { return to[a]; } n }; n long long dist[maxn][40], fi[maxn][40], mi[maxn][40]; n int to[maxn], w[maxn]; n int main() { n   int n; n   long long k; n   cin >> n >> k; n   for (int i = 0; i < n; ++i) scanf( %d , &to[i]); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &w[i]); n     dist[i][0] = w[i]; n     mi[i][0] = w[i]; n     fi[i][0] = to[i]; n   } n   for (int i = 1; i <= 39; ++i) { n     for (int j = 0; j < n; ++j) { n       dist[j][i] = dist[j][i - 1] + dist[fi[j][i - 1]][i - 1]; n       fi[j][i] = fi[fi[j][i - 1]][i - 1]; n       mi[j][i] = min(mi[j][i - 1], mi[fi[j][i - 1]][i - 1]); n     } n   } n   for (int i = 0; i < n; ++i) { n     long long mix = 1e18; n     long long ans = 0; n     long long res = k; n     int now = i; n     for (int j = 39; j >= 0; --j) { n       if (res >= (1ll << j)) { n         ans += dist[now][j]; n         mix = min(mix, mi[now][j]); n         now = fi[now][j]; n         res -= (1ll << j); n       } n     } n     printf( %lld %lld n , ans, mix); n   } n   return 0; n } n


#pragma GCC target ( avx2 ) n #pragma GCC optimize ( O3 ) n #pragma GCC optimize ( unroll-loops ) n #include <bits/stdc++.h> n using namespace std; n  n typedef long long int ll; n typedef long double ld; n typedef pair<ll, ll> pl; n typedef pair<ld, ld> pd; n typedef priority_queue<pl, vector<pl>, greater<pl> > pq; n  n template<class T, class S> n ostream& operator<<(ostream &o, pair<T, S> p) { n     return o<< ( <<p.first<< ,  <<p.second<< ) ; n } n  n template<template<class, class...> class T, class... A> n typename enable_if<!is_same<T<A...>, string>(), ostream&>::type n operator<<(ostream &o, T<A...> V) { n  o<< [ ; n  for(auto a:V) o<<a<< ,  ; n  return o<< ] ; n } n  n // This is tuples, _p is helper n template<ll i, class... T> n typename enable_if<i==sizeof...(T)>::type _p(ostream& o, tuple<T...> t) {} n  n template<ll i, class... T> n typename enable_if<i<sizeof...(T)>::type _p(ostream& o, tuple<T...> t) { n     _p<i+1>(o << get<i>(t)<<  ,  , t); n } n   n template<class... T> n ostream& operator<<(ostream& o, tuple<T...> t) { n     _p<0>(o<< ( , t); n     return o<< ) ; n } n  n  n #define G(x) ll x; cin >> x; n #define Gs(s) string s; cin >> s; n #define Gd(x) ld x; cin >> x; n #define F(i, l, r) for(ll i = l; i < (r); i++) n #define F1(i, l, r) for(ll i = l; i >= (r); i--) n #define Fi(i, s) for(auto i = (s).begin(); i != (s).end(); i++) n #define L G(_t) F(_t1, 0, _t) n #define H(ar, n) vector<ll> ar(n); F(_i, 0, n) cin >> ar[_i]; n #define A first n #define B second n #define PA(ar, n) F(_i, 0, n) cout << (ar)[_i] <<    ; cout << endl;  n #define PB push_back n #define V vector n #define CASE cout <<  Case #  << _t1 + 1 <<  :    n #define CC <<     << n #define BE(ar) ar.begin(), ar.end() n #define CO(x) cout << (x) << endl; n #define D(x) ((x) -  0 ) n #define EX(x) {cout << (x) << endl; return 0;} n #define S(ar, val) memset(ar, val, sizeof(ar)); n ll M = 1000000007; //998244353; n ll inv(ll a, ll b){return 1<a ? b - inv(b%a,a)*b/a : 1;} n ll gcd(ll x, ll y){if(y == 0) return x; return gcd(y, x % y); } n pl neigh[4] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; n  n #define N 0 n  n int main() { n         ios_base::sync_with_stdio(0); n         cin.tie(0); n  L{ n   G(n) n   if(n == 2){ n    cout <<  1 n2 1 n1 n2 1  << endl; n    continue; n   } n   if(n == 3){ n    cout <<  5 n2 3 1 n2 n1 3 n3 2  << endl; n    continue; n   } n   ll perm[n]; n   perm[n-1] = 1; n   perm[0] = n-1; n   F1(i, n-2, (n-1)/2+2){ n    perm[i] = i; n   } n   perm[(n-1)/2] = n; n   perm[(n-1)/2+1]=2; n   F(i, 1, (n-1)/2){ n    perm[i] = i+2; n   } n   ll x = (n-1)*(n-1); n   ll c = 1; n   ll p = n-1; n   while(c < n-1){ n    if(c %2) p--; n    c++; n    x += p * p; n   } n   cout << x << endl; n   F(i, 0, n){ n    cout << perm[i] <<    ; n   } n   cout << endl; n   cout << n - 1 << endl; n   F1(i, n-1, (n-1)/2+2){ n    cout << i <<     << 1 << endl; n   } n   F(i, 1, (n-1)/2+2){ n    cout << i <<     << n << endl; n   } n  } n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n const int mod = 1000000007; n const int inf = 2012345678; n const long long infl = 9012345678901234567; n const double pi = 3.1415926535897932384626433832795; n const int N = 20; n const int M = 100010; n char buf[M]; n int a[M]; n int dp[1 << N][N + 1]; n int main() { n   freopen( input.txt ,  r , stdin); n   int n, m; n   scanf( %d%d , &(n), &(m)); n   for (int i = 0; i < (n); i++) { n     scanf( %s , buf); n     for (int j = 0; j < (m); j++) a[j] = 2 * a[j] + buf[j] -  0 ; n   } n   for (int i = 0; i < (m); i++) dp[a[i]][0]++; n   for (int i = 0; i < (m); i++) n     for (int j = 0; j < (n); j++) dp[a[i] ^ (1 << j)][1]++; n   for (int k = 2; k <= n; k++) { n     for (int i = 0; i < ((1 << n)); i++) { n       int sum = 0; n       for (int j = 0; j < (n); j++) { n         sum += dp[i ^ (1 << j)][k - 1]; n       } n       sum -= (n - k + 2) * dp[i][k - 2]; n       dp[i][k] = sum / k; n     } n   } n   int ans = inf; n   for (int i = 0; i < ((1 << n)); i++) { n     int s = 0; n     for (int k = 0; k <= (n); k++) { n       s += min(k, n - k) * dp[i][k]; n     } n     ans = min(ans, s); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   char cur = s[0]; n   int count = 1; n   for (int i = 1; i < s.length(); i++) { n     if (cur == s[i]) { n       count++; n       if (count == 7) { n         cout <<  YES  << endl; n         return 0; n       } n     } else { n       count = 1; n       cur = s[i]; n     } n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int M = 1e9 + 7; n const long long int N = 2e5 + 5; n const long long int inf = 2e18; n long long int mod(long long int x) { return (x % M); } n long long int mod_minus(long long int a, long long int b) { n   long long int ans = (mod(a) - mod(b)); n   if (ans < 0) ans = mod(ans + M); n   return ans; n } n long long int mod_mul(long long int a, long long int b) { n   return mod(mod(a) * mod(b)); n } n long long int mod_add(long long int a, long long int b) { return mod(a + b); } n long long int power(long long int a, long long int n) { n   if (n == 0) n     return 1; n   else if (n == 1) n     return a; n   long long int R = power(a, n / 2) % M; n   if (n % 2 == 0) { n     return mod(mod_mul(R, R)); n   } else { n     return mod(mod_mul(mod_mul(R, a), mod(R))); n   } n } n long long int mod_inv(long long int n) { return power(n, M - 2); } n long long int mod_div(long long int a, long long int b) { n   long long int ans = mod(a); n   long long int b1 = power(b, M - 2); n   ans = mod(mod_mul(ans, b1)); n   return ans; n } n long long int fact_mod(long long int n) { n   vector<long long int> fact(n + 1); n   fact[0] = 1; n   for (long long int i = 1; i < n + 1; i++) { n     fact[i] = mod_mul(fact[i - 1], i); n   } n   return fact[n]; n } n long long int nCr_mod(long long int n, long long int r) { n   if (r == 0 || n == 0) return 1; n   long long int fac[n + 1]; n   fac[0] = 1; n   for (long long int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % M; n   return (fac[n] * mod_inv(fac[r]) % M * mod_inv(fac[n - r]) % M) % M; n } n int main() { n   long long int n; n   cin >> n; n   long long int i; n   queue<pair<long long int, long long int>> q; n   vector<pair<long long int, long long int>> v(n); n   for (i = 0; i < n; i++) { n     long long int x, y; n     cin >> x >> y; n     v[i] = {x, y}; n     if (x == 1) q.push({i, y}); n   } n   vector<pair<long long int, long long int>> ans; n   while (q.empty() == false) { n     pair<long long int, long long int> temp = q.front(); n     q.pop(); n     ans.push_back({temp}); n     long long int x = temp.second; n     v[x].first--; n     v[x].second = temp.first ^ v[x].second; n     if (v[x].first == 1) q.push({x, v[x].second}); n   } n   set<pair<long long int, long long int>> s; n   for (auto x : ans) { n     if (!s.count({x.first, x.second}) && !s.count({x.second, x.first})) n       s.insert({x.first, x.second}); n   } n   cout << s.size() << endl; n   for (auto x : s) cout << x.first <<     << x.second << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const double eps = 1e-9; n string words[100005]; n int type[100005]; n int gender[100005]; n void reverse(string &c) { n   for (int i = (0); i < (int((c).size()) / 2); i++) { n     char tmp = c[i]; n     c[i] = c[int((c).size()) - i - 1]; n     c[int((c).size()) - i - 1] = tmp; n   } n } n int main() { n   string line; n   getline(cin, line); n   stringstream ss(line); n   int n = 0; n   while (true) { n     string word; n     ss >> word; n     if (ss.fail()) break; n     words[n++] = word; n   } n   for (int i = (0); i < (n); i++) reverse(words[i]); n   for (int i = (0); i < (n); i++) { n     if (words[i].find( soil ) == 0) { n       type[i] = 0; n       gender[i] = 0; n       continue; n     }; n     if (words[i].find( alail ) == 0) { n       type[i] = 0; n       gender[i] = 1; n       continue; n     }; n     if (words[i].find( rte ) == 0) { n       type[i] = 1; n       gender[i] = 0; n       continue; n     }; n     if (words[i].find( arte ) == 0) { n       type[i] = 1; n       gender[i] = 1; n       continue; n     }; n     if (words[i].find( sitini ) == 0) { n       type[i] = 2; n       gender[i] = 0; n       continue; n     }; n     if (words[i].find( setini ) == 0) { n       type[i] = 2; n       gender[i] = 1; n       continue; n     }; n     gender[i] = -1; n   } n   if (n == 1 && gender[0] != -1) { n     cout <<  YES n ; n     return 0; n   } n   bool SameGender = true; n   for (int i = (1); i < (n); i++) n     if (gender[i] != gender[0]) SameGender = false; n   if (!SameGender || gender[0] == -1) { n     cout <<  NO n ; n     return 0; n   } n   int p1, p2, p3; n   p1 = 0; n   while (p1 < n && type[p1] == 0) ++p1; n   p2 = p1; n   while (p2 < n && type[p2] == 1) ++p2; n   p3 = p2; n   while (p3 < n && type[p3] == 2) ++p3; n   if (p3 == n && p2 == p1 + 1) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10; n const int mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n int a1[maxn], a2[maxn]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n, k; n   cin >> n >> k; n   long long ans = (n + 1) * n / 2; n   for (int i = 1; i <= n; i++) a1[i] = i; n   for (int i = 1; i <= n; i++) a2[i] = i; n   if (ans > k) { n     cout << -1 <<   n ; n     return 0; n   } n   long long up = n / 2; n   long long now = n - 1; n   for (int i = 1; i <= up; i++) { n     if (ans + now <= k) { n       ans += now; n       swap(a2[i], a2[i + now]); n     } else { n       swap(a2[i], a2[i + k - ans]); n       ans = k; n       break; n     } n     now -= 2; n   } n   cout << ans <<   n ; n   for (int i = 1; i <= n; i++) cout << a1[i] << (i == n ?   n  :    ); n   for (int i = 1; i <= n; i++) cout << a2[i] << (i == n ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long total = 0; n struct c { n   int can; n   int tru; n }; n int main() { n   double a, b, c; n   scanf( %lf%lf%lf , &a, &b, &c); n   printf( %.100f n , a * (b) / (b + c)); n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n using ll = long long; n using ld = long double; n constexpr int nax = 1000 * 1000 + 105; n constexpr int infty = 1000 * 1000 * 1000 + 5; n constexpr int mod = 1000 * 1000 * 1000 + 7; n int main() { n   int n; n   scanf( %d , &n); n   set<int> s; n   for (int i = 0; i < n; i++) { n     int a; n     scanf( %d , &a); n     s.insert(a); n   } n   printf( %d n , n + 1 - (int)s.size()); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( avx2 ) n #pragma GCC optimize( Os ) n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string str; n   long long i, j, k, x = 0, y = 0, n, m, t, sum = 0, a = 0, b, l, c, d, id; n   cin >> n; n   set<long long> s; n   for (i = 0; i < n; i++) { n     cin >> a; n     sum += a; n     s.insert(a); n   } n   x = s.size(); n   if (x >= 4) n     cout << -1; n   else { n     if (x == 1) n       cout << 0; n     else if (x == 2) { n       a = *next(s.begin(), 0); n       b = *next(s.begin(), 1); n       if ((a + b) % 2 != 0) n         cout << b - a; n       else n         cout << (b - a) / 2; n     } else { n       a = *next(s.begin(), 0); n       b = *next(s.begin(), 1); n       c = *next(s.begin(), 2); n       t = c - b; n       if (a + c == b * 2) n         cout << t; n       else n         cout << -1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, i; n } a[100020], b[100020], c[100020]; n bool f(node a, node b) { return a.x < b.x; } n bool g(node a, node b) { return a.i < b.i; } n int main() { n   int i, n, j; n   cin >> n; n   cout <<  YES n ; n   for (i = 1; i <= n; i++) { n     cin >> a[i].x, a[i].i = i, a[i].x += 2; n   } n   sort(a + 1, a + n + 1, f); n   for (i = 1; i <= n / 3; i++) n     b[i].i = c[i].i = a[i].i, b[i].x = i, c[i].x = a[i].x - i; n   for (i = 1 + n / 3; i <= (n + n) / 3; i++) n     b[i].i = c[i].i = a[i].i, c[i].x = i, b[i].x = a[i].x - i; n   for (i = 1 + (n + n) / 3, j = i; i <= n; i++) n     b[i].i = c[i].i = a[i].i, c[i].x = n - i + 1, b[i].x = a[i].x - c[i].x; n   sort(b + 1, b + n + 1, g); n   sort(c + 1, c + n + 1, g); n   for (i = 1; i <= n; i++) cout << b[i].x - 1 <<    ; n   cout << endl; n   for (i = 1; i <= n; i++) cout << c[i].x - 1 <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> g[1100]; n map<long long, bool> visited; n long long a, b; n map<long long, long long> parent; n void dfs(long long v) { n   visited[v] = 1; n   if (v > 1e9 || v == b) { n     return; n   } n   if (!visited[2 * v]) { n     parent[2 * v] = v; n     dfs(2 * v); n   } n   if (!visited[10 * v + 1]) { n     parent[10 * v + 1] = v; n     dfs(10 * v + 1); n   } n } n decltype(0) main() { n   ios::sync_with_stdio(0); n   cin >> a >> b; n   dfs(a); n   if (!visited[b]) { n     cout <<  NO n ; n   } else { n     vector<long long> ans; n     long long x = b; n     while (x != parent[a]) { n       ans.push_back(x); n       x = parent[x]; n     } n     cout <<  YES n  << (long long)(ans.size()) <<   n ; n     for (long long i = (long long)(ans.size()) - 1; i >= 0; i--) { n       cout << ans[i] <<    ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long X, Y, sum, exor, l, m; n int main() { n   cin >> sum >> exor; n   if (sum < exor || sum % 2 != exor % 2) { n     cout <<  -1  << endl; n     return 0; n   } n   X = (sum - exor) / 2; n   Y = sum - X; n   cout << X << endl << Y << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> ans; n int row[5], col[20]; n vector<int> v[3]; n bool vis[20][11][11][11][11][11][1 << 5]; n bool solve(int x, int r1, int r2, int r3, int r4, int r5, int mask) { n   if (x == m) { n     if (r1 + r2 + r3 + r4 + r5) return false; n     return true; n   } n   bool &ret = vis[x][r1][r2][r3][r4][r5][mask]; n   if (ret) return false; n   ret = true; n   int a[5]; n   a[0] = r1, a[1] = r2, a[2] = r3, a[3] = r4, a[4] = r5; n   int h = col[x]; n   for (int i = 0; i < v[h].size(); i++) { n     int b[5] = {0}; n     int now = v[h][i]; n     for (int j = 0; j < n; j++) b[j] = a[j]; n     bool flag = true; n     for (int j = 0; j < n; j++) { n       if ((mask & (1 << j)) == 0 && now & (1 << j)) b[j]--; n       if (b[j] < 0) { n         flag = false; n         break; n       } n     } n     if (flag) { n       if (solve(x + 1, b[0], b[1], b[2], b[3], b[4], now)) { n         ans.push_back(now); n         return true; n       } n     } n   } n   return false; n } n int main() { n   scanf( %d , &n); n   ; n   scanf( %d , &m); n   ; n   for (int i = 0; i < n; i++) scanf( %d , &row[i]); n   ; n   for (int i = 0; i < m; i++) scanf( %d , &col[i]); n   ; n   for (int i = 0; i < 1 << n; i++) { n     int c = 0, pre = 0; n     for (int j = 0; j < n; j++) { n       if (i & (1 << j) && !pre) { n         pre = 1; n         c++; n       } else n         pre = bool(i & (1 << j)); n     } n     v[c].push_back(i); n   } n   solve(0, row[0], row[1], row[2], row[3], row[4], 0); n   reverse(ans.begin(), ans.end()); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < ans.size(); j++) { n       if (ans[j] & (1 << i)) n         cout <<  * ; n       else n         cout <<  . ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const unsigned long long base = 2333; n const int maxn = 1e2 + 55; n const int maxm = 1e4 + 50; n const int maxv = 1e6 + 5; n const int mod = 51123987; n long long Cal(string s, long long p) { n   long long len = s.size(); n   long long sum = 0; n   for (long long i = 0; i < len; i++) { n     sum = (sum * 10 + s[i] -  0 ) % p; n   } n   return sum; n } n long long phi(long long n) { n   long long res = n, m = n; n   for (long long i = 2; i <= sqrt(m); i++) { n     if (m % i == 0) res = res / i * (i - 1); n     while (m % i == 0) m /= i; n   } n   if (m > 1) res = res / m * (m - 1); n   return res; n } n long long Quick_pow(long long x, long long y, long long p) { n   long long ans = 1, res = x; n   while (y) { n     if (y & 1) ans = ans * res % p; n     res = res * res % p; n     y >>= 1; n   } n   return ans; n } n int main() { n   string b, n; n   long long c; n   cin >> b >> n >> c; n   long long ph = phi(c); n   long long bb = Cal(b, c); n   long long nn = Cal(n, ph); n   if (n.size() < 10) { n     long long z = 0; n     for (long long i = 0; i < n.size(); i++) z = (z * 10 + n[i] -  0 ); n     long long ans = ((bb - 1 + c) % c) * Quick_pow(bb, z - 1, c) % c; n     if (ans == 0) ans = c; n     printf( %lld n , ans); n     return 0; n   } n   nn = (nn - 1 + ph) % ph + ph; n   long long ans = ((bb - 1 + c) % c) * Quick_pow(bb, nn, c) % c; n   if (ans == 0) ans = c; n   printf( %lld n , ans); 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, m, x, y; n     cin >> n >> m >> x >> y; n     char a[n][m]; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         cin >> a[i][j]; n       } n     } n     int county = 0, count = 0; n     if (2 * x > y) { n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < m; j++) { n           if (a[i][j] ==  . ) count++; n           if (j != m - 1) { n             if (a[i][j] == a[i][j + 1] && a[i][j] ==  . ) { n               county++; n               j++; n             } n           } n         } n       } n       cout << (county * y) + (count - county) * x; n     } else { n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < m; j++) { n           if (a[i][j] ==  . ) count++; n         } n       } n       cout << count * x; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[110]; n int n, k; n vector<int> ans; n void solve() { n   cin >> n >> k; n   for (int i = (1); i <= (n); ++i) { n     int x; n     cin >> x; n     a[i].first = x; n     a[i].second = i; n   } n   sort(a + 1, a + 1 + n); n   int s = 0; n   for (int i = 1; i <= n; ++i) { n     s += a[i].first; n     if (s <= k) n       ans.push_back(a[i].second); n     else n       break; n   } n   sort(ans.begin(), ans.end()); n   cout << ans.size() << endl; n   { n     for (int i = (0); i < (ans.size()); ++i) cout << ans[i] <<    ; n     cout << endl; n   }; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000 * 1000 * 1000 + 9; n const long long MOD = 1000 * 1000 * 1000 + 7; n const double EPS = 1e-9; n const int di[] = {-1, 0, 1, 0}; n const int dj[] = {0, -1, 0, 1}; n const int N = 505; n int n, k; n int a[N][N]; n int b[N][N]; n int s[N][N]; n int q; n int f[N * N]; n int g[N * N]; n int ans; n int mod; n void dfs(int x, int y, int c) { n   b[x][y] = c; n   g[c]++; n   for (int i = 0; i < 4; ++i) { n     int xx = x + di[i]; n     int yy = y + dj[i]; n     if (a[xx][yy] && !b[xx][yy]) { n       dfs(xx, yy, c); n     } n   } n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       char c; n       scanf(  %c , &c); n       a[i + 1][j + 1] = c ==  . ; n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       if (a[i][j] && !b[i][j]) { n         dfs(i, j, ++q); n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j]; n     } n   } n   for (int i = 1; i + k - 1 <= n; ++i) { n     for (int r = 0; r <= q; ++r) { n       f[r] = 0; n     } n     mod = 0; n     for (int u = i - 1; u <= i + k; ++u) { n       for (int v = 0; v <= k + 1; ++v) { n         if ((u == i - 1 || u == i + k) && (v == 0 || v == k + 1)) { n           continue; n         } n         if (f[b[u][v]] == 0) { n           mod += g[b[u][v]]; n         } n         f[b[u][v]]++; n       } n     } n     for (int j = 1; j + k - 1 <= n; ++j) { n       ans = max(ans, n                 mod + (k * k - (s[i + k - 1][j + k - 1] - s[i - 1][j + k - 1] - n                                 s[i + k - 1][j - 1] + s[i - 1][j - 1]))); n       if (j + k - 1 < n) { n         for (int u = i - 1; u <= i + k; ++u) { n           int x = b[u][j - 1 + (u == i - 1 || u == i + k)]; n           --f[x]; n           if (f[x] == 0) { n             mod -= g[x]; n           } n         } n         for (int u = i - 1; u <= i + k; ++u) { n           int x = b[u][j + k + 1 - (u == i - 1 || u == i + k)]; n           if (f[x] == 0) { n             mod += g[x]; n           } n           ++f[x]; n         } n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ii = pair<int, int>; n using i3 = pair<int, ii>; n using li = pair<ll, int>; n using lii = pair<ll, ii>; n using vi = vector<int>; n using vl = vector<ll>; n using vli = vector<li>; n using vii = vector<ii>; n using vi3 = vector<i3>; n using vlii = vector<lii>; n const int N = 1e5 + 5; n const int INF = 1e9 + 7; n const double eps = 1e-12, PI = acos(-1); n int n, m; n char s[N]; n int mem[N][5]; n int dp(int i, int rem) { n   if (i == n) { n     return rem == 0 ? 0 : INF; n   } n   int &ret = mem[i][rem]; n   if (ret != -1) return ret; n   return ret = min(1 + dp(i + 1, rem), n                    dp(i + 1, (rem * 10 + int(s[i] -  0 )) % 3)); n } n vi ans; n void path(int i, int rem) { n   if (i == n) return; n   if (dp(i + 1, (rem * 10 + int(s[i] -  0 )) % 3) == dp(i, rem)) { n     ans.push_back(s[i] -  0 ); n     path(i + 1, (rem * 10 + int(s[i] -  0 )) % 3); n     return; n   } n   path(i + 1, rem); n } n void solve(int cs) { n   scanf( %s , s); n   n = strlen(s); n   int mn = INF, idx = INF; n   bool isZero = 0; n   memset(mem, -1, sizeof mem); n   for (int i = 0; s[i]; i++) { n     if (s[i] ==  0 ) { n       isZero = 1; n       continue; n     } n     int curr = dp(i + 1, int(s[i] -  0 ) % 3) + i; n     if (curr < mn) { n       mn = curr; n       idx = i; n     } n   } n   if (idx == INF) { n     printf( %d n , isZero ? 0 : -1); n     return; n   } n   path(idx + 1, int(s[idx] -  0 ) % 3); n   printf( %c , s[idx]); n   for (int A : ans) printf( %d , A); n   printf(  n ); n } n int main() { n   int t = 1; n   for (int cs = 1; t--; cs++) { n     solve(cs); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void seive(bool a[], long long int n) { n   for (int i = 2; i * i <= n; i++) { n     if (a[i] == true) { n       for (int j = i * i; j <= n; j += i) a[j] = false; n     } n   } n } n int np(bool a[], long long int ppr, long long int n) { n   ppr++; n   while (ppr <= n) { n     if (a[ppr] == true) return ppr; n     ppr++; n   } n   return -1; n } n int main() { n   long long int n, i, n_1 = 0, n_2 = 0, sum = 0, s; n   int t; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> t; n     if (t == 1) n       n_1++; n     else n       n_2++; n     sum += t; n   } n   bool a[sum + 1]; n   memset(a, true, sizeof(a)); n   seive(a, sum); n   s = 0; n   a[1] = false; n   long long int ppr = 0, pr; n   while (s <= sum && pr != -1) { n     pr = np(a, ppr, sum); n     if (pr - ppr >= 2 && pr != -1) { n       s = pr; n       int m = min(n_2, (pr - ppr) / 2); n       n_2 -= m; n       for (i = 0; i < m; i++) cout << 2 <<    ; n       m = min(n_1, 2 * ((pr - ppr) / 2 - m)); n       n_1 -= m; n       for (i = 0; i < m; i++) cout << 1 <<    ; n       ppr = pr; n     } else if (pr != -1) { n       n_1--; n       if (n_1 < 0) { n         for (i = 0; i < n_1; i++) cout << 1 <<    ; n         for (i = 0; i < n_2; i++) cout << 2 <<    ; n         pr = -1; n       } else { n         cout << 1 <<    ; n       } n       ppr = pr; n     } else { n       for (i = 0; i < n_1; i++) cout << 1 <<    ; n       for (i = 0; i < n_2; i++) cout << 2 <<    ; n     } n     if (n_1 <= 0 && n_2 <= 0) break; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, z, p, i, j, k, ans, t, a[105], b[105], d[105], f[105][10005]; n bool cmp(int x, int y) { return x > y; } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]), z += a[i]; n   for (i = 1; i <= n; i++) scanf( %d , &b[i]), d[i] = b[i]; n   sort(d + 1, d + n + 1, cmp); n   memset(f, 0x80, sizeof(f)); n   f[0][0] = 0; n   for (i = 1; i <= n; i++) { n     p += d[i]; n     if (p >= z) { n       ans = i; n       break; n     } n   } n   for (i = 1; i <= n; i++) n     for (j = p; j >= b[i]; j--) n       for (k = 1; k <= ans; k++) n         f[k][j] = max(f[k][j], f[k - 1][j - b[i]] + a[i]); n   for (i = z; i <= p; i++) t = max(t, f[ans][i]); n   printf( %d %d , ans, z - t); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int m[100002]; n int main() { n   memset(m, 255, sizeof m); n   int runs; n   scanf( %d , &runs); n   for (int j = 0; j < runs; j++) { n     int x, y, ret = 0; n     scanf( %d%d , &x, &y); n     for (int i = 1; i * i <= x; i++) n       if (x % i == 0) { n         if (m[i] < j - y) ret++; n         if (i * i < x && m[x / i] < j - y) ret++; n         m[i] = j; n         m[x / i] = j; n       } n     printf( %d n , ret); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N_MAX = 1e5; n bool in[N_MAX + 1]; n int t, n, a[N_MAX], m[N_MAX], pr[N_MAX + 1]; n vector<int> inc; n vector<vector<int>> sol; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> t; n   while (t--) { n     cin >> n; n     for (int i = 0; i < n; i++) cin >> a[i]; n     int k = 1, rem = n; n     while ((k + 1) * (k + 2) <= 2 * n) k++; n     for (int i = 1; i <= n; i++) in[i] = true; n     sol.clear(); n     while (0 < rem) { n       inc.clear(); n       for (int i = 0; i < n; i++) { n         if (!in[a[i]]) continue; n         if (inc.empty() || a[i] > inc.back()) { n           pr[a[i]] = (inc.empty() ? -1 : inc.back()); n           inc.push_back(a[i]); n         } else { n           auto it = upper_bound(inc.begin(), inc.end(), a[i]); n           *it = a[i]; n           pr[a[i]] = (it == inc.begin() ? -1 : *(it - 1)); n         } n       } n       if (inc.size() <= k) { n         int first = sol.size(); n         sol.push_back(vector<int>()); n         m[first] = n + 1; n         for (int i = 0; i < n; i++) { n           if (!in[a[i]]) continue; n           if (m[(int)sol.size() - 1] < a[i]) { n             m[sol.size()] = a[i]; n             sol.push_back(vector<int>()); n             sol.back().push_back(a[i]); n             continue; n           } n           int l = first, r = (int)sol.size() - 1; n           while (l < r) { n             int mid = (l + r) / 2; n             if (m[mid] > a[i]) n               r = mid; n             else n               l = mid + 1; n           } n           sol[l].push_back(a[i]); n           m[l] = a[i]; n         } n         break; n       } n       stack<int> st; n       int act = inc.back(); n       while (act != -1) { n         st.push(act); n         act = pr[act]; n       } n       sol.push_back(vector<int>()); n       while (!st.empty()) { n         sol.back().push_back(st.top()); n         st.pop(); n       } n       for (int i : sol.back()) in[i] = false; n       rem -= inc.size(); n       while (2 * rem < k * (k + 1)) k--; n     } n     cout << sol.size() <<   n ; n     for (int i = 0; i < sol.size(); i++) { n       cout << sol[i].size(); n       for (int s : sol[i]) cout <<     << s; n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, i1; n long long cont = 0; n int main() { n   cin >> n; n   for (long long i = 0; i < n; ++i) { n     long long x, y; n     cin >> x >> y; n     if (x - y != 1) { n       cout <<  NO  << endl; n     } else { n       long long p = x + y, s = 0; n       for (long long j = 2; j <= sqrt(p); ++j) { n         if (p % j == 0) { n           s = 1; n           break; n         } n       } n       if (s == 0) { n         cout <<  YES  << endl; n       } else { n         cout <<  NO  << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n bool Max(T1& a, T2 b) { n   return a < b ? a = b, 1 : 0; n } n template <typename T1, typename T2> n bool Min(T1& a, T2 b) { n   return a > b ? a = b, 1 : 0; n } n const int N = 200002, inf = 1e9 + 1; n int s[N], g[N], ans[N]; n bool vi[N]; n vector<int> cap[N * 10]; n void solve() { n   int n, m; n   cin >> n; n   int mncap = N * 10; n   for (int i = 0; i < (n); ++i) { n     cin >> s[i] >> g[i]; n     g[i] += s[i]; n     ans[i] = g[i]; n   } n   int mn = inf; n   for (int i = 0; i < (n); ++i) { n     mn++; n     Min(mn, g[i]); n     Min(ans[i], mn); n   } n   mn = inf; n   for (int i = n - 1; i >= (0); --i) { n     mn++; n     Min(mn, g[i]); n     Min(ans[i], mn); n   } n   long long ret = 0; n   for (int i = 0; i < (n); ++i) { n     if (ans[i] < s[i]) { n       cout << -1 <<   n ; n       return; n     } n     ret += ans[i] - s[i]; n   } n   cout << ret <<   n ; n   for (int i = 0; i < (n); ++i) cout << ans[i] <<    ; n   cout <<   n ; n } n void init() {} n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.setf(ios::fixed); n   cout.precision(20); n   init(); n   int TC = 1; n   for (int TI = 1; TI <= (TC); ++TI) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Mod = 1e9 + 7; n const int N = 1000005; n long long frac[N + 5], inv[N + 5]; n int n, a[N], y[N], Max; n long long ans; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n long long power(long long a, long long b) { n   long long res = 1; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % Mod; n     a = a * a % Mod; n   } n   return res; n } n long long C(int m, int n) { return frac[n] * inv[m] % Mod * inv[n - m] % Mod; } n int main() { n   n = read(); n   frac[1] = 1; n   frac[0] = 1; n   for (int i = 2; i <= n + 2; i++) frac[i] = frac[i - 1] * i % Mod; n   inv[n + 2] = power(frac[n + 2], Mod - 2); n   for (int i = n + 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % Mod; n   inv[0] = 1; n   for (int i = 1; i <= n; i++) a[i] = read(); n   sort(a + 1, a + n + 1); n   a[0] = -1; n   for (int i = 1; i <= n; i++) { n     Max = max(Max, a[i]); n     if (a[i] == a[i - 1]) { n       y[i] = y[i - 1]; n       continue; n     } n     for (int j = i; j >= 0; j--) { n       if (a[j] != a[i]) { n         y[i] = n - j; n         break; n       } n     } n     --y[i]; n   } n   for (int i = 1; i <= n; i++) { n     if (a[i] == Max) continue; n     ans = (ans + (a[i] * frac[y[i]] % Mod * frac[n - y[i] - 1] % Mod * n                   C(y[i] + 1, n) % Mod)) % n           Mod; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n template <typename T> n using v = vector<T>; n const long long mod1 = 1e9 + 7; n const long long mod2 = 36028797018963913; n const long long inf = 2e18; n void read() {} n void print() {} n void debug() { cerr << endl; } n long long gcd(long long a, long long b) { n   if (a > b) swap(a, b); n   if (a) return gcd(a, b % a); n   return b; n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n struct vt { n   long long x, y; n   vt operator-() { return vt(-this->x, -this->y); } n   vt operator+(vt b) { return {this->x + b.x, this->y + b.y}; } n   vt operator-(vt b) { return *this + (-b); } n   vt operator*(long long b) { return vt(this->x * b, this->y * b); } n   long long operator*(vt b) { return this->x * b.x + this->y * b.y; } n   vt operator/(long long b) { return vt(this->x / b, this->y / b); } n   long long operator%(vt b) { return this->x * b.y - b.x * this->y; } n   bool operator==(vt b) { return this->x == b.x && this->y == b.y; } n   bool operator!=(vt b) { return !((*this) == b); } n   bool collinear(vt b) { return (*this) % b == 0; } n   bool opposite(vt b) { return this->collinear(b) && (*this) * b < 0; } n   double length() { return sqrt(this->x * this->x + this->y * this->y); } n   long long sqLength() { return this->x * this->x + this->y * this->y; } n   vt() {} n   vt(long long x, long long y) : x(x), y(y) {} n   vt(long long x1, long long y1, long long x2, long long y2) n       : x(x2 - x1), y(y2 - y1) {} n }; n long long fact(long long a, long long mod) { n   if (a == 1) n     return 1; n   else n     return (a * fact(a - 1, mod)) % mod; n } n long long sign(long long a) { n   if (a > 0) return 1; n   if (a == 0) return 0; n   return -1; n } n bool prime(long long a) { n   if (a < 2) return 0; n   if (a == 2) return 1; n   for (long long b = 2; b <= ceil(sqrt(a)); b++) n     if (a % b == 0) return 0; n   return 1; n } n long long pow(long long a, long long b, long long mod) { n   if (b == 0) return 1; n   if (b == 1) return a; n   long long res = pow(a, b / 2, mod); n   res = (res * res) % mod; n   if (b % 2) return (a * res) % mod; n   return res; n } n long long hashStr(string& s) { n   long long base = 26; n   long long res = 0; n   for (long long i = 0; i < ((long long)(s).size()); i++) n     res = ((res * base) % mod2 + s[i] -  a  + 1) % mod2; n   return (res + mod2) % mod2; n } n long long hashStr(long long prevHash, char curChar) { n   return ((prevHash * 26) % mod2 + curChar -  a  + 1) % mod2; n } n struct node { n   node *left = nullptr, *right = nullptr; n   long long w, val, sz = 1; n   node(long long val) : w((rand() << 16) + rand()), val(val) {} n }; n long long siz(node* a) { n   if (a == nullptr) n     return 0; n   else n     return a->sz; n } n node* treap; n node* merge1(node* v1, node* v2) { n   if (v1 == nullptr) return v2; n   if (v2 == nullptr) return v1; n   if (v1->w > v2->w) { n     v1->right = merge1(v1->right, v2); n     v1->sz = siz(v1->left) + siz(v1->right) + 1; n     return v1; n   } else { n     v2->left = merge1(v1, v2->left); n     v2->sz = siz(v2->left) + siz(v2->right) + 1; n     return v2; n   } n } n pair<node*, node*> split(node* w, long long k) { n   if (w == nullptr) return {nullptr, nullptr}; n   if (siz(w->left) >= k) { n     auto tmp = split(w->left, k); n     w->left = tmp.second; n     w->sz = siz(w->left) + siz(w->right) + 1; n     return {tmp.first, w}; n   } else { n     auto tmp = split(w->right, k - siz(w->left) - 1); n     w->right = tmp.first; n     w->sz = siz(w->left) + siz(w->right) + 1; n     return {w, tmp.second}; n   } n } n ifstream fin( input.txt ); n ofstream fout( output.txt ); n template <typename Arg, typename... Args> n void read(Arg& arg, Args&... args) { n   cin >> (arg); n   read(args...); n } n template <typename Arg, typename... Args> n void print(Arg arg, Args... args) { n   cout << (arg) <<    ; n   print(args...); n } n template <typename Arg, typename... Args> n void debug(Arg arg, Args... args) { n   cerr << (arg) <<    ; n   debug(args...); n } n void prnt(node* a) { n   if (a == nullptr) return; n   prnt(a->left); n   print(a->val); n   prnt(a->right); n } n long long getInt() { n   long long a; n   cin >> a; n   return a; n } n void run() { n   long long w, d; n   read(w, d); n   long long a[w + 1]; n   for (long long i = (0); i < (w - 1); i++) cin >> a[i + 1]; n   a[w] = 1e9; n   long long dp[w + 1]; n   dp[0] = 1e9; n   a[0] = 1e9; n   long long l = 0; n   set<long long> p; n   p.insert(0); n   for (long long i = (1); i < (w + 1); i++) { n     dp[i] = 0; n     l = max(i - d, l); n     while ((*p.begin()) < l) p.erase(*p.begin()); n     while (!p.empty()) { n       long long cur = *p.begin(); n       if (dp[cur] <= a[i] - dp[i]) { n         dp[i] += dp[cur]; n         dp[cur] = 0; n         p.erase(cur); n       } else { n         long long mn = a[i] - dp[i]; n         dp[i] = a[i]; n         dp[cur] -= mn; n         break; n       } n     } n     if (dp[i]) p.insert(i); n   } n   cout << dp[w]; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int blacks(int *pos, int n); n int whites(int *pos, int n); n int main() { n   int n; n   cin >> n; n   int board[100]; n   for (int i = 0; i < n; i++) { n     board[i] = 0; n   } n   for (int i = 0; i < n / 2; i++) { n     int temp; n     cin >> temp; n     board[temp - 1] = 1; n   } n   cout << min(blacks(board, n), whites(board, n)); n } n int blacks(int *pos, int n) { n   int i = 0; n   int label = 0; n   int result = 0; n   while (i < n) { n     if (pos[i] == 1) { n       result += abs(i - label); n       label += 2; n     } n     i++; n   } n   return result; n } n int whites(int *pos, int n) { n   int i = 0; n   int label = 1; n   int result = 0; n   while (i < n) { n     if (pos[i] == 1) { n       result += abs(i - label); n       label += 2; n     } n     i++; n   } n   return result; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int i, n, f = 0; n     cin >> n; n     vector<int> v(n); n     vector<int> use(n + 1, 0); n     for (i = 0; i < n; i++) { n       cin >> v[i]; n       if (v[i] < (i + 1)) { n         f = 1; n       } n     } n     if (f) { n       cout <<  -1  << endl; n       continue; n     } n     vector<int> a(n, 0); n     for (i = 0; i < n; i++) { n       if (!use[v[i]]) { n         a[i] = v[i]; n         use[v[i]] = 1; n       } n     } n     queue<int> q; n     for (i = 1; i <= n; i++) { n       if (!use[i]) { n         q.push(i); n       } n     } n     for (i = 0; i < n; i++) { n       if (a[i] != 0) { n         cout << a[i] <<    ; n       } else { n         cout << q.front() <<    ; n         q.pop(); n       } n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double PI = acos(-1), eps = 1e-6; n const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}; n const int N = 1e6 + 5, M = 2e6 + 5, mod = 1e9 + 7; n int n; n int p[N], c[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   int T; n   cin >> T; n   while (T--) { n     cin >> n; n     bool success = true; n     for (int i = 1, d = 0; i <= n; i++) { n       cin >> p[i] >> c[i]; n       if (p[i] < c[i] || p[i] < p[i - 1] || c[i] < c[i - 1] || p[i] - c[i] < d) n         success = false; n       d = p[i] - c[i]; n     } n     cout << (success ?  YES  :  NO ) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int maxn = 2e5 + 100; n int n, val[maxn]; n void solve() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , val + i); n   set<int> s; n   for (int i = 0; i < n; i++) s.insert((((i + val[i]) % n) + n) % n); n   puts((s.size() == n) ?  YES  :  NO ); n } n int main() { n   int t = 1; n   scanf( %d , &t); n   while (t--) solve(); n   return 0; n } n