#include <bits/stdc++.h> n using namespace std; n template <typename T> n void chkmax(T &x, T y) { n   x = x > y ? x : y; n } n template <typename T> n void chkmin(T &x, T y) { n   x = x > y ? y : x; n } n const int INF = 2139062143; n template <typename T> n void read(T &x) { n   x = 0; n   bool f = 1; n   char ch; n   do { n     ch = getchar(); n     if (ch ==  - ) f = 0; n   } while (ch >  9  || ch <  0 ); n   do { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } while (ch >=  0  && ch <=  9 ); n   x = f ? x : -x; n } n template <typename T> n void write(T x) { n   if (x < 0) x = ~x + 1, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n const int N = 1000 + 5; n const int mod = 998244353; n int n, k, ans, a[N], f[N][N], s[N][N]; n int main() { n   read(n); n   read(k); n   for (int i = 1; i <= n; i++) read(a[i]); n   sort(a + 1, a + n + 1); n   a[0] = -INF; n   for (int v = 1; v * (k - 1) <= a[n]; v++) { n     f[0][0] = s[0][0] = 1; n     int now = 0; n     for (int i = 1; i <= n; i++) { n       while (a[i] - a[now] >= v) now++; n       f[i][0] = 0; n       s[i][0] = (s[i - 1][0] + f[i][0]) % mod; n       for (int j = 1; j <= k; j++) { n         f[i][j] = s[now - 1][j - 1]; n         s[i][j] = (s[i - 1][j] + f[i][j]) % mod; n       } n     } n     ans = (ans + 1ll * s[n][k]) % mod; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const long long INF = 1e18; n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long n, r1, r2, r3, d; n   cin >> n >> r1 >> r2 >> r3 >> d; n   vector<long long> a(n), x(n), y(n); n   vector<vector<long long>> dp(n + 1, vector<long long>(2, INF)); n   dp[0][0] = 0; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (long long i = 0; i < n; i++) { n     x[i] = a[i] * r1 + r3; n     y[i] = min(r1 + r2, (a[i] + 2) * r1); n     y[i] = min(y[i], x[i]); n   } n   for (long long i = 0; i < n; i++) { n     dp[i + 1][0] = min(dp[i][0] + x[i], dp[i][1] + y[i] + d); n     dp[i + 1][1] = dp[i][0] + y[i] + d; n     if (i == n - 1) dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + x[i]); n   } n   long long ans = min(dp[n][0], dp[n][1] + d); n   ans += d * (n - 1); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, c, l = 0, t, ans = 0; n   cin >> n >> c; n   for (int i = 0; i < n; i++) { n     cin >> t; n     if (l) { n       long long x = min(t, c - l); n       l += x; n       t -= x; n     } n     ans += t / c + (l != 0); n     l = t % c; n   } n   ans += l != 0; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char ch[1000100]; n int l; n void dfs(int k) { n   if (k >= l) return; n   if (ch[k] ==  l ) { n     dfs(k + 1); n     printf( %d n , k + 1); n   } else { n     printf( %d n , k + 1); n     dfs(k + 1); n   } n } n int main() { n   scanf( %s , ch); n   l = strlen(ch); n   dfs(0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = (int)1e9; n int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1}; n int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1}; n long long n, x, y; n bool ok; n map<long long, long long> cnt; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     for (int j = 0; j < x; j++) { n       cin >> y; n       cnt[y]++; n     } n   } n   for (int i = 1; i <= 100; i++) { n     if (cnt[i] == n) { n       cout << i <<    ; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int M = 1000000007; n int n; n int dp[1000010]; n int main() { n   while (~scanf( %d , &n)) { n     int a = 0; n     for (int i = 1; i <= n; i++) { n       int x; n       scanf( %d , &x); n       if (x == 1) a++; n     } n     dp[0] = dp[1] = 1; n     for (int i = 2; i <= a; i++) n       dp[i] = (dp[i - 1] + (long long)dp[i - 2] * (i - 1)) % M; n     int ans = dp[a]; n     for (int i = a + 1; i <= n; i++) ans = (long long)ans * i % M; n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct P { n   int x, y, z; n   bool operator<(const P &a) const { return y > a.y; }; n }; n int a, b, c, d, i, k, n, m, e, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1}, n                                dy[10] = {0, 1, 0, -1, 1, -1, 1, -1}; n long long o[500101]; n int l[500111]; n int j[201001]; n long long x, y, z, mod = 998244353; n string r; n P u[500101]; n queue<int> q; n stack<int> s; n map<int, int> p; n vector<int> v; n bool as(P a, P b) { n   if (a.x != b.x) return a.x < b.x; n   return a.y > b.y; n } n int main() { n   scanf( %d %d %d , &a, &b, &c); n   for (int t = 1; t <= c; t++) { n     scanf( %d %d %d , &n, &m, &k); n     u[t] = {n, m, k}; n   } n   sort(u + 1, u + c + 1, as); n   z = 1; n   for (int i = 0; i < b; i++) { n     e = 0; n     for (int t = 1; t <= a + 1; t++) l[t] = o[t] = 0; n     for (int t = 1; t <= c; t++) n       if (u[t].z & (1 << i)) { n         int p; n         for (p = max(e + 1, u[t].x); p <= u[t].y; p++) l[p] = 1; n         e = p - 1; n       } n     e = a + 1; n     n = a; n     o[a + 1] = 1; n     x = 1; n     for (int t = c; t; t--) n       if ((u[t].z & (1 << i)) == 0 && u[t].x <= n) { n         for (; n > u[t].y; n--) n           if (!l[n]) o[n] = x, x *= 2, x %= mod; n         for (; n >= u[t].x; n--) n           if (!l[n]) { n             o[n] = x, x *= 2, x %= mod; n           } n         for (; e > u[t].y; e--) x = (x - o[e] + mod) % mod; n       } n     for (; n >= 1; n--) n       if (!l[n]) x *= 2, x %= mod; n     z *= x, z %= mod; n   } n   printf( %lld , z); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     ll a, b, n; n     cin >> a >> b >> n; n     ll cnt = 0; n     if (a > b) swap(a, b); n     while (max(a, b) <= n) { n       a += b; n       if (a > b) { n         swap(a, b); n       } n       cnt++; n     } n     cout << cnt <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; 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 << 3) + (x << 1) + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const int maxn = 2e5 + 10; n int n, q, typ, x, y, cnt, ans; n int a[maxn], in[maxn], out[maxn]; n int dep[maxn], fc[21], fa[21][maxn]; n vector<int> G[maxn]; n pair<int, int> res; n inline void dfs(int u) { n   in[u] = ++cnt; n   for (int i = 1; fc[i] <= dep[u]; ++i) fa[i][u] = fa[i - 1][fa[i - 1][u]]; n   for (int i = 0, len = G[u].size(); i < len; ++i) { n     dep[G[u][i]] = dep[u] + 1; n     fa[0][G[u][i]] = u; n     dfs(G[u][i]); n   } n   out[u] = ++cnt; n } n inline int LCA(int x, int y) { n   if (dep[x] < dep[y]) swap(x, y); n   for (int i = 0, t = dep[x] - dep[y]; t; ++i) n     if (t & fc[i]) x = fa[i][x], t ^= fc[i]; n   for (int i = 20; ~i; --i) n     if (fa[i][x] ^ fa[i][y]) x = fa[i][x], y = fa[i][y]; n   return x == y ? x : fa[0][x]; n } n namespace Segment { n pair<int, int> T[maxn << 2]; n bool anc(int x, int y) { return in[x] <= in[y] && out[x] >= out[y]; } n pair<int, int> check(pair<int, int> x, int y) { n   if (!x.first || !y) return make_pair(0, 0); n   if (anc(x.first, x.second)) swap(x.first, x.second); n   if (anc(x.second, x.first)) { n     if (anc(x.first, y)) return make_pair(y, x.second); n     if (anc(x.second, y)) { n       if (anc(y, x.first)) return x; n       if (LCA(x.first, y) == x.second) return make_pair(x.first, y); n       return make_pair(0, 0); n     } n     return make_pair(y, x.first); n   } n   if (anc(x.first, y)) return make_pair(y, x.second); n   if (anc(x.second, y)) return make_pair(x.first, y); n   if (!anc(LCA(x.first, x.second), y)) return make_pair(0, 0); n   if (!anc(y, x.first) && !anc(y, x.second)) return make_pair(0, 0); n   return x; n } n pair<int, int> merge(pair<int, int> x, pair<int, int> y) { n   if (x.first == -1) return y; n   x = check(x, y.first); n   x = check(x, y.second); n   return x; n } n void update(int rt, int l, int r, int pos, int x) { n   if (l == r) { n     T[rt] = make_pair(x, x); n     return; n   } n   int mid = l + r >> 1; n   if (pos <= mid) n     update((rt << 1), l, mid, pos, x); n   else n     update((rt << 1 | 1), mid + 1, r, pos, x); n   T[rt] = merge(T[(rt << 1)], T[(rt << 1 | 1)]); n } n bool query(int rt, int l, int r) { n   pair<int, int> tmp = merge(res, T[rt]); n   if (tmp.first) { n     res = tmp; n     ans = r; n     return true; n   } n   if (l == r) return false; n   int mid = l + r >> 1; n   if (query((rt << 1), l, mid)) query((rt << 1 | 1), mid + 1, r); n   return false; n } n }  // namespace Segment n using namespace Segment; n int main() { n   n = read(); n   fc[0] = 1; n   for (int i = 1; i <= n; ++i) a[i] = read() + 1; n   for (int i = 2; i <= n; ++i) G[read()].push_back(i); n   for (int i = 1; i <= 20; ++i) fc[i] = fc[i - 1] << 1; n   dfs(1); n   for (int i = 1; i <= n; ++i) update(1, 1, n, a[i], i); n   q = read(); n   while (q--) { n     typ = read(); n     if (typ == 1) { n       x = read(); n       y = read(); n       swap(a[x], a[y]); n       update(1, 1, n, a[x], x); n       update(1, 1, n, a[y], y); n     } else { n       res = make_pair(-1, 0); n       ans = 1; n       query(1, 1, n); n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int n, k; n   cin >> n >> k; n   long long int arr[n]; n   long long int i; n   for (i = 0; i < n; i++) cin >> arr[i]; n   double ma = 0.0; n   for (i = k; i <= n; i++) { n     double s = 0.0; n     int j; n     for (j = 0; j < i; j++) s += arr[j]; n     ma = max(ma, s / i); n     for (j = i; j < n; j++) { n       s -= arr[j - i]; n       s += arr[j]; n       ma = max(ma, s / i); n     } n   } n   cout << fixed << setprecision(20) << ma; n } n


#include <bits/stdc++.h> n using namespace std; n const long double INF = 1e18 + 7; n long long N = 1e6 * 5; n long double EPS = 1 / 1e18; n long long a[1005]; n map<long long, long long> cnt; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   for (long long i = 0; i < t; i++) { n     long long k = 0, err = 0, n; n     cin >> n; n     for (long long j = 2; j <= round(sqrt(n)); j++) { n       if (!(n % j)) { n         a[k++] = j; n         cnt[j]++; n         a[k++] = n / j; n         cnt[n / j]++; n       } n     } n     for (long long i = 0; i < k; i++) { n       for (long long j = 0; j < k; j++) { n         if (!(a[i] % a[j]) && cnt[a[i] / a[j]] != 0 && a[j] != n / a[i] && n             a[j] != a[i] / a[j] && n / a[i] != a[i] / a[j]) { n           cout <<  YES n  n                << a[j] <<     << a[i] / a[j] <<     << n / a[i] <<   n ; n           err = 1; n           break; n         } n       } n       if (err) break; n     } n     if (!err) cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int cas = 0; cas < t; cas++) { n     int n; n     cin >> n; n     vector<int> numbers(n); n     int sum = 0; n     int zer = 0; n     int ans; n     for (int i = 0; i < n; i++) { n       cin >> numbers[i]; n       sum = sum + numbers[i]; n       if (numbers[i] == 0) zer++; n     } n     if (sum > 0) { n       ans = zer; n     } else if (sum < 0) { n       if (sum == -zer) { n         ans = zer + 1; n       } else { n         ans = zer; n       } n     } else { n       if (zer == 0) { n         ans = 1; n       } else { n         ans = zer; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct debugger { n   template <typename T> n   debugger& operator,(const T& v) { n     cerr << v <<    ; n     return *this; n   } n } dbg; n int main() { n   int T; n   cin >> T; n   while (T--) { n     char c; n     int x1 = -1, y1 = -1, x2 = -1, y2 = -1; n     for (int i = (0), _n = (8); i < _n; i++) { n       for (int j = (0), _n = (8); j < _n; j++) { n         cin >> c; n         if (c ==  K  && (x1 == -1 && y1 == -1)) { n           x1 = i; n           y1 = j; n         } else if (c ==  K  && (x2 == -1 && y2 == -1)) { n           x2 = i; n           y2 = j; n         } n       } n     } n     int a = abs(x2 - x1); n     int b = abs(y2 - y1); n     if (a % 4 == 0 && b % 4 == 0) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 7; n char s[maxn]; n int fa[maxn], siz[maxn]; n int l[maxn][2]; n int n, k; n int findset(int x) { n   if (fa[x] == x) return x; n   return fa[x] = findset(fa[x]); n } n void Union(int x, int y) { n   int rx = findset(x), ry = findset(y); n   if (!ry) swap(rx, ry); n   if (rx) siz[rx] += siz[ry]; n   fa[ry] = rx; n } n int cal(int x) { n   int y = x <= k ? x + k : x - k; n   x = findset(x), y = findset(y); n   if (!x || !y) return siz[x + y]; n   return min(siz[x], siz[y]); n } n int main() { n   scanf( %d%d , &n, &k); n   scanf( %s , s + 1); n   for (int i = 1; i <= k; i++) { n     int m; n     scanf( %d , &m); n     for (int j = 1; j <= m; j++) { n       int x; n       scanf( %d , &x); n       if (l[x][0] == 0) n         l[x][0] = i; n       else n         l[x][1] = i; n     } n     siz[i] = 1; n     fa[i] = i; n     fa[i + k] = i + k; n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int x = l[i][0], y = l[i][1]; n     int rx = findset(x), ry = findset(y); n     int rxk = findset(x + k), ryk = findset(y + k); n     if (!y) { n       ans -= cal(x); n       if (s[i] ==  1 ) fa[rx] = 0; n       if (s[i] ==  0 ) fa[rxk] = 0; n       ans += cal(x); n     } else if (s[i] ==  0  && rx != ryk) { n       ans -= cal(x); n       ans -= cal(y); n       Union(x, y + k); n       Union(y, x + k); n       ans += cal(x); n     } else if (s[i] ==  1  && rx != ry) { n       ans -= cal(x); n       ans -= cal(y); n       Union(x, y); n       Union(x + k, y + k); n       ans += cal(x); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using P = pair<ll, ll>; n using PP = pair<ll, P>; n using VB = vector<bool>; n using VI = vector<ll>; n using VS = vector<string>; n using VC = vector<char>; n using VP = vector<P>; n using VPP = vector<PP>; n using VD = vector<double>; n using VVI = vector<VI>; n using VVP = vector<VP>; n using VVC = vector<VC>; n using VVB = vector<VB>; n using VVVI = vector<VVI>; n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < k; i++) { n     if (n % 10 == 0) n       n /= 10; n     else n       n--; n   } n   cout << n << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100100, M = 32401000, S = 90, oo = 1000000000; n int i, j, k, n, m, ch, ff; n int s[N]; n int F[M]; n void R(int &x) { n   ff = x = 0; n   while (ch <  0  ||  9  < ch) { n     if (ch ==  - ) ff = 1; n     ch = getchar(); n   } n   while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   if (ff) x = -x; n } n int P(int l, int r, int k) { n   int t = 0; n   l--; n   r--; n   k--; n   t = (l * S * 2 + n - r - l + S) * S + k; n   return t; n } n int min(const int &x, const int &y) { n   if (x < y) return x; n   return y; n } n int max(const int &x, const int &y) { n   if (x > y) return x; n   return y; n } n int f(int l, int r, int k, int o) { n   if (r - l + 1 < k) return 0; n   if (o == 1) { n     int ans = f(l, r - k, k, 0) - s[r] + s[r - k]; n     if (r - l + 1 >= k + 1) n       ans = min(ans, f(l, r - k - 1, k + 1, 0) - s[r] + s[r - k - 1]); n     return ans; n   } else { n     int t = P(l, r, k); n     if (F[t] < oo) return F[t]; n     int ans; n     ans = s[l + k - 1] - s[l - 1] + f(l + k, r, k, 1); n     if (r - l + 1 >= k + 1) n       ans = max(ans, s[l + k] - s[l - 1] + f(l + k + 1, r, k + 1, 1)); n     return F[t] = ans; n   } n } n int main() { n   memset(F, 60, sizeof F); n   R(n); n   for (i = 1; i <= n; i++) R(s[i]), s[i] += s[i - 1]; n   printf( %d n , f(1, n, 1, 0)); n } n


#include <bits/stdc++.h> n inline int getx() { n   char c; n   int x; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     ; n   for (x = 0; c >=  0  && c <=  9 ; c = getchar()) n     x = (x << 3) + (x << 1) + c -  0 ; n   return x; n } n bool upmax(int &a, const int &b) { return a < b ? a = b, 1 : 0; } n const int MAX_N = 10050; n int n, m; n int v[MAX_N], c[MAX_N]; n int f[MAX_N]; n int main() { n   n = getx(), m = getx(); n   int c0 = getx(), d0 = getx(); n   for (int i = c0; i <= n; ++i) upmax(f[i], f[i - c0] + d0); n   for (int i = 1; i <= m; ++i) { n     int a = getx(), b = getx(), c = getx(), d = getx(); n     for (int p = b; p <= a; p += b) { n       for (int j = n; j >= c; --j) upmax(f[j], f[j - c] + d); n     } n   } n   printf( %d n , f[n]); n } n


#include <bits/stdc++.h> n using namespace std; n struct guy { n   int x; n   int y; n   int t; n }; n int r, n; n vector<guy> arr; n vector<int> dp; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> r >> n; n   arr = vector<guy>(n); n   dp = vector<int>(n, 0); n   for (int i = 0; i < n; i++) { n     cin >> arr[i].t >> arr[i].x >> arr[i].y; n   } n   for (int i = n - 1; i >= 0; i--) { n     for (int j = i + 1; j < min(n, i + 4 * r); j++) { n       if (abs(arr[j].y - arr[i].y) + abs(arr[j].x - arr[i].x) <= n           arr[j].t - arr[i].t) n         dp[i] = max(dp[i], 1 + dp[j]); n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     if (abs(1 - arr[i].y) + abs(1 - arr[i].x) <= arr[i].t) { n       ans = max(ans, 1 + dp[i]); n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INFint = 2e9; n const long long INF = 1e18; n const long long MOD = 1000000007ll; n int g[100][100]; n vector<int> used; n set<int> roots; n int n, m; n void dfs(int v, int p) { n   used[v] = 1; n   for (int i = 0; i < n; i++) { n     if (i == p || !g[v][i]) continue; n     if (used[i] || roots.count(i)) { n       cout <<  NO ; n       exit(0); n     } n     dfs(i, v); n   } n   used[v] = 1; n } n vector<int> anc; n void addCycle(int st, int en) { n   int v = en; n   while (v != st) { n     roots.insert(v); n     v = anc[v]; n   } n   roots.insert(st); n } n bool cycle(int v, int p = -1) { n   used[v] = 1; n   for (int i = 0; i < n; i++) { n     if (i == p || !g[v][i]) continue; n     if (used[i]) { n       addCycle(i, v); n       return 1; n     } n     anc[i] = v; n     if (cycle(i, v)) return 1; n   } n   used[v] = 1; n   return 0; n } n vector<int> p; n int get(int v) { return p[v] == v ? v : p[v] = get(p[v]); } n void unite(int a, int b) { n   a = get(a); n   b = get(b); n   if (a == b) return; n   if (rand() & 1) swap(a, b); n   p[a] = b; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   used.resize(n); n   p.resize(n); n   for (int i = 0; i < n; i++) p[i] = i; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     a--, b--; n     unite(a, b); n     g[a][b] = g[b][a] = 1; n   } n   int cnt = 0; n   for (int i = 0; i < n; i++) n     if (p[i] == i) cnt++; n   if (cnt != 1) { n     cout <<  NO ; n     return 0; n   } n   anc.resize(n); n   for (int i = 0; i < n; i++) { n     if (!used[i]) { n       if (cycle(i)) break; n     } n   } n   if (roots.size() < 3) { n     cout <<  NO ; n     return 0; n   } n   used.assign(n, 0); n   for (auto v : roots) { n     for (int i = 0; i < n; i++) { n       if (g[v][i] && !roots.count(i)) { n         dfs(i, v); n       } n     } n   } n   cout <<  FHTAGN! ; n   fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC); n   ; n   return 0; n } n


#include <bits/stdc++.h> n long long memo[100005][205]; n std::pair<long long, int> pre[100005]; n int n; n struct q4 { n   int s, t, d, pin; n   long long w; n   bool operator<(const q4& wx) const { n     return ((w > wx.w) || ((w == wx.w) && (d > wx.d))); n   } n }; n std::vector<q4> Q[100005]; n std::multiset<q4> X; n long long BALLIA(int z, int m) { n   if (m < 0) n     return 100000000000000001; n   else if (z > n) n     return 0; n   if (memo[z][m] != -1) return memo[z][m]; n   long long ans = 100000000000000001; n   if (pre[z] != std::make_pair(0LL, 0)) n     ans = std::min(pre[z].first + BALLIA(pre[z].second + 1, m), n                    BALLIA(z + 1, m - 1)); n   else n     ans = BALLIA(z + 1, m); n   memo[z][m] = ans; n   return ans; n } n int main(void) { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(NULL); n   std::cout.tie(NULL); n   memset(memo, -1, sizeof(memo)); n   int m, k; n   std::cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) pre[i] = std::make_pair(0LL, 0); n   for (int i = 1; i <= k; i++) { n     int s, t, d; n     long long w; n     std::cin >> s >> t >> d >> w; n     Q[s].push_back({s, t, d, 1, w}); n     Q[t + 1].push_back({s, t, d, -1, w}); n   } n   for (int i = 1; i <= n; i++) { n     for (auto u : Q[i]) { n       if (u.pin == 1) n         X.insert(u); n       else n         X.erase(X.find({u.s, u.t, u.d, 1, u.w})); n     } n     if (!X.empty()) n       pre[i] = std::make_pair((*X.begin()).w, (*X.begin()).d); n     else n       pre[i] = std::make_pair(0LL, 0); n   } n   long long ans = BALLIA(1, m); n   std::cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int MAX = 2e5 + 5; n long long dis[MAX]; n int a[MAX], ans[MAX]; n int pos[MAX]; n vector<pair<int, int> > adj[MAX]; n void dfs(int x, int idx, long long d) { n   pos[idx] = x; n   dis[idx] = d; n   int len = lower_bound(dis, dis + idx + 1, d - a[x]) - dis - 1; n   ans[pos[len]]--; n   ans[x]++; n   for (int i = 0; i < ((int)(adj[x]).size()); i += 1) { n     dfs(adj[x][i].first, idx + 1, d + adj[x][i].second); n     ans[x] += ans[adj[x][i].first]; n   } n } n int main(int argc, char* argv[]) { n   if (argc == 2 or argc == 3) freopen(argv[1],  r , stdin); n   if (argc == 3) freopen(argv[2],  w , stdout); n   ios::sync_with_stdio(false); n   int n, p, w; n   cin >> n; n   for (int i = 1; i < n + 1; i += 1) { n     cin >> a[i]; n   } n   for (int i = 2; i < n + 1; i += 1) { n     cin >> p >> w; n     adj[p].push_back(make_pair(i, w)); n   } n   dis[0] = -1; n   dfs(1, 1, 0); n   for (int i = 1; i < n + 1; i += 1) n     if (i == 1) n       cout << ans[i] - 1; n     else n       cout <<     << ans[i] - 1; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main(int argc, char const *argv[]) { n   int n, a, b; n   while (scanf( %d%d%d , &n, &a, &b) != EOF) n     printf( %d n , (n - a) < (b + 1) ? (n - a) : (b + 1)); n   return 0; n } n


#include <bits/stdc++.h> n static const int MAXN = 2e5 + 10; n int n, m; n std::pair<int, int> p[MAXN]; n int x_idx[MAXN], x[MAXN]; n int a_i, l_i; n inline int solve_query(int u, int len) { n   while (true) { n     int last_len = len; n     int p = std::upper_bound(x, x + n, x[u] + len) - x - 1; n     len -= (x[p] - x[u]); n     int q = std::lower_bound(x, x + n, x[p] - len) - x; n     len -= (x[p] - x[q]); n     if (p == q) n       return q; n     else if (u == q) n       len %= (last_len - len); n     u = q; n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &p[i].first); n     p[i].second = i + 1; n   } n   std::sort(p, p + n); n   for (int i = 0; i < n; ++i) { n     x[i] = p[i].first; n     x_idx[p[i].second] = i; n   } n   for (int i = 0; i < m; ++i) { n     scanf( %d%d , &a_i, &l_i); n     printf( %d n , p[solve_query(x_idx[a_i], l_i)].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100010]; n int main() { n   long long n; n   cin >> n; n   long long tmp = n; n   for (int i = 2; (long long)i * i <= tmp; i++) { n     if (tmp % i == 0) { n       a[++a[0]] = i; n       while (tmp % i == 0) { n         tmp /= i; n       } n     } n   } n   if (tmp != 1) { n     a[++a[0]] = tmp; n   } n   if (a[0] == 1) { n     cout << a[1] << endl; n   } else { n     puts( 1 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   long long l; n   cin >> n >> l; n   long long *lanterns = new long long[n]; n   for (long long i = 0; i < n; i++) cin >> lanterns[i]; n   double maxDistance = 0; n   sort(lanterns, lanterns + n); n   for (long long i = 0; i < n - 1; i++) n     if (lanterns[i + 1] - lanterns[i] > maxDistance) n       maxDistance = lanterns[i + 1] - lanterns[i]; n   if (maxDistance < lanterns[0] * 2) maxDistance = lanterns[0] * 2; n   if (maxDistance < (l - lanterns[n - 1]) * 2) n     maxDistance = (l - lanterns[n - 1]) * 2; n   cout << fixed; n   cout << maxDistance / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   set<int> ms; n   for (int i = 0; i < n; ++i) { n     int x; n     cin >> x; n     if (x) ms.insert(x); n   } n   cout << ms.size() <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double pi = acos(-1); n void Open() {} n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n void PrintNumber(int n, int len) { n   if (!len) return; n   cout << (n & 1); n } n void PrintAllSubset(int n) { n   for (int i = 0; i < (1 << n); i++) { n     PrintNumber(i, n); n     cout <<   n ; n   } n } n void trr() {} n int main() { n   std::ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   long long n, m; n   cin >> n >> m; n   map<pair<int, int>, int> mpp; n   map<int, int> mp; n   int x, y; n   vector<pair<int, int>> a(m); n   for (int i = 0; i < m; i++) { n     cin >> x >> y; n     a[i] = {x, y}; n     mpp[{x, y}]++; n     mpp[{y, x}]++; n     mp[x]++; n     mp[y]++; n   } n   long long h = 0; n   while (true) { n     int c = 0; n     vector<int> r; n     for (int i = 0; i < a.size(); i++) { n       if (mp[a[i].first] == 0 || mp[a[i].second] == 0) continue; n       if (mp[a[i].first] == 1 || mp[a[i].second] == 1) { n         c++; n         r.push_back(i); n       } n     } n     for (int i = 0; i < r.size(); i++) { n       mp[a[r[i]].first]--; n       mp[a[r[i]].second]--; n     } n     if (c > 0) n       h++; n     else n       break; n   } n   cout << h; n } n


#include <bits/stdc++.h> n int main() { n   int a, b; n   scanf( %d%d , &a, &b); n   if (a == b) n     printf( %d n , a); n   else n     printf( 2 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool visited[100005]; n vector<long long> mp[100005]; n long long res = 0; n long long ans = 0; n const long long U = 1e8 + 7; n void dfs(long long second) { n   visited[second] = true; n   ans++; n   for (int i = 0; i < mp[second].size(); i++) { n     res++; n     if (visited[mp[second][i]] == false) { n       dfs(mp[second][i]); n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n, m; n   cin >> n >> m; n   memset(visited, false, sizeof visited); n   for (int i = 0; i < m; i++) { n     long long a, b; n     cin >> a >> b; n     mp[a].push_back(b); n     mp[b].push_back(a); n   } n   long long x = 0; n   for (int i = 0; i < n; i++) { n     if (visited[i] == false) { n       res = 0; n       ans = 0; n       dfs(i); n       res = res / 2; n       if (res == ans - 1) x++; n     } n   } n   cout << x - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int m[100005], v[100005], selected[100005]; n vector<pair<pair<int, int>, int> > V; n int k, n, h; n bool check(long double time) { n   long double pos = 1.0; n   int id = 0; n   for (int i = 0; i < n; i++) { n     if (V[i].first.second * 1.0 * time >= pos * h) { n       selected[id++] = V[i].second; n       pos += 1.0; n     } n   } n   return (id >= k); n } n int main() { n   V.clear(); n   cin >> n >> k >> h; n   for (int i = 0; i < n; ++i) cin >> m[i]; n   for (int i = 0; i < n; ++i) cin >> v[i]; n   for (int i = 0; i < n; ++i) V.push_back(make_pair(make_pair(m[i], v[i]), i)); n   sort((V).begin(), (V).end()); n   long double l = 0, r = 1000000009, mid; n   for (int i = 0; i < 200; i++) { n     mid = (l + r) * 0.5; n     if (check(mid)) n       r = mid; n     else n       l = mid; n   } n   check(r); n   for (int i = 0; i < k; ++i) { n     if (i != 0) cout <<    ; n     cout << selected[i] + 1; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n struct dsu { n   int forests = 0, parent[N], groupsize[N]; n   void add(int x) { n     parent[x] = x; n     groupsize[x] = 1; n     forests++; n   } n   int findset(int node) { n     if (parent[node] == node) return node; n     return parent[node] = findset(parent[node]); n   } n   bool issameset(int x, int y) { return findset(x) == findset(y); } n   void link(int i, int j) { n     int x = findset(i), y = findset(j); n     if (x == y) return; n     if (groupsize[x] < groupsize[y]) swap(x, y); n     groupsize[x] += groupsize[y]; n     parent[y] = x; n     forests--; n   } n }; n map<long long, int> mp; n map<int, vector<pair<int, int>>> e; n int main() { n   ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0), n       cout.tie(0); n   ; n   int n, m; n   cin >> n >> m; n   dsu mst; n   for (int i = 1; i <= n; ++i) mst.add(i); n   for (int i = 1; i <= m; ++i) { n     int x, y, c; n     cin >> x >> y >> c; n     e[c].push_back({x, y}); n   } n   long long sum = 0, mx = 0; n   for (auto u : e) { n     int add = 0; n     for (auto uu : u.second) { n       if (!mst.issameset(uu.first, uu.second)) { n         add++; n       } n     } n     for (auto uu : u.second) { n       if (!mst.issameset(uu.first, uu.second)) { n         add--; n         mst.link(uu.first, uu.second); n       } n     } n     sum += add; n   } n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   long long team1 = 0, team2 = 0; n   cin >> a; n   cin >> b; n   for (int i = 0; i <= a.size(); i++) { n     if ((a[i] ==  [  && b[i] ==  ( ) || (a[i] ==  8  && b[i] ==  [ ) || n         (a[i] ==  (  && b[i] ==  8 )) { n       team1++; n     } else if ((b[i] ==  [  && a[i] ==  ( ) || (b[i] ==  8  && a[i] ==  [ ) || n                (b[i] ==  (  && a[i] ==  8 )) { n       team2++; n     } n   } n   if (team1 > team2) { n     cout <<  TEAM 1 WINS ; n   } else if (team1 < team2) { n     cout <<  TEAM 2 WINS ; n   } else { n     cout <<  TIE ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int q; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> q; n   while (q--) { n     bool ch = false; n     string s; n     cin >> s; n     if (s.size() == 1) { n       if (s[0] ==  ? ) n         cout <<  a ; n       else n         cout << s; n     } else { n       if (s[0] ==  ? ) { n         if (s[1] ==  a  || s[1] ==  b ) n           s[0] =  c ; n         else n           s[0] =  a ; n       } n       for (int i = 1; i < s.size(); i++) { n         if (s[i] ==  ? ) { n           bool a = 0, b = 0, c = 0; n           if (s[i - 1] ==  a  || s[i + 1] ==  a ) a = 1; n           if (s[i - 1] ==  b  || s[i + 1] ==  b ) b = 1; n           if (s[i - 1] ==  c  || s[i + 1] ==  c ) c = 1; n           if (!a) s[i] =  a ; n           if (!b) s[i] =  b ; n           if (!c) s[i] =  c ; n         } n       } n       if (s[s.size() - 1] ==  ? ) { n         if (s[s.size() - 2] ==  a  || s[s.size() - 2] ==  b ) n           s[s.size() - 1] =  c ; n         else n           s[s.size() - 1] =  a ; n       } n       for (int i = 0; i < s.size() - 1; i++) n         if (s[i] == s[i + 1]) ch = 1; n       if (!ch) n         cout << s; n       else n         cout << -1; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[300]; n int main() { n   int n, k, cnt = 0; n   cin >> n >> k; n   for (int i = 0; i < 2 * n + 1; i++) cin >> a[i]; n   for (int i = 1; (i <= 2 * n - 1) && (cnt != k); i += 2) { n     if (a[i] - 1 > a[i - 1] && a[i] - 1 > a[i + 1]) { n       a[i]--; n       cnt++; n     } n   } n   for (int i = 0; i < 2 * n + 1; i++) cout << a[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int N = 1E5; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   string s; n   cin >> s; n   int len = s.size(); n   int ans = 0; n   for (int i = 0; i < len; i++) { n     int l = 0, r = 0; n     for (int j = i; j < len; j++) { n       if (s[j] ==  ( ) { n         l++, r++; n       } else if (s[j] ==  ) ) { n         l--, r--; n       } else { n         l--, r++; n       } n       if (r < 0) break; n       if (l < 0) { n         l += 2; n       } n       if (l == 0) { n         ans++; n       } n     } n   } n   cout << ans << endl; n } n


/* n Author: Sanskar Agarwal n Nick: sanskaragarwal n Birla Institute Of Technology, Mesra n */ n #include <bits/stdc++.h> n using namespace std; n #define ll long long int n #define endl   n  n #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); n #define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++) n #define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--) n #define INF 100009 n #define mod 1000000007 n #define pb(x) push_back(x) n #define mp(x,y) make_pair(x,y) n #define ff first n #define ss second n #define test while(t--)solve(); n  n void solve() n { n  int n; n  cin >> n; n  int pos[32]; n  int arr[n]; n  memset(pos, 0, sizeof(pos)); n  int xo = 0; n  int pre[n]; n  for (int i = 0; i < n; ++i) n  { n   cin >> arr[i]; n   xo ^= arr[i]; n   pre[i] = xo; n  } n  bool flag = !xo; n  for (int i = 0; i < n; ++i) n  { n   for (int j = i + 1; j < n; ++j) n   { n    int sp1 = pre[i]; n    int sp2 = pre[j] ^ pre[i]; n    int sp3 = pre[n - 1] ^ pre[j]; n    flag |= (sp1 == sp2 && sp2 == sp3); n   } n  } n  if (flag) n   cout <<  YES  << endl; n  else n   cout <<  NO  << endl; n } n  n int main() n { n #ifndef ONLINE_JUDGE n  freopen( input.txt ,  r , stdin); n  freopen( output.txt ,  w , stdout); n #endif n  fast n  int t; n  // t = 1; n  cin >> t; n  test; n #ifndef ONLINE_JUDGE n  cout <<   nTime Elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   s n ; n #endif n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 55; n int type; n const long long int mod = 1e9 + 7; n long long C[N][N]; n void matrix_mul(long long A[N][N], long long B[N][N]) { n   for (int i = 0; i < type; i++) { n     for (int j = 0; j < type; j++) { n       C[i][j] = 0; n       for (int k = 0; k < type; k++) { n         C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod; n       } n     } n   } n   for (int i = 0; i < type; i++) { n     for (int j = 0; j < type; j++) { n       A[i][j] = C[i][j]; n     } n   } n } n void pow(long long A[N][N], long long m) { n   long long res[N][N]; n   memset(res, 0, sizeof(res)); n   for (int i = 0; i < type; i++) res[i][i] = 1; n   while (m) { n     if (m & 1) matrix_mul(res, A); n     matrix_mul(A, A); n     m >>= 1; n   } n   for (int i = 0; i < type; i++) { n     for (int j = 0; j < type; j++) { n       A[i][j] = res[i][j]; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   long long n, m, k; n   cin >> n >> m >> k; n   type = m; n   long long M[N][N]; n   for (int i = 0; i < m; i++) n     for (int j = 0; j < m; j++) M[i][j] = 1; n   while (k--) { n     string str; n     cin >> str; n     char x1 = str[0]; n     int x1n; n     char x2 = str[1]; n     int x2n; n     if (x1 >=  a  && x1 <=  z ) n       x1n = x1 -  a ; n     else if (x1 >=  A  && x1 <=  Z ) n       x1n = x1 -  A  + 26; n     if (x2 >=  a  && x2 <=  z ) n       x2n = x2 -  a ; n     else if (x2 >=  A  && x2 <=  Z ) n       x2n = x2 -  A  + 26; n     M[x1n][x2n] = 0; n   } n   pow(M, n - 1); n   long long sum = 0; n   for (int i = 0; i < m; i++) n     for (int j = 0; j < m; j++) sum = (sum + M[i][j]) % mod; n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class t> n inline void rd(t &s) { n   s = 0; n   register char c = getchar(); n   while (!isdigit(c)) c = getchar(); n   while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); n   return; n } n int ans[5050]; n signed main(void) { n   register int n, x1, x2, x3, x; n   scanf( %d , &n); n   printf( ? 1 2 n ); n   fflush(stdout); n   scanf( %d , &x1); n   printf( ? 2 3 n ); n   fflush(stdout); n   scanf( %d , &x2); n   printf( ? 1 3 n ); n   fflush(stdout); n   scanf( %d , &x3); n   ans[2] = (x1 + x2 - x3) / 2; n   ans[1] = x1 - ans[2]; n   ans[3] = x2 - ans[2]; n   for (int i = 4; i <= n; ++i) { n     printf( ? %d %d n , i - 1, i); n     fflush(stdout); n     scanf( %d , &x); n     ans[i] = x - ans[i - 1]; n   } n   printf( !  ); n   for (int i = 1; i <= n; ++i) printf( %d  , ans[i]); n   printf(  n ); n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int ZIMAX = 3005; n int n, v; n int cnt[ZIMAX]; n int main() { n   cin >> n >> v; n   for (int i = 1; i <= n; ++i) { n     int ai, bi; n     cin >> ai >> bi; n     cnt[ai] += bi; n   } n   int ans = 0; n   int before = 0; n   for (int i = 0; i < ZIMAX; ++i) { n     int azi = before; n     int ramase = v - azi; n     if (ramase < 0) { n       ans += v; n       before = cnt[i]; n     } else { n       azi += (cnt[i] <= ramase ? cnt[i] : ramase); n       ans += azi; n       before = max(0, cnt[i] - ramase); n     } n   } n   cout << ans <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10, mod = 1e9 + 7; n inline int ad(int x, int y) { n   int ans = x + y; n   if (ans > mod) ans -= mod; n   return ans; n } n inline int mu(int x, int y) { return 1LL * x * y % mod; } n inline int wop(int x, int y) { n   int ret = 1; n   while (y) { n     if (y & 1) ret = mu(ret, x); n     y >>= 1; n     x = mu(x, x); n   } n   return ret; n } n int fact[maxn], inv[maxn], lst[maxn], pr[maxn], cnt[maxn]; n int num[maxn][20]; n int pw[maxn], pww[maxn]; n inline void prep() { n   int n = maxn - 5; n   fact[0] = 1; n   for (int i = 1; i < n; i++) fact[i] = mu(fact[i - 1], i); n   for (int i = 0; i < n; i++) inv[i] = wop(fact[i], mod - 2); n   pr[0] = pr[1] = 1; n   for (int i = 2; i < 300005; i++) { n     if (pr[i] == 0) { n       lst[i] = i; n       for (int j = i * 2; j < 300005; j += i) lst[j] = i, pr[j] = 1; n     } n   } n   for (int i = 1; i < n; i++) pw[i] = ad(mu(pw[i - 1], 2), 1); n   pww[0] = 1; n   for (int i = 1; i < n; i++) pww[i] = ad(pww[i - 1], pww[i - 1]); n } n inline int C(int r, int n) { n   if (r < 0 || r > n) return 0; n   return mu(mu(fact[n], inv[n - r]), inv[r]); n } n inline int cal(int x, int y) { n   if (x < 0 || y < 1) return 0; n   if (x == 0) return pw[y]; n   int ans = 0; n   for (int i = 1; i <= y; i++) n     ans = ad(ans, mu(pw[i], C(x - 1, x - 1 + y - i))); n   return ans; n } n inline int f(int x, int y) { n   if (y <= x) return cal(x, y); n   int oth = cal(y, x); n   int eq = 0; n   for (int i = 0; i <= min(x, y); i++) eq = ad(eq, mu(C(i, x), C(i, y))); n   oth = ad(oth, eq); n   return ad(pww[x + y], mod - oth); n } n inline int ff(int x, int y) { return f(x + 1, y - 1); } n int ps[20], answer[20]; n int solve(vector<int> a, bool rev) { n   int n = a.size(); n   for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i - 1]; n   int ans = 0; n   for (int j = 1; j < n; j++) { n     int tmp; n     if (rev) tmp = f(ps[j] - 1, ps[n] - ps[j]); n     if (!rev) tmp = ff(ps[j] - 1, ps[n] - ps[j]); n     answer[j] = tmp; n   } n   for (int i = 0; i < n; i++) { n     int sum = 0; n     for (int j = i + 1; j < n; j++) sum = ad(sum, answer[j]); n     ans = ad(ans, mu(sum, a[i])); n   } n   return ans; n } n int main() { n   prep(); n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     cnt[x]++; n   } n   for (int i = 1; i <= 1e6; i++) { n     if (cnt[i] == 0) continue; n     int cur = i; n     while (cur != 1) { n       int p = lst[cur], tav = 0; n       while (cur % p == 0) cur /= p, tav++; n       num[p][tav] += cnt[i]; n     } n   } n   int ans = 0; n   for (int i = 2; i <= 300000; i++) { n     if (pr[i]) continue; n     vector<int> a; n     int sum = 0; n     for (int j = 1; j < 20; j++) sum += num[i][j]; n     if (sum == 0) continue; n     a.push_back(n - sum); n     for (int j = 1; j < 20; j++) a.push_back(num[i][j]); n     ans = ad(ans, solve(a, 0)); n     reverse(a.begin(), a.end()); n     ans = ad(ans, solve(a, 1)); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> e[200005], E[200005], v; n int vis[200005]; n inline void dfs(int u) { n   if (vis[u]) return; n   vis[u] = 1; n   v.push_back(u); n   int x = E[u][0], y = E[u][1]; n   if (e[x][0] == e[u][0] || e[x][0] == e[u][1] || e[x][1] == e[u][1] || n       e[x][1] == e[u][0]) n     dfs(x); n   dfs(y); n } n int main(int argc, char** argv) { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x, y; n     cin >> x >> y; n     e[i].push_back(y); n     e[i].push_back(x); n     E[x].push_back(i); n     E[y].push_back(i); n   } n   dfs(1); n   for (int i = v.size() - 1; i >= 0; i--) cout << v[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n; n   cin >> n; n   string s1; n   cin >> s1; n   vector<pair<char, int> > v; n   long long int sz = s1.size(); n   long long int j = 0; n   while (j < sz) { n     char ch = s1[j]; n     if (v.empty() || v.back().first != ch) n       v.push_back({ch, 1}); n     else n       v.back().second++; n     j++; n   } n   long long int ans; n   if (v.front().second > 1) { n     ans = v.front().second - 1; n   } else n     ans = 1; n   string s2 =   ; n   s2 += v.front().first; n   long long int f = 0; n   for (long long int i = 1; i < v.size(); i++) { n     if (f) { n       s2 += v[i].first; n       f = 0; n     } else { n       if (v[i].second == 1) { n         s2 += v[i].first; n         f = 1; n       } else { n         s2 += v[i].first; n         s2 += v[i].first; n       } n     } n   } n   long long int sz2 = s2.size(); n   if (sz2 == 0 || sz2 % 2 == 0) { n     cout << n - sz2 << endl; n     cout << s2 << endl; n   } else { n     cout << n - sz2 + 1 << endl; n     s2[sz2 - 1] =   0 ; n     long long int j = 0; n     while (j < sz2 - 1) { n       cout << s2[j]; n       j++; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct state { n   int x, y; n } bl[100005], rec[100005], cur[100005]; n long long n, m; n bool cmp(const state& a, const state& b) { n   if (a.y == b.y) return a.x < b.x; n   return a.y < b.y; n } n bool funct() { n   int counter = 1; n   rec[0].x = 1, rec[0].y = 1; n   for (int i = 0; i < (int)m; i++) { n     if (bl[i].y != bl[i - 1].y + 1) { n       counter = 1; n       rec[0].y = n; n     } n     int k = i + 1; n     int tmp = 0; n     int c = 0; n     for (k = i + 1; bl[k].y == bl[i].y; k++) n       ; n     k = k - 1; n     for (int j = i; j <= k; j++) { n       if (bl[j].x > tmp + 1) { n         cur[c].x = tmp + 1; n         cur[c].y = bl[j].x - 1; n         c++; n       } n       tmp = bl[j].x; n     } n     if (n > tmp) { n       cur[c].x = tmp + 1; n       cur[c].y = n; n       c++; n     } n     int t = 0; n     for (int i = 0; i < counter; i++) { n       while (cur[t].x <= rec[i].y && t < c) { n         if (cur[t].y >= rec[i].x) { n           cur[t].x = max(cur[t].x, rec[i].x); n         } else { n           cur[t].x = cur[t].y = -1; n         } n         t++; n       } n       if (t >= c) break; n     } n     counter = 0; n     for (int i = 0; i < t; i++) n       if (cur[i].x != -1 && cur[i].y != -1) { n         rec[counter].x = cur[i].x; n         rec[counter].y = cur[i].y; n         counter++; n       } n     if (counter == 0) return false; n     i = k; n   } n   if (bl[m - 1].y != n) { n     return true; n   } n   if (rec[counter - 1].y == n) { n     return true; n   } else { n     return false; n   } n } n int main() { n   cin >> n >> m; n   int xx; n   int yy; n   for (int i = 0; i < (int)m; i++) { n     cin >> xx >> yy; n     bl[i].x = xx; n     bl[i].y = yy; n   } n   sort(bl, bl + m, cmp); n   if (funct()) { n     cout << 2 * n - 2 << endl; n   } else { n     printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long x; n int n, d; n int res[100010], a[100010], b[100010]; n long long getNextX() { n   x = (x * 37 + 10007) % 1000000007; n   return x; n } n void initab() { n   for (int i = 0; i < n; i++) { n     a[i] = i + 1; n   } n   for (int i = 0; i < n; i++) { n     swap(a[i], a[getNextX() % (i + 1)]); n   } n   for (int i = 0; i < n; i++) { n     if (i < d) n       b[i] = 1; n     else n       b[i] = 0; n   } n   for (int i = 0; i < n; i++) { n     swap(b[i], b[getNextX() % (i + 1)]); n   } n } n void sol1() { n   for (int i = 0; i < n; i++) n     if (b[i]) { n       for (int j = i; j < n; j++) n         if (res[j] < a[j - i]) res[j] = a[j - i]; n     } n } n void sol2() { n   int k = n - sqrt(n); n   for (int i = 0; i < n; i++) n     if (a[i] >= k) { n       int l = n - i; n       for (int j = 0; j < l; j++) n         if (b[j] && res[j + i] < a[i]) res[j + i] = a[i]; n     } n   for (int i = 0; i < n; i++) n     if (!res[i]) { n       for (int j = 0; j <= i; j++) n         if (b[i - j] && res[i] < a[j]) res[i] = a[j]; n     } n } n int main() { n   cin >> n >> d >> x; n   initab(); n   int sd = sqrt(n) * 4; n   if (d <= sd) n     sol1(); n   else n     sol2(); n   for (int i = 0; i < n; i++) printf( %d n , res[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int max_n = 2e5 + 10; n int n, temp; n vector<int> ans; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> temp; n     int pos = lower_bound(ans.begin(), ans.end(), temp) - ans.begin(); n     if (pos == ans.size()) n       ans.push_back(temp); n     else n       ans[pos] = temp; n   } n   cout << ans.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m, k; n   cin >> n >> m >> k; n   int r = m * n - 2 * (k - 1); n   cout << r <<    ; n   int i = 0, j = 0; n   for (; i < n; i++) { n     if (i % 2 == 0) { n       for (j = 0; j < m; j++) { n         cout << i + 1 <<     << j + 1 <<    ; n         r--; n         if (r == 0) break; n       } n     } else { n       for (j = m; j > 0; j--) { n         cout << i + 1 <<     << j <<    ; n         r--; n         if (r == 0) break; n       } n     } n     if (r == 0) break; n   } n   if (i % 2 == 0) { n     if (j != m) n       j++; n     else n       i++; n   } else { n     if (j != 0) n       j--; n     else n       i++; n   } n   cout << endl; n   r = 2; n   for (; i < n; i++) { n     if (i % 2 == 0) { n       for (; j < m; j++) { n         if (r == 2) cout << r <<    ; n         cout << i + 1 <<     << j + 1 <<    ; n         r--; n         if (r == 0) { n           cout << endl; n           r = 2; n         } n       } n     } else { n       for (; j > 0; j--) { n         if (r == 2) cout << r <<    ; n         cout << i + 1 <<     << j <<    ; n         r--; n         if (r == 0) { n           cout << endl; n           r = 2; n         } n       } n     } n     if (r == 0) r = 2; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int digit(char c) { n   char digits[] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 }; n   for (int i = 0; i < 10; i++) { n     if (c == digits[i]) return 0; n   } n   return 1; n } n int main() { n   int t = 0; n   scanf( %d , &t); n   while (t--) { n     string s; n     cin >> s; n     int len = s.length(); n     int d = 1, c = 1, l = 1; n     int cd = 0, cc = 0, cl = 0; n     int flag = 0; n     for (int i = 0; i < len; i++) { n       if (int(s[i]) >= 48 && int(s[i]) <= 57) { n         d = 0; n         ++cd; n       } else if (tolower(s[i]) == s[i]) { n         l = 0; n         ++cl; n       } else if (toupper(s[i]) == s[i]) { n         c = 0; n         ++cc; n       } n       if ((d + c + l) == 0) { n         flag = 1; n         break; n       } n     } n     if (flag == 1) { n       cout << s << endl; n       continue; n     } n     if ((d + c + l) == 1) { n       if (d) { n         if (cl <= cc) { n           for (int i = 0; i < len; i++) { n             if (toupper(s[i]) == s[i]) { n               s[i] =  7 ; n               break; n             } n           } n         } else { n           for (int i = 0; i < len; i++) { n             if (tolower(s[i]) == s[i]) { n               s[i] =  7 ; n               break; n             } n           } n         } n         d = 0; n       } n       if (c) { n         if (cl <= cd) { n           for (int i = 0; i < len; i++) { n             if (int(s[i]) >= 48 && int(s[i]) <= 57) { n               s[i] =  A ; n               break; n             } n           } n         } else { n           for (int i = 0; i < len; i++) { n             if (tolower(s[i]) == s[i] && digit(s[i])) { n               s[i] = toupper(s[i]); n               break; n             } n           } n         } n         c = 0; n       } n       if (l) { n         if (cc <= cd) { n           for (int i = 0; i < len; i++) { n             if (int(s[i]) >= 48 && int(s[i]) <= 57) { n               s[i] =  a ; n               break; n             } n           } n         } else { n           for (int i = 0; i < len; i++) { n             if (toupper(s[i]) == s[i] && digit(s[i])) { n               s[i] = tolower(s[i]); n               break; n             } n           } n         } n       } n       l = 0; n     } n     if ((d + c + l) == 2) { n       if (!d) { n         s[0] =  A ; n         s[1] =  a ; n       } n       if (!c) { n         s[0] =  a ; n         s[1] =  7 ; n       } n       if (!l) { n         s[0] =  A ; n         s[1] =  7 ; n       } n     } n     cout << s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int root[1000100]; n unordered_map<int, int> mp[1000100]; n pair<pair<int, int>, int> edge[1000100]; n int cnt[1000100]; n int find_root(int u) { n   if (root[u] == u) return u; n   return root[u] = find_root(root[u]); n } n bool cmp(pair<pair<int, int>, int> u, pair<pair<int, int>, int> v) { n   return u.second < v.second; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   while (m--) { n     int u, v; n     scanf( %d%d , &u, &v); n     cnt[u]++; n     cnt[v]++; n     mp[u][v] = 1; n     mp[v][u] = 1; n   } n   int mn = n, f = 0; n   for (int i = 1; i <= n; i++) { n     root[i] = i; n     if (mn > cnt[i]) { n       f = i; n       mn = cnt[i]; n     } n   } n   vector<int> X, Y; n   X.push_back(f); n   for (int i = 1; i <= n; i++) { n     if (i == f) continue; n     if (!mp[f][i]) { n       X.push_back(i); n       root[i] = f; n     } else n       Y.push_back(i); n   } n   m = 0; n   for (int i = 0; i < Y.size(); i++) { n     for (int j = i + 1; j < Y.size(); j++) { n       int u = Y[i], v = Y[j]; n       edge[++m] = pair<pair<int, int>, int>(pair<int, int>(u, v), mp[u][v]); n     } n   } n   for (int i = 0; i < Y.size(); i++) { n     for (int j = 0; j < X.size(); j++) { n       int u = Y[i], v = X[j]; n       edge[++m] = pair<pair<int, int>, int>(pair<int, int>(u, v), mp[u][v]); n     } n   } n   sort(edge + 1, edge + m + 1, cmp); n   int ans = 0; n   for (int i = 1; i <= m; i++) { n     int u = edge[i].first.first, v = edge[i].first.second, w = edge[i].second; n     int fu = find_root(u), fv = find_root(v); n     if (fu == fv) continue; n     root[fu] = fv; n     ans += w; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n double gmin = 100000000000000017; n int a, b; n int Y1[100005], Y2[100005], L[100005]; n double dist(double x1, double y1, double x2, double y2) { n   return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); n } n double f(int i, int j) { n   return dist(0, 0, a, Y1[i]) + L[j] + dist(a, Y1[i], b, Y2[j]); n } n int main() { n   int t, i, j, c, d, idx1, idx2, m, n, idx; n   scanf( %d , &n); n   scanf( %d , &m); n   scanf( %d , &a); n   scanf( %d , &b); n   for (i = 0; i < n; i++) scanf( %d , &Y1[i]); n   for (i = 0; i < m; i++) scanf( %d , &Y2[i]); n   for (i = 0; i < m; i++) scanf( %d , &L[i]); n   for (i = 0; i < m; i++) { n     int low = 0, high = n - 1; n     while (high - low >= 3) { n       int m1 = low + (high - low) / 3; n       int m2 = high - (high - low) / 3; n       if (f(m1, i) < f(m2, i)) n         high = m2; n       else n         low = m1; n     } n     double mini = 1000000000000; n     for (j = low; j <= high; ++j) { n       if (f(j, i) < mini) { n         mini = f(j, i); n         idx = j; n       } n     } n     if (mini < gmin) { n       gmin = mini; n       idx1 = idx + 1; n       idx2 = i + 1; n     } n   } n   printf( %d  , idx1); n   printf( %d  , idx2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   char s[110]; n   int x[30]; n } a[2010]; n int len, k, n; n int main() { n   scanf( %d , &k); n   scanf( %s , a[1].s); n   len = strlen(a[1].s); n   memset(a[1].x, 0, sizeof(a[1].x)); n   for (int i = 0; i < len; i++) a[1].x[a[1].s[i] -  a ]++; n   for (int i = 2; i <= k; i++) a[i] = a[i - 1]; n   scanf( %d , &n); n   while (n--) { n     int p; n     char c; n     scanf( %d %c , &p, &c); n     int i = 1; n     while (p - a[i].x[c -  a ] > 0) { n       p -= a[i].x[c -  a ]; n       i++; n     } n     for (int j = 0; j < len; j++) n       if (a[i].s[j] == c) { n         p--; n         if (p == 0) { n           a[i].s[j] =  ! ; n           a[i].x[c -  a ]--; n           break; n         } n       } n   } n   for (int i = 1; i <= k; i++) n     for (int j = 0; j < len; j++) n       if (a[i].s[j] !=  ! ) printf( %c , a[i].s[j]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n using namespace std; n const double PI = acos(-1.0); n const double eps = 1e-6; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int a[200010]; n int main() { n   int n = read(); n   int fen = 0, gu = 0; n   for (int i = 1; i <= n; i++) a[i] = read(); n   bool ok = 1; n   for (int i = 2; i <= n; i++) { n     if (a[i] == a[i - 1]) ok = 0; n   } n   if (ok == 0) { n     printf( NO ); n     return 0; n   } n   for (int i = 2; i <= n - 1; i++) { n     if (a[i - 1] < a[i] && a[i] > a[i + 1]) n       fen++; n     else if (a[i - 1] > a[i] && a[i + 1] > a[i]) n       gu++; n   } n   if (fen <= 1 && gu == 0) n     printf( YES ); n   else n     printf( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inft = 1000000009; n const int MAXN = 2000006; n bool P[MAXN]; n int SP[MAXN]; n int PAL[MAXN]; n char S[123]; n bool pal(int a) { n   sprintf(S,  %d , a); n   reverse(S, S + strlen(S)); n   int q; n   sscanf(S,  %d , &q); n   return a == q; n } n int main() { n   for (int i = 0; i < (MAXN); ++i) P[i] = 1; n   for (int i = 2; i < MAXN; ++i) n     if (P[i]) n       for (int j = 2 * i; j < MAXN; j += i) P[j] = 0; n   P[0] = P[1] = 0; n   for (int i = 0; i < (MAXN); ++i) n     if (i) SP[i] = SP[i - 1] + P[i]; n   for (int i = 1; i < MAXN; ++i) PAL[i] = PAL[i - 1] + pal(i); n   int ret = 0; n   int p, q; n   scanf( %d%d , &p, &q); n   for (int i = 0; i < (MAXN); ++i) n     if (i && q * SP[i] <= p * PAL[i]) ret = i; n   if (ret) n     printf( %d n , ret); n   else n     printf( Palindromic tree is better than splay tree n ); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char s[1000000], c; n   int x = 0, y = 0, sum = 0, d; n   scanf( %d , &d); n   for (int i = 0; i < d; i++) { n     scanf(  %c , &c); n     s[i] = c; n   } n   for (int i = 0; i < strlen(s); i++) { n     if (s[i] ==  L ) x--; n     if (s[i] ==  R ) y++; n   } n   for (int i = x; i <= y; i++) { n     sum++; n   } n   printf( %d n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void print(int x, int b) { n   if (x) { n     print(x / b, b); n     printf( %d , x % b); n   } n } n int main() { n   int k; n   cin >> k; n   for (int i = (1); i <= (k - 1); ++i) n     for (int j = (1); j <= (k - 1); ++j) n       print(i * j, k), printf( %c , j == k - 1 ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } n bool possible(long long p, long long q, long long x, long long y) { n   if (q < y) { n     return false; n   } n   if (p < x) { n     return false; n   } n   return q - y >= p - x; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long x, y, p, q; n     cin >> x >> y >> p >> q; n     long long l = 1, r = 1000000000; n     while (l < r) { n       long long mid = (l + r) / 2; n       if (possible(mid * p, mid * q, x, y)) { n         r = mid; n       } else { n         l = mid + 1; n       } n     } n     if (possible(l * p, l * q, x, y)) { n       cout << l * q - y << endl; n     } else { n       cout << -1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int q_pow(int x, int n) { n   int ret = 1; n   for (; n; n >>= 1, x = (long long)x * x % 998244353) n     if (n & 1) ret = (long long)ret * x % 998244353; n   return ret; n } n int A[100005 << 2], B[100005 << 2], tmp[100005], tx[100005], ty[100005], Q, n, n     m; n void NTT(int *a, int len, int flag) { n   int i, j, k, t, w, x, tmp; n   for (i = k = 0; i < len; i++) { n     if (i > k) swap(a[i], a[k]); n     for (j = len >> 1; (k ^= j) < j; j >>= 1) n       ; n   } n   for (k = 2; k <= len; k <<= 1) { n     t = k >> 1; n     x = q_pow(3, (998244353 - 1) / k); n     if (flag == -1) x = q_pow(x, 998244353 - 2); n     for (i = 0; i < len; i += k) n       for (w = 1, j = i; j < i + t; j++) { n         tmp = (long long)a[j + t] * w % 998244353; n         a[j + t] = (a[j] - tmp + 998244353) % 998244353; n         a[j] = (a[j] + tmp) % 998244353; n         w = (long long)w * x % 998244353; n       } n   } n   if (flag == -1) n     for (t = q_pow(len, 998244353 - 2), i = 0; i < len; i++) n       a[i] = (long long)t * a[i] % 998244353; n } n struct poly { n   vector<int> a; n   int len; n   poly() {} n   poly(int x) { n     len = 1; n     a.push_back(x); n   } n   void clear() { n     len = 0; n     a.clear(); n   } n   void rev() { reverse(a.begin(), a.end()); } n   void resize(int x) { n     a.resize(x); n     len = x; n   } n   poly operator+(const poly &b) const { n     poly c; n     c.len = max(len, b.len); n     c.resize(c.len); n     for (int i = 0; i < len; i++) c.a[i] = a[i]; n     for (int i = 0; i < b.len; i++) c.a[i] = (c.a[i] + b.a[i]) % 998244353; n     return c; n   } n   poly operator-(const poly &b) const { n     poly c; n     c.len = max(len, b.len); n     c.resize(c.len); n     for (int i = 0; i < len; i++) c.a[i] = a[i]; n     for (int i = 0; i < b.len; i++) n       c.a[i] = (c.a[i] - b.a[i] + 998244353) % 998244353; n     return c; n   } n   poly operator*(const poly &b) const { n     poly c; n     c.len = len + b.len; n     int n = 1; n     while (n < c.len) n <<= 1; n     for (int i = 0; i < len; i++) A[i] = a[i]; n     for (int i = len; i < n; i++) A[i] = 0; n     for (int i = 0; i < b.len; i++) B[i] = b.a[i]; n     for (int i = b.len; i < n; i++) B[i] = 0; n     NTT(A, n, 1); n     NTT(B, n, 1); n     for (int i = 0; i < n; i++) A[i] = (long long)A[i] * B[i] % 998244353; n     NTT(A, n, -1); n     for (int i = 0; i < c.len; i++) c.a.push_back(A[i]); n     return c; n   } n   poly operator+(const int &b) const { n     poly c; n     c.len = len; n     c.a = a; n     (c.a[0] += b) %= 998244353; n     return c; n   } n   poly operator*(const int &b) const { n     poly c; n     c.len = len; n     for (int i = 0; i < len; i++) n       c.a.push_back((long long)a[i] * b % 998244353); n     return c; n   } n   void get_inv(poly &b, int n) { n     if (n == 1) { n       b.a.push_back(q_pow(a[0], 998244353 - 2)); n       b.len = 1; n       return; n     } n     get_inv(b, n >> 1); n     int t = n << 1; n     int lim = min(len, n); n     for (int i = 0; i < lim; i++) A[i] = a[i]; n     for (int i = lim; i < t; i++) A[i] = 0; n     for (int i = 0; i < b.len; i++) B[i] = b.a[i]; n     for (int i = b.len; i < t; i++) B[i] = 0; n     NTT(A, t, 1); n     NTT(B, t, 1); n     for (int i = 0; i < t; i++) n       A[i] = (2 - (long long)A[i] * B[i] % 998244353 + 998244353) * B[i] % n              998244353; n     NTT(A, t, -1); n     for (int i = 0; i < b.len; i++) b.a[i] = A[i]; n     for (int i = b.len; i < n; i++) b.a.push_back(A[i]); n     b.len = n; n   } n   poly Dao() { n     poly c; n     c.len = len - 1; n     for (int i = 0; i < c.len; i++) n       c.a.push_back(a[i + 1] * (i + 1ll) % 998244353); n     return c; n   } n   poly Jifen() { n     poly c; n     c.len = len + 1; n     c.a.push_back(0); n     for (int i = 0; i < len; i++) n       c.a.push_back((long long)a[i] * q_pow(i + 1, 998244353 - 2) % 998244353); n     return c; n   } n   poly get_ln(int len) { n     poly b = Dao(); n     poly c; n     get_inv(c, len); n     return (b * c).Jifen(); n   } n   void get_mod(int b) { n     for (int i = b; i < len; i++) a.pop_back(); n     len = b; n   } n   int get_val(int x) { n     int ret = a[0]; n     for (int i = 1, tmp = x; i < len; tmp = (long long)tmp * x % 998244353, i++) n       ret = (ret + (long long)a[i] * tmp) % 998244353; n     return ret; n   } n   poly operator/(poly b) { n     rev(); n     b.rev(); n     poly c; n     int n = 1; n     while (n < (len - b.len + 1)) n <<= 1; n     b.get_inv(c, n); n     c.get_mod(len - b.len + 1); n     n = 1; n     while (n < len + c.len) n <<= 1; n     for (int i = 0; i < len; i++) A[i] = a[i]; n     for (int i = len; i < n; i++) A[i] = 0; n     for (int i = 0; i < c.len; i++) B[i] = c.a[i]; n     for (int i = c.len; i < n; i++) B[i] = 0; n     NTT(A, n, 1); n     NTT(B, n, 1); n     for (int i = 0; i < n; i++) A[i] = (long long)A[i] * B[i] % 998244353; n     NTT(A, n, -1); n     for (int i = 0; i < c.len; i++) c.a[i] = A[i]; n     c.rev(); n     rev(); n     b.rev(); n     return c; n   } n   poly operator%(poly b) { n     rev(); n     b.rev(); n     poly c; n     int n = 1; n     while (n < (len - b.len + 1)) n <<= 1; n     b.get_inv(c, n); n     c.get_mod(len - b.len + 1); n     n = 1; n     while (n < len + c.len) n <<= 1; n     for (int i = 0; i < len; i++) A[i] = a[i]; n     for (int i = len; i < n; i++) A[i] = 0; n     for (int i = 0; i < c.len; i++) B[i] = c.a[i]; n     for (int i = c.len; i < n; i++) B[i] = 0; n     NTT(A, n, 1); n     NTT(B, n, 1); n     for (int i = 0; i < n; i++) A[i] = (long long)A[i] * B[i] % 998244353; n     NTT(A, n, -1); n     for (int i = 0; i < c.len; i++) c.a[i] = A[i]; n     c.rev(); n     rev(); n     b.rev(); n     for (int i = 0; i < c.len; i++) A[i] = c.a[i]; n     for (int i = c.len; i < n; i++) A[i] = 0; n     for (int i = 0; i < b.len; i++) B[i] = b.a[i]; n     for (int i = b.len; i < n; i++) B[i] = 0; n     NTT(A, n, 1); n     NTT(B, n, 1); n     for (int i = 0; i < n; i++) A[i] = (long long)A[i] * B[i] % 998244353; n     NTT(A, n, -1); n     c.len = b.len; n     c.resize(c.len); n     for (int i = 0; i < c.len; i++) n       c.a[i] = (a[i] - A[i] + 998244353) % 998244353; n     return c; n   } n } a, b; n void get_rot(const poly &a, poly &b, int len) { n   if (len == 1) { n     b.a.push_back(1); n     b.len = 1; n     return; n   } n   get_rot(a, b, len >> 1); n   poly c; n   c.clear(); n   b.get_inv(c, len); n   b = b + (c * a); n   b = b * ((998244353 + 1) / 2); n   b.get_mod(len); n } n void get_exp(const poly &a, poly &b, int len) { n   if (len == 1) { n     b.a.push_back(1); n     b.len = 1; n     return; n   } n   get_exp(a, b, len >> 1); n   b = b * ((a - b.get_ln(len)) + 1); n   b.get_mod(len); n } n int main() { n   scanf( %d%d , &n, &m); n   a.resize(m + 1); n   a.a[0] = 1; n   for (int i = 1, x; i <= n; i++) { n     scanf( %d , &x); n     if (x <= m) a.a[x] = 998244353 - 4; n   } n   int len = 1; n   while (len <= m) len <<= 1; n   get_rot(a, b, len); n   b.a[0]++; n   a.clear(); n   b.get_inv(a, len); n   for (int i = 1; i <= m; i++) printf( %d n , (a.a[i] << 1) % 998244353); n } n


#include <bits/stdc++.h> n int main(int argc, char *argv[]) { n   int i, j; n   unsigned long long n, result, a[10]; n   a[0] = 0; n   a[1] = 9; n   for (i = 2; i <= 9; i++) a[i] = a[i - 1] * 10 + 9; n   scanf( %llu , &n); n   result = 0; n   i = 9; n   ; n   while (n < a[i]) i--; n   result = result + (n - a[i]) * (i + 1); n   for (j = 1; j <= i; j++) result = result + (a[j] - a[j - 1]) * j; n   printf( %llu , result); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream f( date.in ); n queue<long long> q; n long long n, k, fr[1000001]; n long long GCD(long long x, long long y) { n   long long r; n   do { n     r = x % y; n     x = y; n     y = r; n   } while (y != 0); n   return x; n } n int main() { n   long long ans; n   cin >> n >> k; n   ans = k; n   for (int i = 1; i <= n; i++) { n     long long x; n     cin >> x; n     ans = GCD(x, ans); n   } n   cout << k / ans <<   n ; n   for (int i = 0; i < k / ans; i++) cout << i * ans <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[1000000], k, cnt, ans; n int main() { n   cin >> n; n   a[0] = 1; n   a[1] = 1; n   a[2] = 0; n   for (int i = 1; i < n; i++) { n     if (a[i] == 0) { n       for (int j = i * i; j <= n; j += i) { n         a[j] = 1; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     cnt = 0; n     for (int j = i; j > 0; j--) { n       if (i % j == 0) { n         k = i / j; n       } else { n         continue; n       } n       if (a[k] == 0) { n         cnt++; n       } n     } n     if (cnt == 2) { n       ans++; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string p; n   getline(cin, p); n   bool f = 0; n   for (int i = 0; i < p.size(); i++) { n     if (p[i] >=  a  && p[i] <=  z ) { n       if (p[i] ==  a  || p[i] ==  i  || p[i] ==  u  || p[i] ==  e  || n           p[i] ==  o  || p[i] ==  y ) n         f = 1; n       else n         f = 0; n     } n     if (p[i] >=  A  && p[i] <=  Z ) { n       if (p[i] ==  A  || p[i] ==  I  || p[i] ==  U  || p[i] ==  E  || n           p[i] ==  O  || p[i] ==  Y ) n         f = 1; n       else n         f = 0; n     } n   } n   if (f) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long summ(long long n) { return (n * (n + 1)) / 2; } n long long sear(long long n, long long k) { n   if (n == 1 && k == 1) return 0; n   long long lo = 0, hi = n, mid; n   long long sum, eaten; n   while (lo <= hi) { n     mid = lo + (hi - lo) / 2; n     sum = summ(n - mid); n     if (mid + k == sum) n       return mid; n     else if (mid + k > sum) n       hi = mid - 1; n     else n       lo = mid + 1; n   } n   return mid; n } n int main() { n   long long n, k; n   cin >> n >> k; n   if (n == 1 && k == 1) { n     cout << 0 << endl; n     return 0; n   } n   long long ans = sear(n, k); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long query(long long t, long long i, long long j, long long k) { n   cout << t <<     << i <<     << j <<     << k <<     <<   n ; n   cout.flush(); n   long long res; n   cin >> res; n   return res; n } n void solve() { n   long long n; n   cin >> n; n   long long t1 = 1; n   long long oo = 5e18; n   vector<pair<long long, long long>> area(n + 1, {-oo, -1}); n   for (long long i = 1; i <= n; ++i) area[i].second = i; n   long long t2 = 2; n   for (long long i = 3; i <= n; ++i) { n     long long q2 = query(2, t1, t2, i); n     t2 = (q2 > 0 ? t2 : i); n   } n   long long mid = 3, max_s = 0; n   for (long long i = 2; i <= n; ++i) { n     if (i == t2) continue; n     long long q1 = query(1, t1, t2, i); n     area[i].first = q1; n     if (q1 > max_s) { n       max_s = q1; n       mid = i; n     } n   } n   area[mid].first = 0; n   for (long long i = 2; i <= n; ++i) { n     if (i == t2 || i == mid) continue; n     long long q2 = query(2, t1, mid, i); n     if (q2 > 0) area[i].first = oo - area[i].first; n     if (q2 < 0) area[i].first = -oo + area[i].first; n   } n   sort(area.begin() + 1, area.end()); n   cout <<  0  ; n   for (long long i = 1; i <= n; ++i) n     cout << area[i].second << (i == n ?   n  :    ); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, centru; n int l[10]; n int r[10]; n int vars(int i, int tip) { n   if (!tip) { n     if (l[i] <= centru && centru <= r[i]) n       return centru - l[i]; n     else if (r[i] < centru) n       return r[i] - l[i] + 1; n     return 0; n   } else if (tip == 1) n     return ((bool)(l[i] <= centru && centru <= r[i])); n   else { n     if (l[i] <= centru && centru <= r[i]) n       return r[i] - centru; n     else if (centru < l[i]) n       return r[i] - l[i] + 1; n     return 0; n   } n } n int tip[10]; n int _s[3]; n double sum; n void backtr(int poz) { n   if (poz == (n + 1)) { n     if (!_s[1]) return; n     if (_s[2] >= 2) return; n     if (_s[2] == 0) { n       if (_s[1] == 1) return; n     } n     double prod = 1; n     for (int i = 1; i <= n; i++) prod *= vars(i, tip[i]); n     sum += centru * prod; n     return; n   } n   for (int i = 0; i < 3; i++) { n     _s[i]++; n     tip[poz] = i; n     backtr(poz + 1); n     _s[i]--; n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> l[i] >> r[i]; n   for (int i = 1; i <= 10000; i++) { n     centru = i; n     backtr(1); n   } n   for (int i = 1; i <= n; i++) { n     sum /= (r[i] - l[i] + 1); n   } n   cout << fixed << setprecision(12) << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T abs(T &a) { n   return a > 0 ? a : -a; n } n template <class T> n inline T min(T &a, T &b) { n   return a < b ? a : b; n } n template <class T> n inline T max(T &a, T &b) { n   return a > b ? a : b; n } n inline void read(int &x) { n   char ch; n   while ((ch = getchar()) && !(ch >=  0  && ch <=  9 )) n     ; n   x = ch -  0 ; n   while ((ch = getchar()) && (ch >=  0  && ch <=  9 )) x = x * 10 + ch -  0 ; n } n const int N = 2000002; n int n, m, w[N], ans[N], dy[N], T = 1, t[N << 2]; n void add(int x, int c) { n   for (t[x += T] += c, x >>= 1; x; x >>= 1) t[x] = t[x << 1] + t[(x << 1) + 1]; n } n int find(int k, int l, int r) { n   int x = 1; n   while (l < r) { n     int mid = l + r >> 1; n     if (t[x << 1] >= k) n       x = x << 1, r = mid; n     else n       k -= t[x << 1], x = x << 1 | 1, l = mid + 1; n   } n   return l; n } n int main() { n   read(n); n   read(m); n   int Len = n + m, gs = 0; n   while (T < Len) T <<= 1, gs++; n   T--; n   for (int i = m + 1; i <= n + m; i++) w[i] = i - m, add(i, 1); n   int x, y; n   for (int i = m; i >= 1; i--) { n     read(x); n     read(y); n     int p = find(y, 1, T + 1); n     w[i] = w[p]; n     add(i, 1); n     add(p, -1); n     if (ans[w[i]] && ans[w[i]] != x) { n       puts( -1 ); n       return 0; n     } n     ans[w[i]] = x; n     if (dy[x] && dy[x] != w[i]) { n       puts( -1 ); n       return 0; n     } n     dy[x] = w[i]; n   } n   int j = 1; n   for (int i = 1; i <= n; i++) { n     if (ans[i]) n       printf( %d  , ans[i]); n     else { n       for (; dy[j]; j++) n         ; n       printf( %d  , j++); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200005]; n map<long long, int> mp; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     long long n; n     scanf( %lld , &n); n     long long sum = 0; n     mp.clear(); n     for (int i = 1; i <= n; i++) { n       scanf( %lld , &a[i]); n       sum += a[i]; n     } n     long long res = 0; n     for (int i = 1; i <= n; i++) { n       res += mp[2 * sum - n * a[i]]; n       mp[n * a[i]]++; n     } n     printf( %lld n , res); n   } n } n


#include <bits/stdc++.h> n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma ) n #pragma GCC optimize( fast-math ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( Ofast ) n using namespace std; n const long long mod = 1e9 + 7, mod2 = 998244353; n const long double eps = 1e-6; n const long long inf = 1e18; n const int base = 1e9; n const long double PI = 3.1415926; n void deb(long double first){}; n int n, a[100 * 1000]; n long long k; n unsigned int bitcount(unsigned long long val) { n   return __builtin_popcount(val) + __builtin_popcount(val >> 32); n } n void local() { freopen( test.in ,  r , stdin); } n void remote() {} n void read() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n } n long long cnt(long long bound, vector<int> &v) { n   long long res = 0; n   for (int i = 0; i < n; i++) { n     int l = 0, r = a[i] + 1; n     while (r - l > 1) { n       int m = (r + l) / 2; n       if (a[i] - 3 * 1ll * m * (m - 1) - 1 >= bound) n         l = m; n       else n         r = m; n     } n     v[i] = l; n     res += l; n   } n   return res; n } n int main() { n   remote(); n   read(); n   vector<int> v(n); n   long long l = -4e18, r = 4e18; n   while (l < r) { n     long long m = l + (r - l) / 2; n     long long val = cnt(m, v); n     if (val > k) { n       l = m + 1; n     } else n       r = m; n   } n   long long val = cnt(l, v); n   vector<int> res = v; n   long long val2 = cnt(l - 1, v); n   for (int i = 0; i < n; i++) n     if (v[i] == res[i] + 1 && val < k) res[i]++, val++; n   for (int i = 0; i < n; i++) cout << res[i] <<    ; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int MAX = 200005; n int cnt[MAX], pre[MAX], suf[MAX]; n int bpow(int a, int b) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = 1LL * ans * a % MOD; n     b >>= 1; n     a = 1LL * a * a % MOD; n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int val; n     cin >> val; n     cnt[val]++; n   } n   pre[0] = 1; n   for (int i = 1; i < MAX; i++) n     pre[i] = 1LL * pre[i - 1] * (cnt[i - 1] + 1) % (MOD - 1); n   suf[MAX - 1] = 1; n   for (int i = MAX - 2; i >= 0; i--) n     suf[i] = 1LL * suf[i + 1] * (cnt[i] + 1) % (MOD - 1); n   int ans = 1; n   for (int i = 0; i < MAX; i++) n     for (int j = 1; j <= cnt[i]; j++) n       ans = 1LL * ans * n             bpow(bpow(i, j), 1LL * pre[i] * suf[i + 1] % (MOD - 1)) % MOD; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[610000], i, j, k, l, n, m, p[610000], t, last, o, r, mid; n char c[610000]; n bool check(int mid) { n   int tmp = 1e9, res = 0; n   p[0] = mid; n   m = last; n   for (i = 1; i <= n; ++i) { n     p[i] = p[i - 1] + a[i]; n     if (p[i] == 0 && p[i - 1] == -1) m = max(m, i); n   } n   if (m == 0) return 1; n   for (i = 1; i <= m; ++i) { n     if (p[i - 1] == 0 && p[i] == -1) { n       o = i; n       tmp = min(tmp, res + (m - i) * 2); n     } n     if (p[i - 1] == -1 && p[i] == 0) { n       if (i == m) tmp = min(tmp, res + m - o); n       res += (i - o) * 2; n     } n     res++; n   } n   tmp = min(tmp, res - 1); n   return tmp + 1 <= t; n } n int main() { n   scanf( %d%d%s , &n, &t, c + 1); n   for (i = 1; i <= n; ++i) a[i] = c[i] ==  H  ? -1 : c[i] ==  S  ? 1 : 0; n   for (i = 1; i <= n; ++i) { n     if (a[i] == -1) r++, last = i; n     if (a[i] == 1) l--; n   } n   l += r; n   if (l < 0) l = 0; n   if (last > t) { n     printf( -1 n ); n     exit(0); n   } n   while (l <= r) { n     mid = (l + r) / 2; n     if (check(mid)) n       r = mid - 1; n     else n       l = mid + 1; n   } n   printf( %d n , r + 1); n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200010]; n long long l[200010]; n long long r[200010]; n int main() { n   ios_base::sync_with_stdio(0); n   long long n, h; n   cin >> n >> h; n   vector<long long> rast2(n + 1, 0); n   for (int i = 1; i <= n; i++) { n     cin >> l[i] >> r[i]; n     rast2[i] = r[i] - l[i]; n   } n   for (int i = 1; i <= n; i++) { n     rast2[i] += rast2[i - 1]; n   } n   vector<long long> rast(n + 1, 0); n   for (int i = 1; i < n; i++) { n     rast[i] = l[i + 1] - r[i]; n   } n   rast[n] = 2e9; n   for (int i = 1; i <= n; i++) { n     rast[i] += rast[i - 1]; n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     long long r = n         lower_bound(rast.begin(), rast.end(), h + rast[i - 1]) - (rast.begin()); n     if (r <= n) ans = max(ans, (rast2[r] - rast2[i - 1]) + h); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n set<pair<int, int> > s; n vector<int> od; n int p[512]; n vector<int> v[512]; n inline void dfs(int b, int pr = -1) { n   od.push_back(b); n   p[b] = pr; n   auto it = s.lower_bound(make_pair(b, -1)); n   while (it != s.end() && (*it).first == b) { n     if (it->second == pr) { n       it = next(it); n       continue; n     } n     dfs(it->second, b); n     v[b].push_back(it->second); n     v[it->second].push_back(b); n     it = next(it); n   } n } n bool us[512]; n void init() { n   for (int i = 0; i <= n; i++) { n     v[i].clear(); n     us[i] = false; n   } n } n int sz[512]; n inline pair<int, int> cent(int b, int ALL, int pr) { n   sz[b] = 1; n   pair<int, int> ret = make_pair(INT_MAX, -1); n   int mx = -1; n   for (int go : v[b]) { n     if (us[go]) continue; n     if (go == pr) continue; n     ret = min(ret, cent(go, ALL, b)); n     sz[b] += sz[go]; n     mx = max(mx, sz[go]); n   } n   mx = max(mx, ALL - sz[b]); n   ret = min(ret, make_pair(mx, b)); n   return ret; n } n inline void er(int a, int b) { n   s.erase(make_pair(a, b)); n   s.erase(make_pair(b, a)); n } n inline void ins(int a, int b) { n   s.insert(make_pair(a, b)); n   s.insert(make_pair(b, a)); n } n bool ok(vector<int> &vv, int num, int root, int root2) { n   cout << 1 << endl; n   cout << root << endl; n   cout << num + 1 << endl; n   for (int j = 0; j <= num; j++) { n     if (j) printf(   ); n     printf( %d , vv[j]); n   } n   puts(  ); n   cout << root2 << endl; n   fflush(stdout); n   int way; n   scanf( %d , &way); n   if (way == num + 1) { n     return true; n   } n   return false; n } n inline void df(int b, int add) { n   cent(b, 0, -1); n   b = cent(b, sz[b], -1).second; n   vector<int> z; n   for (int go : v[b]) { n     z.push_back(go); n   } n   us[b] = true; n   int mint = 0; n   int maxt = z.size(); n   if (z.size() && ok(z, 0, add, b) == false) { n     maxt = mint; n   } n   while (mint + 1 < maxt) { n     int mid = (mint + maxt) / 2; n     if (ok(z, mid, add, b)) { n       mint = mid; n     } else { n       maxt = mid; n     } n   } n   if (maxt == z.size()) { n     ins(b, add); n     return; n   } n   if (us[z[maxt]] == false) { n     df(z[maxt], add); n     return; n   } n   er(z[maxt], b); n   ins(z[maxt], add); n   ins(add, b); n } n int zz[512]; n vector<int> o; n bool cmp(int a, int b) { return zz[a] > zz[b]; } n int main() { n   cin >> n; n   zz[1] = n; n   for (int i = 2; i <= n; i++) { n     cout << 1 << endl; n     cout << 1 << endl; n     cout << n - 1 << endl; n     for (int j = 2; j <= n; j++) { n       if (j > 1) printf(   ); n       printf( %d , j); n     } n     puts(  ); n     printf( %d n , i); n     fflush(stdout); n     int a; n     scanf( %d , &a); n     zz[i] = a; n   } n   for (int i = 2; i <= n; i++) o.push_back(i); n   sort(o.begin(), o.end(), cmp); n   for (int i : o) { n     od.clear(); n     init(); n     dfs(1); n     reverse(od.begin(), od.end()); n     df(1, i); n   } n   puts( ANSWER ); n   for (auto it : s) { n     if (it.first > it.second) continue; n     printf( %d %d n , it.first, it.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n map<string, string> m1; n int main() { n   cin >> N >> M; n   string s1; n   string s2; n   for (int i = 1; i <= N; i++) { n     cin >> s1; n     cin >> s2; n     m1[s2] = s1; n   } n   for (int i = 1; i <= M; i++) { n     cin >> s1; n     cin >> s2; n     s2.erase(s2.begin() + s2.size() - 1); n     cout << s1 <<    ; n     cout << s2 <<  ; #  << m1[s2] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[110]; n int main() { n   int n, cnt; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> p[i]; n   string s; n   getline(cin, s); n   for (int i = 0; i < n; i++) { n     cnt = 0; n     getline(cin, s); n     for (int j = 0; j < s.size(); j++) n       if (s[j] ==  a  || s[j] ==  e  || s[j] ==  i  || s[j] ==  o  || n           s[j] ==  u  || s[j] ==  y ) n         cnt++; n     if (cnt != p[i]) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename S> n ostream &operator<<(ostream &os, const pair<T, S> &v) { n   os <<  ( ; n   os << v.first <<  ,  << v.second <<  ) ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  [ ; n   long long sz = v.size(); n   for (long long i = 0; i < sz; ++i) { n     os << v[i]; n     if (i != sz - 1) os <<  , ; n   } n   os <<  ] n ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &v) { n   T last = *v.rbegin(); n   os <<  [ ; n   for (auto it : v) { n     os << it; n     if (it != last) os <<  , ; n   } n   os <<  ] n ; n   return os; n } n template <typename T, typename S> n ostream &operator<<(ostream &os, const map<T, S> &v) { n   for (auto it : v) { n     os << it.first <<   :   << it.second <<   n ; n   } n   return os; n } n long long power(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b % 2) { n       res = (res * a) % 1000000007; n     } n     b /= 2; n     a = (a * a) % 1000000007; n   } n   return res; n } n template <typename Arg1> n void __f(const char *name, Arg1 &&arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char *names, Arg1 &&arg1, Args &&...args) { n   const char *comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, T; n   cin >> n >> T; n   vector<pair<long long, long long> > arr; n   for (__typeof(1) i = 1; i <= n; i++) { n     long long t; n     cin >> t; n     long long from = t - i; n     long long to = T - i; n     if (to > from && to > 0) { n       arr.push_back({from, 1}); n       arr.push_back({to, -1}); n     } n   } n   sort((arr).begin(), (arr).end()); n   long long curr = 0, ans = 0; n   for (auto it : arr) { n     curr += it.second; n     ans = max(ans, curr); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int x = 0; n     long long int n, m; n     cin >> n >> m; n     for (long long int i = 0; i < n; i++) { n       long long int a, b, c, d; n       cin >> a >> b >> c >> d; n       if (b == c && m % 2 != 1 && x != 1) { n         cout <<  Yes  << endl; n         x = 1; n       } n     } n     if (x == 0) cout <<  No  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200020; n long long int n; n int main() { n   cin >> n; n   for (long long int i = 1; i <= n - 1; i++) { n     for (long long int j = 1; j <= n - 1; j++) { n       if (i == j) n         cout <<  0  ; n       else n         cout << 1 + (i + j - 2) % (n - 1) <<    ; n     } n     cout << (2 * i - 2) % (n - 1) + 1 << endl; n   } n   for (long long int i = 1; i <= n - 1; i++) { n     cout << (2 * i - 2) % (n - 1) + 1 <<    ; n   } n   cout <<  0  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[1001][1001], row[1001], col[1001]; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   for (int r = 1; r <= n; ++r) row[r] = r; n   for (int c = 1; c <= m; ++c) col[c] = c; n   for (int r = 1; r <= n; ++r) n     for (int c = 1; c <= m; ++c) scanf( %d , &p[r][c]); n   while (k--) { n     char s[2]; n     int x, y; n     scanf( %s%d%d , s, &x, &y); n     switch (s[0]) { n       case  r : n         swap(row[x], row[y]); n         break; n       case  c : n         swap(col[x], col[y]); n         break; n       case  g : n         printf( %d n , p[row[x]][col[y]]); n         break; n       default: n         break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n struct P { n   int x, y; n   bool operator<(const P &a) const { return x > a.x; } n } a[N]; n int main() { n   static int n, b[N * 2]; n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d , (int *)(a + i)), a[i].y = i * 2 - 1; n   sort(a + 1, a + 1 + n); n   for (int i = 1; i < n; i++) printf( %d %d n , a[i].y, a[i + 1].y); n   for (int i = 1; i <= n; i++) b[i] = a[i].y; n   for (int i = 1, aid, *bid; i <= n; i++) { n     aid = a[i].y + 1, bid = b + i + a[i].x; n     if (!*bid) n       printf( %d %d n , aid, *(bid - 1)), *bid = aid; n     else n       printf( %d %d n , aid, *--bid); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> graph[100005]; n int a[100005], b[100005]; n vector<int> ans; n void dfs(int source, int parent, int oddlevel, int evenlevel, int depth) { n   if (depth % 2 == 1) n     a[source] ^= oddlevel; n   else n     a[source] ^= evenlevel; n   if (a[source] != b[source]) { n     a[source] ^= 1; n     if (depth % 2 == 1) n       oddlevel++; n     else n       evenlevel++; n     oddlevel %= 2, evenlevel %= 2; n     ans.push_back(source); n   } n   for (int i = 0; i < graph[source].size(); i++) { n     int child = graph[source][i]; n     if (child == parent) continue; n     dfs(child, source, oddlevel, evenlevel, depth + 1); n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int x, y; n     cin >> x >> y; n     graph[x].push_back(y); n     graph[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 1; i <= n; i++) cin >> b[i]; n   dfs(1, 0, 0, 0, 0); n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (cin >> n) { n     string s; n     cin >> s; n     int l[3005], r[3005]; n     memset(l, -1, sizeof(l)); n     memset(r, -1, sizeof(r)); n     int cnt = 0, t1 = 0, t2 = 0; n     for (int i = 0; i < n; ++i) { n       if (s[i] ==  L ) { n         l[t1++] = i; n         continue; n       } n       if (s[i] ==  R ) { n         r[t2++] = i; n         continue; n       } n     } n     if (l[0] == r[0]) { n       cout << n << endl; n       continue; n     } n     if (l[0] == -1) { n       cout << r[0] << endl; n       continue; n     } n     if (r[0] == -1) { n       cout << n - l[0] - 1 << endl; n       continue; n     } n     if (l[0] < r[0]) { n       cnt += l[0] + 1; n       for (int i = 1; i < t1; ++i) { n         int t = l[i] - r[i - 1]; n         cnt += t + 1; n         if (t % 2 == 0) cnt--; n       } n       if (t1 == t2) cnt += n - r[t2 - 1]; n     } else { n       for (int i = 0; i < t1; ++i) { n         int t = l[i] - r[i]; n         cnt += t + 1; n         if (t % 2 == 0) cnt--; n       } n       if (t2 > t1) cnt += n - r[t2 - 1]; n     } n     cout << n - cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 100100; n const long double INF = 1e100; n const long double eps = 1e-6; n const long double PI = 3.14159265358979323846264338328; n long long x[maxN], y[maxN]; n long double Dis(long long a, long long b, long long p, long long q) { n   long double aa = 1.0 * a, bb = 1.0 * b, pp = 1.0 * p, qq = 1.0 * q; n   return (aa - pp) * (aa - pp) + (bb - qq) * (bb - qq); n } n long double DfromL(long long X1, long long Y1, long long aa, long long bb, n                    long long pp, long long qq) { n   long double X = 1.0 * X1, Y = 1.0 * Y1, a = 1.0 * aa, b = 1.0 * bb, n               p = 1.0 * pp, q = 1.0 * qq; n   bool Inf = (a == p); n   long double m = (Inf) ? INF : ((b - q) / (a - p)); n   long double c = (Inf) ? INF : ((b - m * a)); n   bool zero = (!Inf && m == 0.0); n   long double m1 = (Inf) ? (0) : (zero) ? INF : (-1.0 / m); n   long double c1 = (Inf) ? (Y) : (zero) ? INF : (Y - m1 * X); n   long double XX = (Inf) ? (a) : (zero) ? (X) : ((c1 - c) / (m - m1)); n   long double YY = (Inf) ? (Y) : (zero) ? (b) : ((m * c1 - m1 * c) / (m - m1)); n   if (XX >= min(a, p) && XX <= max(a, p) && YY >= min(b, q) && n       YY <= max(b, q)) { n     if (Inf) return (X - XX) * (X - XX); n     if (zero) return (Y - YY) * (Y - YY); n     return ((m * X - Y + c) * (m * X - Y + c)) / (1.0 + m * m); n   } else n     return -1.0; n } n int main() { n   ios::sync_with_stdio(false); n   long long n, X, Y; n   cin >> n >> X >> Y; n   for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; n   long double maxR = -1.0, minR = INF; n   for (int i = 0; i < n; i++) { n     long double dis = Dis(X, Y, x[i], y[i]); n     maxR = max(maxR, dis); n     minR = min(minR, dis); n     long double diS = DfromL(X, Y, x[i], y[i], x[(i + 1) % n], y[(i + 1) % n]); n     if (diS != -1.0) { n       maxR = max(maxR, diS); n       minR = min(minR, diS); n     } n   } n   long double ans = PI * (maxR - minR); n   cout << setprecision(20) << ans << endl; n   return 0; n } n


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


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n + 1); n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n   } n   sort(a.begin(), a.end()); n   vector<vector<vector<int>>> dp( n       2, vector<vector<int>>(k + 1, vector<int>(k + 1))); n   dp[0][0][0] = 1; n   int ans = 0; n   set<int> sad; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= k; ++j) { n       for (int l = 0; l <= j; ++l) { n         int i2 = i % 2; n         dp[i2][j][l] = dp[abs(i2 - 1)][j][l]; n         if (a[i] <= j) { n           dp[i2][j][l] = n               max(dp[abs(i2 - 1)][j][l], dp[abs(i2 - 1)][j - a[i]][l]); n           if (a[i] <= l) { n             dp[i2][j][l] = n                 max(dp[i2][j][l], dp[abs(i2 - 1)][j - a[i]][l - a[i]]); n           } n         } n         if (i == n && j == k && dp[i2][j][l] != 0) { n           ++ans; n           sad.insert(l); n         } n       } n     } n   } n   cout << ans << endl; n   for (auto i : sad) { n     cout << i <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int m, long long int n) { n   if (n == 0) return m; n   return gcd(n, m % n); n } n int MOD = 1000000000; n long long int powmod(long long int a, long long int b) { n   if (b == 0) return 1; n   long long int x = powmod(a, b / 2); n   long long int y = (x * x) % MOD; n   if (b % 2) return (a * y) % MOD; n   return y % MOD; n } n int main() { n   std::ios::sync_with_stdio(false); n   int n, k; n   cin >> n >> k; n   int z; n   int a[10000]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int ans = 0; n   for (int i = 0; i < n - 1; i++) { n     if (a[i] > 8) { n       a[i + 1] = a[i + 1] + a[i] - 8; n       k = k - 8; n     } else n       k = k - a[i]; n     if (k <= 0) { n       cout << i + 1 << endl; n       return 0; n     } n   } n   if (k - min(a[n - 1], 8) > 0) n     cout <<  -1  << endl; n   else n     cout << n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool pid_comp_second(pair<int, double> a, pair<int, double> b) { n   if (a.second == b.second) return a.first < b.first; n   return a.second > b.second; n } n int main() { n   double x, y, z; n   cin >> x >> y >> z; n   map<int, string> expr; n   expr[1] =  x^y^z ; n   expr[2] =  x^z^y ; n   expr[3] =  (x^y)^z ; n   expr[5] =  y^x^z ; n   expr[6] =  y^z^x ; n   expr[7] =  (y^x)^z ; n   expr[9] =  z^x^y ; n   expr[10] =  z^y^x ; n   expr[11] =  (z^x)^y ; n   vector<pair<int, double> > nums; n   if (x < 1 || x < 1 || x < 1) { n     nums.push_back(make_pair(1, pow(y, z) * log(x))); n     nums.push_back(make_pair(2, pow(z, y) * log(x))); n     nums.push_back(make_pair(3, y * z * log(x))); n     nums.push_back(make_pair(5, pow(x, z) * log(y))); n     nums.push_back(make_pair(6, pow(z, x) * log(y))); n     nums.push_back(make_pair(7, x * z * log(y))); n     nums.push_back(make_pair(9, pow(x, y) * log(z))); n     nums.push_back(make_pair(10, pow(y, x) * log(z))); n     nums.push_back(make_pair(11, x * y * log(z))); n   } else { n     nums.push_back(make_pair(1, z * log(y) + log(log(x)))); n     nums.push_back(make_pair(2, y * log(z) + log(log(x)))); n     nums.push_back(make_pair(3, log(y) + log(z) + log(log(x)))); n     nums.push_back(make_pair(5, z * log(x) + log(log(y)))); n     nums.push_back(make_pair(6, x * log(z) + log(log(y)))); n     nums.push_back(make_pair(7, log(x) + log(z) + log(log(y)))); n     nums.push_back(make_pair(9, y * log(x) + log(log(z)))); n     nums.push_back(make_pair(10, x * log(y) + log(log(z)))); n     nums.push_back(make_pair(11, log(x) + log(y) + log(log(z)))); n   } n   sort(nums.begin(), nums.end(), pid_comp_second); n   cout << expr[nums[0].first] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ofstream fo( test.out ); n ifstream fi( test.inp ); n const long long MOD = 1e9 + 7; n const long long base = 269; n const int N = 1e5 + 5; n long long n, m, q, K, pos, t, rs, r; n long long cnt10, cnt11; n string s, a, b; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n; n   cin >> a >> b; n   for (long long(i) = 0; (i) < (n); (i)++) { n     if (a[i] ==  1  && b[i] ==  0 ) cnt10++; n     if (a[i] ==  1  && b[i] ==  1 ) cnt11++; n   } n   for (long long(i) = 0; (i) < (n); (i)++) { n     if (a[i] ==  0  && b[i] ==  0 ) { n       rs += cnt11; n       rs += cnt10; n     } n     if (a[i] ==  0  && b[i] ==  1 ) rs += cnt10; n   } n   cout << rs; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n, ind; n   cin >> t; n   while (t--) { n     cin >> n; n     ind = -1; n     int a[n]; n     for (int i = 0; i < n; ++i) { n       cin >> a[i]; n       if (a[i] % 2 == 0) ind = i; n     } n     if (ind != -1) n       cout <<  1 n  << ind + 1 <<   n ; n     else if (n > 1) n       cout <<  2 n1 2 n ; n     else n       cout <<  -1 n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n struct my { n   int a; n   double b; n }; n bool Cmp(my a, my b) { return a.b <= b.b; } n int main() { n   int n, m; n   cin >> n >> m; n   my mine[n]; n   for (int i = 0; i < n; ++i) { n     int a; n     cin >> a; n     double b; n     cin >> b; n     mine[i].a = a; n     mine[i].b = b; n   } n   sort(mine, mine + n, Cmp); n   int ord[n]; n   for (int i = 0; i < n; ++i) { n     ord[i] = mine[i].a; n   } n   int dp[n]; n   for (int i = 0; i < n; ++i) { n     dp[i] = 1; n   } n   for (int i = 0; i < n; i++) { n     for (int j = i - 1; j >= 0; j--) { n       if (ord[j] <= ord[i]) { n         dp[i] = max(dp[j] + 1, dp[i]); n       } n     } n   } n   cout << n - *max_element(dp, dp + n) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 1e7 + 10, M = 998244353; n int n, m, k, inv[Maxn], s[Maxn], idk[Maxn]; n int mo2(int x) { return (x < 0) ? x + M : x; } n int fpow(int a, int p = M - 2) { n   int ret = 1; n   for (; p; p >>= 1, a = 1ll * a * a % M) n     if (p & 1) ret = 1ll * ret * a % M; n   return ret; n } n void init(int n) { n   inv[1] = 1; n   for (int i = 2; i <= n; i++) inv[i] = M - 1ll * inv[M % i] * (M / i) % M; n } n void get_idk(int k) { n   for (int i = 0; i <= k; i++) idk[i] = fpow(i, k); n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   int p = fpow(m); n   init(k); n   s[k] = 1; n   int pw = 1, C = 1; n   for (int i = k - 1; i >= 0; i--) { n     pw = 1ll * pw * (M - p) % M; n     C = 1ll * C * (n - i - 1 + M) % M * inv[k - i] % M; n     s[i] = (1ll * (1 - p + M) * s[i + 1] + 1ll * C * pw) % M; n   } n   int E = 0; n   pw = C = 1; n   get_idk(k); n   for (int i = 1; i <= k; i++) { n     pw = 1ll * pw * p % M; n     C = 1ll * C * (n - i + 1 + M) % M * inv[i] % M; n     E = (E + 1ll * idk[i] * C % M * pw % M * s[i]) % M; n   } n   printf( %d n , E); n   return 0; n } n