#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool upmin(T &x, T y) { n   return y < x ? x = y, 1 : 0; n } n template <typename T> n inline bool upmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n const long double eps = 1e-9; n const long double pi = acos(-1); n const int oo = 1 << 30; n const long long loo = 1ll << 60; n const int mods = 1e9 + 7; n const int inv2 = (mods + 1) >> 1; n const int MAXN = 510005; n const int INF = 0x3f3f3f3f; n namespace FastIO { n constexpr int SIZE = (1 << 21) + 1; n int num = 0, f; n char ibuf[SIZE], obuf[SIZE], que[65], *iS, *iT, *oS = obuf, n                                                 *oT = obuf + SIZE - 1, c; n inline void flush() { n   fwrite(obuf, 1, oS - obuf, stdout); n   oS = obuf; n } n inline void putc(char c) { n   *oS++ = c; n   if (oS == oT) flush(); n } n inline void getc(char &c) { n   for (c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++); n        !isalpha(c) && c != EOF; n        c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++)) n     ; n } n inline void reads(char *st) { n   char c; n   int n = 0; n   getc(st[++n]); n   for (c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++); n        isalpha(c); n        c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++)) n     st[++n] = c; n   st[n + 1] =   0 ; n } n template <class I> n inline void read(I &x) { n   for (f = 1, c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), n                               (iS == iT ? EOF : *iS++)) n                             : *iS++); n        c <  0  || c >  9 ; n        c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++)) n     if (c ==  - ) f = -1; n   for (x = 0; c >=  0  && c <=  9 ; n        c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++)) n     x = (x << 3) + (x << 1) + (c & 15); n   x *= f; n } n template <class I> n inline void print(I x) { n   if (x < 0) putc( - ), x = -x; n   if (!x) putc( 0 ); n   while (x) que[++num] = x % 10 + 48, x /= 10; n   while (num) putc(que[num--]); n } n struct Flusher_ { n   ~Flusher_() { flush(); } n } io_Flusher_; n }  // namespace FastIO n using FastIO ::print; n using FastIO ::putc; n using FastIO ::read; n using FastIO ::reads; n char st[1005], ST[1005]; n long long f[1005][1005], K; n int ch[MAXN][26], num = 0, n, m, nodenum = 1, a[MAXN]; n pair<int, int> flag[MAXN]; n void solve(int x) { n   if (!x) return; n   for (int i = 25; i >= 0; --i) solve(ch[x][i]); n   if (flag[x].first) a[++num] = x; n } n void insert(int l, int r) { n   int nw = 1; n   for (int i = l; i <= r; ++i) { n     if (!ch[nw][st[i] -  a ]) ch[nw][st[i] -  a ] = ++nodenum; n     nw = ch[nw][st[i] -  a ]; n   } n   flag[nw] = make_pair(l, r); n } n long long check(int x) { n   int len = 0; n   for (int i = flag[a[x]].first; i <= flag[a[x]].second; ++i) ST[++len] = st[i]; n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j <= m; ++j) f[i][j] = 0; n   f[0][0] = 1; n   for (int i = 0; i < n; ++i) { n     int id = len; n     for (int j = 1; j <= len && i + j - 1 <= n; ++j) n       if (st[i + j] < ST[j]) { n         id = INF; n         break; n       } else if (st[i + j] > ST[j]) { n         id = j; n         break; n       } n     if (i + id <= n) { n       for (int j = 0; j < m; ++j) n         if (f[i + id][j + 1] < loo) f[i + id][j + 1] += f[i][j]; n     } n     for (int j = 1; j <= m; ++j) n       if (f[i + 1][j] < loo) f[i + 1][j] += f[i][j]; n   } n   return f[n][m]; n } n signed main() { n   read(n), read(m), read(K), reads(st); n   for (int i = 1; i <= n; ++i) n     for (int j = i; j <= n; ++j) insert(i, j); n   solve(1); n   int l = 1, r = num; n   while (l < r) { n     int mid = (l + r) >> 1; n     if (check(mid) >= K) n       r = mid; n     else n       l = mid + 1; n   } n   for (int i = flag[a[l]].first; i <= flag[a[l]].second; ++i) putc(st[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n; n string s; n int main(void) { n   cin >> t; n   while (t--) { n     map<pair<int, int>, int> m; n     int start = 0, end = 2147483647, x = 0, y = 0; n     cin >> n >> s; n     s.insert(s.begin(),  0 ); n     m.insert({make_pair(0, 0), 0}); n     for (int i = 1; i < s.size(); i++) { n       if (s[i] ==  L ) n         x -= 1; n       else if (s[i] ==  R ) n         x += 1; n       else if (s[i] ==  U ) n         y += 1; n       else n         y -= 1; n       pair<int, int> p = make_pair(x, y); n       if (m.find(p) == m.end()) { n         m.insert({p, i}); n       } else { n         if (i - m[p] < end - start) { n           start = m[p] + 1; n           end = i; n         } n         m[p] = i; n       } n     } n     if (end == 2147483647) n       cout <<  -1 n ; n     else n       cout << start <<     << end << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 20; n const int M = 1e5 + 55; n pair<int, int> dp[(1 << N) + 5]; n int dis[N][N]; n int My[(1 << N) + 5][N]; n int taken[(1 << N) + 5][N]; n char s[M]; n int sum[N]; n int lg[(1 << N) + 55]; n int m, n; n pair<int, int> bt(int mask) { n   if (mask == (1 << n) - 1) return {0, 0}; n   pair<int, int>& ret = dp[mask]; n   if (ret.first != -1) return ret; n   ret = {10000000, 0}; n   int cur = 0; n   pair<int, int> nxt; n   for (int v = 0; v < n; v++) { n     if ((mask & (1 << v)) == 0) { n       nxt = bt(mask + (1 << v)); n       cur = nxt.second - My[mask][v]; n       cur += nxt.first + taken[mask][v]; n       if (cur < ret.first) n         ret = {cur, nxt.second + taken[mask][v] - My[mask][v]}; n     } n   } n   return ret; n } n void prep(int mask, int i, int l, int pre) { n   if (i == n - 1) { n     taken[mask][l] = pre; n     My[mask][l] = 0; n     return; n   } n   if (My[mask][l] != -1) return; n   for (int j = 0; j < n; j++) { n     if ((mask & (1 << j)) == 0 && j != l) { n       prep(mask + (1 << j), i + 1, l, pre + dis[l][j]); n       My[mask][l] = My[mask + (1 << j)][l] + dis[l][j]; n     } n   } n   taken[mask][l] = pre; n } n int main() { n   memset(dp, -1, sizeof dp); n   memset(My, -1, sizeof My); n   scanf( %d %d , &m, &n); n   scanf( %s , s); n   for (int i = 0; i < m - 1; i++) { n     if (s[i] != s[i + 1]) { n       dis[s[i] -  a ][s[i + 1] -  a ]++; n       sum[s[i] -  a ]++; n       sum[s[i + 1] -  a ]++; n       dis[s[i + 1] -  a ][s[i] -  a ]++; n     } n   } n   for (int i = 0; i < n; i++) lg[(1 << i)] = i; n   int ms; n   for (int l = 0; l < n; l++) { n     for (int mask = (1 << n) - 1; mask >= 0; mask--) { n       if (mask & (1 << l)) continue; n       mask += (1 << l); n       ms = mask | (mask + 1); n       mask -= (1 << l); n       ms -= (1 << l); n       if (ms >= (1 << n)) { n         taken[mask][l] = sum[l]; n         My[mask][l] = 0; n         continue; n       } n       My[mask][l] = My[ms][l] + dis[lg[mask ^ ms]][l]; n       taken[mask][l] = taken[ms][l] - dis[l][lg[mask ^ ms]]; n     } n   } n   cout << bt(0).first << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100001]; n int main() { n   long long int n, i, count = 0; n   long long sum = 0; n   scanf( %I64d , &n); n   for (i = 0; i < n; i++) scanf( %I64d , a + i); n   sort(a, a + n); n   for (i = 0; i < n; i++) { n     if (sum <= a[i]) { n       count++; n       sum += a[i]; n     } n   } n   printf( %I64d n , count); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int x, y, idx; n   cin >> x >> y >> idx; n   if (idx == 0) n     cout << x << endl; n   else if (idx == 1) n     cout << y << endl; n   else { n     idx -= 2; n     int z; n     while (true) { n       z = x + y; n       idx--; n       if (idx < 0) break; n       x = y; n       y = z; n     } n     cout << z << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using INT = unsigned long long; n const int N = 100000; n struct Ring { n   INT a[5]; n   Ring() { memset(a, 0, sizeof a); } n   Ring operator+(Ring r) { n     Ring R = r; n     for (int i = 0; i < 5; i++) R.a[i] += a[i]; n     return R; n   } n   void operator+=(Ring r) { (*this) = (*this) + r; } n   Ring operator*(Ring r) { n     Ring R; n     for (int i = 0; i < 5; i++) n       for (int j = 0; j < 5; j++) n         i + j < 5 ? R.a[i + j] += a[i] * r.a[j] n                   : R.a[i + j - 5] -= a[i] * r.a[j]; n     return R; n   } n   void operator*=(Ring r) { (*this) = (*this) * r; } n   Ring operator<<(int k) { n     Ring R; n     for (int i = 0; i < 5; i++) { n       int j = (i + k) % 10; n       j < 5 ? R.a[j] = a[i] : R.a[j - 5] = -a[i]; n     } n     return R; n   } n   INT real() { return a[0] + a[1]; } n } x[N], w[10], tmp[10]; n INT power(INT a, INT n, INT ans = 1) { n   for (; n; n >>= 1, a *= a) n     if (n & 1) ans *= a; n   return ans; n } n Ring power(Ring a, INT n) { n   Ring ans; n   ans.a[0] = 1; n   for (; n; n >>= 1, a *= a) n     if (n & 1) ans *= a; n   return ans; n } n void DFT(Ring *P, int op) { n   for (int i = 1; i < N; i *= 10) { n     for (int p = i * 10, j = 0; j < N; j += p) { n       for (int k = 0; k < i; k++) { n         for (int x = 0; x < 10; x++) tmp[x] = P[j + k + x * i]; n         for (int x = 0; x < 10; x++) { n           Ring &r = P[j + k + x * i]; n           r = Ring(); n           for (int y = 0; y < 10; y++) r += tmp[y] << x * y * op; n         } n       } n     } n   } n } n int n; n int main() { n   scanf( %d , &n); n   for (int i = 0, k; i < n; i++) { n     scanf( %d , &k); n     x[k].a[0]++; n   } n   DFT(x, 1); n   for (int i = 0; i < N; i++) x[i] = power(x[i], n); n   DFT(x, 9); n   INT inv = power(5, (1ull << 63) - 5); n   for (int i = 0; i < n; i++) n     printf( %I64d n , (x[i].real() >> 5) * inv & ((1ull << 58) - 1)); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   long long int tests = 1; n   while (tests--) { n     long long int n; n     int x; n     cin >> n >> x; n     if (n % 6 == 0) n       cout << x; n     else if (n % 6 == 1) { n       if (x == 0) n         cout << 1; n       else if (x == 1) n         cout << 0; n       else n         cout << 2; n     } else if (n % 6 == 2) { n       if (x == 0) n         cout << 1; n       else if (x == 1) n         cout << 2; n       else n         cout << 0; n     } else if (n % 6 == 3) { n       if (x == 0) n         cout << 2; n       else if (x == 1) n         cout << 1; n       else n         cout << 0; n     } else if (n % 6 == 4) { n       if (x == 0) n         cout << 2; n       else if (x == 1) n         cout << 0; n       else n         cout << 1; n     } else { n       if (x == 0) n         cout << 0; n       else if (x == 1) n         cout << 2; n       else n         cout << 1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n ostream &operator<<(ostream &out, const pair<T, U> &p) { n   out <<  (  << p.first <<  ,   << p.second <<  ) ; n   return out; n } n template <template <typename, typename...> class ContainerType, n           typename ValueType, typename... Args> n void print(const ContainerType<ValueType, Args...> &c) { n   for (const auto &v : c) cout << v <<    ; n   cout <<   n ; n } n void print() { cout <<   n ; } n template <typename T, typename... Args> n void print(T a, Args... args) { n   cout << a <<    ; n   print(args...); n } n long long llipower(long long x, long long y, long long p = LLONG_MAX) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int x, y, z; n     cin >> x >> y >> z; n     if (x == y && x >= z) { n       cout <<  YES  n            <<   n ; n       print(x, 1, z); n     } else if (y == z && y >= x) { n       cout <<  YES  n            <<   n ; n       print(1, x, y); n     } else if (z == x && x >= y) { n       cout <<  YES  n            <<   n ; n       print(1, x, y); n     } else { n       cout <<  NO  n            <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n int isPerfectSquare(int number) { n   int iVar; n   float fVar; n   fVar = sqrt((double)number); n   iVar = fVar; n   if (iVar == fVar) n     return 1; n   else n     return 0; n } n int main() { n   int no; n   scanf( %d n , &no); n   int a[no]; n   int max; n   max = -1000000; n   for (int i = 0; i < no; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 0; i < no; i++) { n     if (isPerfectSquare(a[i])) n       continue; n     else { n       if (a[i] > max) max = a[i]; n     } n   } n   printf( %d , max); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n vector<int> ad[N]; n int h[N], n, m, dp[N][30]; n int d[N], R = 320; n vector<int> red; n void dfs(int v, int p) { n   h[v] = h[p] + 1; n   dp[v][1] = p; n   for (auto u : ad[v]) { n     if (u != p) dfs(u, v); n   } n } n int dis(int u, int v) { n   int res = 0; n   if (h[v] < h[u]) swap(v, u); n   for (int i = 20; i >= 1; i--) { n     if (h[v] - (1 << (i - 1)) >= h[u]) { n       res += (1 << (i - 1)); n       v = dp[v][i]; n     } n   } n   if (u == v) return res; n   for (int i = 20; i >= 1; i--) { n     if (dp[v][i] != dp[u][i]) { n       res += 2 * (1 << (i - 1)); n       v = dp[v][i]; n       u = dp[u][i]; n     } n   } n   return res + 2; n } n void bfs() { n   deque<int> dq; n   memset(d, 0, sizeof d); n   for (auto u : red) dq.push_back(u), d[u] = 1; n   while (dq.size()) { n     int v = dq[0]; n     dq.pop_front(); n     for (auto u : ad[v]) { n       if (!d[u]) d[u] = d[v] + 1, dq.push_back(u); n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     ad[u].push_back(v); n     ad[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) dp[i][0] = i; n   dfs(1, 0); n   for (int j = 2; j <= 20; j++) n     for (int i = 1; i <= n; i++) dp[i][j] = dp[dp[i][j - 1]][j - 1]; n   vector<int> pos; n   red.push_back(1); n   bfs(); n   while (m--) { n     int t; n     cin >> t; n     if (t == 1) { n       int tt; n       cin >> tt; n       pos.push_back(tt); n       if (pos.size() > R) { n         for (auto u : pos) { n           red.push_back(u); n         } n         bfs(); n         pos.clear(); n       } n     } else { n       int v; n       cin >> v; n       int res = d[v] - 1; n       for (auto u : pos) res = min(res, dis(v, u)); n       cout << res <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK: 1024000000,1024000000 ) n using namespace std; n inline int getint() { n   int _x = 0; n   char _tc = getchar(); n   while (_tc <  0  || _tc >  9 ) _tc = getchar(); n   while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar(); n   return _x; n } n const int N = 1e6 + 35; n const int NN = N * 4; n int lazy[NN], mx[NN], a[N], b[N]; n void push_down(int rt) { n   if (lazy[rt]) { n     lazy[rt << 1] += lazy[rt]; n     lazy[rt << 1 | 1] += lazy[rt]; n     mx[rt << 1] += lazy[rt]; n     mx[rt << 1 | 1] += lazy[rt]; n     lazy[rt] = 0; n   } n } n void push_up(int rt) { mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]); } n void update(int rt, int l, int r, int L, int R, int v) { n   if (L <= l && r <= R) { n     lazy[rt] += v; n     mx[rt] += v; n     return; n   } n   int mid = l + r >> 1; n   push_down(rt); n   if (L <= mid) update(rt << 1, l, mid, L, R, v); n   if (R > mid) update(rt << 1 | 1, mid + 1, r, L, R, v); n   push_up(rt); n } n int query(int rt, int l, int r) { n   if (l == r) { n     return l; n   } n   push_down(rt); n   int mid = l + r >> 1; n   if (mx[rt << 1 | 1] > 0) return query(rt << 1 | 1, mid + 1, r); n   return query(rt << 1, l, mid); n } n int main() { n   int n, m, q; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), update(1, 1, N, 1, a[i], 1); n   for (int i = 1; i <= m; i++) scanf( %d , &b[i]), update(1, 1, N, 1, b[i], -1); n   scanf( %d , &q); n   while (q--) { n     int op, x, y; n     scanf( %d%d%d , &op, &x, &y); n     if (op == 1) { n       update(1, 1, N, 1, a[x], -1); n       a[x] = y; n       update(1, 1, N, 1, a[x], 1); n     } else { n       update(1, 1, N, 1, b[x], 1); n       b[x] = y; n       update(1, 1, N, 1, b[x], -1); n     } n     if (mx[1] <= 0) n       puts( -1 ); n     else n       printf( %d n , query(1, 1, N)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n using uint = unsigned int; n template <typename T> n inline void read(T& x) { n   x = 0; n   long long f = 1; n   register char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c & 15); n   x *= f; n } n template <typename T> n inline void print(T x) { n   if (!x) { n     putchar( 0 ); n     return; n   } n   static long long st[105]; n   if (x < 0) putchar( - ), x = -x; n   long long tp = 0; n   while (x) st[++tp] = x % 10, x /= 10; n   while (tp) putchar(st[tp--] +  0 ); n } n template <typename T> n inline void print(T x, char c) { n   print(x); n   putchar(c); n } n template <typename T, typename... Args> n inline void read(T& x, Args&... args) { n   read(x); n   read(args...); n } n template <typename T> n inline void sort(vector<T>& v) { n   sort(v.begin(), v.end()); n   return; n } n template <typename T> n inline void unique(vector<T>& v) { n   sort(v); n   v.erase(unique(v.begin(), v.end()), v.end()); n } n template <typename T> n inline void cmax(T& x, T y) { n   if (x < y) x = y; n   return; n } n template <typename T> n inline void cmin(T& x, T y) { n   if (x > y) x = y; n   return; n } n const long long Mod = LLONG_MAX; n inline long long QP(long long x, long long y) { n   long long ans = 1; n   for (; y; y >>= 1, x = (x * x) % Mod) n     if (y & 1) ans = (ans * x) % Mod; n   return ans; n } n template <typename T> n inline T gcd(T x, T y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n template <typename T> n inline T lcm(T x, T y) { n   return x * y / gcd(x, y); n } n template <typename T> n inline void mul(T& x, T y) { n   x = 1LL * x * y; n   if (x >= Mod) x %= Mod; n } n template <typename T> n inline void add(T& x, T y) { n   if ((x += y) >= Mod) x -= Mod; n } n template <typename T> n inline void sub(T& x, T y) { n   if ((x -= y) < 0) x += Mod; n } n signed main() { n   long long T; n   read(T); n   while (T--) { n     string s; n     getline(cin, s); n     vector<long long> od, ev, ans; n     for (auto x : s) n       if (x -  0  & 1) n         od.push_back(x -  0 ); n       else n         ev.push_back(x -  0 ); n     reverse(ev.begin(), ev.end()); n     reverse(od.begin(), od.end()); n     long long st1 = ev.size(), st2 = od.size(); n     while (st1 || st2) { n       if (!st2 || (st1 && ev[st1 - 1] < od[st2 - 1])) { n         ans.push_back(ev[--st1]); n       } else { n         ans.push_back(od[--st2]); n       } n     } n     for (long long x : ans) print(x); n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const long long MAXN = 4e3 + 7; n const long long MAXM = 1e6 + 7; n const long long MOD = 1e9 + 7; n const double eps = 1e-6; n const double pi = acos(-1.0); n long long quick_pow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = (1LL * ans * a) % MOD; n     a = (1LL * a * a) % MOD; n     b >>= 1; n   } n   return ans; n } n int c[305][305]; n long long ksm1[305], ksm2[305]; n int main() { n   long long n, k; n   scanf( %lld%lld , &n, &k); n   c[0][0] = 1; n   c[1][0] = c[1][1] = 1; n   for (int i = 2; i <= n; i++) { n     c[i][0] = 1; n     for (int j = 1; j <= i; j++) n       c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD; n   } n   ksm1[0] = ksm2[0] = 1; n   for (int i = 1; i <= n; i++) n     ksm1[i] = (ksm1[i - 1] * k) % MOD, ksm2[i] = (ksm2[i - 1] * (k - 1)) % MOD; n   long long ans = 0; n   long long t = 1; n   for (int i = 0; i <= n; i++) { n     ans += t * c[n][i] * quick_pow((ksm1[n - i] * ksm2[i] - ksm2[n]) % MOD, n) % n            MOD; n     t *= -1; n     ans %= MOD; n   } n   printf( %lld n , (ans % MOD + MOD) % MOD); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 255; n const int M = 16; n const int mod = (int)1e9 + 7; n char grid[N][N], ngrid[N][N]; n long long dp[2][M][1 << M][2][2]; n void add(long long& a, long long b) { n   a += b; n   while (a >= mod) { n     a -= mod; n   } n } n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %s , grid[i]); n   } n   if (n < m) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         ngrid[j][i] = grid[i][j]; n       } n     } n     swap(n, m); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         grid[i][j] = ngrid[i][j]; n       } n     } n   } n   if (grid[0][0] ==  x ) { n     dp[0][0][0][0][0] = 1; n   } else { n     dp[0][0][0][0][1] = 1; n     dp[0][0][1][1][0] = 1; n   } n   for (int i = 0; i < n; i++) { n     if (i > 0) { n       for (int j = 0; j < m; j++) { n         for (int mask = 0; mask < 1 << m; mask++) { n           for (int a = 0; a < 2; a++) { n             for (int b = 0; b < 2; b++) { n               dp[i & 1][j][mask][a][b] = 0; n             } n           } n         } n       } n     } n     for (int j = 0; j < m; j++) { n       if (i == 0 && j == 0) continue; n       for (int mask = 0; mask < 1 << m; mask++) { n         for (int a = 0; a < 2; a++) { n           for (int b = 0; b < 2; b++) { n             if (grid[i][j] !=  x ) { n               if (a == 1) { n                 if (mask & (1 << j)) { n                   if (j == 0) { n                     add(dp[i & 1][j][mask][0][b], n                         dp[1 - (i & 1)][m - 1][mask][a][b]); n                     add(dp[i & 1][j][mask][1][b], n                         dp[1 - (i & 1)][m - 1][mask][a][b]); n                   } else { n                     add(dp[i & 1][j][mask][a][b], n                         2 * dp[i & 1][j - 1][mask][a][b]); n                   } n                 } else { n                   if (j == 0) { n                     if (b == 0) { n                       add(dp[i & 1][j][mask][0][b + 1], n                           dp[1 - (i & 1)][m - 1][mask][a][b]); n                     } n                     add(dp[i & 1][j][mask | (1 << j)][a][b], n                         dp[1 - (i & 1)][m - 1][mask][a][b]); n                   } else { n                     add(dp[i & 1][j][mask | (1 << j)][a][b], n                         dp[i & 1][j - 1][mask][a][b]); n                     add(dp[i & 1][j][mask][a][b], dp[i & 1][j - 1][mask][a][b]); n                   } n                 } n               } else { n                 if (mask & (1 << j)) { n                   if (j == 0) { n                     add(dp[i & 1][j][mask][1][b], n                         dp[1 - (i & 1)][m - 1][mask][a][b]); n                     add(dp[i & 1][j][mask][a][b], n                         dp[1 - (i & 1)][m - 1][mask][a][b]); n                   } else { n                     add(dp[i & 1][j][mask][1][b], dp[i & 1][j - 1][mask][a][b]); n                     add(dp[i & 1][j][mask][a][b], dp[i & 1][j - 1][mask][a][b]); n                   } n                 } else { n                   if (j == 0) { n                     if (b == 0) { n                       add(dp[i & 1][j][mask][a][b + 1], n                           dp[1 - (i & 1)][m - 1][mask][a][b]); n                     } n                     add(dp[i & 1][j][mask | (1 << j)][1][b], n                         dp[1 - (i & 1)][m - 1][mask][a][b]); n                   } else { n                     if (b == 0) { n                       add(dp[i & 1][j][mask][a][b + 1], n                           dp[i & 1][j - 1][mask][a][b]); n                     } n                     add(dp[i & 1][j][mask | (1 << j)][1][b], n                         dp[i & 1][j - 1][mask][a][b]); n                   } n                 } n               } n             } else { n               if (j == 0) { n                 add(dp[i & 1][j][mask & (~(1 << j))][0][b], n                     dp[1 - (i & 1)][m - 1][mask][a][b]); n               } else { n                 add(dp[i & 1][j][mask & (~(1 << j))][0][b], n                     dp[i & 1][j - 1][mask][a][b]); n               } n             } n           } n         } n       } n     } n   } n   long long ans = 0; n   for (int mask = 0; mask < 1 << m; mask++) { n     for (int a = 0; a < 2; a++) { n       for (int b = 0; b < 2; b++) { n         add(ans, dp[(n - 1) & 1][m - 1][mask][a][b]); n       } n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename... T> n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<  =  << a <<  ,  ; n   err(++it, args...); n } n const long long inf = 1LL << 60; n const long long md = 1000000007; n vector<long long> adj[200005]; n long long vis[200005] = {0}; n void bfs(long long s) { n   queue<long long> q; n   vis[s] = 1; n   q.push(s); n   while (!q.empty()) { n     long long s = q.front(); n     q.pop(); n     for (auto i : adj[s]) { n       if (vis[i]) continue; n       vis[i] = vis[s] + 1; n       q.push(i); n     } n   } n } n long long vis2[200005] = {0}; n void bfs2(long long s) { n   queue<long long> q; n   vis2[s] = 1; n   q.push(s); n   while (!q.empty()) { n     long long s = q.front(); n     q.pop(); n     for (auto i : adj[s]) { n       if (vis2[i]) continue; n       vis2[i] = vis2[s] + 1; n       q.push(i); n     } n   } n } n bool comp(pair<long long, long long> a, pair<long long, long long> b) { n   return a.first - a.second < b.first - b.second; n } n void solve() { n   long long n, m, k; n   cin >> n >> m >> k; n   long long a[k]; n   for (long long i = 0; i < k; i++) { n     cin >> a[i]; n   } n   for (long long i = 0; i < m; i++) { n     long long x, y; n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   bfs(1); n   bfs2(n); n   pair<long long, long long> d[k]; n   for (long long i = 0; i < k; i++) { n     d[i] = {vis[a[i]], vis2[a[i]]}; n   } n   sort(d, d + k, comp); n   long long ans = 0; n   long long mx = -inf; n   for (long long i = 0; i < k; i++) { n     ans = max(ans, mx + d[i].second); n     mx = max(mx, d[i].first); n   } n   cout << min(vis[n] - 1, ans - 1); n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   for (long long i = 1; i <= t; i++) { n     solve(); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10, inf = 0x3f3f3f3f; n void cmin(int& x, int y) { n   if (x > y) { n     x = y; n   } n } n int n, a[N]; n long long answer; n vector<int> adj[N]; n void dfs(int u, int p, int d, int s) { n   if (d & 1) { n     answer += a[u] - s; n     s = a[u]; n   } else { n     int minv = inf; n     for (auto v : adj[u]) { n       if (v != p) { n         cmin(minv, a[v]); n       } n     } n     if (minv < s) { n       puts( -1 ); n       exit(0); n     } else if (minv != inf) { n       answer += minv - s; n       s = minv; n     } n   } n   for (auto v : adj[u]) { n     if (v != p) { n       dfs(v, u, d + 1, s); n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= n; ++i) { n     int x; n     scanf( %d , &x); n     adj[x].push_back(i); n   } n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n   } n   dfs(1, 0, 1, 0); n   printf( %lld n , answer); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( -ffloat-store ) n #pragma GCC optimize( -fno-defer-pop ) n long long power(long long a, long long b, long long m) { n   if (b == 0) return 1; n   if (b == 1) return a % m; n   long long t = power(a, b / 2, m); n   t = (t * t) % m; n   if (b & 1) t = (t * a) % m; n   return t; n } n using namespace std; n int main() { n   ; n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long t; n   cin >> t; n   while (t--) { n     long long a, b, c, d; n     cin >> a >> b >> c >> d; n     long long x, y, x1, y1, x2, y2; n     cin >> x >> y >> x1 >> y1 >> x2 >> y2; n     if (x2 - x1 == 0 && (a != 0 || b != 0)) { n       cout <<  NO  << endl; n       continue; n     } n     if (y2 - y1 == 0 && (c != 0 || d != 0)) { n       cout <<  NO  << endl; n       continue; n     } n     long long disx, disy; n     disx = b - a; n     disy = d - c; n     if (0 <= disx) { n       if (x2 - x < disx) { n         cout <<  NO  << endl; n         continue; n       } n     } else { n       if (x - x1 < (-disx)) { n         cout <<  NO  << endl; n         continue; n       } n     } n     if (0 <= disy) { n       if (y2 - y < disy) { n         cout <<  NO  << endl; n         continue; n       } n     } else { n       if (y - y1 < (-disy)) { n         cout <<  NO  << endl; n         continue; n       } n     } n     cout <<  YES  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int x[100000]; n int dist(int a, int b) { return abs(a - b); } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> x[i]; n   cout << dist(x[0], x[1]) <<     << dist(x[0], x[n - 1]) << endl; n   for (int i = 1; i < n - 1; i++) n     cout << min(dist(x[i], x[i - 1]), dist(x[i], x[i + 1])) <<     n          << max(dist(x[i], x[0]), dist(x[i], x[n - 1])) << endl; n   cout << dist(x[n - 1], x[n - 2]) <<     << dist(x[0], x[n - 1]) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string s; n   int sz; n   cin >> n; n   cin >> s; n   sz = s.size(); n   int count = 0; n   bool valid = true; n   for (int i = 0; i < sz; i++) { n     if (s[i] ==  1 ) { n       if (i < sz - 1 && s[i + 1] ==  1 ) { n         valid = false; n       } n       count++; n     } else { n       if ((i == 0 || s[i - 1] ==  0 )) { n         if (i == sz - 1 || s[i + 1] ==  0 ) { n           valid = false; n         } n       } n     } n   } n   if (valid == true && count > 0) { n     cout <<  Yes  << endl; n   } else { n     cout <<  No  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 500, mod = 998244353; n int K, tmp[N], tmpa[N], tmpb[N], rev[N], b[N], tw[N], w[N], limn, n, qn; n vector<int> a[N]; n int qpower(int a, int b) { n   int ans = 1; n   for (; b; b >>= 1, a = 1ll * a * a % mod) n     if (b & 1) ans = 1ll * ans * a % mod; n   return ans; n } n void prework(int n) { n   limn = 1; n   while (limn <= n) limn <<= 1; n   for (int i = 1; i < limn; i++) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) ? (limn >> 1) : 0); n   for (int i = 1; i < limn; i <<= 1) { n     int omg = qpower(3, (mod - 1) / (i << 1)); n     w[i] = 1; n     for (int j = 1; j < i; j++) w[i + j] = 1ll * w[i + j - 1] * omg % mod; n   } n } n void NTT(int a[], int l) { n   for (int i = 0; i < l; i++) tmp[rev[i] / (limn / l)] = a[i]; n   for (int i = 1; i < l; i <<= 1) n     for (int j = 0; j < l; j += i << 1) n       for (int k = 0; k < i; k++) { n         int x = tmp[j + k], y = 1ll * w[i + k] * tmp[i + j + k] % mod; n         tmp[j + k] = (x + y) % mod, tmp[i + j + k] = (x - y) % mod; n       } n   for (int i = 0; i < l; i++) a[i] = tmp[i]; n } n void mul(const vector<int> A, const vector<int> B, vector<int>& c) { n   int la = A.size(), lb = B.size(), n = la + lb - 1; n   int l = 1; n   while (l < n) l <<= 1; n   for (int i = 0; i < la; i++) tmpa[i] = A[i]; n   for (int i = la; i < l; i++) tmpa[i] = 0; n   for (int i = 0; i < lb; i++) tmpb[i] = B[i]; n   for (int i = lb; i < l; i++) tmpb[i] = 0; n   NTT(tmpa, l), NTT(tmpb, l); n   for (int i = 0; i < l; i++) tmpa[i] = 1ll * tmpa[i] * tmpb[i] % mod; n   reverse(tmpa + 1, tmpa + l); n   NTT(tmpa, l); n   int iv = mod - (mod - 1) / l; n   if (K + 1 < n) n = K + 1; n   c.resize(n); n   for (int i = 0; i < n; i++) c[i] = 1ll * tmpa[i] * iv % mod; n } n void solve(int rot, int lt, int rt) { n   if (lt == rt) { n     a[rot].resize(2); n     a[rot][0] = 1, a[rot][1] = b[lt]; n     return; n   } n   int mid = (lt + rt) >> 1; n   solve(rot << 1, lt, mid), solve(rot << 1 | 1, mid + 1, rt); n   mul(a[rot << 1], a[rot << 1 | 1], a[rot]); n } n int main() { n   scanf( %d%d , &n, &K); n   prework(n); n   for (int i = 1; i <= n; i++) scanf( %d , tw + i); n   scanf( %d , &qn); n   for (int i = 1, opt, l, r, q, d; i <= qn; i++) { n     scanf( %d , &opt); n     if (opt == 1) { n       scanf( %d%d%d , &q, &l, &d); n       for (int j = 1; j <= n; j++) b[j] = q - tw[j]; n       b[l] = q - d; n       solve(1, 1, n); n       printf( %d n , (a[1][K] + mod) % mod); n     } else { n       scanf( %d%d%d%d , &q, &l, &r, &d); n       for (int j = 1; j <= n; j++) b[j] = q - tw[j]; n       for (int j = l; j <= r; j++) b[j] -= d; n       solve(1, 1, n); n       printf( %d n , (a[1][K] + mod) % mod); n     } n   } 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 x = 0; x < n; x++) { n     cin >> a[x]; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       for (int k = 0; k < n; ++k) { n         if (a[i] == a[j] + a[k] && (i != j && j != k && i != k)) { n           cout << i + 1 <<     << j + 1 <<     << k + 1 << endl; n           return 0; n         } n       } n     } n   } n   cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct FenwickTree { n   int n; n   vector<int> bit; n   FenwickTree(int n) { n     this->n = n + 1; n     bit.assign(n + 1, 0); n   } n   int sum(int r) { n     int sum = 0; n     while (r > 0) { n       sum += bit[r]; n       r -= (r & -r); n     } n     return sum; n   } n   int sum(int l, int r) { return sum(r) - sum(l - 1); } n   void add(int index, int val) { n     while (index < n) { n       bit[index] += val; n       index += (index & -index); n     } n   } n   int getNum(int index) { return sum(index, index); } n }; n int main() { n   int n, k, a, b, q; n   cin >> n >> k >> a >> b >> q; n   FenwickTree antes = FenwickTree(n); n   FenwickTree depois = FenwickTree(n); n   while (q--) { n     int type, d, val; n     cin >> type >> d; n     if (type == 1) { n       cin >> val; n       int aux1 = min(b - antes.getNum(d), val); n       int aux2 = min(a - depois.getNum(d), val); n       antes.add(d, aux1); n       depois.add(d, aux2); n     } else { n       int resp = 0; n       resp += antes.sum(d - 1); n       resp += depois.sum(d + k, n); n       cout << resp << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, d, a, b, x, y, ans = 0; n pair<int, int> m[111111]; n long long sum = 0; n int main() { n   scanf( %d%d%d%d , &n, &d, &a, &b); n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &x, &y); n     m[i].first = a * x + b * y; n     m[i].second = i + 1; n   } n   sort(m, m + n); n   for (int i = 0; i < n; i++) { n     sum += m[i].first; n     if (sum > d) break; n     ans++; n   } n   printf( %d n , ans); n   for (int i = 0; i < ans; i++) printf( %d  , m[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int LIMIT = 3e5; n long long n, m, a[LIMIT], p[LIMIT], d[LIMIT]; n long long gcd(long long a, long long b) { n   if (a % b == 0) return b; n   return gcd(b, a % b); n } n int main() { n   scanf( %lld %lld , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %lld , &a[i]); n   } n   for (int i = 0; i < m; i++) { n     scanf( %lld , &p[i]); n   } n   for (int i = 0; i < (n - 1); i++) { n     d[i] = a[i + 1] - a[i]; n   } n   long long gcdAll = d[0]; n   for (int i = 1; i < (n - 1); i++) { n     gcdAll = gcd(d[i], gcdAll); n   } n   for (int i = 0; i < m; i++) { n     if ((gcdAll % p[i]) == 0) { n       printf( %s n%lld %d ,  YES , a[0], (i + 1)); n       return 0; n     } n   } n   printf( %s ,  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n int Q[N], S[N], ok[N + N], Sav[N], mat[N + N][N]; n int dp[N + N][N]; n int solve(int p, int k) { n   if (ok[p]) return k == 0; n   if (!k) return 0; n   if (dp[p][k] != -1) return dp[p][k]; n   return dp[p][k] = solve(p - 1, k - 1) | solve(p + 1, k - 1); n } n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> Q[i], Sav[Q[i]] = i, mat[100][i] = i; n   for (int i = 1; i <= n; i++) cin >> S[i]; n   for (int i = 99; i >= 0; i--) n     for (int j = 1; j <= n; j++) mat[i][j] = mat[i + 1][Sav[j]]; n   for (int i = 101; i <= 200; i++) n     for (int j = 1; j <= n; j++) mat[i][j] = mat[i - 1][Q[j]]; n   for (int i = 0; i <= 200; i++) { n     ok[i] = 1; n     for (int j = 1; j <= n; j++) ok[i] &= mat[i][j] == S[j]; n   } n   memset(dp, -1, sizeof(dp)); n   puts(solve(100, k) ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, a, n, sum = 0, hand = 0; n   vector<long long int> v; n   cin >> n; n   v.clear(); n   for (i = 0; i < n; i++) { n     cin >> a; n     if (a % 2 != 0) hand++; n     v.push_back(a); n     sum += a; n   } n   long long int value = 1e13; n   if (hand % 2 != 0) { n     for (i = 0; i < v.size(); i++) { n       if (v[i] & 1) value = min(v[i], value); n     } n     sum -= value; n   } n   cout << sum << endl; n   v.clear(); n } n


#include <bits/stdc++.h> n using namespace std; n int a[10]; n int main() { n   cin >> a[1] >> a[2] >> a[3]; n   sort(a + 1, a + 1 + 3); n   cout << max(a[3] - a[1] - a[2] + 1, 0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n inline int getint() { n   int x = 0, p = 1; n   char c = getchar(); n   while (c <= 32) c = getchar(); n   if (c == 45) p = -p, c = getchar(); n   while (c > 32) x = x * 10 + c - 48, c = getchar(); n   return x * p; n } n using namespace std; n const int N = 110; n const int M = 25; n int dp[N][M][M], n, k, res, tmp[N][M][M]; n vector<int> G[N]; n inline void add(int &x, int y) { n   x += y; n   if (x >= 1000000007) x -= 1000000007; n } n inline int mul(int x, int y) { n   long long ans = 1ll * x * y; n   return ans % 1000000007; n } n void go(int x, int p) { n   vector<int> v; n   for (int(i) = 0; (i) < (G[x].size()); (i)++) { n     int to = G[x][i]; n     if (to != p) { n       go(to, x); n       v.push_back(to); n     } n   } n   tmp[0][1][M - 1] = tmp[0][0][1] = 1; n   for (int(i) = 0; (i) < (v.size()); (i)++) { n     int x = v[i]; n     for (int(i0) = 0; (i0) < (M); (i0)++) n       for (int(i1) = 0; (i1) < (M); (i1)++) tmp[i + 1][i0][i1] = 0; n     for (int(i0) = 0; (i0) < (k + 2); (i0)++) n       for (int(i1) = 0; (i1) < (M); (i1)++) { n         for (int(i2) = 0; (i2) < (k + 2); (i2)++) n           for (int(i3) = 0; (i3) < (M); (i3)++) { n             int hh = mul(tmp[i][i0][i1], dp[x][i2][i3]); n             if ((!i2 || i1 + i2 - 1 <= k) && (!i0 || i0 + i3 - 1 <= k)) { n               add(tmp[i + 1][0][min(i1, i3 + 1)], hh); n               continue; n             } n             if (!i2 || i1 + i2 - 1 <= k) { n               add(tmp[i + 1][i0][min(i1, i3 + 1)], hh); n               continue; n             } n             if (!i0 || i0 + i3 - 1 <= k) { n               if (i2 <= k) add(tmp[i + 1][i2 + 1][min(i1, i3 + 1)], hh); n               continue; n             } n             if (i2 <= k) add(tmp[i + 1][max(i0, i2 + 1)][min(i1, i3 + 1)], hh); n           } n       } n   } n   for (int(i) = 0; (i) < (k + 2); (i)++) n     for (int(j) = 0; (j) < (M); (j)++) dp[x][i][j] = tmp[v.size()][i][j]; n } n int main() { n   n = getint(); n   k = getint(); n   for (int(i) = 0; (i) < (n - 1); (i)++) { n     int x = getint() - 1, y = getint() - 1; n     G[x].push_back(y); n     G[y].push_back(x); n   } n   go(0, -1); n   for (int i = 1; i <= k + 1; i++) n     if (dp[0][0][i] > 0) add(res, dp[0][0][i]); n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   double x, y; n   Point() : x(0), y(0) {} n   Point(double _x, double _y) : x(_x), y(_y) {} n   bool operator<(const Point &b) const { return tie(x, y) < tie(b.x, b.y); } n   bool operator==(const Point &b) const { return tie(x, y) == tie(b.x, b.y); } n   Point operator+(const Point &b) const { return Point(x + b.x, y + b.y); } n   Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); } n   double operator*(const Point &b) const { return x * b.x + y * b.y; } n   double operator%(const Point &b) const { return x * b.y - y * b.x; } n   Point operator*(const double &b) const { return Point(x * b, y * b); } n   double abs() { return sqrt(abs2()); } n   double abs2() { return x * x + y * y; } n }; n long long cross(Point o, Point a, Point b) { return (a - o) % (b - o); } n vector<Point> convex_hull(vector<Point> &pt) { n   sort(pt.begin(), pt.end()); n   int top = 0; n   vector<Point> stk(2 * pt.size()); n   for (int i = 0; i < (int)pt.size(); i++) { n     while (top >= 2 && cross(stk[top - 2], stk[top - 1], pt[i]) <= 0) top--; n     stk[top++] = pt[i]; n   } n   for (int i = pt.size() - 2, t = top + 1; i >= 0; i--) { n     while (top >= t && cross(stk[top - 2], stk[top - 1], pt[i]) <= 0) top--; n     stk[top++] = pt[i]; n   } n   stk.resize(top - 1); n   return stk; n } n int N, R; n int ans; n vector<Point> convexP, chp, sol; n int dis2(Point a, Point b) { n   return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); n } n void DFS(int i, int prv, int val) { n   if (i >= N) { n     if (val > ans) { n       ans = val; n       sol = chp; n     } n     return; n   } n   for (int j = prv; j < (int)convexP.size(); j++) { n     int c = 0; n     for (auto pt : chp) c += (pt - convexP[j]).abs2(); n     chp.push_back(convexP[j]); n     DFS(i + 1, j, val + c); n     chp.pop_back(); n   } n } n int main() { n   vector<Point> pt; n   cin >> N >> R; n   if (N % 2 == 0) { n     for (int i = 0; i < N / 2; i++) { n       sol.push_back(Point(R, 0)); n       sol.push_back(Point(-R, 0)); n     } n     for (int i = 0; i < N; i++) n       for (int j = 0; j < i; j++) ans += (sol[i] - sol[j]).abs2(); n   } else { n     for (int i = -R; i <= R; i++) { n       for (int j = -R; j <= R; j++) { n         if (i * i + j * j <= R * R) { n           pt.push_back(Point(i, j)); n         } n       } n     } n     convexP = convex_hull(pt); n     ans = 0; n     DFS(0, 0, 0); n   } n   cout << ans << endl; n   for (auto p : sol) cout << p.x <<     << p.y << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string str; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> str; n   int ans = 0; n   for (int i = 0; i < n; i += 2) { n     int cnt = 0; n     if (str[i] ==  a ) n       cnt++; n     else n       cnt--; n     if (str[i + 1] ==  a ) n       cnt++; n     else n       cnt--; n     if (cnt != 0) { n       if (str[i] ==  a ) n         str[i] =  b ; n       else n         str[i] =  a ; n       ans++; n     } n   } n   cout << ans <<   n ; n   cout << str <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) { n     long long n; n     cin >> n; n     string s; n     cin >> s; n     cout << n + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n const int N = 2e5 + 5; n vector<pair<long long, long long> > v; n long long n, m, k; n void solve() { n   sort(v.rbegin(), v.rend()); n   long long sum = 0; n   vector<long long> index; n   for (long long i = 0; i < m * k; i++) { n     sum += v[i].first; n     index.push_back(v[i].second); n   } n   sort(index.begin(), index.end()); n   cout << sum <<   n ; n   for (int i = 0; i < k - 1; i++) cout << index[(i + 1) * m - 1] <<    ; n } n int main() { n   fast(); n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     long long t; n     cin >> t; n     v.push_back(make_pair(t, i + 1)); n   } n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, a, b, v, ans; n   while (scanf( %d%d%d%d , &k, &a, &b, &v) != EOF) { n     ans = 0; n     while (a > 0) { n       if (b >= k - 1) { n         b -= (k - 1); n         a -= v * k; n         ans++; n       } else { n         b = b + 1; n         a -= v * b; n         ans++; n         b = 0; n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int kN = int(3E2 + 10), kC = int(2E6 + 10); n vector<pair<int, int>> v[kC], nv[kC]; n int ans[kC], a[kN][kN], pos[kN][kN], p[kN * kN], up[kN * kN], dwn[kN * kN], n     lft[kN * kN], rht[kN * kN], nans[kC]; n bool have[kN * kN]; n int Find(int n) { return p[n] == n ? n : p[n] = Find(p[n]); } n bool merge(int l, int r) { n   l = Find(l), r = Find(r); n   if (l == r) n     return false; n   else { n     p[l] = r; n     return true; n   } n } n int main() { n   int n, m, q, x, y, c, now = 0, tmp; n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) a[i][j] = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) pos[i][j] = now++; n   for (int i = 1; i < n; i++) n     for (int j = 1; j <= m; j++) { n       up[pos[i][j]] = pos[i + 1][j]; n       dwn[pos[i + 1][j]] = pos[i][j]; n     } n   for (int i = 1; i <= m; i++) up[pos[n][i]] = dwn[pos[1][i]] = -1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j < m; j++) { n       lft[pos[i][j]] = pos[i][j + 1]; n       rht[pos[i][j + 1]] = pos[i][j]; n     } n   for (int i = 1; i <= n; i++) lft[pos[i][m]] = rht[pos[i][1]] = -1; n   for (int i = 1; i <= q; i++) { n     scanf( %d%d%d , &x, &y, &c); n     if (a[x][y] == c) n       continue; n     else { n       nv[a[x][y]].push_back({pos[x][y], i}); n       a[x][y] = c; n       v[a[x][y]].push_back({pos[x][y], i}); n     } n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) nv[a[i][j]].push_back({pos[i][j], q + 1}); n   ans[0] = nans[q + 1] = 0; n   for (int i = 0; i <= c; i++) { n     for (int j = 0; j < now; j++) p[j] = j; n     for (int j = 0; j < now; j++) have[j] = false; n     tmp = 0; n     for (pair<int, int> j : v[i]) { n       ans[j.second]++; n       tmp++; n       have[j.first] = true; n       if (up[j.first] >= 0 && have[up[j.first]]) n         if (merge(j.first, up[j.first])) { n           tmp--; n           ans[j.second]--; n         } n       if (lft[j.first] >= 0 && have[lft[j.first]]) n         if (merge(j.first, lft[j.first])) { n           ans[j.second]--; n           tmp--; n         } n       if (rht[j.first] >= 0 && have[rht[j.first]]) n         if (merge(j.first, rht[j.first])) { n           ans[j.second]--; n           tmp--; n         } n       if (dwn[j.first] >= 0 && have[dwn[j.first]]) n         if (merge(j.first, dwn[j.first])) { n           ans[j.second]--; n           tmp--; n         } n     } n     reverse(nv[i].begin(), nv[i].end()); n     if (tmp) { n       ans[v[i].back().second + 1] -= tmp; n       nans[v[i].back().second] -= tmp; n     } n     for (int j = 0; j < now; j++) p[j] = j; n     for (int j = 0; j < now; j++) have[j] = false; n     for (pair<int, int> j : nv[i]) { n       nans[j.second - 1]++; n       have[j.first] = true; n       if (up[j.first] >= 0 && have[up[j.first]]) n         if (merge(j.first, up[j.first])) nans[j.second - 1]--; n       if (lft[j.first] >= 0 && have[lft[j.first]]) n         if (merge(j.first, lft[j.first])) nans[j.second - 1]--; n       if (rht[j.first] >= 0 && have[rht[j.first]]) n         if (merge(j.first, rht[j.first])) nans[j.second - 1]--; n       if (dwn[j.first] >= 0 && have[dwn[j.first]]) n         if (merge(j.first, dwn[j.first])) nans[j.second - 1]--; n     } n   } n   for (int i = q; i >= 1; i--) nans[i] += nans[i + 1]; n   for (int i = 1; i <= q; i++) ans[i] += ans[i - 1]; n   for (int i = 1; i <= q; i++) printf( %d n , ans[i] + nans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> graph[80005]; n bool vis[100005]; n long long int size[100005]; n long long int arr[100005]; n long long int ans2; n long long int ans; n int dfs1(int node) { n   vis[node] = true; n   int ret = 1; n   for (int i = 0; i < graph[node].size(); i++) { n     if (vis[graph[node][i]]) continue; n     ret += dfs1(graph[node][i]); n   } n   return (size[node] = ret); n } n void dfs2(int node, long long int cum) { n   vis[node] = true; n   long long int rem = n - size[node]; n   int i; n   long long int sum = 0, sqsum = 0, temp; n   for (i = 0; i < graph[node].size(); i++) { n     if (vis[graph[node][i]]) continue; n     temp = size[graph[node][i]]; n     sum += temp; n     sqsum += temp * temp; n   } n   long long int paths = (sum * sum - sqsum) / 2 + sum; n   ans += (rem * (rem - 1) / 2) * paths; n   ans2 += cum * paths; n   for (i = 0; i < graph[node].size(); i++) { n     if (vis[graph[node][i]]) continue; n     temp = size[graph[node][i]]; n     dfs2(graph[node][i], cum + (-(sum - temp) + (sqsum - temp * temp)) / 2); n   } n } n int main() { n   int i, a, b; n   scanf( %d , &n); n   for (i = 0; i < n - 1; i++) { n     scanf( %d , &a); n     scanf( %d , &b); n     graph[a].push_back(b); n     graph[b].push_back(a); n   } n   memset(vis, 0, sizeof(vis)); n   dfs1(1); n   ans = 0; n   ans2 = 0; n   memset(vis, 0, sizeof(vis)); n   dfs2(1, 0); n   ans = 2 * ans - ans2; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n signed main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long arr[n]; n     long long sum = 0; n     for (long long i = 0; i < n; i++) { n       cin >> arr[i]; n       sum += arr[i]; n     } n     sum = 2 * sum; n     if (sum % n) { n       cout << 0 <<   n ; n       continue; n     } n     sum /= n; n     long long ans = 0; n     unordered_map<long long, long long, custom_hash> mp1; n     for (long long i = 0; i < n; i++) { n       ans += mp1[sum - arr[i]]; n       mp1[arr[i]]++; n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char ff[1005][1005]; n int main() { n   int t; n   scanf( %d , &t); n   for (int i = 0; i < t; i++) { n     int zz[1005]; n     int n, m, x, y; n     int ww = 0; n     int w = 0; n     scanf( %d%d%d%d , &n, &m, &x, &y); n     for (int j = 1; j <= n; j++) { n       char f[1005]; n       scanf( %s , f); n       memset(zz, 0, sizeof(zz)); n       for (int z = 0; z < strlen(f); z++) { n         ff[j][z + 1] = f[z]; n         if (ff[j][z + 1] == ff[j][z] && ff[j][z] ==  .  && zz[z + 1] == 0 && n             zz[z] == 0) { n           ww++; n           zz[z + 1] = 1; n           zz[z] = 1; n         } n         if (ff[j][z + 1] ==  . ) w++; n       } n     } n     if (y >= 2 * x) { n       printf( %d n , x * w); n     } else n       printf( %d n , ww * y + x * (w - ww * 2)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000; n const int MAX = 100000 + 100; n const int inf = 999999999; n const int p1 = 104393321, p2 = 104393329; n int n, m; n int par[MAX], sizeofcom[MAX], size[MAX], a[MAX], b[MAX], d[MAX]; n bool lucky(int x) { n   while (x > 0) { n     if (x % 10 == 7 || x % 10 == 4) n       x /= 10; n     else n       return false; n   } n   return true; n } n int find(int k) { n   if (par[k] == k) n     return k; n   else n     par[k] = find(par[k]); n   return par[k]; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = (0); i < int(n); ++i) par[i] = i; n   int x, y; n   for (int i = (0); i < int(m); ++i) { n     cin >> x >> y; n     x--; n     y--; n     par[find(x)] = find(y); n   } n   for (int i = (0); i < int(n); ++i) sizeofcom[find(i)]++; n   for (int i = (0); i < int(n + 1); ++i) size[sizeofcom[i]]++; n   for (int i = (1); i < int(n + 1); ++i) n     if (lucky(i) && size[i]) { n       cout << 0 << endl; n       return 0; n     } n   int sz = 0; n   for (int i = (1); i < int(n + 1); ++i) { n     int tmp = 1; n     while (tmp <= size[i]) { n       a[sz] = tmp * i; n       b[sz++] = tmp; n       size[i] -= tmp; n       tmp *= 2; n     } n     if (size[i]) { n       a[sz] = size[i] * i; n       b[sz++] = size[i]; n     } n   } n   int ans = inf; n   for (int i = (1); i < int(n + 1); ++i) d[i] = inf; n   d[a[0]] = 1; n   for (int j = (1); j < int(sz); ++j) { n     for (int i = (n); i > int(0); --i) { n       if (a[j] <= i) d[i] = min(d[i], d[i - a[j]] + b[j]); n       if (lucky(i) && d[i] != inf) ans = min(ans, d[i]); n     } n   } n   if (ans == inf) n     cout << -1 << endl; n   else n     cout << ans - 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int main() { n   string s1, s2, s; n   int n, m; n   scanf( %d%d , &n, &m); n   map<string, string> mp; n   for (int i = 0; i < m; ++i) { n     cin >> s1 >> s2; n     if (s2.size() >= s1.size()) n       mp[s1] = s1; n     else n       mp[s1] = s2; n   } n   for (int i = 0; i < n; ++i) { n     cin >> s; n     cout << mp[s] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int INF = 2e9; n const long long int LONGINF = 4e18; n long long int inv[200200], fct[200200], invfct[200200]; n long long int c[2222]; n long long int C(long long int n, long long int k) { n   return fct[n] * invfct[n - k] % mod * invfct[k] % mod; n } n void solve(int n) { n   int m, g; n   long long int c, ans = 0; n   scanf( %d%d , &m, &g); n   inv[1] = 1; n   fct[0] = 1; n   fct[1] = 1; n   invfct[0] = 1; n   invfct[1] = 1; n   for (int i = (2); i < (200200); i++) { n     inv[i] = -((long long int)mod / i * inv[mod % i] % mod) + mod; n     fct[i] = fct[i - 1] * i % mod; n     invfct[i] = invfct[i - 1] * inv[i] % mod; n   } n   if (m == 0) { n     if (n % 2 == 1 - g) { n       printf( 1 ); n     } else { n       printf( 0 ); n     } n     return; n   } n   c = C(n + m - 1, n); n   for (int i = 0; i < (n + 1); i++) { n     if (m == 1 && i == n) { n       if ((n + 1) % 2 == g) { n         ans++; n         ans %= mod; n       } n       continue; n     } n     if (i % 2 == g) { n       ans += c; n       ans %= mod; n     } n     c = c * inv[n + m - i - 1] % mod * (n - i) % mod; n     ; n   } n   printf( %I64d , ans); n } n int main() { n #pragma comment(linker,  /STACK:268435456 ) n   int n; n   long long int a; n   char c[200200]; n   string s; n   while (scanf( %d , &n) == 1) solve(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[110], s[110]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = (1); i < (n + 1); i++) cin >> x[i]; n   for (int i = (1); i < (n + 1); i++) s[i] = s[i - 1] + x[i]; n   int v = 0; n   while (m--) { n     int l, r; n     cin >> l >> r; n     if (s[r] - s[l - 1] > 0) v += s[r] - s[l - 1]; n   } n   cout << v <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n vector<vector<int>> g; n vector<int> vis, cap; n void dfs(int s) { n   vis[s] = 1; n   cap[s] = 1; n   for (int i : g[s]) { n     if (vis[i] == 0) { n       dfs(i); n     } n   } n } n int32_t main() { n   { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n   } n   int n, m; n   cin >> n >> m; n   vector<vector<int>> a(n); n   g.resize(m + 1); n   vis.assign(m + 1, 0); n   cap.assign(m + 1, 0); n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     a[i].resize(k); n     for (int j = 0; j < k; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 1; i < n; i++) { n     int k0 = a[i - 1].size(), k1 = a[i].size(); n     int j = 0, f = 0; n     while (j < k0 and j < k1) { n       if (a[i - 1][j] == a[i][j]) { n         j++; n         continue; n       } n       f = 1; n       if (a[i - 1][j] < a[i][j]) { n         g[a[i][j]].push_back(a[i - 1][j]); n       } else { n         cap[a[i - 1][j]] = 1; n       } n       break; n     } n     if (f == 0) { n       if (a[i].size() < a[i - 1].size()) { n         cout <<  No ; n         return 0; n       } n     } n   } n   for (int i = 1; i <= m; i++) { n     if (vis[i] == 0 and cap[i] == 1) { n       dfs(i); n     } n   } n   for (int i = 1; i < n; i++) { n     int k0 = a[i - 1].size(), k1 = a[i].size(); n     int j = 0; n     while (j < k0 and j < k1) { n       if (a[i - 1][j] == a[i][j]) { n         j++; n         continue; n       } n       if (a[i - 1][j] < a[i][j]) { n         if (cap[a[i][j]] == 1 and cap[a[i - 1][j]] != 1) { n           cout <<  No ; n           return 0; n         } n       } else { n         if (cap[a[i][j]] == 1) { n           cout <<  No ; n           return 0; n         } n       } n       break; n     } n   } n   { n     cout <<  Yes n ; n     vector<int> ans; n     for (int i = 1; i <= m; i++) { n       if (cap[i] == 1) { n         ans.push_back(i); n       } n     } n     cout << ans.size() <<   n ; n     for (int i : ans) { n       cout << i <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(T& num) { n   char CH; n   bool F = false; n   for (CH = getchar(); CH <  0  || CH >  9 ; F = CH ==  - , CH = getchar()) n     ; n   for (num = 0; CH >=  0  && CH <=  9 ; n        num = num * 10 + CH -  0 , CH = getchar()) n     ; n   F && (num = -num); n } n int stk[70], tp; n template <class T> n inline void print(T p) { n   if (!p) { n     puts( 0 ); n     return; n   } n   while (p) stk[++tp] = p % 10, p /= 10; n   while (tp) putchar(stk[tp--] +  0 ); n   putchar(  n ); n } n const long long mod = 1e9 + 7; n const double PI = acos(-1.0); n const int inf = 1e9; n const int N = 1e5 + 10; n const int maxn = 1e3 + 20; n const double eps = 1e-12; n int check(int x) { n   int l = 1, r = 1000005; n   if (x == 0) return 0; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if ((long long)mid * (mid - 1) < (long long)2 * x) n       l = mid + 1; n     else n       r = mid - 1; n   } n   return l; n } n int main() { n   int a, b, c, d; n   read(a); n   read(b); n   read(c); n   read(d); n   int x = check(a), y = check(d); n   if (x == 0 && (b || c)) x = 1; n   if (y == 0 && (b || c)) y = 1; n   if ((long long)x * (x - 1) != (long long)2 * a || n       (long long)y * (y - 1) != (long long)2 * d || n       (long long)x * y != (long long)b + c) n     cout <<  Impossible n ; n   else { n     if (x == 0 && y == 0) n       printf( 0 ); n     else if (x == 0) { n       for (int i = 1; i <= y; i++) printf( 1 ); n     } else if (y == 0) { n       for (int i = 1; i <= x; i++) printf( 0 ); n     } else { n       int t = b / y, f = y - b % y; n       for (int i = 1; i <= t; i++) printf( 0 ), x--; n       for (int i = 1; i <= f; i++) printf( 1 ), y--; n       if (x > 0) { n         printf( 0 ); n         x--; n       } n       for (int i = 1; i <= y; i++) printf( 1 ); n       for (int i = 1; i <= x; i++) printf( 0 ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n struct edge { n   int from, to, next; n } e[N * 20], e2[N * 10]; n int head[N], ecnt, vis[N], fa[N][18], dep[N], ok[N * 10], ecnt2; n map<pair<int, int>, int> mp; n inline void adde(int from, int to) { n   e[++ecnt] = (edge){from, to, head[from]}, head[from] = ecnt; n   e[++ecnt] = (edge){to, from, head[to]}, head[to] = ecnt; n } n int fir, sec; n vector<int> G[N]; n void dfs(int u, int f) { n   fa[u][0] = f, dep[u] = dep[f] + 1, vis[u] = 1; n   for (int i = 1; i <= 17; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1]; n   for (auto v : G[u]) n     if (!vis[v]) { n       adde(v, u); n       int a = v, b = u; n       if (a > b) swap(a, b); n       ok[mp[pair<int, int>(a, b)]] = 1, dfs(v, u); n     } n } n inline int LCA(int a, int b) { n   if (dep[a] < dep[b]) swap(a, b); n   for (int i = 17; i >= 0; i--) n     if (dep[fa[a][i]] >= dep[b]) a = fa[a][i]; n   if (a == b) return a; n   for (int i = 17; i >= 0; i--) n     if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i]; n   return fa[a][0]; n } n set<int> add[N], del[N], fuck[N]; n bool flg; n inline void mark(int a, int b, int id) { n   int lca = LCA(a, b); n   add[a].insert(id), add[b].insert(id), del[lca].insert(id); n } n void dfs2(int u, int f) { n   for (int i = head[u]; i && !flg; i = e[i].next) n     if (e[i].to != f) dfs2(e[i].to, u); n   if (flg) return; n   for (auto v : add[u]) fuck[u].insert(v); n   for (int i = head[u]; i; i = e[i].next) n     if (e[i].to != f && fuck[e[i].to].size()) n       fuck[u].insert(*fuck[e[i].to].begin()); n   for (auto v : del[u]) fuck[u].erase(v); n   if (fuck[u].size() >= 2) { n     fir = *fuck[u].begin(), fuck[u].erase(fuck[u].begin()), n     sec = *fuck[u].begin(); n     flg = true; n   } n } n int tmp[N], to, stk[N], top, hh, tmp2[N * 10]; n void dfs3(int u) { n   if (u == to) { n     hh = 1, printf( %d  , top); n     for (int i = 1; i <= top; i++) printf( %d  , stk[i]); n     puts(  ); n     return; n   } n   tmp[u] = 1; n   for (auto v : G[u]) n     if (!tmp[v]) { n       int a = u, b = v; n       if (a > b) swap(a, b); n       int t = mp[pair<int, int>(a, b)]; n       if (tmp2[t]) continue; n       if (!ok[t] && t != fir && t != sec) continue; n       tmp2[t] = 1, stk[++top] = v, dfs3(v), top--; n       if (hh) return; n     } n } n inline void work(int a1, int a2, int b1, int b2) { n   static int p[5]; n   p[1] = LCA(a1, b1), p[2] = LCA(a1, b2), p[3] = LCA(a2, b1), n   p[4] = LCA(a2, b2); n   sort(p + 1, p + 5, [](int a, int b) { return dep[a] > dep[b]; }); n   int A = p[1], B = p[2]; n   hh = 0, to = B, stk[top = 1] = A, dfs3(A), hh = 0, top = 1, dfs3(A), hh = 0, n   top = 1, dfs3(A); n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1, a, b; i <= m; i++) { n     scanf( %d%d , &a, &b); n     if (a > b) swap(a, b); n     G[a].push_back(b), G[b].push_back(a), e2[++ecnt2] = (edge){a, b, 0}, n                                           mp[pair<int, int>(a, b)] = ecnt2; n   } n   for (int i = 1; i <= n; i++) n     if (!vis[i]) dfs(i, 0); n   for (int i = 1; i <= ecnt2; i++) n     if (!ok[i]) mark(e2[i].from, e2[i].to, i); n   for (int i = 1; i <= n; i++) n     if (!fa[i][0]) { n       dfs2(i, 0); n       if (flg) { n         puts( YES ), work(e2[fir].from, e2[fir].to, e2[sec].from, e2[sec].to); n         return 0; n       } n     } n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n const int P = 1e9 + 7; n template <typename T> n void chkmax(T &x, T y) { n   x = max(x, y); n } n template <typename T> n void chkmin(T &x, T y) { n   x = min(x, y); n } n template <typename T> n void read(T &x) { n   x = 0; n   int f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -f; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   x *= f; n } n template <typename T> n void write(T x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n template <typename T> n void writeln(T x) { n   write(x); n   puts(  ); n } n int n, bit[MAXN], cnt[MAXN], a[MAXN]; n int main() { n   read(n), bit[0] = 1; n   for (int i = 1; i <= n; i++) { n     bit[i] = bit[i - 1] * 2 % P; n     read(a[i]); n     if (a[i] != -1) cnt[a[i]]++; n   } n   int ans = bit[n - 1] - 1; n   for (int i = 1; i <= n; i++) n     if (a[i] == -1) ans = (ans - (bit[cnt[i]] - 1)) % P; n   writeln((ans + P) % P); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long minn; n   int p, min_ind; n   node(long long a = 0, int b = 0, int c = 0) { minn = a, p = b, min_ind = c; } n }; n struct lazy_node { n   long long sv, snx, av, anx; n   lazy_node(long long a = -1, int b = 0, long long c = 0, int d = 0) { n     sv = a, snx = b; n     av = c, anx = d; n   } n }; n const int max_N = 100000 + 10; n const int X = 1e8; n int a[max_N], n; n set<pair<int, int> > s; n set<pair<int, int> >::iterator it, itt; n long long pw42[15]; n node seg[4 * max_N]; n lazy_node lazy[4 * max_N]; n inline int find_pw(long long x) { n   return lower_bound(pw42, pw42 + 12, x) - pw42; n } n inline node merge(int ind) { n   if (seg[2 * ind].minn < seg[2 * ind + 1].minn) return seg[2 * ind]; n   return seg[2 * ind + 1]; n } n inline void split1(int l, int r) { n   it = s.upper_bound(make_pair(l, X)), itt = s.upper_bound(make_pair(r, X)); n   it--, itt--; n   pair<int, int> t = make_pair((it->first), (itt->second)); n   while (it != s.end() && (it->first) <= r) { n     s.erase(it); n     it = s.lower_bound(make_pair(l, X)); n   } n   s.insert(make_pair(l, r)); n   if (l > t.first) s.insert(make_pair(t.first, l - 1)); n   if (r < t.second) s.insert(make_pair(r + 1, t.second)); n } n inline void split2(int l, int r) { n   it = s.upper_bound(make_pair(l, X)); n   itt = s.upper_bound(make_pair(r, X)); n   pair<int, int> t1 = *(--it), t2 = *(--itt); n   s.erase(it); n   if (t1 != t2) { n     itt = s.upper_bound(make_pair(r, X)); n     s.erase(--itt); n   } n   if (l > t1.first) s.insert(make_pair(t1.first, l - 1)); n   if (r < t2.second) s.insert(make_pair(r + 1, t2.second)); n   s.insert(make_pair(l, min(r, t1.second))); n   s.insert(make_pair(max(l, t2.first), r)); n } n void build(int st = 0, int en = n, int ind = 1) { n   if (en - st == 1) { n     int t = find_pw(a[st]); n     seg[ind] = node(pw42[t] - a[st], t, st); n     return; n   } n   int mid = (st + en) / 2; n   build(st, mid, 2 * ind); n   build(mid, en, 2 * ind + 1); n   seg[ind] = merge(ind); n } n inline void shift(int ind) { n   lazy_node t = lazy[ind]; n   lazy[ind] = lazy_node(); n   int i1 = 2 * ind, i2 = 2 * ind + 1; n   if (t.sv != -1) { n     seg[i1] = node(t.sv, t.snx, seg[i1].min_ind); n     seg[i2] = node(t.sv, t.snx, seg[i2].min_ind); n     lazy[i1] = lazy_node(t.sv, t.snx); n     lazy[i2] = lazy_node(t.sv, t.snx); n   } n   seg[i1].minn -= t.av, seg[i2].minn -= t.av; n   seg[i1].p += t.anx, seg[i2].p += t.anx; n   lazy[i1].av += t.av, lazy[i2].av += t.av; n   lazy[i1].anx += t.anx, lazy[i2].anx += t.anx; n } n void modify1(int l, int r, long long val, int nx, int st = 0, int en = n, n              int ind = 1) { n   if (l >= en || r <= st) return; n   if (l <= st && r >= en) { n     seg[ind] = node(val, nx, st); n     lazy[ind] = lazy_node(val, nx); n     return; n   } n   shift(ind); n   int mid = (st + en) / 2; n   modify1(l, r, val, nx, st, mid, 2 * ind); n   modify1(l, r, val, nx, mid, en, 2 * ind + 1); n   seg[ind] = merge(ind); n } n void modify2(int o, int l, int r, long long val, int st = 0, int en = n, n              int ind = 1) { n   if (l >= en || r <= st) return; n   if (l <= st && r >= en) { n     seg[ind].minn -= val, seg[ind].p += o; n     lazy[ind].av += val, lazy[ind].anx += o; n     return; n   } n   shift(ind); n   int mid = (st + en) / 2; n   modify2(o, l, r, val, st, mid, 2 * ind); n   modify2(o, l, r, val, mid, en, 2 * ind + 1); n   seg[ind] = merge(ind); n } n inline void relax() { n   while (seg[1].minn < 0) { n     int x = seg[1].p; n     it = s.upper_bound(make_pair(seg[1].min_ind, X)); n     pair<int, int> t = *(--it); n     modify2(1, t.first, t.second + 1, pw42[x] - pw42[x + 1]); n   } n } n long long calc(int x, int st = 0, int en = n, int ind = 1) { n   if (en - st == 1) return pw42[seg[ind].p] - seg[ind].minn; n   shift(ind); n   int mid = (st + en) / 2; n   if (x < mid) return calc(x, st, mid, 2 * ind); n   return calc(x, mid, en, 2 * ind + 1); n } n int main() { n   int q, l, r, x, t; n   scanf( %d %d , &n, &q); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     s.insert(make_pair(i, i)); n   } n   pw42[0] = 1; n   for (int i = 1; i < 12; i++) pw42[i] = pw42[i - 1] * 42; n   build(); n   while (q--) { n     scanf( %d , &t); n     if (t == 1) { n       scanf( %d , &x); n       printf( %lld n , calc(x - 1)); n     } else { n       scanf( %d %d %d , &l, &r, &x); n       l--; n       if (t == 2) { n         int nx = find_pw(x); n         modify1(l, r, pw42[nx] - x, nx); n         split1(l, r - 1); n       } else { n         split2(l, r - 1); n         do { n           modify2(0, l, r, x); n           relax(); n         } while (!seg[1].minn); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int rain(int n, int *T, int i) { n   int r = 1; n   int d = i + 1, g = i - 1, ex = i; n   while ((g >= 0) && (T[g] <= T[i])) { n     r++; n     i = g; n     g--; n   } n   i = ex; n   while ((d < n) && (T[d] <= T[i])) { n     r++; n     i = d; n     d++; n   } n   return r; n } n int max(int n, int *T) { n   int x; n   x = rain(n, T, 0); n   for (int i = 1; i < n; i++) { n     if (rain(n, T, i) > x) x = rain(n, T, i); n   } n   return x; n } n int main() { n   int *T; n   int n; n   cin >> n; n   T = new int[n]; n   for (int i = 0; i < n; i++) cin >> T[i]; n   cout << max(n, T); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[131100]; n int cal(int l, int r, char t) { n   int cnt = 0; n   for (int i = l; i <= r; i++) { n     if (s[i] != t) cnt++; n   } n   return cnt; n } n int dfs(int l, int r, char t) { n   if (l == r) return cal(l, r, t); n   int ret = 1e9; n   int mid = (l + r) >> 1; n   ret = min(ret, dfs(l, mid, t + 1) + cal(mid + 1, r, t)); n   ret = min(ret, dfs(mid + 1, r, t + 1) + cal(l, mid, t)); n   return ret; n } n int main() { n   int _; n   scanf( %d , &_); n   while (_--) { n     int n; n     scanf( %d , &n); n     scanf( %s , s); n     char temp =  a ; n     printf( %d n , dfs(0, n - 1, temp)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mo = 1e9 + 7; n char s[2010], ss[2010]; n long long dp[2010][2010], a[2010]; n long long m, d, jo; n int len; n long long dfs(int pos, long long sum, bool limit) { n   if (pos == len) return sum == 0; n   if (!limit && dp[pos][sum] != -1) return dp[pos][sum]; n   int up = limit ? a[pos] : 9; n   long long tmp = 0; n   for (int i = 0; i <= up; i++) { n     if (pos & 1) { n       if (i == d) n         tmp = n             (tmp + dfs(pos + 1, (sum * 10 + i) % m, limit && i == a[pos])) % mo; n     } else if (i != d) n       tmp = (tmp + dfs(pos + 1, (sum * 10 + i) % m, limit && i == a[pos])) % mo; n   } n   if (!limit) dp[pos][sum] = tmp; n   return tmp; n } n int solve(char *s) { n   int pos = strlen(s) - 1; n   len = 0; n   while (len <= pos) { n     a[len] = s[len] -  0 ; n     len++; n   } n   long long as = dfs(0, 0, true); n   return as; n } n int main() { n   int le, ri; n   while (scanf( %lld%lld , &m, &d) != EOF) { n     memset(dp, -1, sizeof(dp)); n     scanf( %s%s , s, ss); n     int l = strlen(s); n     long long spc = 1, sm = 0; n     for (int i = 0; i < l; i++) { n       if ((i % 2 == 0) && ((s[i] & 15) == d)) { n         spc = 0; n         break; n       } else if ((i & 1) && ((s[i] & 15) != d)) { n         spc = 0; n         break; n       } n       sm = (sm * 10 + (s[i] & 15)) % m; n     } n     if (spc) spc = (sm == 0); n     printf( %lld n , (solve(ss) - solve(s) + spc + mo) % mo); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n long long M; n int A[200002], B[200002]; n map<int, int> MP; n vector<pair<long long, long long> > ST; n long long getover(pair<long long, long long> p, int i2) { n   if (p.second >= ST[i2].second) return 0; n   return (ST[i2].second - p.second) / (p.first - ST[i2].first) + n          ((ST[i2].second - p.second) % (p.first - ST[i2].first) != 0); n } n long long getover(int i1, int i2) { n   if (ST[i1].second >= ST[i2].second) return 0; n   return (ST[i2].second - ST[i1].second) / (ST[i1].first - ST[i2].first) + n          ((ST[i2].second - ST[i1].second) % (ST[i1].first - ST[i2].first) != 0); n } n int main() { n   cin.sync_with_stdio(false); n   cin >> N >> M; n   int bestinit = 0; n   for (int i = 1; i <= N; ++i) { n     cin >> A[i] >> B[i]; n     if (B[i] == 0) bestinit = max(bestinit, A[i]); n     if (MP.find(A[i]) == MP.end()) MP[A[i]] = 0x3f3f3f3f; n     MP[A[i]] = min(MP[A[i]], B[i]); n   } n   ST.push_back(make_pair(bestinit, 0)); n   for (map<int, int>::iterator it = MP.begin(); it != MP.end(); ++it) { n     if (it->first <= bestinit) continue; n     int step = (1 << 17), now = 0; n     for (; step; step >>= 1) n       if (now + step < int(ST.size()) && n           1LL * ST[now + step - 1].first * n                       (getover(now + step, now + step - 1) - 1) + n                   ST[now + step - 1].second < n               it->second) n         now += step; n     step = (1 << 30); n     int pos = 0; n     for (; step; step >>= 1) n       if (ST[now].first * (pos + step - 1) + ST[now].second < it->second) n         pos += step; n     int rem = ST[now].first * pos + ST[now].second - it->second; n     pair<long long, long long> pnow = n         make_pair(it->first, rem - 1LL * it->first * pos); n     while (ST.size() >= 2 && getover(pnow, ST.size() - 1) <= n                                  getover(ST.size() - 1, ST.size() - 2)) n       ST.pop_back(); n     ST.push_back(pnow); n   } n   int step = (1 << 17), now = 0; n   for (; step; step >>= 1) n     if (now + step < int(ST.size()) && n         1LL * ST[now + step - 1].first * n                     (getover(now + step, now + step - 1) - 1) + n                 ST[now + step - 1].second < n             M) n       now += step; n   long long times = 100000000 + M / ST.back().first; n   long long astep = 1; n   while (astep <= times) astep *= 2; n   long long pos = 0; n   for (; astep; astep >>= 1) n     if (ST[now].first * (pos + astep - 1) + ST[now].second < M) pos += astep; n   cout << pos <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int b[200010]; n int main() { n   long long n; n   cin >> n; n   for (int i = 0; i < n; i++) scanf( %d , &b[i]); n   sort(b, b + n); n   int m = b[n - 1] - b[0]; n   int m1 = b[n - 1], m2 = b[0]; n   long long c1 = 0, c2 = 0; n   for (int i = 0; i < n; i++) { n     if (b[i] == m1) c1++; n     if (b[i] == m2) c2++; n   } n   printf( %d  , m); n   if (m1 == m2) n     cout << n * (n - 1) / 2 << endl; n   else n     cout << c1 * c2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int binomialCoeff(long long int n, long long int k) { n   long long int C[n + 1][k + 1]; n   long long int i, j; n   for (i = 0; i <= n; i++) { n     for (j = 0; j <= min(i, k); j++) { n       if (j == 0 || j == i) n         C[i][j] = 1; n       else n         C[i][j] = ((C[i - 1][j - 1]) % 998244353 + (C[i - 1][j]) % 998244353) % n                   998244353; n     } n   } n   return C[n][k]; n } n long long int digsum(long long int a) { n   long long int sum = 0; n   while (a > 0) { n     sum += a % 10; n     a = a / 10; n   } n   return sum; n } n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n int fact(int a) { n   if (a == 1) n     return a; n   else n     return a * fact(a - 1); n } n int max3(int a, int b, int c) { return max(a, max(b, c)); } n int main() { n   int q; n   cin >> q; n   while (q--) { n     int n; n     cin >> n; n     int temp; n     int each = 0; n     for (long long int i = 1; i <= n; i++) { n       cin >> temp; n       each += temp; n     } n     cout << (int)(ceil((double)(each) / (double)(n))) << endl; n   } n   return 0; n } n


#include<bits/stdc++.h> n #define ll long long n #define ld long double n #define pb push_back n #define x first n #define y second n #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); n using namespace std; n  n //modulo op n  n const ll mod = 1e9 + 7; n  n ll add(ll a, ll b) { n  return (a + b) % mod; n } n  n ll sub(ll a, ll b) { n  return ((a - b) % mod + mod) % mod; n } n  n ll mul(ll a, ll b) { n  return (a * b) % mod; n } n  n ll normalize(ll a) { n  return (a % mod + mod) % mod; n } n //end of modulo op n ll power(ll a, ll b) { n  if (b == 0) n   return 1; n  ll val = power(a, b / 2); n  val = mul(val, val); n  if (b & 1) n   val = mul(val, a); n  return val; n } n  n const int maxn = 2e5 + 7; n ll fact[maxn], ifact[maxn]; n  n void precalc() { n  fact[0] = 1; n  ifact[0] = 1; n  for (int i = 1; i < maxn; i++) { n   fact[i] = mul(i, fact[i - 1]); n   ifact[i] = power(fact[i], mod - 2); n  } n } n  n ll ncr(ll n, ll r) { n  return mul(fact[n], mul(ifact[n - r], ifact[r])); n } n  n  n void solve() { n  ll n, l, r; n  cin >> n >> l >> r; n  ll double_op_limit = min(1 - l, r - n); n  ll ans = mul(add(ncr(n, n / 2), n & 1 == 1 ? ncr(n, n / 2 + 1) : 0), double_op_limit); n  // cout << double_op_limit <<     << ans << endl; n  for (ll i = double_op_limit + 1; i <= double_op_limit + n; i++) { n   ll left_fixed = max(l + i - 1, 0LL); n   ll right_fixed = n - min(n, r - i); n   // cout << i <<     << left_fixed <<     << right_fixed << endl; n   if (left_fixed > (n + 1) / 2 || right_fixed > (n + 1) / 2) n    break; n   ll rem = n - left_fixed - right_fixed; n   if (rem < 0) n    break; n   if (left_fixed == (n + 1) / 2) { n    ans = add(ans, 1); n    break; n   } n   ans = add(ans, ncr(rem, n / 2 - left_fixed)); n   if (n & 1) n    ans = add(ans, ncr(rem, n / 2 + 1 - left_fixed)); n   // cout << ans << endl; n  } n  cout << ans; n } n  n int main() n { n  fastread; n  precalc(); n  int t; n  cin >> t; n  while (t--) { n   solve(); n   cout <<   n ; n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n __attribute__((constructor)) void Init() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; n } n constexpr int N = 5e3; n char A[N + 2], B[N + 2]; n int16_t dp[2][N + 1]; n int main() { n   int n, m, t = 0, ans = 0; n   cin >> n >> m >> &A[1] >> &B[1]; n   for (int i = 1; i <= n; ++i, t = 1 - t) { n     for (int j = 1; j <= m; ++j) { n       int s = dp[1 - t][j - 1] + 4 * (A[i] == B[j]) - 2; n       dp[t][j] = max(0, max(s, max(dp[t][j - 1], dp[1 - t][j]) - 1)); n       ; n       ans = max<int>(ans, dp[t][j]); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   cin.tie(nullptr)->sync_with_stdio(false); n   long long _; n   for (cin >> _; _--;) { n     long long n, m, k; n     cin >> n >> m >> k; n     long long mn = (n % 2 == 1 ? m / 2 : 0); n     long long mx = n * m / 2 - (m % 2 == 1 ? n / 2 : 0); n     if (mn <= k and k <= mx and (k - mn) % 2 == 0) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000007; n const long long INF2 = 1000000000000000007; n const int MOD = 774254531; n const int MOD1 = 892237699; n const int SIZE = 150010; n const double eps = 1e-6; n long long n, m; n long long ar[1010][1010], res; n string st, b, minn; n long long gcd(long long a, long long b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       cin >> ar[i][j]; n     } n   } n   res = sqrt(ar[0][1] * ar[0][2] / ar[1][2]); n   cout << res <<    ; n   for (int i = 1; i < n; ++i) { n     cout << ar[0][i] / res <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 5; n string name[maxn], s; n vector<int> G[maxn]; n int tot, a[maxn], maxd, dep[maxn]; n int dfs(int &p, int d) { n   maxd = max(maxd, d); n   int ret = ++tot; n   dep[ret] = d; n   while (s[p] !=  , ) { n     name[ret].push_back(s[p++]); n   } n   ++p; n   int son = 0; n   while (s[p] !=  , ) { n     son = son * 10 + s[p++] -  0 ; n   } n   ++p; n   for (int i = 0; i < son; ++i) G[ret].push_back(dfs(p, d + 1)); n   return ret; n } n void bfs() { n   queue<int> que; n   cout << maxd; n   int t = 0; n   for (int i = 0; i < G[0].size(); ++i) que.push(G[0][i]); n   while (!que.empty()) { n     int p = que.front(); n     que.pop(); n     if (dep[p] != t) { n       ++t; n       cout << endl; n     } else n       cout <<    ; n     cout << name[p]; n     for (int i = 0; i < G[p].size(); ++i) que.push(G[p][i]); n   } n   cout << endl; n } n int main() { n   cin >> s; n   s.push_back( , ); n   maxd = 0; n   int p = 0; n   while (p < s.size()) G[0].push_back(dfs(p, 1)); n   bfs(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double C = 1e6; n struct cir { n   int x, y, z; n } a[5]; n int disf(cir x, cir y) { n   return (x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y); n } n bool kcr(cir x, cir y) { n   return disf(x, y) <= (x.z + y.z) * (x.z + y.z) && n          disf(x, y) >= (x.z - y.z) * (x.z - y.z); n } n bool cr(cir x, cir y) { n   return disf(x, y) < (x.z + y.z) * (x.z + y.z) && n          disf(x, y) > (x.z - y.z) * (x.z - y.z); n } n bool in(long double x, long double y, cir _) { n   return (_.x - x) * (_.x - x) + (_.y - y) * (_.y - y) < _.z * _.z; n } n pair<pair<long double, long double>, pair<long double, long double> > check( n     int i, int j) { n   bool flag = 0; n   if (a[i].y == a[j].y) flag = 1, swap(a[i].x, a[i].y), swap(a[j].x, a[j].y); n   long double k = 1. * (a[i].x - a[j].x) / (a[j].y - a[i].y); n   long double g = (a[i].z * a[i].z - a[j].z * a[j].z - a[i].x * a[i].x + n                    a[j].x * a[j].x - a[i].y * a[i].y + a[j].y * a[j].y) / n                   (2. * (a[j].y - a[i].y)); n   long double aa = k * k + 1; n   long double bb = 2 * ((g - a[i].y) * k - a[i].x); n   long double cc = n       a[i].x * a[i].x + (g - a[i].y) * (g - a[i].y) - a[i].z * a[i].z; n   long double x1 = n       (-bb - sqrt(max(bb * bb - 4 * aa * cc, (long double)0))) / (2 * aa); n   long double x2 = n       (-bb + sqrt(max(bb * bb - 4 * aa * cc, (long double)0))) / (2 * aa); n   long double y1 = k * x1 + g; n   long double y2 = k * x2 + g; n   if (flag) n     swap(x1, y1), swap(x2, y2), swap(a[i].x, a[i].y), swap(a[j].x, a[j].y); n   x1 = (round(x1 * C)) / C; n   x2 = (round(x2 * C)) / C; n   y1 = (round(y1 * C)) / C; n   y2 = (round(y2 * C)) / C; n   return pair<pair<long double, long double>, pair<long double, long double> >( n       pair<long double, long double>(x1, y1), n       pair<long double, long double>(x2, y2)); n } n int main() { n   int n; n   cin >> n; n   if (n == 1) n     return cout << 2, 0; n   else if (n == 2) { n     for (int i = 1; i <= 2; ++i) cin >> a[i].x >> a[i].y >> a[i].z; n     if (cr(a[1], a[2])) n       return cout << 4, 0; n     else n       return cout << 3, 0; n   } n   for (int i = 1; i <= 3; ++i) cin >> a[i].x >> a[i].y >> a[i].z; n   set<pair<long double, long double> > g[5]; n   int c = 3; n   for (int i = 1; i <= 3; ++i) n     for (int j = i + 1; j <= 3; ++j) n       if (kcr(a[i], a[j])) { n         pair<pair<long double, long double>, pair<long double, long double> > n             t = check(i, j); n         g[0].insert(t.first); n         g[0].insert(t.second); n         g[i].insert(t.first); n         g[i].insert(t.second); n         g[j].insert(t.first); n         g[j].insert(t.second); n         if (c > 1) --c; n       } n   int e = 0, v = g[0].size() + 6; n   for (int i = 1; i <= 3; ++i) e += g[i].size() + 2; n   cout << e - v + c + 1; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int arr[n]; n   int ar[m]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   for (int j = 0; j < m; j++) { n     cin >> ar[j]; n   } n   for (int k = 0; k < n; k++) { n     for (int l = 0; l < m; l++) { n       if (ar[l] == arr[k]) { n         cout << arr[k] <<    ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(0); n   long long n, h, k; n   cin >> n >> h >> k; n   vector<long long> mas(n); n   for (int i = 0; i < n; i++) cin >> mas[i]; n   long long time = 0, currVolume = 0; n   bool have = false; n   for (int i = 0; i < n; i++) { n     long long top = mas[i]; n     if (currVolume + top <= h) n       currVolume += top; n     else { n       time += (currVolume / k); n       if (currVolume < k) { n         ++time; n         currVolume = 0; n       } n       currVolume = currVolume % k; n       if (currVolume + top <= h) { n         currVolume += top; n       } else { n         ++time; n         currVolume = top; n       } n     } n   } n   if (currVolume % k != 0) ++time; n   time += currVolume / k; n   cout << time; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n char s[200010], p[200010]; n int a[200010], n, t; n bool ok(int len) { n   int i = 1, j = 1; n   while (i <= n) { n     if (a[i] <= len) { n       i++; n       continue; n     } n     if (s[i] == p[j]) { n       i++; n       j++; n     } else { n       i++; n     } n     if (j == t + 1) return true; n   } n   return false; n } n int main() { n   scanf( %s , &s[1]); n   n = strlen(s + 1); n   scanf( %s , &p[1]); n   t = strlen(p + 1); n   int l = 0, r = n, ans; n   for (int i = 1; i <= n; i++) { n     int b; n     scanf( %d , &b); n     a[b] = i; n   } n   while (l + 1 < r) { n     int m = (l + r) >> 1; n     if (ok(m)) { n       l = m; n     } else { n       r = m; n     } n   } n   printf( %d n , l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, p =    ; n   cin >> s; n   int i, j = 0, f = 0, start, end; n   for (i = s.size() - 1; i >= 0 && f == 0; i--) { n     if (s[i] !=  0 ) { n       end = i; n       f = 1; n     } n   } n   f = 0; n   for (i = 0; i < s.size() && f == 0; i++) { n     if (s[i] !=  0 ) { n       start = i; n       f = 1; n     } n   } n   j = 0; n   for (i = end; i >= start; i--) { n     p[j] = s[i]; n     j++; n   } n   j = 0; n   f = 0; n   for (i = start; i <= end && f == 0; i++) { n     if (p[j] != s[i]) n       f = 1; n     else n       j++; n   } n   if (f) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 15; n map<pair<int, int>, int> H; n int t[N]; n vector<int> adj[N]; n int sum[N]; n void update(int x, int add) { n   if (x == 0) return; n   while (x < N) sum[x] += add, x += x & (-x); n } n int q(int x) { n   int ret = 0; n   while (x) ret += sum[x], x = x & (x - 1); n   return ret; n } n int main() { n   int n, i, p, x, y, tot, j; n   scanf( %d%d , &n, &p); n   for (i = 0; i < n; ++i) { n     scanf( %d%d , &x, &y); n     if (x > y) swap(x, y); n     ++t[x], ++t[y]; n     if (!H.count(make_pair(x, y))) adj[x].push_back(y); n     ++H[make_pair(x, y)]; n   } n   long long ret = 0; n   for (i = 1; i <= n; ++i) update(t[i], 1); n   for (i = 1; i <= n; ++i) { n     update(t[i], -1); n     if (t[i] >= p) n       ret += n - i; n     else { n       tot = q(n) - q(p - t[i] - 1); n       ret += tot; n       for (j = 0; j < adj[i].size(); ++j) { n         x = adj[i][j]; n         if (t[i] + t[x] < p) continue; n         y = H[make_pair(i, x)]; n         if (t[x] + t[i] - y < p) --ret; n       } n     } n   } n   cout << ret << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int ans[100100]; n struct by { n   int l, r, id, i, num; n } a[100100 * 2]; n bool cmp(by a, by b) { n   if (a.r != b.r) return a.r < b.r; n   return a.id < b.id; n } n struct byy { n   int i, l; n   byy() {} n   byy(int i, int l) : i(i), l(l) {} n   bool operator<(const byy &rhs) const { n     if (l != rhs.l) return l < rhs.l; n     return i < rhs.i; n   } n }; n set<byy> s; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &a[i].l, &a[i].r); n     a[i].i = i; n     a[i].id = 0; n   } n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &a[i + n].l, &a[i + n].r, &a[i + n].num); n     a[i + n].i = i; n     a[i + n].id = 1; n   } n   sort(a + 1, a + m + n + 1, cmp); n   int cnt = 0; n   for (int i = 1; i <= m + n; i++) { n     if (!a[i].id) n       s.insert(byy(a[i].i, a[i].l)); n     else { n       while (s.size() && a[i].num--) { n         set<byy>::iterator p = s.lower_bound(byy(0, a[i].l)); n         if (p == s.end()) break; n         byy now = *p; n         s.erase(p); n         ans[now.i] = a[i].i; n         cnt++; n       } n     } n   } n   if (cnt == n) { n     printf( YES n ); n     for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n     printf(  n ); n   } else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 2 * acos(0); n unsigned long long int binpow(unsigned long long int b, n                               unsigned long long int n) { n   if (n == 0) return 1; n   if (n == 1) return b; n   if (n & 1) n     return binpow(b, n - 1) * b; n   else n     return binpow(b * b, n / 2); n } n long long int bigmod(long long int b, long long int n, long long int m) { n   if (n == 0) return 1; n   if (n % 2 == 0) { n     long long int x = bigmod(b, n / 2, m) % m; n     return (x * x) % m; n   } else n     return ((b % m) * bigmod(b, n - 1, m) % m) % m; n } n void start() {} n long long int to_num(string &s) { n   stringstream second; n   second << s; n   long long int n; n   second >> n; n   return n; n } n long long int get(long long int n) { n   long long int s = 0; n   while (n) { n     s += (n % 10); n     n /= 10; n   } n   return s; n } n void solve() { n   long long int n, cn = 0; n   cin >> n; n   string s = to_string(n), tmp =   ; n   for (long long int i = 0; i < s.size() - 1; i++) { n     tmp +=  9 ; n   } n   if (n < 10) { n     cout << n <<   n ; n     return; n   } n   cn = (s.size() - 1) * 9; n   long long int left = n - to_num(tmp); n   cn += get(left); n   cout << cn <<   n ; n } n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   start(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 1; n const long long INF = 1e9 + 7; n const long long inf = 1e18; n vector<long long> adj[N]; n long long vis[N]; n long long ans[N]; n long long ct; n void dfs(long long node) { n   vis[node] = ct; n   ans[ct]++; n   for (auto it : adj[node]) { n     if (!vis[it]) { n       dfs(it); n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   for (long long i = 0; i < m; i++) { n     long long x; n     cin >> x; n     long long count = 0, temp; n     while (x--) { n       long long a; n       cin >> a; n       if (count == 0) { n         temp = a; n       } n       if (count > 0) { n         adj[temp].push_back(a); n         adj[a].push_back(temp); n         temp = a; n       } n       count++; n     } n     count = 0; n   } n   for (long long i = 1; i <= n; i++) { n     if (!vis[i]) { n       ct++; n       dfs(i); n     } n     cout << ans[vis[i]] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 30; n const int maxn = 100007; n int n, m, T; n int top, k[10004], ans[maxn]; n struct student { n   int t, x, i; n   void get(int l) { n     scanf( %d%d , &t, &x); n     i = l; n   } n   bool operator<(const student &b) const { n     if (t == b.t) return x < b.x; n     return t < b.t; n   } n } s[maxn], bus[maxn]; n inline bool cmp(const student &a, const student &b) { return a.x < b.x; } n void geton(int &st) { n   top = 0; n   memset(k, 0, sizeof(k)); n   for (int rest = m; st <= n && rest; st++, rest--) { n     bus[++top] = s[st]; n     k[s[st].x]++; n     if (s[st].t > T) T = s[st].t; n   } n } n void getoff() { n   int t1 = 0, t2 = 0; n   sort(bus + 1, bus + top + 1, cmp); n   for (int i = 1; i <= top; i++) { n     if (bus[i].x != bus[i - 1].x) { n       T += t1; n       t1 = k[bus[i].x] / 2 + 1; n     } n     ans[bus[i].i] = bus[i].x + T; n   } n   T += bus[top].x * 2 + t1; n } n int main() { n   int st = 1, ti; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) s[i].get(i); n   sort(s + 1, s + n + 1); n   while (st <= n) { n     geton(st); n     getoff(); n   } n   for (int i = 1; i <= n - 1; i++) printf( %d  , ans[i]); n   printf( %d n , ans[n]); n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n inline long long read() { n   char c = getchar(); n   long long x = 0; n   bool f = 0; n   for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   if (f) x = -x; n   return x; n } n long long res, n, m, k; n vector<pair<long long, long long> > e[200005]; n vector<long long> v[13]; n const long long b1 = 19491001; n unsigned long long pw[200005], sumn, sum[13][13], qwq; n void dfs(long long u) { n   if (u == k + 1) { n     res += (qwq == sumn); n     return; n   } n   for (register long long i = (0); i <= (u - 1); ++i) { n     qwq += sum[u][i]; n     dfs(u + 1); n     qwq -= sum[u][i]; n   } n } n signed main() { n   n = read(), m = read(), k = read(); n   pw[0] = 1; n   for (register long long i = (1); i <= (n); ++i) n     pw[i] = pw[i - 1] * b1, sumn += pw[i]; n   for (register long long i = (1); i <= (m); ++i) { n     long long u = read(), v = read(), w = read(); n     e[u].push_back(make_pair(w, v)); n   } n   for (register long long i = (1); i <= (n); ++i) n     sort(e[i].begin(), e[i].end()), v[e[i].size()].push_back(i); n   for (register long long i = (1); i <= (k); ++i) n     for (register long long j = (0); j <= (i - 1); ++j) { n       unsigned long long now = 0; n       for (long long p = 0; p < v[i].size(); ++p) n         now += pw[e[v[i][p]][j].second]; n       sum[i][j] = now; n     } n   dfs(1); n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const long long MAX = 1e9 + 7; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int a[n]; n   set<int> s; n   for (int i = 0; i < n; i++) s.insert(i + 1); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i]) s.erase(a[i]); n   } n   int prev = -1; n   for (int i = 0; i < n; i++) { n     if (a[i] == 0) { n       auto it = s.begin(); n       while (it != s.end() && *it == (i + 1)) it++; n       if (it == s.end()) { n         it = s.begin(); n         a[i] = a[prev]; n         a[prev] = *it; n       } else { n         a[i] = *it; n         s.erase(it); n         prev = i; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     cout << a[i] <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int box[300010]; n bool check(int times) { n   int mi = 0; n   for (int i = 0; i < n; ++i) { n     if (box[i] + times < m) { n       if (mi > box[i] + times) return false; n       mi = max(mi, box[i]); n     } else { n       if (mi >= box[i]) n         continue; n       else if (box[i] + times - m >= mi) n         continue; n       else n         mi = box[i]; n     } n   } n   return true; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &box[i]); n   } n   int l = 0, r = m, mid, ans = -1; n   while (l <= r) { n     mid = (l + r) / 2; n     if (check(mid)) { n       ans = mid; n       r = mid - 1; n     } else { n       l = mid + 1; n     } n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   for (int i = 0; i < q; i++) { n     int n; n     cin >> n; n     int ans = 0; n     int ct_4 = n / 4; n     int rem = n % 4; n     if (rem == 1) { n       ct_4 -= 2; n       ans = ct_4 + 1; n     } else if (rem == 2) { n       ct_4 -= 1; n       ans = ct_4 + 1; n     } else if (rem == 3) { n       ct_4 -= 3; n       ans = ct_4 + 2; n     } else { n       ans = ct_4; n     } n     if (ct_4 < 0) { n       cout << -1 << endl; n     } else { n       cout << ans << endl; n     } n   } n   return 0; n } n