#include <bits/stdc++.h> n using namespace std; n struct tri { n   tri(int x = 0, int y = 0, int z = 0) { a = x, b = y, c = z; } n   int a, b, c; n } par[101][101][101]; n char col[101][101]; n string h[101]; n int d[101][101][101]; n queue<tri> q; n int main() { n   int n, a, b, c; n   cin >> n >> a >> b >> c; n   if (a == b || b == c || a == c) { n     cout << -1; n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     cin >> h[i]; n     for (int j = 1; j <= n; j++) col[i][j] = h[i][j - 1]; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       for (int k = 1; k <= n; k++) d[i][j][k] = 1e9; n   d[a][b][c] = 0; n   q.push(tri(a, b, c)); n   while (!q.empty()) { n     tri cu = q.front(); n     q.pop(); n     int dis = d[cu.a][cu.b][cu.c]; n     int tmp[] = {cu.a, cu.b, cu.c}; n     sort(tmp, tmp + 3); n     int A = tmp[0], B = tmp[1], C = tmp[2]; n     if (A == 1 && B == 2 && C == 3) { n       cout << dis << endl; n       vector<pair<int, int> > m; n       for (int i = dis; i > 0; i--) { n         tri pare = par[cu.a][cu.b][cu.c]; n         if (pare.a != cu.a) m.push_back(make_pair(pare.a, cu.a)); n         if (pare.b != cu.b) m.push_back(make_pair(pare.b, cu.b)); n         if (pare.c != cu.c) m.push_back(make_pair(pare.c, cu.c)); n         cu = pare; n       } n       for (int i = dis - 1; i >= 0; i--) n         cout << m[i].first <<     << m[i].second << endl; n       return 0; n     } n     A = cu.a, B = cu.b, C = cu.c; n     for (int i = 1; i <= n; i++) { n       if (i != A && i != B && i != C) { n         if (d[i][B][C] == 1e9 && col[A][i] == col[B][C]) { n           par[i][B][C] = tri(A, B, C); n           d[i][B][C] = dis + 1; n           q.push(tri(i, B, C)); n         } n         if (d[A][i][C] == 1e9 && col[B][i] == col[A][C]) { n           par[A][i][C] = tri(A, B, C); n           d[A][i][C] = dis + 1; n           q.push(tri(A, i, C)); n         } n         if (d[A][B][i] == 1e9 && col[C][i] == col[A][B]) { n           par[A][B][i] = tri(A, B, C); n           d[A][B][i] = dis + 1; n           q.push(tri(A, B, i)); n         } n       } n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; n const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1}, n                          {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; n const long long INF = 1000000000000000000; n struct SEG { n   int siz = 1 << 19; n   long long s[1 << 20]; n   long long t[1 << 20]; n   void init() { n     for (int i = 0; i < 2 * siz - 1; i++) { n       s[i] = 0; n       t[i] = 0; n     } n   } n   void add(int a, int b, long long x, int k, int l, int r) { n     if (b <= l || r <= a) return; n     if (a <= l && r <= b) { n       s[k] += x; n       t[k] += x; n       return; n     } n     add(a, b, x, 2 * k + 1, l, (l + r) / 2); n     add(a, b, x, 2 * k + 2, (l + r) / 2, r); n     s[k] = min(s[2 * k + 1], s[2 * k + 2]) + t[k]; n   } n   long long query(int a, int b, int k, int l, int r) { n     if (b <= l || r <= a) return INF; n     if (a <= l && r <= b) return s[k]; n     long long chl = query(a, b, 2 * k + 1, l, (l + r) / 2); n     long long chr = query(a, b, 2 * k + 2, (l + r) / 2, r); n     return min(chl, chr) + t[k]; n   } n } seg; n int main() { n   static int n, q; n   static int p[500010]; n   static long long w[500010]; n   static int v[500010], l[500010], r[500010]; n   scanf( %d%d , &n, &q); n   for (int i = 2; i <= n; i++) { n     scanf( %d%lld , &p[i], &w[i]); n   } n   for (int i = 0; i < q; i++) scanf( %d%d%d , &v[i], &l[i], &r[i]); n   static int R[500010]; n   for (int i = 1; i <= n; i++) R[i] = i; n   for (int i = n; i >= 2; --i) { n     R[p[i]] = max(R[p[i]], R[i]); n   } n   seg.init(); n   static int cnt[500010] = {}; n   for (int i = 1; i <= n; i++) { n     cnt[p[i]]++; n   } n   static long long d[500010]; n   d[1] = 0; n   seg.add(1, 2, INF, 0, 0, seg.siz); n   for (int i = 2; i <= n; i++) { n     d[i] = d[p[i]] + w[i]; n     seg.add(i, i + 1, cnt[i] == 0 ? d[i] : INF, 0, 0, seg.siz); n   } n   static vector<pair<pair<int, int>, pair<int, int> > > Que; n   for (int i = 0; i < q; i++) n     Que.push_back(pair<pair<int, int>, pair<int, int> >( n         pair<int, int>(v[i], i), pair<int, int>(l[i], r[i]))); n   sort(Que.begin(), Que.end()); n   static long long ans[500010]; n   int k = 0; n   for (int i = 1; i <= n; i++) { n     while (k < Que.size() && Que[k].first.first == i) { n       ans[Que[k].first.second] = seg.query( n           Que[k].second.first, Que[k].second.second + 1, 0, 0, seg.siz); n       k++; n     } n     if (i == n) break; n     int loc = i; n     while (loc != p[i + 1]) { n       seg.add(0, seg.siz, -w[loc], 0, 0, seg.siz); n       seg.add(loc, R[loc] + 1, 2 * w[loc], 0, 0, seg.siz); n       loc = p[loc]; n     } n     seg.add(0, seg.siz, w[i + 1], 0, 0, seg.siz); n     seg.add(i + 1, R[i + 1] + 1, -2 * w[i + 1], 0, 0, seg.siz); n   } n   for (int i = 0; i < q; i++) { n     printf( %lld n , ans[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int maxn = 4e5 + 400; n int prime[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41, n                43,  47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101, n                103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, n                173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, n                241, 251, 257, 263, 269, 271, 277, 281, 283, 293}; n long long poww(long long a, long long b) { n   long long res = 1; n   long long base = a; n   while (b) { n     if (b & 1) { n       res *= base; n       res %= mod; n     } n     base *= base; n     base %= mod; n     b >>= 1; n   } n   return res; n } n struct node { n   int l, r; n   long long mul; n   long long p; n   long long lazy; n   long long lazy2; n } Node[maxn << 2]; n void build(int l, int r, int step) { n   Node[step].l = l; n   Node[step].r = r; n   Node[step].mul = Node[step].lazy = 1; n   Node[step].p = Node[step].lazy2 = 0; n   if (l == r) return; n   build(l, (l + r) >> 1, step << 1); n   build(((l + r) >> 1) + 1, r, step << 1 | 1); n } n void push_up(int step) { n   Node[step].mul = Node[step << 1].mul * Node[step << 1 | 1].mul % mod; n   Node[step].p = Node[step << 1].p | Node[step << 1 | 1].p; n } n void push_down(int step) { n   if (Node[step].lazy != 1) { n     Node[step << 1].lazy = Node[step << 1].lazy * Node[step].lazy % mod; n     Node[step << 1].mul = n         Node[step << 1].mul * n         poww(Node[step].lazy, (Node[step << 1].r - Node[step << 1].l + 1)) % n         mod; n     Node[step << 1 | 1].lazy = Node[step << 1 | 1].lazy * Node[step].lazy % mod; n     Node[step << 1 | 1].mul = n         Node[step << 1 | 1].mul * n         poww(Node[step].lazy, n              (Node[step << 1 | 1].r - Node[step << 1 | 1].l + 1)) % n         mod; n     Node[step].lazy = 1; n   } n   if (Node[step].lazy2) { n     Node[step << 1].lazy2 |= Node[step].lazy2; n     Node[step << 1].p |= Node[step].lazy2; n     Node[step << 1 | 1].lazy2 |= Node[step].lazy2; n     Node[step << 1 | 1].p |= Node[step].lazy2; n     Node[step].lazy2 = 0; n   } n } n void update(int l, int r, int step, long long val) { n   if (Node[step].l == l && Node[step].r == r) { n     Node[step].mul = Node[step].mul * poww(val, (r - l + 1)) % mod; n     int vval = val; n     for (int i = 0; prime[i]; i++) { n       while (vval % prime[i] == 0) { n         Node[step].p |= (1ll << i); n         Node[step].lazy2 |= (1ll << i); n         vval /= prime[i]; n       } n       if (vval == 1) break; n     } n     Node[step].lazy = Node[step].lazy * val % mod; n     return; n   } n   push_down(step); n   int mid = (Node[step].l + Node[step].r) >> 1; n   if (mid >= r) n     update(l, r, step << 1, val); n   else if (mid < l) n     update(l, r, step << 1 | 1, val); n   else { n     update(l, mid, step << 1, val); n     update(mid + 1, r, step << 1 | 1, val); n   } n   push_up(step); n } n long long qqq = 0; n long long query(int l, int r, int step) { n   if (Node[step].l == l && Node[step].r == r) { n     long long val = Node[step].p; n     long long res = 1; n     qqq |= val; n     res = res * Node[step].mul % mod; n     return res; n   } n   push_down(step); n   int mid = (Node[step].l + Node[step].r) >> 1; n   if (mid >= r) n     return query(l, r, step << 1); n   else if (mid < l) n     return query(l, r, step << 1 | 1); n   else { n     return (query(l, mid, step << 1) * query(mid + 1, r, step << 1 | 1)) % mod; n   } n } n int n, q; n int main() { n   scanf( %d%d , &n, &q); n   build(1, n, 1); n   for (int i = 1; i <= n; i++) { n     long long a; n     scanf( %lld , &a); n     update(i, i, 1, a); n   } n   while (q--) { n     char ss[20]; n     scanf( %s , ss); n     if (ss[0] ==  M ) { n       int l, r; n       long long val; n       scanf( %d%d%lld , &l, &r, &val); n       update(l, r, 1, val); n     } else { n       int l, r; n       scanf( %d%d , &l, &r); n       qqq = 0; n       long long ans = query(l, r, 1); n       int tot = 0; n       while (qqq) { n         if (qqq & 1) { n           ans *= (1 - poww(prime[tot], mod - 2)); n           ans %= mod; n         } n         qqq >>= 1; n         tot++; n       } n       ans %= mod; n       ans += mod; n       ans %= mod; n       printf( %lld n , ans); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e6 + 10; n const long long mod = 998244353; n long long power(long long x, long long y) { n   x = x % mod, y = y % (mod - 1); n   long long ans = 1; n   while (y > 0) { n     if (y & 1) { n       ans = (1ll * x * ans) % mod; n     } n     y >>= 1; n     x = (1ll * x * x) % mod; n   } n   return ans; n } n long long add(long long a, long long b) { return (a % mod + b % mod) % mod; } n long long mul(long long a, long long b) { return (a % mod * b % mod) % mod; } n long long n, k; n const long long K = 210; n vector<long long> a(N); n vector<long long> b(N); n multiset<long long> st; n long long pow2[N]; n void power_2() { n   pow2[0] = 1; n   long long x = 1; n   long long cnt = 1; n   while (cnt < 3e5) { n     pow2[cnt] = mul(pow2[cnt - 1], 2); n     cnt++; n   } n } n int32_t main() { n   long long nx, mx; n   cin >> nx >> mx; n   string s, t; n   cin >> s >> t; n   power_2(); n   long long temp = 0, ans = 0; n   long long n = min(s.size(), t.size()); n   for (long long i = 0; i < mx; i++) { n     if (i < nx and s[nx - i - 1] ==  1 ) temp = add(temp, pow2[i]); n     if (t[mx - i - 1] ==  1 ) ans = add(ans, temp); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n long long n, m; n long long a[maxn], b[maxn]; n bool cmp(long long a, long long b) { return a > b; } n int main() { n   scanf( %lld %lld , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   for (int i = 1; i <= m; i++) scanf( %lld , &b[i]); n   sort(a + 1, a + n + 1, cmp); n   sort(b + 1, b + m + 1, cmp); n   if (a[1] > b[m]) { n     cout << -1 << endl; n     return 0; n   } n   long long ans = a[1], t = m - 1, bj = 1; n   for (int i = 1; i <= m; i++) { n     if (b[i] == a[1]) continue; n     if (t == 0) { n       bj++; n       ans += a[bj]; n       t = m - 1; n     } n     ans += b[i]; n     t--; n   } n   for (int i = n; i > bj; i--) ans += (a[i] * m); n   ans += t * a[bj]; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, l; n   cin >> k; n   vector<int> a[k]; n   for (int i = 0; i < k; i++) n     for (int j = 0; j < k; j++) cin >> l, a[i].push_back(l); n   l = 0; n   for (int i = 0; i < k; i++) l += a[k / 2][i]; n   for (int i = 0; i < k; i++) l += a[i][k / 2]; n   for (int i = 0; i < k; i++) l += a[i][i]; n   for (int i = 0; i < k; i++) l += a[i][k - i - 1]; n   cout << l - (3 * (a[k / 2][k / 2])); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void fast_scan(T &number); n template <typename T> n inline void fast_scan(T *nums, size_t size); n size_t fast_scan_line(char *chars, size_t size); n size_t fast_scan_word(char *chars, size_t size); n inline void fast_write(int num); n inline void fast_write(char *str); n int comp_double(double a, double b); n vector<string> string_split(char *str, char *delimiter); n int n, m; n int p[101][2]; n bool used[101]; n unsigned int ex = 0; n void dfs(int c_node, int p_node, int &c) { n   int *enemies = p[c_node]; n   if (used[c_node] || c_node == 0) return; n   used[c_node] = true; n   c++; n   if (enemies[0] != p_node) { n     if (used[enemies[0]] && enemies[1] == p_node) { n       if (c & 1) { n         ex++; n       } n     } else { n       dfs(enemies[0], c_node, c); n     } n   } n   if (enemies[1] != p_node) { n     if (used[enemies[1]] && enemies[0] == p_node) { n       if (c & 1) { n         ex++; n       } n     } else { n       dfs(enemies[1], c_node, c); n     } n   } n } n void read() { n   fast_scan(n); n   fast_scan(m); n   int t1, t2; n   for (int i = 0; i < m; ++i) { n     fast_scan(t1); n     fast_scan(t2); n     if (p[t1][0] == 0) { n       p[t1][0] = t2; n     } else { n       p[t1][1] = t2; n     } n     if (p[t2][0] == 0) { n       p[t2][0] = t1; n     } else { n       p[t2][1] = t1; n     } n   } n } n void solve() { n   for (int i = 1; i < n + 1; ++i) { n     int c = 0; n     dfs(i, 0, c); n   } n   if ((n - ex) & 1) { n     cout << (ex + 1); n   } else { n     cout << ex; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   read(); n   solve(); n   return 0; n } n size_t fast_scan_word(char *chars, size_t size) { n   char temp; n   for (int i = 0; i < size; ++i) { n     temp = (char)getchar(); n     if (temp ==   n  || temp ==     || temp ==   0 ) return i; n     chars[i] = temp; n   } n } n size_t fast_scan_line(char *chars, size_t size) { n   char temp; n   for (int i = 0; i < size; ++i) { n     temp = (char)getchar(); n     if (temp ==   n  || temp ==   0 ) return i; n     chars[i] = temp; n   } n } n template <typename T> n void fast_scan(T &number) { n   bool negative = false; n   int c; n   number = 0; n   c = getchar(); n   if (c ==  - ) { n     negative = true; n     c = getchar(); n   } n   for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48; n   if (negative) number *= -1; n } n template <typename T> n inline void fast_scan(T *nums, size_t size) { n   for (size_t i = 0; i < size; ++i) fast_scan(nums[i]); n } n inline void fast_write(int num) { n   int N = num, rev, count = 0; n   rev = N; n   if (N == 0) { n     putchar( 0 ); n     putchar(  n ); n     return; n   } n   if (N < 0) { n     putchar( - ); n     N *= -1; n   } n   while ((rev % 10) == 0) { n     count++; n     rev /= 10; n   } n   rev = 0; n   while (N != 0) { n     rev = (rev << 3) + (rev << 1) + N % 10; n     N /= 10; n   } n   while (rev != 0) { n     putchar(rev % 10 +  0 ); n     rev /= 10; n   } n   while (count--) putchar( 0 ); n } n inline void fast_write(char *str) { n   for (int i = 0; str[i]; i++) putchar(str[i]); n } n int comp_double(double a, double b) { n   if (abs(a - b) <= 1e-9) return 0; n   return a < b ? -1 : 1; n } n vector<string> string_split(char *str, char *delimiter) { n   vector<string> tokens; n   char *token = strtok(str, delimiter); n   while (token != nullptr) { n     tokens.emplace_back(token); n     token = strtok(nullptr, delimiter); n   } n   return tokens; n } n vector<string> split(const string &s, char delimiter) { n   vector<string> tokens; n   string token; n   istringstream tokenStream(s); n   while (getline(tokenStream, token, delimiter)) { n     tokens.push_back(token); n   } n   return tokens; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   while (a != 0 && b != 0) { n     if (a > b) { n       a %= b; n     } else if (a < b) { n       b %= a; n     } else { n       return a; n     } n   } n   return a + b; n } n long long divS(long long a) { n   long long res = 0; n   while (a > 0) { n     res += a % 10; n     a /= 10; n   } n   return res; n } n int distToSym(char a, char b) { n   if (abs(int(a) - int(b)) <= 13) n     return abs(int(a) - int(b)); n   else n     return (26 % abs(int(a) - int(b))); n } n int main() { n   ios_base::sync_with_stdio(false); n   string s; n   cin >> s; n   bool v = false, h = false; n   for (auto& x : s) { n     if (x ==  0 ) { n       if (v) n         cout <<  1 1 n ; n       else n         cout <<  3 1 n ; n       v = !v; n     } else { n       if (h) n         cout <<  1 1 n ; n       else n         cout <<  1 3 n ; n       h = !h; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 4010; n const int MAXT = 1 << 15; n int N, P, Q; n vector<pair<int, int> > qu[MAXT]; n vector<pair<int, int> > items[2 * MAXT]; n int ans[MAXT]; n void update(int a, int b, pair<int, int> v, int cur = 1, int lt = 0, n             int rt = MAXT) { n   if (rt <= a || b <= lt) { n     return; n   } n   if (a <= lt && rt <= b) { n     items[cur].push_back(v); n     return; n   } n   int mid = (lt + rt) / 2; n   update(a, b, v, 2 * cur, lt, mid); n   update(a, b, v, 2 * cur + 1, mid, rt); n } n int dp[17][MAXN]; n void rec(int lt = 0, int rt = MAXT, int cur = 1, int dep = 0) { n   if (dep) { n     memcpy(dp[dep], dp[dep - 1], sizeof(dp[dep])); n   } n   for (pair<int, int> p : items[cur]) { n     for (int i = MAXN - 1; i >= p.first; i--) { n       dp[dep][i] = max(dp[dep][i], dp[dep][i - p.first] + p.second); n     } n   } n   if (rt == lt + 1) { n     for (pair<int, int> p : qu[lt]) { n       ans[p.second] = dp[dep][p.first]; n     } n   } else { n     int mid = (lt + rt) / 2; n     rec(lt, mid, 2 * cur, dep + 1); n     rec(mid, rt, 2 * cur + 1, dep + 1); n   } n } n int main() { n   scanf( %d %d , &N, &P); n   for (int i = 0; i < N; i++) { n     int c, h, t; n     scanf( %d %d %d , &c, &h, &t); n     update(t, t + P, pair<int, int>(c, h)); n   } n   scanf( %d , &Q); n   for (int i = 0; i < Q; i++) { n     int t, b; n     scanf( %d %d , &t, &b); n     qu[t].push_back(pair<int, int>(b, i)); n   } n   rec(); n   for (int i = 0; i < Q; i++) { n     printf( %d n , ans[i]); n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:256000000 ) n using namespace std; n int main() { n   int tux; n   cin >> tux; n   int foo = 0; n   int bar = 0; n   int baz = 0; n   int quz = 1; n   for (int i = 0; i < tux; i++) { n     int pur; n     cin >> pur; n     foo = foo + pur; n     bar = bar + 1; n     if (max(foo * quz, bar * baz) == foo * quz) { n       baz = foo; n       quz = bar; n     } n   } n   printf( %.10lf n , (double)baz / quz); n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 200005; n const int inf = 1234567890; n using namespace std; n int n, a, b; n int main(void) { n   cin >> n >> a >> b; n   double max_x = -1; n   for (int i = ((1) > (n - b) ? (1) : (n - b)); n        i <= ((n - 1) < (a) ? (n - 1) : (a)); i++) { n     double av1 = 1.0 * a / i; n     double av2 = 1.0 * b / (n - i); n     double cur_x = ((av1) < (av2) ? (av1) : (av2)); n     max_x = ((max_x) > (cur_x) ? (max_x) : (cur_x)); n   } n   cout << (int)max_x << endl; n   return 0; n } n


#include <bits/stdc++.h> n static inline void setio(void); n int main(void) { n   setio(); n   long long n; n   std::cin >> n; n   std::vector<long long> vec(n); n   std::vector<char> neg(n); n   for (long long i = 0; i < n; ++i) { n     std::cin >> vec[i]; n     if (vec[i] < 0) { n       neg[i] = true; n       vec[i] = -vec[i]; n     } n   } n   std::vector<long long> primes; n   std::vector<char> sieve(1000000, true); n   for (long long i = 2; i < sieve.size(); ++i) { n     if (!sieve[i]) continue; n     primes.push_back(i * i); n     if (primes.back() > 100000001LL) break; n     for (long long j = i + i; j < sieve.size(); j += i) sieve[j] = false; n   } n   for (auto& num : vec) { n     for (const auto& p : primes) { n       if (p > num) break; n       while (num % p == 0) num /= p; n     } n   } n   for (long long i = 0; i < n; ++i) n     if (neg[i]) vec[i] = -vec[i]; n   std::vector<long long> cnts(n + 1, 0); n   std::vector<long long> last_time(n); n   std::map<long long, long long> bleh; n   for (long long i = 0; i < n; ++i) { n     last_time[i] = bleh[vec[i]] - 1; n     bleh[vec[i]] = i + 1; n   } n   bool seen_zero; n   for (long long i = 0; i < n; ++i) { n     long long count = 0; n     seen_zero = false; n     for (long long j = i; j < n; ++j) { n       count += last_time[j] < i; n       seen_zero = seen_zero || vec[j] == 0; n       if (count == 1 && seen_zero) n         cnts[count]++; n       else if (count > 0) n         cnts[count - (seen_zero)]++; n     } n   } n   for (long long i = 1; i <= n; ++i) std::cout << cnts[i] <<    ; n   std::cout <<   n ; n   return 0; n } n static inline void setio(void) { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   std::cout.precision(10); n   std::cout << std::fixed; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, c, d; n   cin >> a >> b >> c >> d; n   long long x = max((3 * a) / 10, (a - ((a / 250) * c))); n   long long y = max((3 * b) / 10, (b - ((b / 250) * d))); n   string s =  Tie ; n   if (x > y) n     s =  Misha ; n   else if (x < y) n     s =  Vasya ; n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int seg[(long long int)3e5 * 3]; n int laz[(long long int)3e5 * 3]; n void build(int index, int a, int b, int *ar) { n   if (a == b) { n     seg[index] = ar[a]; n     return; n   } n   int mid = (a + b) / 2; n   build(2 * index, a, mid, ar); n   build(2 * index + 1, mid + 1, b, ar); n   seg[index] = max(seg[2 * index], seg[2 * index + 1]); n } n void la(int l, int r, int index) { n   seg[index] += laz[index]; n   int a = 2 * index; n   int b = 2 * index + 1; n   if (l < r) { n     laz[a] += laz[index]; n     laz[b] += laz[index]; n   } n   laz[index] = 0; n } n void upd(int val, int l, int r, int x, int y, int index) { n   la(x, y, index); n   if (x > r || l > y) return; n   if (l <= x and r >= y) { n     laz[index] += val; n     la(x, y, index); n     return; n   } n   int mid = (x + y) / 2; n   upd(val, l, r, x, mid, 2 * index); n   upd(val, l, r, mid + 1, y, 2 * index + 1); n   seg[index] = max(seg[2 * index], seg[2 * index + 1]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m, p; n   cin >> n >> m >> p; n   vector<pair<int, int>> weap; n   vector<pair<int, int>> armr; n   vector<pair<int, pair<int, int>>> monst; n   for (int i = 0; i < n; i++) { n     int a, b; n     cin >> a >> b; n     weap.push_back({a, b}); n   } n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     armr.push_back({a, b}); n   } n   for (int i = 0; i < p; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     monst.push_back({a, {b, c}}); n   } n   sort(weap.begin(), weap.end()); n   sort(armr.begin(), armr.end()); n   sort(monst.begin(), monst.end()); n   int pt = 0; n   int ar[(int)3e5]; n   for (int i = 0; i < m; i++) ar[i + 1] = -armr[i].second; n   build(1, 1, m, ar); n   int ans = -2 * (1e9 + 7); n   for (int i = 0; i < n; i++) { n     while (pt < p and weap[i].first > monst[pt].first) { n       int l = upper_bound(armr.begin(), armr.end(), n                           make_pair(monst[pt].second.first, (int)1e9 + 7)) - n               armr.begin(); n       l++; n       if (l <= m) { n         upd(monst[pt].second.second, l, m, 1, m, 1); n       } n       pt++; n     } n     ans = max(ans, (seg[1] - weap[i].second)); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ifstream ff( file.txt ); n   int n, m; n   cin >> n >> m; n   map<int, int> Mymap; n   int u; n   for (int i = 0; i < n; i++) { n     cin >> u; n     Mymap.insert(pair<int, int>(i + 1, u)); n   } n   unsigned long long sum = 0; n   vector<int> v2; n   int z; n   unsigned int sv; n   for (int i = 0; i < m; i++) { n     sv = v2.size(); n     cin >> z; n     if (v2.empty()) { n       v2.push_back(z); n     } else { n       for (int j = sv - 1; j >= 0; j--) { n         if (v2[j] != z) { n           sum += Mymap[v2[j]]; n         } else { n           v2.erase(v2.begin() + j); n           v2.push_back(z); n           break; n         } n         if (j == 0) { n           v2.push_back(z); n         } n       } n     } n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n int n, p[N]; n void solve(int n) { n   if ((n & 1) && (n - 1) % 4) { n     puts( -1 ); n     return; n   } n   if (!(n & 1) && n % 4) { n     puts( -1 ); n     return; n   } n   if (n & 1) p[(n + 1) >> 1] = (n + 1) >> 1; n   for (int i = (1); i < ((n >> 1) + 1); ++i) n     if (!p[i]) { n       p[i] = i + 1; n       p[i + 1] = n + 1 - i; n       p[n + 1 - i] = n - i; n       p[n - i] = i; n     } n   for (int i = (1); i < (n + 1); ++i) printf( %d%c , p[i],    n [i == n]); n } n int main() { n   scanf( %d , &n); n   solve(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long INF = (long)1e09; n int n, m, k, p = 0, id, inv, minv, ans, d = -2; n int main() { n   scanf( %d , &n); n   if (n == 3) { n     cout << 5; n     return 0; n   } n   if (n == 1) { n     cout << 1; n     return 0; n   } n   for (m = 3; (m * m + 1) / 2 < n; m += 2) n     ; n   printf( %d , m); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void getar(T a, int n, int m) { n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; ++j) { n       scanf( %d , &a[i][j]); n     } n } n inline void getar(int *a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %d , a + ii); n   } n } n inline void getar(pair<int, int> *a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( d , &a[ii].first, &a[ii].second); n   } n } n inline void getar(long long *a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %I64d , a + ii); n   } n } n inline void getv(vector<int> &a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %d , &a[ii]); n   } n } n inline void getv(vector<long long> &a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %I64d , &a[ii]); n   } n } n inline void getv(vector<pair<int, int> > &a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %d , &a[ii].first, &a[ii].second); n   } n } n inline void getv(vector<pair<long long, long long> > &a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %I64d , &a[ii].first, &a[ii].second); n   } n } n inline void getvv(vector<vector<int> > &a, int n, int m) { n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; ++j) { n       scanf( %d , &a[i][j]); n     } n } n inline void printa(int *a, int i, int j) { n   for (int ii = i; ii <= j; ii++) { n     printf( %d  , a[ii]); n   } n } n inline void printa(long long *a, int i, int j) { n   for (int ii = i; ii <= j; ii++) { n     printf( %I64d  , a[ii]); n   } n } n inline void printv(vector<int> &a, int i, int j) { n   for (int ii = i; ii <= j; ii++) { n     printf( %d  , a[ii]); n   } n } n inline void printv(vector<long long> &a, int n, int i, int j) { n   for (int ii = i; ii <= j; ii++) { n     printf( %I64d  , a[ii]); n   } n } n inline long long max(long long a, long long b) { return (a > b) ? a : b; } n inline int max(int a, int b) { return (a > b) ? a : b; } n inline double max(double a, double b) { return (a > b) ? a : b; } n inline long long max(long long a, long long b, long long c) { n   return max(a, max(b, c)); n } n inline int max(int a, int b, int c) { return max(a, max(b, c)); } n inline double max(double a, double b, double c) { return max(a, max(b, c)); } n inline long long min(long long a, long long b) { return (a < b) ? a : b; } n inline int min(int a, int b) { return (a < b) ? a : b; } n inline double min(double a, double b) { return (a < b) ? a : b; } n inline long long min(long long a, long long b, long long c) { n   return min(a, min(b, c)); n } n inline int min(int a, int b, int c) { return min(a, min(b, c)); } n inline double min(double a, double b, double c) { return min(a, min(b, c)); } n inline long long pow(long long x, long long n) { n   long long res = 1; n   while (n) { n     if (n & 1) res *= x; n     x *= x; n     n >>= 1; n   } n   return res; n } n inline long long powmod(long long x, long long n, long long _mod) { n   long long res = 1; n   while (n) { n     if (n & 1) res = (res * x) % _mod; n     x = (x * x) % _mod; n     n >>= 1; n   } n   return res; n } n inline long long gcd(long long a, long long b) { n   long long t; n   while (b) { n     a = a % b; n     t = a; n     a = b; n     b = t; n   } n   return a; n } n inline int gcd(int a, int b) { n   int t; n   while (b) { n     a = a % b; n     t = a; n     a = b; n     b = t; n   } n   return a; n } n inline long long lcm(int a, int b) { return a / gcd(a, b) * (long long)b; } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long gcd(long long a, long long b, long long c) { n   return gcd(gcd(a, b), c); n } n inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); } n inline long long lcm(long long a, long long b, long long c) { n   return lcm(lcm(a, b), c); n } n inline long long lcm(int a, int b, int c) { n   return lcm(lcm(a, b), (long long)c); n } n inline int bits_count(int v) { n   v = v - ((v >> 1) & 0x55555555); n   v = (v & 0x33333333) + ((v >> 2) & 0x33333333); n   return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; n } n inline int bits_count(long long v) { n   long long t = v >> 32; n   long long p = (v & ((1LL << 32) - 1)); n   return bits_count(t) + bits_count(p); n } n inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); } n const char nl =   n ; n string s; n int n, k; n string rgb; n vector<vector<int> > dp; n void intialize_dp() { n   for (int i = 0; i < 3; i++) n     for (int j = 0; j < k; j++) dp[i][0] += (s[j] != rgb[(j + i) % 3]); n } n void solve() { n   rgb =  RGB ; n   cin >> n >> k; n   cin >> s; n   dp = vector<vector<int> >(3, vector<int>(n, 0)); n   intialize_dp(); n   bool prev_first, cur_last; n   int ans = min(dp[0][0], dp[1][0], dp[2][0]); n   for (int i = 0; i < 3; i++) n     for (int j = 1; j < n - k + 1; j++) { n       prev_first = (s[j - 1] != rgb[(j - 1 + i) % 3]); n       cur_last = (s[j + k - 1] != rgb[(j + i + k - 1) % 3]); n       dp[(i + j) % 3][j] = dp[(i + j - 1) % 3][j - 1] + cur_last - prev_first; n       ans = min(ans, dp[(i + j) % 3][j]); n     } n   cout << ans << nl; n } n int main() { n   clock_t clk = clock(); n   cerr <<  Hey P.. n ; n   int t; n   cin >> t; n   while (t--) solve(); n   cerr <<  Look at the sky. n ; n   cerr <<  Time (in ms):   << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p; n long long u, v, w, res; n map<long long, long long> a; n void cal(long long u, long long v, long long w) { n   res = 0; n   while (u != v) { n     if (u < v) swap(u, v); n     a[u] += w; n     if (w == 0) res += a[u]; n     u >>= 1; n   } n } n int main() { n   cin >> n; n   while (n-- > 0) { n     cin >> p; n     if (p == 1) { n       cin >> u >> v >> w; n       cal(u, v, w); n     } else { n       cin >> u >> v; n       cal(u, v, 0); n       cout << res << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long tc = 1; n   cin >> tc; n   while (tc--) { n     long long n; n     cin >> n; n     set<long long> st; n     for (long long i = 0; i < n; i++) { n       long long a; n       cin >> a; n       st.insert(a); n     } n     if (st.size() > 1) n       cout <<  1 n ; n     else n       cout << n <<   n ; n   } n } n


#include <bits/stdc++.h> n struct info { n   int p, c; n }; n bool vis[5010]; n int check[10010], level = 1, I[5010], pair[10010], result[5010]; n info input[5010]; n std::vector<int> graph[10010]; n bool dfs(int index) { n   check[index] = level; n   for (int i = 0; i < graph[index].size(); i++) { n     int next = graph[index][i]; n     if (pair[next] == -1) { n       pair[next] = index; n       return true; n     } else if (check[pair[next]] != level && dfs(pair[next])) { n       pair[next] = index; n       return true; n     } n   } n   return false; n } n int main(void) { n   int n, m, d; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &input[i].p); n   for (int i = 1; i <= n; i++) scanf( %d , &input[i].c); n   scanf( %d , &d); n   for (int i = 1; i <= d; i++) { n     scanf( %d , I + i); n     vis[I[i]] = true; n   } n   for (int i = 1; i <= n; i++) { n     if (vis[i] == false && input[i].p < m) { n       graph[input[i].p].push_back(input[i].c + m - 1); n     } n   } n   memset(pair, -1, sizeof(pair)); n   int r = 0; n   while (r < m && dfs(r)) { n     level++; n     r++; n   } n   for (int i = d; i >= 1; i--) { n     result[i] = r; n     if (input[I[i]].p < m) n       graph[input[I[i]].p].push_back(input[I[i]].c + m - 1); n     level++; n     while (r < m && dfs(r)) { n       level++; n       r++; n     } n   } n   for (int i = 1; i <= d; i++) printf( %d n , result[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10; n const int maxn5 = 5e5 + 10; n const int maxnt = 1.2e6 + 10; n const int maxn3 = 1e3 + 10; n const long long mod = 1e9 + 7; n const long long inf = 2e18; n int st, cmp[maxn5], nxt[maxn5], pre[maxn5]; n vector<int> adj[maxn5], ver[maxn5]; n bool mark[maxn5]; n void join(int a, int b) { n   if (ver[a].size() > ver[b].size()) swap(a, b); n   for (auto u : ver[a]) { n     cmp[u] = b; n     ver[b].push_back(u); n   } n   if (a == st) { n     st = nxt[a]; n     pre[nxt[a]] = -1; n   } else { n     if (nxt[a] != -1) pre[nxt[a]] = pre[a]; n     nxt[pre[a]] = nxt[a]; n   } n   ver[a].clear(); n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   for (int i = 1; i <= n; i++) { n     cmp[i] = i; n     ver[i].push_back(i); n     pre[i] = i == 1 ? -1 : i - 1; n     nxt[i] = i == n ? -1 : i + 1; n   } n   st = 1; n   for (int i = 1; i <= n; i++) { n     int ind = st; n     for (auto u : adj[i]) mark[u] = true; n     while (ind != -1) { n       if (ind == cmp[i]) { n         ind = nxt[ind]; n         continue; n       } n       bool done = false; n       for (auto u : ver[ind]) n         if (!mark[u]) { n           int c = ind; n           ind = nxt[ind]; n           done = true; n           join(c, cmp[i]); n           break; n         } n       if (!done) ind = nxt[ind]; n     } n     for (auto u : adj[i]) mark[u] = false; n   } n   int cnt = 0, ind = st; n   while (ind != -1) { n     cnt++; n     ind = nxt[ind]; n   } n   cout << cnt <<   n ; n   while (st != -1) { n     cout << ver[st].size() <<    ; n     for (auto u : ver[st]) cout << u <<    ; n     cout <<   n ; n     st = nxt[st]; n   } n   return 0; n } n


#include <bits/stdc++.h> n int x[2002], y[2002]; n using namespace std; n int main() { n   int n; n   cin >> n; n   set<int> S; n   for (int i = 1; i <= n; ++i) { n     cin >> x[i]; n     S.insert(x[i]); n   } n   for (int i = 1; i <= n; ++i) { n     cin >> y[i]; n     S.insert(y[i]); n   } n   int val = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       if (S.find(x[i] ^ y[j]) != S.end()) val++; n     } n   } n   if (val & 1) n     cout <<  Koyomi n ; n   else n     cout <<  Karen n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 4e4; n long long a[maxn]; n int v[maxn]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   for (long long i = 1; i < maxn; i++) { n     a[i] = i * (i - 1) / 2; n   } n   int T; n   cin >> T; n   while (T--) { n     long long n; n     cin >> n; n     int tn = 0; n     for (int i = maxn - 1; i && n; i--) { n       while (n >= a[i]) { n         n -= a[i]; n         v[++tn] = i; n       } n     } n     v[tn + 1] = 0; n     for (int i = 1; i <= tn; i++) { n       cout << 1; n       for (int j = 0; j < v[i] - v[i + 1]; j++) cout << 3; n     } n     cout << 7 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long; n int n, x, y; n bool ask_1y(const vector<int>& a) { n   if (a.empty()) { n     return false; n   } n   cout <<  ?   << a.size(); n   for (int i : a) { n     cout <<     << i + 1; n   } n   cout << endl; n   int r; n   cin >> r; n   return r == y || r == (x ^ y); n } n bool same[11]; n void solve(istream& cin, ostream& cout) { n   cin >> n >> x >> y; n   int hb = -1; n   for (int i = 0; i < 10; i++) { n     vector<int> a; n     for (int j = (0); j < int(n); ++j) { n       if ((((j) >> (i)) & 1)) { n         a.push_back(j); n       } n     } n     if (ask_1y(a)) { n       hb = i; n     } else { n       same[i] = true; n     } n   } n   int a = 0; n   int b = 0; n   for (int i = 0; i < 10; i++) { n     if (i == hb) { n       b |= (1 << (hb)); n       continue; n     } n     vector<int> v; n     for (int j = (0); j < int(n); ++j) { n       if (!(((j) >> (i)) & 1) && !(((j) >> (hb)) & 1)) { n         v.push_back(j); n       } n     } n     if (ask_1y(v)) { n       if (!same[i]) { n         b |= (1 << (i)); n       } n     } else { n       a |= (1 << (i)); n       if (same[i]) { n         b |= (1 << (i)); n       } n     } n   } n   cout <<  !   << a + 1 <<     << b + 1 <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   solve(cin, cout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 7 + 5; n int n, a[maxn]; n char str[maxn]; n int main() { n   cin >> n; n   int ans = 0; n   while (n--) { n     cin >> str; n     for (int i = 0; i < 7; i++) { n       a[i] += str[i] -  0 ; n       ans = max(ans, a[i]); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int sum = 0; n   sort(a, a + n); n   for (int i = 0; i < n; i++) { n     sum = sum + (a[n - 1] - a[i]); n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n int low, up, x, n; n int vec[16]; n int recurse(int i, int a, int b, int s, int cnt) { n   if (i == n) { n     if (cnt >= 2 && low <= s && s <= up && a - b >= x) { n       return 1; n     } n     return 0; n   } n   return recurse(i + 1, max(a, vec[i]), min(b, vec[i]), s + vec[i], cnt + 1) + n          recurse(i + 1, a, b, s, cnt); n } n int main() { n   scanf( %d , &n); n   scanf( %d , &low); n   scanf( %d , &up); n   scanf( %d , &x); n   for (int i = 0; i <= n - 1; ++i) scanf( %d , &vec[i]); n   printf( %d n , recurse(0, INT_MIN, INT_MAX, 0, 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class TH> n void _dbg(const char *sdbg, TH h) { n   cerr << sdbg <<  =  << h << endl; n } n template <class TH, class... TA> n void _dbg(const char *sdbg, TH h, TA... a) { n   while (*sdbg !=  , ) cerr << *sdbg++; n   cerr <<  =  << h <<  , ; n   _dbg(sdbg + 1, a...); n } n template <class L, class R> n ostream &operator<<(ostream &os, pair<L, R> p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <class Iterable, n           class = typename enable_if<!is_same<string, Iterable>::value>::type> n auto operator<<(ostream &os, Iterable v) -> decltype(os << *begin(v)) { n   os <<  [ ; n   for (auto vv : v) os << vv <<  ,  ; n   return os <<  ] ; n } n const int inf = 0x3f3f3f3f; n const long long infll = 0x3f3f3f3f3f3f3f3fll; n template <class T> n int sign(T x) { n   return (x > 0) - (x < 0); n } n template <class T> n T abs(const T &x) { n   return (x < T(0)) ? -x : x; n } n vector<int> graph[112345]; n int c[112345][4]; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   int n, a, b; n   cin >> n; n   for (int k = 1; k <= 3; k++) n     for (int i = 1; i <= n; i++) cin >> c[i][k]; n   for (int i = 0; i + 1 < n; i++) { n     cin >> a >> b; n     graph[a].push_back(b); n     graph[b].push_back(a); n   } n   int start; n   for (int i = 1; i <= n; i++) { n     if (graph[i].size() > 2) { n       cout << -1 << endl; n       return 0; n     } n     if (graph[i].size() == 1) start = i; n   } n   vector<int> pi = {1, 2, 3}; n   long long ans = infll; n   vector<int> best_color; n   vector<int> color(n + 1); n   do { n     long long tmp = 0; n     int cur = start; n     int prev = start; n     for (int i = 0; i < n; i++) { n       color[cur] = pi[i % 3]; n       tmp += c[cur][pi[i % 3]]; n       for (int j = 0; j < graph[cur].size(); j++) n         if (graph[cur][j] != prev) { n           prev = cur; n           cur = graph[cur][j]; n           break; n         } n     } n     if (tmp < ans) { n       ans = min(ans, tmp); n       best_color = color; n     } n   } while (next_permutation(pi.begin(), pi.end())); n   cout << ans << endl; n   for (int i = 1; i <= n; i++) cout << best_color[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n < 6) n     cout << -1 << endl; n   else { n     for (int i = 2; i <= 4; i++) cout << 1 <<     << i << endl; n     for (int i = 5; i <= n; i++) { n       cout << 2 <<     << i << endl; n     } n   } n   for (int i = 1; i < n; i++) { n     cout << i <<     << i + 1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<vector<int>> adj; n vector<vector<int>> vis; n int dfs1(int a, int b) { n   if (a == n - 1 and b == m - 1) return 1; n   vis[a][b] = 1; n   if (a + 1 < n and adj[a + 1][b] and !vis[a + 1][b]) n     if (dfs1(a + 1, b)) return 1; n   if (b + 1 < m and adj[a][b + 1] and !vis[a][b + 1]) n     if (dfs1(a, b + 1)) return 1; n   vis[a][b] = 2; n   return 0; n } n int dfs2(int a, int b) { n   if (a == n - 1 and b == m - 1) return 1; n   vis[a][b] = 1; n   if (a + 1 < n and adj[a + 1][b] and vis[a + 1][b] != 1) n     if (dfs2(a + 1, b)) return 1; n   if (b + 1 < m and adj[a][b + 1] and vis[a][b + 1] != 1) n     if (dfs2(a, b + 1)) return 1; n   return 0; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   adj = vector<vector<int>>(n, vector<int>(m)); n   for (int i = 0; i < n; ++i) { n     string s; n     cin >> s; n     for (int j = 0; j < m; ++j) { n       if (s[j] ==  . ) n         adj[i][j] = 1; n       else n         adj[i][j] = 0; n     } n   } n   int a = 0; n   vis = vector<vector<int>>(n, vector<int>(m, 0)); n   a += dfs1(0, 0); n   a += dfs2(0, 0); n   cout << a <<   n ; n } n


#include <bits/stdc++.h> n long long cmpfunc(const void* a, const void* b) { n   return (*(long long*)a - *(long long*)b); n } n int main(void) { n   long long int test, i, j, n, count, flag = 0, o1 = 0, o2 = 0, b1, x, m, l, n                                       max, sum2, min, f, r, o, sum1, sum = 0, y, n                                       count1 = 0, a[1000000]; n   scanf( %lld , &n); n   count = 0; n   f = 0; n   for (i = 0; i < n; i++) { n     scanf( %lld , &x); n     if (a[x] == 0 && x != 0) { n       count++; n       a[x]++; n     } n   } n   printf( %lld n , count); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (a % b == 0) return b; n   return gcd(b, a % b); n } n int v[11]; n int main() { n   int a, k = 0; n   scanf( %d , &a); n   for (int i = 2; i < a; i++) { n     int t = a; n     int pos = 0; n     while (t) { n       int mod = t % i; n       k += mod; n       t = (t - mod) / i; n       if (!t) break; n     } n   } n   int vbcd = gcd(k, a - 2); n   printf( %d/%d , k / vbcd, (a - 2) / vbcd); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x[100009], y[100009], sx, sy; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x[i] >> y[i]; n     sx += x[i]; n     sy += y[i]; n   } n   if (sx % 2 == 0 && sy % 2 == 0) { n     cout << 0; n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     if ((sx - x[i] + y[i]) % 2 == 0 && (sy - y[i] + x[i]) % 2 == 0) { n       cout << 1; n       return 0; n     } n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n long long int min(long long int a, long long int b) { n   if (a < b) { n     return a; n   } else { n     return b; n   } n } n long long int max(long long int a, long long int b) { n   if (a > b) { n     return a; n   } else { n     return b; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     string str; n     cin >> str; n     if (n == 1) { n       cout << 1 <<   n ; n       continue; n     } n     if (n == 2) { n       if (str[0] == str[1]) { n         cout << 1 <<   n ; n         continue; n       } n     } n     vector<long long int> seg; n     long long int curr_length = 1; n     for (long long int i = 0; i < str.size() - 1; i++) { n       if (str[i] == str[i + 1]) { n         curr_length++; n       } else { n         seg.push_back(curr_length); n         curr_length = 1; n       } n     } n     seg.push_back(curr_length); n     long long int segtillnow = 0; n     long long int ans = 0; n     for (long long int i = 0; i < seg.size(); i++) { n       segtillnow++; n       if (seg[i] == 1) { n         continue; n       } else if (seg[i] > 1) { n         long long int operations = min(seg[i] - 1, segtillnow); n         ans += operations; n         segtillnow -= operations; n       } n     } n     ans += ((segtillnow + 1) / 2); n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string cad1; n   string cad2; n   cin >> cad1 >> cad2; n   if (cad1 == cad2) { n     cout <<  YES ; n   } else { n     if (cad1.size() != cad2.size()) { n       cout <<  NO ; n     } else { n       int ceros = 0; n       int unos = 0; n       for (int i = 0; i < cad2.size(); ++i) { n         if (cad2[i] ==  0 ) ceros++; n         if (cad1[i] ==  1 ) unos++; n       } n       if (ceros == cad2.size()) n         cout <<  NO ; n       else { n         if (unos > 0) n           cout <<  YES ; n         else n           cout <<  NO ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100000]; n int n, m, x, y, i, sol, v[501][501]; n int main() { n   cin >> n >> m >> x >> y; n   cin >> s; n   cout << 1 <<    ; n   int l = strlen(s); n   for (i = 0; i < l - 1; i++) { n     v[x][y] = 1; n     if (s[i] ==  R  && y < m) y++; n     if (s[i] ==  L  && y > 1) y--; n     if (s[i] ==  U  && x > 1) x--; n     if (s[i] ==  D  && x < n) x++; n     if (v[x][y] == 1) n       cout << 0 <<    ; n     else { n       cout << 1 <<    ; n       sol++; n     } n   } n   cout << n * m - sol - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, cnt; n char phone[128]; n int main() { n   scanf( %d , &n); n   scanf( %s , phone); n   cnt = 0; n   for (int i = 0; i < n; i++) { n     if (cnt == 2 and n - i >= 2) { n       printf( - ); n       cnt = 0; n     } n     printf( %c , phone[i]); n     cnt++; n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double a, b; n int main() { n   cin >> a >> b; n   cout << fixed << a * pow((long double)1.000000011, b) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<string> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   set<string> s; n   for (int i = n - 1; i >= 0; i--) { n     if (s.find(a[i]) == s.end()) { n       cout << a[i] <<   n ; n     } n     s.insert(a[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n const long double EPS = 1e-10; n const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; n const int MAX_N = 400; n int ans[181]; n void init() { n   fill(ans, ans + 181, -1); n   for (int i = 3; i <= MAX_N; ++i) { n     double min_deg = 180.0 / i; n     for (int deg = 1; deg <= 180; ++deg) { n       if (ans[deg] != -1) continue; n       if (deg - floor(deg / min_deg + EPS) * min_deg < EPS && n           deg <= min_deg * double(i - 2)) n         ans[deg] = i; n     } n   } n } n int main() { n   init(); n   int t, deg; n   cin >> t; n   while (t--) { n     cin >> deg; n     cout << ans[deg] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long ans; n void solve(long long a, long long b, long long c, long long l) { n   for (long long i = 0; i <= l; i++) { n     long long x = min(a - b - c + i, l - i); n     if (x >= 0) ans -= (x + 1) * (x + 2) / 2LL; n   } n } n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long a, b, c, l; n   cin >> a >> b >> c >> l; n   ans = (l + 1) * (l + 2) * (l + 3) / 6LL; n   solve(a, b, c, l); n   solve(b, a, c, l); n   solve(c, a, b, l); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T m, T n) { n   while (n) { n     T t = m % n; n     m = n; n     n = t; n   }; n   return m; n } n template <typename T> n T exgcd(T a, T b, T& sa, T& ta) { n   T q, r, sb = 0, tb = 1, sc, tc; n   sa = 1, ta = 0; n   if (b) do n       q = a / b, r = a - q * b, a = b, b = r, sc = sa - q * sb, sa = sb, n       sb = sc, tc = ta - q * tb, ta = tb, tb = tc; n     while (b); n   return a; n } n template <typename T> n T mul_inv(T a, T b) { n   T t1 = a, t2 = b, t3; n   T v1 = 1, v2 = 0, v3; n   T x; n   while (t2 != 1) n     x = t1 / t2, t3 = t1 - x * t2, v3 = v1 - x * v2, t1 = t2, t2 = t3, v1 = v2, n     v2 = v3; n   return (v2 + b) % b; n } n template <typename T> n T powmod(T a, T b, T MOD) { n   if (b < 0) return 0; n   T rv = 1; n   while (b) (b % 2) && (rv = (rv * a) % MOD), a = a * a % MOD, b /= 2; n   return rv; n } n const int maxn = 2e5 + 7; n int n; n int L; n int a[maxn]; n int b[maxn]; n vector<int> to_remove[maxn]; n vector<int> to_add[maxn]; n int dist_tbl[maxn]; n bool explored[maxn]; n int dis(int x, int y) { return min(abs(x - y), L - abs(x - y)); } n int calc(int k) { n   int& r = dist_tbl[k]; n   if (r >= 0) return r; n   r = 0; n   for (int i = 0; i < n; i++) r = max(r, dis(a[i], b[(i + k) % n])); n   return r; n } n int main(int argc, char* argv[]) { n   std::cin.sync_with_stdio(false); n   std::cin.tie(nullptr); n   cin >> n >> L; n   { n     clock_t time_start = clock(); n     clock_t time_end = time_start + CLOCKS_PER_SEC * 0.8; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) cin >> b[i]; n     sort(a, a + n); n     sort(b, b + n); n     memset(dist_tbl, -1, sizeof(dist_tbl)); n     memset(explored, 0, sizeof(explored)); n     map<int, set<int> > values; n     for (int i = 0, ij = max(1, n / 64); i < n; i += ij) { n       values[calc(i)].insert(i); n     } n     int explore_values[] = {-4, -2, -1, 1, 2, 4, 0}; n     while (clock() < time_end && values.size() < n) { n       vector<int> toExplore; n       int nmin = 64; n       for (auto it : values) { n         if (it.second.empty()) --nmin; n         for (int k : it.second) { n           if (--nmin < 0) break; n           if (!explored[k]) { n             toExplore.push_back(k); n             explored[k] = true; n           } n         } n         if (nmin < 0) break; n       } n       if (toExplore.size() == 0) break; n       int new_explore = 0; n       for (int k : toExplore) { n         values[calc(k)].erase(k); n         for (int ei = 0; explore_values[ei]; ei++) { n           int k2 = (k + n + explore_values[ei]) % n; n           k2 = (k2 + n) % n; n           if (dist_tbl[k2] < 0) { n             new_explore++; n             values[calc(k2)].insert(k2); n           } n         } n       } n       if (!new_explore) break; n     } n     cout << values.begin()->first << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fr() { n   freopen( test_input.txt ,  r , stdin); n   freopen( a.out ,  w , stdout); n } n const int N = 5e5 + 5; n const int MAX = 5e6 + 123; n const int INF = 2e9; n const int mod = 1e9 + 7; n const double pi = 3.1415926536; n double eps = 1e-10; n bool used1[N], used2[N]; n void solve() { n   int n; n   string s1, s2; n   map<int, int> cnt1, cnt2; n   map<int, pair<int, int> > ans; n   cin >> s1 >> s2; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int t, m; n     char p, c; n     cin >> t >> p >> m >> c; n     if (p ==  h ) { n       if (c ==  y ) n         cnt1[m]++; n       else n         cnt1[m] += 2; n       if (cnt1[m] >= 2 and !used1[m]) { n         ans[t] = make_pair(0, m); n         used1[m] = 1; n       } n     } else { n       if (c ==  y ) n         cnt2[m]++; n       else n         cnt2[m] += 2; n       if (cnt2[m] >= 2 and !used2[m]) { n         ans[t] = make_pair(1, m); n         used2[m] = 1; n       } n     } n   } n   for (int i = 1; i <= 90; i++) { n     if (ans[i] != make_pair(0, 0)) { n       if (ans[i].first == 0) n         cout << s1 <<    ; n       else n         cout << s2 <<    ; n       cout << ans[i].second <<     << i << endl; n     } n   } n } n int t; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5010; n int n, k; n int a[N]; n int dp[N][N / 2][2]; n int solve(int r, int num, int sub) { n   if (num == 0) return 0; n   int& res = dp[r][num][sub]; n   if (res != 1000000000) return res; n   if (sub == 1) { n     res = solve(r - 2, num - 1, (a[r - 1] < a[r] ? 0 : 1)) + n           (a[r - 1] < a[r] ? 0 : (a[r - 1] - a[r] + 1)) + n           (a[r + 2] - 1 < a[r] ? 0 : (a[r + 2] - 1 - a[r] + 1)); n     if (num * 2 <= r) { n       res = min(res, solve(r - 1, num, 0)); n     } n   } else { n     res = solve(r - 2, num - 1, (a[r - 1] < a[r] ? 0 : 1)) + n           (a[r - 1] < a[r] ? 0 : (a[r - 1] - a[r] + 1)) + n           (a[r + 1] < a[r] ? 0 : (a[r + 1] - a[r] + 1)); n     if (num * 2 <= r) { n       res = min(solve(r - 1, num, 0), res); n     } n   } n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   k = (n + 1) / 2; n   for (int i = 0; i < n; i++) { n     cin >> a[i + 1]; n   } n   a[0] = -100; n   a[n + 1] = -100; n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < N / 2; j++) { n       for (int k = 0; k < 2; k++) { n         dp[i][j][k] = 1000000000; n       } n     } n   } n   cout << solve(n, 1, 0); n   for (int i = 2; i < k + 1; i++) { n     cout <<     << solve(n, i, 0); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, p, q1, q2, t, a[300010], y[300010], w, u; n long long x[300010]; n map<long long, int> f, g; n vector<int> r[300010]; n inline bool cmp(int a, int b) { return x[a] < x[b]; } n inline int power(int a, int b, int q) { n   if (!b) return 1; n   int c = power(a, b >> 1, q); n   c = (long long)c * c % q; n   if (b & 1) c = (long long)c * a % q; n   return c; n } n inline long long ran() { n   return ((long long)rand() << 45) + ((long long)rand() << 30) + n          (rand() << 15) + rand(); n } n inline void dfs(int i) { n   int j; n   u--; n   g[x[i]] = ++w; n   for (j = 0; j < r[i].size(); j++) n     if (!g[x[r[i][j]]]) dfs(r[i][j]); n } n inline bool check(int p) { n   int i; n   for (i = 2; i * i <= p; i++) n     if (p % i == 0) return 0; n   return 1; n } n int main() { n   int i, j, k; n   srand(time(0)); n   ran(); n   ran(); n   ran(); n   for (q1 = ran() % 1000000000 + 100000000; !check(q1); q1++) n     ; n   for (q2 = ran() % 1000000000 + 100000000; !check(q2); q2++) n     ; n   for (p = ran() % 1000000 + 100000; !check(p); p++) n     ; n   for (t = ran() % 1000000 + 100000; !check(t); t++) n     ; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     x[i] = power(p, i ^ t, q1); n     y[i] = power(p, i ^ t, q2); n   } n   for (i = 1; i <= m; i++) { n     scanf( %d%d , &j, &k); n     x[j] = (x[j] + power(p, k ^ t, q1)) % q1; n     y[j] = (y[j] + power(p, k ^ t, q2)) % q2; n     x[k] = (x[k] + power(p, j ^ t, q1)) % q1; n     y[k] = (y[k] + power(p, j ^ t, q2)) % q2; n     r[j].push_back(k); n     r[k].push_back(j); n   } n   for (i = 1; i <= n; i++) { n     x[i] = x[i] * 2000000000 + y[i]; n     a[i] = i; n   } n   sort(a + 1, a + n + 1, cmp); n   for (i = 1; i <= n; i++) n     if (i == 1 || x[a[i]] != x[a[i - 1]]) { n       for (j = 0, k = 0; j < r[a[i]].size(); j++) n         if (x[r[a[i]][j]] != x[a[i]] && !g[x[r[a[i]][j]]]) { n           g[x[r[a[i]][j]]] = 1; n           k++; n         } n       g.clear(); n       f[x[a[i]]] = k; n       u++; n     } n   for (i = 1; i <= n; i++) n     if (f[x[i]] > 2) { n       u = 1; n       break; n     } else if (f[x[i]] <= 1 && !g[x[i]]) n       dfs(i); n   if (u) n     printf( NO n ); n   else { n     printf( YES n ); n     for (i = 1; i <= n; i++) printf( %d  , g[x[i]]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, m; n   cin >> n >> m; n   int a[n]; n   for (__typeof((n)) i = (0); i < (n); i++) cin >> a[i]; n   int fq[m]; n   for (__typeof((m)) i = (0); i < (m); i++) fq[i] = 0; n   for (__typeof((n)) i = (0); i < (n); i++) { n     fq[a[i] % m]++; n   } n   int flg = 0; n   for (__typeof((m)) i = (0); i < (m); i++) { n     if (fq[i] >= 2) { n       flg = 1; n       break; n     } n   } n   if (flg == 1) n     cout << 0 << endl; n   else { n     int prd = 1; n     for (__typeof((n)) i = (0); i < (n); i++) { n       for (int j = i + 1; j < n; j++) n         prd = ((prd % m) * (abs(a[i] - a[j]) % m)) % m; n     } n     cout << prd << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n1, n2; n   cin >> n1 >> n2; n   int k, m; n   cin >> k >> m; n   long long a[n1], b[n2]; n   for (int i = 0; i < n1; i++) cin >> a[i]; n   for (int i = 0; i < n2; i++) cin >> b[i]; n   int count = 0; n   for (int i = 0; i < n1; i++) { n     if (a[i] >= b[n2 - m]) break; n     count++; n     if (count >= k) break; n   } n   if (count >= k && n2 >= m) n     cout <<  YES n ; n   else n     cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int color[400100]; n int w[400100]; n struct segment_tree { n   long long a[1600100]; n   bool put[1600100]; n   void push(int x) { n     if (put[x]) { n       a[x * 2] = a[x * 2 + 1] = a[x]; n       put[x] = false; n       put[x * 2] = put[x * 2 + 1] = true; n     } n   } n   void calc(int x) { a[x] = a[x * 2] | a[x * 2 + 1]; } n   void build(int x, int l, int r) { n     if (l < r) { n       int y = (l + r) >> 1; n       build(x * 2, l, y); n       build(x * 2 + 1, y + 1, r); n       a[x] = a[x * 2] | a[x * 2 + 1]; n       put[x] = false; n     } else { n       a[x] = (1LL << color[w[l]]); n       put[x] = true; n     } n   } n   void modify(int x, int l, int r, int ll, int rr, long long v) { n     if (r < ll || l > rr) return; n     if (ll <= l && rr >= r) { n       a[x] = v; n       put[x] = true; n       return; n     } n     push(x); n     int y = (l + r) >> 1; n     modify(x * 2, l, y, ll, rr, v); n     modify(x * 2 + 1, y + 1, r, ll, rr, v); n     calc(x); n   } n   long long get(int x, int l, int r, int ll, int rr) { n     if (r < ll || l > rr) return 0LL; n     if (ll <= l && rr >= r) { n       return a[x]; n     } n     push(x); n     int y = (l + r) >> 1; n     long long ret = get(x * 2, l, y, ll, rr); n     ret |= get(x * 2 + 1, y + 1, r, ll, rr); n     calc(x); n     return ret; n   } n } seg; n vector<int> ga[400100]; n int u, v; n int din[400100], dout[400100]; n int timer; n void dfs(int u, int p) { n   timer++; n   din[u] = timer; n   w[timer] = u; n   for (int i = 0; i < ga[u].size(); i++) { n     int v = ga[u][i]; n     if (v != p) dfs(v, u); n   } n   dout[u] = timer; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> color[i]; n   for (int i = 1; i < n; i++) { n     cin >> u >> v; n     ga[u].push_back(v); n     ga[v].push_back(u); n   } n   dfs(1, -1); n   seg.build(1, 1, n); n   int tp, aa, bb; n   for (int i = 1; i <= m; i++) { n     cin >> tp; n     if (tp == 1) { n       cin >> aa >> bb; n       seg.modify(1, 1, n, din[aa], dout[aa], (1LL << bb)); n     } else { n       cin >> aa; n       cout << __builtin_popcountll(seg.get(1, 1, n, din[aa], dout[aa])) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string name[7]; n int a, b, c, n, max_p, dexp, was[7]; n bool p[7][7]; n void perebor(int point, int num); n int main() { n   name[0] =  Anka ; n   name[1] =  Chapay ; n   name[2] =  Cleo ; n   name[3] =  Troll ; n   name[4] =  Dracul ; n   name[5] =  Snowy ; n   name[6] =  Hexadecimal ; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a, b; n     string name1, name2, s; n     cin >> name1 >> s >> name2; n     for (int j = 0; j < 7; j++) { n       if (name[j] == name1) a = j; n       if (name[j] == name2) b = j; n     } n     p[a][b] = true; n   } n   cin >> a >> b >> c; n   dexp = (int)1e9 * 2 + 1; n   max_p = -1; n   perebor(1, 0); n   cout << dexp <<     << max_p; n   return 0; n } n void perebor(int point, int num) { n   if (point == 4 && num != 7) return; n   if (num == 7) { n     int c_p = 0, t[4], ans; n     for (int i = 0; i < 4; i++) t[i] = 0; n     for (int i = 0; i < 7; i++) { n       t[was[i]]++; n       for (int j = 0; j < 7; j++) n         if (was[i] == was[j] && p[i][j] == true && i != j) c_p++; n     } n     if (!(t[1] && t[2] && t[3])) n       return; n     else { n       ans = max(ceil(a / t[1]), max(ceil(b / t[2]), ceil(c / t[3]))) - n             min(ceil(a / t[1]), min(ceil(b / t[2]), ceil(c / t[3]))); n       if (ans <= dexp) { n         if (ans < dexp) max_p = 0; n         dexp = ans; n         if (max_p < c_p) max_p = c_p; n       } n     } n     return; n   } n   for (int i = 0; i < 7; i++) n     if (was[i] == 0) { n       was[i] = point; n       perebor(point, num + 1); n       perebor(point + 1, num + 1); n       was[i] = 0; n     } n   return; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   double x, sum = 0; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     cin >> x; n     sum += x; n   } n   cout << (sum / t) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 2e5 + 10; n const int mod = 1e9 + 7; n struct pairNode { n   char ch; n   long long times; n   pairNode(char ch = 0, long long times = 0) : ch(ch), times(times) {} n   ~pairNode() = default; n   bool operator==(const pairNode &rhs) const { n     return ch == rhs.ch && times == rhs.times; n   } n   bool operator!=(const pairNode &rhs) const { n     return ch != rhs.ch || times != rhs.times; n   } n   bool operator>=(const pairNode &rhs) const { n     return ch == rhs.ch && times >= rhs.times; n   } n }; n int tS, tT; n vector<pairNode> S, T, newT; n int nxt[M]; n inline void getInput(vector<pairNode> &S, int len) { n   char cur = 0, ch[3]; n   long long curtimes = 0, times; n   for (int i = 0; i < len; ++i) { n     scanf( %I64d-%s , &times, ch); n     if (ch[0] == cur) { n       curtimes += times; n     } else { n       if (i) S.push_back(pairNode(cur, curtimes)); n       cur = ch[0]; n       curtimes = times; n     } n   } n   S.push_back(pairNode(cur, curtimes)); n } n int main() { n   S.clear(); n   T.clear(); n   cin >> tS >> tT; n   getInput(S, tS); n   getInput(T, tT); n   if (T.size() == 1) { n     long long ans = 0; n     for (int i = 0; i < S.size(); ++i) n       if (S[i] >= T[0]) ans += S[i].times - T[0].times + 1; n     cout << ans << endl; n     return 0; n   } n   if (T.size() == 2) { n     long long ans = 0; n     for (int i = 0; i < S.size() - 1; ++i) n       if (S[i] >= T[0] && S[i + 1] >= T[1]) ++ans; n     cout << ans << endl; n     return 0; n   } n   for (int i = 1; i < T.size() - 1; ++i) newT.push_back(T[i]); n   nxt[0] = -1; n   int k = -1; n   for (int i = 1; i < newT.size(); ++i) { n     while (k != -1 && newT[k + 1] != newT[i]) k = nxt[k]; n     if (newT[k + 1] == newT[i]) ++k; n     nxt[i] = k; n   } n   long long ans = 0; n   k = -1; n   for (int i = 0; i < S.size(); ++i) { n     while (k != -1 && newT[k + 1] != S[i]) k = nxt[k]; n     if (newT[k + 1] == S[i]) ++k; n     if (k == newT.size() - 1) { n       if (i >= newT.size() && i + 1 <= S.size() && S[i - newT.size()] >= T[0] && n           S[i + 1] >= T[T.size() - 1]) n         ++ans; n       k = nxt[k]; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n   n #define ll long long int n #define ii pair<int,int> n #define int long long int n   n using namespace std; n   n const int inf = 0x3f3f3f3f; n  n int32_t main() { n     int t; scanf( %lld ,&t); n     while(t--) { n         int n, m, x; scanf( %lld%lld%lld ,&n,&m,&x); n         --x; n  n         int c = (x/n); n         int r = (x%n); n          n         int ans = r*m+c; n         printf( %lld n ,ans+1); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, sum, k, ans, c; n long long arr[1000000 + 5]; n long long tmp[1000000 + 5]; n vector<long long> frac; n signed main() { n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> arr[i], sum += arr[i]; n   } n   ans = 1e18; n   for (long long i = 2; i <= sqrt(sum); i++) { n     if (sum % i == 0) frac.push_back(i), frac.push_back(sum / i); n   } n   frac.push_back(1); n   for (long long i : frac) { n     k = sum / i, c = 0; n     for (long long j = 0; j < n; j++) tmp[j] = 0; n     for (long long j = 0; j < n; j++) { n       tmp[j] += arr[j]; n       if (tmp[j] < 0) { n         c += -tmp[j]; n         tmp[j + 1] += tmp[j]; n         tmp[j] = 0; n       } n       if (tmp[j] % k != 0) { n         if (tmp[j] % k < k - tmp[j] % k) { n           c += tmp[j] % k; n           tmp[j + 1] += tmp[j] % k; n         } else { n           c += k - tmp[j] % k; n           tmp[j + 1] -= k - tmp[j] % k; n         } n       } n     } n     ans = min(ans, c); n   } n   if (sum > 1) n     cout << ans <<   n ; n   else n     cout << -1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long m[10000005], x = 0, n, k, i, j, a; n int main() { n   cin >> a >> n; n   for (i = 1; i < a + n; i++) { n     m[i] = i; n   } n   for (i = 2; i < 3400; i++) { n     k = 0; n     for (j = i * i; j <= a + n; j = j + i * i) { n       k++; n       m[j] = k; n     } n   } n   for (i = a; i < a + n; i++) x = x + m[i]; n   cout << x; n } n


#include <bits/stdc++.h> n using namespace std; n long long big = 1000000007; n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long a, b; n   cin >> a >> b; n   int g = gcd(a, b); n   a /= g; n   b /= g; n   int ctr = 0; n   while (a % 2 == 0) { n     ctr += 1; n     a /= 2; n   } n   while (a % 3 == 0) { n     ctr += 1; n     a /= 3; n   } n   while (a % 5 == 0) { n     ctr += 1; n     a /= 5; n   } n   if (a != 1) { n     cout << -1 <<   n ; n     return 0; n   } n   while (b % 2 == 0) { n     ctr += 1; n     b /= 2; n   } n   while (b % 3 == 0) { n     ctr += 1; n     b /= 3; n   } n   while (b % 5 == 0) { n     ctr += 1; n     b /= 5; n   } n   if (b != 1) { n     cout << -1 <<   n ; n     return 0; n   } n   cout << ctr <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 2e5 + 10; n struct Edge { n   int u, v, cost, idx; n   bool operator<(const Edge& rhs) const { return cost < rhs.cost; } n } ed[MAX_N]; n inline bool cmp_idx(const Edge& lhs, const Edge& rhs) { n   return lhs.idx < rhs.idx; n } n map<pair<int, int>, int> ID; n int ver[MAX_N][19], maxCost[MAX_N][19], dep[MAX_N]; n int par[MAX_N], _rank[MAX_N]; n int n, m, ans[MAX_N]; n bool inMST[MAX_N]; n vector<pair<int, int> > g[MAX_N]; n inline void init(int n) { n   for (int i = 1; i <= n; i++) { n     par[i] = i; n     _rank[i] = 0; n   } n } n int find(int x) { n   if (par[x] == x) return x; n   return par[x] = find(par[x]); n } n inline void unite(int x, int y) { n   x = find(x), y = find(y); n   if (x == y) return; n   if (_rank[x] < _rank[y]) { n     par[x] = y; n   } else { n     par[y] = x; n     if (_rank[x] == _rank[y]) _rank[x]++; n   } n } n inline bool same(int x, int y) { return find(x) == find(y); } n void dfs(int u, int fa, int d) { n   dep[u] = d; n   for (pair<int, int>& e : g[u]) { n     int v = e.first, cost = e.second; n     if (v != fa) { n       ver[v][0] = u; n       maxCost[v][0] = cost; n       dfs(v, u, d + 1); n     } n   } n } n void initLca() { n   memset(ver, -1, sizeof ver); n   memset(maxCost, 0x8f, sizeof maxCost); n   dfs(1, -1, 1); n   for (int k = 1; k < 19; k++) { n     for (int v = 1; v <= n; v++) { n       if (ver[v][k - 1] != -1 && ver[ver[v][k - 1]][k - 1] != -1) { n         maxCost[v][k] = max(maxCost[v][k - 1], maxCost[ver[v][k - 1]][k - 1]); n         ver[v][k] = ver[ver[v][k - 1]][k - 1]; n       } n     } n   } n } n pair<int, int> find_lca(int u, int v) { n   if (dep[u] > dep[v]) swap(u, v); n   int res = -0x7fffffff; n   for (int k = 18; k >= 0; k--) { n     if (ver[v][k] != -1 && dep[ver[v][k]] >= dep[u]) { n       res = max(res, maxCost[v][k]); n       v = ver[v][k]; n     } n   } n   if (u == v) return pair<int, int>(res, v); n   for (int k = 18; k >= 0; k--) { n     if (ver[v][k] != ver[u][k]) { n       res = max(res, max(maxCost[v][k], maxCost[u][k])); n       v = ver[v][k]; n       u = ver[u][k]; n     } n   } n   res = max(res, max(maxCost[v][0], maxCost[u][0])); n   return pair<int, int>(res, ver[v][0]); n } n void modify(int u, int v, int w) { n   v = find(v); n   while (dep[u] < dep[v]) { n     int fa = ver[v][0], id = ID[pair<int, int>(fa, v)]; n     ans[id] = min(ans[id], w); n     par[v] = find(fa); n     v = find(v); n   } n } n int main() { n   int u, v, c; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d%d%d , &u, &v, &c); n     ed[i] = (Edge){u, v, c, i}; n     ID[pair<int, int>(u, v)] = i; n     ID[pair<int, int>(v, u)] = i; n     ans[i] = 0x7fffffff; n   } n   sort(ed, ed + m); n   init(n); n   for (int i = 0; i < m; i++) { n     Edge& e = ed[i]; n     if (!same(e.u, e.v)) { n       unite(e.u, e.v); n       g[e.u].push_back(pair<int, int>(e.v, e.cost)); n       g[e.v].push_back(pair<int, int>(e.u, e.cost)); n       inMST[i] = true; n     } n   } n   initLca(); n   init(n); n   for (int i = 0; i < m; i++) { n     if (inMST[i]) continue; n     Edge& e = ed[i]; n     pair<int, int> lca = find_lca(e.u, e.v); n     ans[e.idx] = min(ans[e.idx], lca.first - 1); n     modify(lca.second, e.u, e.cost - 1); n     modify(lca.second, e.v, e.cost - 1); n   } n   for (int i = 0; i < m; i++) { n     if (ans[i] == 0x7fffffff) ans[i] = -1; n     printf( %d  , ans[i]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = (long long)((1e5) + 100); n long long cuberoot(long long x) { n   long long lo = 1, hi = min(2000000ll, x); n   while (hi - lo > 1) { n     long long mid = (lo + hi) / 2; n     if (mid * mid * mid < x) { n       lo = mid; n     } else n       hi = mid; n   } n   if (hi * hi * hi <= x) n     return hi; n   else n     return lo; n } n const long long dx[4] = {-1, 1, 0, 0}; n const long long dy[4] = {0, 0, -1, 1}; n long long XX[] = {-1, -1, -1, 0, 0, 1, 1, 1}; n long long YY[] = {-1, 0, 1, -1, 1, -1, 0, 1}; n const long long N = (long long)(1 * 1e6 + 10); n bool comp(pair<long long, pair<long long, long long>> p1, n           pair<long long, pair<long long, long long>> p2) { n   if (p1.first > p2.first) n     return true; n   else if (p1.second == p2.second) { n     if (p1.second.first < p2.second.first) return true; n   } n   return false; n } n long long fact(long long n); n long long ncr(long long n, long long r) { n   return fact(n) / (fact(r) * fact(n - r)); n } n long long fact(long long n) { n   long long res = 1; n   for (long long i = 2; i <= n; i++) res = res * i; n   return res % 1000000007; n } n const long long a = 1000000000; n long long nCr(long long n, long long r) { n   long long fac1 = 1, fac2 = 1, fac; n   for (long long i = r; i >= 1; i--, n--) { n     fac1 = fac1 * n; n     if (fac1 % i == 0) n       fac1 = fac1 / i; n     else n       fac2 = fac2 * i; n   } n   fac = fac1 / fac2; n   return fac % a; n } n const long long m = 1000000007; n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n signed main() { n   long long n; n   cin >> n; n   long long arr[n + 1]; n   for (long long i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   long long mx = 0; n   vector<long long> v; n   for (long long i = n - 1; i >= 0; i--) { n     if (i == n - 1) { n       v.push_back(0); n       mx = arr[i]; n     } else { n       long long ans = 0; n       if (mx >= arr[i]) n         ans = max(mx, arr[i]) - arr[i] + 1; n       else n         ans = max(mx, arr[i]) - arr[i]; n       v.push_back(ans); n       mx = max(mx, arr[i]); n     } n   } n   for (long long i = n - 1; i >= 0; i--) cout << v[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MN = 100000 + 1; n int N; n char buf[2000]; n int main() { n   scanf( %d , &N); n   for (int i = 0; i < N; i++) { n     int a, b; n     scanf( %s%d%d , buf, &a, &b); n     if (a >= 2400 && b > a) { n       puts( YES ); n       return 0; n     } n   } n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1005], b[1005], c[1005], d[1005], posa[1005], posb[1005]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int q = 1; q <= n; q++) { n     int x; n     cin >> x; n     a[x] = q; n   } n   for (int q = 1; q <= n; q++) { n     int x; n     cin >> x; n     b[x] = q; n   } n   for (int q = 1; q <= n; q++) { n     c[q] = d[q] = posa[q] = posb[q] = q; n   } n   vector<array<int, 4>> v; n   for (int q = 1; q <= n; q++) { n     if (c[q] == a[q] && d[q] == b[q]) continue; n     v.push_back({q, posb[b[q]], posa[a[q]], q}); n     posb[d[q]] = posb[b[q]]; n     posa[c[q]] = posa[a[q]]; n     d[posb[d[q]]] = d[q]; n     c[posa[c[q]]] = c[q]; n   } n   cout << ((int)((v).size())) <<   n ; n   for (int q = 0; q < ((int)((v).size())); q++) { n     for (int w = 0; w < 4; w++) cout << v[q][w] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int tree[4 * 200005]; n void update(int n, int st, int en, int index, int val) { n   if (st == en) { n     tree[n] = val; n     return; n   } n   int mid = (st + en) / 2, lc = 2 * n, rc = lc + 1; n   if (index <= mid) n     update(lc, st, mid, index, val); n   else n     update(rc, mid + 1, en, index, val); n   tree[n] = max(tree[lc], tree[rc]); n } n int query(int n, int st, int en, int l, int r) { n   if (r < st || en < l) return 0; n   if (l <= st && en <= r) return tree[n]; n   int mid = (st + en) / 2, lc = 2 * n, rc = lc + 1; n   return max(query(lc, st, mid, l, r), query(rc, mid + 1, en, l, r)); n } n vector<int> pos[200005 + 5]; n int main() { n   int n, inp; n   scanf( %d , &n); n   int mx = 0; n   for (int i = 1; i < n + 1; i++) { n     scanf( %d , &inp); n     pos[inp].push_back(i); n   } n   for (int num = 1; num < 200005; num++) { n     reverse(pos[num].begin(), pos[num].end()); n     for (auto position : pos[num]) { n       if (position < num) continue; n       int highestDeletePossible = position - num; n       int maxAns = query(1, 0, 200005, 0, highestDeletePossible) + 1; n       update(1, 0, 200005, highestDeletePossible, maxAns); n     } n   } n   cout << query(1, 0, 200005, 0, 200005) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXM = 111111; n vector<int> v[MAXM]; n int n, m, lim, x, lower, upper; n inline bool check(int score) { n   for (int i = 1; i <= m; ++i) n     for (int j = score - 1; j < (int)v[i].size(); ++j) { n       int k = j - score + 1; n       if (v[i][j] - v[i][k] - lim <= score - 1) return true; n     } n   return false; n } n int main() { n   scanf( %d %d %d , &n, &m, &lim); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &x); n     v[x].push_back(i); n   } n   lower = 0, upper = n; n   while (lower < upper) { n     int mid = (lower + upper + 1) / 2; n     if (check(mid)) n       lower = mid; n     else n       upper = mid - 1; n   } n   printf( %d n , lower); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000 + 10, MAXL = 500 + 10; n int n, S, in[MAXN], out[MAXN], w[MAXN], s[MAXN], v[MAXN]; n int id[MAXN], h[MAXN][MAXN], g[MAXN][MAXN], f[MAXL][MAXN], Tohka; n vector<int> l[MAXN]; n bool cmp(int first, int second) { n   if ((out[first] - in[first]) != (out[second] - in[second])) n     return (out[first] - in[first]) < (out[second] - in[second]); n   return (s[first] + w[first]) < (s[second] + w[second]); n } n int main() { n   scanf( %d%d , &n, &S); n   for (int i = 1; i <= n; ++i) n     scanf( %d%d%d%d%d , &in[i], &out[i], &w[i], &s[i], &v[i]), ++in[i], n         id[i] = i; n   ++n; n   in[n] = 1, out[n] = n * 2 + 1, w[n] = 0, s[n] = S; n   id[n] = n; n   sort(id + 1, id + n + 1, cmp); n   for (int i = 1; i <= n; ++i) l[out[id[i]]].push_back(id[i]); n   for (int t = 1; t <= n; ++t) { n     int i = id[t], R = min(S - w[i], s[i]); n     for (int k = 0; k <= R; ++k) g[in[i] - 1][k] = 0; n     for (int j = in[i]; j <= out[i]; ++j) { n       for (int k = 0; k <= R; ++k) g[j][k] = g[j - 1][k]; n       vector<int> &L = l[j]; n       for (int p = 0; p < (int)L.size() && L[p] != i && in[L[p]] >= in[i]; ++p) n         for (int k = w[L[p]]; k <= R; ++k) n           g[j][k] = max(g[j][k], g[in[L[p]] - 1][k] + f[L[p]][k]); n     } n     for (int k = R; k >= 0; --k) n       f[i][k + w[i]] = g[out[i]][k] + v[i], Tohka = max(Tohka, f[i][k + w[i]]); n     for (int k = 0; k < w[i]; ++k) f[i][k] = 0; n     for (int k = 1; k <= S; ++k) f[i][k] = max(f[i][k], f[i][k - 1]); n   } n   cout << Tohka << endl; n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int long long n; n   cin >> n; n   if (n % 2 == 0) n     cout << 2; n   else n     cout << 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct flight { n   int d, f, t, c; n   flight() {} n   flight(int d, int f, int t, int c) : d(d), f(f), t(t), c(c) {} n   bool operator<(const flight& a) const { return d > a.d; } n }; n int n, m, k; n priority_queue<flight> arr, dep; n priority_queue<pair<int, int> > cheap[100010]; n long long minarr[100010], arrcost, depcost; n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) { n     int d, f, t, c; n     cin >> d >> f >> t >> c; n     if (t == 0) { n       arr.push(flight(d, f, t, c)); n     } else { n       dep.push(flight(d, f, t, c)); n       cheap[t].push(make_pair(-c, d)); n     } n   } n   for (int i = 1; i <= n; i++) { n     if (cheap[i].empty()) { n       cout << -1 <<   n ; n       return 0; n     } n     depcost += -cheap[i].top().first; n   } n   memset(minarr, -1, sizeof(minarr)); n   int num = 0; n   long long ans = -1; n   while (!arr.empty()) { n     flight f = arr.top(); n     arr.pop(); n     int u = f.f; n     if (minarr[u] == -1) { n       num++; n       minarr[u] = f.c; n       arrcost += f.c; n     } else if (f.c < minarr[u]) { n       arrcost += f.c - minarr[u]; n       minarr[u] = f.c; n     } n     if (num < n) continue; n     bool done = 0; n     while (!dep.empty() && dep.top().d <= f.d + k) { n       flight df = dep.top(); n       dep.pop(); n       depcost -= -cheap[df.t].top().first; n       while (!cheap[df.t].empty() && cheap[df.t].top().second <= df.d) n         cheap[df.t].pop(); n       if (cheap[df.t].empty()) { n         done = 1; n         break; n       } n       depcost += -cheap[df.t].top().first; n     } n     if (done) break; n     if (ans == -1 || arrcost + depcost < ans) { n       ans = arrcost + depcost; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n const int INF = (int)(1e9); n const long long INFLL = (long long)(1e18); n const double EPS = 1e-13; n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, k; n   cin >> n >> k; n   vector<int> b(n); n   for (int i = 0; i < n; i++) cin >> b[i]; n   vector<int> a; n   for (int i = 0; i < n; i++) n     if (b[i] == 0) a.push_back(i); n   for (int i = n - 1; i >= 0; i--) n     if (b[i] > 0) { n       int cnt = 0; n       int index = -1; n       for (int j = 0; j < a.size(); j++) { n         if (a[j] >= i + k) cnt++; n         if (cnt == b[i]) { n           index = j + 1; n           break; n         } n       } n       a.insert(a.begin() + index, i); n     } n   for (int i = 0; i < n; i++) cout << a[i] + 1 <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int in() { n   int x; n   scanf( %d , &x); n   return x; n } n const long double EPS = 1e-12; n const int INF = 1e9 + 10; n const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100; n const int MN = 1e5 + 10; n vector<int> fir[MN], lst[MN]; n int arr[MN]; n int n, q, sz; n pair<int, int> inv[MN]; n bool lz[4 * MN]; n int seg[4 * MN]; n void input() { n   cin >> n >> q; n   for (int i = 0; i < n; ++i) cin >> arr[i]; n   sort(arr, arr + n); n   while (q--) { n     int l, r; n     cin >> l >> r; n     int L = lower_bound(arr, arr + n, l) - arr; n     int R = upper_bound(arr, arr + n, r) - arr; n     if (L >= R) continue; n     --R; n     if (L == R) continue; n     inv[sz++] = make_pair(L, R); n     lst[R].push_back(sz - 1), fir[L].push_back(sz - 1); n   } n } n void shift(int segnum, int left, int right) { n   if (lz[segnum] == false) return; n   int mid = (left + right) >> 1; n   lz[2 * segnum] = !lz[2 * segnum], lz[2 * segnum + 1] = !lz[2 * segnum + 1]; n   lz[segnum] = false; n   seg[2 * segnum] = (mid - left + 1) - seg[2 * segnum]; n   seg[2 * segnum + 1] = (right - mid) - seg[2 * segnum + 1]; n } n void upd(int segnum, int left, int right, int l, int r) { n   if (r < left || right < l) return; n   if (l <= left && right <= r) { n     lz[segnum] = !lz[segnum]; n     seg[segnum] = (right - left + 1) - seg[segnum]; n     return; n   } n   shift(segnum, left, right); n   int mid = (left + right) >> 1; n   upd(2 * segnum, left, mid, l, r); n   upd(2 * segnum + 1, mid + 1, right, l, r); n   seg[segnum] = seg[2 * segnum] + seg[2 * segnum + 1]; n } n int get(int segnum, int left, int right, int l, int r) { n   if (r < left || right < l) return 0; n   if (l <= left && right <= r) return seg[segnum]; n   shift(segnum, left, right); n   int mid = (left + right) >> 1; n   return get(2 * segnum, left, mid, l, r) + n          get(2 * segnum + 1, mid + 1, right, l, r); n } n void solve() { n   long long ans = 1ll * n * (n - 1) * (n - 2) / 6; n   for (int i = 0; i < n; ++i) { n     upd(1, 0, n - 1, i, n - 1); n     for (int j = 0; j < ((int)(fir[i]).size()); ++j) n       upd(1, 0, n - 1, inv[fir[i][j]].first, inv[fir[i][j]].second); n     if (i - 1 >= 0) { n       for (int j = 0; j < ((int)(lst[i - 1]).size()); ++j) n         upd(1, 0, n - 1, inv[lst[i - 1][j]].first, inv[lst[i - 1][j]].second); n     } n     int t = 0; n     if (i - 1 >= 0) t += get(1, 0, n - 1, 0, i - 1); n     if (i != n - 1) t += get(1, 0, n - 1, i + 1, n); n     upd(1, 0, n - 1, i, n - 1); n     long long val = 1ll * t * (t - 1) / 2; n     ans -= val; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long QuickPow(long long x, long long y) { n   long long Res = 1, Temp = x; n   while (y) { n     if (y & 1) Res = Res * Temp % 1000000007; n     Temp = Temp * Temp % 1000000007; n     y /= 2; n   } n   return Res; n } n inline void Swap(long long &x, long long &y) { n   long long Temp = x; n   x = y; n   y = Temp; n } n inline long long Max(long long x, long long y) { return x > y ? x : y; } n inline long long Min(long long x, long long y) { return x < y ? x : y; } n inline void read(long long &x) { n   x = 0; n   long long f = 1; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = (x << 3) + (x << 1) + (s ^ 48); n     s = getchar(); n   } n   x *= f; n } n struct node { n   long long v, Index; n   node() {} n   node(long long V, long long INDEX) { n     v = V; n     Index = INDEX; n   } n }; n set<long long> Ans, Bian[100005], Dian[100005]; n set<long long>::iterator item; n stack<long long> S; n vector<node> G[100005]; n bool InStack[100005]; n long long Dfn[100005], Low[100005], Cnt, Col; n void Tarjan(long long x, long long Pre) { n   Dfn[x] = Low[x] = ++Cnt; n   int l = G[x].size(); n   for (register long long i = 0; i < l; ++i) { n     long long to = G[x][i].v; n     if (to == Pre) continue; n     if (!Dfn[to]) { n       S.push(to); n       S.push(x); n       S.push(G[x][i].Index); n       Tarjan(to, x); n       Low[x] = Min(Low[x], Low[to]); n       if (Low[to] >= Dfn[x]) { n         Col++; n         long long u, v; n         do { n           Bian[Col].insert(S.top()); n           S.pop(); n           u = S.top(); n           S.pop(); n           v = S.top(); n           S.pop(); n           Dian[Col].insert(u); n           Dian[Col].insert(v); n         } while (u != x || v != to); n       } n     } else if (Dfn[to] < Dfn[x]) { n       S.push(to); n       S.push(x); n       S.push(G[x][i].Index); n       Low[x] = Min(Low[x], Dfn[to]); n     } n   } n } n int main() { n   long long n, m; n   read(n); n   read(m); n   for (register long long i = 1; i <= m; ++i) { n     long long u, v; n     read(u); n     read(v); n     G[u].push_back(node(v, i)); n     G[v].push_back(node(u, i)); n   } n   for (register long long i = 1; i <= n; ++i) n     if (!Dfn[i]) Tarjan(i, i); n   for (register long long i = 1; i <= Col; ++i) n     if (Bian[i].size() == Dian[i].size()) n       Ans.insert(Bian[i].begin(), Bian[i].end()); n   int l = Ans.size(); n   printf( %d n , l); n   for (item = Ans.begin(); item != Ans.end(); item++) printf( %lld  , *item); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v, vv, vv2; n int main() { n   int t, n, a[1000], k, f = 0; n   cin >> n; n   if (n == 3) { n     for (int i = 1; i <= n; i++) { n       if (i % 2 != 0) { n         for (int j = 1; j <= n; j++) { n           if (j % 2 != 0) { n             cout <<  W ; n           } else n             cout <<  B ; n         } n         cout << endl; n       } else { n         for (int k = 0; k < n; k++) { n           cout <<  B ; n         } n         cout << endl; n       } n     } n   } else { n     for (int i = 1; i <= n; i++) { n       if (i % 2 != 0) { n         for (int j = 1; j <= n; j++) { n           if (j % 2 != 0) n             cout <<  W ; n           else n             cout <<  B ; n         } n         cout << endl; n       } else { n         for (int j = 1; j <= n; j++) { n           if (j % 2 != 0) n             cout <<  B ; n           else n             cout <<  W ; n         } n         cout << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n int tree[4 * MAXN]; n int maxTree[4 * MAXN]; n int p[MAXN]; n int n; n void push(int v) { n   if (tree[v]) { n     tree[2 * v] += tree[v]; n     tree[2 * v + 1] += tree[v]; n     maxTree[2 * v] += tree[v]; n     maxTree[2 * v + 1] += tree[v]; n     tree[v] = 0; n   } n } n void update(int v, int tl, int tr, int l, int r, int add) { n   if (l > r) return; n   if (tl == l && tr == r) { n     tree[v] += add; n     maxTree[v] += add; n     return; n   } n   int tm = (tl + tr) >> 1; n   push(v); n   update(2 * v, tl, tm, l, min(r, tm), add); n   update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, add); n   maxTree[v] = max(maxTree[2 * v], maxTree[2 * v + 1]); n } n int findIndex(int v, int tl, int tr) { n   if (tl == tr) return tl; n   push(v); n   int tm = (tl + tr) >> 1; n   if (maxTree[2 * v] > 0) { n     return findIndex(2 * v, tl, tm); n   } else { n     return findIndex(2 * v + 1, tm + 1, tr); n   } n } n int main() { n   for (int i = 0; i < 4 * MAXN; i++) { n     tree[i] = 0; n     maxTree[i] = 0; n   } n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int pos, op; n     scanf( %d %d , &pos, &op); n     pos = n - pos + 1; n     if (op) { n       int number; n       scanf( %d , &number); n       p[pos] = number; n       update(1, 1, n, pos, n, 1); n     } else { n       p[pos] = -1; n       update(1, 1, n, pos, n, -1); n     } n     if (maxTree[1] > 0) { n       int index = findIndex(1, 1, n); n       printf( %d n , p[index]); n     } else { n       printf( -1 n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma optimize( SEX_ON_THE_BEACH ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( fast-math ) n using ll = long long int; n using ull = long long int; n using dd = double; n using ldd = long double; n namespace Hashes { n const int mod197 = 1e9 + 7; n const int mod199 = 1e9 + 9; n const int modfft = 998244353; n int MOD = mod197; n template <typename T = int> n struct Hash { n   T me, mod; n   Hash() {} n   Hash(T _me, T _mod = MOD) { n     me = _me, mod = _mod; n     if (me >= mod) me %= mod; n   } n   Hash operator+(Hash to) { n     to.me += me; n     if (to.me >= to.mod) to.me -= to.mod; n     return to; n   } n   Hash operator-(Hash to) { n     to.me -= me; n     to.me *= -1; n     if (to.me < 0) to.me += to.mod; n     return to; n   } n   Hash operator*(Hash to) { n     to.me *= me; n     to.me %= to.mod; n     return to; n   } n   Hash& operator+=(Hash to) { n     me += to.me; n     if (me >= mod) me -= mod; n     return *this; n   } n   Hash& operator-=(Hash to) { n     me -= to.me; n     if (me < 0) me += mod; n     return *this; n   } n   Hash& operator*=(Hash to) { n     me *= to.me; n     me %= mod; n     return *this; n   } n   bool operator==(Hash to) { return me == to.me; } n   T operator*() { return me; } n }; n }  // namespace Hashes n namespace someUsefull { n template <typename T1, typename T2> n inline void checkMin(T1& a, T2 b) { n   if (a > b) a = b; n } n template <typename T1, typename T2> n inline void checkMax(T1& a, T2 b) { n   if (a < b) a = b; n } n const int _popcount_size_ = 16; n char _bits_count_[1 << _popcount_size_]; n inline void _build_bits_count_() { n   for (int i = 1, j = 0; i < (1 << _popcount_size_); ++i) { n     if (i & (1 << (j + 1))) ++j; n     _bits_count_[i] = _bits_count_[i ^ (1 << j)] + 1; n   } n } n template <typename T1 = int, typename T2 = int> n inline T1 popcnt(T2 x) { n   T1 ans = 0; n   while (x) { n     ans += _bits_count_[x & (1 << _popcount_size_) - 1]; n     x >>= _popcount_size_; n   } n   return ans; n } n }  // namespace someUsefull n using namespace std; n using namespace Hashes; n using namespace someUsefull; n vector<vector<int>> gr; n vector<vector<pair<int, ll>>> hr; n set<pair<int, int>> br; n vector<int> tin, tout, cmp; n vector<int> was; n vector<ll> pr; n vector<ll> dp; n vector<ll> ans; n vector<int> cntST; n vector<int> isMe; n int TT; n int t = 0; n void dfs(int v, int p = -1) { n   tin[v] = tout[v] = ++t; n   was[v] = 1; n   for (int to : gr[v]) { n     if (to == p) continue; n     if (was[to] == 1) n       checkMin(tout[v], tin[to]); n     else { n       dfs(to, v); n       checkMin(tout[v], tout[to]); n       if (tout[to] > tin[v]) { n         br.insert({v, to}); n         br.insert({to, v}); n       } n     } n   } n } n void dfs2(int v, int c) { n   cmp[v] = c; n   for (int to : gr[v]) n     if (!cmp[to] && br.count({v, to}) == 0) dfs2(to, c); n } n void dfs3(int v, int p = -1) { n   cntST[v] = isMe[v]; n   for (pair<int, int> to : hr[v]) { n     if (to.first == p) continue; n     dfs3(to.first, v); n     cntST[v] += cntST[to.first]; n   } n } n void dpC(int v, int p = -1) { n   dp[v] += pr[v]; n   for (pair<int, int> to : hr[v]) { n     if (to.first == p) continue; n     dpC(to.first, v); n     if (cntST[to.first] != 0 && cntST[to.first] != TT) n       dp[v] += max(0ll, dp[to.first] - to.second); n     else n       dp[v] += dp[to.first]; n   } n } n void dpF(int v, int p = -1) { n   ans[v] = dp[v]; n   for (pair<int, int> to : hr[v]) { n     if (to.first == p) continue; n     if (cntST[to.first] != 0 && cntST[to.first] != TT) n       dp[v] -= max(0ll, dp[to.first] - to.second); n     else n       dp[v] -= dp[to.first]; n     cntST[v] -= cntST[to.first]; n     if (cntST[v] != 0 && cntST[v] != TT) n       dp[to.first] += max(0ll, dp[v] - to.second); n     else n       dp[to.first] += dp[v]; n     cntST[to.first] += cntST[v]; n     dpF(to.first, v); n     if (cntST[v] != 0 && cntST[v] != TT) n       dp[to.first] -= max(0ll, dp[v] - to.second); n     else n       dp[to.first] -= dp[v]; n     cntST[to.first] -= cntST[v]; n     if (cntST[to.first] != 0 && cntST[to.first] != TT) n       dp[v] += max(0ll, dp[to.first] - to.second); n     else n       dp[v] += dp[to.first]; n     cntST[v] += cntST[to.first]; n   } n } n void solve(int test) { n   int n, k, m; n   cin >> n >> m >> k; n   vector<int> inter(k); n   vector<ll> cc(n); n   vector<ll> w(m); n   for (int i = 0; i < k; ++i) cin >> inter[i]; n   for (int i = 0; i < n; ++i) cin >> cc[i]; n   for (int i = 0; i < m; ++i) cin >> w[i]; n   vector<pair<int, int>> ed; n   gr.resize(n); n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     --a; n     --b; n     ed.push_back({a, b}); n     gr[a].push_back(b); n     gr[b].push_back(a); n   } n   tin.resize(n); n   tout.resize(n); n   cmp.resize(n); n   was.resize(n); n   dfs(0); n   int c = 1; n   for (int i = 0; i < n; ++i) { n     if (cmp[i] == 0) { n       dfs2(i, c); n       c++; n     } n   } n   for (int i = 0; i < n; ++i) --cmp[i]; n   --c; n   hr.resize(c); n   pr.resize(c); n   dp.resize(c); n   ans.resize(c); n   cntST.resize(c); n   isMe.resize(c); n   for (int i : inter) isMe[cmp[i - 1]] = 1; n   for (int i = 0; i < n; ++i) { n     pr[cmp[i]] += cc[i]; n   } n   for (int i = 0; i < m; ++i) { n     if (br.count(ed[i])) { n       hr[cmp[ed[i].first]].push_back({cmp[ed[i].second], w[i]}); n       hr[cmp[ed[i].second]].push_back({cmp[ed[i].first], w[i]}); n     } n   } n   dfs3(0); n   TT = cntST[0]; n   dpC(0); n   0; n   ; n   dpF(0); n   for (int i = 0; i < n; ++i) { n     cout << ans[cmp[i]] <<    ; n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(0); n   _build_bits_count_(); n   int t = 1; n   for (int i = 0; i < t; ++i) { n     solve(i + 1); n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using vi = vector<int>; n using vl = vector<ll>; n using vii = vector<pii>; n using vll = vector<pll>; n #define fi first n #define se second n #define sz(c)  ((int)(c).size()) n #define all(c) (c).begin(), (c).end() n #define forn(i, m, n)  for (int i = m, nnnn = (n); i < nnnn; ++i) n #define pb  push_back n #define mp  make_pair n //using int128 = __int128_t; n ll P = 1000000007; n   n int main(){ n  ios_base::sync_with_stdio(false); n  cin.tie(NULL); n  cout.tie(NULL); n  int n, t; n  cin >> n >> t; n  ll prev = 0; n  ll segmenttree[4*n]; n  forn(i, 0, 4*n) segmenttree[i] = -1; n  n  while (t--){ n   int k; n   cin >> k; n   cout.flush(); n   ll low = 1, high = n, curr = 0, index = 1; n   while (low <= high){ n    ll mid = (low + high)/2; n    ll temp = segmenttree[index]; n    if (segmenttree[index] == -1){ n     cout <<  ?  <<     << low <<     << mid << endl; n     cout.flush(); n     cin >> temp; n     cout.flush(); n     segmenttree[index] = temp; n    }  n    if ((mid - low + 1 - temp) + curr < k) { n     curr += (mid - low + 1 - temp); n     low = mid + 1; n     index = index * 2 + 1; n    } else { n     high = mid - 1; n     index *= 2; n    } n    //cout << low <<     << high <<   n ; n   } n   cout <<  !  <<     << low <<   n ; n   cout.flush(); n   if(index % 2 == 0) segmenttree[index]++; n   while (index != 0) { n    bool add = (index % 2 == 0); n    index /= 2; n    if (add) segmenttree[index]++; n   } n  } n }


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   char ch; n   int Sum = 0, Count = 0; n   n /= 2; n   for (int i = 1; i <= n; i++) { n     cin >> ch; n     if (ch ==  4  || ch ==  7 ) { n       Count++; n     } n     Sum += ch -  0 ; n   } n   for (int i = 1; i <= n; i++) { n     cin >> ch; n     if (ch ==  4  || ch ==  7 ) { n       Count++; n     } n     Sum -= ch -  0 ; n   } n   cout << (Sum == 0 && Count == n * 2 ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n; n   cin >> n; n   int ans = 1; n   for (int i = 1; i < n; i++) { n     ans *= 3; n     ans %= 1000003; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n vector<int> v[maxn]; n int ma = 0; n int h = 0; n int f = 0; n int root = 0; n int g[maxn]; n bool mark[maxn]; n void dfs(int k) { n   if (mark[k] == false) { n     mark[k] = true; n   } else { n     return; n   } n   for (int i = 0; i < v[k].size(); i++) { n     int child = v[k][i]; n     if (mark[child] == false) { n       g[h]++; n       dfs(child); n     } n   } n   if (v[k].size() == 1 && root != k) { n     if (g[h] + 1 > ma) { n       ma = g[h] + 1; n     } n     f = 1; n   } n   if (f == 1) { n     g[h]--; n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int u; n     cin >> u; n     if (u == -1) { n       mark[i] = true; n     } else { n       v[i].push_back(u); n       v[u].push_back(i); n     } n   } n   for (int i = 1; i <= n; i++) { n     if (mark[i] == true) { n       mark[i] = false; n       root = i; n       dfs(i); n       h++; n     } n   } n   if (ma == 0) { n     cout << 1; n     return 0; n   } n   cout << ma; n } n