#include <bits/stdc++.h> n using namespace std; n const int mxn = 1e5 + 10; n int n, m; n bool jest[410][410]; n bool vis_sam[mxn], vis_poc[mxn]; n int sam[mxn], poc[mxn]; n void wczytaj() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     jest[a][b] = true; n     jest[b][a] = true; n   } n } n void bfs_sam() { n   queue<int> q; n   q.push(1); n   vis_sam[1] = true; n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     for (int i = 1; i <= n; i++) { n       if (i == v) continue; n       if (vis_sam[i]) continue; n       if (!jest[i][v]) continue; n       sam[i] = sam[v] + 1; n       q.push(i); n       vis_sam[i] = true; n     } n   } n } n void bfs_poc() { n   queue<int> q; n   q.push(1); n   vis_poc[1] = true; n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     for (int i = 1; i <= n; i++) { n       if (i == v) continue; n       if (vis_poc[i]) continue; n       if (jest[i][v]) continue; n       poc[i] = poc[v] + 1; n       q.push(i); n       vis_poc[i] = true; n     } n   } n } n int main() { n   wczytaj(); n   bfs_poc(); n   bfs_sam(); n   if (vis_poc[n] == false || vis_sam[n] == false) { n     printf( -1 n ); n     return 0; n   } n   printf( %d n , max(poc[n], sam[n])); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5050, b = 53, mod = 1073676287; n int n, q, pre[N], suf[N], ans[N], binv[N], dp[N][N]; n int mul(int x, int y) { return (x * 1ll * y) % mod; } n int add(int x, int y) { return ((x + y) % mod + mod) % mod; } n int pw(int b, int p) { n   if (!p) return 1; n   int ret = pw(b, p / 2); n   ret = mul(ret, ret); n   if (p % 2) ret = mul(ret, b); n   return ret; n } n int getl(int l, int r) { n   int f = add(pre[r], -pre[l - 1]); n   return mul(f, binv[l]); n } n int getr(int l, int r) { n   int f = add(suf[l], -suf[r + 1]); n   return mul(f, binv[n - r + 1]); n } n int check(int l, int r) { return getl(l, r) == getr(l, r); } n int solve(int i, int j) { n   if (i > n || j <= 0 || j < i) return 0; n   int &x = dp[i][j]; n   if (x != -1) return x; n   return x = check(i, j) + solve(i, j - 1) + solve(i + 1, j) - n              solve(i + 1, j - 1); n } n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> s; n   memset(dp, -1, sizeof dp); n   n = s.size(); n   s =  @  + s; n   int bb = 1; n   for (int i = 1; i <= n; i++) { n     binv[i] = pw(bb, mod - 2); n     pre[i] = add(pre[i - 1], mul((s[i] -  a ), bb)); n     bb = mul(bb, b); n   } n   bb = 1; n   for (int i = n; i >= 1; i--) { n     suf[i] = add(suf[i + 1], mul((s[i] -  a ), bb)); n     bb = mul(bb, b); n   } n   cin >> q; n   while (q--) { n     int l, r; n     cin >> l >> r; n     cout << solve(l, r) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[20]; n int main() { n   cin >> n >> m; n   for (int t, i = 1; i <= n; i++) { n     cin >> t; n     a[t]++; n   } n   int ans = 0; n   for (int i = 1; i <= m; i++) n     for (int j = i + 1; j <= m; j++) ans += a[i] * a[j]; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > ke[105]; n int d[105], x[105], y[105], a[105]; n int n, m, s, t, module; n void dijkstra() { n   set<pair<int, int> > q; n   for (int u = 1; u <= n; ++u) d[u] = 1000000007; n   d[1] = 0; n   q.insert(make_pair(d[1], 1)); n   while (!q.empty()) { n     pair<int, int> top = *(q.begin()); n     q.erase(top); n     int u = top.second; n     if (u == n) return; n     for (int i = 0; i < ke[u].size(); ++i) { n       int v = ke[u][i].first; n       int w = ke[u][i].second; n       if (d[v] > d[u] + w) { n         q.erase(make_pair(d[v], v)); n         d[v] = d[u] + w; n         q.insert(make_pair(d[v], v)); n       } n     } n   } n } n int main() { n   cin >> n >> module; n   for (int i = 2; i <= n - 1; ++i) scanf( %d , &a[i]); n   for (int i = 1; i <= n; ++i) scanf( %d%d , &x[i], &y[i]); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       if (i != j) { n         ke[i].push_back(make_pair( n             j, module * (abs(x[i] - x[j]) + abs(y[i] - y[j])) - a[j])); n         ke[j].push_back(make_pair( n             i, module * (abs(x[i] - x[j]) + abs(y[i] - y[j])) - a[i])); n       } else { n         ke[i].push_back(make_pair(j, 1000000007)); n         ke[j].push_back(make_pair(i, 1000000007)); n       } n     } n   } n   s = 1; n   t = n; n   dijkstra(); n   if (d[t] == 1000000007) n     printf( -1 ); n   else n     printf( %d n , d[t]); n   return 0; n } n


#include <bits/stdc++.h> n const long long MOD = 1e9 + 7; n const long long MAXN = 1e6 + 1; n using namespace std; n long long readInt() { n   bool minus1 = false; n   long long result = 0; n   char ch; n   ch = getchar(); n   while (true) { n     if (ch ==  - ) break; n     if (ch >=  0  && ch <=  9 ) break; n     ch = getchar(); n   } n   if (ch ==  - ) n     minus1 = true; n   else n     result = ch -  0 ; n   while (true) { n     ch = getchar(); n     if (ch <  0  || ch >  9 ) break; n     result = result * 10 + (ch -  0 ); n   } n   if (minus1) n     return -result; n   else n     return result; n } n long long a[MAXN]; n long long b[MAXN]; n long long pref_a[MAXN]; n long long pref_b[MAXN]; n long long mn[MAXN]; n long long n, m; n long long x; n long long GGGG(long long kek) { n   int l = 1, r = m; n   while (r - l > 1) { n     int mid = (l + r) / 2; n     if (kek * mn[mid] <= x) { n       l = mid; n     } else { n       r = mid; n     } n   } n   return (kek * mn[r] <= x ? r : kek * mn[l] <= x ? l : 0); n } n int main() { n   n = readInt(), m = readInt(); n   for (int i = 1; i <= n; i++) { n     a[i] = readInt(); n   } n   for (int j = 1; j <= m; j++) { n     b[j] = readInt(); n   } n   x = readInt(); n   for (int i = 1; i <= n; i++) { n     pref_a[i] = pref_a[i - 1] + a[i]; n   } n   for (int i = 1; i <= m; i++) { n     pref_b[i] = pref_b[i - 1] + b[i]; n   } n   multiset<pair<int, int> > second; n   for (int i = 1; i <= m; i++) { n     mn[i] = MOD; n   } n   for (int i = 1; i <= m; i++) { n     for (int j = i; j <= m; j++) { n       mn[j - i + 1] = min(mn[j - i + 1], pref_b[j] - pref_b[i - 1]); n     } n   } n   long long mx = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = i; j <= n; j++) { n       mx = max(mx, (j - i + 1) * GGGG(pref_a[j] - pref_a[i - 1])); n     } n   } n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1000000007; n long long int max(long long int a, long long int b) { n   if (a > b) n     return a; n   else n     return b; n } n long long int min(long long int a, long long int b) { n   if (a < b) n     return a; n   else n     return b; n } n long long int binpow(long long a, long long b, long long m) { n   a %= m; n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % m; n     a = a * a % m; n     b >>= 1; n   } n   return res; n } n long long binpow(long long a, long long b) { n   if (b == 0) return 1; n   long long res = binpow(a, b / 2); n   if (b % 2) n     return res * res * a; n   else n     return res * res; n } n vector<vector<pair<int, int>>> adj; n vector<int> dp; n vector<int> ans; n int dfs(int x, int p) { n   for (auto c : adj[x]) { n     if (c.first == p) continue; n     int val = dfs(c.first, x); n     if (val == 0 && c.second == 2) { n       dp[x] += val + 1; n       ans.push_back(c.first); n     } else { n       dp[x] += val; n     } n   } n   return dp[x]; n } n void solve() { n   int n; n   cin >> n; n   adj.resize(n + 1); n   for (int i = 0; i < n - 1; i++) { n     int x, y, t; n     cin >> x >> y >> t; n     adj[x].push_back({y, t}); n     adj[y].push_back({x, t}); n   } n   dp.resize(n + 1); n   dfs(1, 0); n   cout << dp[1] << endl; n   for (auto c : ans) { n     cout << c <<    ; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   long long l = s.size(); n   for (long long i = 1; i < l - 1; i++) { n     if (s[i] == s[i - 1]) { n       if (s[i - 1] !=  a  && s[i + 1] !=  a ) n         s[i] =  a ; n       else if (s[i - 1] !=  b  && s[i + 1] !=  b ) n         s[i] =  b ; n       else n         s[i] =  c ; n     } n   } n   if (s[l - 1] == s[l - 2]) { n     if (s[l - 2] !=  a ) n       s[l - 1] =  a ; n     else if (s[l - 2] !=  b ) n       s[l - 1] =  b ; n     else n       s[l - 1] =  c ; n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unsigned long long int ops = 0; n   long long int x, y, m; n   cin >> x >> y >> m; n   if (x >= m || y >= m) { n     cout << 0 << endl; n     return 0; n   } n   if (x <= 0 && y <= 0) { n     cout << -1 << endl; n     return 0; n   } n   long long int mi = min(x, y), ma = max(x, y); n   long long int dif = ma - mi; n   ops = dif / ma; n   if (dif % ma != 0) ops++; n   mi += ops * ma; n   swap(mi, ma); n   while (mi < m && ma < m) { n     mi += ma; n     swap(mi, ma); n     ops++; n   } n   cout << ops << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int mod2 = 1e9 + 9; n const int maxN = 5e5 + 100; n const int INF = 1e9 + 7; n const int maxedge = 1e6 + 100; n const long long LL_INF = 1e18 + 11; n using namespace std; n long long n, ans; n map<long long, long long> ma; n void file() { n   freopen( pluses.in ,  r , stdin); n   freopen( pluses.out ,  w , stdout); n } n void boost() { n   ios_base ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n int main() { n   cin >> n; n   for (int long long i = 1; i * i <= n; i++) { n     if (n % i == 0) { n       if (ma[i] == 0) { n         ans++; n         ma[i]++; n       } n       if (ma[n / i] == 0) { n         ans++; n         ma[n / i]++; n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1010][3][50]; n bool p[1010]; n int main() { n   int n, i, j, c; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> s[i][1] >> s[i][2]; n   memset(p, true, sizeof(p)); n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) { n       if (i != j) { n         if (strcmp(s[i][2], s[j][1]) == 0) { n           strcpy(s[i][2], s[j][2]); n           p[j] = false; n         } n       } n     } n   } n   for (i = 1, c = 0; i <= n; i++) n     if (p[i]) c++; n   cout << c << endl; n   for (i = 1; i <= n; i++) { n     if (p[i]) cout << s[i][1] <<     << s[i][2] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1.5e3 + 5; n const int T = 1e5 + 5; n const int mod = 1e9 + 7; n int n, m, a, b, p, t; n int fac[T], inv[T], res; n int P[N], F[N], SP[N], SPL[N], S[N][N], L[N][N]; n namespace _ { n inline int mul(int x, int y) { return 1ll * x * y % mod; } n inline int dec(int x, int y) { n   x -= y; n   if (x < 0) x += mod; n   return x; n } n inline int add(int x, int y) { n   x += y; n   if (x >= mod) x -= mod; n   return x; n } n inline int modpow(int x, int y, int res = 1) { n   for (; y; y >>= 1, x = mul(x, x)) n     if (y & 1) res = mul(res, x); n   return res; n } n inline int C(int n, int m) { n   if (m > n) return 0; n   return mul(fac[n], mul(inv[m], inv[n - m])); n } n template <typename _Tp> n inline void IN(_Tp& x) { n   char ch; n   bool flag = 0; n   x = 0; n   while (ch = getchar(), !isdigit(ch)) n     if (ch ==  - ) flag = 1; n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   if (flag) x = -x; n } n }  // namespace _ n using namespace _; n int main() { n   fac[0] = inv[0] = 1; n   IN(n), IN(m), IN(a), IN(b), IN(t), p = mul(a, modpow(b, mod - 2)); n   for (int i = 1; i <= t; ++i) fac[i] = mul(fac[i - 1], i); n   for (int i = 1; i <= t; ++i) inv[i] = modpow(fac[i], mod - 2); n   for (int i = 0; i <= m; ++i) n     if (i <= t) n       P[i] = mul(C(t, i), mul(modpow(p, i), modpow(dec(1, p), t - i))); n   for (int i = 0; i <= m; ++i) SP[i] = i ? add(P[i], SP[i - 1]) : P[i]; n   S[0][m] = F[0] = 1; n   for (int i = 1; i <= n; ++i) { n     for (int r = 1; r <= m; ++r) { n       res = dec(mul(SP[r - 1], dec(F[i - 1], L[i - 1][m - r + 1])), SPL[r]); n       S[i][r] = mul(P[m - r], res), L[i][r + 1] = add(L[i][r], S[i][r]); n       SPL[r] = add(SPL[r - 1], mul(P[r - 1], L[i][r])); n     } n     for (int r = 1; r <= m; ++r) F[i] = add(F[i], S[i][r]); n   } n   printf( %d n , F[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int matrix[105][105]; n int vis[105][105]; n int main() { n   int n, k; n   while (scanf( %d%d , &n, &k) != EOF) { n     memset(matrix, 0, sizeof(matrix)); n     memset(vis, 0, sizeof(vis)); n     if (k > n * n) { n       printf( -1 n ); n       continue; n     } n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         if (!vis[i][j] && k) { n           if (i == j) { n             matrix[i][j]++; n             vis[i][j] = 1; n             k--; n           } else if (k >= 2) { n             matrix[i][j]++; n             matrix[j][i]++; n             vis[i][j] = vis[j][i] = 1; n             k -= 2; n           } n         } n       } n     } n     if (k) { n       printf( -1 n ); n       continue; n     } n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         if (j == n) { n           printf( %d n , matrix[i][j]); n         } else { n           printf( %d  , matrix[i][j]); n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e4 + 5; n long long int dp[N][102]; n int main() { n   int n, k, m; n   scanf( %d%d%d , &n, &k, &m); n   for (int i = 1; i <= 9; i++) dp[1][i % k]++; n   long long int wynik = 0, p = 1; n   for (int x = 1; x <= n - 1; x++) { n     p = (p * 10) % k; n     wynik = (wynik * 10) % m; n     wynik += dp[x][0] % m; n     for (int i = 1; i < k; i++) { n       dp[x][i] %= m; n       for (int j = 0; j <= 9; j++) n         if (j || (x != n - 1)) dp[x + 1][(i + j * p) % k] += dp[x][i]; n     } n     for (int j = 1; j <= 9; j++) dp[x + 1][(j * p) % k]++; n   } n   wynik *= 9; n   wynik += dp[n][0]; n   printf( %lld n , wynik % m); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000006, B = 1000001969; n int n, k, m, L[N], R[N]; n char a[N], b[N]; n long long a1[N], M[N]; n set<int> Set; n int actual(int x) { n   auto it = Set.lower_bound(x); n   return it == Set.end() ? n + 1 : *it; n } n void hash_build(char a[], int n, long long H[]) { n   for (int i = 1; i <= n; i++) H[i] = (H[i - 1] * M[1] + a[i]) % B; n } n long long hash_range(long long H[], int L, int R) { n   return (H[R] - H[L - 1] * M[R - L + 1] + 1LL * B * B) % B; n } n int main() { n   scanf( %d%d , &n, &k); n   scanf( %s , b + 1); n   m = strlen(b + 1); n   for (int i = 1; i <= k; i++) { n     scanf( %d , &L[i]); n     R[i] = L[i] + m - 1; n   } n   for (int i = 1; i <= n; i++) { n     a[i] =  ? ; n     Set.insert(i); n   } n   for (int i = 1; i <= k; i++) { n     for (int j = actual(L[i]); j <= R[i]; j = actual(j + 1)) { n       a[j] = b[j - L[i] + 1]; n       Set.erase(j); n     } n   } n   M[0] = 1; n   M[1] = 2309; n   for (int i = 2; i < N; i++) M[i] = M[i - 1] * M[1] % B; n   hash_build(a, n, a1); n   if (k) { n     long long H = hash_range(a1, L[1], R[1]); n     for (int i = 2; i <= k; i++) n       if (hash_range(a1, L[i], R[i]) != H) { n         cout << 0 << endl; n         return 0; n       } n   } n   long long P = 1; n   for (int i = 1; i <= Set.size(); i++) P = P * 26 % 1000000007; n   cout << P << endl; 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   long long int arr[n], i, c = 0; n   for (i = 0; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] == 1) c++; n   } n   if (c == n) { n     for (i = 0; i < n - 1; i++) cout << 1 <<    ; n     cout << 2 <<   n ; n   } else { n     sort(arr, arr + n); n     cout << 1 <<    ; n     for (i = 0; i < n - 1; i++) cout << arr[i] <<    ; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n unsigned N, M; n vector<unsigned> V; n double dens(const unsigned idxV1, const unsigned idxV2, const unsigned eW) { n   if (eW == 0) { n     return 0; n   } n   return (double)(V[idxV1] + V[idxV2]) / (double)eW; n } n int main() { n   unsigned v1, v2, w, n, m; n   double densidad; n   double max = 0; n   cout << setprecision(20); n   cin >> N; n   cin >> M; n   V = vector<unsigned>(N); n   for (n = 0; n < N; n++) { n     cin >> w; n     V[n] = w; n   } n   for (m = 0; m < M; m++) { n     cin >> v1; n     cin >> v2; n     cin >> w; n     v1--; n     v2--; n     densidad = dens(v1, v2, w); n     if (densidad > max) { n       max = densidad; n     } n   } n   cout << max << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int N = 2e6 + 10; n const long long mod = 1000000007; n const double eps = 1e-9; n const double PI = acos(-1); n template <typename T> n inline void read(T &a) { n   char c = getchar(); n   T x = 0, f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + c -  0 ; n     c = getchar(); n   } n   a = f * x; n } n int gcd(int a, int b) { return (b > 0) ? gcd(b, a % b) : a; } n int n, m; n char str[N]; n int main() { n   int T; n   read(T); n   while (T--) { n     read(n), read(m); n     scanf( %s , str + 1); n     int len = strlen(str + 1); n     int dx = 0, dy = 0; n     int minx = 0, miny = 0; n     int maxx = 0, maxy = 0; n     int ansx = 1, ansy = 1; n     for (int i = 1; i <= len; i++) { n       char it = str[i]; n       if (it ==  L ) n         dx--; n       else if (it ==  R ) n         dx++; n       else if (it ==  U ) n         dy--; n       else if (it ==  D ) n         dy++; n       minx = min(minx, dx); n       miny = min(miny, dy); n       maxx = max(maxx, dx); n       maxy = max(maxy, dy); n       if ((maxx - minx) >= m || (maxy - miny) >= n) break; n       ansx = 1 - minx; n       ansy = 1 - miny; n     } n     cout << ansy <<     << ansx << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(0); n   ; n   int T; n   cin >> T; n   while (T--) { n     int n; n     string s; n     cin >> n; n     cin >> s; n     int arr[200002]; n     int cnt = 1; n     int idx = 1; n     char x = s[0]; n     for (int i = (1); i <= (n - 1); i++) { n       if (s[i] == x) { n         cnt++; n       } else if (s[i] != x) { n         x = s[i]; n         arr[idx] = cnt; n         idx++; n         cnt = 1; n       } n     } n     arr[idx] = cnt; n     arr[idx + 1] = 2; n     int ans = 0; n     int idx2 = 1; n     int usable_idx = 1; n     int len = idx; n     while (arr[usable_idx] == 1) { n       usable_idx++; n     } n     while (idx2 <= len) { n       if (usable_idx > len) { n         ans += (len - idx2) / 2 + 1; n         break; n       } n       if (arr[idx2] == 1) { n         arr[usable_idx]--; n         if (arr[usable_idx] == 1) { n           usable_idx++; n           while (arr[usable_idx] == 1) { n             usable_idx++; n           } n         } n       } else if (arr[idx2] != 1) { n         if (usable_idx == idx2) { n           usable_idx++; n           while (arr[usable_idx] == 1) { n             usable_idx++; n           } n         } n       } n       idx2++; n       ans++; n     } n     cout << ans <<   n ; 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   cout << (n / 2) + 1 << endl; n   for (i = 1; i <= (n / 2) + 1; i++) cout << i <<   1  << endl; n   ; n   if (n % 2 != 0) n     for (i = 2; i <= (n / 2) + 1; i++) cout << (n / 2) + 1 <<     << i << endl; n   else n     for (i = 2; i < (n / 2) + 1; i++) cout << (n / 2) + 1 <<     << i << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int inf = 1000000000; n const long long int mod = 1000000000 + 7; n inline void IO() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); } n template <class T> n inline int CHECK(T MASK, int i) { n   return (MASK >> i) & 1; n } n template <class T> n inline T ON(T MASK, int i) { n   return MASK | (T(1) << i); n } n template <class T> n inline T OFF(T MASK, int i) { n   return MASK & (~(T(1) << i)); n } n template <typename T> n inline int CNT(T MASK) { n   if (numeric_limits<T>::digits <= numeric_limits<unsigned int>::digits) n     return __builtin_popcount(MASK); n   else n     return __builtin_popcountll(MASK); n } n template <class T> n inline int RIGHT(T MASK) { n   return log2(MASK & -MASK); n } n int dx4[] = {0, 0, -1, +1}; n int dy4[] = {+1, -1, 0, 0}; n int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0}; n int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0}; n inline void I(int& a) { scanf( %d , &a); } n inline void I(long long int& a) { scanf( %I64d , &a); } n inline void I(unsigned long long int& a) { scanf( %I64u , &a); } n inline void I(char* a) { scanf( %s , a); } n char Iarr[2000010]; n inline void I(string& a) { n   scanf( %s , Iarr); n   a = Iarr; n } n template <typename T, typename... Args> n void I(T& a, Args&... args) { n   I(a); n   I(args...); n } n inline void OUT(int a) { printf( %d , a); } n inline void OUT(long long int a) { printf( %I64d , a); } n inline void OUT(const char* a) { printf( %s , a); } n inline void OUT(char* a) { printf( %s , a); } n inline void OUT(bool a) { printf( %d , a); } n inline void OUT(string a) { n   for (__typeof(a.end()) it = (a.begin()) - ((a.begin()) > (a.end())); n        it != (a.end()) - ((a.begin()) > (a.end())); n        it += 1 - 2 * ((a.begin()) > (a.end()))) n     printf( %c , *it); n } n inline void OUT(unsigned long long int a) { printf( %I64u , a); } n template <typename T, typename... Args> n void OUT(T a, Args... args) { n   OUT(a); n   OUT(   ); n   OUT(args...); n } n template <typename... Args> n void O(Args... args) { n   OUT(args...); n   OUT(  n ); n } n template <typename T1, typename T2> n inline ostream& operator<<(ostream& os, pair<T1, T2> p) { n   os <<  {  << p.first <<  ,   << p.second <<  } ; n   return os; n } n template <typename T> n inline ostream& operator<<(ostream& os, vector<T>& a) { n   os <<  [ ; n   for (int i = 0; i < (int)a.size(); i++) { n     if (i) os <<  ,  ; n     os << a[i]; n   } n   os <<  ] ; n   return os; n } n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cout << *it <<   =   << a << endl; n   err(++it, args...); n } n const int M = 50010; n int pre[M][26]; n int query(int in, char c) { return pre[in][c -  a ]; } n int main() { n   string s; n   I(s); n   for (int i = 0; i < (int)s.size(); i++) { n     for (int j = 0; j < 26; j++) { n       if (i) n         pre[i][j] = pre[i - 1][j]; n       else n         pre[i][j] = -1; n     } n     pre[i][s[i] -  a ] = i; n   } n   int dp[(int)s.size()][101]; n   for (int i = 0; i < (int)s.size(); i++) { n     for (int j = 1; j <= 100; j++) { n       dp[i][j] = -1; n       if (j == 1) n         dp[i][j] = i; n       else if (i) { n         dp[i][j] = dp[i - 1][j]; n         int in; n         if (j != 2) n           in = dp[i - 1][j - 2]; n         else n           in = i; n         if (in > 0) { n           int q = query(in - 1, s[i]); n           if (q != -1) { n             dp[i][j] = max(dp[i][j], q); n           } n         } n       } n     } n   } n   int len, st; n   for (int i = 100; i >= 1; i--) { n     if (dp[(int)s.size() - 1][i] != -1) { n       len = i; n       st = dp[(int)s.size() - 1][i]; n       break; n     } n   } n   string second; n   second.resize(len); n   for (int i = (int)s.size() - 1; i >= 0 && len > 0; i--) { n     if (s[st] == s[i]) { n       int u = ((int)second.size() - len) / 2; n       second[u] = s[st]; n       second[u + len - 1] = s[st]; n       len -= 2; n       if (len > 0 && i) st = dp[i - 1][len]; n     } n   } n   O(second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void dbg_out() { cerr <<   b b] n ; } n template <typename Head, typename... Tail> n void dbg_out(Head H, Tail... T) { n   cerr << H <<  ,  ; n   dbg_out(T...); n } n void solve() { n   long double n; n   cin >> n; n   cout << fixed << setprecision(10); n   if (n == 2) { n     long double ans = 1; n     cout << ans <<   n ; n     return; n   } n   n *= 2; n   const double pi = acosl((long double)-1); n   double radian = pi / n; n   double radius = 1.0 / tan(radian); n   cout << radius <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int t = 0; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   vector<long long int> a(n); n   for (auto &it : a) cin >> it; n   long long o = (n + 1) / 2, e = n / 2; n   for (auto it : a) { n     if (!it) continue; n     if (it % 2) n       o--; n     else n       e--; n   } n   long long l_val = -1, l_idx = -1; n   vector<pair<long long int, long long int> > v11, v00, v10, v01; n   for (long long i = 0; i < n; i++) { n     long long it = a[i]; n     if (!it) continue; n     if (it % 2) { n       if (l_val == -1) n         v11.push_back({i - l_idx - 1, 1}); n       else if (l_val % 2) n         v11.push_back({i - l_idx - 1, 0}); n       else n         v01.push_back({i - l_idx - 1, 0}); n     } else { n       if (l_val == -1) n         v00.push_back({i - l_idx - 1, 1}); n       else if (l_val % 2 == 0) n         v00.push_back({i - l_idx - 1, 0}); n       else n         v10.push_back({i - l_idx - 1, 0}); n     } n     l_idx = i, l_val = it % 2; n   } n   if (l_val != -1) { n     if (l_val % 2) n       v11.push_back({n - l_idx - 1, 1}); n     else n       v00.push_back({n - l_idx - 1, 1}); n   } n   sort(v00.begin(), v00.end()); n   sort(v11.begin(), v11.end()); n   long long ans = ((long long int)(v01).size()) + ((long long int)(v10).size()); n   for (auto it : v11) { n     if (it.second == 1) continue; n     if (o >= it.first) n       o -= it.first; n     else n       ans += 2; n   } n   for (auto it : v11) { n     if (it.second == 0) continue; n     if (o >= it.first) n       o -= it.first; n     else n       ans++; n   } n   for (auto it : v00) { n     if (it.second == 1) continue; n     if (e >= it.first) n       e -= it.first; n     else n       ans += 2; n   } n   for (auto it : v00) { n     if (it.second == 0) continue; n     if (e >= it.first) n       e -= it.first; n     else n       ans++; n   } n   bool first = 0; n   for (auto it : a) first |= it; n   if (!first and n > 1) ans++; n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.precision(20); n   long long t = 1; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read() { return; } n void wrt() { cout << (string)   n ; } n void wrt(long long t) { cout << t; } n void wrt(int t) { cout << t; } n void wrt(char t) { cout << t; } n void wrt(string t) { cout << t; } n void wrt(double t) { cout << t; } n template <class T> n void wrt(set<T> v); n template <class T> n void wrt(vector<T> v); n template <class T> n void wrt(multiset<T> v); n template <class T, class V> n void wrt(map<T, V> v); n template <class T, class V> n void wrt(pair<T, V> p); n template <size_t T> n void wrt(const char (&a)[T]) { n   string s = a; n   wrt(s); n   wrt(); n } n template <class T> n void wrt(set<T> v) { n   for (T i : v) { n     wrt(i); n     wrt(   ); n   } n   wrt(); n } n template <class T> n void wrt(vector<T> v) { n   for (T i : v) { n     wrt(i); n     wrt(   ); n   } n   wrt(); n } n template <class T> n void wrt(multiset<T> v) { n   for (T i : v) { n     wrt(i); n     wrt(   ); n   } n   wrt(); n } n template <class T, class V> n void wrt(map<T, V> v) { n   for (auto i : v) { n     wrt(i); n     wrt(   ); n   } n   wrt(); n } n template <class T, class V> n void wrt(pair<T, V> p) { n   wrt(p.first); n   wrt(   ); n   wrt(p.second); n   wrt(); n } n template <class T, class... V> n void wrt(T x, V... args) { n   (wrt(x), wrt(   ), wrt(args...)); n } n template <class T, class... V> n void read(T &x, V &...args) { n   ((cin >> x), read(args...)); n } n template <class T> n void readArr(T &arr, int x, int y) { n   for (int i = (int)x; i < (int)y; ++i) cin >> arr[i]; n } n const int N = 1e6; n const int INF = INT_MAX; n const int MOD = 1e9 + 7; n int countBits(long long number) { return (int)log2(number) + 1; } n long long getSum(vector<int> a) { return accumulate(a.begin(), a.end(), 0ll); } n long long gcd(long long a, long long b) { n   return (b == 0) ? (a) : (gcd(b, a %= b)); n } n long long lcd(long long a, long long b) { return (a * b) / gcd(a, b); } n long long add(long long x, long long y) { return (x + y) % MOD; } n long long sub(long long x, long long y) { return (x - y + MOD) % MOD; } n long long mul(long long x, long long y) { return (x * 1ll * y) % MOD; } n long long inv(long long p, long long q) { n   long long expo = MOD - 2; n   while (expo) { n     if (expo & 1) p = mul(p, q); n     q = mul(q, q), expo >>= 1; n   } n   return p; n } n long long power(long long x, long long y) { n   if (y == 0) n     return 1; n   else if (y % 2 == 0) { n     long long tmp = power(x, y / 2); n     return mul(tmp, tmp); n   } else n     return mul(x, power(x, y - 1)); n } n void solveTestCase() { n   int n, m; n   read(n, m); n   vector<int> f(n * m + 1, -1); n   vector<vector<int> > r(n, vector<int>(m)), c(m, vector<int>(n)); n   for (int i = (int)0; i < (int)n; ++i) readArr(r[i], 0, m); n   for (int i = (int)0; i < (int)m; ++i) readArr(c[i], 0, n); n   for (int i = (int)0; i < (int)n; ++i) { n     f[c[0][i]] = i; n   } n   vector<vector<int> > ans(n, vector<int>(m)); n   for (int i = (int)0; i < (int)n; ++i) { n     int done = -1; n     for (int j = (int)0; j < (int)m; ++j) { n       if (f[r[i][j]] != -1) { n         done = f[r[i][j]]; n         break; n       } n     } n     for (int j = (int)0; j < (int)m; ++j) { n       ans[done][j] = r[i][j]; n     } n   } n   wrt(ans); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   ; n   int t = 1; n   cin >> t; n   while (t--) solveTestCase(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[100006][2]; n int main(void) { n   string s; n   cin >> s; n   int len = s.size(); n   memset(dp, -1, sizeof(dp)); n   dp[0][0] = 0; n   dp[0][1] = 0; n   for (int i = 1; i <= len; ++i) { n     dp[i][1] = dp[i - 1][1] + (bool)islower(s[i - 1]); n     dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + (bool)isupper(s[i - 1]); n   } n   cout << min(dp[len][0], dp[len][1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 100, mod = 998244353; n int n, c[N], s[N]; n int qpow(int x, int y) { n   int res = 1; n   while (y) { n     if (y & 1) res = 1ll * res * x % mod; n     x = 1ll * x * x % mod, y >>= 1; n   } n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &c[i]); n   sort(c + 1, c + n + 1), reverse(c + 1, c + n + 1); n   for (int i = 1; i <= n; ++i) s[i] = (s[i - 1] + c[i]) % mod; n   int iv = qpow(n, mod - 2); n   for (int i = 1; i <= n; ++i) { n     int ans = 0; n     for (int j = i + 1; j <= n; j += i) n       ans = (ans + 1ll * (s[min(n, j + i - 1)] - s[j - 1] + mod) * n                        ((j - 1) / i) % mod) % n             mod; n     printf( %lld  , 1ll * ans * iv % mod); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100007], b[100007]; n vector<int> v, ans; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m, x; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> x, a[x]++; n   for (int i = 0; i < n; i++) cin >> x, b[m - x - 1]++; n   for (int x = 0; x < 2 * m; x++) { n     int i = x % m; n     while (a[i]) v.push_back(i), a[i]--; n     while (b[i] && v.size()) n       ans.push_back((v.back() + m - i - 1) % m), v.pop_back(), b[i]--; n   } n   sort(ans.begin(), ans.end()); n   for (long i = ans.size() - 1; i >= 0; i--) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int popc(long long int x) { n   int cnt = 0; n   for (int i = 0; i < 50; i++) { n     if ((1ll << i) & x) cnt++; n   } n   return cnt; n } n int main() { n   ios_base::sync_with_stdio(0); n   long long int s, x; n   cin >> s >> x; n   if (s < x) { n     cout <<  0 n ; n     return 0; n   } n   if (s == x) { n     cout << ((1ll << (popc(s))) - 2) << endl; n     return 0; n   } n   if ((s - x) % 2 == 1) { n     cout <<  0  << endl; n     return 0; n   } n   long long int rest = (s - x) / 2; n   for (int i = 0; i < 50; i++) { n     if ((((1ll << i) & x) != 0) && (((1ll << i) & rest) != 0)) { n       cout <<  0 n ; n       return 0; n     } n   } n   cout << (1ll << popc(x)) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int p = 1; n   int diagjump = n + 1; n   for (int i = 1; i <= n; i++) { n     p = i; n     for (int j = 1; j <= n; j++) { n       cout << p <<    ; n       if (p == n * j) n         p++; n       else n         p += diagjump; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n bool checkprime(long long n) { n   long long i = 2; n   while (i * i <= n) { n     if (n % i == 0) return 0; n     i++; n   } n   return 1; n } n long long fact(long long n) { n   if (n == 0) return 1; n   return n * fact(n - 1); n } n bool compare(const pair<long long, long long>& i, n              const pair<long long, long long>& j) { n   return i.first < j.first; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   long long ans = 0; n   long long l[m + 1], r[m + 1], t[m + 1], c[m + 1]; n   for (long long i = 1; i <= m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i]; n   for (long long i = 1; i <= n; i++) { n     long long mxc = 0, mx = 100000, mxi = -1; n     for (long long j = 1; j <= m; j++) { n       if (i >= l[j] && i <= r[j] && t[j] < mx) { n         mxi = j; n         mx = t[j]; n         mxc = c[j]; n       } n     } n     ans += mxc; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool flag; n int n, k, vis[10][105]; n char s[10][105]; n int judge(int x, int y) { n   if ((s[x][y] ==  .  || s[x][y] ==  s ) && (x >= 1 && x <= 3)) n     return 1; n   else n     return 0; n } n void dfs(int x, int y) { n   vis[x][y] = 1; n   if (y >= n - 1) { n     flag = 1; n     return; n   } n   if (!judge(x, y + 1)) return; n   if (flag == 1) return; n   if (judge(x, y + 1) && judge(x, y + 2) && judge(x, y + 3) && !vis[x][y + 3]) n     dfs(x, y + 3); n   if (judge(x - 1, y + 1) && judge(x - 1, y + 2) && judge(x - 1, y + 3) && n       !vis[x - 1][y + 3]) n     dfs(x - 1, y + 3); n   if (judge(x + 1, y + 1) && judge(x + 1, y + 2) && judge(x + 1, y + 3) && n       !vis[x + 1][y + 3]) n     dfs(x + 1, y + 3); n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     flag = 0; n     for (int i = 1; i <= 3; i++) { n       for (int j = 0; j < n; j++) cin >> s[i][j]; n     } n     int x, y; n     for (int i = 1; i <= 3; i++) { n       for (int j = 0; j < n; j++) { n         if (s[i][j] ==  s ) x = i, y = j; n       } n     } n     for (int i = 1; i <= 3; i++) n       for (int j = n; j <= 104; j++) s[i][j] =  . ; n     memset(vis, 0, sizeof(vis)); n     dfs(x, y); n     if (flag == 1) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long a, b, c; n     cin >> a >> b >> c; n     string s; n     cin >> s; n     long long x = 0, y = 0, z = 0; n     for (long long i = 0; i < n; i++) { n       if (s[i] ==  R ) { n         x++; n       } else if (s[i] ==  P ) { n         y++; n       } else { n         z++; n       } n     } n     long long win = 0; n     win = min(a, z) + min(b, x) + min(c, y); n     long long r = (n + 1) / 2; n     if (win >= r) { n       cout <<  YES  << endl; n       char ans[n]; n       for (long long i = 0; i < n; i++) { n         if (s[i] ==  S  && a) { n           ans[i] =  R ; n           a--; n           z--; n         } else if (s[i] ==  R  && b) { n           ans[i] =  P ; n           b--; n           x--; n         } else if (s[i] ==  P  && c) { n           ans[i] =  S ; n           c--; n           y--; n         } else if (s[i] ==  S  && b > x) { n           ans[i] =  P ; n           b--; n         } else if (s[i] ==  S  && c > y) { n           ans[i] =  S ; n           c--; n         } else if (s[i] ==  R  && a > z) { n           ans[i] =  R ; n           a--; n         } else if (s[i] ==  R  && c > y) { n           ans[i] =  S ; n           c--; n         } else if (s[i] ==  P  && a > z) { n           ans[i] =  R ; n           a--; n         } else if (s[i] ==  P  && b > x) { n           ans[i] =  P ; n           b--; n         } n       } n       for (long long i = 0; i < n; i++) { n         cout << ans[i]; n       } n       cout << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n using ld = long double; n const ll INF = 1e18; n const ll MOD = 1e9 + 7; n const ld EPS = 1e-10; n const ld PI = acos(-1); n vector<ll> po[2]; n ll n, k; n pair<ll, ll> CountHash(ll x, ll ind, ll q) { n   ll h1 = 0, h2 = 0; n   for (ll i = 2; i * i <= x; ++i) { n     if (x % i == 0) { n       ll a = 0; n       while (x % i == 0) { n         ++a; n         x /= i; n       } n       a %= k; n       ll b = (k - a) % k; n       h1 += a * po[ind][i] % q; n       h2 += b * po[ind][i] % q; n       h1 %= q; n       h2 %= q; n     } n   } n   if (x > 1) { n     h1 += 1 * po[ind][x] % q; n     h2 += (k - 1) * po[ind][x] % q; n     h1 %= q; n     h2 %= q; n   } n   return {h1, h2}; n } n void solve() { n   cin >> n >> k; n   map<pair<ll, ll>, ll> cnt; n   ll P1 = 239; n   ll Q1 = 1e9 + 7; n   ll P2 = 41; n   ll Q2 = 1e9 + 9; n   po[0].resize(100000); n   po[1].resize(100000); n   po[0][0] = 1; n   po[1][0] = 1; n   for (int i = 1; i < 100000; ++i) { n     po[0][i] = po[0][i - 1] * P1 % Q1; n     po[1][i] = po[1][i - 1] * P2 % Q2; n   } n   ll ans = 0; n   for (int i = 0; i < n; ++i) { n     ll x; n     cin >> x; n     auto h1 = CountHash(x, 0, Q1); n     auto h2 = CountHash(x, 1, Q2); n     ans += cnt[{h1.second, h2.second}]; n     ++cnt[{h1.first, h2.first}]; n   } n   cout << ans <<   n ; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 2000 + 5; n int s, n, m, a[maxN]; n vector<int> p[maxN]; n vector<int> f[maxN], g[maxN]; n void initialize() { n   ios::sync_with_stdio(false); n   cin >> n >> s; n   s--; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   vector<int> t(a, a + n); n   sort(t.begin(), t.end()); n   t.erase(unique(t.begin(), t.end()), t.end()); n   for (int i = 0; i < n; ++i) n     a[i] = lower_bound(t.begin(), t.end(), a[i]) - t.begin() + 1; n   m = t.size(); n   for (int i = 0; i < n; ++i) p[a[i]].push_back(i); n   p[0].push_back(s); n   f[0].push_back(0); n   g[0].push_back(-1); n } n int cyc(int x, int y) { return y < x ? y + n - x : y - x; } n int cont(int x, int y) { return cyc(y, x); } n int sp(int x, int y) { return min(cyc(x, y), cont(x, y)); } n template <typename T> n bool chmin(T &x, const T &y) { n   return y < x ? x = y, true : false; n } n int solve() { n   for (int st = 1; st <= m; ++st) { n     int sz = p[st].size(); n     f[st].assign(sz, maxN * maxN); n     g[st].assign(sz, -1); n     for (int i = 0; i < sz; ++i) { n       int pre = i - 1, post = i + 1; n       if (pre == -1) pre = sz - 1; n       if (post == sz) post = 0; n       for (int j = 0; j < (int)p[st - 1].size(); ++j) { n         chmin(f[st][i], f[st - 1][j] + sp(p[st - 1][j], p[st][pre]) + n                             cont(p[st][pre], p[st][i])) && n             (g[st][i] = j); n         chmin(f[st][i], f[st - 1][j] + sp(p[st - 1][j], p[st][post]) + n                             cyc(p[st][post], p[st][i])) && n             (g[st][i] = j); n       } n     } n   } n   return *min_element(f[m].begin(), f[m].end()); n } n void psp(int x, int y) { n   if (cyc(x, y) <= cont(x, y)) n     printf( +%d n , cyc(x, y)); n   else n     printf( -%d n , cont(x, y)); n } n void print(int st, int i) { n   if (st == 0) return; n   int j = g[st][i]; n   print(st - 1, j); n   int sz = p[st].size(); n   int pre = i - 1, post = i + 1; n   if (pre == -1) pre = sz - 1; n   if (post == sz) post = 0; n   int cpre = n       f[st - 1][j] + sp(p[st - 1][j], p[st][pre]) + cont(p[st][pre], p[st][i]); n   int cpost = n       f[st - 1][j] + sp(p[st - 1][j], p[st][post]) + cyc(p[st][post], p[st][i]); n   if (cpre < cpost) { n     psp(p[st - 1][j], p[st][pre]); n     while (pre != i) { n       int pp = pre - 1; n       if (pp == -1) pp = sz - 1; n       printf( -%d n , cont(p[st][pre], p[st][pp])); n       pre = pp; n     } n   } else { n     psp(p[st - 1][j], p[st][post]); n     while (post != i) { n       int pp = post + 1; n       if (pp == sz) pp = 0; n       printf( +%d n , cyc(p[st][post], p[st][pp])); n       post = pp; n     } n   } n } n int main() { n   initialize(); n   cout << solve() << endl; n   print(m, min_element(f[m].begin(), f[m].end()) - f[m].begin()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, num, m; n map<long long, bool> isInsert; n priority_queue<long long, vector<long long>, greater<long long> > pq; n vector<string> vs; n vector<long long> vi; n int main() { n   m = 0; n   cin >> n; n   while (n--) { n     string s; n     cin >> s; n     if (s ==  insert ) { n       cin >> num; n       pq.push(num); n       isInsert[num] = true; n       vs.push_back(s); n       vi.push_back(num); n       m++; n     } else if (s ==  getMin ) { n       cin >> num; n       if (!pq.empty() && pq.top() == num) { n         vs.push_back(s); n         vi.push_back(num); n         m++; n       } else { n         if (!isInsert[num]) { n           pq.push(num); n           isInsert[num] = true; n           vs.push_back( insert ); n           vi.push_back(num); n           m++; n         } n         while (pq.top() != num) { n           isInsert[pq.top()] = false; n           vs.push_back( removeMin ); n           vi.push_back(-10000000000); n           m++; n           pq.pop(); n         } n         vs.push_back(s); n         vi.push_back(num); n         m++; n       } n     } else { n       m++; n       if (pq.empty()) { n         pq.push(2); n         isInsert[2] = true; n         vs.push_back( insert ); n         vi.push_back(2); n         m++; n       } n       isInsert[pq.top()] = false; n       pq.pop(); n       vs.push_back(s); n       vi.push_back(-10000000000); n     } n   } n   cout << m <<   n ; n   int size = vs.size(); n   for (int i = 0; i < size; ++i) { n     cout << vs[i] <<    ; n     if (vi[i] != -10000000000) n       cout << vi[i] <<   n ; n     else n       cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int team[1000010][2], ans[1010], n, x; n bool used[1010]; n int main() { n   scanf( %d , &n); n   n *= 2; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j < i; j++) { n       scanf( %d , &x); n       team[x][0] = i; n       team[x][1] = j; n     } n   used[0] = 1; n   for (int i = 1000000; i > 0; i--) { n     if (!used[team[i][0]] && !used[team[i][1]]) { n       used[team[i][0]] = 1; n       used[team[i][1]] = 1; n       ans[team[i][0]] = team[i][1]; n       ans[team[i][1]] = team[i][0]; n     } n   } n   for (int i = 1; i < n; i++) printf( %d  , ans[i]); n   printf( %d n , ans[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n inline void chkmin(T1& a, T2 b) { n   if (a > b) a = b; n } n template <typename T1, typename T2> n inline void chkmax(T1& a, T2 b) { n   if (a < b) a = b; n } n using ll = long long; n using d = double; n using ld = long double; n const string FILENAME =  input ; n const int MAXN = 200228; n const d eps = 1e-15; n __int128 gcd(__int128 a, __int128 b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n __int128 mabs(__int128 a) { return (a >= 0 ? a : -a); } n struct Ratio { n   __int128 p, q; n   Ratio() {} n   Ratio(__int128 a, __int128 b) { n     p = a; n     q = b; n     auto d = mabs(gcd(p, q)); n     if (d != 0) { n       p /= d; n       q /= d; n     } n     if (q < 0) { n       p = -p; n       q = -q; n     } n   } n }; n void norm(Ratio& a) { n   auto d = mabs(gcd(a.p, a.q)); n   if (d != 0) { n     a.p /= d; n     a.q /= d; n   } n   if (a.q < 0) { n     a.p = -a.p; n     a.q = -a.q; n   } n   if (a.p == 0 && a.q != 0) { n     a.q = 1; n   } n } n bool operator==(const Ratio& a, const Ratio& b) { n   return a.p == b.p && a.q == b.q; n } n bool operator<(const Ratio& a, const Ratio& b) { return a.p * b.q < b.p * a.q; } n Ratio operator+(const Ratio& a, const Ratio& b) { n   Ratio c; n   c.q = a.q * b.q; n   c.p = a.p * b.q + b.p * a.q; n   norm(c); n   return c; n } n Ratio operator-(const Ratio& a, const Ratio& b) { n   Ratio c; n   c.q = a.q * b.q; n   c.p = a.p * b.q - b.p * a.q; n   norm(c); n   return c; n } n Ratio operator*(const Ratio& a, const Ratio& b) { n   Ratio c; n   c.p = a.p * b.p; n   c.q = a.q * b.q; n   norm(c); n   return c; n } n Ratio operator/(const Ratio& a, const Ratio& b) { n   Ratio c; n   c.p = a.p * b.q; n   c.q = a.q * b.p; n   norm(c); n   return c; n } n struct Point { n   Ratio x, y; n   Point() {} n   Point(Ratio _x, Ratio _y) { n     x = _x; n     y = _y; n   } n }; n bool operator==(const Point& a, const Point& b) { n   return a.x == b.x && a.y == b.y; n } n bool operator<(const Point& a, const Point& b) { n   return make_pair(a.x, a.y) < make_pair(b.x, b.y); n } n Point operator-(const Point& a, const Point& b) { n   return Point(a.x - b.x, a.y - b.y); n } n Point createPoint(ll a, ll b, ll c) { n   Point res(Ratio(a, a + b + c), Ratio(b, a + b + c)); n   return res; n } n int n; n Point p[MAXN]; n ll cnt1 = 0; n Point target; n map<Point, int> kek; n map<Point, int> cntr; n void print(Point pp) { n   cout << (ll)pp.x.p <<  /  << (ll)pp.x.q <<     << (ll)pp.y.p <<  /  n        << (ll)pp.y.q << endl; n } n Ratio vec(const Point& a, const Point& b) { return a.x * b.y - a.y * b.x; } n int check(Point a, Point b) { n   if (a == b) { n     return 0; n   } n   return vec(a, b).p < 0; n } n struct event { n   Point a; n   event() {} n   event(Point _a) { a = _a; } n }; n Ratio len(Point a) { return a.x * a.x + a.y * a.y; } n bool operator==(const event& a, const event& b) { return a.a == b.a; } n int getHalf(Point a) { return a.y.p > 0 || (a.y.p == 0 && a.x.p > 0); } n bool operator<(const event& a, const event& b) { n   int t = getHalf(a.a); n   int t1 = getHalf(b.a); n   if (t != t1) { n     return t > t1; n   } n   if (a.a == b.a) { n     return false; n   } n   Ratio s = vec(a.a, b.a); n   if (s.p == 0) { n     return len(a.a) < len(b.a); n   } else { n     return s.p > 0; n   } n } n multiset<event> st; n int cntk = 0; n Point getRight(Point x) { n   auto f = st.upper_bound(event(x)); n   if (f == st.end()) { n     f = st.begin(); n   } n   return (*f).a; n } n Point getLeft(Point x) { n   auto f = st.lower_bound(event(x)); n   if (f == st.begin()) { n     f = st.end(); n   } n   f--; n   return (*f).a; n } n void norm(Point& a) { n   if (a.x.p == 0) { n     a.x.p = 0; n     a.x.q = 1; n     int c = (a.y.p > 0 ? 1 : -1); n     a.y.p = c; n     a.y.q = 1; n   } else if (a.y.p == 0) { n     a.y.p = 0; n     a.y.q = 1; n     int c = (a.x.p > 0 ? 1 : -1); n     a.x.p = c; n     a.x.q = 1; n   } else { n     a.x.p *= a.y.q; n     a.y.p *= a.x.q; n     a.x.q = 1; n     a.y.q = 1; n     auto d = mabs(gcd(a.x.p, a.y.p)); n     a.x.p /= d; n     a.y.p /= d; n   } n } n map<Point, int> cntf; n void add(Point t) { n   if (t == target) { n     return; n   } n   t = t - target; n   norm(t); n   cntf[t]++; n   if (cntf[t] == 1) { n     auto t1 = event(t); n     if ((int)(st).size() == 0) { n       st.insert(t1); n     } else { n       auto f = getLeft(t); n       auto f1 = getRight(t); n       cntk -= check(f, f1); n       cntk += check(f, t); n       cntk += check(t, f1); n       st.insert(t1); n     } n   } n } n void del(Point t) { n   if (t == target) { n     return; n   } n   t = t - target; n   norm(t); n   cntf[t]--; n   if (cntf[t] == 0) { n     auto t1 = event(t); n     st.erase(st.find(t1)); n     if (st.empty()) { n       return; n     } n     auto f = getLeft(t); n     auto f1 = getRight(t); n     cntk += check(f, f1); n     cntk -= check(f, t); n     cntk -= check(t, f1); n   } n } n void proceedBich(int id) { n   Point x = p[id] - target; n   norm(x); n   Point x1 = x; n   x1.x.p *= -1; n   x1.y.p *= -1; n   cnt1 += cntr[x1]; n   cntr[x]++; n } n void proceedBich1(int id) { n   Point x = p[id] - target; n   norm(x); n   Point x1 = x; n   x1.x.p *= -1; n   x1.y.p *= -1; n   cntr[x]--; n   cnt1 -= cntr[x1]; n } n void addPoint(int id) { n   kek[p[id]]++; n   proceedBich(id); n   add(p[id]); n } n void delPoint(int id) { n   kek[p[id]]--; n   proceedBich1(id); n   del(p[id]); n } n int check() { n   if (kek[target]) { n     return 1; n   } n   if (cnt1) { n     return 2; n   } n   if (cntk == 0) { n     if ((int)(st).size() >= 3) { n       return 3; n     } n   } n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int ss, pp, gg; n   cin >> ss >> pp >> gg; n   target = createPoint(ss, pp, gg); n   cin >> n; n   int uk = 0; n   for (int it = 0; it < n; it++) { n     char c; n     cin >> c; n     if (c ==  A ) { n       int ph, pg, pd; n       cin >> ph >> pg >> pd; n       p[uk] = createPoint(ph, pg, pd); n       addPoint(uk); n       uk++; n     } else if (c ==  R ) { n       int id; n       cin >> id; n       id--; n       delPoint(id); n     } n     cout << check() <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long LL_INF = (long long)2e18 + 5; n struct point { n   long long x, y; n   point() : x(0), y(0) {} n   point(long long _x, long long _y) : x(_x), y(_y) {} n }; n struct reverse_monotonic_dp_hull { n   vector<point> points; n   int size() const { return (int)points.size(); } n   void clear() { n     points.clear(); n     prev_x = LL_INF; n   } n   static long long floor_div(long long a, long long b) { n     return a / b - ((a ^ b) < 0 && a % b != 0); n   } n   static bool bad_middle(const point &a, const point &b, const point &c) { n     return floor_div(a.y - b.y, b.x - a.x) >= floor_div(b.y - c.y, c.x - b.x); n   } n   void insert(const point &p) { n     assert(size() == 0 || p.x >= points.back().x); n     if (size() > 0 && p.x == points.back().x) { n       if (p.y <= points.back().y) return; n       points.pop_back(); n     } n     while (size() >= 2 && n            bad_middle(points[points.size() - 2], points.back(), p)) n       points.pop_back(); n     points.push_back(p); n   } n   void insert(long long a, long long b) { insert(point(a, b)); } n   long long prev_x = LL_INF; n   long long query(long long x) { n     assert(x <= prev_x); n     prev_x = x; n     while (size() >= 2 && x * (points.back().x - points[size() - 2].x) <= n                               points[size() - 2].y - points.back().y) n       points.pop_back(); n     return points.back().x * x + points.back().y; n   } n }; n int N, K; n vector<long long> A; n vector<long long> dp, next_dp; n vector<long long> left_max, right_max; n void update(int start, int end) { n   if (start >= end) return; n   if (end - start == 1) { n     next_dp[end] = min(next_dp[end], dp[start] + A[start]); n     return; n   } n   int mid = (start + end) / 2; n   update(start, mid); n   left_max[mid] = right_max[mid] = -LL_INF; n   for (int i = mid - 1; i >= start; i--) n     left_max[i] = max(left_max[i + 1], A[i]); n   for (int i = mid; i < end; i++) right_max[i + 1] = max(right_max[i], A[i]); n   reverse_monotonic_dp_hull hull; n   for (int right = mid + 1, left = mid; right <= end; right++) { n     while (left >= start && right_max[right] >= left_max[left]) { n       hull.insert(-left, -dp[left]); n       left--; n     } n     if (hull.size() > 0) n       next_dp[right] = min(next_dp[right], -hull.query(-right_max[right]) + n                                                right * right_max[right]); n   } n   hull.clear(); n   for (int right = end, left = start; right > mid; right--) { n     while (left <= mid && left_max[left] >= right_max[right]) { n       hull.insert(-left_max[left], left * left_max[left] - dp[left]); n       left++; n     } n     if (hull.size() > 0) n       next_dp[right] = min(next_dp[right], -hull.query(right)); n   } n   update(mid + 1, end); n } n void update_dp() { n   left_max.assign(N + 1, -LL_INF); n   right_max.assign(N + 1, -LL_INF); n   next_dp.assign(N + 1, LL_INF); n   update(0, N); n   swap(dp, next_dp); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> N >> K; n   A.resize(N); n   for (auto &a : A) cin >> a; n   dp.assign(N + 1, LL_INF); n   dp[0] = 0; n   for (int k = 0; k < K; k++) update_dp(); n   cout << dp[N] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int judge(int n) { n   int flag = 0; n   for (int i = 2; i <= n / 2; i++) { n     if (n % i == 0) { n       flag = 1; n       break; n     } n   } n   if (flag) n     return 0; n   else n     return 1; n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= 1000; i++) { n     int sum = i * n + 1; n     if (judge(sum) == 0) { n       printf( %d n , i); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int inf = 1e18; n const int N = 1e5 + 5; n void solve() { n   int n; n   cin >> n; n   set<int> st; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     if (x % 2 == 0) st.insert(x); n   } n   int ans = 0; n   while (!st.empty()) { n     int x = *st.rbegin(); n     st.erase(x); n     if (x % 2 == 0) st.insert(x / 2), ans++; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout << fixed << showpoint; n   cout << setprecision(9); n   int test = 1; n   cin >> test; n   while (test--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read(int &n) { n   n = 0; n   int s = 1; n   char c; n   for (; (c = getchar()) >  9  || c <  0 ;) n     if (c ==  - ) s = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) n = (n << 1) + (n << 3) + c - 48; n   n *= s; n } n void write(int n) { n   if (!n) putchar(48); n   int t = 0, b[20]; n   for (; n; n /= 10) b[++t] = n % 10; n   while (t) putchar(b[t--] + 48); n } n int f[18][200100], nxt[18][200100], m, n, q, deep[200100], fir[200100], n     nex[200100], to[200100], top, son[10001001][2], siz[10001001], cnt, n     rt[200100], dfl[200100], dfr[200100], mn[200100], opl, opr; n struct dot { n   int a, b; n } a[200100 + 200100]; n bool cmp(dot a, dot b) { return a.a < b.a; } n void dfs(int x) { n   ++deep[x]; n   dfl[x] = dfr[x] = ++top; n   for (int i = fir[x]; i; i = nex[i]) n     deep[to[i]] = deep[x], dfs(to[i]), dfr[x] = dfr[to[i]]; n } n int lca(int x, int y) { n   if (deep[x] > deep[y]) return lca(y, x); n   for (int i(17), _E_(0); i >= _E_; --i) n     if (deep[f[i][y]] >= deep[x]) y = f[i][y]; n   if (x == y) return x; n   for (int i(17), _E_(0); i >= _E_; --i) n     if (f[i][y] ^ f[i][x]) x = f[i][x], y = f[i][y]; n   return f[0][x]; n } n void doit(int x) { n   for (int i = fir[x]; i; i = nex[i]) { n     doit(to[i]); n     mn[x] = deep[mn[to[i]]] < deep[mn[x]] ? mn[to[i]] : mn[x]; n   } n   if (x ^ mn[x]) nxt[0][x] = mn[x]; n } n void update(int u, int &v, int h, int t) { n   v = ++cnt; n   siz[v] = siz[u] + 1; n   son[v][0] = son[u][0]; n   son[v][1] = son[u][1]; n   if (h == t) return; n   int m = h + t >> 1; n   if (opl <= m) n     update(son[u][0], son[v][0], h, m); n   else n     update(son[u][1], son[v][1], m + 1, t); n } n int query(int w, int h, int t) { n   if (opl > t || opr < h || !w) return 0; n   if (opl <= h && opr >= t) return siz[w]; n   int m = h + t >> 1, res = 0; n   if (opl <= m) res += query(son[w][0], h, m); n   if (opr > m) res += query(son[w][1], m + 1, t); n   return res; n } n int exist(int u, int v) { n   int sum = 0; n   opr = dfr[v]; n   opl = dfl[v]; n   sum += query(rt[dfr[u]], 1, n); n   opr = dfr[v]; n   opl = dfl[v]; n   sum -= query(rt[dfl[u] - 1], 1, n); n   return sum > 0; n } n int main() { n   scanf( %d , &n); n   for (int i(1), _E_(n); i <= _E_; ++i) mn[i] = i; n   for (int i(2), _E_(n); i <= _E_; ++i) n     scanf( %d , f[0] + i), to[++top] = i, nex[top] = fir[f[0][i]], n                            fir[f[0][i]] = top; n   top = 0; n   dfs(1); n   scanf( %d , &m); n   for (int j(1), _E_(17); j <= _E_; ++j) n     for (int i(1), _E_(n); i <= _E_; ++i) f[j][i] = f[j - 1][f[j - 1][i]]; n   int t = 0; n   for (int i(1), _E_(m); i <= _E_; ++i) { n     int x, y, l; n     scanf( %d %d , &x, &y); n     l = lca(x, y); n     a[++t] = (dot){dfl[x], dfl[y]}; n     a[++t] = (dot){dfl[y], dfl[x]}; n     mn[x] = deep[mn[x]] > deep[l] ? l : mn[x]; n     mn[y] = deep[mn[y]] > deep[l] ? l : mn[y]; n   } n   doit(1); n   sort(a + 1, a + m + m + 1, cmp); n   for (int j(1), _E_(17); j <= _E_; ++j) n     for (int i(1), _E_(n); i <= _E_; ++i) nxt[j][i] = nxt[j - 1][nxt[j - 1][i]]; n   for (int i(1), _E_(m + m); i <= _E_; ++i) n     opl = a[i].b, update(rt[a[i - 1].a], rt[a[i].a], 1, n); n   for (int i(1), _E_(n); i <= _E_; ++i) n     if (!rt[i]) rt[i] = rt[i - 1]; n   scanf( %d , &q); n   for (int i(1), _E_(q); i <= _E_; ++i) { n     int u, v; n     scanf( %d %d , &u, &v); n     if (u == v) { n       printf( 0 n ); n       continue; n     } n     int L = lca(u, v), ans = 0; n     for (int j(17), _E_(0); j >= _E_; --j) n       if (deep[nxt[j][u]] > deep[L]) u = nxt[j][u], ans += 1 << j; n     for (int j(17), _E_(0); j >= _E_; --j) n       if (deep[nxt[j][v]] > deep[L]) v = nxt[j][v], ans += 1 << j; n     if (L == u && nxt[0][v]) n       printf( %d n , ans + 1); n     else if (L == v && nxt[0][u]) n       printf( %d n , ans + 1); n     else if (!nxt[0][u] || !nxt[0][v]) n       printf( -1 n ); n     else n       printf( %d n , ans + 2 - exist(u, v)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxN = 1e5 + 13; n long long root, sz[maxN], h[maxN], ans, val[maxN], m, n, pw[maxN], pre[maxN]; n map<long long, long long> mp; n vector<long long> vec; n vector<pair<long long, long long>> adj[maxN]; n bool mark[maxN], fl; n void dfs(long long v, long long p) { n   sz[v] = 1; n   for (auto a : adj[v]) { n     long long u = a.first, w = a.second; n     if (u != p && !mark[u]) { n       dfs(u, v); n       sz[v] += sz[u]; n     } n   } n } n long long getpw(long long a, long long b) { n   long long ret = 1; n   for (; b; b >>= 1, a = 1ll * a * a % m) n     if (b & 1) ret = 1ll * ret * a % m; n   return ret; n } n void precomp() { n   pw[0] = 1; n   for (long long i = 1; i < n + 5; i++) pw[i] = pw[i - 1] * 10 % m; n   long long tmp = m, tot = m; n   for (long long p = 2; p * p <= tmp; p++) n     if (tmp % p == 0) { n       tot = tot / p * (p - 1); n       while (tmp % p == 0) tmp /= p; n     } n   if (tmp > 1) tot = tot / tmp * (tmp - 1); n   pre[0] = 1; n   pre[1] = getpw(10, tot - 1); n   for (long long i = 2; i < n + 5; i++) pre[i] = 1ll * pre[i - 1] * pre[1] % m; n } n void du(long long v, long long p) { n   for (auto a : adj[v]) { n     long long u = a.first, w = a.second; n     if (u != p && !mark[u]) { n       h[u] = h[v] + 1; n       val[u] = ((val[v]) + w * pw[h[v]]) % m; n       if (val[u] == 0) ans++; n       du(u, v); n     } n   } n } n void dd(long long v, long long p, long long cur) { n   if (v != root) vec.push_back(v); n   reverse(adj[v].begin(), adj[v].end()); n   for (auto a : adj[v]) { n     long long u = a.first, w = a.second; n     if (u != p && !mark[u]) { n       long long nwcur = (cur * 10 + w) % m; n       long long wnt = ((1ll * pre[h[u]] * ((-nwcur) % m + m)) + m) % m; n       ans += mp[wnt]; n       dd(u, v, nwcur); n       if (nwcur == 0 && fl) ans++; n       if (v == root) { n         while (vec.size()) { n           long long u = vec.back(); n           vec.pop_back(); n           mp[val[u]]++; n         } n       } n     } n   } n } n void calc(long long v) { n   long long tmp = ans; n   h[v] = 0; n   val[v] = 0; n   du(v, -1); n   mp.clear(); n   fl = 0; n   dd(v, -1, 0); n   mp.clear(); n   fl = 1; n   dd(v, -1, 0); n } n void solve(long long v) { n   dfs(v, -1); n   root = v; n   long long p = -1; n   bool fl = true; n   while (fl) { n     fl = false; n     for (auto a : adj[v]) { n       long long u = a.first; n       if (!mark[u] && u != p && sz[u] > sz[root] / 2) { n         p = v; n         v = u; n         fl = true; n         break; n       } n     } n   } n   mark[v] = true; n   root = v; n   calc(v); n   for (auto a : adj[v]) { n     long long u = a.first; n     if (!mark[u]) solve(u); n   } n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   precomp(); n   for (long long i = 0; i < n - 1; i++) { n     long long a, b, w; n     cin >> a >> b >> w; n     a++; n     b++; n     w %= m; n     adj[a].push_back({b, w}); n     adj[b].push_back({a, w}); n   } n   solve(1); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, M; n   cin >> n >> M; n   vector<char> s(n); n   int m = M; n   vector<int> p(m), b(n), yes(n, 0), cnt(26, 0); n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n     cnt[s[i] -  a ]++; n   } n   for (int i = 0; i < m; i++) { n     cin >> p[i]; n     p[i]--; n   } n   sort(p.begin(), p.end()); n   int top = 0; n   for (int i = 0; i < n; i++) { n     if (top >= M) break; n     if (p[top] != i) n       cnt[s[i] -  a ] += m; n     else { n       int t = top; n       while (top < M - 1 && p[top] == p[top + 1]) top++; n       int c = ++top - t; n       cnt[s[i] -  a ] += m; n       m -= c; n     } n   } n   for (int i = 0; i < 26; i++) cout << cnt[i] <<    ; n   cout << endl; n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct tree { n   tree() : par(NULL), val(0) { next.clear(); }; n   map<int, tree *> next; n   tree *par; n   int val; n   void setParent(tree *p) { par = p; } n }; n tree *moveDown(tree *root, int n) { n   tree *ret = NULL; n   if (root->next.count(n)) { n     ret = root->next[n]; n   } else { n     ret = new tree(); n     ret->setParent(root); n     root->next[n] = ret; n   } n   ret->val++; n   return ret; n } n tree *moveUp(tree *root) { return root->par; } n char line[1000003]; n char tmp[5002]; n map<string, int> f; n vector<int> v; n int go(tree *root, int what) { n   int ans = 0; n   for (map<int, tree *>::iterator it = root->next.begin(); n        it != root->next.end(); ++it) { n     if (it->first == what) n       ans += it->second->val + go(it->second, what); n     else n       ans += go(it->second, what); n   } n   return ans; n } n int calc(tree *root, int ind = 0) { n   if (ind + 1 == v.size()) { n     return go(root, v[ind]); n   } n   int ans = 0; n   for (map<int, tree *>::iterator it = root->next.begin(); n        it != root->next.end(); ++it) { n     if (it->first == v[ind]) n       ans += calc(it->second, ind + 1); n     else n       ans += calc(it->second, ind); n   } n   return ans; n } n void out(tree *root, int par = -1) { n   for (map<int, tree *>::iterator it = root->next.begin(); n        it != root->next.end(); ++it) { n     out(it->second, it->first); n   } n } n int main() { n   tree *root = new tree(), *root1 = root; n   char str[25] = {0}; n   gets(line); n   int l = strlen(line), tot = 0; n   map<string, int>::iterator it; n   for (int i = 0; i < l; ++i) { n     if (line[i] ==  < ) { n       int type = 0, len = 0; n       if (line[i + 1] ==  / ) type = 1; n       for (i = i + 1 + (type == 1); i < l; ++i) { n         if (line[i] ==  / ) n           type = 2; n         else if (line[i] ==  > ) n           break; n         else n           str[len++] = line[i]; n       } n       int num = 0; n       str[len] =   0 ; n       it = f.find(string(str)); n       if (it != f.end()) n         num = it->second; n       else n         f[string(str)] = num = tot++; n       if (type == 0) { n         root = moveDown(root, num); n       } else if (type == 1) { n         root = moveUp(root); n       } else { n         moveDown(root, num); n       } n     } n   } n   int q; n   scanf( %d n , &q); n   while (q--) { n     gets(tmp); n     istringstream ss(tmp); n     string s; n     bool ok = true; n     v.clear(); n     while (ss >> s) { n       it = f.find(s); n       if (it != f.end()) { n         v.push_back(it->second); n       } else { n         ok = false; n         break; n       } n     } n     if (ok) n       printf( %d n , calc(root1)); n     else n       printf( 0 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long inv(long long a, long long mod) { n   long long b = mod, p = 1, q = 0; n   while (b) { n     long long c = a / b, d = a; n     a = b; n     b = d % b; n     d = p; n     p = q; n     q = d - c * q; n   } n   return (p + mod) % mod; n } n map<tuple<long long, long long, long long, long long, int>, long long> mp; n long long sol(long long w0, long long w1, long long w2, long long a, int m) { n   long long res = 0; n   long long mod = 998244353; n   tuple<long long, long long, long long, long long, int> key = n       make_tuple(w0, w1, w2, a, m); n   if (mp.find(key) != mp.end()) return mp[key]; n   if (m == 0) { n     res = w2; n   } else { n     long long sum = w0 + w1 + w2; n     long long isum = inv(sum, mod); n     long long t0 = w0 * isum % mod * sol(w0 - 1, w1, w2, a, m - 1) % mod; n     long long t1 = w1 * isum % mod * sol(w0, w1 + 1, w2, a, m - 1) % mod; n     long long t2 = n         w2 * isum % mod * sol(w0, w1, w2 + (a == 0 ? -1 : 1), a, m - 1) % mod; n     res = (t0 + t1 + t2) % mod; n   } n   mp[key] = res; n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   vector<long long> a(n), w(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> w[i]; n   long long mod = 998244353; n   vector<long long> res(n); n   for (int i = 0; i < n; i++) { n     long long w0 = 0, w1 = 0; n     for (int j = 0; j < n; j++) { n       if (j == i) continue; n       if (a[j] == 0) n         w0 = (w0 + w[j]) % mod; n       else n         w1 = (w1 + w[j]) % mod; n     } n     long long w2 = w[i]; n     res[i] = sol(w0, w1, w2, a[i], m); n   } n   for (int i = 0; i < n; i++) { n     cout << res[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double ans = 1111111111; n int ap[111111], bp[111111], bt[111111], n, m, a, b, l, r, m1, m2, minap, minbp; n double dist(double ax, double ay, double bx, double by) { n   return sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay)); n } n double f(int i, int j) { n   return dist(0, 0, a, ap[i]) + dist(a, ap[i], b, bp[j]) + bt[j]; n } n int main() { n   scanf( %d%d%d%d , &n, &m, &a, &b); n   for (int i = 0; i < n; i++) scanf( %d , &ap[i]); n   for (int i = 0; i < m; i++) scanf( %d , &bp[i]); n   for (int i = 0; i < m; i++) { n     scanf( %d , &bt[i]); n     l = 0, r = n - 1; n     while (r - l >= 3) { n       m1 = l + (r - l) / 3; n       m2 = r - (r - l) / 3; n       if (f(m1, i) < f(m2, i)) n         r = m2; n       else n         l = m1; n     } n     for (int j = l; j <= r; j++) { n       if (f(j, i) < ans) ans = f(j, i), minap = j, minbp = i; n     } n   } n   printf( %d %d , minap + 1, minbp + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, sum, sum1, count = 1; n   cin >> n; n   int arr[4 * n + 1]; n   arr[0] = 0; n   for (i = 1; i <= 4 * n - 3; i = i + 4) { n     cin >> arr[i] >> arr[i + 1] >> arr[i + 2] >> arr[i + 3]; n     if (i == 1) n       sum = arr[1] + arr[2] + arr[3] + arr[4]; n     else { n       sum1 = arr[i] + arr[i + 1] + arr[i + 2] + arr[i + 3]; n       if (sum1 > sum) count++; n     } n   } n   cout << count; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-10; n const double PI = acos(-1.0); n template <class T> n T gcd(T a, T b) { n   for (T c; b; c = a, a = b, b = c % b) n     ; n   return a; n } n template <class T> n void out(const vector<T> &a) { n   for (int i = 0; i < ((int)(a).size()); ++i) cout << a[i] <<    ; n   cout << endl; n } n int countbit(int n) { return n == 0 ? 0 : 1 + countbit(n & (n - 1)); } n const int d8[8][2] = {{1, 0}, {-1, 0},  {0, 1},  {0, -1}, n                       {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}; n const int d4[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n inline long long cross(const complex<long long> &a, n                        const complex<long long> &b) { n   return (conj(a) * b).imag(); n } n inline long long cross(const complex<long long> &a, const complex<long long> &b, n                        const complex<long long> &c) { n   return cross(b - a, c - a); n } n inline long long dot(const complex<long long> &a, const complex<long long> &b) { n   return (conj(a) * b).real(); n } n inline bool which_part(const complex<long long> &p) { n   return p.imag() > 0 || p.imag() == 0 && p.real() > 0; n } n namespace std { n bool operator<(const complex<long long> &a, const complex<long long> &b) { n   int flag_a = which_part(a); n   int flag_b = which_part(b); n   if (flag_a != flag_b) return flag_a < flag_b; n   return cross(a, b) > 0; n } n }  // namespace std n struct node { n   complex<long long> p; n   int color; n }; n struct cmp { n   complex<long long> p; n   cmp(const complex<long long> &p) : p(p) {} n   bool operator()(const node &a, const node &b) { return a.p - p < b.p - p; } n }; n node a[1000], b[2000]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; ++i) { n     long long x, y; n     scanf( %I64d %I64d , &x, &y); n     a[i].p = complex<long long>(x, y); n     a[i].color = 0; n   } n   for (int i = 0; i < m; ++i) { n     long long x, y; n     scanf( %I64d %I64d , &x, &y); n     a[n + i].p = complex<long long>(x, y); n     a[n + i].color = 1; n   } n   long long ret = 0; n   for (int i = 0; i < n; ++i) { n     int L = 0; n     for (int j = i + 1; j < n + m; ++j) { n       if (j == i) continue; n       b[L++] = a[j]; n     } n     sort(b, b + L, cmp(a[i].p)); n     for (int j = 0; j < L; ++j) b[L + j] = b[j]; n     int u; n     for (u = 1; cross(a[i].p, b[0].p, b[u].p) > 0; ++u) n       ; n     for (int j = 0; j < L; ++j) { n       if (b[j].color == 1) continue; n       bool found = false; n       complex<long long> p; n       for (u = max(u, j + 1); cross(a[i].p, b[j].p, b[u].p) > 0; ++u) n         ; n       for (int k = j + 1; k != u; ++k) { n         if (b[k].color == 1) { n           if (!found || cross(b[j].p, p, b[k].p) > 0) { n             found = true; n             p = b[k].p; n           } n         } else { n           if (!found || cross(b[j].p, p, b[k].p) > 0) { n             ++ret; n           } n         } n       } n     } n   } n   printf( %I64d n , ret); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   int v = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n inline void read(long long &x) { n   long long v = 0ll, f = 1ll; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n inline void readc(char &x) { n   char c; n   while ((c = getchar()) ==    ) n     ; n   x = c; n } n inline void writes(string s) { puts(s.c_str()); } n inline void writeln() { writes(  ); } n inline void writei(int x) { n   if (x < 0) { n     putchar( - ); n     x = abs(x); n   } n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n inline void writell(long long x) { n   if (x < 0) { n     putchar( - ); n     x = abs(x); n   } n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n int n, m, i, j, v, dis[505], cnt, cst, vis[505]; n string st, s; n struct edg { n   int y, z, d; n } ee[18005]; n vector<int> e[505]; n void add(int x, int y, int z, int d) { n   cnt++; n   e[x].push_back(cnt * 2 - 2); n   e[y].push_back(cnt * 2 - 1); n   ee[cnt * 2 - 2] = (edg){y, z, d}; n   ee[cnt * 2 - 1] = (edg){x, 0, -d}; n } n bool bfs(int s, int t) { n   memset(dis, -18, sizeof(dis)); n   dis[s] = 0; n   queue<int> q; n   q.push(s); n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); n          it++) { n       if (ee[*it].z == 0) continue; n       int y = ee[*it].y, z = dis[x] + ee[*it].d; n       if (dis[y] < z) { n         dis[y] = z; n         q.push(y); n       } n     } n   } n   return dis[t] > dis[504]; n } n int dfs(int x, int t, int flw) { n   if (!flw || (x != t && vis[x])) return 0; n   if (x == t) { n     vis[x] = 1; n     return flw; n   } n   vis[x] = 1; n   int ans = 0; n   for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) { n     if (ee[*it].z == 0) continue; n     int y = ee[*it].y; n     if (dis[y] == dis[x] + ee[*it].d) { n       int tt = dfs(y, t, min(flw, ee[*it].z)); n       ans += tt; n       flw -= tt; n       ee[*it].z -= tt; n       ee[(*it) ^ 1].z += tt; n       cst += tt * ee[*it].d; n     } n   } n   return ans; n } n int dinic(int s, int t) { n   int ans = 0; n   while (bfs(s, t)) { n     do { n       memset(vis, 0, sizeof(vis)); n       ans += dfs(s, t, 0x3bbbbbbb); n     } while (vis[t]); n   } n   return cst; n } n int main() { n   ios_base::sync_with_stdio(false); n   ; n   cin >> n >> st >> m; n   st =     + st; n   for (((i)) = (1); ((i)) <= ((n)); ((i))++) add(i, i + 1, 0x3bbbbbbb, 0); n   while (m--) { n     cin >> s >> v; n     for (((i)) = (1); ((i)) <= ((n - ((int)(s.length())) + 1)); ((i))++) { n       if (st.substr(i, s.length()) == s) { n         add(i, i + s.length(), 1, v); n       } n     } n   } n   cin >> v; n   add(0, 1, v, 0); n   cout << dinic(0, n + 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2 * 1e5 + 100; n long long n, m, k, w, a[N], d[N], p[N], fa[N], vi[N]; n long long tot, first[N], nxt[N * 2], point[N * 2], len[N * 2]; n priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, n                greater<pair<long long, long long> > > n     q; n struct node { n   long long u, v, w; n } sh[N]; n bool cmp(node a, node b) { return a.w < b.w; } n long long find(long long x) { n   return (x == fa[x]) ? fa[x] : fa[x] = find(fa[x]); n } n inline long long read() { n   long long f = 1, x = 0; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = x * 10 + s -  0 ; n     s = getchar(); n   } n   return x * f; n } n inline void add_edge(long long x, long long y, long long z) { n   nxt[++tot] = first[x]; n   first[x] = tot; n   point[tot] = y; n   len[tot] = z; n } n inline bool merge(long long a, long long b) { n   long long fax = find(a), fay = find(b); n   if (fax == fay) return 0; n   fa[fax] = fay; n   return 1; n } n signed main() { n   tot = -1; n   memset(first, -1, sizeof(first)); n   n = read(); n   m = read(); n   for (long long i = 1; i <= m; i++) { n     long long u = read(), v = read(), w = read(); n     add_edge(u, v, w); n     add_edge(v, u, w); n   } n   k = read(); n   for (long long i = 1; i <= k; i++) a[i] = read(); n   for (long long i = 1; i <= n; i++) d[i] = 1e18; n   for (long long i = 1; i <= k; i++) n     p[a[i]] = a[i], d[a[i]] = 0, q.push(make_pair(0, a[i])); n   while (!q.empty()) { n     long long x = q.top().second; n     q.pop(); n     if (vi[x]) continue; n     vi[x] = 1; n     for (long long i = first[x]; i != -1; i = nxt[i]) { n       long long u = point[i]; n       if (d[u] > d[x] + len[i]) { n         d[u] = d[x] + len[i]; n         p[u] = p[x]; n         q.push(make_pair(d[u], u)); n       } n     } n   } n   for (long long i = 0; i <= tot; i += 2) { n     long long u = point[i], v = point[i ^ 1]; n     if (p[u] == p[v]) continue; n     sh[++w] = (node){p[u], p[v], d[u] + d[v] + len[i]}; n   } n   sort(sh + 1, sh + 1 + w, cmp); n   for (long long i = 1; i <= n; i++) fa[i] = i; n   long long ans = d[1]; n   for (long long i = 1; i <= w; i++) n     if (merge(sh[i].u, sh[i].v)) ans += sh[i].w; n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n char input[5001]; n int data[1000]; n using namespace std; n int main() { n   int r = 0; n   stack<int> s; n   char temp[10]; n   int b = 0, p, count; n   while (scanf( %s , input) != EOF) { n     for (int i = 0; i < strlen(input); i++) { n       if (input[i] ==  < ) { n         count = 0; n         i++; n         while (i < strlen(input) && input[i] !=  > ) { n           temp[count++] = input[i++]; n         } n       } n       if (i < strlen(input) && input[i] ==  > ) { n         temp[count] =   0 ; n         fflush(0); n         if (strcmp(temp,  table ) == 0) { n           b = 0; n           s.push(b); n         } else if (strcmp(temp,  td ) == 0) { n           p = s.top(); n           p++; n           s.pop(); n           s.push(p); n         } else if (strcmp(temp,  /table ) == 0) { n           data[r++] = s.top(); n           s.pop(); n         } n       } else if (i < strlen(input) && input[i] !=  < ) n         temp[count++] = input[i]; n     } n   } n   sort(data, data + r); n   for (int k = 0; k < r; k++) printf( %d  , data[k]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() {} n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   long long k = 1; n   vector<long long> v; n   while (1) { n     long long tmp = ((1 << k) - 1) * (1 << (k - 1)); n     if (tmp > 100001) break; n     v.push_back(tmp); n     k++; n   } n   while (t--) { n     long long n; n     cin >> n; n     for (int i = (int)v.size() - 1; i > -1; i--) { n       if (n % v[i] == 0) { n         cout << v[i] <<   n ; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int abs(int x) { return x >= 0 ? x : -x; } n int main() { n   int n; n   cin >> n; n   while (n--) { n     vector<int> x; n     vector<int> y; n     char tmp; n     for (int i = 0; i < 8; i++) { n       for (int j = 0; j < 8; j++) { n         cin >> tmp; n         if (tmp ==  K ) { n           x.push_back(i); n           y.push_back(j); n         } n       } n     } n     int tx, ty; n     tx = abs(x[0] - x[1]); n     ty = abs(y[0] - y[1]); n     if ((tx % 4 == 0) && (ty % 4 == 0) && ((tx + ty) % 4 == 0)) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int n, i, j, k, mx = 0, sum = 0, vis[5005], letter[26], check[26][5005][26], ok; n double ans = 0; n int main() { n   cin >> s; n   n = s.length(); n   s = s + s; n   for (i = 0; i < n; i++) { n     letter[s[i] -  a ]++; n     for (j = i; j < i + n; j++) { n       check[s[i] -  a ][j - i + 1][s[j] -  a ]++; n     } n   } n   for (i = 0; i < 26; i++) { n     if (!letter[i]) continue; n     mx = -1; n     for (j = 2; j <= n; j++) { n       sum = 0; n       for (k = 0; k < 26; k++) n         if (check[i][j][k] == 1) sum += 1; n       mx = max(mx, sum); n     } n     ans += 1.0 * mx / n; n   } n   printf( %lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<pair<int, int>> sms; n   int time1, amount1; n   for (int i = 0; i < n; i++) { n     cin >> time1 >> amount1; n     sms.push_back(make_pair(time1, amount1)); n   } n   int time = 0; n   int amount = 0; n   int maxamount = 0; n   for (int i = 0; i < n; i++) { n     if (amount <= sms[i].first - time) { n       time = sms[i].first; n       amount = sms[i].second; n     } else { n       amount -= sms[i].first - time; n       time += sms[i].first - time; n       amount += sms[i].second; n     } n     if (amount > maxamount) maxamount = amount; n   } n   if (amount) { n     if (amount > maxamount) maxamount = amount; n     time += amount; n   } n   cout << time <<     << maxamount << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n int n, t, cc, flag[maxn], a[maxn]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   if (n == 1) { n     cout <<  +  << endl; n     return 0; n   } n   for (int i = 1; i <= n; i++) flag[i] = 1; n   flag[n] = -1; n   flag[n - 1] = -1; n   t = a[n] - a[n - 1]; n   for (int i = n - 2; i >= 1; i--) { n     if (t >= a[i]) { n       t = t - a[i]; n       flag[i + 1] *= -1; n       flag[i] *= -1; n     } else { n       t = a[i] - t; n       flag[i + 1] *= -1; n     } n   } n   cc = 1; n   for (int i = 1; i <= n; i++) { n     cc *= flag[i]; n     if (cc < 0) n       cout <<  - ; n     else n       cout <<  + ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double revs, a, b, c, d, C, totdist; n const double pi = atan(1) * 4; n int n, r, v, s, f; n double distcovered(double t) { return max(r * (t + sin(t)), r * (t - sin(t))); } n int main() { n   cout << fixed << setprecision(8); n   cin >> n >> r >> v; n   for (int c = 0; c < n; c++) { n     scanf( %d%d , &s, &f); n     a = f - s; n     a = a / 2; n     double up, low; n     low = 0; n     up = a / r + 2 * pi; n     for (int c = 0; c < 100; c++) { n       double mid = (low + up) / 2; n       b = distcovered(mid); n       if (b == a) n         break; n       else if (b > a) n         up = mid; n       else n         low = mid; n     } n     double mid = (low + up) / 2; n     double speed = (double)v / r; n     double time = mid / speed * 2; n     printf( %.8f n , time); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e15; n const int MOD = 1e9 + 7; n const double EPS = 1e-7; n const double PI = acos(-1.0); n const int N = 3e5 + 5; n long long n, a[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   long long ans = 0, left = 0; n   for (int i = 0; i < n; ++i) { n     if (i) { n       ans += min(a[i] / 2, left); n       long long tmp = left; n       left -= min(a[i] / 2, left); n       a[i] -= min(a[i] / 2 * 2, tmp * 2); n     } n     ans += a[i] / 3; n     a[i] -= a[i] / 3 * 3; n     left += a[i]; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n void make(vector<pair<int, int> > &a, long long int b) { n   int last = 0; n   int n = a.size(); n   for (int i = 0; i < a.size() - 1; i++) { n     if (b >= pow(2, n - 2 - i)) { n       a[i].first = n - last; n       last++; n       b = b - pow(2, n - 2 - i); n     } else { n       a[i].first = i + 1 - last; n     } n   } n   a[n - 1].first = n - last; n } n int main() { n   long long int n, b; n   cin >> n >> b; n   vector<pair<int, int> > a; n   for (int i = 0; i < n; i++) { n     a.push_back(make_pair(0, i + 1)); n   } n   make(a, b - 1); n   sort(a.begin(), a.end()); n   for (int i = 0; i < n; i++) cout << a[i].second <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int MAX = 1000005; n int n, k; n int st1[MAX][20]; n int st2[MAX][20]; n int v[MAX]; n int c[MAX]; n int ans[MAX]; n double factor[MAX]; n int log(int x) { n   int ct = 0; n   int k = 1; n   while (k <= x) { n     k *= 2; n     ct++; n   } n   return ct - 1; n } n int pow2(int x) { n   int ans = 1; n   for (int i = 0; i < x; i++) { n     ans *= 2; n   } n   return ans; n } n void process2() { n   for (int j = 1; (1 << j) <= n; j++) { n     for (int i = 1; i + (1 << j) - 1 <= n; i++) { n       if (st2[i][j - 1] < st2[i + (1 << (j - 1))][j - 1]) { n         st2[i][j] = st2[i][j - 1]; n       } else { n         st2[i][j] = st2[i + (1 << (j - 1))][j - 1]; n       } n     } n   } n } n int rmq2(int i, int j) { n   int k = log(j - i + 1); n   if (st2[i][k] <= st2[j - pow2(k) + 1][k]) { n     return st2[i][k]; n   } n   return st2[j - pow2(k) + 1][k]; n } n void process1() { n   for (int j = 1; (1 << j) <= n; j++) { n     for (int i = 1; i + (1 << j) - 1 <= n; i++) { n       if (st1[i][j - 1] > st1[i + (1 << (j - 1))][j - 1]) { n         st1[i][j] = st1[i][j - 1]; n       } else { n         st1[i][j] = st1[i + (1 << (j - 1))][j - 1]; n       } n     } n   } n } n int rmq1(int i, int j) { n   int k = log(j - i + 1); n   if (st1[i][k] >= st1[j - pow2(k) + 1][k]) { n     return st1[i][k]; n   } n   return st1[j - pow2(k) + 1][k]; n } n int first(int l, int r) { return 100 * rmq1(l, r); } n int g(int l, int r) { return rmq2(l, r); } n int p(int l, int r) { return min(g(l, r), first(l, r)); } n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , &v[i + 1]); n     st1[i + 1][0] = v[i + 1]; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &c[i + 1]); n     st2[i + 1][0] = c[i + 1]; n   } n   process1(); n   process2(); n   factor[1] = (k + 0.0) / n; n   for (int i = 2; i < n + 1; i++) { n     factor[i] = factor[i - 1] * (0.0 + n - k - (i - 2)) / (n - i + 1); n   } n   for (int l = 1; l < n + 1; l++) { n     int lo = l; n     int hi = n; n     while (lo < hi) { n       int mid = (lo + hi) / 2; n       if (first(l, mid) == g(l, mid)) { n         lo = mid; n         ans[l] = first(l, mid); n         break; n       } n       if (first(l, mid) < g(l, mid)) { n         lo = mid + 1; n       } else { n         hi = mid; n       } n     } n     if (ans[l] == 0) { n       ans[l] = p(l, lo); n       if (l <= lo - 1) { n         ans[l] = max(ans[l], p(l, lo - 1)); n       } n     } n   } n   sort(ans + 1, ans + n + 1); n   double fin = 0; n   for (int i = 1; i < n + 1; i++) { n     fin += ans[i] * factor[i]; n   } n   printf( %.10f n , fin); n } n


#include <bits/stdc++.h> n using namespace std; n void fast_in_out() { n   std::ios_base::sync_with_stdio(NULL); n   cin.tie(NULL); n   cout.tie(NULL); n } n int main() { n   fast_in_out(); n   int n, x, y, c = 0; n   cin >> n; n   for (int(i) = 0; (i) < (n); ++(i)) { n     cin >> x >> y; n     if (y >= x + 2) c++; n   } n   cout << c << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n const int mxn = 1e5 * 4 + 10, mod = 1e9 + 7; n using namespace std; n long long phi(long long n); n long long gcd(long long a, long long b); n long long lcm(long long a, long long b); n long long n, m, t = 0, l, k, a, tmp, d; n int mn = 1e9, mx = -1; n int main() { n   cin >> n >> t >> k >> d; n   long long ao, bo, c, g; n   c = (n + k - 1) / k; n   ao = c * t; n   c -= d / t; n   g = d / t * t; n   c -= (d - g) / t; n   g += (d - g) / t * t; n   if (c % 2) { n     g += (c / 2 + 1) * t; n     d += (c / 2) * t; n   } else { n     g += (c / 2) * t; n     d += (c / 2) * t; n   } n   bo = max(d, g); n   cout << ((ao > bo) ?  YES  :  NO ); n } n long long phi(long long n) { n   long long res = n, i = 2; n   for (; i * i <= n; i++) n     if (n % i == 0) { n       while (n % i == 0) n = n / i; n       res -= res / i; n     } n   if (n > 1) res -= res / n; n   return res; n } n long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n


#include <bits/stdc++.h> n using namespace std; n int x[10007], y[10007]; n int n, w, v, u; n int main() { n   cin >> n >> w >> v >> u; n   double maxer = -1; n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n   } n   double lim = u * 1.0 / v; n   bool flag1 = false; n   bool flag2 = false; n   for (int i = 0; i < n; i++) { n     if (y[i] * 1.0 / x[i] > lim || y[i] * 1.0 / x[i] < 0) { n       flag1 = true; n     } n     if (y[i] * 1.0 / x[i] < lim) { n       flag2 = true; n     } n     double tmp = x[i] * 1.0 / v + (w - y[i]) * 1.0 / u; n     maxer = max(maxer, tmp); n   } n   if (flag1 == false || flag2 == false) { n     printf( %.10f n , w * 1.0 / u); n     return 0; n   } n   printf( %.10f n , maxer); n } n


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


#include <bits/stdc++.h> n using namespace std; n long long int cnt[22]; n int main() { n   int n; n   cin >> n; n   int a; n   for (int i = 0; i < n; i++) { n     cin >> a; n     cnt[a + 10]++; n   } n   long long int ans = cnt[10] * (cnt[10] - 1) / 2; n   for (int i = 1; i <= 10; i++) ans += cnt[-i + 10] * cnt[i + 10]; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10, size = 1 << 20, mod = 998244353; n template <class o> n void qr(o &x) { n   char c = getchar(); n   x = 0; n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n   x *= f; n } n template <class o> n void qw(o x) { n   if (x / 10) qw(x / 10); n   putchar(x % 10 +  0 ); n } n template <class o> n void pr1(o x) { n   if (x < 0) x = -x, putchar( - ); n   qw(x); n   putchar(   ); n } n template <class o> n void pr2(o x) { n   if (x < 0) x = -x, putchar( - ); n   qw(x); n   puts(  ); n } n long long mult(long long a, long long b, long long p) { n   a = (a % p + p) % p; n   b = (b % p + p) % p; n   long long c = (long double)a * b / p; n   return a * b - c * p; n } n long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n long long power(long long a, long long b = mod - 2) { n   long long c = 1; n   while (b) { n     if (b & 1) c = c * a % mod; n     b /= 2; n     a = a * a % mod; n   } n   return c; n } n long long Power(long long a, long long b = mod - 2) { n   long long c = 1; n   while (b) { n     if (b & 1) c = mult(c, a, mod); n     b /= 2; n     a = mult(a, a, mod); n   } n   return c; n } n int n; n long long inv, a[N]; n int main() { n   qr(n); n   inv = power(n); n   for (int i = 1; i <= n; i++) qr(a[i]); n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) (a[i] += a[i - 1]) %= mod; n   for (int i = 1; i <= n; i++) { n     int pos = n - i, t = 1; n     long long ans = 0; n     while (pos >= i) { n       ans += (a[pos] - a[pos - i] + mod) * t++ % mod; n       pos -= i; n     } n     (ans += a[pos] * t) %= mod; n     pr1(ans * inv % mod); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   while (n--) { n     int a; n     cin >> a; n     string s; n     cin >> s; n     set<char> st; n     for (int i = 0; i < s.size(); i++) { n       st.insert(s[i]); n     } n     if (st.size() == 1) { n       cout << -1 <<     << -1 << endl; n     } else { n       for (int i = 0; i < s.size(); i++) { n         if (s[i] ==  a  && s[i + 1] ==  b ) { n           cout << i + 1 <<     << i + 2 << endl; n           break; n         } n         if (s[i] ==  b  && s[i + 1] ==  a ) { n           cout << i + 1 <<     << i + 2 << endl; n           break; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int MOD = 998244353; n   long long int n; n   cin >> n; n   pair<long long int, long long int> arr[n]; n   for (long long int i = 0; i < n; ++i) cin >> arr[i].first >> arr[i].second; n   long long int fact[n + 1]; n   fact[0] = 1; n   for (long long int i = 1; i <= n; ++i) { n     fact[i] = (fact[i - 1] * i + MOD) % MOD; n   } n   map<long long int, long long int> count1; n   map<long long int, long long int> count2; n   map<pair<long long int, long long int>, long long int> count3; n   for (long long int i = 0; i < n; ++i) { n     count1[arr[i].first]++; n     count2[arr[i].second]++; n     count3[make_pair(arr[i].first, arr[i].second)]++; n   } n   long long int n1 = 1, n2 = 1, n3 = 1; n   map<long long int, long long int>::iterator it; n   for (it = count1.begin(); it != count1.end(); ++it) { n     n1 = (n1 * (fact[it->second]) + MOD) % MOD; n   } n   for (it = count2.begin(); it != count2.end(); ++it) { n     n2 = (n2 * (fact[it->second]) + MOD) % MOD; n   } n   map<pair<long long int, long long int>, long long int>::iterator itd; n   long long int last2 = -1; n   for (itd = count3.begin(); itd != count3.end(); ++itd) { n     n3 = (n3 * (fact[itd->second]) + MOD) % MOD; n     if (itd->first.second < last2) { n       n3 = 0; n       break; n     } n     last2 = itd->first.second; n   } n   long long int ans = (fact[n] - n1 - n2 + n3 + 2 * MOD) % MOD; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long h, w; n   cin >> h >> w; n   long long pow2max = 1; n   while (2 * pow2max <= h && 2 * pow2max <= w) pow2max *= 2; n   long long hmax = min(h, (long long)(1.25 * pow2max)); n   long long wmax = min(w, (long long)(1.25 * pow2max)); n   if (hmax >= wmax) n     cout << hmax <<     << pow2max; n   else n     cout << pow2max <<     << wmax; n   return; n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long i, n, d = 0; n   scanf( %ld , &n); n   for (i = 1; i <= n / 2; i++) { n     if (n % i == 0) d++; n   } n   printf( %d , d); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long Ax, Ay, Bx, By, Cx, Cy; n bool solvable(long long A, long long B) { n   return (Cx * A + Cy * B) % (Cx * Cx + Cy * Cy) == 0 && n          (-Cy * A + Cx * B) % (Cx * Cx + Cy * Cy) == 0; n } n bool possible() { n   cin >> Ax >> Ay >> Bx >> By >> Cx >> Cy; n   if (Cx == 0 && Cy == 0) { n     if (Bx == Ax && By == Ay) return true; n     if (Bx == Ay && By == -Ax) return true; n     if (Bx == -Ax && By == -Ay) return true; n     if (Bx == -Ay && By == Ax) return true; n     return false; n   } n   if (solvable(Bx - Ax, By - Ay)) return true; n   if (solvable(Bx - Ay, By + Ax)) return true; n   if (solvable(Bx + Ax, By + Ay)) return true; n   if (solvable(Bx + Ay, By - Ax)) return true; n   return false; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout << (possible() ?  YES  :  NO ) << endl; n   cout << flush; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool a[1000][1000]; n int main() { n   ios::sync_with_stdio(false); n   int n, m, ans = 0; n   cin >> n >> m; n   bool tmp = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     tmp = 0; n     for (int j = 0; j < m; j++) { n       tmp = max(tmp, a[i][j]); n       if (a[i][j] == 0 && tmp) ans++; n     } n   } n   for (int i = 0; i < m; i++) { n     tmp = 0; n     for (int j = 0; j < n; j++) { n       tmp = max(tmp, a[j][i]); n       if (a[j][i] == 0 && tmp) ans++; n     } n   } n   for (int i = 0; i < n; i++) { n     tmp = 0; n     for (int j = m - 1; j >= 0; j--) { n       tmp = max(tmp, a[i][j]); n       if (a[i][j] == 0 && tmp) ans++; n     } n   } n   for (int i = 0; i < m; i++) { n     tmp = 0; n     for (int j = n - 1; j >= 0; j--) { n       tmp = max(tmp, a[j][i]); n       if (a[j][i] == 0 && tmp) ans++; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n char s[6][8], t[10]; n int n; n bool match(char* a, char* b) { n   for (int i = 0; i < 7; i++) n     if (b[i] !=  .  && a[i] != b[i]) return 0; n   return 1; n } n int main() { n   sprintf(s[0],  jolteon ); n   sprintf(s[1],  flareon ); n   sprintf(s[2],  umbreon ); n   sprintf(s[3],  leafeon ); n   sprintf(s[4],  glaceon ); n   sprintf(s[5],  sylveon ); n   scanf( %d%s , &n, t); n   if (n == 6) return 0 * printf( espeon n ); n   if (n == 8) return 0 * printf( vaporeon n ); n   for (int i = 0; i < 6; i++) n     if (match(s[i], t)) return 0 * printf( %s n , s[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s, v; n int ans, p, t; n char c; n char tr[1000]; n int mypow(int k) { n   int c = 1; n   for (int i = 1; i <= k; i++) { n     c *= 2; n   } n   return c; n } n int main() { n   gets(tr); n   s = (string)tr; n   p = 0; n   for (int i = 0; i < s.length(); i++) { n     v =   ; n     c = s[i]; n     int k = 7; n     ans = 0; n     while ((c > 0) && (k >= 0)) { n       if (c % 2 == 1) ans += mypow(k); n       k--; n       c /= 2; n     } n     t = (p - ans) % 256; n     if (t < 0) t += 256; n     cout << t << endl; n     p = ans; n   } n   return 0; n } n