#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e15; n struct Edge { n   int t, w; n } e[100010 << 1]; n queue<int> g[100010]; n long long d[100010], f[100010]; n int i, j, k, n, m, q, x, h[100010]; n struct _ { n   int x; n   _(int x) : x(x) {} n   bool operator<(const _& a) const { return d[x] > d[a.x]; } n }; n priority_queue<_> Q; n vector<int> V[100010]; n int done[100010 << 2]; n inline void Dij() { n   for (i = 2; i <= n; i++) d[i] = INF; n   Q.push(1); n   while (!Q.empty()) { n     x = Q.top().x; n     Q.pop(); n     for (int j : V[x]) n       if (d[e[j].t] > d[x] + e[j].w) { n         d[e[j].t] = d[x] + e[j].w; n         Q.push(e[j].t); n       } n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= m; ++i) { n     scanf( %d%d%d , &x, &e[i].t, &e[i].w); n     V[x].push_back(i); n   } n   Dij(); n   for (int i = 1; i <= q; ++i) { n     scanf( %d%d , &x, &k); n     if (x == 1) n       printf( %lld n , d[k] >= INF ? -1 : d[k]); n     else { n       for (int i = 1; i <= k; ++i) scanf( %d , &x), e[x].w++; n       for (int i = 2; i <= n; ++i) f[i] = INF; n       g[m = 0].push(1); n       k = min(k, n - 1); n       for (int i = 0; i <= m; ++i) n         while (!g[i].empty()) { n           x = g[i].front(); n           g[i].pop(); n           if (i > f[x]) continue; n           for (int j : V[x]) { n             long long y = f[x] + d[x] + e[j].w - d[e[j].t]; n             if (f[e[j].t] > y) { n               f[e[j].t] = y; n               if (y <= k) { n                 g[y].push(e[j].t); n                 if (y > m) m = y; n               } n             } n           } n         } n       for (int i = 2; i <= n; ++i) d[i] = min(INF, d[i] + f[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LL_INF = 0x3f3f3f3f3f3f3f3f; n const int xx[4] = {1, -1, 0, 0}; n const int yy[4] = {0, 0, 1, -1}; n int inline in() { n   int x = 0, c; n   for (; (unsigned)((c = getchar()) -  0 ) >= 10;) { n     if (c ==  - ) return -in(); n     if (!~c) throw ~0; n   } n   do { n     x = (x << 3) + (x << 1) + (c -  0 ); n   } while ((unsigned)((c = getchar()) -  0 ) < 10); n   return x; n } n int main() { n   cin.sync_with_stdio(false); n   cin.tie(0); n   int n, t; n   string buf; n   cin >> n >> t >> buf; n   int i = buf.find( . ) + 1; n   while (i < n && buf[i] <  5 ) i++; n   if (i == n) { n     cout << buf << endl; n     return 0; n   } n   while (t-- && buf[i] >=  5 ) { n     i--; n     bool flag = (buf[i] ==  . ); n     if (flag) i--; n     buf[i]++; n     if (flag) break; n   } n   int len = i + 1; n   for (; i >= 1 && buf[i] ==  9  + 1; i--) { n     buf[i] =  0 ; n     buf[i - 1]++; n   } n   if (buf[0] ==  9  + 1) { n     buf[0] =  0 ; n     buf =  1  + buf; n     len++; n   } n   buf.resize(len); n   cout << buf << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, i, e = 0, o = 0, k, p, j; n   long long int arr[100005]; n   vector<long long int> v[100005], od, ev; n   cin >> n >> k >> p; n   for (i = 0; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] % 2 == 0) { n       ev.push_back(arr[i]); n       e++; n     } else { n       od.push_back(arr[i]); n       o++; n     } n   } n   if (o < (k - p)) { n     cout <<  NO n ; n     return 0; n   } n   o = o - k + p; n   if (o % 2 == 1) { n     cout <<  NO n ; n     return 0; n   } n   if ((e + (o) / 2) < p) { n     cout <<  NO n ; n     return 0; n   } n   cout <<  YES n ; n   int j1 = 0, j2 = k - p; n   for (i = 0; i < od.size(); i++) { n     j1++; n     if (j1 <= k - p) { n       v[j1].push_back(od[i]); n     } else { n       j2++; n       if (j2 > k) { n         j2 = k; n       } n       v[j2].push_back(od[i]); n       i++; n       v[j2].push_back(od[i]); n     } n   } n   for (i = 0; i < ev.size(); i++) { n     j2++; n     if (j2 <= k) { n       v[j2].push_back(ev[i]); n     } else { n       v[k].push_back(ev[i]); n     } n   } n   for (i = 1; i <= k; i++) { n     cout << v[i].size() <<    ; n     for (j = 0; j < v[i].size(); j++) { n       cout << v[i][j] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n template <class T_T> n T_T gcd(T_T a, T_T b) { n   return b ? gcd(b, a % b) : a; n } n template <class T_T> n T_T f_max(T_T a, T_T b) { n   return a > b ? a : b; n } n using namespace std; n const int N = 100000; n int a[105][105], r[105], c[105], cnt_r[105], cnt_c[105], ans; n int main() { n   int n, m, i, j; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) { n       scanf( %d , &a[i][j]); n       r[i] += a[i][j]; n       c[j] += a[i][j]; n     } n   queue<int> q; n   for (i = 1; i <= n; i++) n     if (r[i] < 0) q.push(i); n   for (i = 1; i <= m; i++) n     if (c[i] < 0) q.push(i + n); n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     if (v <= n) { n       if (r[v] >= 0) continue; n       cnt_r[v]++; n       r[v] = -r[v]; n       for (i = 1; i <= m; i++) { n         c[i] -= 2 * a[v][i]; n         a[v][i] = -a[v][i]; n         if (c[i] < 0) q.push(i + n); n       } n     } else { n       v -= n; n       if (c[v] >= 0) continue; n       cnt_c[v]++; n       c[v] = -c[v]; n       for (i = 1; i <= n; i++) { n         r[i] -= 2 * a[i][v]; n         a[i][v] = -a[i][v]; n         if (r[i] < 0) q.push(i); n       } n     } n   } n   for (i = 1, ans = 0; i <= n; i++) n     if (cnt_r[i] & 1) ans++; n   printf( %d  , ans); n   for (i = 1; i <= n; i++) n     if (cnt_r[i] & 1) printf( %d  , i); n   puts(  ); n   for (i = 1, ans = 0; i <= m; i++) n     if (cnt_c[i] & 1) ans++; n   printf( %d  , ans); n   for (i = 1; i <= m; i++) n     if (cnt_c[i] & 1) printf( %d  , i); n   puts(  ); n } n


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


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int n, m, a = 0, b = 0, c = 0, d, h, p, x, y, z, i = 0, j = 0, n                       k = 0, l, r, rem, time = 0, ans = 0, mini = 1e18 + 1, n                       maxi = 0, count = 0, sum = 0, sign = 0, xx, yy, zz; n   cin >> n; n   if (n >= 22 || n <= 10) n     cout <<  0  n          <<   n ; n   else if (n > 10 && n < 20 || n == 21) n     cout <<  4  n          <<   n ; n   else if (n == 20) n     cout <<  15  n          <<   n ; n } n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n int main() { n   fast(); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> r; n   for (int i = 0; i < n; i++) { n     int tmp; n     cin >> tmp; n     r.push_back(tmp); n   } n   int m_lng = 0; n   for (int i = 0; i < n; i++) { n     int cnt = 1; n     int lng = 0; n     int sum = 0; n     for (int j = i; j < n; j++) { n       sum += r[j]; n       if (sum > 100 * cnt) lng = cnt; n       cnt++; n     } n     if (m_lng < lng) m_lng = lng; n   } n   cout << m_lng; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int fact[500005]; n void criba() { n   for (int i = 2; i * i < 500005; i++) n     if (fact[i] == 0) n       for (int j = i * i; j < 500005; j += i) fact[j] = i; n   for (int i = 2; i < 500005; i++) n     if (fact[i] == 0) fact[i] = i; n } n bool vis[500005]; n int F[500005], a[500005]; n int mask[1 << 9], primes[9]; n vector<pair<int, int> > G[500005]; n int main() { n   int n, q; n   criba(); n   while (cin >> n >> q) { n     for (int i = 0; i < n; i++) { n       scanf( %d , &a[i]); n       int num = a[i], top = 0; n       while (num > 1) { n         int f = fact[num]; n         while (num % f == 0) num /= f; n         primes[top++] = f; n       } n       mask[0] = 1; n       for (int j = 1, l; j < (1 << top); j++) { n         l = 31 - __builtin_clz(j & -j); n         mask[j] = mask[j ^ (1 << l)] * primes[l]; n         if (__builtin_popcount(j) % 2 == 0) n           G[i].push_back(make_pair(mask[j], 0)); n         else n           G[i].push_back(make_pair(mask[j], 1)); n       } n     } n     long long pos, cur = 0, last = 0; n     long long ans, val, id; n     for (int i = 0; i < q; i++) { n       scanf( %d , &pos); n       pos--; n       ans = cur; n       if (vis[pos]) { n         for (int j = 0; j < G[pos].size(); j++) { n           val = G[pos][j].first; n           id = G[pos][j].second; n           if (id) n             ans -= F[val]; n           else n             ans += F[val]; n           F[val]--; n         } n         cur--; n       } else { n         for (int j = 0; j < G[pos].size(); j++) { n           val = G[pos][j].first; n           id = G[pos][j].second; n           if (id) n             ans -= F[val]; n           else n             ans += F[val]; n           F[val]++; n         } n         cur++; n       } n       if (vis[pos] && a[pos] == 1) ans--; n       if (vis[pos]) n         ans = last - ans; n       else n         ans = last + ans; n       vis[pos] = 1 - vis[pos]; n       printf( %I64d n , ans); n       last = ans; n     } n   } n } n


#include <bits/stdc++.h> n int main() { n   int n, m, a[1003], b[1003], i, j, count = 0, k = 0, flag = 0; n   scanf( %d %d , &n, &m); n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   for (i = 0; i < m; i++) { n     scanf( %d , &b[i]); n   } n   for (i = 0; i < m; i++) { n     for (j = k; j < n; j++) { n       if (b[i] >= a[j]) { n         count++; n         flag = 1; n         break; n       } n     } n     if (flag == 1) { n       k = j + 1; n     } else if (flag == 0) { n       break; n     } n     flag = 0; n   } n   printf( %d n , count); n } n


#include <bits/stdc++.h> n using namespace std; n int n, c[3010]; n struct info { n   int x, y; n }; n struct as { n   int a, b, c; n } ans; n struct node { n   int x, id; n } a[3010]; n inline bool cmp(node a, node b) { return a.x > b.x; } n inline info max(info a, info b) { n   if (a.x < b.x) return b; n   return a; n } n struct seg { n   int lt[12010], rt[12010]; n   info mx[12010]; n   inline void build(int i, int l, int r) { n     lt[i] = l; n     rt[i] = r; n     if (l == r) { n       mx[i] = (info){a[l].x - a[l + 1].x, l}; n       return; n     } n     int mid = l + r >> 1; n     build(i * 2, l, mid); n     build(i * 2 + 1, mid + 1, r); n     mx[i] = max(mx[i * 2], mx[i * 2 + 1]); n   } n   inline info query(int i, int l, int r) { n     if (l <= lt[i] && r >= rt[i]) return mx[i]; n     int mid = lt[i] + rt[i] >> 1; n     info ans = {-1, 0}; n     if (l <= mid) ans = query(i * 2, l, r); n     if (r > mid) ans = max(ans, query(i * 2 + 1, l, r)); n     return ans; n   } n } A; n inline as max(as t1, as t2) { n   if (t1.a == 0) return t2; n   if (a[t1.a].x - a[t1.a + 1].x != a[t2.a].x - a[t2.a + 1].x) n     return a[t1.a].x - a[t1.a + 1].x > a[t2.a].x - a[t2.a + 1].x ? t1 : t2; n   if (a[t1.b].x - a[t1.b + 1].x != a[t2.b].x - a[t2.b + 1].x) n     return a[t1.b].x - a[t1.b + 1].x > a[t2.b].x - a[t2.b + 1].x ? t1 : t2; n   if (a[t1.c].x - a[t1.c + 1].x != a[t2.c].x - a[t2.c + 1].x) n     return a[t1.c].x - a[t1.c + 1].x > a[t2.c].x - a[t2.c + 1].x ? t1 : t2; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i].x), a[i].id = i; n   sort(a + 1, a + n + 1, cmp); n   A.build(1, 1, n); n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j < n; j++) n       if (2 * (j - i) >= i && i * 2 >= j - i) { n         int lk = max(j + (max(i, j - i) + 1) / 2, j + 1), n             rk = min(j + 2 * min(i, j - i), n); n         if (lk <= rk) ans = max(ans, (as){i, j, A.query(1, lk, rk).y}); n       } n   for (int i = 1; i <= ans.a; i++) c[a[i].id] = 1; n   for (int i = ans.a + 1; i <= ans.b; i++) c[a[i].id] = 2; n   for (int i = ans.b + 1; i <= ans.c; i++) c[a[i].id] = 3; n   for (int i = ans.c + 1; i <= n; i++) c[a[i].id] = -1; n   for (int i = 1; i <= n; i++) printf( %d  , c[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A, B; n char a[5555]; n char b[5555]; n int dp[5555][5555]; n int main() { n   scanf( %d%d , &A, &B); n   scanf( %s%s , a + 1, b + 1); n   int ans = 0; n   int i, j; n   for (i = 1; i <= A; i++) { n     for (j = 1; j <= B; j++) { n       if (a[i] == b[j]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2); n       dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1); n       dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1); n       ans = max(ans, dp[i][j]); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int x, l; n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     cnt = 0; n     cin >> x; n     if (x % 7 != 0) { n       cnt++; n     } n     x /= 7; n     cout << x + cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:36777216 ) n using namespace std; n long long pow_mod(long long x, long long y, long long z) { n   long long res = 1; n   while (y) { n     if (y & 1) res *= x, res %= z; n     x *= x, x %= z, y >>= 1; n   } n   return res % z; n } n void ext_gcd(long long a, long long b, long long &d, long long &x, n              long long &y) { n   if (!b) { n     d = a, x = 1, y = 0; n   } else { n     ext_gcd(b, a % b, d, y, x), y -= x * (a / b); n   } n } n long long inv(long long a, long long c) { n   long long d, x, y; n   ext_gcd(a, c, d, x, y); n   return (x + c) % c; n } n long long fac[111111]; n long long C(int x, int y) { n   if (x < y) return 0; n   return fac[x] * inv(fac[y], 1000000007) % 1000000007 * n          inv(fac[x - y], 1000000007) % 1000000007; n } n int n, v; n vector<pair<int, int> > vec; n long long gao(int l, int r, int pre) { n   if (l < 1) return 0; n   if (r > n) return 0; n   long long res; n   if (pre == 1) n     res = 1; n   else n     res = pow_mod(2, pre - 2, 1000000007); n   for (int i = 1; i < vec.size(); i++) { n     if (vec[i].second > r) { n       res *= C(vec[i].first - pre - 1, vec[i].second - r - 1); n       res %= 1000000007; n       if (res == 0) return 0; n       l = l - (vec[i].first - pre - 1 - (vec[i].second - r - 1)); n       r = vec[i].second; n     } else if (vec[i].second < l) { n       res *= C(vec[i].first - pre - 1, l - vec[i].second - 1); n       res %= 1000000007; n       if (res == 0) return 0; n       r = r + (vec[i].first - pre - 1 - (l - vec[i].second - 1)); n       l = vec[i].second; n     } else n       return 0; n     if (i == vec.size() - 1) return res; n     if (r > n || l < 1) return 0; n     pre = vec[i].first; n   } n   return res; n } n int main() { n   fac[0] = 1; n   for (int i = 1; i <= 100000; i++) fac[i] = fac[i - 1] * i % 1000000007; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &v); n     if (v) vec.push_back(make_pair(v, i)); n   } n   if (vec.size() == 0) { n     printf( %I64d n , pow_mod(2, n - 1, 1000000007)); n     return 0; n   } n   vec.push_back(make_pair(n + 1, n + 1)); n   sort(vec.begin(), vec.end()); n   long long ans; n   if (vec[0].first == 1) n     ans = gao(vec[0].second, vec[0].second, 1); n   else n     ans = gao(vec[0].second - vec[0].first + 1, vec[0].second, vec[0].first) + n           gao(vec[0].second, vec[0].second + vec[0].first - 1, vec[0].first) % n               1000000007; n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n struct BIT { n   long long T[1000100]; n   long long ALL; n   BIT() { ALL = 0; } n   void add(int pos, long long w) { n     ++pos; n     ALL += w; n     for (; pos < 1000100; pos += (pos & (-pos))) T[pos] += w; n   } n   long long all_from(int pos) { n     long long ret = ALL; n     for (; pos > 0; pos -= pos & (-pos)) ret -= T[pos]; n     return ret; n   } n }; n int N, M, H[1000100], FL[1000100], FR[1000100]; n stack<int> pos; n vector<int> ib, ie, spl, spr, val; n vector<int> ids; n inline bool icompare(const int& f, const int& s) { n   return ie[f] - ib[f] > ie[s] - ib[s]; n } n vector<double> ans; n vector<int> Q, qid; n inline bool qcompare(const int& f, const int& s) { return Q[f] > Q[s]; } n BIT rem_val, rem_sum; n int main() { n   scanf( %d , &N); n   H[0] = H[N + 1] = -1100000000; n   for (int i = 0; i < N; ++i) scanf( %d , &H[i + 1]); n   pos.push(0); n   for (int i = 1; i <= N; ++i) { n     while (H[pos.top()] > H[i]) pos.pop(); n     FL[i] = pos.top(); n     pos.push(i); n   } n   while (!pos.empty()) pos.pop(); n   pos.push(N + 1); n   for (int i = N; i > 0; --i) { n     while (H[pos.top()] >= H[i]) pos.pop(); n     FR[i] = pos.top(); n     pos.push(i); n   } n   for (int i = 1; i <= N; ++i) { n     ib.push_back(FL[i] + 1); n     ie.push_back(FR[i] - 1); n     val.push_back(H[i]); n     spl.push_back(i - FL[i] - 1); n     spr.push_back(FR[i] - i - 1); n   } n   for (int i = 0; i < ((int)(ib).size()); ++i) ids.push_back(i); n   sort(ids.begin(), ids.end(), icompare); n   scanf( %d , &M); n   ans.resize(M); n   Q.resize(M); n   for (int i = 0; i < M; ++i) qid.push_back(i); n   for (int i = 0; i < M; ++i) scanf( %d , &Q[i]); n   sort(qid.begin(), qid.end(), qcompare); n   long long val_all = 0, sum_all = 0; n   int cur = 0; n   for (int i = 0; i < ((int)(qid).size()); ++i) { n     int V = Q[qid[i]]; n     while (cur < ((int)(ids).size()) && ie[ids[cur]] - ib[ids[cur]] + 1 >= V) { n       int T = ids[cur++]; n       val_all += val[T] * 1LL * (ie[T] - ib[T] + 1); n       sum_all += val[T]; n       if (spl[T] > 0) n         rem_val.add(spl[T], spl[T] * 1LL * val[T]), rem_sum.add(spl[T], val[T]); n       if (spr[T] > 0) n         rem_val.add(spr[T], spr[T] * 1LL * val[T]), rem_sum.add(spr[T], val[T]); n     } n     long long out = val_all - (V - 1) * sum_all; n     out -= rem_val.all_from(V) - (V - 1) * rem_sum.all_from(V); n     ans[qid[i]] = ((double)out) / (N - V + 1); n   } n   for (int i = 0; i < M; ++i) printf( %.12lf n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n const double PI = acos(-1.0); n using namespace std; n char a[2000010], b[2000010]; n int main() { n   int n; n   int i; n   int x, y, z; n   int p, q; n   while (~scanf( %d %s %s , &n, a, b)) { n     x = y = z = 0; n     for (i = 0; i < 2 * n; i++) { n       if (a[i] ==  1  && b[i] ==  1 ) { n         z++; n       } else if (a[i] ==  1 ) { n         x++; n       } else if (b[i] ==  1 ) { n         y++; n       } n     } n     p = x + (z + 1) / 2; n     q = y + z - (z + 1) / 2; n     if (p == q || p + 1 == q) { n       puts( Draw ); n     } else if (p > q) { n       puts( First ); n     } else { n       puts( Second ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T; n string hxt[16]; n int main() { n   cin >> T; n   while (T--) { n     int n, m; n     cin >> n >> m; n     for (int i = 1; i <= n; i++) cin >> hxt[i]; n     bool iif = false; n     for (int i = 0; i < m; i++) { n       char x = hxt[1][i]; n       for (char j =  a ; j <=  z ; j++) { n         hxt[1][i] = j; n         bool flag = true; n         for (int k = 2; k <= n; k++) { n           int js = 0; n           for (int l = 0; l < m; l++) { n             if (hxt[k][l] != hxt[1][l]) js++; n             if (js > 1) break; n           } n           if (js > 1) { n             flag = false; n             break; n           } n         } n         if (flag) { n           cout << hxt[1] << endl; n           iif = true; n           break; n         } n         hxt[1][i] = x; n       } n       if (iif) break; n     } n     if (!iif) cout << -1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<string> v; n   for (int i = 0; i < 3; i++) { n     string s; n     cin >> s; n     v.push_back(s); n   } n   vector<string> so; n   vector<string> po; n   vector<string> mo; n   for (int i = 0; i < v.size(); i++) { n     if (v[i][1] ==  s ) n       so.push_back(v[i]); n     else if (v[i][1] ==  p ) n       po.push_back(v[i]); n     else if (v[i][1] ==  m ) n       mo.push_back(v[i]); n   } n   sort(so.begin(), so.end()); n   sort(po.begin(), po.end()); n   sort(mo.begin(), mo.end()); n   if (v[0] == v[1] && v[1] == v[2]) n     cout << 0 << endl; n   else if (v[0] == v[1] || v[0] == v[2] || v[1] == v[2]) n     cout << 1 << endl; n   else if (so.size() == 3) { n     int m1 = (so[2][0] -  0 ) - (so[1][0] -  0 ); n     int m2 = (so[1][0] -  0 ) - (so[0][0] -  0 ); n     if (m1 == 1 && m2 == 1) n       cout <<  0  << endl; n     else if (m1 <= 2 || m2 <= 2) n       cout <<  1  << endl; n     else n       cout <<  2  << endl; n   } else if (mo.size() == 3) { n     int m1 = (mo[2][0] -  0 ) - (mo[1][0] -  0 ); n     int m2 = (mo[1][0] -  0 ) - (mo[0][0] -  0 ); n     if (m1 == 1 && m2 == 1) n       cout <<  0  << endl; n     else if (m1 <= 2 || m2 <= 2) n       cout <<  1  << endl; n     else n       cout <<  2  << endl; n   } else if (po.size() == 3) { n     int m1 = (po[2][0] -  0 ) - (po[1][0] -  0 ); n     int m2 = (po[1][0] -  0 ) - (po[0][0] -  0 ); n     if (m1 == 1 && m2 == 1) n       cout <<  0  << endl; n     else if (m1 <= 2 || m2 <= 2) n       cout <<  1  << endl; n     else n       cout <<  2  << endl; n   } else if (so.size() == 2) { n     int m1 = (so[1][0] -  0 ) - (so[0][0] -  0 ); n     if (m1 == 1 || m1 == 2) n       cout <<  1  << endl; n     else n       cout <<  2 n ; n   } else if (mo.size() == 2) { n     int m1 = (mo[1][0] -  0 ) - (mo[0][0] -  0 ); n     if (m1 == 1 || m1 == 2) n       cout <<  1  << endl; n     else n       cout <<  2 n ; n   } else if (po.size() == 2) { n     int m1 = (po[1][0] -  0 ) - (po[0][0] -  0 ); n     if (m1 == 1 || m1 == 2) n       cout <<  1  << endl; n     else n       cout <<  2 n ; n   } else n     cout <<  2 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 2; n int n; n int a[N]; n map<int, int> m; n map<pair<int, int>, bool> checked; n int main() { n   cin >> n; n   int zero = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %d , a + i); n     if (!a[i]) zero++; n     ; n     m[a[i]]++; n   } n   sort(a, a + n); n   int ans = -1; n   int help1, help2, help3; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < n; ++j) n       if (i != j) { n         if (!a[i] and (!a[j])) continue; n         if (checked[make_pair(a[i], a[j])]) continue; n         checked[make_pair(a[i], a[j])] = true; n         map<int, int> m1; n         help3 = 2; n         m1[a[i]]++, m1[a[j]]++; n         help1 = a[i]; n         help2 = a[j]; n         while (m1[help1 + help2] < m[help1 + help2]) { n           m1[help1 + help2]++; n           help3++; n           help2 += help1; n           help1 = help2 - help1; n         } n         ans = max(ans, help3); n       } n   ans = max(ans, zero); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 4005; n vector<int> v[maxn]; n int vis[maxn][maxn]; n int main(void) { n   int n, m, ans = maxn; n   memset(vis, 0, sizeof(vis)); n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     v[x].push_back(y); n     v[y].push_back(x); n     vis[x][y] = vis[y][x] = 1; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       if (!vis[i][j]) continue; n       for (int k = j + 1; k <= n; k++) { n         if (!vis[i][k] || !vis[k][j]) continue; n         int cur = 0; n         int len = v[i].size(); n         for (int d = 0; d < len; d++) { n           if (v[i][d] != j && v[i][d] != k) cur++; n         } n         len = v[j].size(); n         for (int d = 0; d < len; d++) { n           if (v[j][d] != i && v[j][d] != k) cur++; n         } n         len = v[k].size(); n         for (int d = 0; d < len; d++) { n           if (v[k][d] != i && v[k][d] != j) cur++; n         } n         ans = min(ans, cur); n       } n     } n   } n   if (ans == maxn) n     printf( -1 n ); n   else n     printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int T, N; n int arr[500005]; n stack<int> stk; n vector<pair<int, int>> v; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> T; n   while (T--) { n     cin >> N; n     bool pos = 1; n     while (stk.size()) { n       stk.pop(); n     } n     v.clear(); n     for (int i = 1; i <= N; i++) { n       while (stk.size() && stk.top() == i) { n         stk.pop(); n       } n       cin >> arr[i]; n       if (arr[i] == -1) { n         if (stk.empty()) { n           arr[i] = N + 1; n         } else { n           arr[i] = stk.top(); n         } n       } n       v.push_back({-arr[i], i}); n       if (stk.size() && stk.top() < arr[i]) { n         pos = 0; n       } n       stk.push(arr[i]); n     } n     if (pos) { n       sort(v.begin(), v.end()); n       int cnt = N; n       for (auto p : v) { n         arr[p.second] = cnt--; n       } n       for (int i = 1; i <= N; i++) { n         cout << arr[i] <<    ; n       } n       cout <<   n ; n     } else { n       cout << -1 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n namespace io { n const int __SIZE = (1 << 21) + 1; n char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, n                                            __c, qu[55]; n int __f, qr, _eof; n inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; } n inline void gc(char &x) { n   x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                    (iS == iT ? EOF : *iS++)) n                 : *iS++); n } n inline void pc(char x) { n   *oS++ = x; n   if (oS == oT) flush(); n } n inline void pstr(const char *s) { n   int __len = strlen(s); n   for (__f = 0; __f < __len; ++__f) pc(s[__f]); n } n inline void gstr(char *s) { n   for (__c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                          (iS == iT ? EOF : *iS++)) n                        : *iS++); n        __c < 32 || __c > 126 || __c ==    ;) n     __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                        (iS == iT ? EOF : *iS++)) n                     : *iS++); n   for (; __c > 31 && __c < 127 && __c !=    ; n        ++s, __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                               (iS == iT ? EOF : *iS++)) n                             : *iS++)) n     *s = __c; n   *s = 0; n } n template <class I> n inline bool gi(I &x) { n   _eof = 0; n   for (__f = 1, n       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                         (iS == iT ? EOF : *iS++)) n                       : *iS++); n        (__c <  0  || __c >  9 ) && !_eof; n        __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                          (iS == iT ? EOF : *iS++)) n                        : *iS++)) { n     if (__c ==  - ) __f = -1; n     _eof |= __c == EOF; n   } n   for (x = 0; __c <=  9  && __c >=  0  && !_eof; n        __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), n                          (iS == iT ? EOF : *iS++)) n                        : *iS++)) n     x = x * 10 + (__c & 15), _eof |= __c == EOF; n   x *= __f; n   return !_eof; n } n template <class I> n inline void print(I x) { n   if (!x) pc( 0 ); n   if (x < 0) pc( - ), x = -x; n   while (x) qu[++qr] = x % 10 +  0 , x /= 10; n   while (qr) pc(qu[qr--]); n } n struct Flusher_ { n   ~Flusher_() { flush(); } n } io_flusher_; n }  // namespace io n using io::gc; n using io::gi; n using io::gstr; n using io::pc; n using io::print; n using io::pstr; n using ll = long long; n using pii = pair<int, int>; n const int MOD = 1000000007; n pii dat[500005 << 2]; n bool laz[500005 << 2]; n void push(int idx, int l, int r) { n   if (!laz[idx] || l == r) return; n   dat[idx * 2] = {dat[idx * 2].second, dat[idx * 2].first}; n   laz[idx * 2] = !laz[idx * 2]; n   dat[idx * 2 + 1] = {dat[idx * 2 + 1].second, dat[idx * 2 + 1].first}; n   laz[idx * 2 + 1] = !laz[idx * 2 + 1]; n   laz[idx] = 0; n } n void upd(int idx, int l, int r, int i, pii v) { n   if (!(l <= i && i <= r)) return; n   push(idx, l, r); n   if (l == r) { n     dat[idx] = v; n     return; n   } n   upd(idx * 2, l, (l + r) / 2, i, v); n   upd(idx * 2 + 1, (l + r) / 2 + 1, r, i, v); n   dat[idx] = {max(dat[idx * 2].first, dat[idx * 2 + 1].first), n               max(dat[idx * 2].second, dat[idx * 2 + 1].second)}; n } n void tag(int idx, int l, int r, int ql, int qr) { n   if (qr < l || r < ql) return; n   push(idx, l, r); n   if (ql <= l && r <= qr) { n     dat[idx] = {dat[idx].second, dat[idx].first}; n     laz[idx] = !laz[idx]; n     return; n   } n   tag(idx * 2, l, (l + r) / 2, ql, qr); n   tag(idx * 2 + 1, (l + r) / 2 + 1, r, ql, qr); n   dat[idx] = {max(dat[idx * 2].first, dat[idx * 2 + 1].first), n               max(dat[idx * 2].second, dat[idx * 2 + 1].second)}; n } n pii el2[500005]; n vector<pii> elist[500005]; n pii dfsfar(int u, int f) { n   pii ans = {0, u}; n   for (pii &v : elist[u]) n     if (v.first != f) ans = max(ans, dfsfar(v.first, u)); n   return {ans.first + 1, ans.second}; n } n int clck = 1; n int n; n int L[500005], R[500005]; n int qr[500005], ans[500005]; n void dfs(int u, int f, int dep, int cnt) { n   L[u] = clck++; n   if (cnt % 2 == 0) n     upd(1, 1, n, L[u], {dep, 0}); n   else n     upd(1, 1, n, L[u], {0, dep}); n   for (pii &v : elist[u]) n     if (v.first != f) dfs(v.first, u, dep + 1, cnt + v.second); n   R[u] = clck - 1; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   gi(n); n   for (int i = (0); i < (n - 1); i++) { n     int u, v, w; n     gi(u), gi(v), gi(w); n     el2[i] = {u, v}; n     elist[u].push_back({v, w}); n     elist[v].push_back({u, w}); n   } n   int root = dfsfar(1, -1).second; n   dfs(root, -1, 0, 0); n   int q; n   gi(q); n   for (int i = (0); i < (q); i++) gi(qr[i]); n   for (int i = (0); i < (q); i++) { n     int par = el2[qr[i] - 1].first, ch = el2[qr[i] - 1].second; n     if (R[par] - L[par] < R[ch] - L[ch]) swap(par, ch); n     tag(1, 1, n, L[ch], R[ch]); n     ans[i] = max(ans[i], dat[1].first); n   } n   root = dfsfar(root, -1).second; n   memset(dat, 0, sizeof dat); n   memset(laz, 0, sizeof laz); n   clck = 1; n   dfs(root, -1, 0, 0); n   for (int i = (0); i < (q); i++) { n     int par = el2[qr[i] - 1].first, ch = el2[qr[i] - 1].second; n     if (R[par] - L[par] < R[ch] - L[ch]) swap(par, ch); n     tag(1, 1, n, L[ch], R[ch]); n     ans[i] = max(ans[i], dat[1].first); n     print(ans[i]), pc(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int yekdast(char c, int l, int r) { n   int ans = 0; n   for (int i = l; i <= r; i++) { n     if (s[i] != c) ans++; n   } n   return ans; n } n int check(char c, int l, int r) { n   if ((r - l) > 1) { n     int mid1 = (floor((l * 1.0 + r * 1.0) / 2.0)), n         mid2 = (ceil((l * 1.0 + r * 1.0) / 2.0)); n     int first = check(char(c + 1), l, mid1) + yekdast(c, mid2, r); n     int second = check(char(c + 1), mid2, r) + yekdast(c, l, mid1); n     return min(first, second); n   } else if (r == l + 1) { n     int first = check(char(c + 1), l, l) + yekdast(c, r, r); n     int second = check(char(c + 1), r, r) + yekdast(c, l, l); n     return min(first, second); n   } else { n     return yekdast(c, l, r); n   } n } n int t, n; n int main() { n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> n >> s; n     cout << check( a , 0, n - 1) << endl; n   } n } n


#include <bits/stdc++.h> n const int N = 1e5 + 2, p = 1e9 + 7; n int siz[N], f[N]; n int n, m, x, y, z, i, c; n inline void read(int &x) { n   c = getchar(); n   while ((c < 48) || (c > 57)) c = getchar(); n   x = c ^ 48; n   c = getchar(); n   while ((c >= 48) && (c <= 57)) { n     x = x * 10 + (c ^ 48); n     c = getchar(); n   } n } n int getf(register int x) { n   if (f[x] == x) return f[x]; n   f[x] = getf(f[x]); n   siz[f[x]] += siz[x]; n   siz[x] = 0; n   return f[x]; n } n inline int ksm(register int x, register int y) { n   register int r = 1; n   while (y) { n     if (y & 1) r = (long long)r * x % p; n     x = (long long)x * x % p; n     y >>= 1; n   } n   return r; n } n int main() { n   read(n); n   read(m); n   for (i = 1; i <= n; i++) siz[f[i] = i] = 1; n   for (i = 1; i < n; i++) { n     read(x); n     read(y); n     read(z); n     if (z == 0) { n       siz[getf(y)] += siz[getf(x)]; n       siz[f[x]] = 0; n       f[f[x]] = f[y]; n     } n   } n   c = ksm(n, m); n   for (i = 1; i <= n; i++) n     if (siz[i]) c = (c - ksm(siz[i], m) + p) % p; n   printf( %d , c); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char name[2000], part[2000000]; n int work() { n   int p = 0; n   for (int i = 0; i < m; i++) { n     if (part[i] == name[p]) p++; n     if (p == n) return i; n   } n   return m; n } n int main() { n   scanf( %s , name); n   scanf( %s , part); n   n = strlen(name), m = strlen(part); n   int x = work(); n   reverse(name, name + n); n   reverse(part, part + m); n   int y = work(); n   printf( %d n , max(0, m - y - x - 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(int b, int pw) { n   long long int res = 1; n   for (int i = 1; i <= pw; i++) { n     res = res * b; n   } n   return res; n } n long long int typ[1000000]; n int main() { n   ios_base::sync_with_stdio(false); n   long long int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> typ[i]; n   } n   set<int> prev; n   vector<pair<int, int> > ns; n   long long int cnt = 0; n   long long int from = 1; n   for (int i = 1; i <= n; i++) { n     if (prev.find(typ[i]) != prev.end()) { n       ns.push_back(make_pair(from, i)); n       prev.clear(); n       from = i + 1; n     } else { n       prev.insert(typ[i]); n     } n   } n   if (ns.size() == 0) { n     printf( -1 n ); n     return 0; n   } n   cout << ns.size() << endl; n   int temp = ns.size(); n   for (int i = 0; i < ns.size(); i++) { n     if (i == temp - 1) { n       cout << ns[i].first <<     << n << endl; n       return 0; n     } n     cout << ns[i].first <<     << ns[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5010; n int n, m; n int pnt[N * 4], last; n char tab[N][N], a[N][N]; n int find(int x) { n   if (x != pnt[x]) pnt[x] = find(pnt[x]); n   return pnt[x]; n } n int id(int x, int y, int d) { return (x * m + y) * 4 + d; } n void add(int x, int y) { n   pnt[id(x, y, 0)] = x - 1 >= 0 ? id(x - 1, y, 0) : last; n   pnt[id(x, y, 1)] = x + 1 < n ? id(x + 1, y, 1) : last; n   pnt[id(x, y, 2)] = y - 1 >= 0 ? id(x, y - 1, 2) : last; n   pnt[id(x, y, 3)] = y + 1 < m ? id(x, y + 1, 3) : last; n } n void solve() { n   int ans = 0, cnt; n   last = n * m * 4; n   for (int i = 0; i < n; ++i) scanf( %s , tab[i]); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) { n       if (tab[i][j] ==  . ) continue; n       for (int u = 0; u <= last; ++u) pnt[u] = u; n       for (int u = 0; u < n; ++u) n         for (int v = 0; v < m; ++v) { n           a[u][v] = tab[u][v]; n           if (a[u][v] ==  . ) add(u, v); n         } n       int x = i, y = j, t = 0; n       while (1) { n         t++; n         int dir; n         if (a[x][y] ==  U ) dir = 0; n         if (a[x][y] ==  D ) dir = 1; n         if (a[x][y] ==  L ) dir = 2; n         if (a[x][y] ==  R ) dir = 3; n         add(x, y); n         int p = find(id(x, y, dir)); n         if (p == last) break; n         x = p / 4 / m; n         y = p / 4 % m; n       } n       if (ans < t) n         ans = t, cnt = 1; n       else if (ans == t) n         cnt++; n     } n   printf( %d %d n , ans, cnt); n } n int main() { n   while (scanf( %d%d , &n, &m) != EOF) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> adj[100005]; n long long a[100005]; n long long col; n bool ok; n bool dfs(long long v, long long par) { n   ok &= (col == a[v]); n   for (auto i : adj[v]) { n     if (i != par) dfs(i, v); n   } n } n bool fn(long long v) { n   bool res = 1; n   for (auto i : adj[v]) { n     ok = 1; n     col = a[i]; n     dfs(i, v); n     res &= ok; n   } n   return res; n } n int main() { n   int t = 1; n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   while (t--) { n     long long n; n     cin >> n; n     long long i; n     long long p = -1, q = -1; n     for (i = 1; i < n; i++) { n       long long x, y; n       cin >> x >> y; n       adj[x].push_back(y); n       adj[y].push_back(x); n     } n     for (i = 0; i < n; i++) cin >> a[i + 1]; n     for (i = 1; i <= n; i++) { n       for (auto j : adj[i]) { n         if (a[j] != a[i]) { n           p = i; n           q = j; n         } n       } n     } n     if (q == -1) { n       cout <<  YES  << endl; n       cout << 1 << endl; n       continue; n     } n     bool a1 = fn(p); n     bool a2 = fn(q); n     if (a1) { n       cout <<  YES  << endl; n       cout << p << endl; n     } else if (a2) { n       cout <<  YES  << endl; n       cout << q << endl; n     } else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int R, r, k; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     scanf( %d%d%d , &R, &r, &k); n     double a = R, b = r; n     printf( %lf n , 1 / (1 / (a - b) + k * k * (a - b) / a / b)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool checkmin(T &a, const T &b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T> n inline bool checkmax(T &a, const T &b) { n   return a < b ? a = b, 1 : 0; n } n const int MAXN = 2600 / 2; n const int MAXM = 51; n const int MMAX = MAXN * MAXM + MAXN + MAXM + 100; n const int di[] = {0, 0, 1, 0, -1}; n const int dj[] = {0, 1, 0, -1, 0}; n struct Graph { n  public: n   int n, m; n   int adj[MAXN][MAXM]; n   void init() { n     n = m = 0; n     memset(adj, 0, sizeof(adj)); n   } n   void insert(int u, int v) { n     n = max(n, v + 1); n     m = max(m, v + 1); n     adj[u][v] = 1; n   } n   int find_ans() { n     build_dlx(); n     for (int ans = 0; ans <= n; ++ans) { n       if (dfs(0, ans)) { n         return ans; n       } n     } n     return -1; n   } n  n  private: n   int head; n   int U[MMAX], D[MMAX], L[MMAX], R[MMAX], CN[MMAX], RN[MMAX]; n   void addUD(const int &a, const int &h) { n     U[a] = h; n     D[a] = D[h]; n     U[D[h]] = a; n     D[h] = a; n     CN[a] = h; n   } n   void addLR(const int &a, const int &h) { n     L[a] = h; n     R[a] = R[h]; n     L[R[h]] = a; n     R[h] = a; n     RN[a] = h; n   } n   void add(const int &k, const int &r, const int &c) { n     addUD(k, c); n     addLR(k, r); n   } n   void remove(const int &k) { n     for (int j = R[k]; j != k; j = R[j]) { n       for (int i = D[j]; i != j; i = D[i]) { n         L[R[i]] = L[i]; n         R[L[i]] = R[i]; n       } n       D[U[j]] = D[j]; n       U[D[j]] = U[j]; n     } n   } n   void unremove(const int &k) { n     for (int j = L[k]; j != k; j = L[j]) { n       D[U[j]] = j; n       U[D[j]] = j; n       for (int i = U[j]; i != j; i = U[i]) { n         L[R[i]] = i; n         R[L[i]] = i; n       } n     } n   } n   void build_dlx() { n     head = MMAX - 1; n     U[head] = D[head] = L[head] = R[head] = head; n     int cnt = 0; n     for (int i = 0; i < m; i++) { n       U[cnt] = D[cnt] = cnt; n       addLR(cnt++, head); n     } n     for (int i = 0; i < n; i++) { n       L[cnt] = R[cnt] = cnt; n       addUD(cnt++, head); n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) n         if (adj[i][j]) { n           addLR(cnt, m + i); n           addUD(cnt, j); n           cnt++; n         } n     } n   } n   int h() { n     int hash[MAXM] = {}; n     int ans = 0; n     for (int c = R[head]; c != head; c = R[c]) { n       if (hash[c] == 0) { n         hash[c] = 1; n         ++ans; n         for (int j = D[c]; j != c; j = D[j]) { n           for (int i = R[j]; i != j; i = R[i]) { n             if (CN[i] != head) { n               hash[CN[i]] = 1; n             } n           } n         } n       } n     } n     return ans; n   } n   bool dfs(int k, int lim) { n     if (k + h() > lim) { n       return false; n     } n     if (R[head] == head) { n       return true; n     } n     int c; n     c = R[head]; n     L[R[c]] = L[c]; n     R[L[c]] = R[c]; n     for (int i = D[c]; i != c; i = D[i]) { n       L[R[i]] = L[i]; n       R[L[i]] = R[i]; n     } n     for (int i = D[c]; i != c; i = D[i]) { n       remove(RN[i]); n       if (dfs(k + 1, lim)) { n         return true; n       } n       unremove(RN[i]); n     } n     for (int i = U[c]; i != c; i = U[i]) { n       L[R[i]] = i; n       R[L[i]] = i; n     } n     L[R[c]] = c; n     R[L[c]] = c; n     return false; n   } n } G; n int N, M; n int change(const int &i, const int &j) { return i * M + j; } n int main() { n   while (scanf( %d%d , &N, &M) == 2) { n     G.init(); n     for (int i = 0; i < N; i++) { n       for (int j = 0; j < M; j++) { n         for (int p = 0; p < 5; p++) { n           int ii = i + di[p], jj = j + dj[p]; n           if (0 <= ii && ii < N && 0 <= jj && jj < M) { n             G.insert(change(i, j), change(ii, jj)); n           } n         } n       } n     } n     int res = G.find_ans(); n     printf( %d n , M * N - res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005; n priority_queue<pair<long long, int> > Q; n int h[N], a[N]; n int n, m, k, p; n bool check(long long lim) { n   static long long now[N]; n   for (int i = 1; i <= n; i++) now[i] = lim; n   while (!Q.empty()) Q.pop(); n   for (int i = 1; i <= n; i++) n     if (now[i] - 1ll * a[i] * m < h[i]) Q.push(make_pair(-lim / a[i], i)); n   for (int i = 1; i <= m; i++) n     for (int j = 1; j <= k; j++) { n       if (Q.empty()) return true; n       pair<long long, int> mx = Q.top(); n       Q.pop(); n       if (-mx.first < i) return false; n       now[mx.second] += p; n       if (now[mx.second] - 1ll * a[mx.second] * m < h[mx.second]) n         Q.push(make_pair(-now[mx.second] / a[mx.second], mx.second)); n     } n   return Q.empty(); n } n int main() { n   scanf( %d%d%d%d , &n, &m, &k, &p); n   for (int i = 1; i <= n; i++) scanf( %d%d , &h[i], &a[i]); n   long long l = 0, r = 6e12, ans; n   while (l <= r) { n     long long mid = (l + r) >> 1ll; n     if (check(mid)) n       ans = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)3e5 + 5; n const int K = (int)3e5 + 5; n vector<pair<int, int>> adj[N]; n queue<pair<int, int>> q; n bool visited[N]; n int res[300005]; n int n; n int k; n int d; n int main() { n   scanf( %d%d%d , &n, &k, &d); n   for (int i = 0; i < k; i++) { n     int place; n     scanf( %d , &place); n     q.push({place, 0}); n   } n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].push_back({v, i + 1}); n     adj[v].push_back({u, i + 1}); n   } n   while (!q.empty()) { n     int pos = q.front().first; n     int from = q.front().second; n     q.pop(); n     if (visited[pos]) continue; n     visited[pos] = 1; n     for (pair<int, int> u : adj[pos]) { n       if (u.first != from) { n         if (visited[u.first]) n           res[u.second] = 1; n         else n           q.push({u.first, pos}); n       } n     } n   } n   int rescnt = 0; n   for (int i = 1; i <= n - 1; i++) n     if (res[i]) rescnt++; n   cout << rescnt << endl; n   for (int x = 1; x <= n - 1; x++) n     if (res[x]) cout << x <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt, n; n string ss; n int main() { n   cin >> n >> ss; n   for (int i = 0; i < n; i++) { n     if (i < n - 1 && ((ss[i] ==  R  && ss[i + 1] ==  U ) || n                       (ss[i] ==  U  && ss[i + 1] ==  R ))) { n       i++; n       cnt++; n     } else n       cnt++; n   } n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s, i, x, y; n   cin >> n >> s; n   int sol = 100; n   int f = 1; n   for (i = 0; i < n; i++) { n     cin >> x >> y; n     if (x < s) { n       if (y) { n         sol = min(sol, y); n       } n     } n     if (x < s || (x == s && y == 0)) { n       f = 0; n     } n   } n   if (f) n     cout << -1 << endl; n   else n     cout << 100 - sol << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long l, r, ans = 0; n int main() { n   cin >> l >> r; n   for (long long i = 1; i <= r; i *= 2) { n     for (long long j = 1; j <= r; j *= 3) { n       if (i * j >= l && i * j <= r) ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using pii = pair<int, int>; n using vpii = vector<pii>; n using vi = vector<int>; n using vvi = vector<vi>; n using ll = long long; n using vll = vector<long long>; n template <class T> n using min_queue = priority_queue<T, vector<T>, greater<T>>; n template <class T> n istream &operator>>(istream &, vector<T> &); n template <class T> n ostream &operator<<(ostream &, const vector<T> &); n template <class T, class U> n istream &operator>>(istream &, pair<T, U> &); n template <class T, class U> n ostream &operator<<(ostream &, const pair<T, U> &); n template <class T> n struct Inf { n   static constexpr T inf() { n     return std::numeric_limits<T>::has_infinity() n                ? std::numeric_limits<T>::infinty() n                : std::numeric_limits<T>::max(); n   } n }; n template <> n struct Inf<int> { n   static constexpr int inf() { return 0x3f3f3f3f; } n }; n template <> n struct Inf<long long> { n   static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } n }; n constexpr int INF = Inf<int>::inf(); n constexpr ll BINF = Inf<ll>::inf(); n int solve() { n   int n, k; n   cin >> n >> k; n   vi a(n); n   cin >> a; n   ll ans = a[n - 1] - a[0]; n   vi wtf; n   for (int i = 0; i + 1 < n; i++) wtf.push_back(a[i] - a[i + 1]); n   sort(wtf.begin(), wtf.end()); n   for (int i = 0; i < k - 1; i++) ans += wtf[i]; n   cout << ans << endl; n   return 0; n } n int main() { n   ios::sync_with_stdio(0); n   solve(); n   return 0; n } n template <class T> n istream &operator>>(istream &is, vector<T> &v) { n   for (auto it = v.begin(); it != v.end(); ++it) is >> *it; n   return is; n } n template <class T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   for (auto it = v.begin(); it != v.end();) n     os << *it, os <<    n [++it == v.end()]; n   return os; n } n template <class T, class U> n istream &operator>>(istream &is, pair<T, U> &p) { n   return is >> p.first >> p.second; n } n template <class T, class U> n ostream &operator<<(ostream &os, const pair<T, U> &p) { n   return os << p.first <<     << p.second; n } n


#include <bits/stdc++.h> n using namespace std; n typedef pair<long long, long long> ll; n typedef vector<long long> vl; n typedef vector<ll> vll; n typedef vector<vl> vvl; n template <typename T> n ostream &operator<<(ostream &o, vector<T> v) { n   if (v.size() > 0) o << v[0]; n   for (unsigned i = 1; i < v.size(); i++) o <<     << v[i]; n   return o <<   n ; n } n template <typename U, typename V> n ostream &operator<<(ostream &o, pair<U, V> p) { n   return o <<  (  << p.first <<  ,   << p.second <<  )  ; n } n template <typename T> n istream &operator>>(istream &in, vector<T> &v) { n   for (unsigned i = 0; i < v.size(); i++) in >> v[i]; n   return in; n } n template <typename T> n istream &operator>>(istream &in, pair<T, T> &p) { n   in >> p.first; n   in >> p.second; n   return in; n } n vvl g(111000); n vl ind(111000, 0), vis(111000, false); n long long c = 0; n bool rec(long long node, long long p) { n   vl ch; n   ind[node] = c++; n   vis[node] = 1; n   for (auto &it : g[node]) { n     if (it == p) continue; n     if (!vis[it]) { n       if (!rec(it, node)) ch.push_back((it)); n     } else if (ind[node] < ind[it]) n       ch.push_back((it)); n   } n   for (long long i = 0; i + 1 < ch.size(); i += 2) n     cout << ch[i] <<     << node <<     << ch[i + 1] <<   n ; n   if (ch.size() % 2 == 1) { n     cout << p <<     << node <<     << ch[ch.size() - 1] <<   n ; n     return true; n   } n   return false; n } n int main() { n   long long n, m; n   cin >> n >> m; n   if (m % 2 == 1) { n     cout <<  No solution  n          <<   n ; n     return 0; n   } n   while (m--) { n     long long x, y; n     cin >> x >> y; n     g[x].push_back((y)); n     g[y].push_back((x)); n   } n   rec(1, -1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9; n const int maxn = 100010; n const int maxbit = 18; n const int sz = 1500; n inline int read() { n   int x = 0, f = 1; n   char ch = 0; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; n   return x * f; n } n struct node { n   int l, r, tid, ans, id; n   node() {} n   node(int _l, int _r, int _tid, int _ans, int _id) { n     l = _l; n     r = _r; n     tid = _tid; n     ans = _ans; n     id = _id; n   } n } que[maxn]; n struct node2 { n   int p, fr, to; n   node2() {} n   node2(int _p, int _fr, int _to) { n     p = _p; n     fr = _fr; n     to = _to; n   } n } cz[maxn]; n vector<int> oo; n inline int bl(int x) { return (x - 1) / sz; } n bool cmp(node x, node y) { n   if (bl(x.l) != bl(y.l)) n     return x.l < y.l; n   else if (bl(x.r) != bl(y.r)) n     return x.r < y.r; n   else n     return x.tid < y.tid; n } n bool cmp2(node x, node y) { return x.id < y.id; } n int n, q, cntz, cntq; n int a[maxn], fl[maxn], Now, L, R, cnt[maxn << 2]; n inline void add(int x) { n   --fl[cnt[x]]; n   ++fl[++cnt[x]]; n } n inline void del(int x) { n   --fl[cnt[x]]; n   ++fl[--cnt[x]]; n } n inline void go(node2 &t) { n   if (t.p >= L && t.p <= R) del(t.fr), add(t.to); n   a[t.p] = t.to; n } n inline void re(node2 &t) { n   if (t.p >= L && t.p <= R) del(t.to), add(t.fr); n   a[t.p] = t.fr; n } n int main() { n   fl[0] = INF; n   n = read(); n   q = read(); n   for (int i = 1; i <= n; ++i) a[i] = read(), oo.push_back(a[i]); n   for (int i = 1; i <= q; ++i) { n     int t = read(); n     if (t == 1) { n       int l = read(), r = read(); n       que[++cntq] = node(l, r, Now, 0, i); n     } else { n       int p = read(), x = read(); n       oo.push_back(x); n       cz[++cntz] = node2(p, a[p], x); n       a[p] = x; n       ++Now; n     } n   } n   sort(oo.begin(), oo.end()); n   int ss = unique(oo.begin(), oo.end()) - oo.begin(); n   oo.resize(ss); n   for (int i = 1; i <= n; ++i) n     a[i] = lower_bound(oo.begin(), oo.end(), a[i]) - oo.begin() + 1; n   for (int i = 1; i <= cntz; ++i) { n     cz[i].fr = lower_bound(oo.begin(), oo.end(), cz[i].fr) - oo.begin() + 1; n     cz[i].to = lower_bound(oo.begin(), oo.end(), cz[i].to) - oo.begin() + 1; n   } n   sort(que + 1, que + cntq + 1, cmp); n   for (int i = 1; i <= cntq; ++i) { n     node now = que[i]; n     while (R < now.r) add(a[++R]); n     while (L > now.l) add(a[--L]); n     while (R > now.r) del(a[R--]); n     while (L < now.l) del(a[L++]); n     while (Now < now.tid) go(cz[++Now]); n     while (Now > now.tid) re(cz[Now--]); n     while (fl[que[i].ans]) ++que[i].ans; n   } n   sort(que + 1, que + cntq + 1, cmp2); n   for (int i = 1; i <= cntq; ++i) printf( %d n , que[i].ans); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> myvec[100001]; n set<int> myset[2]; n set<int>::iterator it; n int mark[100001]; n bool isbipartite(int src) { n   int color[100001]; n   memset(color, -1, sizeof(color)); n   queue<int> q; n   q.push(src); n   mark[src] = 1; n   color[src] = 1; n   myset[color[src]].insert(src); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int v = 0; v < myvec[u].size(); v++) { n       if (color[myvec[u][v]] == -1) n         color[myvec[u][v]] = 1 - color[u], q.push(myvec[u][v]), n         myset[color[myvec[u][v]]].insert(myvec[u][v]), mark[myvec[u][v]] = 1; n       else if (color[myvec[u][v]] == color[u]) n         return false; n     } n   } n   return true; n } n int main() { n   long long int x, y; n   int a, b; n   cin >> a >> b; n   while (b--) { n     cin >> x >> y; n     myvec[x].push_back(y); n     myvec[y].push_back(x); n   } n   bool solve = true; n   for (int i = 1; i <= a; i++) { n     if (mark[i] == 0) { n       solve = (solve && isbipartite(i)); n     } n   } n   if (solve == true) { n     cout << myset[0].size() << endl; n     for (it = myset[0].begin(); it != myset[0].end(); it++) { n       cout << *it <<    ; n     } n     cout << endl; n     cout << myset[1].size() << endl; n     for (it = myset[1].begin(); it != myset[1].end(); it++) { n       cout << *it <<    ; n     } n     cout << endl; n   } else n     cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int timeTook[50010][10]; n int timeSpent[50010]; n int main() { n   int numOfPictures, numOfPainters; n   scanf( %d %d , &numOfPictures, &numOfPainters); n   for (int i = 0; i < numOfPictures; i++) { n     for (int j = 0; j < numOfPainters; j++) { n       scanf( %d , &timeTook[i][j]); n     } n   } n   for (int i = 0; i < numOfPictures; i++) timeSpent[i] = 0; n   for (int painter = 0; painter < numOfPainters - 1; painter++) { n     int curTime = 0; n     for (int i = 0; i < numOfPictures; i++) { n       if (curTime >= timeSpent[i]) { n         timeSpent[i] += (curTime - timeSpent[i]) + timeTook[i][painter]; n         curTime += timeTook[i][painter]; n       } else { n         int waitTime = timeSpent[i] - curTime; n         timeSpent[i] += timeTook[i][painter]; n         curTime += waitTime + timeTook[i][painter]; n       } n     } n   } n   int curTime = 0; n   for (int i = 0; i < numOfPictures; i++) { n     if (curTime >= timeSpent[i]) { n       curTime += timeTook[i][numOfPainters - 1]; n     } else { n       int waitTime = timeSpent[i] - curTime; n       curTime += waitTime + timeTook[i][numOfPainters - 1]; n     } n     printf( %d  , curTime); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n string s; n int a[maxn], tot, n; n int main() { n   while (cin >> n) { n     memset(a, 0, sizeof a); n     tot = 0; n     cin >> s; n     string temp = s; n     if (n == 1) { n       puts( 0 ); n       continue; n     } n     for (int i = n - 1; i >= 1; i--) { n       if (s[i] ==  B ) n         s[i] =  W , s[i - 1] = (s[i - 1] ==  B  ?  W  :  B ), a[++tot] = i - 1; n     } n     if (s[0] ==  B ) { n       tot = 0; n       s = temp; n       for (int i = n - 1; i >= 1; i--) { n         if (s[i] ==  W ) n           s[i] =  B , s[i - 1] = (s[i - 1] ==  B  ?  W  :  B ), n           a[++tot] = i - 1; n       } n       if (s[0] ==  W ) n         puts( -1 ); n       else { n         cout << tot << endl; n         for (int i = 1; i <= tot; i++) cout << a[i] + 1 <<    ; n         cout << endl; n       } n     } else { n       cout << tot << endl; n       for (int i = 1; i <= tot; i++) cout << a[i] + 1 <<    ; n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a = 0, b = 0, c = 0, d = 0, n, temp, dl; n   cin >> n; n   for (int i = 0; i <= n; i++) { n     if (i < n) { n       cin >> temp; n     } else { n       temp = max(a, d) + 1; n     } n     dl = temp - a; n     if (dl != 1 && dl != -1) { n       if (!b) { n         b = i + 1; n         d = temp; n       } else if (!c) { n         c = i; n       } else { n         b = 0; n         c = 0; n         break; n       } n     } else if (!c && b) { n       if (dl != -1) { n         b = 0; n         c = 0; n         break; n       } n     } n     a = temp; n   } n   cout << b <<     << c; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, T, q, w, e, d[100001], v[100001], t[100001], B = 130; n int main() { n   scanf( %lld%lld , &a, &b); n   for (int i = 1; i <= a; i++) scanf( %lld , &d[i]), v[d[i]] = i, t[i] = i; n   for (int i = 1; i <= a; i++) n     for (int j = 1; j <= B; j++) t[i] = d[t[i]]; n   for (int ii = 1; ii <= b; ii++) { n     scanf( %lld%lld%lld , &q, &w, &e); n     if (q == 1) { n       swap(d[w], d[e]); n       swap(v[d[w]], v[d[e]]); n       long long tt = e, yy = e; n       for (int i = 1; i <= B; i++) yy = d[yy]; n       for (int i = 1; i <= B + 1; i++) t[tt] = yy, tt = v[tt], yy = v[yy]; n       tt = w, yy = w; n       for (int i = 1; i <= B; i++) yy = d[yy]; n       for (int i = 1; i <= B + 1; i++) t[tt] = yy, tt = v[tt], yy = v[yy]; n     } else { n       long long ff = w; n       for (int i = 1; i <= e / B; i++) ff = t[ff]; n       e %= B; n       for (int i = 1; i <= e; i++) ff = d[ff]; n       printf( %lld n , ff); n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n istream& operator>>(istream& in, pair<T1, T2>& a) { n   in >> a.first >> a.second; n   return in; n } n template <typename T1, typename T2> n ostream& operator<<(ostream& out, pair<T1, T2> a) { n   out << a.first <<     << a.second; n   return out; n } n template <typename T, typename T1> n T amax(T& a, T1 b) { n   if (b > a) a = b; n   return a; n } n template <typename T, typename T1> n T amin(T& a, T1 b) { n   if (b < a) a = b; n   return a; n } n const long long fx[] = {+1, -1, +0, +0}; n const long long fy[] = {+0, +0, +1, -1}; n const int32_t M = 1e9 + 7; n const int32_t MM = 998244353; n long long xo, yo, ax, ay, bx, by, xs, ys, t; n void solve() { n   cin >> xo >> yo >> ax >> ay >> bx >> by; n   cin >> xs >> ys >> t; n   vector<long long> x(1, xo), y(1, yo); n   long long LIMIT = (1LL << 62) - 1; n   while ((LIMIT - bx) / ax >= x.back() && (LIMIT - by) / ay >= y.back()) { n     x.push_back(ax * x.back() + bx); n     y.push_back(ay * y.back() + by); n   } n   long long n = x.size(); n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     for (long long j = i; j < n; j++) { n       long long length = x[j] - x[i] + y[j] - y[i]; n       long long dist2Left = abs(xs - x[i]) + abs(ys - y[i]); n       long long dist2Right = abs(xs - x[j]) + abs(ys - y[j]); n       if (length <= t - dist2Left || length <= t - dist2Right) n         ans = max(ans, j - i + 1); n     } n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n #define For(i, a, b) for (int i = (a), _##i = (b); i < _##i; ++i) n #define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i) n #define Forr(i, a, b) for (int i = (a), _##i = (b); i > _##i; --i) n #define FORR(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i) n #define all(a) a.begin(), a.end() n #define range(i, a) for (auto& i : a) n #define RANGE(i, a) for (auto i = a.rbegin(); i != a.rend(); ++i) n #define SINGLE n using ll = long long; n using pii = std::pair<int, int>; n using pdd = std::pair<double, double>; n  n namespace Solver { n   const int N = (1 << 18) + 5; n   std::string opt; n   int res[N << 1]; n   int n, cnt; n   void update(int p, char c) { n     if (opt[p] == c) n       return; n     opt[p] = c; n     // if (c ==  ? ) n     //   res[p] = res[p << 1] + res[p << 1 | 1]; n     while (p) { n       if (opt[p] ==  ? ) n         res[p] = res[p << 1] + res[p << 1 | 1]; n       else if (opt[p] ==  1 ) n         res[p] = res[p << 1]; n       else n         res[p] = res[p << 1 | 1]; n       p >>= 1; n     } n   } n   void build(int u) { n     if ((u << 1) <= cnt) n       build(u << 1); n     if ((u << 1 | 1) <= cnt) n       build(u << 1 | 1); n     if (opt[u] ==  ? ) n       res[u] = res[u << 1] + res[u << 1 | 1]; n     else if (opt[u] ==  1 ) n       res[u] = res[u << 1]; n     else n       res[u] = res[u << 1 | 1]; n   } n   void main() { n     std::cin >> n; n     std::string temp; n     std::cin >> temp; n     std::fill(res, res + (N << 1) - 1, 1); n     cnt = (1 << n) - 1; n     opt =    ; n     RANGE (i, temp) n       opt.push_back(*i); n     build(1); n     int T; n     for (std::cin >> T; T--;) { n       int p; n       char c; n       std::cin >> p >> c; n       update(cnt - p + 1, c); n       std::cout << res[1] << std::endl; n     } n   } n } n  n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   #ifndef SINGLE n   int T; n   for (std::cin >> T; T--;) n   #endif n     Solver::main(); n   return 0; n }


#include<iostream> n #include<vector> n #include<queue> n #include<cstring> n #include<cmath> n #include<map> n #include<set> n #include<cstdio> n #include<algorithm> n #define debug(a) cout<<#a<< = <<a<<endl; n using namespace std; n const int maxn=1e3+100; n typedef long long LL; n LL a[maxn]; n int main(void) n { n   cin.tie(0);std::ios::sync_with_stdio(false); n   LL n;cin>>n; n   if(n==1){ n     cout<<4<<endl; n   } n   else{ n  n     if(n&1) cout<<(1+ ( (3*n*(n+4)+2)+ ( (n+4)*n+2 )   )/8 )<<endl; n     else cout<<(1+ ( (3*n*(n+4)+2)- ( (n+4)*n+2 )   )/8 )<<endl; n   } n return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   long long int n; n   cin >> n; n   if (n == 1 || n == 2) { n     cout << n << endl; n     return 0; n   } n   if (n % 2 == 1) { n     cout << (n * (n - 1) * (n - 2)) << endl; n     return 0; n   } n   if (n == 4 || n == 6) { n     cout << ((n * (n - 1) * (n - 2)) / 2) << endl; n     return 0; n   } n   if (n % 3 == 0) { n     cout << ((n - 1) * (n - 2) * (n - 3)) << endl; n     return 0; n   } n   cout << (n * (n - 1) * (n - 3)) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, t, z; n bool dfs(long long x, long long y) { n   if (x < y) swap(x, y); n   if (!y) return 0; n   if (!dfs(y, x % y)) return 1; n   z = x / y; n   if (y & 1) return (z & 1) ^ 1; n   return z % (y + 1) & 1 ^ 1; n } n signed main() { n   scanf( %lld , &t); n   while (t--) { n     scanf( %lld%lld , &a, &b); n     if (dfs(a, b)) n       printf( First n ); n     else n       printf( Second n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   cin.sync_with_stdio(0); n   cout.tie(0); n   string s, t, b; n   int n; n   vector<pair<char, char>> v; n   set<char> z; n   bool fine = false; n   char a[26]; n   for (int i = 0; i < 26; i++) a[i] =  @ ; n   cin >> s >> t; n   for (int i = 0; i < s.length(); i++) n     if (a[s[i] -  a ] ==  @ ) n       a[s[i] -  a ] = t[i]; n     else if (a[s[i] -  a ] != t[i]) { n       cout << -1; n       return 0; n     } n   for (int i = 0; i < 26; i++) n     if (a[i] !=  @ ) { n       if (((char)(i +  a ) != a[a[i] -  a ]) && ( @  != a[a[i] -  a ])) { n         cout << -1; n         return 0; n       } n     } n   for (int i = 0; i < 26; i++) n     if ((a[i] != (char)( a  + i)) && (a[i] !=  @ )) { n       fine = false; n       for (int j = 0; j < v.size(); j++) n         if ((v[j].first == a[i]) && (v[j].second == (char)( a  + i))) n           fine = true; n       if (fine == false) v.push_back(make_pair((char)( a  + i), a[i])); n     } n   for (int i = 0; i < v.size(); i++) z.insert(v[i].second); n   if (z.size() != v.size()) { n     cout << -1; n     return 0; n   } n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) n     cout << v[i].first <<     << v[i].second << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC diagnostic ignored  -Wunused-result  n #pragma GCC diagnostic ignored  -Wsign-compare  n using namespace std; n void solve(); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int test_case = 1; n   cin >> test_case; n   while (test_case--) { n     solve(); n   } n   cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl; n   return 0; n } n void solve() { n   int n, m, t; n   vector<int> arr; n   bool odd = false; n   bool zero = false; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> t; n       if (t == 0) { n         zero = true; n       } n       if (t < 0) { n         odd = !odd; n         arr.push_back(-t); n       } else { n         arr.push_back(t); n       } n     } n   } n   sort(arr.begin(), arr.end()); n   int sum = 0; n   for (int i = 0; i < arr.size(); i++) { n     sum += arr[i]; n   } n   if (zero) { n     cout << sum << endl; n   } else { n     if (odd) { n       sum -= 2 * arr[0]; n       cout << sum << endl; n     } else { n       cout << sum << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200002; n int n, x1, x2, p[N]; n pair<int, int> a[N]; n int i1, i2; n bool solve() { n   i1 = i2 = -1; n   for (int i = n; i >= 1; --i) { n     if (a[i].first * (n - i + 1) >= x1) { n       i1 = i; n       break; n     } n   } n   for (int i = i1 - 1; i >= 1; --i) { n     if (a[i].first * (i1 - i) >= x2) { n       i2 = i; n       break; n     } n   } n   return i1 != -1 && i2 != -1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> x1 >> x2; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i].first; n     a[i].second = i; n   } n   sort(a + 1, a + 1 + n); n   if (solve()) { n     cout <<  Yes  << endl; n     cout << (n - i1 + 1) <<     << (i1 - i2) << endl; n     for (int i = i1; i <= n; ++i) cout << a[i].second <<    ; n     cout << endl; n     for (int i = i2; i < i1; ++i) cout << a[i].second <<    ; n     cout << endl; n     return 0; n   } n   swap(x1, x2); n   if (solve()) { n     cout <<  Yes  << endl; n     cout << (i1 - i2) <<     << (n - i1 + 1) << endl; n     for (int i = i2; i < i1; ++i) cout << a[i].second <<    ; n     cout << endl; n     for (int i = i1; i <= n; ++i) cout << a[i].second <<    ; n     cout << endl; n     return 0; n   } n   cout <<  No ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1E5 + 9; n vector<int> g[N]; n int tin[N]; n int tout[N]; n int sz[N]; n int tt; n int toys[N]; n bool root[N]; n void dfs(int v) { n   tin[v] = tt++; n   sz[v] = 1; n   for (auto i : g[v]) { n     dfs(i); n     sz[v] += sz[i]; n   } n   tout[v] = tt++; n } n bool parent(int v, int p) { return (tin[v] > tin[p] && tout[v] < tout[p]); } n int main() { n   int n, m, k, q; n   cin >> n >> m >> k >> q; n   for (int i = 1; i <= n; i++) root[i] = true; n   for (int i = 1; i <= k; i++) { n     int v, t; n     cin >> v >> t; n     if (toys[t] == 0) { n       toys[t] = v; n       continue; n     } n     g[toys[t]].push_back(v); n     root[v] = false; n     toys[t] = v; n   } n   for (int i = 1; i <= n; i++) n     if (root[i]) dfs(i); n   for (int i = 1; i <= q; i++) { n     int v, t; n     cin >> v >> t; n     if (toys[t] == 0) { n       cout << 0 << endl; n       continue; n     } n     if (parent(toys[t], v)) { n       cout << sz[v] << endl; n       continue; n     } n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int sum, a, b, c, ans = 0; n   cin >> sum >> a >> b >> c; n   for (int i = 0; i <= a; i += 2) n     for (int j = 0; j <= c; ++j) n       if (sum - i / 2 - 2 * j <= b && sum - i / 2 - 2 * j >= 0) ans++; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int z = 1000000007; n int main() { n   int n; n   cin >> n; n   if (n % 3 == 0) n     cout <<  1  n          <<   1   << (n - 2); n   else if (n % 3 == 1) n     cout <<  1  n          <<   1   << (n - 2); n   else n     cout <<  1  n          <<   2   << (n - 3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 128; n struct Matrix { n   double a[N][N]; n   Matrix() { n     for (int i = 0; i < N; i++) n       for (int j = 0; j < N; j++) a[i][j] = (i == j ? 1 : 0); n   } n   Matrix operator*(const Matrix &A) const { n     Matrix R = Matrix(); n     for (int i = 0; i < N; i++) n       for (int j = 0; j < N; j++) { n         R.a[i][j] = 0; n         for (int h = 0; h < N; h++) R.a[i][j] += a[i][h] * A.a[h][j]; n       } n     return R; n   } n }; n Matrix bin_pow(Matrix A, int p) { n   if (p == 0) return Matrix(); n   if (p == 2 || (p & 1)) return A * bin_pow(A, p - 1); n   return bin_pow(bin_pow(A, p / 2), 2); n } n double p[N]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i <= m; i++) scanf( %lf , &p[i]); n   Matrix A = Matrix(); n   for (int i = 0; i < N; i++) n     for (int j = 0; j < N; j++) A.a[i][j] = p[i ^ j]; n   A = bin_pow(A, n); n   printf( %.13lf n , 1 - A.a[0][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, b, p, f, h, c; n   cin >> t; n   vector<int> arr(t); n   for (int i = 0; i < t; ++i) { n     cin >> b >> p >> f; n     cin >> h >> c; n     if (h > c) { n       while (b >= 2 && p > 0) { n         arr[i] = arr[i] + h; n         b = b - 2; n         p--; n       } n       while (b >= 2 && f > 0) { n         arr[i] = arr[i] + c; n         b = b - 2; n         f--; n       } n     } else { n       while (b >= 2 && f > 0) { n         arr[i] = arr[i] + c; n         b = b - 2; n         f--; n       } n       while (b >= 2 && p > 0) { n         arr[i] = arr[i] + h; n         b = b - 2; n         p--; n       } n     } n   } n   for (int i = 0; i < t; ++i) { n     cout << arr[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[2222][2]; n int main() { n   int n, k, x, a, c, s, i; n   bool j; n   scanf( %d%d%d , &n, &k, &x); n   for (i = 0; i < n; i++) { n     scanf( %d , &a); n     A[a][0]++; n   } n   for (j = 0; k--; j = !j) { n     for (i = s = 0; i <= 2047; i++) { n       c = (s + A[i][j] + 1) / 2 - (s + 1) / 2; n       A[i][!j] += A[i][j] - c; n       A[i ^ x][!j] += c; n       s += A[i][j]; n       A[i][j] = 0; n     } n   } n   for (i = 2047; i >= 0; i--) { n     if (A[i][j]) { n       printf( %d  , i); n       break; n     } n   } n   for (i = 0; i <= 2047; i++) { n     if (A[i][j]) { n       printf( %d n , i); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n void solve() { n   long long int n, k; n   cin >> n >> k; n   if (n / 2 > k or n == 1) { n     if (k == 0 and n == 1) { n       cout << 1 <<   n ; n       return; n     } n     cout << -1 <<   n ; n     return; n   } else { n     vector<long long int> v; n     k -= (n / 2); n     k++; n     if (k == 0) k = 1; n     v.push_back(k); n     v.push_back(2 * k); n     map<long long int, long long int> make_pair; n     make_pair[k]++; n     make_pair[2 * k]++; n     long long int c = 1; n     for (__typeof(n / 2 - 1) i = (0) - ((0) > (n / 2 - 1)); n          i != (n / 2 - 1) - ((0) > (n / 2 - 1)); n          i += 1 - 2 * ((0) > (n / 2 - 1))) { n       while (make_pair[c] + make_pair[c + 1] != 0) { n         c++; n       } n       v.push_back(c); n       v.push_back(c + 1); n       make_pair[c]++; n       make_pair[c + 1]++; n       c += 2; n     } n     if (v.size() != n) { n       while (make_pair[2 * k + 1] != 0) k++; n       v.push_back(2 * k + 1); n     } n     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); n          i += 1 - 2 * ((0) > (n))) { n       cout << v[i] <<    ; n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const long long MOD = 1000000007; n const int inf = 1 << 30; n const long long linf = 1LL << 60; n const double PI = 3.14159265358979323846; n int n, k; n char s[100000]; n vector<int> v[2]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf(  %c , s + i); n   for (int i = 0; i < n; i++) { n     if (s[i] ==  0 ) n       v[0].push_back(i); n     else n       v[1].push_back(i); n   } n   if (v[0].size() == 0 || v[1].size() == 0) { n     puts( tokitsukaze ); n     return 0; n   } n   if (v[0][v[0].size() - 1] - v[0][0] + 1 <= k || n       v[1][v[1].size() - 1] - v[1][0] + 1 <= k) { n     puts( tokitsukaze ); n     return 0; n   } n   for (int i = 0; i < n - k + 1; i++) { n     for (int j = 0; j < 2; j++) { n       if (i <= v[j ^ 1][0] && v[j ^ 1][0] < i + k) { n         int pos = lower_bound(v[j ^ 1].begin(), v[j ^ 1].end(), i + k) - n                   v[j ^ 1].begin(); n         if (v[j ^ 1][v[j ^ 1].size() - 1] - v[j ^ 1][pos] + 1 > k) { n           puts( once again ); n           return 0; n         } n       } else if (i <= v[j ^ 1][v[j ^ 1].size() - 1] && n                  v[j ^ 1][v[j ^ 1].size() - 1] < i + k) { n         int pos = n             lower_bound(v[j ^ 1].begin(), v[j ^ 1].end(), i) - v[j ^ 1].begin(); n         pos--; n         if (v[j ^ 1][pos] - v[j ^ 1][0] + 1 > k) { n           puts( once again ); n           return 0; n         } n       } else { n         puts( once again ); n         return 0; n       } n     } n   } n   puts( quailty ); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void _R(T &x) { n   cin >> x; n } n void _R(int &x) { scanf( %d , &x); } n void _R(long long &x) { scanf( %lld , &x); } n void _R(double &x) { scanf( %lf , &x); } n void _R(char &x) { scanf(  %c , &x); } n void _R(char *x) { scanf( %s , x); } n void R() {} n template <class T, class... U> n void R(T &head, U &...tail) { n   _R(head); n   R(tail...); n } n template <class T> n void _W(const T &x) { n   cout << x; n } n void _W(const int &x) { printf( %d , x); } n void _W(const long long &x) { printf( %lld , x); } n void _W(const double &x) { printf( %.16f , x); } n void _W(const char &x) { putchar(x); } n void _W(const char *x) { printf( %s , x); } n template <class T, class U> n void _W(const pair<T, U> &x) { n   _W(x.first); n   putchar(   ); n   _W(x.second); n } n template <class T> n void _W(const vector<T> &x) { n   for (auto i = x.begin(); i != x.end(); _W(*i++)) n     if (i != x.cbegin()) putchar(   ); n } n void W() {} n template <class T, class... U> n void W(const T &head, const U &...tail) { n   _W(head); n   putchar(sizeof...(tail) ?     :   n ); n   W(tail...); n } n int MOD = 1e9 + 7; n void ADD(long long &x, long long v) { n   x = (x + v) % MOD; n   if (x < 0) x += MOD; n } n const int SIZE = 1e6 + 10; n int max_score[5] = {25, 25, 25, 25, 15}; n pair<int, int> dp[6][4][201][201]; n void pre() { n   for (int i = 0; i < (6); ++i) n     for (int win = 0; win < (4); ++win) n       for (int j = 0; j < (201); ++j) n         for (int k = 0; k < (201); ++k) dp[i][win][j][k].first = -1; n   dp[0][0][0][0] = {0, 0}; n   for (int i = 0; i < (5); ++i) n     for (int win = 0; win < (4); ++win) n       for (int j = 0; j < (201); ++j) n         for (int k = 0; k < (201); ++k) { n           if (dp[i][win][j][k].first == -1) continue; n           if (win == 3 || i - win == 3) continue; n           if (i - win < 3 && k + max_score[i] <= 200) { n             for (int score = (0); score <= (max_score[i] - 2); ++score) { n               if (j + score <= 200) { n                 dp[i + 1][win][j + score][k + max_score[i]] = {score, n                                                                max_score[i]}; n               } n             } n           } n           if (win < 3 && j + max_score[i] <= 200) { n             for (int score = (0); score <= (max_score[i] - 2); ++score) { n               if (k + score <= 200) { n                 dp[i + 1][win + 1][j + max_score[i]][k + score] = {max_score[i], n                                                                    score}; n               } n             } n           } n           for (int score = (max_score[i] + 1); score <= (200); ++score) { n             int good = 0; n             if (i - win < 3 && j + score - 2 <= 200 && k + score <= 200) { n               good = 1; n               dp[i + 1][win][j + score - 2][k + score] = {score - 2, score}; n             } n             if (win < 3 && j + score <= 200 && k + score - 2 <= 200) { n               good = 1; n               dp[i + 1][win + 1][j + score][k + score - 2] = {score, score - 2}; n             } n             if (!good) break; n           } n         } n } n void print(int i, int win, int j, int k) { n   printf( %d:%d n , win, i - win); n   vector<pair<int, int> > AA; n   while (i) { n     AA.push_back(dp[i][win][j][k]); n     i--; n     if (AA.back().first > AA.back().second) win--; n     j -= AA.back().first; n     k -= AA.back().second; n   } n   reverse((AA).begin(), (AA).end()); n   for (int i = 0; i < (((int)(AA).size())); ++i) { n     if (i) printf(   ); n     printf( %d:%d , AA[i].first, AA[i].second); n   } n   W(  ); n } n void solve(int a, int b) { n   for (int lose = (0); lose <= (2); ++lose) { n     if (dp[lose + 3][3][a][b].first != -1) { n       print(lose + 3, 3, a, b); n       return; n     } n   } n   for (int win = 2; win >= 0; win--) { n     if (dp[win + 3][win][a][b].first != -1) { n       print(win + 3, win, a, b); n       return; n     } n   } n   W( Impossible ); n } n int main() { n   pre(); n   int ___T; n   scanf( %d , &___T); n   for (int cs = 1; cs <= ___T; cs++) { n     int a, b; n     R(a, b); n     solve(a, b); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void inputOutput() {} n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   inputOutput(); n   string yelo =  AHIMOTUVWXY ; n   string s; n   cin >> s; n   long long int n = s.length(); n   for (long long int i = 0; i < n; i++) { n     if (yelo.find(s[i]) == string::npos) return cout <<  NO , 0; n   } n   for (long long int i = 0; i < n / 2; i++) { n     if (s[i] != s[n - i - 1]) return cout <<  NO , 0; n   } n   cout <<  YES ; n   cerr <<  time elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   sec  n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100, V = 100; n struct bottle { n   int a, b; n   bool operator<(const bottle &bt) const { return b > bt.b; } n } bot[N + 1]; n int dp[N + 1][N * V + 1]; n int main() { n   int n, shui = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &bot[i].a); n     shui += bot[i].a; n   } n   for (int j = 1; j <= n; ++j) scanf( %d , &bot[j].b); n   sort(bot + 1, bot + n + 1); n   int ping = 0; n   for (int i = 1, w = shui; w > 0; ++i) { n     w -= bot[i].b; n     ++ping; n   } n   memset(dp, -1, sizeof dp); n   dp[0][0] = 0; n   for (int i = 1; i <= n; ++i) n     for (int j = ping; j; --j) n       for (int k = shui; k >= bot[i].a; --k) n         if (~dp[j - 1][k - bot[i].a]) n           dp[j][k] = max(dp[j][k], dp[j - 1][k - bot[i].a] + bot[i].b); n   int mx = 0; n   for (int i = shui; ~i; --i) n     if (dp[ping][i] >= shui) { n       mx = i; n       break; n     } n   printf( %d %d n , ping, shui - mx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[300001]; n bool mark[300001]; n bool vis[300001]; n int road_count = 0; n int main(void) { n   int n, m; n   cin >> n >> m; n   int a, b; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     a--; n     b--; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   memset(mark, 0, sizeof(bool) * n); n   queue<int> q; n   for (int i = 0; i < n; i++) q.push(i); n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     int count = 0; n     for (int i = 0; i < g[x].size(); i++) { n       if (mark[x] == mark[g[x][i]]) count++; n     } n     if (count > 1) { n       mark[x] = !mark[x]; n       for (int i = 0; i < g[x].size(); i++) { n         if (mark[x] == mark[g[x][i]]) q.push(g[x][i]); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     if (mark[i]) n       cout <<  1 ; n     else n       cout <<  0 ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n struct node { n   int id, next; n   node() {} n   node(int a, int b) { n     id = a; n     next = b; n   } n }; n struct Brige { n   int x, y; n } brige[maxn]; n vector<int> v[maxn], g[maxn]; n vector<node> q[maxn]; n int dfn[maxn], low[maxn]; n int f[maxn], belong[maxn]; n bool visit[maxn]; n int n, m, k, cnt, t, bge; n void init() { n   for (int i = 1; i <= n; i++) { n     v[i].clear(); n     g[i].clear(); n   } n } n int find(int x) { n   if (x != f[x]) f[x] = find(f[x]); n   return f[x]; n } n void merge(int a, int b) { n   int x = find(a), y = find(b); n   if (x == y) return; n   f[y] = x; n } n void tarjan(int u, int father) { n   visit[u] = true; n   cnt++; n   dfn[u] = low[u] = cnt; n   for (int i = 0; i < (int)v[u].size(); i++) { n     int x = v[u][i]; n     if (!visit[x]) { n       tarjan(x, u); n       low[u] = min(low[u], low[x]); n       if (low[x] > dfn[u]) { n         bge++; n         brige[bge].x = u; n         brige[bge].y = x; n       } n       if (low[x] <= dfn[u]) merge(x, u); n     } else if (x != father) n       low[u] = min(low[u], dfn[x]); n   } n } n void rebuild() { n   t = 0; n   memset(belong, -1, sizeof(belong)); n   for (int i = 1; i <= n; i++) { n     int x = find(i); n     if (belong[x] == -1) { n       t++; n       belong[x] = t; n     } n     belong[i] = belong[x]; n   } n   for (int i = 1; i <= bge; i++) { n     int a = brige[i].x, b = brige[i].y; n     g[belong[a]].push_back(belong[b]); n     g[belong[b]].push_back(belong[a]); n   } n } n void solve() { n   memset(visit, false, sizeof(visit)); n   cnt = 0; n   bge = 0; n   for (int i = 1; i <= n; i++) f[i] = i; n   tarjan(1, 0); n   rebuild(); n } n bool Solve[maxn], check[maxn]; n int ans[maxn], d[maxn]; n void lca(int u) { n   visit[u] = true; n   for (int i = 0; i < (int)g[u].size(); i++) { n     int x = g[u][i]; n     if (!visit[x]) { n       d[x] = d[u] + 1; n       lca(x); n       f[x] = u; n     } n   } n   check[u] = true; n   for (int i = 0; i < (int)q[u].size(); i++) { n     int x = q[u][i].next; n     if (check[x] == true && Solve[q[u][i].id] == false) { n       int ansestor = find(x); n       ans[q[u][i].id] = d[u] + d[x] - 2 * d[ansestor]; n       Solve[q[u][i].id] = true; n     } n   } n } n int main() { n   int a, b; n   while (scanf( %d%d , &n, &m) != EOF) { n     init(); n     while (m--) { n       scanf( %d%d , &a, &b); n       v[a].push_back(b); n       v[b].push_back(a); n     } n     solve(); n     scanf( %d , &k); n     for (int i = 1; i <= k; i++) { n       scanf( %d%d , &a, &b); n       a = belong[a], b = belong[b]; n       q[a].push_back(node(i, b)); n       q[b].push_back(node(i, a)); n     } n     memset(visit, false, sizeof(visit)); n     memset(Solve, false, sizeof(Solve)); n     memset(check, false, sizeof(check)); n     for (int i = 1; i <= t; i++) f[i] = i; n     d[1] = 0; n     lca(1); n     for (int i = 1; i <= k; i++) printf( %d n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using INT = long long; n int a[200100], b[200100]; n map<int, int> mp[2]; n int arr[200100]; n map<int, int> vst; n int main() { n   int n, st; n   cin >> n >> st; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   int m, ed; n   cin >> m >> ed; n   for (int i = 1; i <= m; i++) { n     scanf( %d , &b[i]); n   } n   int d = 1; n   int ans = 1; n   for (int j = 1; j <= 30; j++) { n     mp[0].clear(); n     mp[1].clear(); n     int x = (1 << j); n     int nn = 0; n     for (int i = 1; i <= n; i++) { n       int r = a[i] % x; n       mp[0][r]++; n       ans = max(ans, mp[0][r]); n       arr[++nn] = r; n     } n     for (int i = 1; i <= m; i++) { n       int r = b[i] % x; n       mp[1][r]++; n       ans = max(ans, mp[1][r] + mp[0][(r + x / 2) % x]); n       arr[++nn] = r; n     } n   } n   for (int i = 1; i <= n; i++) vst[a[i]] = 1; n   for (int i = 1; i <= m; i++) n     if (vst[b[i]]) ans = max(ans, 2); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int x; n   cin >> x; n   cout << x / 2520; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T abs(T a) { n   return a < 0 ? -a : a; n } n template <typename T> n T sqr(T a) { n   return a * a; n } n const int INF = (int)1e9; n const long double EPS = 1e-9; n const long double PI = 3.1415926535897932384626433832795; n const int N = 1000; n pair<long double, long double> operator-( n     const pair<long double, long double>& a, n     const pair<long double, long double>& b) { n   return pair<long double, long double>(a.first - b.first, a.second - b.second); n } n pair<long double, long double> operator+( n     const pair<long double, long double>& a, n     const pair<long double, long double>& b) { n   return pair<long double, long double>(a.first + b.first, a.second + b.second); n } n inline pair<long double, long double> rotate( n     const pair<long double, long double>& a, const long double& ang) { n   return pair<long double, long double>( n       a.first * cos(ang) - a.second * sin(ang), n       a.first * sin(ang) + a.second * cos(ang)); n } n int m; n int n; n pair<long double, long double> p[N]; n vector<int> g[N]; n vector<int> pol[N]; n const long double ROT_ANG = 2 * PI / 5; n void draw(int cnt, int s1, int s2) { n   int cp[10]; n   cp[0] = s1; n   cp[1] = s2; n   pair<long double, long double> v = p[s2] - p[s1]; n   int prev = s2; n   for (int i = 0; i < int(3); ++i) { n     v = rotate(v, ROT_ANG); n     p[n] = p[prev] + v; n     cp[2 + i] = n; n     prev = n; n     n++; n   } n   v = rotate(v, ROT_ANG); n   pair<long double, long double> u = p[n - 1] + v; n   if (abs(p[s1].first - u.first) > 1e-1 || abs(p[s1].second - u.second) > 1e-1) n     throw; n   for (int i = 0; i < int(5); ++i) { n     int i1 = (i + 1) % 5; n     int i2 = (i + 4) % 5; n     for (int j = 0; j < int(5); ++j) { n       if (j != i1 && j != i && j != i2) g[cp[i]].push_back(cp[j]); n     } n   } n   for (int i = 0; i < int(5); ++i) pol[m - cnt].push_back(cp[i]); n   if (cnt > 1) { n     int i1 = 0; n     for (int i = 1; i < 5; ++i) n       if (p[cp[i1]] < p[cp[i]]) i1 = i; n     int i2 = i1 + 1; n     if (i2 == 5) i2 = 0; n     draw(cnt - 1, cp[i2], cp[i1]); n   } n } n set<pair<long double, long double> > visited; n vector<int> ans; n void fleury(int v) { n   while (!g[v].empty()) { n     int u = g[v].back(); n     g[v].pop_back(); n     if (visited.count(pair<long double, long double>(min(v, u), max(v, u)))) n       continue; n     visited.insert(pair<long double, long double>(min(v, u), max(v, u))); n     fleury(u); n     ans.push_back(u); n   } n } n int main() { n   cin >> m; n   p[0] = pair<long double, long double>(0, 0); n   p[1] = pair<long double, long double>(10, 0); n   n = 2; n   draw(m, 0, 1); n   long double minY = 1e100, minX = 1e100; n   for (int i = 0; i < int(n); ++i) { n     minY = min(minY, p[i].second); n     minX = min(minX, p[i].first); n   } n   for (int i = 0; i < int(n); ++i) { n     p[i].first -= minX + 4999; n     p[i].second -= minY + 4999; n   } n   cout << n << endl; n   for (int i = 0; i < int(n); ++i) { n     printf( %0.10lf %0.10lf n , (double)p[i].first, (double)p[i].second); n   } n   for (int i = 0; i < int(m); ++i) { n     for (int j = 0; j < int(5); ++j) { n       if (j != 0) printf(   ); n       printf( %d , pol[i][j] + 1); n     } n     puts(  ); n   } n   fleury(0); n   ans.push_back(0); n   for (int i = 0; i < int(int((ans).size())); ++i) { n     if (i != 0) printf(   ); n     printf( %d , ans[i] + 1); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   set<char> deputi; n   vector<vector<char> > off; n   int m, n; n   char boss; n   cin >> n >> m >> boss; n   off.resize(n); n   for (int i = 0; i < n; i++) off[i].resize(m); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) do { n         cin >> off[i][j]; n       } while (off[i][j] ==   n ); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (off[i][j] == boss) { n         if (i > 0) deputi.insert(off[i - 1][j]); n         if (i < n - 1) deputi.insert(off[i + 1][j]); n         if (j > 0) deputi.insert(off[i][j - 1]); n         if (j < m - 1) deputi.insert(off[i][j + 1]); n       } n   deputi.erase( . ); n   deputi.erase(boss); n   cout << deputi.size() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     int a[n]; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     for (int num : a) { n       m -= num; n     } n     if (m != 0) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, res = 0, cp = 0, cn = 0, cz = 0; n   cin >> n; n   vector<long long> arr(n); n   for (long long i = 0; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] > 0) n       cp++; n     else if (arr[i] < 0) n       cn++; n     else n       cz++; n   } n   if (cp > (cn + cz)) { n     cout <<  1 ; n   } else if (cn > (cp + cz)) { n     cout <<  -1 ; n   } else { n     if (cp == (cn + cz) && n % 2 == 0) n       cout <<  1 ; n     else if (cn == (cp + cz) && n % 2 == 0) n       cout <<  -1 ; n     else n       cout <<  0 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int inf = 1e9 + 7; n const ll longinf = 1LL << 60; n const ll mod = 1e9 + 7; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   for (int i = 0; i < t; ++i) { n     int n; n     cin >> n; n     cout << n / 2 + 1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = (int)1e9 + 7; n const int N_ = (int)1e6 + 2; n long long Hash_a[N_]; n long long Hash_b[N_]; n long long pow26[N_]; n string a, b; n long long n; n long long get_hash_a(long long x, long long y) { n   return (Hash_a[y] - Hash_a[x - 1] * pow26[y - x + 1] + 1LL * mod * mod) % mod; n } n long long get_hash_b(long long x, long long y) { n   return (Hash_b[y] - Hash_b[x - 1] * pow26[y - x + 1] + 1LL * mod * mod) % mod; n } n bool F(long long L1, long long R1, long long L2, long long R2) { n   int len = R1 - L1 + 1; n   if (len % 2 == 1) { n     return get_hash_a(L1, R1) == get_hash_b(L2, R2); n   } else { n     if (get_hash_a(L1, R1) == get_hash_b(L2, R2)) return true; n     int R_1 = L1 + len / 2 - 1; n     int L_1 = R_1 + 1; n     int R_2 = L2 + len / 2 - 1; n     int L_2 = R_2 + 1; n     if (F(L1, R_1, L_2, R2) && F(L_1, R1, L2, R_2)) return true; n     if (F(L1, R_1, L2, R_2) && F(L_1, R1, L_2, R2)) return true; n     return false; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> a >> b; n   n = a.size(); n   pow26[0] = 1; n   for (int i = 1; i <= n; i++) { n     Hash_a[i] = (Hash_a[i - 1] * 26 + (a[i - 1] -  a  + 1)) % mod; n     Hash_b[i] = (Hash_b[i - 1] * 26 + (b[i - 1] -  a  + 1)) % mod; n     pow26[i] = pow26[i - 1] * 26; n     pow26[i] %= mod; n   } n   if (F(1, n, 1, n)) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, p, ans(0); n   cin >> n; n   map<string, int> mp; n   string s; n   while (n--) { n     cin >> s; n     mp[s]++; n   } n   for (auto x : mp) { n     if (x.first ==  Tetrahedron ) n       p = 4; n     else if (x.first ==  Cube ) n       p = 6; n     else if (x.first ==  Octahedron ) n       p = 8; n     else if (x.first ==  Dodecahedron ) n       p = 12; n     else n       p = 20; n     ans += p * x.second; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n struct ele { n   long long a, b; n }; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     struct ele arr[n]; n     bool issorted = true, zer0 = false, one = false; n     for (long long i = 0; i < n; i++) { n       cin >> arr[i].a; n       if (i > 0 && arr[i].a < arr[i - 1].a) issorted = false; n     } n     for (long long i = 0; i < n; i++) { n       cin >> arr[i].b; n       if (arr[i].b == 1) n         one = true; n       else n         zer0 = true; n     } n     if (issorted) n       cout <<  Yes  n            <<   n ; n     else if (one && zer0) n       cout <<  Yes  n            <<   n ; n     else n       cout <<  No  n            <<   n ; n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long n #define ld long double n #define Test int T;cin>>T;while(T--) n #define PI acos(-1) n #define endl   n  n #define fx(x) fixed<<setprecision(x) n #define sz(s) (int)s.size() n #define all(v) (v).begin(),(v).end() n #define allr(v) (v).rbegin(),(v).rend() n #define mem(a,n) memset((a),n,sizeof (a)) n #define INF 1e9 n #define ii pair<ll,ll> n ll gcd(ll x,ll y){return(!y?x:gcd(y,x%y));} n ll lcm(ll x,ll y){return x/gcd(x,y)*y;} n void file(){ n #ifndef ONLINE_JUDGE n     freopen( in.txt ,  r , stdin); n     freopen( out.txt ,  w , stdout); n #else n     //freopen( bridges.in ,  r , stdin); n     //freopen( bridges.out ,  w , stdout); n #endif n } n void fast(){ n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     file(); n } n int dx[]= {-1,0,1,0}; n int dy[]= {0,1,0,-1}; n const double eps=1e-9; n const int mod=1e9+7; n const int N=1e5+5; n int a[N]; n int ask(int i){ n     if(a[i])return a[i]; n     cout<< ?  <<i<<endl; n     cout.flush(); n     int x;cin>>x; n     return a[i]=x; n } n int main(){ n     fast(); n     int n; n     cin>>n; n     a[0]=a[n+1]=1e9; n     int l=1,r=n; n     while(l<=r){ n         int md=l+r>>1; n         int xl=ask(md); n         int xr=ask(md+1); n         if(xl>=xr){ n             l=md+1; n         } n         else r=md-1; n     } n     cout<< !  <<l<<endl; n     cout.flush(); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int qnt, time, felicity, time_to_eat, best = -999999999; n   cin >> qnt >> time; n   for (int i = 0; i < qnt; i++) { n     cin >> felicity >> time_to_eat; n     if (time_to_eat <= time && felicity > best) { n       best = felicity; n     } else if (time_to_eat > time) { n       int aux = felicity - (time_to_eat - time); n       if (aux > best) { n         best = felicity - (time_to_eat - time); n       } n     } n   } n   cout << best << endl; n   return 0; n } n


#include <bits/stdc++.h> n int va[100000], vb[100000]; n int main() { n   int na, nb, k, m, i, j; n   scanf( %d%d%d%d , &na, &nb, &k, &m); n   for (i = 0; i < na; i++) scanf( %d , &va[i]); n   for (i = 0; i < nb; i++) scanf( %d , &vb[i]); n   if (va[k - 1] < vb[nb - m]) n     printf( YES ); n   else n     printf( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> erat; 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 nd(long long a) { n   map<long long, long long> m; n   while (a != 1) { n     ++m[erat[a]]; n     a /= erat[a]; n   } n   long long count = 1; n   for (auto e : m) count *= e.second + 1; n   return count; n } n int main() { n   vector<vector<vector<bool> > > count( n       8, vector<vector<bool> >(8, vector<bool>(8, true))); n   count[1][7][6] = false; n   count[3][7][6] = false; n   count[5][3][6] = false; n   count[5][3][7] = false; n   count[5][7][6] = false; n   count[7][2][5] = false; n   count[7][3][4] = false; n   count[7][3][5] = false; n   count[7][3][6] = false; n   count[7][3][7] = false; n   count[7][6][5] = false; n   count[7][7][5] = false; n   count[7][7][6] = false; n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   erat = vector<long long>(1e5 + 1, 1); n   erat[0] = erat[1] = 1; n   for (long long i = 2; i <= 1e5; ++i) { n     if (erat[i] == 1) { n       erat[i] = i; n       for (long long j = i * i; j <= 1e5; j += i) { n         if (erat[j] == 1) erat[j] = i; n       } n     } n   } n   long long t; n   cin >> t; n   while (t--) { n     long long a, b, c; n     cin >> a >> b >> c; n     long long d = gcd(a, b); n     long long e = gcd(a, c); n     long long f = gcd(b, c); n     long long g = gcd(d, c); n     a = nd(a); n     b = nd(b); n     c = nd(c); n     d = nd(d); n     e = nd(e); n     f = nd(f); n     g = nd(g); n     d -= g, e -= g, f -= g; n     a -= d + e + g, b -= d + f + g, c -= e + f + g; n     vector<long long> v(8); n     v[1] = a, v[2] = b, v[3] = d, v[4] = c, v[5] = e, v[6] = f, v[7] = g; n     long long total = 0; n     for (int i = 0; i < 4; ++i) { n       for (int j = 0; j < 4; ++j) { n         for (int k = 0; k < 4; ++k) { n           int l = 2 * i + 1; n           int m = 2 + j; n           if (j >= 2) m += 2; n           int p = 4 + k; n           if (count[l][m][p]) { n             if (l == m) { n               if (m == p) n                 total += v[l] * (v[m] + 1) * (v[p] + 2) / 6; n               else n                 total += v[l] * (v[m] + 1) * v[p] / 2; n             } else if (l == p or m == p) n               total += v[l] * v[m] * (v[p] + 1) / 2; n             else n               total += v[l] * v[m] * v[p]; n           } n         } n       } n     } n     cout << total << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n long long x[maxn], y[maxn]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n; n   cin >> n; n   long long s = 0, sx = 0, sy = 0; n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n     sx += x[i]; n     sy += y[i]; n     s += (n - 1) * (x[i] * x[i]) + (n - 1) * (y[i] * y[i]); n   } n   for (int i = 0; i < n; i++) { n     s -= ((x[i] * (sx - x[i])) + (y[i] * (sy - y[i]))); n   } n   cout << s; n   return 0; n } n