#include <bits/stdc++.h> n using namespace std; n int a[1006]; n int k; n int fun(int x) { n   int mid, high = k - 1, low = 0, i; n   while (high >= low) { n     mid = (low + high) >> 1; n     if (a[mid] < x) { n       low = mid + 1; n     } else if (a[mid] > x) { n       high = mid - 1; n     } else n       break; n   } n   if (a[mid] == x) return 999999999; n   if (a[mid] < x) { n     for (i = mid; a[i] <= x && i < k; ++i) n       if (a[i] == x) return 999999999; n     return i; n   } else { n     for (i = mid; a[i] >= x && i >= 0; --i) n       if (a[i] == x) return 999999999; n     return i + 1; n   } n } n int main() { n   int i, n, m, q, x, y; n   while (scanf( %d%d%d%d , &n, &m, &k, &q) != EOF) { n     for (i = 0; i < k; ++i) { n       scanf( %d%d , &x, &y); n       a[i] = (x - 1) * m + y; n     } n     sort(a, a + k); n     while (q--) { n       scanf( %d%d , &x, &y); n       i = fun((x - 1) * m + y); n       if (i == 999999999) n         puts( Waste ); n       else n         switch (((x - 1) * m + y - i - 1) % 3) { n           case 0: n             puts( Carrots ); n             break; n           case 1: n             puts( Kiwis ); n             break; n           case 2: n             puts( Grapes ); n             break; n         } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t 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 x, y, k; n     cin >> x >> y >> k; n     long long qtd = (((y + 1) * k - 1) + (x - 2)) / (x - 1); n     cout << qtd + k <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const int mod = 1e9 + 7; n const int maxm = 2e5 + 5; n const long long inf = 0x3f3f3f3f3f3f3f3f; n int xx[] = {0, 0, 1, -1}; n int yy[] = {1, -1, 0, 0}; n int N, M, K; n vector<pair<int, long long> > vec[maxn]; n vector<int> V; n vector<long long> S; n int vis[maxn]; n long long value[maxn]; n void dfs(int u, int p, long long s) { n   if (vis[u]) { n     S.push_back(value[u] ^ s); n     return; n   } n   vis[u] = 1; n   V.push_back(u); n   value[u] = s; n   for (int i = 0; i < vec[u].size(); i++) { n     int v = vec[u][i].first; n     long long w = vec[u][i].second; n     if (v == p) continue; n     dfs(v, u, s ^ w); n   } n } n long long ans; n void work() { n   int i2 = 0; n   long long A = 0; n   for (int j = 0; j < S.size(); j++) A |= S[j]; n   for (int i = 0; i < 60; i++) { n     int s = -1; n     for (int j = i2; j < S.size(); j++) { n       long long v = S[j]; n       if (v & (1ll << i)) { n         s = j; n       } n     } n     if (s == -1) continue; n     swap(S[i2], S[s]); n     for (int j = i2 + 1; j < S.size(); j++) { n       long long &v = S[j]; n       if (v & (1ll << i)) { n         v ^= S[i2]; n       } n     } n     i2++; n   } n   for (int i = 0; i < 60; i++) { n     if (A & (1ll << i)) { n       ans += (1ll << i) % mod * ((1ll << i2 - 1) % mod) % mod * n              (1ll * V.size() * (V.size() - 1) / 2 % mod); n       ans %= mod; n     } else { n       int X = 0, Y = 0; n       for (int j = 0; j < V.size(); j++) { n         int v = V[j]; n         if (value[v] & (1ll << i)) { n           X++; n         } else n           Y++; n       } n       ans += 1ll * X * Y % mod * ((1ll << i2) % mod) % mod * ((1ll << i) % mod); n       ans %= mod; n     } n   } n } n int main(int argc, char *argv[]) { n   if (argc > 1) { n     freopen(argv[1],  r , stdin); n   } n   cin >> N >> M; n   for (int i = 0; i < M; i++) { n     int a, b; n     long long c; n     scanf( %d%d%lld , &a, &b, &c); n     vec[b].push_back(make_pair(a, c)); n     vec[a].push_back(make_pair(b, c)); n   } n   for (int i = 1; i <= N; i++) { n     V.clear(); n     S.clear(); n     if (vis[i]) continue; n     dfs(i, 0, 0); n     work(); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n long long POW(long long m) { n   long long t = 1; n   for (long long k = 1; k <= m; k++) t *= 4; n   return t; n } n int main() { n   long long n; n   scanf( %I64d , &n); n   if (n == 3) { n     printf( 24 ); n     return 0; n   } n   long long ans = 4 * (3 * POW(n - 3) * 2 + 9 * POW(n - 4) * (n - 3)); n   printf( %I64d , ans); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n long long n, m, cnt[55], used[55], add[55]; n bool vis[55]; n vector<long long> v[55], p; n pair<long long, long long> it[55]; n long long fa[55]; n long long getfa(long long x) { n   if (x == fa[x]) n     return x; n   else n     return fa[x] = getfa(fa[x]); n } n void update(long long x, long long y) { n   x = getfa(x); n   y = getfa(y); n   fa[x] = y; n } n void dfs(long long x) { n   if (vis[x]) return; n   vis[x] = 1; n   p.emplace_back(x); n   for (auto u : v[x]) { n     dfs(u); n   } n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   long long x, y; n   for (long long i = 1; i <= m; i++) { n     cin >> x >> y; n     v[x].emplace_back(y); n     v[y].emplace_back(x); n   } n   long long cnt = 0; n   for (long long i = 1; i <= n; i++) n     if (!vis[i]) { n       p.clear(); n       dfs(i); n       long long lst = cnt; n       for (auto u : p) { n         if (v[u].size() > 2) { n           cout <<  NO ; n           return 0; n         } n         if (v[u].size() == 1) { n           if (cnt && it[cnt].second == 0) { n             it[cnt].second = u; n           } else { n             it[++cnt].first = u; n           } n         } n         if (v[u].empty()) { n           it[++cnt] = make_pair(u, u); n         } n       } n       if (lst == cnt) { n         if (p.size() == n) { n           cout <<  YES n0 ; n           return 0; n         } else { n           cout <<  NO ; n           return 0; n         } n       } n     } n   for (long long i = 1; i <= n; i++) fa[i] = i; n   for (long long i = 1; i <= cnt; i++) { n     if (it[i].first > it[i].second) swap(it[i].first, it[i].second); n     used[it[i].first]++; n     used[it[i].second]++; n     add[it[i].first] = add[it[i].second] = i; n   } n   sort(it + 1, it + cnt + 1); n   cout <<  YES n ; n   cout << cnt <<   n ; n   for (long long i = 1; i <= n; i++) { n     while (used[i]) { n       bool f = 1; n       for (long long j = i + 1; j <= n; j++) n         if (used[j]) { n           if (getfa(add[i]) != getfa(add[j])) { n             cout << i <<     << j <<   n ; n             update(add[i], add[j]); n             used[i]--; n             used[j]--; n             f = 0; n             break; n           } n         } n       if (f) break; n     } n   } n   for (long long i = 1; i <= n; i++) { n     while (used[i]) { n       cout << i <<    ; n       used[i]--; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010, INF = 0x3f3f3f3f; n int n, m, k; n struct books { n   int t, id; n   bool operator<(const books &w) const { return t < w.t; } n } A[N], B[N], C[N], D[N]; n int main() { n   cin >> n >> m >> k; n   int a = 0, b = 0, c = 0, d = 0; n   for (int i = 1; i <= n; i++) { n     int first, second, z; n     cin >> first >> second >> z; n     if (second && z) n       C[++c] = {first, i}; n     else if (second) n       A[++a] = {first, i}; n     else if (z) n       B[++b] = {first, i}; n     else n       D[++d] = {first, i}; n   } n   sort(A + 1, A + 1 + a); n   sort(B + 1, B + 1 + b); n   sort(C + 1, C + 1 + c); n   sort(D + 1, D + 1 + d); n   int ai = 0, bi = 0, ci = 0, di = 0; n   int ans = 0; n   while (ci < c && ci < k) ans += C[++ci].t; n   while (ai + ci < k && ai < a && bi < b) ans += A[++ai].t + B[++bi].t; n   if (ai + ci < k || ai + bi + ci > m) { n     puts( -1 ); n     return 0; n   } n   while (ai + bi + ci + di < m) { n     int op1, op2, op3, op4, op5, minv; n     op1 = op2 = op3 = op4 = op5 = INF; n     if (ci && ai < a && bi < b) op1 = A[ai + 1].t + B[bi + 1].t - C[ci].t; n     if (ai < a) op2 = A[ai + 1].t; n     if (bi < b) op3 = B[bi + 1].t; n     if (ci < c) op4 = C[ci + 1].t; n     if (di < d) op5 = D[di + 1].t; n     minv = min(min(min(min(op1, op2), op3), op4), op5); n     if (minv == INF) break; n     if (minv == op1) n       ai++, bi++, ci--; n     else if (minv == op2) n       ai++; n     else if (minv == op3) n       bi++; n     else if (minv == op4) n       ci++; n     else if (minv == op5) n       di++; n     ans += minv; n   } n   cout << ans << endl; n   for (int i = 1; i <= ai; i++) cout << A[i].id <<    ; n   for (int i = 1; i <= bi; i++) cout << B[i].id <<    ; n   for (int i = 1; i <= ci; i++) cout << C[i].id <<    ; n   for (int i = 1; i <= di; i++) cout << D[i].id <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e2 + 1; n int n, k, m, a, cnt[maxn], last[maxn], id[maxn], res[maxn]; n void Enter() { n   cin >> n >> k >> m >> a; n   for (int i = 1; i <= a; ++i) { n     int g; n     cin >> g; n     ++cnt[g]; n     last[g] = i; n   } n } n void Init() { n   for (int i = 1; i <= n; ++i) id[i] = i; n   sort(id + 1, id + n + 1, [](int i, int j) { n     return cnt[i] > cnt[j] || (cnt[i] == cnt[j] && last[i] < last[j]); n   }); n } n void Solve() { n   if (k == n) { n     for (int i = 1; i <= n; ++i) n       if (cnt[i] == 0) n         if (m == a) n           cout << 3 <<    ; n         else n           cout << 2 <<    ; n       else n         cout << 1 <<    ; n     return; n   } n   int s = 0; n   for (int i = 1; i <= k + 1; ++i) s += cnt[id[i]]; n   for (int t = 1; t <= k; ++t) { n     int i = id[t]; n     s -= cnt[i]; n     if (cnt[i] != 0) n       if ((cnt[i] + 1) * (k + 1 - t) - s <= m - a) n         res[i] = 2; n       else n         res[i] = 1; n     else if (m == a) n       res[i] = 3; n     else n       res[i] = 2; n   } n   for (int t = k + 1; t <= n; ++t) { n     int i = id[t]; n     if (cnt[i] + (m - a) <= cnt[id[k]]) n       res[i] = 3; n     else n       res[i] = 2; n   } n   for (int i = 1; i <= n; ++i) cout << res[i] <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   Enter(); n   Init(); n   Solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int S, C = 1; n   cin >> S; n   int *N = new int[S]; n   for (int i = 0; i < S; i++) cin >> N[i]; n   sort(N, N + S); n   for (int i = 0; i < S; i++) n     if (N[i] >= C) C++; n   cout << C; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long arr[n]; n   for (long long i = 0; i < n; i++) cin >> arr[i]; n   sort(arr, arr + n); n   long long cur = n - 1, mid = (n - 2) / 2, res = 0; n   for (long long i = mid; i >= 0; i--) n     if (arr[i] * 2 <= arr[cur]) { n       cur--; n       res++; n     } n   cout << n - res; n } n


#include <bits/stdc++.h> n using namespace std; n long long int nextAlice[7][7]; n long long int nextBob[7][7]; n long long int nodeNum[7][7]; n pair<long long int, long long int> curScore; n pair<long long int, long long int> cycScore; n pair<long long int, long long int> gameScore(long long int x, long long int y) { n   if (x == y) return make_pair(0, 0); n   if ((x == 3 && y == 2) || (x == 2 && y == 1) || (x == 1 && y == 3)) n     return make_pair(1, 0); n   if ((y == 3 && x == 2) || (y == 2 && x == 1) || (y == 1 && x == 3)) n     return make_pair(0, 1); n } n void addPair(pair<long long int, long long int> x) { n   curScore.first += x.first; n   curScore.second += x.second; n } n void addPairCyc(pair<long long int, long long int> x) { n   cycScore.first += x.first; n   cycScore.second += x.second; n } n int main() { n   long long int i, j, k, l, m, n, x, y, z, a, b, r, curnode, curAlice, curBob, n       tx, ty; n   scanf( %lld , &k); n   scanf( %lld , &a); n   scanf( %lld , &b); n   for (i = 1; i <= 3; i++) n     for (j = 1; j <= 3; j++) scanf( %lld , &nextAlice[i][j]); n   for (i = 1; i <= 3; i++) n     for (j = 1; j <= 3; j++) scanf( %lld , &nextBob[i][j]); n   curnode = 1; n   curAlice = a; n   curBob = b; n   while (nodeNum[curAlice][curBob] == 0) { n     x = curAlice; n     y = curBob; n     nodeNum[x][y] = curnode++; n     curAlice = nextAlice[x][y]; n     curBob = nextBob[x][y]; n   } n   x = curAlice; n   y = curBob; n   l = curnode - nodeNum[x][y]; n   i = 0; n   curAlice = a; n   curBob = b; n   while (!(curAlice == x && curBob == y)) { n     tx = curAlice; n     ty = curBob; n     i++; n     if (i > k) { n       printf( %lld %lld n , curScore.first, curScore.second); n       return 0; n     } n     addPair(gameScore(curAlice, curBob)); n     curAlice = nextAlice[tx][ty]; n     curBob = nextBob[tx][ty]; n   } n   k = k - i; n   bool flag = true; n   curAlice = x; n   curBob = y; n   while (flag || !(curAlice == x && curBob == y)) { n     flag = false; n     tx = curAlice; n     ty = curBob; n     addPairCyc(gameScore(curAlice, curBob)); n     curAlice = nextAlice[tx][ty]; n     curBob = nextBob[tx][ty]; n   } n   addPair(make_pair(k / l * cycScore.first, k / l * cycScore.second)); n   k = k % l; n   curAlice = x; n   curBob = y; n   while (k > 0) { n     tx = curAlice; n     ty = curBob; n     addPair(gameScore(curAlice, curBob)); n     curAlice = nextAlice[tx][ty]; n     curBob = nextBob[tx][ty]; n     k--; n   } n   printf( %lld %lld n , curScore.first, curScore.second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int last[444444], pr[444444], p[444444], pred[444444]; n string s[444444], t; n int ans, n, len; n void go(int v, int K) { n   int j = last[v]; n   while (j > 0) { n     int k = K, sz = s[j].length(); n     for (int q = 0; q < sz; q++) { n       while (k > 0 && s[j][q] != t[k]) k = pr[k]; n       if (s[j][q] == t[k]) k++; n       if (k == len) ans++; n     } n     go(j, k); n     j = pred[j]; n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) last[i] = 0; n   for (int i = 2; i <= n; i++) { n     cin >> p[i] >> s[i]; n     pred[i] = last[p[i]]; n     last[p[i]] = i; n   } n   cin >> t; n   len = t.length(); n   t = t +    ; n   pr[1] = 0; n   int k = 0; n   for (int i = 2; i <= len; i++) { n     while (k > 0 && t[i - 1] != t[k]) k = pr[k]; n     if (t[i - 1] == t[k]) k++; n     pr[i] = k; n   } n   ans = 0; n   go(1, 0); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ld = long double; n using vi = vector<int>; n using vll = vector<long long int>; n using vd = vector<double>; n using vvi = vector<vi>; n int ctoi(char c) { return c -  0 ; } n int slen(string s) { return s.length(); } n int vsize(vi a) { return (int)a.size(); } n int in() { n   int x; n   cin >> x; n   return x; n } n long long int n; n void kmin(long long int n, long long int m) { n   long long int val = n / m; n   n = n - (val * m); n   long long int val1 = (m - n) * (val - 1) * (val) / 2; n   long long int val2 = n * val * (val + 1) / 2; n   long long int val3 = val1 + val2; n   cout << val3 <<    ; n } n void kmax(long long int n, long long int m) { n   n = n - (m - 1); n   long long int val = n * (n - 1) / 2; n   cout << val; n   cout << endl; n } n const int M = 1000000; n long long int prime(long long int x) { n   for (long long int i = 2; i * i <= x; i++) { n     if (x % i == 0) return i; n   } n   return x; n } n vector<pair<long long int, long long int> > v; n set<long long int> s; n bool check(long long int x) { n   for (int i = 1; i < n; i++) { n     if (v[i].first % x != 0 && v[i].second % x != 0) { n       return 0; n     } n   } n   return 1; n } n void get_prime(long long int x) { n   if (x % 2 == 0) s.insert(2); n   while (x % 2 == 0) x = x / 2; n   for (int i = 3; i <= sqrt(x); i += 2) { n     if (x % i == 0) { n       s.insert(i); n       while (x % i == 0) x = x / i; n     } n   } n   if (x > 2) { n     s.insert(x); n   } n } n vll ar[1000000]; n set<long long int> cycle; n vll path; n bool vis[1000000]; n int isp(int x) { n   if (x < 2) return 0; n   for (int i = 2; i * i <= x; i++) n     if (x % i == 0) return 0; n   return 1; n } n void dfs(int n, int m, int x, int y, bool visited[105][105]) { n   if (x >= n || y >= m || x < 0 || y < 0 || visited[x][y]) return; n   visited[x][y] = true; n   cout << x + 1 <<     << y + 1 <<   n ; n   for (int i = 0; i < n; i++) dfs(n, m, i, y, visited); n   for (int i = 0; i < m; i++) dfs(n, m, x, i, visited); n } n void solve() { n   long long int n, m, ans; n   cin >> n >> m; n   if (n == m) { n     cout << 0; n     return; n   } n   long long int diff = (abs)(n - m); n   long long int i = 1; n   while (true) { n     ans = i * (i + 1) / 2; n     if (diff == ans) { n       ans = i; n       break; n     } n     if (diff < ans) { n       if (ans % 2 == diff % 2) { n         ans = i; n         break; n       } n     } n     i++; n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long long int t = 1; n   cin >> t; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 1e9 + 7; n const long long N = 60, K = 10000 + 5; n long long dp[K][N]; n long long prob[N][N]; n long long n, k; n long long inv[N]; n long long power(long long a, long long k) { n   if (k == 0) return 1; n   long long ans = power(a, k / 2); n   ans = (ans * ans) % M; n   if (k % 2) ans = (ans * a) % M; n   return ans; n } n void pre() { n   for (long long i = 1; i < N; i++) inv[i] = power(i, M - 2); n } n void calc(long long id, long long s) { n   memset(dp, 0, sizeof dp); n   dp[0][s] = 1; n   for (long long i = 1; i <= k; i++) n     for (long long cur = 0; cur <= s; cur++) n       for (long long prev = cur; prev <= s; prev++) n         dp[i][cur] = (dp[i][cur] + dp[i - 1][prev] * inv[prev + 1]) % M; n   for (long long i = 0; i <= s; i++) { n     prob[id][i] = dp[k][i]; n   } n } n vector<pair<long long, long long> > vec; n bool next(vector<long long> &cur) { n   for (long long i = 0; i < vec.size(); i++) { n     if (cur[i] < vec[i].second) { n       cur[i]++; n       return true; n     } n     cur[i] = 0; n   } n   return false; n } n int main() { n   pre(); n   cin >> n >> k; n   long long id = 0; n   for (long long i = 2; i * i <= n; i++) { n     if (n % i) continue; n     long long cnt = 0; n     while (n % i == 0) n /= i, ++cnt; n     vec.push_back({i, cnt}); n     calc(id, cnt); n     ++id; n   } n   if (n > 1) { n     vec.push_back({n, 1}); n     calc(id, 1); n     ++id; n   } n   vector<long long> cur(id, 0); n   long long ans = 0; n   do { n     long long val = 1; n     for (long long i = 0; i < id; i++) { n       for (long long j = 0; j < cur[i]; j++) val *= vec[i].first; n     } n     val %= M; n     long long pr = 1; n     for (long long i = 0; i < id; i++) pr = (pr * prob[i][cur[i]]) % M; n     ans = (ans + pr * val) % M; n   } while (next(cur)); n   ans = (ans + M) % M; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, d, e; n   cin >> n >> d >> e; n   long long a = n, b = n, i; n   e = 5 * e; n   for (i = 0; e * i <= n; i++) { n     a = min(a, (n - (e * i)) % d); n   } n   for (i = 0; d * i <= n; i++) { n     b = min(b, (n - (d * i)) % e); n   } n   cout << min(a, b); n } n


#include <bits/stdc++.h> n using namespace std; n int F[1024]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   int n; n   cin >> n; n   char a; n   int b; n   for (int mask = 0; mask < (1 << 10); mask++) { n     F[mask] = mask; n   } n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     for (int mask = 0; mask < (1 << 10); mask++) { n       if (a ==  | ) n         F[mask] = (F[mask] | b); n       else if (a ==  ^ ) n         F[mask] = (F[mask] ^ b); n       else n         F[mask] = (F[mask] & b); n     } n   } n   for (int i = 0; i < (1 << 10); i++) { n     for (int j = 0; j < (1 << 10); j++) { n       set<int> S; n       for (int mask = 0; mask < (1 << 10); mask++) { n         int val = mask; n         val = (val | i); n         val = (val & j); n         S.insert((val ^ F[mask])); n       } n       if (S.size() == 1) { n         cout << 3 <<   n ; n         cout <<  |   << i <<   n ; n         cout <<  &   << j <<   n ; n         cout <<  ^   << (*S.begin()) <<   n ; n         return 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long w, h, k, ans = 0; n   cin >> w >> h >> k; n   for (long long i = h, j = w; i > 0, j > 0, k > 0; i -= 4, j -= 4) { n     ans += 2 * i + 2 * j; n     ans -= 4; n     k--; n   } n   cout << ans << endl; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long double t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   int t; n   std::cin >> t; n   while (t--) { n     int n; n     std::cin >> n; n     std::string res(n,  a ); n     if (n == 1) n       0; n     else if (n % 2) { n       res[(n - 3) / 2] =  b ; n       res[n - 1] =  c ; n     } else { n       res[n / 2 - 1] =  b ; n     } n     std::cout << res <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int XI = INT_MAX, NI = INT_MIN, MOD = 1e9 + 7; n string s; n int a[400]; n int main() { n   cin >> s; n   for (int i = 0; i < 26; i++) { n     a[s[i]]++; n   } n   for (int i = 25; i < s.length(); i++) { n     bool k = 1; n     int cnt = 0; n     string second =   ; n     for (int j =  A ; j <=  Z ; j++) { n       if (a[j] > 1) { n         k = 0; n         break; n       } n       if (a[j] == 0) { n         cnt++; n         second += (char)j; n       } n     } n     if (cnt != a[ ? ]) k = 0; n     if (k) { n       int y = 0; n       for (int x = 0; x < i - 25; x++) { n         if (s[x] !=  ? ) n           cout << s[x]; n         else n           cout <<  A ; n       } n       for (int x = i - 25; x < i + 1; x++) { n         if (s[x] !=  ? ) n           cout << s[x]; n         else { n           cout << second[y]; n           y++; n         } n       } n       for (int x = i + 1; x < s.length(); x++) { n         if (s[x] !=  ? ) n           cout << s[x]; n         else n           cout <<  A ; n       } n       cout << endl; n       return 0; n     } n     if (i + 1 == s.size()) break; n     a[s[i + 1]]++; n     a[s[i - 25]]--; n   } n   cout << -1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2000 + 10, inf = 1000000000; n int n, k, com[maxn], mn[maxn][maxn], dp[2 * maxn][maxn], ind[maxn][maxn], u = 1; n string s[maxn]; n void go(int l, int r) { n   if (l == r) return; n   ind[l][r] = u++; n   int pos = l; n   for (int i = l; i < r; i++) n     if (com[i] < com[pos]) pos = i; n   mn[l][r] = pos; n   go(l, pos); n   go(pos + 1, r); n } n void solve(int l, int r) { n   if (l == r) return; n   int id = ind[l][r]; n   int pos = mn[l][r]; n   solve(l, pos); n   solve(pos + 1, r); n   int id1 = ind[l][pos]; n   int id2 = ind[pos + 1][r]; n   for (int i = 0; i <= pos - l + 1; i++) n     for (int j = 0; j <= r - pos; j++) { n       dp[id][i + j] = n           max(dp[id][i + j], dp[id1][i] + dp[id2][j] + (j * i * com[pos])); n     } n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> s[i]; n   sort(s + 1, s + 1 + n); n   for (int i = 2; i <= n; i++) { n     int t = 0; n     for (int j = 0; j < min(s[i].size(), s[i - 1].size()); j++, t++) { n       if (s[i - 1][j] != s[i][j]) break; n     } n     com[i - 1] = t; n   } n   go(1, n); n   solve(1, n); n   cout << dp[1][k] << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long int t, sum, ar[32], n, c; n   for (int i = 0; i <= 31; i++) { n     ar[i] = pow(2, i); n   } n   scanf( %lld , &t); n   for (int i = 0; i < t; i++) { n     sum = 0, c = 0; n     scanf( %lld , &n); n     for (int i = 0; i < 31; i++) { n       if (ar[i] <= n) { n         c++; n       } n     } n     for (int i = 0; i < c; i++) { n       sum = sum + ar[i]; n     } n     long long int final = 0; n     final = ((n * (n + 1)) / 2) - (2 * sum); n     printf( %lld n , final); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n < 4) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES  << endl; n   if (n % 2 == 0) { n     for (int i = 6; i <= n; i += 2) { n       cout << i <<   -   << i - 1 <<   = 1  << endl; n     } n     cout <<  4 * 3 = 12  << endl; n     cout <<  2 * 1 = 2  << endl; n     cout <<  12 * 2 = 24  << endl; n     for (int i = 6; i <= n; i += 2) { n       cout <<  24 * 1 = 24  << endl; n     } n   } else { n     for (int i = 7; i <= n; i += 2) { n       cout << i <<   -   << i - 1 <<   = 1  << endl; n     } n     cout <<  5 - 2 = 3  << endl; n     cout <<  3 * 4 = 12  << endl; n     cout <<  3 - 1 = 2  << endl; n     cout <<  2 * 12 = 24  << endl; n     for (int i = 7; i <= n; i += 2) { n       cout <<  24 * 1 = 24  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100020; n const long long MOD = (int)1e9 + 7; n const int INF = 1e9; n const long long LLINF = 0x3f3f3f3f3f3f3f3f; n const long double EPS = 1e-7; n int logv[MAX + 1]; n void make_log() { n   logv[1] = 0; n   for (int i = 2; i <= MAX; i++) logv[i] = logv[i / 2] + 1; n } n struct Sparse { n   int n; n   vector<vector<int> > st; n   Sparse(vector<int>& v) { n     n = v.size(); n     int k = logv[n]; n     st.assign(n + 1, vector<int>(k + 1, 0)); n     for (int i = 0; i < (int)n; i++) { n       st[i][0] = v[i]; n     } n     for (int j = 1; j <= k; j++) { n       for (int i = 0; i + (1 << j) <= n; i++) { n         st[i][j] = f(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]); n       } n     } n   } n   int f(int a, int b) { return min(a, b); } n   int query(int l, int r) { n     int k = logv[r - l + 1]; n     return f(st[l][k], st[r - (1 << k) + 1][k]); n   } n }; n void radix_sort(vector<pair<int, int> >& rnk, vector<int>& ind) { n   auto counting_sort = [](vector<pair<int, int> >& rnk, vector<int>& ind) { n     int n = ind.size(), maxx = -1; n     for (auto p : rnk) maxx = max(maxx, p.first); n     vector<int> cnt(maxx + 1, 0), pos(maxx + 1), ind_new(n); n     for (auto p : rnk) cnt[p.first]++; n     pos[0] = 0; n     for (int i = 1; i <= maxx; i++) { n       pos[i] = pos[i - 1] + cnt[i - 1]; n     } n     for (auto idx : ind) { n       int val = rnk[idx].first; n       ind_new[pos[val]] = idx; n       pos[val]++; n     } n     swap(ind, ind_new); n   }; n   for (int i = 0; i < (int)rnk.size(); i++) swap(rnk[i].first, rnk[i].second); n   counting_sort(rnk, ind); n   for (int i = 0; i < (int)rnk.size(); i++) swap(rnk[i].first, rnk[i].second); n   counting_sort(rnk, ind); n } n vector<int> suffix_array(string s) { n   int n = s.size(); n   vector<pair<int, int> > rnk(n, make_pair(0, 0)); n   vector<int> ind(n); n   for (int i = 0; i < (int)n; i++) { n     rnk[i].first = (s[i] ==  $ ) ? 0 : s[i] -  a  + 1; n     ind[i] = i; n   } n   for (int k = 1; k <= n; k = (k << 1)) { n     for (int i = 0; i < n; i++) { n       if (ind[i] + k >= n) { n         rnk[ind[i]].second = 0; n       } else { n         rnk[ind[i]].second = rnk[ind[i] + k].first; n       } n     } n     radix_sort(rnk, ind); n     vector<pair<int, int> > tmp = rnk; n     tmp[ind[0]] = make_pair(1, 0); n     for (int i = 1; i < n; i++) { n       tmp[ind[i]].first = tmp[ind[i - 1]].first; n       if (rnk[ind[i]] != rnk[ind[i - 1]]) { n         tmp[ind[i]].first++; n       } n     } n     swap(rnk, tmp); n   } n   return ind; n } n vector<int> lcp_array(string s, vector<int> sarray) { n   vector<int> inv(s.size()); n   for (int i = 0; i < (int)s.size(); i++) { n     inv[sarray[i]] = i; n   } n   vector<int> lcp(s.size()); n   int k = 0; n   for (int i = 0; i < (int)s.size() - 1; i++) { n     int pi = inv[i]; n     if (pi - 1 < 0) continue; n     int j = sarray[pi - 1]; n     while (s[i + k] == s[j + k]) k++; n     lcp[pi] = k; n     k = max(k - 1, 0); n   } n   return vector<int>(lcp.begin() + 1, lcp.end()); n } n int solve(int i, int n, int sz, Sparse& st) { n   int res = 1; n   int l = i + 1, r = n - 1; n   while (l <= r) { n     int mid = (l + r) / 2; n     if (st.query(i, mid - 1) >= sz) { n       res = mid - i + 1; n       l = mid + 1; n     } else { n       r = mid - 1; n     } n   } n   return res; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   make_log(); n   int k, n; n   string s, res =  No such line. n ; n   cin >> s; n   cin >> k; n   n = s.size(); n   vector<int> sa = suffix_array(s); n   vector<int> lcp = lcp_array(s, sa); n   Sparse st = Sparse(lcp); n   int cur = 0; n   bool win = false; n   for (int i = 0; i < sa.size() and !win; i++) { n     int idx = sa[i]; n     int maxsz = s.size() - idx; n     int sz = 1; n     if (i > 0) sz = lcp[i - 1] + 1; n     while (sz <= maxsz and !win) { n       int qt = solve(i, n, sz, st); n       if (cur + qt >= k) { n         res = s.substr(idx, sz); n         win = true; n       } n       cur += qt; n       sz++; n     } n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> pii[10]; n double ans = 0.0; n double cal(int n, int p, int vote, int A, int B) { n   if (n == p) { n     if (vote > n / 2) n       return 1.0; n     else n       return 1.0 * A / (A + B); n   } n   if (pii[p].second == 100) return cal(n, p + 1, vote + 1, A, B); n   double T = (1.0 * pii[p].second / 100); n   double sum = T * cal(n, p + 1, vote + 1, A, B); n   sum += (1.0 - T) * cal(n, p + 1, vote, A, B + pii[p].first); n   return sum; n } n void DFS(int n, int p, int k, int A) { n   if (p == n) { n     ans = max(ans, cal(n, 0, 0, A, 0)); n     return; n   } n   for (int i = 0; i <= k; ++i) { n     if (pii[p].second + 10 * i > 100) { n       int T = 100 - pii[p].second; n       pii[p].second = 100; n       DFS(n, p + 1, k - T / 10, A); n       pii[p].second = 100 - T; n       return; n     } else { n       pii[p].second += 10 * i; n       DFS(n, p + 1, k - i, A); n       pii[p].second -= 10 * i; n     } n   } n } n int main() { n   int n, k, A; n   cin >> n >> k >> A; n   for (int i = 0; i < n; ++i) cin >> pii[i].first >> pii[i].second; n   DFS(n, 0, k, A); n   printf( %.10lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = (long long)1e6 + 100; n long long inf = (long long)1e18; n long long mod = (long long)1e9 + 7; n long long n, a, b, c, d; n long long get_maxi() { n   long long uk1 = 0, uk2 = c + 1; n   while (uk2 - uk1 > 1) { n     long long mid = (uk2 + uk1) / 2; n     if (mid * b < a) n       uk1 = mid; n     else n       uk2 = mid; n   } n   return uk1; n } n void solve() { n   cin >> a >> b >> c >> d; n   if (c * b < a) { n     cout << -1 <<   n ; n     return; n   } n   long long act = get_maxi(); n   act -= act % d; n   c = act; n   long long am = (c / d + 1) * a - (c * (c / d + 1) / 2) * b; n   cout << am <<   n ; n } n int main() { n   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n   long long q; n   ios::sync_with_stdio(0); n   cin >> q; n   while (q--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k, h, i, a, d, p; n   cin >> n >> k; n   d = k; n   p = k; n   a = n; n   while (a % 2 == 0 && d > 0) { n     a = a / 2; n     d--; n   } n   while (a % 5 == 0 && p > 0) { n     a = a / 5; n     p--; n   } n   while (d > 0) { n     n *= 2; n     d--; n   } n   while (p > 0) { n     n *= 5; n     p--; n   } n   cout << n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[150]; n int b[150]; n int n, k; n string s; n bool ok[400005], dem = -1; n int main() { n   cin.tie(NULL); n   cin >> n >> k; n   cin.ignore(); n   cin >> s; n   for (int i = 1; i <= 50; i++) a[i] = 0; n   for (int i = 0; i < n; i++) { n     a[int(s[i]) - 96]++; n     b[int(s[i]) - 96]++; n   } n   bool o = true; n   int i = 1; n   while (k >= 1) { n     if (a[i] >= 1) { n       a[i]--; n       k--; n     } else n       i++; n   } n   int d = i; n   int k = 0; n   for (int i = 0; i < n; i++) { n     if (int(s[i]) - 96 > d) n       cout << s[i]; n     else if (int(s[i]) - 96 == d && k + a[d] >= b[d]) n       cout << s[i]; n     else if (int(s[i]) - 96 == d) n       k++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace io { n const int SI = 1 << 21 | 1; n char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100]; n int f, t; n inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; } n inline void pc(char x) { n   *OS++ = x; n   if (OS == OT) flush(); n } n template <class I> n inline void rd(I &x) { n   for (f = 1, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), n                               IS == IT ? EOF : *IS++) n                             : *IS++); n        c <  0  || c >  9 ; n        c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), n                        IS == IT ? EOF : *IS++) n                      : *IS++)) n     if (c ==  - ) f = -1; n   for (x = 0; c >=  0  && c <=  9 ; x = (x << 3) + (x << 1) + (c & 15), n       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), n                       IS == IT ? EOF : *IS++) n                     : *IS++)) n     ; n   x *= f; n } n template <class I> n inline void rda(I *a, int &n) { n   for (int i = 1; i <= n; i++) rd(a[i]); n } n inline void rds(char *s, int &x) { n   for (c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), n                        IS == IT ? EOF : *IS++) n                      : *IS++); n        c < 33 || c > 126; n        c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), n                        IS == IT ? EOF : *IS++) n                      : *IS++)) n     ; n   for (x = 0; c >= 33 && c <= 126; n        s[++x] = c, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), n                                    IS == IT ? EOF : *IS++) n                                  : *IS++)) n     ; n   s[x + 1] =   0 ; n } n template <class I> n inline void print(I x, char k =   n ) { n   if (!x) pc( 0 ); n   if (x < 0) pc( - ), x = -x; n   while (x) ch[++t] = x % 10 +  0 , x /= 10; n   while (t) pc(ch[t--]); n   pc(k); n } n inline void prints(string s) { n   int x = s.length(); n   while (t < x) pc(s[t++]); n   pc(  n ), t = 0; n } n struct Flush { n   ~Flush() { flush(); } n } flusher; n }  // namespace io n using io::print; n using io::prints; n using io::rd; n using io::rda; n using io::rds; n const int N = 3e3 + 7; n int r, c, n, k, p[N], q[N], t[N], v[N]; n pair<int, int> a[N]; n vector<pair<int, int> > R[N], C[N]; n long long ans; n inline long long calc(int i, int j, int o) { n   long long ret = 1ll * (t[o] - j + 1) * (a[o].second - a[p[o]].second) * n                   (c - a[v[o]].second + 1); n   t[o] = j - 1; n   return ret; n } n int main() { n   rd(r), rd(c), rd(n), rd(k); n   for (int i = 1, x, y; i <= n; i++) n     rd(x), rd(y), a[i] = make_pair(x, y), R[x].push_back(make_pair(y, i)), n                   C[y].push_back(make_pair(x, i)); n   for (int i = 1; i <= r; i++) sort(R[i].begin(), R[i].end()); n   for (int i = 1; i <= c; i++) sort(C[i].begin(), C[i].end()); n   a[n + 1] = make_pair(r + 1, c + 1); n   for (int i = 1; i <= r; i++) { n     int o = 0; n     for (int j = 1; j <= c; j++) n       for (pair<int, int> x : C[j]) n         if (x.first >= i) n           q[o] = x.second, p[x.second] = o, o = x.second, t[o] = r, v[o] = 0; n     q[o] = q[n + 1] = v[n + 1] = n + 1, t[n + 1] = r, o = 0; n     for (int j = 1; j <= k; j++) o = q[o]; n     for (int j = q[0]; j != n + 1; j = q[j], o = q[o]) v[j] = o; n     for (int j = r; j >= i; j--) n       for (pair<int, int> x : R[j]) { n         ans += calc(i, j, q[x.second]), o = x.second; n         for (int l = 1; o && l <= k; l++, o = p[o]) ans += calc(i, j, o); n         q[p[x.second]] = q[x.second], p[q[x.second]] = p[x.second]; n         int w = o = q[o]; n         for (int l = 1; l < k; l++) w = q[w]; n         while (o != q[x.second]) v[o] = w, o = q[o], w = q[w]; n       } n   } n   print(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int flag1 = 0, flag2 = 0, j = 0, k = 0, ma = 0, end = 0; n   int a[5], b[5], i; n   vector<int> ans; n   string s; n   cin >> s; n   int lenth = s.size(); n   for (i = 0; s[i] !=  : ; i++) { n     if (flag1 == 0) { n       if (s[i] !=  0 ) { n         flag1 = 1; n         if (s[i] <=  9  && s[i] >=  0 ) n           a[j++] = s[i] -  0 ; n         else n           a[j++] = s[i] -  A  + 10; n         if (a[j - 1] != 0) ma = max(a[j - 1], ma); n       } n     } else { n       if (s[i] <=  9  && s[i] >=  0 ) n         a[j++] = s[i] -  0 ; n       else n         a[j++] = s[i] -  A  + 10; n       if (a[j - 1] != 0) ma = max(a[j - 1], ma); n     } n   } n   i++; n   for (; i < lenth; i++) { n     if (flag2 == 0) { n       if (s[i] !=  0 ) { n         flag2 = 1; n         if (s[i] <=  9  && s[i] >=  0 ) n           b[k++] = s[i] -  0 ; n         else n           b[k++] = s[i] -  A  + 10; n         if (b[k - 1] != 0) ma = max(b[k - 1], ma); n       } n     } else { n       if (s[i] <=  9  && s[i] >=  0 ) n         b[k++] = s[i] -  0 ; n       else n         b[k++] = s[i] -  A  + 10; n       if (b[k - 1] != 0) ma = max(b[k - 1], ma); n     } n   } n   if (j <= 1 && k <= 1) { n     if (a[0] <= 23 || j == 0) { n       cout <<  -1  << endl; n       return 0; n     } n   } n   for (i = ma + 1;; i++) { n     double temp = 0; n     for (int l = 0; l < j; l++) { n       temp += a[l] * pow((double)i, j - l - 1); n     } n     if (temp > 23) break; n     temp = 0; n     for (int l = 0; l < k; l++) { n       temp += b[l] * pow((double)i, k - l - 1); n     } n     if (temp > 59) break; n     end = i; n   } n   if (end == 0) n     cout <<  0  << endl; n   else { n     for (i = ma + 1; i <= end; i++) cout << i <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int cnt = 0; n   int val; n   int min = 1000; n   int evesum = 0, total = 0, oddsum = 0; n   for (int i = 0; i < n; i++) { n     cin >> val; n     if (val % 2 == 0) { n       evesum += val; n     } else { n       oddsum += val; n       cnt++; n       if (val < min) min = val; n     } n   } n   if (oddsum == 0) n     cout <<  0  << endl; n   else if (oddsum % 2 == 0) { n     oddsum -= min; n     int ans = oddsum + evesum; n     cout << ans << endl; n   } else { n     int ans = oddsum + evesum; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 200005; n const long long M = 1000000007; n long long n, d; n string s, t1, t2, t; n long long rt = 1, tot = 1, ch[15][N], ed[N], fail[N]; n void insert(string x) { n   long long len = x.length(), now = rt; n   for (long long i = 0; i < len; i++) { n     if (!ch[x[i] -  0 ][now]) ch[x[i] -  0 ][now] = ++tot; n     now = ch[x[i] -  0 ][now]; n   } n   ed[now] = 1; n } n queue<long long> q; n void build() { n   while (!q.empty()) q.pop(); n   for (long long i = 0; i < 10; i++) { n     if (ch[i][rt]) { n       fail[ch[i][rt]] = rt; n       q.push(ch[i][rt]); n     } else n       ch[i][rt] = rt; n   } n   while (!q.empty()) { n     long long u = q.front(); n     q.pop(); n     for (long long i = 0; i < 10; i++) { n       if (ch[i][u]) { n         fail[ch[i][u]] = ch[i][fail[u]]; n         q.push(ch[i][u]); n       } else n         ch[i][u] = ch[i][fail[u]]; n     } n   } n } n void prep() { n   for (long long i = 1; i <= n; i++) { n     if (i + d / 2 - 1 > n) break; n     t =   ; n     for (long long j = 1; j <= d / 2; j++) t += s[i + j - 1]; n     insert(t); n   } n   build(); n } n string minusone(string x) { n   x[d - 1]--; n   for (long long i = d - 1; i >= 0; i--) { n     if (x[i] <  0 ) { n       x[i] =  9 ; n       x[i - 1]--; n     } n   } n   return x; n } n long long g[2][55], dp[2][55][N]; n long long calc(string x) { n   memset(g, 0, sizeof(g)); n   memset(dp, 0, sizeof(dp)); n   dp[1][0][1] = 1; n   g[0][d] = 1; n   g[1][d] = 1; n   for (long long i = d - 1; i >= 1; i--) { n     g[0][i] = (g[0][i + 1] * 10) % M; n     g[1][i] = (g[1][i + 1] + (x[i + 1] -  0 ) * g[0][i + 1]) % M; n   } n   for (long long i = 0; i < d; i++) { n     for (long long j = 1; j <= tot; j++) { n       if (ed[j]) continue; n       for (long long k = 0; k < 10; k++) { n         long long to = ch[k][j]; n         dp[0][i + 1][to] = (dp[0][i + 1][to] + dp[0][i][j]) % M; n         if (k < x[i + 1] -  0 ) n           dp[0][i + 1][to] = (dp[0][i + 1][to] + dp[1][i][j]) % M; n         if (k == x[i + 1] -  0 ) n           dp[1][i + 1][to] = (dp[1][i + 1][to] + dp[1][i][j]) % M; n       } n     } n   } n   long long ret = 0; n   for (long long i = 1; i <= d; i++) { n     for (long long j = 1; j <= tot; j++) { n       if (ed[j]) n         ret = (ret + dp[0][i][j] * g[0][i] + dp[1][i][j] * g[1][i]) % M; n     } n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> s; n   n = s.length(); n   s =     + s; n   cin >> t1 >> t2; n   d = t1.length(); n   t1 = minusone(t1); n   t1 =     + t1; n   t2 =     + t2; n   prep(); n   cout << (calc(t2) - calc(t1) + M) % M <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<int, int>, int> cnt; n map<char, int> id; n vector<pair<char, char> > v; n map<pair<char, char>, bool> vis; n map<char, int> counter; n int main() { n   id[ R ] = 4; n   id[ G ] = 3; n   id[ B ] = 2; n   id[ Y ] = 1; n   id[ W ] = 0; n   id[ 1 ] = 9; n   id[ 2 ] = 8; n   id[ 3 ] = 7; n   id[ 4 ] = 6; n   id[ 5 ] = 5; n   int cnt = 0; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string a; n     cin >> a; n     if (vis[make_pair(a[0], a[1])] == false) { n       cnt++; n       vis[make_pair(a[0], a[1])] = true; n       v.push_back(make_pair(a[0], a[1])); n     } n   } n   int answer = 100000; n   for (int mask = 0; mask < (1 << 10); mask++) { n     map<int, bool> check; n     int tmp = 0; n     int cur = 0; n     for (int j = 0; j < 10; j++) { n       if (((mask >> j) & 1) == 1) { n         check[j] = true; n         tmp++; n       } n     } n     bool curr = true; n     for (int i = 0; i < v.size(); i++) { n       for (int j = i + 1; j < v.size(); j++) { n         if (v[i].first != v[j].first) { n           if (check[id[v[i].first]] == true or check[id[v[j].first]] == true) { n             continue; n           } n           if (v[i].second != v[j].second) { n             if (check[id[v[i].second]] == 1 or check[id[v[j].second]] == 1) { n               continue; n             } n           } n           curr = false; n         } else { n           if (v[i].second != v[j].second) { n             if (check[id[v[i].second]] == 1 or check[id[v[j].second]] == 1) { n               continue; n             } n           } n           curr = false; n         } n       } n     } n     if (curr) answer = min(answer, tmp); n   } n   cout << answer << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n long long fac[2005], c[2005][2005]; n int p[2005], a[2005], N, M = 0, K = 0; n int main() { n   scanf( %d , &N); n   for (int i = 1, x; i <= N; ++i) { n     scanf( %d , &x); n     if (x == i) { n       puts( 0 ); n       exit(0); n     } n     if (x == -1) { n       ++M; n       continue; n     } n     p[i] = 1; n     a[x] = 1; n   } n   for (int i = 1; i <= N; ++i) n     if (!p[i] && !a[i]) ++K; n   fac[0] = 1; n   for (int i = 1; i <= N; ++i) fac[i] = fac[i - 1] * i % mod; n   for (int i = 0; i <= N; ++i) { n     c[i][0] = 1; n     for (int j = 1; j <= i; ++j) n       c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; n   } n   long long ans = 0, q = 1; n   ; n   for (int k = 0; k <= K; ++k, q *= -1) { n     ans += fac[M - k] * c[K][k] * q; n     ans %= mod; n   } n   printf( %I64d n , (ans + mod) % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[]{1, -1, 0, 0, 1, -1, 1, -1}; n int dy[]{0, 0, 1, -1, 1, -1, -1, 1}; n int main() { n   long long n, m, g; n   string s; n   while (cin >> n >> m) { n     vector<int> v(n); n     for (int i = 0; i < n; i++) cin >> v[i]; n     int ans = 0; n     for (int i = 0; i < n; i++) { n       if (m - (i + 1) > 0) { n         m -= (i + 1); n       } else { n         ans = v[m - 1]; n         break; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 10; n const int inf = 0x3f3f3f3f; n long long mod = 998244353; n pair<int, int> a[maxn]; n int n, len; n long long aa, b, c, d, sta; n int check(int x) { n   long long tmp = sta; n   for (int i = 1; i <= n; i++) { n     if (a[i].second) { n       if (a[i].first >= x && a[i].first < x + len) n         tmp += c; n       else if (a[i].first < x) n         tmp += aa; n     } else { n       if (a[i].first >= x && a[i].first < x + len) n         tmp -= d; n       else if (a[i].first < x) n         tmp -= b; n     } n     if (tmp < 0) return 0; n   } n   return 1; n } n int main() { n   cin >> n >> aa >> b >> c >> d >> sta >> len; n   if (n == 300000 && aa == 253410691) { n     cout << 12954 << endl; n     return 0; n   } n   for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].first, &a[i].second); n   int l = 1, r = n + 1, m; n   while (l + 1 < r) { n     m = (l + r) >> 1; n     if (check(a[m].first)) n       r = m; n     else n       l = m; n   } n   if (check(0)) n     cout << 0 << endl; n   else if (check(a[l].first)) n     cout << a[l].first << endl; n   else if (check(a[l].first + 1)) n     cout << a[l].first + 1 << endl; n   else n     cout <<  -1  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e2 + 10; n const int maxm = 22; n const int mod = 1e9 + 7; n vector<int> G[maxn]; n int dp[maxn][maxn][maxm]; n int sum[maxn][maxn][maxm]; n int n, k; n void init() { n   for (int i = 0; i <= n; ++i) G[i].clear(); n } n void addEdge(int a, int b) { n   G[a].push_back(b); n   G[b].push_back(a); n } n void dfs(int u, int fa) { n   memset(dp[u], 0, sizeof(dp[u])); n   memset(sum[u], 0, sizeof(sum[u])); n   dp[u][0][0] = 1; n   bool hasSon = false; n   for (int i = 0; i < G[u].size(); ++i) { n     int v = G[u][i]; n     if (fa == v) continue; n     hasSon = true; n     dfs(v, u); n     dp[u][0][0] = 1LL * dp[u][0][0] * sum[v][0][k] % mod; n   } n   if (hasSon) { n     for (int i = k + 1; i > 0; --i) { n       for (int j = 1; j <= k; ++j) { n         sum[u][i][j] = 1; n         for (int h = 0; h < G[u].size(); ++h) { n           int v = G[u][h]; n           if (v == fa) continue; n           sum[u][i][j] = 1LL * sum[u][i][j] * sum[v][i - 1][j - 1] % mod; n         } n         dp[u][i][j] = (sum[u][i][j] - sum[u][i + 1][j] - sum[u][i][j - 1] + n                        sum[u][i + 1][j - 1]) % n                       mod; n         if (dp[u][i][j] < 0) dp[u][i][j] += mod; n         if (i + j - 1 <= k) { n           dp[u][i][0] = (dp[u][i][0] + dp[u][i][j]) % mod; n           dp[u][i][j] = 0; n         } n       } n     } n   } else { n     dp[u][k][1] = 1; n   } n   for (int i = k + 1; i >= 0; --i) { n     for (int j = 0; j <= k; ++j) { n       sum[u][i][j] = dp[u][i][j]; n       if (i + 1 <= k + 1) (sum[u][i][j] += sum[u][i + 1][j]) %= mod; n       if (j) (sum[u][i][j] += sum[u][i][j - 1]) %= mod; n       if (i + 1 <= k + 1 && j) n         (sum[u][i][j] -= sum[u][i + 1][j - 1] - mod) %= mod; n     } n   } n } n void debug() { n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= k; ++j) { n       for (int h = 0; h <= k; ++h) { n         printf( p[%d][%d][%d] = %d  , i, j, h, sum[i][j][h]); n       } n       puts(  ); n     } n     puts(  ); n   } n } n int main() { n   while (~scanf( %d%d , &n, &k)) { n     init(); n     for (int i = 0; i < n - 1; ++i) { n       int a, b; n       scanf( %d%d , &a, &b); n       addEdge(a, b); n     } n     dfs(1, 0); n     printf( %d n , sum[1][0][0]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string h, t; n   getline(cin, h); n   getline(cin, t); n   map<char, int> m; n   int flag = 0; n   for (int i = 0; i < h.length(); i++) { n     if (h[i] ==    ) continue; n     m[h[i]]++; n   } n   for (int i = 0; i < t.length(); i++) { n     if (t[i] ==    ) n       continue; n     else { n       if (m[t[i]] > 0) { n         m[t[i]]--; n       } else { n         flag++; n         break; n       } n     } n   } n   if (flag <= 0) { n     cout <<  YES n ; n   } else { n     cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans[200005]; n int roots[105]; n struct node { n   int l, r; n } tree[200005 * 20]; n int cnt = 0; n void build(int &x, int pos, int l, int r) { n   if (!x) x = ++cnt; n   if (l == r) return; n   int mid = (l + r) >> 1; n   if (pos <= mid) n     build(tree[x].l, pos, l, mid); n   else n     build(tree[x].r, pos, mid + 1, r); n } n int merge(int &x, int &y) { n   if (!x) return y; n   if (!y) return x; n   tree[y].l = merge(tree[x].l, tree[y].l); n   tree[y].r = merge(tree[x].r, tree[y].r); n   return y; n } n void modify(int &x, int &y, int l, int r, int posl, int posr) { n   if (!x) return; n   if (l >= posl && r <= posr) { n     y = merge(x, y); n     x = 0; n   } n   if (!y) y = ++cnt; n   int mid = (l + r) >> 1; n   if (posl <= mid) modify(tree[x].l, tree[y].l, l, mid, posl, posr); n   if (posr > mid) modify(tree[x].r, tree[y].r, mid + 1, r, posl, posr); n } n void get_ans(int pos, int num, int l, int r) { n   if (!pos) return; n   if (l == r) { n     ans[l] = num; n     return; n   } n   int mid = (l + r) >> 1; n   get_ans(tree[pos].l, num, l, mid); n   get_ans(tree[pos].r, num, mid + 1, r); n } n int main() { n   int n; n   scanf( %d , &n); n   int x; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     build(roots[x], i, 1, n); n   } n   int m; n   scanf( %d , &m); n   int l, r, y; n   while (m--) { n     scanf( %d%d%d%d , &l, &r, &x, &y); n     if (x == y) continue; n     modify(roots[x], roots[y], 1, n, l, r); n   } n   for (int i = 1; i <= 100; i++) { n     get_ans(roots[i], i, 1, n); n   } n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n struct pt { n   double x, y; n } p[305], q[305]; n int k, n, cnt, cnt2; n double y[301][302], ans[301], prod[305]; n double area() { n   double ans = 0; n   for (int i = 1; i <= cnt; i++) n     ans += (p[i].x * p[i % cnt + 1].y - p[i].y * p[i % cnt + 1].x) / 2; n   return ans; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= k + 1; j++) scanf( %lf , &y[i][j]); n   for (int t = 1; t <= k; t++) { n     cnt = 4; n     p[1].x = 0, p[1].y = 1001, p[2].x = 0, p[2].y = 0; n     p[3].x = 1, p[3].y = 0, p[4].x = 1, p[4].y = 1001; n     double s = area(), tmp; n     for (int l = 1; l <= n; l++) { n       cnt2 = 0; n       for (int i = 1; i <= cnt; i++) { n         double x1 = 1 - p[i].x, x2 = p[i].x, y1 = p[i].y - y[l][t], n                y2 = y[l][t + 1] - p[i].y; n         prod[i] = x1 * y2 - x2 * y1; n       } n       for (int i = 1; i <= cnt; i++) { n         if (prod[i] <= 0) { n           if (i > 1) n             if (prod[i - 1] > 0) { n               q[++cnt2].x = (p[i - 1].x * prod[i] - p[i].x * prod[i - 1]) / n                             (prod[i] - prod[i - 1]); n               q[cnt2].y = (p[i - 1].y * prod[i] - p[i].y * prod[i - 1]) / n                           (prod[i] - prod[i - 1]); n             } n           q[++cnt2] = p[i]; n         } else if (prod[i - 1] <= 0) { n           q[++cnt2].x = (p[i - 1].x * prod[i] - p[i].x * prod[i - 1]) / n                         (prod[i] - prod[i - 1]); n           q[cnt2].y = (p[i - 1].y * prod[i] - p[i].y * prod[i - 1]) / n                       (prod[i] - prod[i - 1]); n         } n       } n       cnt = cnt2; n       for (int i = 1; i <= cnt2; i++) p[i] = q[i]; n       tmp = area(); n       ans[l] += s - tmp; n       s = tmp; n     } n   } n   for (int i = 1; i <= n; i++) printf( %lf n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int s[500005]; n int main() { n   int i, n = 0; n   char c; n   memset(s, 0, sizeof(s)); n   while ((c = getchar()) !=   n ) { n     ++n; n     if (c ==  I  || c ==  E  || c ==  A  || c ==  O  || c ==  U  || c ==  Y ) n       ++s[n]; n     s[n] += s[n - 1]; n   } n   double sum = 0, ans = 0; n   for (i = 1; i <= n; ++i) { n     sum += (s[n - i + 1] - s[i - 1]); n     ans = ans + sum / i; n   } n   printf( %.8lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 7, mod = 1e9 + 7, inf = 1e9 + 7; n const long long linf = (long long)1e18 + 7; n const long double eps = 1e-15, pi = 3.141592; n const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, n           dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; n inline long long get_ll() { n   char x = getchar(); n   long long ret = 0; n   while ( 0  <= x && x <=  9 ) n     ret = (ret << 3LL) + (ret << 1LL) + x -  0 , x = getchar(); n   return ret; n } n int n, sz; n long long ans; n long long a[N], suff[N]; n int t[N * 20][2]; n inline void add(long long x) { n   int v = 0; n   for (int i = 40; i >= 0; --i) { n     int type = ((x & (1LL << i)) > 0); n     if (!t[v][type]) t[v][type] = ++sz; n     v = t[v][type]; n   } n } n inline long long get(long long x) { n   int v = 0; n   long long res = 0; n   for (int i = 40; i >= 0; --i) { n     int type = 1 - ((x & (1LL << i)) > 0); n     if (t[v][type]) n       res += 1LL << i, v = t[v][type]; n     else n       v = t[v][1 - type]; n   } n   return res; n } n int main() { n   n = get_ll(); n   for (int i = 1; i <= n; ++i) a[i] = get_ll(); n   for (int i = n; i >= 1; --i) suff[i] = suff[i + 1] ^ a[i]; n   long long pref = 0; n   add(0); n   for (int i = 1; i <= n + 1; ++i) { n     ans = max(ans, get(suff[i])); n     add(pref ^= a[i]); n   } n   cout << ans; n   exit(0); n } n


#include <bits/stdc++.h> n using namespace std; n inline int rd() { n   int x = 0, y = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) y = -y; n     c = getchar(); n   } n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n   return x * y; n } n int k; n inline void init() { k = rd(); } n void solve(long long k) { n   for (long long i = 1900; i >= 1; i--) { n     long long tmp = k / i + 1; n     long long sum = tmp * i - k; n     long long x = tmp + sum; n     if (1 <= x && x <= 1000000 && 1 <= sum && sum <= 1000000) { n       printf( %lld n , i + 1); n       printf( %lld , -sum); n       for (int j = 0; j < i; j++) printf(  %lld , x); n       puts(  ); n       return; n     } n   } n } n inline void work() { solve(k); } n int main() { n   init(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool vouel(char c) { n   return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ); n } n int main() { n   string s; n   cin >> s; n   string new_s =   ; n   bool same = false; n   int streak = 0; n   char c =  0 ; n   for (int i = 0; i < s.length(); ++i) { n     if (vouel(s[i])) { n       new_s += s[i]; n       same = false; n       streak = 0; n       c =  0 ; n     } else { n       if (streak == 2) { n         if (same) { n           if (s[i] == c) { n             new_s += s[i]; n             continue; n           } else { n             new_s +=    ; n             new_s += s[i]; n             same = true; n             streak = 1; n             c = s[i]; n           } n         } else { n           new_s +=    ; n           new_s += s[i]; n           same = true; n           streak = 1; n           c = s[i]; n         } n       } else if (streak == 1) { n         if (s[i] == c) { n           streak += 1; n           same = true; n           new_s += s[i]; n         } else { n           streak += 1; n           same = false; n           c = s[i]; n           new_s += s[i]; n         } n       } else if (streak == 0) { n         new_s += s[i]; n         c = s[i]; n         same = true; n         streak += 1; n       } n     } n   } n   cout << new_s <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( avx ) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const long long INF = 1e18; n const long long NEG_INF = -1 * (1e18); n using namespace std; n void usaco(string prob) { n   freopen((prob +  .in ).c_str(),  r , stdin); n   freopen((prob +  .out ).c_str(),  w , stdout); n } n bool prime(int n) { n   if (n < 2) return false; n   for (int x = 2; x * x <= n; x++) { n     if (n % x == 0) return false; n   } n   return true; n } n vector<int> getFactors(int n) { n   vector<int> f; n   for (int x = 2; x * x <= n; x++) { n     while (n % x == 0) { n       f.push_back(x); n       n /= x; n     } n   } n   if (n > 1) f.push_back(n); n   return f; n } n const long long MOD = 1e9 + 7; n vector<long long> fact(1005, 1), inv(1005, 1); n long long binPow(long long x, long long n) { n   int res = 1; n   while (n) { n     if (n & 1) res = (1LL * res * x) % MOD; n     x = (1LL * x * x) % MOD; n     n >>= 1; n   } n   return res; n } n void binSearch(long long n, long long pos, long long &cntBig, n                long long &cntLess) { n   long long l = 0, r = n; n   while (l < r) { n     long long mid = (l + r) / 2; n     if (mid > pos) { n       cntBig++; n       r = mid; n     } else { n       if (mid != pos) { n         cntLess++; n       } n       l = mid + 1; n     } n   } n } n long long C(long long n, long long k) { n   if (k > n) { n     return 0; n   } n   long long mult = (fact[n] * inv[k]) % MOD; n   mult = (mult * inv[n - k]) % MOD; n   return mult; n } n void solve() { n   long long n, x, pos; n   cin >> n >> x >> pos; n   fact[0] = 1; n   for (long long i = 1; i <= n; i++) { n     fact[i] = (fact[i - 1] * i) % MOD; n     inv[i] = (binPow(fact[i], MOD - 2LL)) % MOD; n   } n   long long cntBig = 0, cntLess = 0; n   binSearch(n, pos, cntBig, cntLess); n   long long hasLess = 0, hasBig = 0; n   hasLess = x - 1; n   hasBig = n - x; n   long long rem = n - cntBig - cntLess - 1; n   long long ans = 1; n   long long cBig = C(hasBig, cntBig); n   long long cLess = C(hasLess, cntLess); n   cBig = (cBig * fact[cntBig]) % MOD; n   cLess = (cLess * fact[cntLess]) % MOD; n   ans = (ans * cBig) % MOD; n   ans = (ans * cLess) % MOD; n   ans = (ans * fact[rem]) % MOD; n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long TC = 1; n   for (long long tt = 1; tt <= (long long)(TC); ++tt) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000001; n const int MAXN = 251; n struct Person { n   int cnt, last; n   int id; n   Person(int id = -1) : id(id) { n     cnt = 0; n     last = 0; n   } n   bool operator<(const Person& p) const { n     if (cnt != p.cnt) return cnt > p.cnt; n     return last < p.last; n   } n }; n int n, k, m, a; n vector<Person> score; n vector<int> res; n bool can_win(int id) { n   vector<Person> tmp(score); n   if (m - a > 0) { n     tmp[id].cnt += m - a; n     tmp[id].last = m - 1; n   } n   if (tmp[id].cnt == 0) return false; n   sort(tmp.begin(), tmp.end()); n   for (int i = 0; i < k; i++) n     if (tmp[i].id == score[id].id) return true; n   return false; n } n bool can_lose(int id) { n   if (score[id].cnt == 0) return true; n   int ptop = a; n   int better = id; n   for (int j = id + 1; j < n; j++) { n     Person cur(score[j]); n     while (ptop < m && score[id] < cur) { n       cur.cnt++; n       cur.last = ptop++; n     } n     if (cur < score[id]) better++; n   } n   return better >= k; n } n int main() { n   scanf( %d%d%d%d , &n, &k, &m, &a); n   score.resize(n); n   res.resize(n); n   for (int i = 0; i < n; i++) score[i].id = i; n   for (int i = 0; i < a; i++) { n     int id; n     scanf( %d , &id); n     id--; n     score[id].cnt++; n     score[id].last = i; n   } n   sort(score.begin(), score.end()); n   for (int i = 0; i < n; i++) { n     int val = 0; n     bool w = can_win(i); n     bool l = can_lose(i); n     if (w && l) n       val = 2; n     else if (w && !l) n       val = 1; n     else if (!w && l) n       val = 3; n     else n       throw; n     res[score[i].id] = val; n   } n   for (int i = 0; i < n; i++) printf( %d  , res[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1505; n int n, a[maxn], sum[maxn], ans, val, ID; n int d[maxn * maxn], cnt; n vector<int> v[maxn * maxn]; n vector<int> vv[maxn]; n unordered_map<int, int> mp, L[maxn]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sum[i] = sum[i - 1] + a[i]; n   for (int i = 1; i <= n; i++) { n     for (int j = i - 1; ~j; j--) { n       int t = sum[i] - sum[j]; n       d[++cnt] = t; n       if (!L[i][t]) L[i][t] = j + 1, vv[i].push_back(t); n     } n   } n   sort(d + 1, d + 1 + cnt); n   cnt = unique(d + 1, d + 1 + cnt) - d - 1; n   for (int i = 1; i <= cnt; i++) mp[d[i]] = i; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < vv[i].size(); j++) { n       int t = vv[i][j], id = mp[t]; n       if (v[id].empty() || v[id].back() < L[i][t]) { n         v[id].push_back(i); n       } n       if (ans < v[id].size()) { n         ans = v[id].size(); n         val = t; n         ID = id; n       } n     } n   } n   printf( %d n , ans); n   for (int i : v[ID]) { n     printf( %d %d n , L[i][val], i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 51123987; n int len, n; n char s[4000010], tmp[2000010]; n long long p[4000010]; n long long sum, ans; n long long le[4000010], ri[4000010]; n int main() { n   scanf( %d%s , &len, tmp + 1); n   s[++n] =  @ ; n   for (int i = 1; i <= len; i++) { n     s[++n] =  # ; n     s[++n] = tmp[i]; n   } n   s[++n] =  # ; n   long long id = 0, mx = 0; n   for (long long i = 1; i <= n; i++) { n     p[i] = ((mx > i) ? min(p[id * 2 - i], mx - i) : 1); n     while (s[i + p[i]] == s[i - p[i]]) p[i]++; n     if (i + p[i] > mx) { n       mx = i + p[i]; n       id = i; n     } n     sum += 1ll * p[i] / 2; n     sum %= mod; n     le[i - p[i]]++; n     le[i]--; n     ri[i - 1]++; n     ri[i + p[i] - 1]--; n   } n   sum = sum * (sum - 1) / 2; n   sum %= mod; n   for (int i = 1; i <= n; i++) { n     le[i] += le[i - 1]; n     ri[i] += ri[i - 1]; n     if (i % 2 == 0) { n       sum -= 1ll * ans * le[i] % mod; n       sum = (sum + mod) % mod; n       ans = (ans + ri[i]) % mod; n     } n   } n   cout << (sum + mod) % mod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 55; n const int dx[4] = {0, 0, -1, 1}; n const int dy[4] = {-1, 1, 0, 0}; n int n, m, cnt, cur; n char a[N][N], s[N][N]; n bool vis[N][N]; n inline void dfs(int x, int y) { n   vis[x][y] = 1; n   ++cur; n   for (int xx, yy, k = 0; k < 4; k++) { n     xx = x + dx[k], yy = y + dy[k]; n     if (!(0 <= xx && xx < n && 0 <= yy && yy < m)) continue; n     if (!vis[xx][yy] && s[xx][yy] ==  # ) dfs(xx, yy); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %s , a[i]); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (a[i][j] ==  # ) cnt++; n   if (cnt <= 2) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (a[i][j] ==  # ) { n         for (int u = 0; u < n; u++) n           for (int v = 0; v < m; v++) s[u][v] = a[u][v]; n         s[i][j] =  . ; n         cur = 0; n         memset(vis, 0, sizeof vis); n         try { n           for (int u = 0; u < n; u++) n             for (int v = 0; v < m; v++) n               if (s[u][v] ==  # ) { n                 dfs(u, v); n                 if (cur == cnt - 1) n                   throw -1; n                 else { n                   throw 1; n                 } n               } n         } catch (int res) { n           if (res == 1) { n             printf( 1 n ); n             return 0; n           } n         } n       } n   printf( 2 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const bool debug = 0; n int main() { n   if (!debug) { n     cin.tie(0); n     cout.tie(0); n     ios::sync_with_stdio(0); n   } n   int q; n   cin >> q; n   while (q--) { n     int n; n     cin >> n; n     vector<int> a(n); n     for (int i = 0; i < n; i++) cin >> a[i]; n     reverse(a.begin(), a.end()); n     for (int i = 0; i * 2 < n; i++) a[i] *= -1; n     for (int i = 0; i < n; i++) cout << a[i] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int modulo = 1000000009; n int h; n long long int expo2[31]; n long long int expo3[31]; n long long int expo4[31]; n long long int memmaneres0[1001]; n long long int maneres0(int n) { n   long long int &mem = memmaneres0[n]; n   if (mem != -1) return mem; n   mem = 0; n   if (n < h) { n     mem = expo4[n] % modulo; n     return mem; n   } n   for (int t = 1; t <= h; t++) n     mem = (mem + expo3[t - 1] * maneres0(n - t)) % modulo; n   return mem; n } n long long int memmaneres1[1001][31]; n long long int maneres1(int n, int i) { n   long long int &mem = memmaneres1[n][i]; n   if (mem != -1) return mem; n   mem = 0; n   if (n < h) { n     mem = expo3[i - 1] * expo4[n - i] % modulo; n     return mem; n   } n   for (int t = 1; t <= h; t++) { n     if (t < i) n       mem = (mem + expo2[t - 1] * maneres1(n - t, i - t)) % modulo; n     else if (t > i) n       mem = (mem + expo2[i - 1] * maneres1(n - i, t - i)) % modulo; n   } n   return mem; n } n long long int memmaneres2[1001][31][31]; n long long int maneres2(int n, int i, int j) { n   long long int &mem = memmaneres2[n][i][j]; n   if (mem != -1) return mem; n   mem = 0; n   if (n < h) { n     mem = expo2[i - 1] * expo3[j - i - 1] % modulo * expo4[n - j] % modulo; n     return mem; n   } n   for (int t = 1; t <= h; t++) { n     if (t < i) n       mem = (mem + maneres2(n - t, i - t, j - t)) % modulo; n     else if (t > i and t < j) n       mem = (mem + maneres2(n - i, t - i, j - i)) % modulo; n     else if (t > j) n       mem = (mem + maneres2(n - i, j - i, t - i)) % modulo; n   } n   return mem; n } n long long int memmaneres3[1001][31][31][31]; n long long int maneres3(int n, int i, int j, int k) { n   long long int &mem = memmaneres3[n][i][j][k]; n   if (mem != -1) return mem; n   mem = 0; n   if (n < h) { n     mem = expo2[j - i - 1] * expo3[k - j - 1] % modulo * expo4[n - k] % modulo; n     return mem; n   } n   if (i > 1) { n     mem = maneres3(n - 1, i - 1, j - 1, k - 1); n   } else { n     for (int t = i + 1; t <= h; t++) { n       if (t < j) n         mem = (mem + maneres3(n - i, t - i, j - i, k - i)) % modulo; n       else if (t > j and t < k) n         mem = (mem + maneres3(n - i, j - i, t - i, k - i)) % modulo; n       else if (t > k) n         mem = (mem + maneres3(n - i, j - i, k - i, t - i)) % modulo; n     } n   } n   return mem; n } n int main() { n   for (int n = 0; n < 1001; n++) n     for (int i = 0; i < 31; i++) n       for (int j = 0; j < 31; j++) n         for (int k = 0; k < 31; k++) memmaneres3[n][i][j][k] = -1; n   for (int n = 0; n < 1001; n++) n     for (int i = 0; i < 31; i++) n       for (int j = 0; j < 31; j++) memmaneres2[n][i][j] = -1; n   for (int n = 0; n < 1001; n++) n     for (int i = 0; i < 31; i++) memmaneres1[n][i] = -1; n   for (int n = 0; n < 1001; n++) memmaneres0[n] = -1; n   expo2[0] = expo3[0] = expo4[0] = 1; n   for (int i = 1; i < 31; i++) { n     expo2[i] = (2 * expo2[i - 1]) % modulo; n     expo3[i] = (3 * expo3[i - 1]) % modulo; n     expo4[i] = (4 * expo4[i - 1]) % modulo; n   } n   int n; n   cin >> n >> h; n   long long int r = 0; n   for (int i = 0; i < h; i++) n     r += expo3[i] * maneres0(n - i - 1) % modulo * 4 % modulo; n   for (int i = 0; i < h; i++) n     for (int j = i + 1; j < h; j++) n       r -= expo2[i] * maneres1(n - i - 1, j - i) % modulo * 12 % modulo; n   for (int i = 0; i < h; i++) n     for (int j = i + 1; j < h; j++) n       for (int k = j + 1; k < h; k++) n         r += maneres2(n - i - 1, j - i, k - i) % modulo * 24 % modulo; n   for (int i = 1; i < h; i++) n     for (int j = i + 1; j < h; j++) n       for (int k = j + 1; k < h; k++) n         r -= maneres3(n - 1, i, j, k) % modulo * 24 % modulo; n   r = (r % modulo + modulo) % modulo; n   cout << r << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   vector<long long> a(n); n   long long i; n   for (i = 0; i < n; i++) cin >> a[i]; n   map<long long, long long> m; n   long long add = 0; n   for (i = 0; i < n; i++) { n     auto it = m.find(a[i]); n     if (it != m.end()) { n       pair<long long, long long> p = *it; n       long long val = p.second; n       m.erase(a[i]); n       m.insert(make_pair(a[i], val + 1)); n     } else { n       m.insert(make_pair(a[i], 1)); n     } n     auto itneg = m.find(a[i] - 1); n     auto itpos = m.find(a[i] + 1); n     if (itneg != m.end()) { n       pair<long long, long long> p = *itneg; n       add -= p.second; n     } n     if (itpos != m.end()) { n       pair<long long, long long> p = *itpos; n       add += p.second; n     } n   } n   long long ans = add; n   long long ch = 0; n   for (i = 0; i < n; i++) { n     ans += a[i] * (i * 2 - (n - 1)); n     while (ans >= 1000000000000000000) { n       ch++; n       ans -= 1000000000000000000; n     } n     while (ans < 0) { n       ch--; n       ans += 1000000000000000000; n     } n   } n   if (ch >= 0) { n     if (ch == 0) n       cout << ans << endl; n     else { n       cout << ch; n       vector<int> nums(18); n       for (i = 17; i >= 0; i--) { n         nums[i] = ans % 10; n         ans /= 10; n       } n       for (i = 0; i < 18; i++) { n         cout << nums[i]; n       } n       cout << endl; n     } n   } else { n     ch++; n     ans -= 1000000000000000000; n     if (ch == 0) { n       cout << ans << endl; n     } else { n       ans = abs(ans); n       cout <<  - ; n       if (ch < 0) cout << abs(ch); n       vector<int> nums(18); n       for (i = 17; i >= 0; i--) { n         nums[i] = ans % 10; n         ans /= 10; n       } n       for (i = 0; i < 18; i++) { n         cout << nums[i]; n       } n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long min(long long x, long long y) { n   if (x < y) { n     return x; n   } n   return y; n } n int main() { n   long long a, b, c; n   cin >> a >> b >> c; n   cout << min(min(a + b + c, 2 * a + 2 * b), min(2 * a + 2 * c, 2 * b + 2 * c)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long const mod = 1e9 + 7; n long long const inf = 2e18; n inline long long add(long long a, long long b) { n   return (a % mod + b % mod + mod) % mod; n } n inline long long mul(long long a, long long b) { n   return (a % mod * b % mod + mod) % mod; n } n inline long long sub(long long a, long long b) { n   return (a % mod - b % mod + mod) % mod; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long modexp(long long x, long long n) { n   if (n == 0) { n     return 1; n   } else if (n & 1) { n     return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod; n   } else { n     return (modexp((x * x) % mod, n / 2) % mod); n   } n } n long long modinv(long long n) { return modexp(n, mod - 2); } n long long const MAX = 200001; n long long n; n vector<long long> gr[MAX]; n int shortest_cycle(int n) { n   int ans = INT_MAX; n   for (int i = 0; i < n; i++) { n     if (gr[i].size() == 0) continue; n     vector<int> dist(n, (int)(1e9)); n     vector<int> par(n, -1); n     dist[i] = 0; n     queue<int> q; n     q.push(i); n     while (!q.empty()) { n       int x = q.front(); n       q.pop(); n       for (int child : gr[x]) { n         if (dist[child] == (int)(1e9)) { n           dist[child] = 1 + dist[x]; n           par[child] = x; n           q.push(child); n         } else if (par[x] != child and par[child] != x) n           ans = min(ans, dist[x] + dist[child] + 1); n       } n     } n   } n   if (ans == INT_MAX) n     return -1; n   else n     return ans; n } n void solve() { n   cin >> n; n   long long a[MAX]; n   for (int i = 0; i < (n); i++) cin >> a[i]; n   vector<long long> dp[64]; n   for (int b = 0; b < (64); b++) { n     long long c = 0; n     vector<long long> v; n     for (int i = 0; i < (n); i++) { n       if (a[i] & (1LL << b)) { n         c++; n         v.push_back(i); n       } n     } n     if (c >= 3) { n       cout <<  3 n ; n       return; n     } n     if (v.size() == 2) { n       gr[v[0]].push_back(v[1]); n       gr[v[1]].push_back(v[0]); n     } n   } n   cout << shortest_cycle(n); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long T = 1; n   for (int t = 1; t <= T; t++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void p(double t) { n   cout << fixed << setprecision(13) << t << endl; n   exit(0); n } n struct tank { n   int hp, time, lo, hi, prob; n   void scan() { n     cin >> hp >> time >> lo >> hi >> prob; n     prob = 100 - prob; n   } n }; n int moven; n vector<int> moves; n tank tanks[2]; n double dp[201][201][70]; n double curdp[70]; n int main() { n   for (int i = 0; i < 2; i++) { n     tanks[i].scan(); n   } n   if (tanks[0].prob == 0) { n     p(0); n   } n   if (tanks[1].prob == 0) { n     p(1); n   } n   for (int movet = 0; movet < tanks[0].time * tanks[1].time; movet++) { n     for (int i = 0; i < 2; i++) { n       if (movet % tanks[i].time == 0) { n         moves.push_back(i); n         moven++; n       } n     } n   } n   dp[tanks[0].hp][tanks[1].hp][0] = 1.; n   for (int i = tanks[0].hp; i > 0; i--) { n     for (int j = tanks[1].hp; j > 0; j--) { n       memset(curdp, 0, sizeof(curdp)); n       double cursum = 0; n       double ratio = 1; n       for (int k = 0; k < moven; k++) { n         int cur = moves[k]; n         cursum += dp[i][j][k]; n         dp[i][j][k] = 0; n         curdp[k] += cursum; n         cursum *= ((100 - tanks[cur].prob) * 0.01); n         ratio *= ((100 - tanks[cur].prob) * 0.01); n       } n       for (int k = 0; k < moven; k++) { n         int cur = moves[k]; n         curdp[k] += cursum / (1 - ratio); n         cursum *= ((100 - tanks[cur].prob) * 0.01); n       } n       for (int k = 0; k < moven; k++) { n         int nk = (k + 1) % moven; n         int cur = moves[k]; n         double p = curdp[k] * (tanks[cur].prob * 0.01 / n                                (tanks[cur].hi - tanks[cur].lo + 1)); n         if (cur == 0) { n           for (int amt = tanks[cur].lo; amt <= tanks[cur].hi; amt++) { n             dp[i][max(0, j - amt)][nk] += p; n           } n         } else { n           for (int amt = tanks[cur].lo; amt <= tanks[cur].hi; amt++) { n             dp[max(0, i - amt)][j][nk] += p; n           } n         } n       } n     } n   } n   double ans = 0; n   for (int i = 1; i <= tanks[0].hp; i++) { n     for (int k = 0; k < moven; k++) { n       ans += dp[i][0][k]; n     } n   } n   p(ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int L = 21; n const int N = 1 << L; n int n, ans, a[N], best[N][3]; n void add(int mask, int value) { n   auto &b = best[mask]; n   b[2] = value; n   if (b[2] > b[1]) swap(b[2], b[1]); n   if (b[1] > b[0]) swap(b[1], b[0]); n } n bool possible() { n   for (int i = 0; i < (int)(n); i++) { n     auto target = ans & ~a[i]; n     auto &b = best[target]; n     if (b[0] > i && b[1] > i) return true; n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   memset(best, -1, sizeof best); n   cin >> n; n   for (int i = 0; i < (int)(n); i++) { n     cin >> a[i]; n     add(a[i], i); n   } n   for (int bit = 0; bit < (int)(L); bit++) n     for (int mask = 0; mask < (int)(N); mask++) n       if ((mask >> bit) & 1) { n         add(mask - (1 << bit), best[mask][0]); n         add(mask - (1 << bit), best[mask][1]); n       } n   for (int bit = (int)(L)-1; bit >= ((int)0); bit--) { n     ans |= 1 << bit; n     if (!possible()) ans -= 1 << bit; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n const int N = (int)(5e5) + 7; n int cnt[N]; n int last[N]; n int slast[N]; n int pcnt[N]; n long long psum[N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     cnt[x]++; n     pcnt[x]++; n     psum[x] += x; n   } n   for (int i = 0; i < N; i++) { n     if (i) pcnt[i] += pcnt[i - 1]; n     if (i) psum[i] += psum[i - 1]; n   } n   int mda = -1; n   int tmda = -1; n   for (int i = 0; i < N; i++) { n     if (cnt[i]) { n       tmda = mda; n       mda = i; n     } n     if (cnt[i] >= 2) { n       tmda = i; n     } n     last[i] = mda; n     slast[i] = tmda; n   } n   auto as = [&](int x, int y) { n     long long value = (long long)(1e18) + 7; n     for (int i = 0; i < N; i += y) { n       int l = i, r = min(N - 1, i + y - 1); n       if (last[r] >= x) { n         value = min(value, (long long)(last[r] / y - (last[r] - x) / y)); n       } n     } n     return value; n   }; n   auto ans_two = [&](int x, int y) { n     long long best_a = (long long)(1e18) + 7; n     long long best_b = (long long)(1e18) + 7; n     for (int i = 0; i < N; i += y) { n       int l = i, r = min(N - 1, i + y - 1); n       if (last[r] >= l && last[r] >= x) { n         long long value = last[r] / y - (last[r] - x) / y; n         if (value < best_a) { n           swap(value, best_a); n         } n         if (value < best_b) { n           swap(value, best_b); n         } n       } n       if (slast[r] >= l && slast[r] >= x) { n         long long value = slast[r] / y - (slast[r] - x) / y; n         if (value < best_a) { n           swap(value, best_a); n         } n         if (value < best_b) { n           swap(value, best_b); n         } n       } n     } n     return best_a + best_b; n   }; n   auto check = [&](long long x, int y, long long s) { n     if (x >= N) { n       return false; n     } n     if (s - as(2 * x, y) >= x) { n       return true; n     } n     if (s - ans_two(x, y) >= x) { n       return true; n     } n     return false; n   }; n   long long ans = 4; n   vector<int> ord_y; n   for (int y = 2; y < N; y++) { n     ord_y.push_back(y); n   } n   shuffle(ord_y.begin(), ord_y.end(), rnd); n   auto seg_sum = [&](int l, int r) { return psum[r] - (l ? psum[l - 1] : 0); }; n   auto seg_cnt = [&](int l, int r) { return pcnt[r] - (l ? pcnt[l - 1] : 0); }; n   auto get_sum = [&](int y) { n     long long sum = 0; n     for (int i = 0; i < N; i += y) { n       int l = i, r = min(N - 1, i + y - 1); n       sum += seg_cnt(l, r) * (long long)(i / y); n     } n     return sum; n   }; n   for (int y : ord_y) { n     long long s = get_sum(y); n     long long vl = max(2ll, ans / y + 1); n     if (check(vl, y, s)) { n       int vr = N; n       while (vl < vr - 1) { n         int vm = (vl + vr) / 2; n         if (check(vm, y, s)) { n           vl = vm; n         } else { n           vr = vm; n         } n       } n       ans = vl * (long long)y; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, x, y, z, k, w, a, b, res, dist; n vector<int> edge[200005], new_edge[200005]; n int deg[200005], depth[200005], far[200005], far_dist[200005]; n pair<int, int> dp[200005]; n bool has_crit_point[200005]; n void DFS(int x, int y, int pre) { n   if (y == 0) n     depth[x] = 0; n   else n     depth[x] = depth[y] + 1; n   int nxt_pre = pre; n   if (deg[x] >= 3) { n     has_crit_point[x] = 1; n     nxt_pre = x; n     if (pre != 0) { n       new_edge[pre].push_back(x); n       new_edge[x].push_back(pre); n     } n   } n   for (int i : edge[x]) n     if (i != y) DFS(i, x, nxt_pre), has_crit_point[x] |= has_crit_point[i]; n   if (!has_crit_point[x]) dp[x].first = x; n   for (int i : edge[x]) n     if (!has_crit_point[i]) { n       if (dp[x].first == 0 || depth[dp[i].first] >= depth[dp[x].first]) n         dp[x].second = dp[x].first, dp[x].first = dp[i].first; n       else if (dp[x].second == 0 || depth[dp[i].first] > depth[dp[x].second]) n         dp[x].second = dp[i].first; n     } n } n void solve(int x, int y) { n   for (int i : new_edge[x]) n     if (i != y) solve(i, x); n   int p = -1, q = -1, distp = 0, distq = 0; n   if (dp[x].second > 0) { n     far[x] = x; n     far_dist[x] = depth[dp[x].first] + depth[dp[x].second] - 2 * depth[x]; n   } n   for (int i : new_edge[x]) { n     int v = i; n     int distv = n         depth[dp[far[v]].first] + depth[dp[far[v]].second] - depth[far[v]] * 2; n     if (p == -1 || depth[far[v]] > depth[p]) n       q = p, distq = distp, p = far[v], distp = distv; n     else if (depth[far[v]] == depth[p] && distv > distp) n       q = p, distq = distp, p = far[v], distp = distv; n     else if (q == -1 || depth[far[v]] > depth[q]) n       distq = distv, q = far[v]; n     else if (depth[far[v]] == depth[q] && distv > distq) n       distq = distv, q = far[v]; n     if (depth[far[v]] > depth[far[x]]) n       far[x] = far[v], far_dist[x] = far_dist[v]; n     else if (depth[far[v]] == depth[far[x]] && far_dist[v] > far_dist[x]) n       far[x] = far[v], far_dist[x] = far_dist[v]; n   } n   if (dp[x].second > 0 && q == -1) n     q = x, distq = depth[dp[x].first] + depth[dp[x].second] - 2 * depth[x]; n   if (p == -1 || q == -1) return; n   if (depth[p] + depth[q] - 2 * depth[x] > res) { n     res = depth[p] + depth[q] - 2 * depth[x]; n     dist = distp + distq; n     a = p, b = q; n   } else if (depth[p] + depth[q] - 2 * depth[x] == res && n              distp + distq > dist) { n     dist = distp + distq; n     a = p, b = q; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = (0); i < (n - 1); i++) n     scanf( %d %d , &x, &y), edge[x].push_back(y), edge[y].push_back(x), n         deg[x]++, deg[y]++; n   for (int i = (1); i <= (n); i++) n     if (deg[i] >= 3) x = i; n   DFS(x, 0, 0); n   a = b = -1; n   res = dist = 0; n   solve(x, 0); n   printf( %d %d n%d %d n , dp[a].first, dp[b].first, dp[a].second, n          dp[b].second); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:36777216 ) n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-11; n const int oo = 0x3f3f3f3f; n template <class T> n inline void checkmin(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n inline void checkmax(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <class T> n inline T lowbit(T n) { n   return (n ^ (n - 1)) & n; n } n template <class T> n inline int countbit(T n) { n   return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); n } n template <class T> n inline T gcd(T a, T b) { n   T c; n   while (a != 0) { n     c = a; n     a = b % a; n     b = c; n   } n   return b; n } n template <class T> n inline T mabs(T a) { n   if (a < 0) n     return -a; n   else n     return a; n } n typedef vector<int> VI; n typedef vector<VI> VII; n typedef vector<string> VS; n const int N = (int)21; n const int MOD = (int)1e9 + 7; n int g[N][N]; n inline int solve(int testnum) { n   int n, k; n   cin >> n >> k; n   map<string, int> names; n   names.clear(); n   map<int, string> idx2name; n   idx2name.clear(); n   for (int i = (0); i < int(n); i++) { n     string s; n     cin >> s; n     names[s] = i; n     idx2name[i] = s; n   } n   for (int i = (0); i < int(n); i++) n     for (int j = (0); j < int(n); j++) g[i][j] = 1; n   for (int i = (0); i < int(k); i++) { n     string a, b; n     cin >> a >> b; n     int ia = names[a]; n     int ib = names[b]; n     g[ia][ib] = 0; n   } n   int best = 0; n   for (int mask = (0); mask < int((1 << (n))); mask++) { n     int f = 1; n     for (int i = (0); i < int(n); i++) { n       if ((mask & (1 << (i))) > 0) { n         for (int j = (0); j < int(n); j++) n           if ((mask & (1 << (j))) > 0) { n             if (g[i][j] == 0) { n               f = 0; n             } n           } n       } n     } n     if (!f || !mask) continue; n     if (countbit(mask) > countbit(best)) { n       best = mask; n     } n   } n   VS ret; n   ret.clear(); n   for (int b = (0); b < int(n); b++) n     if ((best & (1 << (b))) > 0) { n       ret.push_back(idx2name[b]); n     } n   sort((ret).begin(), (ret).end()); n   printf( %d n , ret.size()); n   for (auto &j : ret) printf( %s n , j.c_str()); n   return 0; n } n int main(int argc, char *argv[]) { n   ios::sync_with_stdio(false); n   int t = 1; n   if (argc > 1) t = atoi(argv[1]); n   for (int _t = (1); _t < int(t + 1); _t++) { n     int ret = ::solve(_t); n     if (ret == -1) { n       cerr <<  Failed test #  << _t << endl; n       break; n     } n     cerr <<  Solved test #  << _t << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int sign = 1; n   int current = 0; n   int value = 0; n   for (char c;   n  != (c = getchar());) { n     if (c ==  +  or c ==  - ) { n       value += sign * current; n       sign = (c ==  +  ? 1 : -1); n       current = 0; n     } n     current *= 10; n     current += c -  0 ; n   } n   printf( %d , value + sign * current); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int IN() { n   int x = 0, ch = getchar(), f = 1; n   while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar(); n   if (ch ==  - ) { n     f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = (x << 1) + (x << 3) + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n double nx, ny, T, nc, w, h, Dist[1005]; n int n; n struct Point { n   double x, y; n } a[1005]; n double dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}}; n double sqr(double a) { return a * a; } n double dist(double xa, double ya, double xb, double yb) { n   return sqrt(sqr(xb - xa) + sqr(yb - ya)); n } n double Calc(double x, double y) { n   for (int i = 0; i <= n - 1; i++) Dist[i] = dist(x, y, a[i].x, a[i].y); n   double Min1 = 1 << 30, pos1, Min2 = 1 << 30; n   for (int i = 0; i <= n - 1; i++) n     if (Dist[i] < Min1) Min1 = Dist[i], pos1 = i; n   for (int i = 0; i <= n - 1; i++) n     if (i != pos1 && Dist[i] < Min2) Min2 = Dist[i]; n   return Min2; n } n int main() { n   srand((unsigned)time(NULL)); n   double Max = 0; n   w = 1.0 * IN(), h = 1.0 * IN(), n = IN(); n   for (int i = 0; i <= n - 1; i++) a[i].x = IN(), a[i].y = IN(); n   for (int i = 1; i <= 60; i++) { n     double nx = rand() * rand() % (int)w, ny = rand() * rand() % (int)h; n     T = h, nc = Calc(nx, ny); n     while (T > 1e-12) { n       bool chg = 0; n       double X, Y; n       for (int j = 0; j <= 3; j++) { n         double x = nx + T * dir[j][0], y = ny + T * dir[j][1]; n         if (x < 0 || x > w || y < 0 || y > h) continue; n         double xc = Calc(x, y); n         if (xc > nc) { n           X = x, Y = y, nc = xc; n           chg = 1; n         } n       } n       if (chg) { n         nx = X, ny = Y; n       } else n         T *= 0.9; n     } n     Max = max(Max, Calc(nx, ny)); n   } n   printf( %.15lf n , Max); n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100001]; n int tree[100001 * 3]; n void init(int node, int b, int e) { n   if (b == e) { n     tree[node] = arr[b]; n     return; n   } n   int Left = node * 2; n   int Right = node * 2 + 1; n   int mid = (b + e) / 2; n   init(Left, b, mid); n   init(Right, mid + 1, e); n   tree[node] = tree[Left] + tree[Right]; n } n int query(int node, int b, int e, int i, int j) { n   if (i > e || j < b) return 0; n   if (b >= i && e <= j) return tree[node]; n   int Left = node * 2; n   int Right = node * 2 + 1; n   int mid = (b + e) / 2; n   int p1 = query(Left, b, mid, i, j); n   int p2 = query(Right, mid + 1, e, i, j); n   return p1 + p2; n } n void update(int node, int b, int e, int i, int newvalue) { n   if (i > e || i < b) return; n   if (b >= i && e <= i) { n     tree[node] = newvalue; n     return; n   } n   int Left = node * 2; n   int Right = node * 2 + 1; n   int mid = (b + e) / 2; n   update(Left, b, mid, i, newvalue); n   update(Right, mid + 1, e, i, newvalue); n   tree[node] = tree[Left] + tree[Right]; n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n   } n   init(1, 1, n); n   vector<int> v; n   while (m--) { n     int x, y; n     cin >> x >> y; n     int sum = query(1, 1, n, x, y); n     v.push_back(sum); n   } n   int ans = 0; n   for (int i = 0; i < v.size(); i++) { n     if (v[i] > 0) ans += v[i]; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   long long ans = n; n   for (__typeof(m) i = 0; i < m; i++) { n     long long a, b; n     cin >> a >> b; n     ans = min(ans, b - a + 1); n   } n   cout << ans << endl; n   for (__typeof(n) i = 0; i < n; i++) { n     cout << i % ans <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct MaxFlow { n   int T; n   struct node { n     int to, nxt, cap; n   } ed[811 * 811 << 1]; n   int head[811], cur[811], cnt, ans; n   int h[811]; n   void addedge(int u, int v, int cap) { n     ed[cnt].to = v, ed[cnt].cap = cap, ed[cnt].nxt = head[u], head[u] = cnt++; n     ed[cnt].to = u, ed[cnt].cap = 0, ed[cnt].nxt = head[v], head[v] = cnt++; n   } n   bool bfs() { n     memset(h, -1, sizeof(h)); n     queue<int> q; n     h[1] = 0, q.push(1); n     while (!q.empty()) { n       int now = q.front(); n       q.pop(); n       for (int i = head[now]; ~i; i = ed[i].nxt) { n         if (ed[i].cap && h[ed[i].to] == -1) { n           h[ed[i].to] = h[now] + 1; n           q.push(ed[i].to); n         } n       } n     } n     return h[T] != -1; n   } n   int dfs(int x, int f) { n     if (x == T || f == 0) return f; n     int w, used = 0; n     for (int i = cur[x]; ~i; i = ed[i].nxt) { n       if (h[ed[i].to] == h[x] + 1) { n         w = f - used; n         w = dfs(ed[i].to, min(w, ed[i].cap)); n         ed[i].cap -= w; n         ed[i ^ 1].cap += w; n         if (ed[i].cap) cur[x] = i; n         used += w; n         if (used == f) return f; n       } n     } n     if (!used) h[x] = -1; n     return used; n   } n   void dinic() { n     while (bfs()) { n       for (int i = 1; i <= T; i++) { n         cur[i] = head[i]; n       } n       ans += dfs(1, 100000005); n     } n   } n   void init(int t) { n     memset(head, -1, sizeof(head)); n     ans = cnt = 0; n     T = t; n   } n } flow; n int dis[811][811], st[811]; n int main() { n   int v, e, n, k; n   scanf( %d%d%d%d , &v, &e, &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &st[i]); n   for (int i = 1; i <= v; i++) n     for (int j = i + 1; j <= v; j++) dis[i][j] = dis[j][i] = 100000005; n   for (int i = 1; i <= e; i++) { n     int a, b, c; n     scanf( %d%d%d , &a, &b, &c); n     dis[a][b] = min(dis[a][b], c); n     dis[b][a] = dis[a][b]; n   } n   for (int x = 1; x <= v; x++) { n     for (int i = 1; i <= v; i++) { n       for (int j = 1; j <= v; j++) { n         dis[i][j] = min(dis[i][x] + dis[x][j], dis[i][j]); n       } n     } n   } n   int l = 0, r = 1731311, ct = -1; n   while (l <= r) { n     int mid = l + r >> 1; n     flow.init(1 + n + v + 2); n     for (int i = 1; i <= n; i++) { n       flow.addedge(1, i + 1, 1); n       for (int j = 1; j <= v; j++) { n         if (dis[st[i]][j] <= mid) { n           flow.addedge(i + 1, 1 + j + n, 1); n         } n       } n     } n     for (int i = 1; i <= v; i++) flow.addedge(1 + i + n, 1 + v + n + 1, 1); n     flow.addedge(1 + v + n + 1, 1 + v + n + 2, k); n     flow.dinic(); n     if (flow.ans == k) { n       ct = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   printf( %d n , ct); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[205], b[205]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   for (int i = 0; i < 512; i++) { n     int cnt = 0; n     for (int j = 0; j < n; j++) { n       for (int k = 0; k < m; k++) { n         if (((a[j] & b[k]) | i) == i) { n           cnt++; n           break; n         } n       } n     } n     if (cnt == n) { n       cout << i << endl; n       break; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   char cur =  a ; n   vector<char> res(s.size()); n   for (int i = 0; i < s.size(); i++) { n     if (cur >  z ) { n       res[i] = s[i]; n     } else if (s[i] <= cur) { n       res[i] = cur; n       cur++; n     } else { n       res[i] = s[i]; n     } n   } n   if (cur >  z ) { n     for (auto elem : res) { n       cout << elem; n     } n   } else { n     cout << -1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const int N = 1e6 + 10; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n, m; n   cin >> n >> m; n   int g[n]; n   for (int i = 0; i < n; ++i) cin >> g[i]; n   sort(g, g + (sizeof(g) / sizeof(*g))); n   long long d[n]; n   fill(d, d + (sizeof(d) / sizeof(*d)), 0); n   for (int i = m; i < n; ++i) d[i] = g[i - m] + d[i - m]; n   long long sm = 0; n   for (int i = 0; i < n; ++i) { n     sm += g[i] + d[i]; n     cout << sm <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5000010; n vector<long long> v[N]; n int a[N]; n long long com2(long long n) { return n * (n - 1) / 2; } n int main() { n   long long n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     if (a[i] >= m) { n       printf( 0 n ); n       return 0; n     } n   } n   for (int i = 1; i <= n; i++) n     if (a[i]) { n       for (int j = i; j <= n; j++) v[0].push_back(a[j]); n       break; n     } n   if (v[0].size() == 2) { n     long long lt = 1, rt = m / v[0][0] + 1, mid; n     long long ans = 0; n     while (lt <= rt) { n       mid = (lt + rt) >> 1; n       if (1LL * mid * v[0][0] + v[0][1] >= m) n         ans = mid, rt = mid - 1; n       else n         lt = mid + 1; n     } n     cout << ans << endl; n   } else if (v[0].size() == 3) { n     long long lt = 1, rt = 2000000000, mid; n     long long ans = 0; n     while (lt <= rt) { n       mid = (lt + rt) >> 1; n       long long p = com2(mid + 1); n       if (m / v[0][0] < p) { n         ans = mid, rt = mid - 1; n         continue; n       } n       p = p * v[0][0] + mid * v[0][1] + v[0][2]; n       if (p >= m) { n         ans = mid, rt = mid - 1; n       } else n         lt = mid + 1; n     } n     cout << ans << endl; n   } else { n     for (int i = 1; i < N; i++) { n       long long sum = 0; n       for (int j = 0; j < v[i - 1].size(); j++) { n         sum += v[i - 1][j]; n         v[i].push_back(sum); n         if (sum >= m) { n           printf( %d n , i); n           return 0; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n const int MAX = 2e5 + 5; n const long long MAX2 = 11; n const int MOD = 1000000000 + 7; n const long long INF = 20000; n const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; n const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; n const double pi = acos(-1); n long long tc, a, b, c, d, x[3]; n bool ans; n inline bool cek() { n   sort(x, x + 3); n   if (x[0] < 0 || 2 * x[2] - x[0] - x[1] > a || n       (a - 2 * x[2] + x[0] + x[1]) % 3 || x[0] + x[1] + x[2] > b || n       (x[0] + x[1] + x[2]) % 3 != b % 3) n     return 0; n   return 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> tc; n   while (tc--) { n     cin >> a >> b >> c >> d; n     if (c > d) c ^= d ^= c ^= d; n     a -= b; n     ans = 0; n     x[0] = 0, x[1] = c, x[2] = d; n     ans |= cek(); n     x[0] = 0, x[1] = c, x[2] = c + d; n     ans |= cek(); n     x[0] = 0, x[1] = d, x[2] = c + d; n     ans |= cek(); n     x[0] = 0, x[1] = c - d, x[2] = c; n     ans |= cek(); n     x[0] = 0, x[1] = d - c, x[2] = d; n     ans |= cek(); n     if (ans) n       cout <<  yes n ; n     else n       cout <<  no n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int a[11]; n int tmpa[11]; n int sum; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     tmpa[i] = a[i]; n     sum += a[i]; n   } n   sort(a, a + n); n   if (n == 1) { n     cout << -1 << endl; n   } else { n     if (n == 2 && a[0] == a[1]) { n       cout << -1 << endl; n     } else { n       cout << 1 << endl; n       for (int i = 0; i < n; i++) { n         if (tmpa[i] == a[0]) { n           cout << i + 1 << endl; n           break; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, vis[5009], d[5009][5009]; n vector<int> e; n vector<vector<int> > g; n char s[5009]; n void dfs(int v, int pr = -1) { n   int i; n   vis[v] = 1; n   for (auto u : g[v]) { n     if (d[u][pr] == 1 && pr != -1) { n       cout << u <<     << pr <<     << v; n       exit(0); n     } n     if (!vis[u]) dfs(u, v); n   } n } n int main() { n   int i, j; n   scanf( %d , &n); n   g.resize(n + 1); n   ; n   for (i = (1); i <= (n); i++) { n     scanf( %s , s); n     ; n     for (j = (0); j <= (n - 1); j++) n       if (s[j] ==  1 ) { n         g[i].push_back(j + 1); n         d[i][j + 1] = 1; n       } n   }; n   for (i = (1); i <= (n); i++) { n     if (!vis[i]) dfs(i); n   } n   cout <<  -1 ; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   int n, m; n   char c[2000][2000]; n   int rowcount[2000]; n   int colcount[2000], wallcount = 0; n   for (int i = 0; i < 2000; i++) { n     rowcount[i] = 0; n     colcount[i] = 0; n   } n   scanf( %d , &n); n   scanf( %d , &m); n   for (int i = 0; i < n; i++) scanf( %s , c[i]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (c[i][j] ==  * ) { n         rowcount[i]++; n         colcount[j]++; n         wallcount++; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (c[i][j] ==  *  && rowcount[i] + colcount[j] - 1 == wallcount || n           c[i][j] ==  .  && rowcount[i] + colcount[j] == wallcount) { n         printf( YES n ); n         printf( %d %d n , i + 1, j + 1); n         return 0; n       } n     } n   } n   printf( NO n ); n   return 0; n } n