#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,fast-math ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n using i32 = int; n using i64 = long long; n using u8 = unsigned char; n using u32 = unsigned; n using u64 = unsigned long long; n using f64 = double; n using f80 = long double; n long long power(long long a, long long b, long long p) { n   if (!b) return 1; n   long long t = power(a, b / 2, p); n   t = t * t % p; n   if (b & 1) t = t * a % p; n   return t; n } n long long exgcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   long long px, py; n   long long d = exgcd(b, a % b, px, py); n   x = py; n   y = px - a / b * py; n   return d; n } n template <class T> n inline void freshmin(T &a, const T &b) { n   if (a > b) a = b; n } n template <class T> n inline void freshmax(T &a, const T &b) { n   if (a < b) a = b; n } n namespace io { n const int BUFSIZE = 1 << 20; n int isize, osize; n char ibuf[BUFSIZE + 10], obuf[BUFSIZE + 10]; n char *is, *it, *os = obuf, *ot = obuf + BUFSIZE; n char getchar() { n   if (is == it) { n     is = ibuf; n     it = ibuf + fread(ibuf, 1, BUFSIZE, stdin); n     if (is == it) return EOF; n   } n   return *is++; n } n char getalpha() { n   char c = getchar(); n   while (!isalpha(c)) c = getchar(); n   return c; n } n void putchar(char c) { n   *os++ = c; n   if (os == ot) { n     fwrite(obuf, 1, BUFSIZE, stdout); n     os = obuf; n   } n } n int inp() { n   int x = 0, f = 0; n   char ch; n   for (ch = getchar(); !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = 1; n   for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar()) n     ; n   return f ? -x : x; n } n long long inp_ll() { n   long long x = 0; n   int f = 0; n   char ch; n   for (ch = getchar(); !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = 1; n   for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar()) n     ; n   return f ? -x : x; n } n template <class T> n bool read(T &x) { n   x = 0; n   char ch = getchar(); n   if (ch == EOF) return 0; n   for (; !isdigit(ch);) { n     ch = getchar(); n     if (ch == EOF) return 0; n   } n   for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar()) n     ; n   return 1; n } n template <class T> n void write(T x) { n   static char s[22]; n   static char *it = s + 20; n   static char *end = s + 20; n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   do { n     *--it = x % 10 +  0 ; n     x /= 10; n   } while (x); n   for (; it < end; ++it) putchar(*it); n } n template <> n void write(const char *s) { n   for (; *s; ++s) putchar(*s); n } n template <> n void write(char c) { n   putchar(c); n } n template <class T, class V> n void write(T x, V y) { n   write(x); n   write(y); n } n template <class T> n void writeln(T x) { n   write(x); n   putchar(  n ); n } n struct ender { n   ~ender() { n     if (os != obuf) fwrite(obuf, 1, os - obuf, stdout); n   } n } __ender; n }  // namespace io n template <class T> n void print(const T &a) { n   for (auto x : a) printf( %d  , x); n   puts(  ); n } n const int MAXN = 1 << 18; n const int MAXK = 17; n const int INF = 1000000010; n using namespace io; n using tiii = tuple<int, int, int>; n int n, m; n vector<pair<int, int> > v[MAXN]; n vector<tiii> e; n int pre[MAXN], weight[MAXN], dis[MAXN]; n void dfs(int x) { n   for (auto p : v[x]) { n     int y = p.first, z = p.second; n     if (y == pre[x]) continue; n     pre[y] = x; n     weight[y] = z; n     dis[y] = dis[x] + 1; n     dfs(y); n   } n } n int F[MAXN]; n int father(int x) { return F[x] == x ? x : F[x] = father(F[x]); } n const int K = 2; n const int mods[] = {1000000007, 998244353, 1000000009}; n void FWT(int a[], int n, int mod) { n   int MOD = mod; n   for (int d = 1; d < n; d <<= 1) n     for (int m = d << 1, i = 0; i < n; i += m) n       for (int j = 0; j < d; j++) { n         long long x = a[i + j], y = a[i + j + d]; n         a[i + j] = (x + y) % MOD; n         a[i + j + d] = (x - y + MOD) % MOD; n       } n } n void IFWT(int a[], int n, int mod) { n   int MOD = mod; n   int inv = (mod + 1) / 2; n   for (int d = 1; d < n; d <<= 1) n     for (int m = d << 1, i = 0; i < n; i += m) n       for (int j = 0; j < d; j++) { n         long long x = a[i + j], y = a[i + j + d]; n         a[i + j] = (x + y) % MOD; n         a[i + j + d] = (x - y + MOD) % MOD; n         a[i + j] = (long long)a[i + j] * inv % MOD; n         a[i + j + d] = (long long)a[i + j + d] * inv % MOD; n       } n } n int a[K][MAXN]; n int b[MAXN]; n void solve() { n   n = inp(); n   m = inp(); n   int sum = 0; n   for (int i = 1; i <= n; ++i) F[i] = i; n   for (int i = 1; i <= m; ++i) { n     int x = inp(), y = inp(), z = inp(); n     sum ^= z; n     int fx = father(x), fy = father(y); n     if (fx == fy) { n       e.push_back(tiii{x, y, z}); n     } else { n       F[fx] = fy; n       v[x].push_back({y, z}); n       v[y].push_back({x, z}); n     } n   } n   dfs(1); n   for (int k = 0; k < K; ++k) { n     a[k][sum] = 1; n     FWT(a[k], 1 << 17, mods[k]); n   } n   for (auto p : e) { n     int x, y, z; n     tie(x, y, z) = p; n     vector<int> w(1, z); n     while (x != y) { n       if (dis[x] < dis[y]) swap(x, y); n       w.push_back(weight[x]); n       x = pre[x]; n     } n     for (int k = 0; k < K; ++k) { n       for (int i = 0; i < 1 << 17; ++i) b[i] = 0; n       for (auto x : w) b[x]++; n       FWT(b, 1 << 17, mods[k]); n       for (int i = 0; i < 1 << 17; ++i) a[k][i] = (u64)a[k][i] * b[i] % mods[k]; n     } n   } n   for (int k = 0; k < K; ++k) { n     IFWT(a[k], 1 << 17, mods[k]); n   } n   for (int i = 0; i < 1 << 17; ++i) n     if (a[0][i] || a[1][i]) { n       printf( %d %d n , i, a[0][i]); n       break; n     } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int UNDEF = -1; n const long long INF = 1e18; n template <typename T> n inline bool chkmax(T &aa, T bb) { n   return aa < bb ? aa = bb, true : false; n } n template <typename T> n inline bool chkmin(T &aa, T bb) { n   return aa > bb ? aa = bb, true : false; n } n const int mn = 1e6 + 4; n const int MAXFACT = mn; n int fact[MAXFACT + 1], invfact[MAXFACT + 1]; n int mod_pow(int a, int n) { n   const int mod = MOD; n   int ret = 1; n   int p = a % mod; n   while (n) { n     if (n & 1) ret = (ret * (long long)p) % mod; n     p = (p * (long long)p) % mod; n     n >>= 1; n   } n   return ret; n } n inline int mod_inv(int a) { return mod_pow(a, MOD - 2); } n inline int add(int a, int b) { n   int res = a + b; n   if (res >= MOD) res -= MOD; n   return res; n } n inline int mul(int a, int b) { return (a * (long long)b) % MOD; } n int fast_max(vector<int> a, int k) { n   int n = a.size(); n   int ans = 0; n   int offset = 0; n   for (int i = 0; i < n; ++i) n     if (ans < a[i]) { n       ans = a[i]; n       offset = 0; n     } else { n       offset = offset + 1; n       if (offset == k) return ans; n     } n   return ans; n } n bool isgood(vector<int> a, int k) { n   int n = a.size(); n   int ans = 0; n   int offset = 0; n   for (int i = 0; i < n; ++i) n     if (ans < a[i]) { n       ans = a[i]; n       offset = 0; n     } else { n       offset = offset + 1; n       if (offset == k) return false; n     } n   return true; n } n int bf(int n, int k) { n   vector<int> v; n   for (int x = 1; x <= n; x++) v.push_back(x); n   int ans = 0; n   do { n     if (isgood(v, k)) ans++; n   } while (next_permutation(v.begin(), v.end())); n   return ans; n } n int g1[mn]; n int g[mn]; n int makeg(int lim, int k) { n   for (int n = 0; n <= lim; n++) { n     int gn; n     if (n == 0) n       gn = 1; n     else { n       int sum1 = (n - k - 1 >= 0) ? g1[n - k - 1] : 0; n       int sum3 = 1 + (MOD - sum1); n       gn = mul(fact[n], sum3); n     } n     g[n] = gn; n     g1[n] = n         add(n > 0 ? g1[n - 1] : 0, mul(gn, mod_inv(mul(n + k + 1, fact[n])))); n   } n   return g[lim]; n } n void init() { n   int got = 1; n   for (int x = 0; x <= MAXFACT; x++) { n     fact[x] = got; n     got = mul(got, x + 1); n   } n   got = mod_pow(got, MOD - 2); n   for (int x = MAXFACT; x >= 0; x--) { n     got = mul(got, x + 1); n     invfact[x] = got; n   } n } n int binom(int n, int k) { n   if (n < k) return 0; n   if (n < 0 || k < 0) return 0; n   return mul(fact[n], mul(invfact[k], invfact[n - k])); n } n int solve(int n, int k) { n   makeg(n, k); n   int final = 0; n   for (int x = 0; x <= n - (k + 2); x++) { n     int ans = mul(mul(binom(n - 1, x + k + 1), binom(x + k, x)), g[x]); n     int ans2 = mul(ans, mul(fact[k], fact[n - (x + k + 1)])); n     final += ans2; n     if (final >= MOD) final -= MOD; n   } n   return final; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   init(); n   int n, k; n   scanf( %d%d , &n, &k); n   int ans = solve(n, k); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n long long int spf[100001]; n void sieve(); n set<long long int> factors(long long int x); n void getZarr(string str, long long int Z[]); n int n; n vector<int> ans; n vector<bool> vis; n vector<int> mas; n vector<int> del; n vector<int> koll; n vector<vector<int>> edges; n int nod(int a, int b) { n   if (b == 0) return a; n   return nod(b, a % b); n } n void dfs1(int v) { n   vis[v] = 1; n   for (auto u : edges[v]) n     if (!vis[u]) { n       ans[u] = nod(ans[v], mas[u]); n       dfs1(u); n     } n } n void dfs2(int v, int dist) { n   vis[v] = 1; n   for (int i = 0; i < del.size(); i++) { n     koll[i] += (mas[v] % del[i] == 0); n     if (koll[i] >= dist) ans[v] = max(ans[v], del[i]); n   } n   for (auto u : edges[v]) n     if (!vis[u]) dfs2(u, dist + 1); n   for (int i = 0; i < del.size(); i++) koll[i] -= (mas[v] % del[i] == 0); n } n signed main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   ans.resize(n); n   vis.resize(n); n   mas.resize(n); n   edges.resize(n); n   for (int i = 0; i < n; i++) cin >> mas[i]; n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     edges[a].push_back(b); n     edges[b].push_back(a); n   } n   int p = mas[0]; n   mas[0] = 0; n   ans[0] = 0; n   dfs1(0); n   mas[0] = p; n   for (int i = 0; i < n; i++) vis[i] = 0; n   for (int i = 1; i * i <= mas[0]; i++) { n     if (mas[0] % i == 0) { n       del.push_back(i); n       del.push_back(mas[0] / i); n       if (i * i == mas[0]) del.pop_back(); n     } n   } n   sort(del.begin(), del.end()); n   koll.resize(del.size()); n   dfs2(0, 0); n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n   return 0; n } n void sieve() { n   spf[1] = 1; n   for (long long int i = 2; i < 100001; i++) spf[i] = i; n   for (long long int i = 4; i < 100001; i += 2) spf[i] = 2; n   for (long long int i = 3; i * i < 100001; i++) { n     if (spf[i] == i) { n       for (long long int j = i * i; j < 100001; j += i) n         if (spf[j] == j) spf[j] = i; n     } n   } n } n void getZarr(string str, long long int Z[]) { n   long long int n = str.length(); n   long long int L, R, k; n   L = R = 0; n   for (long long int i = 1; i < n; ++i) { n     if (i > R) { n       L = R = i; n       while (R < n && str[R - L] == str[R]) R++; n       Z[i] = R - L; n       R--; n     } else { n       k = i - L; n       if (Z[k] < R - i + 1) n         Z[i] = Z[k]; n       else { n         L = i; n         while (R < n && str[R - L] == str[R]) R++; n         Z[i] = R - L; n         R--; n       } n     } n   } 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


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


#include <bits/stdc++.h> n using namespace std; n int N, cnt1 = 0, cnt2 = 0; n int main(int argc, char *argv[]) { n   string a, b; n   cin >> N; n   for (int i = 1; i <= N; i++) n     cin >> a >> b, cnt1 += (b ==  soft ), cnt2 += (b ==  hard ); n   for (int i = 1; i <= N; i++) { n     int q1 = i * i / 2, q2 = (i * i + 1) / 2; n     if ((q1 >= cnt1 && q2 >= cnt2) || (q2 >= cnt1 && q1 >= cnt2)) { n       printf( %d n , i); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   int hm = 0, wm = 0; n   for (int i = 0; i < (int)(n); i++) { n     char c; n     int h, w; n     cin >> c >> h >> w; n     if (h < w) { n       swap(h, w); n     } n     if (c ==  + ) { n       hm = max(hm, h); n       wm = max(wm, w); n     } else { n       if (h >= hm && w >= wm) { n         cout <<  YES  << endl; n       } else { n         cout <<  NO  << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int n, k; n char str[MAXN]; n vector<int> loc[2]; n int main() { n   scanf( %d%d%s , &n, &k, str); n   for (int i = 0; i < n; i++) loc[str[i] -  0 ].push_back(i); n   if (loc[0].empty() || loc[1].empty()) return 0 * printf( tokitsukaze n ); n   int flag = 0; n   for (int l = 0, r = k - 1; r < n; l++, r++) { n     vector<int> tmp[2]; n     for (int i = 0; i < 2; i++) { n       if (loc[i].front() < l || loc[i].front() > r) n         tmp[i].push_back(loc[i].front()); n       if (loc[i].back() < l || loc[i].back() > r) n         tmp[i].push_back(loc[i].back()); n       auto itr = lower_bound(loc[i].begin(), loc[i].end(), l); n       if (itr != loc[i].begin()) tmp[i].push_back(*--itr); n       itr = upper_bound(loc[i].begin(), loc[i].end(), r); n       if (itr != loc[i].end()) tmp[i].push_back(*itr); n       sort(tmp[i].begin(), tmp[i].end()); n     } n     if (tmp[0].empty() || tmp[1].empty()) return 0 * printf( tokitsukaze n ); n     flag |= (tmp[0].back() - tmp[0].front() >= k || n              tmp[1].back() - tmp[1].front() >= k); n   } n   return 0 * printf( %s n , (flag ?  once again  :  quailty )); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, d; n long long din[2][150003]; n long long a[303]; n long long mx[150003]; n long long b[303]; n long long t[303]; n deque<long long> deq; n int main() { n   cin >> n >> m >> d; n   t[0] = 0; n   for (int i = 0; i < m; i++) { n     cin >> a[i + 1] >> b[i + 1] >> t[i + 1]; n   } n   for (int i = 1; i <= m; i++) { n     deq.clear(); n     long long T = (t[i] - t[i - 1]) * d; n     for (int j = 0; j < n && j < T; j++) { n       while (deq.size() && deq.back() < din[(i - 1) % 2][j]) { n         deq.pop_back(); n       } n       deq.push_back(din[(i - 1) % 2][j]); n     } n     for (int j = 0; j < n; j++) { n       if (T + j < n) { n         while (deq.size() && deq.back() < din[(i - 1) % 2][T + j]) { n           deq.pop_back(); n         } n         deq.push_back(din[(i - 1) % 2][T + j]); n       } n       mx[j] = deq.front(); n       if (j - T >= 0 && deq.front() == din[(i - 1) % 2][j - T]) deq.pop_front(); n     } n     for (int j = 0; j < n; j++) { n       din[i % 2][j] = mx[j] + (b[i] - abs(a[i] - (j + 1))); n     } n   } n   long long res = din[m % 2][0]; n   for (int i = 0; i < n; i++) { n     if (din[m % 2][i] > res) res = din[m % 2][i]; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l, p, q; n   cin >> l >> p >> q; n   double ans; n   ans = (double)l * p / ((p + q)); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     int k = s.size(); n     if (s[k - 1] ==  o ) n       cout <<  FILIPINO  << endl; n     else if (s[k - 1] ==  u ) n       cout <<  JAPANESE  << endl; n     else n       cout <<  KOREAN  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double w, h, d; n const double pi = acos(-1); n int main() { n   scanf( %lf%lf%lf , &w, &h, &d); n   if (d >= 90) d = 180 - d; n   if (w < h) swap(w, h); n   if (d == 0 || d == 180) n     printf( %.10f n , w * h); n   else if (d == 90) n     printf( %.10f n , min(w, h) * min(w, h)); n   else { n     d = d * pi / 180; n     double mid = 2 * atan(h / w); n     if (d >= mid) { n       printf( %.10f n , h * h / sin(d)); n     } else { n       double u = (w + h) / (1 + 1 / cos(d) + tan(d)); n       double v = (w - h) / (1 + 1 / cos(d) - tan(d)); n       double x = (u + v) / 2; n       double y = (u - v) / 2; n       printf( %.10f n , w * h - (x * x + y * y) * tan(d)); n     } n   } n   return 0; n } n


/* cerberus97 - Hanit Banga */ n  n #include <iostream> n #include <iomanip> n #include <cassert> n #include <cmath> n #include <cstdio> n #include <cstring> n #include <cstdlib> n #include <map> n #include <set> n #include <queue> n #include <stack> n #include <vector> n #include <algorithm> n #include <numeric> n  n using namespace std; n  n #define pb push_back n #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL) n  n typedef long long ll; n typedef long double ld; n typedef pair <int, int> pii; n typedef pair <ll, ll> pll; n  n const int N = 1e5 + 10; n  n int main() { n  fast_cin(); n  int t; cin >> t; n  while (t--) { n   int n; cin >> n; n   vector<ll> d(n); n   for (auto& i : d) { n    cin >> i; n   } n   sort(d.begin(), d.end()); n   ll ans = d[n - 1]; n   for (int i = 0; i < n; ++i) { n    ans += d[i] * (n - 1 - 2 * i); n   } n   cout << ans <<   n ; n  } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   float a, b, l, s = 0; n   cin >> a >> b >> l; n   s = (b * a) / (b + l); n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b, c, x, y, z; n   cin >> a >> b >> c >> x >> y >> z; n   long long int a1, b1, c1; n   a1 = a - x; n   b1 = b - y; n   c1 = c - z; n   long long int pol = 0, otr = 0; n   pol += max(a1 / 2, (long long)0) + max(b1 / 2, (long long)0) + n          max(c1 / 2, (long long)0); n   otr += min(a1, (long long)0) + min(b1, (long long)0) + min(c1, (long long)0); n   if (pol + otr >= 0) n     cout <<  Yes ; n   else n     cout <<  No ; n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n vector<vector<int> > G; n vector<long long> cnt; n vector<long long> dp; n int main(int argc, char const* argv[]) { n   cin >> N >> M; n   for (int i = 0; i < N; i++) { n     G.push_back(vector<int>()); n     cnt.push_back(0); n     dp.push_back(1); n   } n   for (int i = 0; i < M; i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     cnt[u]++; n     cnt[v]++; n     if (u >= v) { n       swap(u, v); n     } n     G[u].push_back(v); n   } n   long long res = 0; n   for (int i = 0; i < N; i++) { n     const auto& es = G[i]; n     res = max(res, dp[i] * cnt[i]); n     for (int j : es) { n       dp[j] = max(dp[j], dp[i] + 1); n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b >> c; n   int x, y, z; n   cin >> x >> y >> z; n   int a_rest = 0, a_sh = 0, b_rest = 0, b_sh = 0, c_sh = 0, c_rest = 0; n   if (a > x) { n     a_rest = a - x; n     if (a_rest % 2 == 1) a_rest--; n     a_sh = 0; n   } else { n     a_rest = 0; n     a_sh = x - a; n   } n   if (b > y) { n     b_rest = b - y; n     if (b_rest % 2 == 1) b_rest--; n     b_sh = 0; n   } else { n     b_rest = 0; n     b_sh = y - b; n   } n   if (c > z) { n     c_rest = c - z; n     if (c_rest % 2 == 1) c_rest--; n     c_sh = 0; n   } else { n     c_rest = 0; n     c_sh = z - c; n   } n   int free_pair = (a_rest + b_rest + c_rest) / 2; n   int need = a_sh + b_sh + c_sh; n   if (free_pair >= need) n     cout <<  Yes  << endl; n   else n     cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct SCC { n   int n; n   vector<int> comp, order; n   vector<bool> used; n   vector<vector<int> > G, RG; n   SCC(int _n = 0) : n(_n), comp(_n, -1), used(_n, false), G(_n), RG(_n) {} n   void add_edge(int from, int to) { n     G[from].push_back(to); n     RG[to].push_back(from); n   } n   void copy(const vector<vector<int> >& H) { n     for (int i = 0; i < H.size(); i++) { n       for (int j = 0; j < H[i].size(); j++) { n         G[i].push_back(H[i][j]); n         RG[H[i][j]].push_back(i); n       } n     } n   } n   int operator[](int u) const { return comp[u]; } n   void dfs(int u) { n     used[u] = true; n     for (int i = 0; i < G[u].size(); i++) n       if (!used[G[u][i]]) dfs(G[u][i]); n     order.push_back(u); n   } n   void rdfs(int u, int cnt) { n     comp[u] = cnt; n     for (int i = 0; i < RG[u].size(); i++) n       if (comp[RG[u][i]] == -1) rdfs(RG[u][i], cnt); n   } n   int build() { n     for (int i = 0; i < n; i++) n       if (!used[i]) dfs(i); n     int cnt = 0; n     for (int i = n - 1; i >= 0; i--) n       if (comp[order[i]] == -1) rdfs(order[i], cnt++); n     return cnt; n   } n   int build(vector<vector<int> >& H) { n     int ret = build(); n     H.assign(ret, vector<int>()); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < G[i].size(); j++) { n         if (comp[i] != comp[G[i][j]]) H[comp[i]].push_back(comp[G[i][j]]); n       } n     } n     return ret; n   } n }; n int N, M, D, K; n vector<int> G[1 << 17]; n long long S[1 << 17]; n SCC P; n vector<int> vs[1 << 17]; n long long dist[1 << 17]; n int add[1 << 17][50], cnt[1 << 17][50]; n int main() { n   scanf( %d%d%d , &N, &M, &D); n   P = SCC(N); n   for (int i = 0; i < M; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     u--, v--; n     G[u].push_back(v); n     P.add_edge(u, v); n   } n   for (int i = 0; i < N; i++) { n     scanf(  n ); n     for (int j = 0; j < D; j++) { n       char c; n       scanf( %c , &c); n       if (c ==  1 ) S[i] |= 1LL << j; n     } n   } n   int K = P.build(); n   for (int i = 0; i < N; i++) vs[P[i]].push_back(i); n   const long long msk = (1LL << D) - 1; n   for (int k = K; k--;) { n     dist[vs[k][0]] = 1; n     queue<int> Q; n     Q.push(vs[k][0]); n     while (!Q.empty()) { n       int u = Q.front(); n       Q.pop(); n       for (int v : G[u]) { n         if (k == P[v]) { n           long long nxt = dist[u] << 1 & msk | dist[u] >> D - 1; n           if (nxt & ~dist[v]) { n             dist[v] |= nxt; n             Q.push(v); n           } n         } n       } n     } n     for (int u : vs[k]) n       for (int v : G[u]) n         if (k != P[v]) { n           vector<int> ret(D); n           for (int d2 = 0; d2 < D; d2++) { n             int nd = (d2 + 1) % D; n             for (int d3 = 0; d3 < D; d3++) n               if (dist[v] >> d3 & 1) { n                 int d4 = (nd - d3 + D) % D; n                 ret[d2] = max(ret[d2], cnt[P[v]][d4] + add[P[v]][d4]); n               } n           } n           for (int d = 0; d < D; d++) { n             for (int d2 = 0; d2 < D; d2++) n               if (dist[u] >> d2 & 1) { n                 add[k][d] = max(add[k][d], ret[(d + d2) % D]); n               } n           } n         } n     for (int d = 0; d < D; d++) { n       for (int u : vs[k]) { n         long long now = dist[u]; n         if (now & S[u]) cnt[k][d]++; n         dist[u] = dist[u] << 1 & msk | dist[u] >> D - 1; n       } n     } n   } n   printf( %d n , add[P[0]][0] + cnt[P[0]][0]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m; n   cin >> n >> m; n   if (n == m) { n     cout << n - 1 <<     << n; n   } else if (n > m) { n     cout << n - 1 <<     << m; n   } else n     cout << m - 1 <<     << n; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> v, v1; n   for (int i = 0; i < n; i++) { n     int t, y; n     cin >> t >> y; n     v.push_back(t); n     v1.push_back(y); n   } n   sort(v.begin(), v.end()); n   sort(v1.begin(), v1.end()); n   long long ans = n; n   for (int i = 0; i < n; i++) { n     ans += max(v[i], v1[i]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100009; n struct query { n   long long a, b, op, s; n } q[N * 9], b[N * 9]; n long long n, m, a[N], ans[N], cnt, cntq, tr[N]; n set<long long> Set[N]; n inline void add(long long x, long long c) { n   while (x <= n) { n     tr[x] += c, x += (x & -x); n   } n } n inline long long ask(long long x) { n   long long res = 0; n   while (x) { n     res += tr[x], x -= (x & -x); n   } n   return res; n } n inline bool cmp(query x, query y) { n   if (x.op != y.op) n     return x.op < y.op; n   else if (x.op) n     return x.a < y.a; n   else n     return x.b < y.b; n } n void cdq(long long l, long long r) { n   if (l >= r) return; n   long long mid = (l + r) >> 1; n   cdq(l, mid), cdq(mid + 1, r); n   long long p1 = l, p2 = mid + 1, Cnt = l; n   for (long long i = mid + 1; i <= r; i++) n     if (q[i].op) { n       while (p1 <= mid && (q[p1].b <= q[i].b)) { n         if (!q[p1].op) add(q[p1].a, (q[p1].s * (q[p1].b - q[p1].a))); n         p1++; n       } n       ans[q[i].op] += ask(n) - ask(q[i].a - 1); n     } n   for (long long i = l; i < p1; i++) n     if (!q[i].op) add(q[i].a, -(q[i].s * (q[i].b - q[i].a))); n   for (long long k = l, i = l, j = mid + 1; k <= r; k++) n     b[k] = (j > r || (i <= mid && q[i].b <= q[j].b)) ? q[i++] : q[j++]; n   for (long long i = l; i <= r; i++) q[i] = b[i]; n } n signed main() { n   scanf( %lld%lld , &n, &m); n   for (long long i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     Set[a[i]].insert(i); n     if (Set[a[i]].size() != 1) q[++cnt] = {*(--Set[a[i]].rbegin()), i, 0, 1}; n   } n   for (long long i = 1; i <= m; i++) { n     long long op, b, c, l = 0, r = 0; n     scanf( %lld%lld%lld , &op, &b, &c); n     if (op == 2) { n       q[++cnt] = {b, c, ++cntq, 0}; n     } else { n       set<long long>::iterator i = Set[a[b]].find(b); n       if (i != Set[a[b]].begin()) { n         l = *--i; n         q[++cnt] = {l, b, 0, -1}; n         i++; n       } n       if (++i != Set[a[b]].end()) { n         r = *i; n         q[++cnt] = {b, r, 0, -1}; n       } n       if (l && r) q[++cnt] = {l, r, 0, 1}; n       Set[a[b]].erase(b); n       Set[c].insert(b); n       l = r = 0; n       i = Set[c].find(b); n       a[b] = c; n       if (i != Set[c].begin()) { n         l = *--i; n         q[++cnt] = {l, b, 0, 1}; n         i++; n       } n       if (++i != Set[c].end()) { n         r = *i; n         q[++cnt] = {b, r, 0, 1}; n       } n       if (l && r) q[++cnt] = {l, r, 0, -1}; n     } n   } n   cdq(1, cnt); n   for (long long i = 1; i <= cntq; i++) printf( %lld n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int func(char c) { n   if (c >=  a  && c <=  z ) { n     return 1; n   } n   if (c >=  A  && c <=  Z ) { n     return 2; n   } n   return 0; n } n void solve() { n   string s; n   cin >> s; n   long long int lw = 0; n   long long int up = 0; n   long long int nm = 0; n   string str = s; n   long long int mp[3] = {0}; n   for (long long int i = 0; i < s.length(); i++) { n     mp[func(s[i])]++; n   } n   long long int cn = 0; n   for (long long int i = 0; i < 3; i++) { n     if (!mp[i]) cn++; n   } n   if (!cn) { n     cout << s << endl; n     return; n   } n   if (cn == 1) { n     for (long long int i = 0; i < s.length(); i++) { n       if (mp[func(s[i])] > 1) { n         long long int index = 0; n         for (long long int id = 0; id < 3; id++) { n           if (!mp[id]) index = id; n         } n         if (index == 0) { n           s[i] =  0 ; n           break; n         } else if (index == 1) { n           s[i] =  a ; n           break; n         } else { n           s[i] =  A ; n           break; n         } n       } n     } n     cout << s << endl; n   } else { n     long long int index; n     for (long long int i = 0; i < 3; i++) { n       if (mp[i]) { n         index = i; n         break; n       } n     } n     if (index == 1) { n       s[0] =  A ; n       s[1] =  0 ; n     } else if (index == 0) { n       s[0] =  A ; n       s[1] =  a ; n     } else { n       s[0] =  0 ; n       s[1] =  a ; n     } n     cout << s << endl; n   } n } n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v; n int main() { n   int n, k, l, r, sall, sk, i, res, ext, j, a, b; n   while (scanf( %d %d %d %d %d %d , &n, &k, &l, &r, &sall, &sk) == 6) { n     v.clear(); n     if (sk % k == 0) { n       res = sk / k; n       for (i = 0; i < k; i++) { n         v.push_back(res); n       } n     } else { n       res = sk / k; n       ext = sk % k; n       for (i = 0, j = 0; i < k; i++, j++) { n         if (j < ext) n           v.push_back(res + 1); n         else n           v.push_back(res); n       } n     } n     a = sall - sk; n     b = n - k; n     if (b > 0) { n       if (a % b == 0) { n         res = a / b; n         for (i = 0; i < b; i++) { n           v.push_back(res); n         } n       } else { n         res = a / b; n         ext = a % b; n         for (i = 0, j = 0; i < b; i++, j++) { n           if (j < ext) n             v.push_back(res + 1); n           else n             v.push_back(res); n         } n       } n     } n     for (i = 0; i < ((int)v.size()); i++) { n       if (!i) n         cout << v[i]; n       else n         cout <<     << v[i]; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool pr[10000005] = {false}; n vector<long long> prime; n void prim() { n   pr[0] = true; n   pr[1] = true; n   for (long long i = 2; i <= sqrt(100005); i++) { n     for (long long j = i * 2; j <= sqrt(100005); j += i) { n       pr[j] = true; n     } n   } n } n vector<long long> divisor(long long n) { n   vector<long long> div; n   div.push_back(n); n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       div.push_back(i); n       if (n / i != i) div.push_back(n / i); n     } n   } n   sort(div.begin(), div.end()); n   return div; n } n long long modInverse(long long a, long long m) { n   long long m0 = m; n   long long y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     long long q = a / m; n     long long t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n long long find(long long n) { n   long long count = 0; n   while (n) { n     count++; n     n = n / 2; n   } n   return count; n } n void solve() { n   long long n; n   cin >> n; n   long long arr[n]; n   for (long long i = 0; i < (long long)n; i++) cin >> arr[i]; n   vector<vector<long long>> ans; n   if (n % 2 == 0) { n     long long ans1 = 0; n     for (long long i = 0; i < n; i++) { n       ans1 = ans1 ^ arr[i]; n     } n     if (ans1 != 0) { n       cout <<  NO n ; n       return; n     } else { n       cout <<  YES n ; n       for (long long i = 0; i < n - 2; i += 2) { n         ans.push_back({i + 1, i + 2, i + 3}); n       } n       for (long long i = 0; i < n - 2; i += 2) { n         ans.push_back({i + 1, i + 2, n}); n       } n       ans.push_back({n - 2, n - 1, n}); n       cout << ans.size() <<   n ; n       for (long long i = 0; i < (long long)ans.size(); i++) { n         cout << ans[i][0] <<     << ans[i][1] <<     << ans[i][2] <<   n ; n       } n       return; n     } n   } n   cout <<  YES n ; n   for (long long i = 0; i < n - 2; i += 2) { n     ans.push_back({i + 1, i + 2, n}); n     arr[n] = arr[n] ^ arr[i + 1] ^ arr[i + 2]; n   } n   for (long long i = 0; i < n - 2; i += 2) { n     ans.push_back({i + 1, i + 2, n}); n   } n   cout << ans.size() <<   n ; n   for (long long i = 0; i < (long long)ans.size(); i++) { n     cout << ans[i][0] <<     << ans[i][1] <<     << ans[i][2] <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   prim(); n   for (long long i = 2; i <= 100005; i++) { n     if (pr[i] == false) { n       prime.push_back(i); n     } n   } n   long long t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   string s; n   cin >> s; n   n = s.size(); n   int z = 0, o = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  1 ) n       o++; n     else n       z++; n   } n   if (min(o, z) & 1) { n     cout <<  DA n ; n   } else { n     cout <<  NET n ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1, s2; n   getline(cin, s1); n   getline(cin, s2); n   int a; n   for (int i = 0; i < s2.size(); i++) { n     if (s2[i] ==    ) continue; n     a = 0; n     for (int j = 0; j < s1.size(); j++) n       if (s1[j] ==    ) n         continue; n       else if (s1[j] == s2[i]) { n         a = 1; n         s1.erase(j, 1); n         break; n       } n     if (!a) { n       cout <<  NO ; n       break; n     } n   } n   if (a) cout <<  YES ; n } n


#include <bits/stdc++.h> n int x[30]; n template <class T> n inline void read(T &num) { n   num = 0; n   char c = getchar(); n   T sign = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) sign = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     num = (num << 1) + (num << 3) + (c ^ 48); n     c = getchar(); n   } n   num *= sign; n } n int main() { n   int t, a; n   read(t); n   while (t--) { n     read(a); n     int tag = a, cnt = 0, ok = 0, ans = 0; n     while (tag) { n       x[++cnt] = tag & 1; n       if (!x[cnt]) ok = 1; n       tag >>= 1; n     } n     if (ok) { n       for (register int i = cnt; i; --i) { n         ans <<= 1; n         if (!x[i]) ++ans; n       } n       printf( %d n , ans ^ a); n     } else { n       for (register int i = 2; i * i <= a; ++i) n         if (a % i == 0) { n           printf( %d n , a / i); n           ok = 1; n           break; n         } n       if (!ok) puts( 1 ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9; n const int N = 155; n int old[N][N * N]; n int now[N][N * N]; n int q[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(nullptr); n   int n, k, s; n   cin >> n >> k >> s; n   for (int i = 0; i < n; i++) cin >> q[i]; n   for (int i = 0; i < N; i++) n     for (int j = 0; j < N * N / 2; j++) old[i][j] = INF; n   old[0][0] = 0; n   for (int pos = 0; pos < n; pos++) { n     for (int i = 0; i < N; i++) n       for (int j = 0; j < N * N / 2; j++) now[i][j] = INF; n     for (int taken = 0; taken <= k; taken++) { n       for (int swaps = 0; swaps <= N * N / 2; swaps++) { n         now[taken][swaps] = min(now[taken][swaps], old[taken][swaps]); n         if (taken <= pos) n           now[taken + 1][swaps + pos - taken] = min( n               now[taken + 1][swaps + pos - taken], old[taken][swaps] + q[pos]); n       } n     } n     for (int i = 0; i < N; i++) n       for (int j = 0; j < N * N / 2; j++) old[i][j] = now[i][j]; n   } n   int res = INF; n   for (int swaps = 0; swaps <= min(N * N / 2 - 1, s); swaps++) n     res = min(res, now[k][swaps]); n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > g; n vector<int> col; n int n, m; n void dfs(int v) { n   int cnt = 0; n   for (size_t i = 0; i < g[v].size(); i++) n     if (col[g[v][i]] == col[v]) cnt++; n   if (cnt > 1) { n     col[v] ^= 1; n     for (size_t i = 0; i < g[v].size(); i++) n       if (col[g[v][i]] == col[v]) dfs(g[v][i]); n   } n } n int main() { n   ios_base ::sync_with_stdio(false); n   cin >> n >> m; n   int x, y; n   g.resize(n); n   col.resize(n, 0); n   for (int i = 0; i < m; i++) { n     cin >> x >> y; n     x--, y--; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   for (int i = 0; i < n; i++) { n     dfs(i); n   } n   for (int i = 0; i < n; i++) cout << col[i]; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt0, cnt1, timer; n void dfs(int v, vector<int> &colour, vector<int> &comp, n          vector<vector<pair<int, int>>> &g) { n   if (colour[v] == 0) n     cnt0++; n   else n     cnt1++; n   comp[v] = timer; n   for (auto &now : g[v]) n     if (colour[now.first] == -1) { n       colour[now.first] = (colour[v] ^ now.second); n       dfs(now.first, colour, comp, g); n     } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     timer = 0; n     int n; n     cin >> n; n     vector<int> a(n), b(n); n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       a[i]--; n     } n     for (int i = 0; i < n; i++) { n       cin >> b[i]; n       b[i]--; n     } n     vector<int> cnt(n); n     for (int i = 0; i < n; i++) cnt[a[i]]++, cnt[b[i]]++; n     bool tf = true; n     for (int i = 0; i < n; i++) n       if (cnt[i] != 2) tf = false; n     if (!tf) { n       cout << -1 <<   n ; n       continue; n     } n     vector<int> pos1(n, -1), pos2(n, -1); n     for (int i = 0; i < n; i++) { n       if (pos1[a[i]] == -1) n         pos1[a[i]] = i; n       else n         pos2[a[i]] = i; n     } n     for (int i = 0; i < n; i++) { n       if (pos1[b[i]] == -1) n         pos1[b[i]] = i; n       else n         pos2[b[i]] = i; n     } n     vector<vector<pair<int, int>>> g(n); n     for (int i = 0; i < n; i++) { n       if (pos1[i] == pos2[i]) continue; n       int ina_1 = (a[pos1[i]] != i), ina_2 = (a[pos2[i]] != i); n       g[pos1[i]].push_back({pos2[i], ina_1 == ina_2}); n       g[pos2[i]].push_back({pos1[i], ina_1 == ina_2}); n     } n     vector<int> colour(n, -1), comp(n, -1); n     int ans = 0; n     vector<bool> arr; n     for (int i = 0; i < n; i++) n       if (colour[i] == -1) { n         cnt0 = cnt1 = 0; n         colour[i] = 0; n         dfs(i, colour, comp, g); n         timer++; n         ans += min(cnt0, cnt1); n         arr.push_back((bool)(cnt0 < cnt1)); n       } n     for (int i = 0; i < n; i++) n       for (auto &now : g[i]) n         if (colour[i] != (colour[now.first] ^ now.second)) tf = false; n     if (!tf) { n       cout << -1 <<   n ; n       continue; n     } n     cout << ans <<   n ; n     for (int i = 0; i < n; i++) n       if (arr[comp[i]] ^ colour[i]) cout << i + 1 <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n using VV = vector<vector<T>>; n template <class T> n inline T SMIN(T& a, const T b) { n   return a = (a > b) ? b : a; n } n template <class T> n inline T SMAX(T& a, const T b) { n   return a = (a < b) ? b : a; n } n template <class Iter> n void __kumaerrc(Iter begin, Iter end) { n   for (; begin != end; ++begin) { n     cerr << *begin <<  , ; n   } n   cerr << endl; n } n void __kumaerr(istream_iterator<string> it) { n   (void)it; n   cerr << endl; n } n template <typename T, typename... Args> n void __kumaerr(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<  =  << a <<  ,  , __kumaerr(++it, args...); n } n template <typename S, typename T> n std::ostream& operator<<(std::ostream& _os, const std::pair<S, T>& _p) { n   return _os <<  {  << _p.first <<  ,  << _p.second <<  } ; n } n const int MAX_N = 1e6 + 1; n long long A[MAX_N]; n int N; n long long f(vector<long long> bs) { n   int N = int((bs).size()); n   long long cur = 0, mn = 0, res = 0; n   for (int i = 0; i < (N); ++i) { n     cur += bs[i]; n     SMAX(res, cur - mn); n     SMIN(mn, cur); n   } n   return res; n } n void solve() { n   long long base = 0; n   for (int i = 0; i < (N); ++i) n     if (i % 2 == 0) base += A[i]; n   vector<long long> bs; n   for (int i = 0; i < (N / 2); ++i) bs.push_back(A[2 * i + 1] - A[2 * i]); n   long long res = base; n   SMAX(res, base + f(bs)); n   bs.clear(); n   for (int i = (1); i <= ((N - 1) / 2); ++i) n     bs.push_back(A[2 * i - 1] - A[2 * i]); n   SMAX(res, base + f(bs)); n   cout << res << endl; n } n const long long Inf = 1e18; n long long dp[MAX_N][4]; n void solve_dp() { n   for (int i = 0; i <= (N); ++i) n     for (int j = 0; j < (4); ++j) dp[i][j] = -Inf; n   dp[0][0] = dp[0][2] = dp[0][3] = 0; n   for (int i = 0; i < (N); ++i) n     for (int j = 0; j < (4); ++j) { n       if (j == 0) { n         if (i % 2 == 0) { n           SMAX(dp[i + 1][j], dp[i][j] + A[i]); n           SMAX(dp[i + 1][1], dp[i][j] + A[i]); n         } else { n           SMAX(dp[i + 1][j], dp[i][j]); n           SMAX(dp[i + 1][2], dp[i][j]); n         } n       } n       if (j == 1 || j == 2) { n         if (i % 2 == 0) { n           SMAX(dp[i + 1][j], dp[i][j]); n           if (j == 1) SMAX(dp[i + 1][3], dp[i][j]); n         } else { n           SMAX(dp[i + 1][j], dp[i][j] + A[i]); n           if (j == 2) SMAX(dp[i + 1][3], dp[i][j] + A[i]); n         } n       } n       if (j == 3) { n         if (i % 2 == 0) { n           SMAX(dp[i + 1][j], dp[i][j] + A[i]); n         } else { n           SMAX(dp[i + 1][j], dp[i][j]); n         } n       } n     } n   long long res = 0; n   if (N % 2 == 0) dp[N][1] = -Inf; n   for (int j = 0; j < (4); ++j) { n     SMAX(res, dp[N][j]); n   } n   cout << res << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout << setprecision(12) << fixed; n   int t; n   cin >> t; n   while (t--) { n     cin >> N; n     for (int i = 0; i < (N); ++i) cin >> A[i]; n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n long long n, k; n vector<long long int> v[50005]; n long long ans; n vector<long long int> dfs(long long node, long long par) { n   vector<long long int> temp(k + 1); n   temp[0] = 1; n   for (auto i : v[node]) { n     if (i != par) { n       vector<long long int> cc = dfs(i, node); n       for (long long i = 0; i <= k; i++) ans += cc[i] * temp[k - i]; n       for (long long i = 0; i <= k; i++) temp[i] += cc[i]; n     } n   } n   for (long long i = k; i >= 1; i--) temp[i] = temp[i - 1]; n   temp[0] = 0; n   return temp; n } n void solve() { n   cin >> n >> k; n   for (long long i = 1; i <= n - 1; i++) { n     long long x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   ans = 0; n   dfs(1, -1); n   cout << ans; n } 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     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Mod = 1e9 + 9; n int Pow(int x, int e) { n   int ret = 1; n   while (e) { n     if (e & 1) ret = 1ll * ret * x % Mod; n     x = 1ll * x * x % Mod; n     e >>= 1; n   } n   return ret; n } n const int N = 1e5 + 10; n char S[N]; n int main() { n   int n, a, b, k; n   scanf( %d%d%d%d%s , &n, &a, &b, &k, S); n   int ia = Pow(a, Mod - 2); n   int coe = Pow(a, n), ans = 0; n   for (int i = 0; i <= k - 1; i++) { n     ans = (ans + 1ll * (S[i] ==  +  ? 1 : Mod - 1) * coe) % Mod; n     coe = 1ll * coe * ia % Mod * b % Mod; n   } n   int p = 1ll * Pow(ia, k) * Pow(b, k) % Mod; n   if (p == 1) n     ans = 1ll * ans * ((n + 1) / k) % Mod; n   else n     ans = n         1ll * ans * (Pow(p, (n + 1) / k) - 1) % Mod * Pow(p - 1, Mod - 2) % Mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, su = 0; n   cin >> n; n   vector<long long> a(n); n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n     su += a[i]; n   } n   if (su % 2) { n     cout <<  NO n ; n     return; n   } n   long long s = 0, ind = -1; n   for (long long i = 0; i < n; ++i) { n     if (!a[i] && s % 2 == 0) { n       ind = i; n       break; n     } n     s += a[i]; n   } n   vector<long long> ans; n   if (ind == -1) { n     for (long long i = n - 2; i > 0; i -= 2) { n       if (a[i - 1] && a[i]) continue; n       ans.push_back(i); n       a[i] = 1; n       if (a[i - 1]) { n         ind = i - 1; n         a[i - 1] = a[i] = a[i + 1] = 0; n         break; n       } n       a[i - 1] = 1; n     } n     if (ind == -1) { n       cout <<  NO n ; n       return; n     } n   } n   for (long long i = ind - 1; i >= 0; --i) { n     if (a[i]) { n       if (a[i - 1]) { n         ans.push_back(i); n         a[i - 1] = a[i] = 0; n       } else { n         if (a[i - 2]) { n           ans.push_back(i - 1); n           a[i - 2] = a[i] = 0; n         } else { n           ans.push_back(i - 1); n           ans.push_back(i); n           a[i - 2] = 1; n           a[i] = 0; n         } n       } n     } n   } n   for (long long i = ind + 1; i < n; ++i) { n     if (a[i]) { n       if (a[i + 1]) { n         ans.push_back(i); n         a[i + 1] = a[i] = 0; n       } else { n         if (a[i + 2]) { n           ans.push_back(i + 1); n           a[i + 2] = a[i] = 0; n         } else { n           ans.push_back(i + 1); n           ans.push_back(i); n           a[i + 2] = 1; n           a[i] = 0; n         } n       } n     } n   } n   cout <<  YES n  << ans.size() <<   n ; n   for (long long i = 0; i < ans.size(); ++i) { n     cout << ans[i] <<    ; n   } n   cout <<   n ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr), cout.tie(nullptr); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n int main() { n   int vladik, valera; n   std::cin >> vladik >> valera; n   int vladik_rounds = sqrt(vladik); n   int valera_rounds = valera > vladik_rounds ? sqrt(valera - vladik_rounds) : 0; n   if (valera_rounds >= vladik_rounds) { n     std::cout <<  Vladik n ; n   } else { n     std::cout <<  Valera n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int NUM = 100010; n const double eps = 1e-10, pi = acos(-1.0); n using namespace std; n int n; n vector<int> g[NUM]; n pair<int, int> node[NUM], edge[NUM]; n int tot, cnt; n void dfs(int u, int p, int x) { n   for (int i = 0; i < g[u].size(); i++) n     if (g[u][i] != p) { n       node[tot++] = pair<int, int>(u, g[u][i]); n       if (x == -1) n         x = tot - 1; n       else n         edge[cnt++] = pair<int, int>(x + 1, tot); n       dfs(g[u][i], u, tot - 1); n     } n } n int main() { n   int i, j; n   int u, v; n   scanf( %d , &n); n   for (i = 1; i < n; i++) { n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(1, -1, -1); n   printf( %d n , tot); n   for (i = 0; i < tot; i++) printf( 2 %d %d n , node[i].first, node[i].second); n   for (i = 0; i < cnt; i++) printf( %d %d n , edge[i].first, edge[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, c0, c1, h; n     cin >> n >> c0 >> c1 >> h; n     string second; n     cin >> second; n     int cost1 = 0, z = 0, o = 0; n     for (int i = 0; i < second.length(); i++) { n       if (second[i] ==  0 ) { n         cost1 += c0; n         z++; n       } else { n         cost1 += c1; n         o++; n       } n     } n     int cost2 = o * h + c0 * (second.length()); n     int cost3 = z * h + c1 * (second.length()); n     cout << min(cost1, min(cost2, cost3)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, i, j, b, p, f, h, c, sum; n   cin >> t; n   while (t--) { n     cin >> b >> p >> f >> h >> c; n     sum = 0; n     b /= 2; n     if (h < c) { n       if (b < f) { n         sum += (c * b); n         b = 0; n       } else if (b > f) { n         sum += (c * f); n         b -= f; n       } else { n         sum += (c * f); n         b = 0; n       } n       if (b > 0) { n         if (b < p) { n           sum += (h * b); n         } else if (b > p) { n           sum += (h * p); n         } else n           sum += (h * p); n       } n     } else if (h > c) { n       if (b < p) { n         sum += (h * b); n         b = 0; n       } else if (b > p) { n         sum += (h * p); n         b -= p; n       } else { n         sum += (h * p); n         b = 0; n       } n       if (b > 0) { n         if (b < f) { n           sum += (c * b); n         } else if (b > f) { n           sum += (c * f); n         } else n           sum += (c * f); n       } n     } else n       sum += (c * min(b, p + f)); n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   long long s, x; n   cin >> s >> x; n   bool flag = true; n   bool valid = true; n   if ((s & 1) != (x & 1)) valid = false; n   long long ans = 1; n   for (int i = 62; i >= 1; i--) { n     long long sb = (s >> i) & 1; n     long long xb = (x >> i) & 1; n     long long sp = (s >> (i - 1)) & 1; n     long long xp = (x >> (i - 1)) & 1; n     if (sb == 0 && xb == 0) { n       if (sp == 0 && xp == 1) valid = false; n     } n     if (sb == 0 && xb == 1) { n       if (sp == 1 && xp == 1) valid = false; n     } n     if (sb == 1 && xb == 0) { n       if (sp == 1 && xp == 1) valid = false; n     } n     if (sb == 1 && xb == 1) { n       if (sp == 0 && xp == 1) valid = false; n     } n     if (xb != sb) flag = false; n   } n   for (int i = 0; i < 62; i++) n     if ((x >> i) & 1) ans *= 2; n   if (!valid) n     cout <<  0 n ; n   else n     cout << ans - flag * 2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   ,  ; n   __f(comma + 1, args...); n } n inline long long int gcd(long long int a, long long int b) { n   a = abs(a), b = abs(b); n   while (b) a = a % b, swap(a, b); n   return a; n } n inline long long int power(long long int a, long long int p) { n   long long int res = 1, x = a; n   while (p) { n     if (p & 1) res = (res * x); n     x = (x * x), p >>= 1; n   } n   return res; n } n inline long long int big_mod(long long int a, long long int p, n                              long long int m) { n   long long int res = 1 % m, x = a % m; n   while (p) { n     if (p & 1) res = (res * x) % m; n     x = (x * x) % m, p >>= 1; n   } n   return res; n } n const long long int INF = 1e15; n const int nax = 2e5 + 5; n int parent[nax]; n int sz[nax]; n void makeset(int u) { n   parent[u] = u; n   sz[u] = 1; n } n void init_DSU(int N) { n   for (int i = 0; i <= N; i++) { n     makeset(i); n   } n } n int Find(int r) { n   if (parent[r] == r) { n     return r; n   } n   parent[r] = Find(parent[r]); n   return parent[r]; n } n int FindSize(int r) { return sz[Find(r)]; } n void Union(int a, int b) { n   int u = Find(a); n   int v = Find(b); n   if (u != v) { n     parent[u] = v; n     sz[v] += sz[u]; n   } n } n int main() { n   int q; n   cin >> q; n   while (q--) { n     int n; n     cin >> n; n     init_DSU(n); n     for (int i = 1; i <= n; i++) { n       int x; n       cin >> x; n       Union(i, x); n     } n     for (int i = 1; i <= n; i++) { n       cout << FindSize(i) <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[2005]; n int n, k; n int main() { n   scanf( %d , &k); n   k += 2; n   int len = 0; n   a[len++] = -1; n   int res; n   while (k > 1000000) { n     k++; n     a[len++] = 1000000; n     k -= 1000000; n   } n   a[len++] = k; n   printf( %d n , len); n   for (int i = 0; i < len; i++) printf( %d  , a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7; n int sz[N], col[2]; n int n; n long long ans = 0, odd; n vector<int> V[N]; n void dfs(int a, int fa, int zt) { n   sz[a] = 1; n   col[zt]++; n   for (int i = (0); i < (((int)(V[a]).size())); ++i) { n     int nxt = V[a][i]; n     if (nxt == fa) continue; n     dfs(nxt, a, zt ^ 1); n     sz[a] += sz[nxt]; n     ans += 1ll * sz[nxt] * (n - sz[nxt]); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = (1); i < (n); ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     V[a].push_back(b); n     V[b].push_back(a); n   } n   dfs(1, 1, 0); n   odd = 1ll * col[0] * col[1]; n   cout << ans / 2 + (odd + 1) / 2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ara[100010]; n int cnt[50]; n int func(int x) { n   if (x == 0) return 0; n   if (x % 2 == 0) { n     return func(x / 2); n   } else { n     return 1 + func(x - 1); n   } n } n int main() { n   std::ios_base::sync_with_stdio(false); n   ; n   int n; n   cin >> n; n   for (int i = 0; i <= n - 1; i++) { n     cin >> ara[i]; n     cnt[func(ara[i])]++; n   } n   long long ans = 0; n   for (int i = 0; i <= 40; i++) { n     if (cnt[i] == 0) continue; n     long long yo = cnt[i]; n     ans += (yo * (yo - 1LL)) / 2LL; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, c; n   cin >> a >> b >> c; n   long long m, mi, mid; n   long long v[3]; n   v[0] = a; n   v[1] = b; n   v[2] = c; n   sort(v, v + 3); n   a = v[2]; n   b = v[0]; n   c = v[1]; n   if (a - b < c) { n     cout <<  0 ; n   } else { n     m = a - b - c + 1; n     cout << m; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void printArray(const T* a, int n, ostream& out = cerr); n template <class T> n void printArray(const vector<T>& arr, ostream& out = cerr); n const long long mod = 1e9 + 7; n const double PI = acos(-1); n int n, i, j, k, t; n int m; n int a[200002]; n int b[200002]; n int c[200002]; n int pos[200002]; n int ac[200002]; n int bc[200002]; n int cc[200002]; n int mab[200002]; n int hitung(int st, int pem, int ed) { n   int total = ac[st]; n   total += (bc[pem] - bc[st]); n   total += (cc[ed] - cc[pem]); n   return total; n } n int hitung2(int st, int pem, int ed) { n   int total = ac[st]; n   total += (bc[pem] - bc[st]); n   total += (cc[ed] - cc[pem]); n   return total; n } n int main() { n   scanf( %d %d %d , &n, &m, &k); n   int tot = n + m + k; n   for (int i = 0; i < n; ++i) { n     scanf( %d , a + i); n     pos[a[i]] = 1; n   } n   for (int i = 0; i < m; ++i) { n     scanf( %d , b + i); n     pos[b[i]] = 2; n   } n   for (int i = 0; i < k; ++i) { n     scanf( %d , c + i); n     pos[c[i]] = 3; n   } n   for (int i = 1; i <= tot; ++i) { n     ac[i] = ac[i - 1] + (pos[i] == 1); n     bc[i] = bc[i - 1] + (pos[i] == 2); n     cc[i] = cc[i - 1] + (pos[i] == 3); n   } n   mab[tot] = bc[tot]; n   for (int i = tot - 1; i >= 0; --i) { n     mab[i] = max(mab[i + 1], bc[i] + cc[tot] - cc[i]); n   } n   int ans = 0; n   for (int i = 0; i <= tot; ++i) { n     ans = max(ans, ac[i] + mab[i] - bc[i]); n   } n   printf( %d n , tot - ans); n   return 0; n } n template <class T> n void printArray(const T* a, int n, ostream& out) { n   for (int i = 0; i < n; ++i) { n     out << a[i] <<    ; n   } n   out << endl; n } n template <class T> n void printArray(const vector<T>& arr, ostream& out) { n   for (const T& x : arr) { n     out << x <<    ; n   } n   out << endl; n } n


#include <bits/stdc++.h> n using namespace std; n std::vector<long long> a; n long long sm = 0; n long long n, m; n bool doo(long long x) { n   long long res = 0; n   for (long long i = 0; i < x; ++i) { n     res += a[i]; n     long long k = i + x; n     long long count = 1; n     while (k < n and a[k] - count > 0) { n       res += max(0ll, a[k] - count); n       k += x; n       count++; n     } n   } n   return res >= m; n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   cin >> n >> m; n   (a).clear(), (a).resize(n); n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n     sm += a[i]; n   } n   sort((a).rbegin(), (a).rend()); n   if (sm < m) { n     cout <<  -1 ; n     exit(0); n   } n   long long l = 1, h = n + 1; n   long long mid; n   long long ans = -1; n   while (l <= h) { n     mid = (l + h) / 2; n     if (doo(mid)) { n       ans = mid; n       h = mid - 1; n     } else n       l = mid + 1; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v1[1000100]; n vector<long long> v2; n map<long long, long long> m1; n map<long long, long long> m2; n map<long long, long long> m3; n map<char, long long> ms1; n map<string, long long> ms2; n stack<long long> sta; n long long big = 999999999999999999, small = -999999999999999999; n long long z, y, x, n, m, i, j, k, t, l, ans, sum1, sum2, avg, test, b[500100], n     c[500100], a[500100], d[500100], co1[100100], co2[100100]; n char s[1000100], s1[1000100], s2[1000100], temp; n bool pro[1000100], pro1, pro2, pro3; n int main() { n   cin >> n >> k; n   k > (n + 1) / 2 ? cout << 2 * (k - (n + 1) / 2) : cout << 2 * k - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int segtree[400001]; n int val[100001]; n int inf = (1 << 30) - 1; n void build(int l, int r, int pos) { n   if (l == r) { n     segtree[pos] = val[r]; n     return; n   } n   int mid = (l + r) / 2; n   build(l, mid, 2 * pos + 1); n   build(mid + 1, r, 2 * pos + 2); n   segtree[pos] = (segtree[2 * pos + 1] & segtree[2 * pos + 2]); n } n int query(int lq, int rq, int l, int r, int pos) { n   if (rq < l || lq > r) return inf; n   if (lq <= l && r <= rq) return segtree[pos]; n   int mid = (l + r) / 2; n   return query(lq, rq, l, mid, 2 * pos + 1) & n          query(lq, rq, mid + 1, r, 2 * pos + 2); n } n int main() { n   int n; n   cin >> n; n   int m; n   cin >> m; n   int flag[n + 1][30]; n   memset(flag, 0, sizeof flag); n   int l[m], r[m], v[m]; n   for (int i = 0; i < m; i++) { n     cin >> l[i] >> r[i] >> v[i]; n     l[i]--; n     r[i]--; n     for (int j = 0; j < 30; j++) { n       if (v[i] & (1 << j)) { n         flag[l[i]][j] += 1; n         flag[r[i] + 1][j] -= 1; n       } n     } n   } n   for (int j = 0; j < 30; j++) { n     for (int i = 1; i < n; i++) { n       flag[i][j] += flag[i - 1][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     val[i] = 0; n     for (int j = 0; j < 30; j++) { n       if (flag[i][j]) val[i] += (1 << j); n     } n   } n   build(0, n - 1, 0); n   for (int i = 0; i < m; i++) { n     if (query(l[i], r[i], 0, n - 1, 0) != v[i]) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES n ; n   for (int j = 0; j < n; j++) cout << val[j] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   int t; n   cin >> t; n   for (; t--;) { n     cin >> n >> m; n     if (n == 1) { n       cout << 0 << endl; n       continue; n     } n     int ansl = 0, ansr = n, ans = (ansl + ansr) / 2; n     for (; ansl < ansr; ans = (ansl + ansr) / 2) { n       int tmp = n; n       long long C = 1, all = 0; n       for (int i = 0; i <= ans; ++i) { n         all += (long long)min((long long)tmp, C) * i; n         tmp -= min((long long)tmp, C); n         if (!tmp) break; n         C *= ans - i; n         C /= i + 1; n       } n       if (!tmp) n         if (all > (long long)m * ans) n           ansl = ans + 1; n         else n           ansr = ans; n       else n         ansl = ans + 1; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 102; n pair<int, int> ar[N]; n bool used[N]; n vector<deque<int>> vc; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> ar[i].first >> ar[i].second; n   for (int i = 1; i <= n; ++i) { n     if (used[i]) continue; n     deque<int> q; n     q.push_back(i); n     int cur = i; n     while (ar[cur].first) { n       used[cur] = true; n       cur = ar[cur].first; n       q.push_front(cur); n     } n     used[cur] = true; n     cur = i; n     while (ar[cur].second) { n       used[cur] = true; n       cur = ar[cur].second; n       q.push_back(cur); n     } n     used[cur] = true; n     vc.push_back(q); n   } n   for (int i = 1; i < vc.size(); ++i) { n     while (!vc[i].empty()) { n       vc[0].push_back(vc[i].front()); n       vc[i].pop_front(); n     } n   } n   auto cur = vc[0]; n   ar[cur.front()].first = ar[cur.back()].second = 0; n   for (int i = 0; i < (int)cur.size() - 1; ++i) ar[cur[i]].second = cur[i + 1]; n   for (int i = (int)cur.size() - 1; i > 0; --i) ar[cur[i]].first = cur[i - 1]; n   for (int i = 1; i <= n; ++i) n     cout << ar[i].first <<     << ar[i].second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n long long rnd(long long l, long long r) { return l + rng() % (r - l + 1); } n const long long N = 5e5 + 5; n const long long K = 5005; n long long n, a[N], k; n long long f[2][K][2]; n void minimize(long long &x, long long y) { x = min(x, y); } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> k >> n; n   for (long long i = 1, __c = n; i <= __c; ++i) cin >> a[i]; n   vector<pair<long long, long long> > w; n   sort(a + 1, a + n + 1); n   for (long long i = 1, __c = n - 1; i <= __c; ++i) n     w.emplace_back(a[i + 1] - a[i], i); n   sort(begin(w), end(w)); n   long long m = min((long long)w.size(), 3 * k); n   w.resize(m); n   for (auto &v : w) swap(v.first, v.second); n   w.push_back(make_pair(-1, 0)); n   sort(begin(w), end(w)); n   memset(f, 0x3f, sizeof(f)); n   f[0][0][0] = 0; n   long long now = 0; n   for (long long i = 1, __c = m; i <= __c; ++i) { n     f[now][0][0] = f[now][0][1] = 0; n     for (long long j = 1, __c = k; j <= __c; ++j) { n       minimize(f[now ^ 1][j][0], f[now][j][0]); n       minimize(f[now ^ 1][j][0], f[now][j][1]); n       minimize(f[now ^ 1][j][1], f[now ^ 1][j][0]); n       minimize(f[now ^ 1][j][1], f[now][j - 1][0] + w[i].second); n       if (w[i].first != w[i - 1].first + 1) n         minimize(f[now ^ 1][j][1], f[now][j - 1][1] + w[i].second); n     } n     now ^= 1; n   } n   cout << f[now][k][1] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int n1, n2, m, R, B, mxn, E[10005], nxt[10005], hd[10005], to[10005], n     adj[10005], cost[10005], cur[10005], dis[10005], D[10005], second, T, s, t, n     tot = 0, mnc = 0; n bool vis[10005], inq[10005]; n char s1[10005], s2[10005]; n inline void add(int u, int v, int w, int f) { n   nxt[tot] = hd[u]; n   hd[u] = tot; n   to[tot] = v; n   adj[tot] = w; n   cost[tot] = f; n   ++tot; n   nxt[tot] = hd[v]; n   hd[v] = tot; n   to[tot] = u; n   adj[tot] = 0; n   cost[tot] = -f; n   ++tot; n   return; n } n inline bool spfa() { n   for (int i = second; i <= T; ++i) dis[i] = 0x3f3f3f3f, inq[i] = 0; n   queue<int> q; n   q.push(T); n   dis[T] = 0; n   inq[T] = 1; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     inq[u] = 0; n     for (int i = hd[u]; ~i; i = nxt[i]) n       if (adj[i ^ 1] && dis[to[i]] > dis[u] - cost[i]) { n         dis[to[i]] = dis[u] - cost[i]; n         if (!inq[to[i]]) q.push(to[i]), inq[to[i]] = 1; n       } n   } n   return dis[second] < 0x3f3f3f3f; n } n inline int dfs(int u, int low) { n   vis[u] = 1; n   if (u == T) return low; n   int sum = 0, gt; n   for (int &i = cur[u]; ~i; i = nxt[i]) n     if (adj[i] > 0 && dis[to[i]] == dis[u] - cost[i] && !vis[to[i]]) { n       gt = dfs(to[i], min(low - sum, adj[i])); n       if (gt) { n         adj[i] -= gt; n         adj[i ^ 1] += gt; n         sum += gt; n         mnc += gt * cost[i]; n       } n       if (sum == low) break; n     } n   return sum; n } n inline int dinic() { n   int mxf = 0; n   while (spfa()) { n     vis[T] = 1; n     while (vis[T]) { n       for (int i = second; i <= T; ++i) cur[i] = hd[i], vis[i] = 0; n       mxf += dfs(second, 0x3f3f3f3f); n     } n   } n   return mxf; n } n int main() { n   int u, v; n   scanf( %d%d%d%d%d%s%s , &n1, &n2, &m, &R, &B, s1 + 1, s2 + 1); n   memset(hd, -1, sizeof(hd)); n   second = 1; n   s = 2; n   t = 3 + n1 + n2; n   T = 4 + n1 + n2; n   for (int i = 1; i <= n1; ++i) { n     if (s1[i] ==  R ) { n       --D[s]; n       ++D[i + 2]; n       add(s, i + 2, 0x3f3f3f3f, 0); n     } n     if (s1[i] ==  B ) { n       --D[i + 2]; n       ++D[t]; n       add(i + 2, t, 0x3f3f3f3f, 0); n     } n     if (s1[i] ==  U ) { n       add(s, i + 2, 0x3f3f3f3f, 0), add(i + 2, t, 0x3f3f3f3f, 0); n     } n   } n   for (int i = 1; i <= n2; ++i) { n     if (s2[i] ==  R ) { n       --D[i + 2 + n1]; n       ++D[t]; n       add(i + 2 + n1, t, 0x3f3f3f3f, 0); n     } n     if (s2[i] ==  B ) { n       ++D[i + 2 + n1]; n       --D[s]; n       add(s, i + 2 + n1, 0x3f3f3f3f, 0); n     } n     if (s2[i] ==  U ) { n       add(s, i + 2 + n1, 0x3f3f3f3f, 0), add(i + 2 + n1, t, 0x3f3f3f3f, 0); n     } n   } n   for (int i = 1; i <= m; ++i) { n     scanf( %d%d , &u, &v); n     E[i] = tot; n     add(u + 2, v + 2 + n1, 1, R); n     add(v + 2 + n1, u + 2, 1, B); n   } n   for (int i = s; i <= t; ++i) { n     if (D[i] < 0) add(i, T, -D[i], 0); n     if (D[i] > 0) add(second, i, D[i], 0), mxn += D[i]; n   } n   add(t, s, 0x3f3f3f3f, 0); n   if (dinic() < mxn) { n     puts( -1 ); n     return 0; n   } n   printf( %d n , mnc); n   for (int i = 1; i <= m; ++i) { n     if (!adj[E[i]]) n       putchar( R ); n     else if (!adj[E[i] + 2]) n       putchar( B ); n     else n       putchar( U ); n   } n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int C = 26; n void add(int &x, int y) { n   x += y; n   while (x >= MOD) x -= MOD; n   while (x < 0) x += MOD; n } n int fix(int x) { n   while (x >= MOD) x -= MOD; n   while (x < 0) x += MOD; n   return x; n } n int pw(int a, int b) { n   int ret = 1; n   while (b) { n     if (b & 1) ret = 1ll * ret * a % MOD; n     b >>= 1; n     a = 1ll * a * a % MOD; n   } n   return ret; n } n const int MAXN = 105; n int n, m, dp[MAXN][MAXN], l[MAXN][MAXN], r[MAXN][MAXN]; n void solve() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     for (int rep = 0; rep < k; rep++) { n       int a, b; n       cin >> a >> b; n       --a; n       for (int j = a; j < b; j++) { n         r[i][j] = b; n         l[i][j] = a; n       } n     } n   } n   for (int b = m - 1; ~b; --b) { n     for (int e = b + 1; e <= m; e++) { n       for (int k = b; k < e; k++) { n         int val = 0; n         for (int i = 0; i < n; i++) n           if (b <= l[i][k] && r[i][k] <= e) ++val; n         dp[b][e] = max(dp[b][e], val * val + dp[b][k] + dp[k + 1][e]); n       } n     } n   } n   cout << dp[0][m] <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int te = 1; n   for (int w = 1; w <= te; w++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, o, p, x, y, z; n vector<long long> a, b, c, d; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     cin >> n; n     string s; n     cin >> s; n     int leftFirst = -1; n     int rightFirst = -1; n     for (long long i = 0; i < n; i++) n       if (s[i] ==  1 ) { n         leftFirst = i; n         break; n       } n     for (long long i = 0; i < n; i++) n       if (s[i] ==  1 ) { n         rightFirst = i; n       } n     if (leftFirst == -1) { n       cout << n << endl; n       continue; n     } n     if (rightFirst >= n - leftFirst) { n       cout << 2 * (rightFirst + 1) << endl; n     } else n       cout << 2 * (n - leftFirst) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int n, m, jm; n long long ans; n int main() { n   cin >> n >> m >> jm; n   ans = ceil(1.0 * n / jm) * ceil(1.0 * m / jm) * ((n - 1) % jm + 1) * n         ((m - 1) % jm + 1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int N = 2e5 + 10, M = 1e6 + 10; n long long f(long long x) { n   long long y = x + 1; n   if (x & 2) n     y /= 2; n   else n     x /= 2; n   return x * y; n } n void solve() { n   long long n; n   scanf( %lld , &n); n   long long x = 3, cnt = 1; n   n--; n   while (1) { n     long long t = f(x); n     if (t > n) break; n     cnt++; n     n -= t; n     x = (x << 1) + 1; n   } n   printf( %lld n , cnt); n } n int main() { n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> n >> k; n   string s[n]; n   set<string> store; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n     store.insert(s[i]); n   } n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     set<string> v; n     store.erase(s[i]); n     for (int j = i + 1; j < n; j++) { n       v.insert(s[j]); n       store.erase(s[j]); n       string temp; n       for (int l = 0; l < k; l++) { n         if (s[i][l] == s[j][l]) { n           temp += s[i][l]; n         } else { n           temp += ( S  +  E  +  T  - s[i][l] - s[j][l]); n         } n       } n       if (store.find(temp) != store.end()) { n         cnt++; n         v.insert(temp); n         store.erase(temp); n       } n     } n     for (auto it : v) { n       store.insert(it); n     } n   } n   cout << cnt <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug; n const int inf = 1e9 + 5; n const long long INF = (long long)inf * inf; n const int nax = 1e6 + 5; n const int D = 2; n const long long MM = 1000 * 1000 * 1000; n const long long m[5] = {MM + 7, MM + 9, MM + 21, MM + 33, 333333361LL}; n char sl[nax]; n long long preh[nax][D]; n int n; n long long potega[nax][D]; n long long h(pair<int, int> a, int j) { n   long long x = preh[a.second][j]; n   if (a.first) x -= preh[a.first - 1][j]; n   if (x < 0) x += m[j]; n   x = (x * potega[n - a.first][j]) % m[j]; n   return x; n } n bool rowne(pair<int, int> a, pair<int, int> b) { n   for (int j = 0; j <= (D)-1; ++j) n     if (h(a, j) != h(b, j)) return false; n   return true; n } n int porow(pair<int, int> a, pair<int, int> b) { n   assert(a.second - a.first == b.second - b.first); n   if (a.first > a.second) return true; n   if (rowne(a, b)) return 1; n   int low = 0, high = a.second - a.first; n   while (low != high) { n     int med = (low + high) / 2; n     if (rowne(make_pair(a.first, a.first + med), n               make_pair(b.first, b.first + med))) n       low = med + 1; n     else n       high = med; n   } n   if (sl[a.first + low] ==  ( ) return 0; n   return 2; n } n int pref[nax]; n int LICZ; n const int pot = 1024 * 1024; n int tr[2 * pot]; n int mi(int a, int b) { n   a += pot; n   b += pot; n   int ku = min(tr[a], tr[b]); n   while (a < b - 1) { n     ku = min(ku, tr[a + 1]); n     ku = min(ku, tr[b - 1]); n     a /= 2; n     b /= 2; n   } n   return ku; n } n bool ok_podzial_szybkie(int i) { n   int s1 = pref[i]; n   int s2 = LICZ - pref[i]; n   int k = 0; n   if (LICZ < 0) k = -LICZ; n   if (i + 1 <= n - 1 && k + mi(i + 1, n - 1) - s1 < 0) return false; n   if (0 <= i && k + s2 + mi(0, i) < 0) return false; n   return true; n } n bool ok_podzial(int i) { n   int teraz = 0; n   if (LICZ < 0) teraz = -LICZ; n   for (int j = i + 1; j <= n - 1; ++j) { n     if (sl[j] ==  ( ) n       ++teraz; n     else n       --teraz; n     if (teraz < 0) return false; n   } n   for (int j = 0; j <= i; ++j) { n     if (sl[j] ==  ( ) n       ++teraz; n     else n       --teraz; n     if (teraz < 0) return false; n   } n   return true; n } n int best = -1; n bool jebaj(int i) { n   if (best == -1) return true; n   int kon = best + 1 + (n - 1 - (i + 1)); n   int pom = porow(make_pair(best + 1, kon), make_pair(i + 1, n - 1)); n   if (pom == 0) return false; n   if (pom == 2) return true; n   int kon2 = n - 1 - (kon + 1); n   pom = porow(make_pair(kon + 1, n - 1), make_pair(0, kon2)); n   if (pom == 0) return false; n   if (pom == 2) return true; n   pom = porow(make_pair(0, best), make_pair(kon2 + 1, i)); n   if (pom == 0) return false; n   return true; n } n int main(int argc, char *argv[]) { n   debug = argc > 1; n   scanf( %s , sl); n   n = strlen(sl); n   for (int i = 0; i <= (n)-1; ++i) { n     if (i) pref[i] = pref[i - 1]; n     if (sl[i] ==  ( ) n       pref[i]++; n     else n       pref[i]--; n   } n   for (int i = 0; i <= (2 * pot) - 1; ++i) tr[i] = inf; n   for (int i = 0; i <= (n)-1; ++i) tr[pot + i] = pref[i]; n   for (int i = pot - 1; i >= 1; --i) tr[i] = min(tr[2 * i], tr[2 * i + 1]); n   LICZ = 0; n   for (int i = 0; i <= (n)-1; ++i) { n     if (sl[i] ==  ( ) n       ++LICZ; n     else n       --LICZ; n   } n   for (int j = 0; j <= (D)-1; ++j) { n     potega[0][j] = 1; n     for (int i = 1; i <= n; ++i) n       potega[i][j] = ((j == 2 ? 3 : 2) * potega[i - 1][j]) % m[j]; n   } n   for (int j = 0; j <= (D)-1; ++j) n     for (int i = 0; i <= (n)-1; ++i) { n       int teraz = int(sl[i] ==  ( ); n       preh[i][j] = ((i ? preh[i - 1][j] : 0LL) + teraz * potega[i][j]) % m[j]; n     } n   for (int i = 0; i <= (n)-1; ++i) n     if (ok_podzial_szybkie(i)) n       if (jebaj(i)) best = i; n   assert(best != -1); n   if (LICZ < 0) n     for (int _ = 0; _ <= (-LICZ) - 1; ++_) printf( ( ); n   for (int j = best + 1; j <= n - 1; ++j) printf( %c , sl[j]); n   for (int j = 0; j <= best; ++j) printf( %c , sl[j]); n   if (LICZ > 0) n     for (int _ = 0; _ <= (LICZ)-1; ++_) printf( ) ); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n inline int read() { n   int x = 0, f = 0; n   register char ch = getchar(); n   for (; ch < 48 || ch > 57; ch = getchar()) f |= ch ==  - ; n   for (; ch > 47 && ch < 58; ch = getchar()) n     x = (x << 1) + (x << 3) + (ch ^ 48); n   return f ? ~x + 1 : x; n } n using namespace std; n int t[7005], l[7005], r[7005], x[7005], pos[7005][2], cnt; n set<int> s; n int main() { n   int n = read(), m = read(); n   for (int i = 0; i < m; ++i) { n     int k = read(); n     if (k == 1) n       t[++cnt] = read(), l[cnt] = read(), r[cnt] = read(), x[cnt] = read(); n     else { n       int lvl = read(); n       pos[lvl][1] = pos[lvl][0] = read(); n       s.clear(); n       for (int i = lvl; i < n; ++i) { n         int k = pos[i][0], j = 0, c = 0; n         for (; k; k >>= 1, ++j) c += k & 1; n         pos[i + 1][0] = pos[i][0] + j - (c == 1); n         k = pos[i][1], j = 0; n         for (; k; k >>= 1, ++j) n           ; n         pos[i + 1][1] = pos[i][1] + j; n       } n       for (int i = 1; i <= cnt; ++i) n         if (t[i] >= lvl && (l[i] <= pos[t[i]][0] && pos[t[i]][0] <= r[i] || n                             l[i] <= pos[t[i]][1] && pos[t[i]][1] <= r[i] || n                             pos[t[i]][0] <= l[i] && r[i] <= pos[t[i]][1])) n           s.insert(x[i]); n       printf( %d n , s.size()); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct { n   long long loc; n   long long num; n } amar; n bool operator<(amar x, amar y) { n   if (x.num >= y.num) n     return false; n   else n     return true; n } n int main() { n   long long n, k, c[40]; n   char s[100005]; n   memset(c, 0, sizeof c); n   cin >> n >> k >> s; n   for (long long i = 0; i < n; i++) { n     c[s[i] -  A ]++; n   } n   priority_queue<amar> a; n   amar tmp; n   for (long long i = 0; i < 40; i++) { n     tmp.loc = i; n     tmp.num = c[i]; n     a.push(tmp); n   } n   long long ans = 0; n   while (k > 0 && !a.empty()) { n     tmp = a.top(); n     if (k >= tmp.num) { n       ans += (tmp.num * tmp.num); n       k -= tmp.num; n     } else if (k < tmp.num) { n       ans += k * k; n       k = 0; n     } n     a.pop(); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7, inv = 5e8 + 4; n long long n, m, k; n long long pow(long long base, long long exp) { n   long long res = 1; n   while (exp) { n     if (exp & 1) (res *= base) %= mod; n     exp >>= 1; n     (base *= base) %= mod; n   } n   return res; n } n int main() { n   cin >> n >> m >> k; n   --n; n   --m; n   if (k == -1 && n + m & 1) n     cout << 0; n   else n     cout << pow(pow(2, n), m); n } n


#include <bits/stdc++.h> n using namespace std; n vector<bool> flag_pr(10001000, 0), flag_pal(10001000, 0); n vector<long long> prime_upto(10001000, 0), palin_upto(10001000, 0); n int gcd(int a, int b) { n   if (a % b == 0) n     return b; n   else n     return gcd(b, a % b); n } n bool isPalin(int num) { n   int ret = 0, n = num; n   while (n > 0) { n     int val = (n / 10) * 10; n     int dig = n - val; n     ret = ret * 10 + dig; n     n /= 10; n   } n   if (ret == num) n     return true; n   else n     return false; n } n void init() { n   flag_pr[2] = 1; n   for (int i = 3; i * i < 10001000; i += 2) n     if (!flag_pr[i]) n       for (int j = 2 * i; j < 10001000; j += i) flag_pr[j] = 1; n   prime_upto[2] = 1; n   for (int i = 3; i < 10001000; i++) { n     if (i & 1) { n       prime_upto[i] = prime_upto[i - 1] + (flag_pr[i] == 0 ? 1 : 0); n     } else { n       prime_upto[i] = prime_upto[i - 1]; n     } n   } n   for (int i = 1; i < 10001000; i++) { n     if (i == 1) n       palin_upto[i] = 1; n     else { n       palin_upto[i] = palin_upto[i - 1] + isPalin(i); n     } n   } n   return; n } n void solve() { n   int p, q; n   cin >> p >> q; n   int g = gcd(p, q); n   p /= g; n   q /= g; n   int ret = -1; n   for (int i = 1; i < 10001000; i++) { n     if (q * prime_upto[i] <= p * palin_upto[i]) { n       ret = max(ret, i); n     } n   } n   cout << ret <<   n ; n   return; n } n int main() { n   init(); n   solve(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long int func(vector<vector<long long int>> &d, vector<int> &v, int i, n                    int k) { n   if (d[k][i - 1] != 0) return d[k][i - 1]; n   if (k && (i + v[i - 1] <= d[0].size())) { n     d[k][i - 1] = -1; n     long long int y = func(d, v, i + v[i - 1], 1 - k); n     if (y != -1) y += v[i - 1]; n     return d[k][i - 1] = y; n   } else if (k) n     return d[k][i - 1] = v[i - 1]; n   else if (i - v[i - 1] > 0) { n     d[k][i - 1] = -1; n     long long int y = func(d, v, i - v[i - 1], 1 - k); n     if (y != -1) y += v[i - 1]; n     return d[k][i - 1] = y; n   } else n     return d[k][i - 1] = v[i - 1]; n } n int main() { n   long long int n, x, y, k = 1; n   cin >> n; n   vector<int> v; n   v.push_back(0); n   for (int i = 0; i < n - 1; i++) { n     cin >> x; n     v.push_back(x); n   } n   vector<vector<long long int>> d(2, vector<long long int>(n, 0)); n   for (int i = 1; i < n; i++) { n     y = 0; n     v[0] = i; n     d[1][0] = d[0][0] = -1; n     y = func(d, v, v[0] + 1, 0); n     if (y != -1) y += i; n     cout << y << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void maxtt(T& t1, T t2) { n   t1 = max(t1, t2); n } n template <typename T> n void mintt(T& t1, T t2) { n   t1 = min(t1, t2); n } n bool debug = 0; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n string direc =  RDLU ; n long long ln, lk, lm; n void etp(bool f = 0) { n   puts(f ?  YES  :  NO ); n   exit(0); n } n void addmod(int& x, int y, int mod = 998244353) { n   assert(y >= 0); n   x += y; n   if (x >= mod) x -= mod; n   assert(x >= 0 && x < mod); n } n void et(int x = -1) { n   printf( %d n , x); n   exit(0); n } n long long fastPow(long long x, long long y, int mod = 998244353) { n   long long ans = 1; n   while (y > 0) { n     if (y & 1) ans = (x * ans) % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ans; n } n long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; } n struct Point { n   int x, y; n   Point() {} n   Point(int x, int y) : x(x), y(y) {} n   long double abs() const { return hypot(x, y); } n   long double arg() const { return atan2(y, x); } n   Point operator*(double o) const { return Point(x * o, y * o); } n   Point operator+(const Point& o) const { return Point(x + o.x, y + o.y); } n   Point operator-(const Point& o) const { return Point(x - o.x, y - o.y); } n   Point operator/(double o) const { return Point(x / o, y / o); } n   bool operator<(const Point& o) const { n     return x < o.x - 1e-9 || (x < o.x + 1e-9 && y < o.y - 1e-9); n   } n   friend bool operator==(const Point& r1, const Point& r2) { n     return r1.x == r2.x && r1.y == r2.y; n   } n   int cross(Point b) const { return x * b.y - b.x * y; } n   void readin() { scanf( %d%d , &x, &y); } n   void pp() { printf( %d %d n , x, y); } n } a[6135], b[6135]; n int r[6135]; n void cal(vector<int> A, vector<int> B) { n   if (A.size() == 1) { n     if (!debug) n       for (int z : B) printf( %d %d n , z, A[0]); n     return; n   } n   if (B.size() == 1) { n     if (!debug) n       for (int z : A) printf( %d %d n , B[0], z); n     return; n   } n   assert(A.size() > 1 && B.size() > 1); n   int mxR = 0, tar = -1; n   for (int z : B) n     if (mxR < r[z]) { n       tar = z; n       mxR = r[z]; n     } n   vector<pair<long double, int>> vp; n   for (int z : A) { n     vp.push_back({(a[z] - b[tar]).arg(), z + m}); n   } n   for (int z : B) n     if (z != tar) { n       vp.push_back({(b[z] - b[tar]).arg(), z}); n     } n   sort(vp.begin(), vp.end()); n   int N = vp.size(), S = 0; n   for (int i = 0, j = -1; i < N; i++) { n     j = max(i, j); n     if (i == j) { n       S += 1 - r[vp[i].second]; n       j++; n     } n     Point cur = vp[i].second <= m ? b[vp[i].second] : a[vp[i].second - m]; n     cur = cur - b[tar]; n     while (1) { n       int id = vp[j % N].second; n       Point tt = id <= m ? b[id] : a[id - m]; n       tt = tt - b[tar]; n       if (tt.cross(cur) < 0) { n         S += 1 - r[id]; n         j++; n       } else n         break; n     } n     if (S >= 1 && S <= mxR - 1) { n       r[tar] = S; n       vector<int> ta, tb; n       tb.push_back(tar); n       for (int z = i; z < j; z++) { n         int id = vp[z % N].second; n         if (id <= m) n           tb.push_back(id); n         else n           ta.push_back(id - m); n       } n       cal(ta, tb); n       r[tar] = mxR - S; n       ta.clear(); n       tb.clear(); n       tb.push_back(tar); n       for (int z = j;; z++) { n         if (z % N == i) break; n         int id = vp[z % N].second; n         if (id <= m) n           tb.push_back(id); n         else n           ta.push_back(id - m); n       } n       cal(ta, tb); n       break; n     } n     S -= 1 - r[vp[i].second]; n   } n } n void fmain(int tid) { n   scanf( %d%d , &n, &m); n   for (int(i) = 1; (i) <= (int)(m); (i)++) { n     scanf( %d , r + i); n   } n   for (int(i) = 1; (i) <= (int)(n); (i)++) r[m + i] = 0; n   for (int(i) = 1; (i) <= (int)(n); (i)++) a[i].readin(); n   for (int(j) = 1; (j) <= (int)(m); (j)++) b[j].readin(); n   vector<int> A, B; n   for (int(i) = 1; (i) <= (int)(n); (i)++) A.push_back(i); n   for (int(j) = 1; (j) <= (int)(m); (j)++) B.push_back(j); n   if (!debug) puts( YES ); n   cal(A, B); n } n int main() { n   int t = 1; n   scanf( %d , &t); n   for (int(i) = 1; (i) <= (int)(t); (i)++) { n     fmain(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, y, q; n void exgcd(int a, int b) { n   int temp; n   if (b == 0) { n     x = 1; n     y = 0; n     q = a; n   } else { n     exgcd(b, a % b); n     temp = x; n     x = y; n     y = temp - a / b * y; n   } n } n int c3, c4, c5; n int k3, k4, k5; n int f, x0, Why_Cant_I_Use_y0_In_Eclipse; n int up, down; n void init() { n   up = 0xfffffff; n   down = -0xfffffff; n   down = max(down, (-x * f) / x0); n   if (x * f + x0 * down < 0) down++; n   up = min(up, (k4 - x * f) / x0); n   if (x * f + x0 * up > k4) up--; n   up = min(up, (y * f - k4) / Why_Cant_I_Use_y0_In_Eclipse); n   if (y * f - Why_Cant_I_Use_y0_In_Eclipse * up < k4) up--; n } n int o3, o4, o5; n int ans; n void get_o(int t) { n   o3 = x * f + x0 * t; n   o4 = k4; n   o5 = y * f - Why_Cant_I_Use_y0_In_Eclipse * t; n } n void solve(int s) { n   exgcd(c3, c5); n   if (s % q != 0) return; n   f = s / q; n   x0 = c5 / q; n   Why_Cant_I_Use_y0_In_Eclipse = c3 / q; n   { n     init(); n     down = max(down, (c4 * k4 - c3 * x * f) / (c3 * x0)); n     if (c3 * x * f + c3 * x0 * down < c4 * k4) down++; n     up = min(up, (c5 * y * f - c4 * k4) / (c5 * Why_Cant_I_Use_y0_In_Eclipse)); n     if (c5 * y * f - c4 * k4 < c5 * Why_Cant_I_Use_y0_In_Eclipse * up) up--; n     if (down <= up) { n       int judge = s - 2 * c4 * k4; n       if (judge < ans) { n         ans = judge; n         get_o(down); n       } n     } n   } n   { n     init(); n     up = min(up, (c4 * k4 - c3 * x * f) / (c3 * x0)); n     if (c4 * k4 - c3 * x * f < c3 * x0 * up) up--; n     down = n         max(down, (c5 * y * f - c4 * k4) / (c5 * Why_Cant_I_Use_y0_In_Eclipse)); n     if (c5 * y * f - c5 * Why_Cant_I_Use_y0_In_Eclipse * down > c4 * k4) down++; n     if (down <= up) { n       int judge = 2 * c4 * k4 - s; n       if (judge < ans) { n         ans = judge; n         get_o(up); n       } n     } n   } n   { n     init(); n     down = max(down, (c4 * k4 - c3 * x * f) / (c3 * x0)); n     if (c3 * x * f + c3 * x0 * down < c4 * k4) down++; n     down = n         max(down, (c5 * y * f - c4 * k4) / (c5 * Why_Cant_I_Use_y0_In_Eclipse)); n     if (c5 * y * f - c5 * Why_Cant_I_Use_y0_In_Eclipse * down > c4 * k4) down++; n     if (down <= up) { n       int judge = c3 * (x * f + x0 * down) - n                   c5 * (y * f - Why_Cant_I_Use_y0_In_Eclipse * down); n       if (judge < ans) { n         ans = judge; n         get_o(down); n       } n     } n   } n   { n     init(); n     up = min(up, (c4 * k4 - c3 * x * f) / (c3 * x0)); n     if (c4 * k4 - c3 * x * f < c3 * x0 * up) up--; n     up = min(up, (c5 * y * f - c4 * k4) / (c5 * Why_Cant_I_Use_y0_In_Eclipse)); n     if (c5 * y * f - c4 * k4 < c5 * Why_Cant_I_Use_y0_In_Eclipse * up) up--; n     if (down <= up) { n       int judge = -c3 * (x * f + x0 * up) + n                   c5 * (y * f - Why_Cant_I_Use_y0_In_Eclipse * up); n       if (judge < ans) { n         ans = judge; n         get_o(up); n       } n     } n   } n } n int main() { n   int n, s; n   scanf( %d %d , &n, &s); n   c3 = c4 = c5 = 0; n   while (n--) { n     int f; n     scanf( %d , &f); n     if (f == 3) c3++; n     if (f == 4) c4++; n     if (f == 5) c5++; n   } n   ans = 0xfffffff; n   for (int i = 0; i <= s; i++) { n     if (c4 * i > s) break; n     k4 = i; n     solve(s - c4 * k4); n   } n   if (ans == 0xfffffff) n     printf( -1 n ); n   else { n     printf( %d %d %d n , o3, o4, o5); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long int, long long int> mp; n int main() { n   int n, c = 0, x = 0, a[200], i, j; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     c += a[i]; n   } n   if (n == 1) x = 1; n   if (n == 2 && a[0] == a[1]) x = 1; n   if (x == 1) n     cout << -1; n   else { n     cout << 1 << endl; n     for (i = 0; i < n; i++) { n       if (2 * a[i] != c) { n         cout << i + 1; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxN = 5e4 + 7; n const int inf = 1e5 + 7; n const long long mod = 1e5 + 7; n const long long infll = 1e18 + 7; n long long a[mxN], b[mxN]; n map<long long, bool> mp; n int n; n bool check = false; n bool ok(long long x) { n   for (int i = 1; i <= n; i++) a[i] = b[i]; n   mp.clear(); n   for (int i = 1; i <= n; i++) { n     if (a[i] <= x) { n       if (mp[a[i]] == true) { n         while (mp[a[i]] == true && a[i] != 1) { n           a[i] /= 2; n         } n         if (mp[a[i]] == true) return false; n       } n       mp[a[i]] = true; n     } else { n       while ((a[i] > x || mp[a[i]] == true) && a[i] != 1) { n         a[i] /= 2; n       } n       if (mp[a[i]] == true) return false; n       mp[a[i]] = true; n     } n     if (check == true) cout << a[i] <<    ; n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + 1 + n); n   for (int i = 1; i <= n; i++) b[i] = a[i]; n   long long l = 0; n   long long r = infll; n   while (l + 1 < r) { n     long long m = (l + r) / 2; n     if (ok(m)) n       r = m; n     else n       l = m; n   } n   check = true; n   ok(r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n int n, a[300100], q; n struct node { n   int x; n   int val; n }; n bool operator<(node a, node b) { return a.val < b.val; } n priority_queue<node> heap; n set<int> tree; n int main() { n   n = read(), q = read(); n   for (int i = 1; i <= n; ++i) { n     a[i] = read(); n     tree.insert(a[i]); n   } n   sort(a + 1, a + 1 + n); n   for (int i = 1; i < n; ++i) { n     heap.push({a[i], a[i + 1] - a[i]}); n   } n   if (tree.size() <= 2) { n     puts( 0 ); n   } else { n     cout << (*(--tree.end())) - (*tree.begin()) - heap.top().val << endl; n   } n   for (int i = 1; i <= q; ++i) { n     int t = read(), p = read(); n     if (t == 0) { n       set<int>::iterator it; n       it = tree.lower_bound(p); n       set<int>::iterator lst = it; n       lst--; n       if (it != tree.end()) { n         set<int>::iterator nxt = it; n         nxt++; n         heap.push({(*lst), (*nxt) - (*lst)}); n         tree.erase(it); n       } n     } else { n       tree.insert(p); n       set<int>::iterator it; n       it = tree.lower_bound(p); n       set<int>::iterator nxt = it; n       nxt++; n       set<int>::iterator lst = it; n       lst--; n       heap.push({(*lst), (*it) - (*lst)}); n       heap.push({(*it), (*nxt) - (*it)}); n     } n     bool flag = false; n     do { n       flag = false; n       int x = heap.top().x, val = heap.top().val; n       set<int>::iterator it; n       it = tree.find(x); n       set<int>::iterator nxt = it; n       if (it != tree.end()) nxt++; n       if (it == tree.end() || nxt == tree.end()) { n         heap.pop(); n         flag = true; n       } else { n         if (val != (*nxt) - (*it)) { n           heap.pop(); n           flag = true; n         } n       } n     } while (flag && heap.size()); n     if (tree.size() <= 2) { n       puts( 0 ); n     } else { n       cout << (*(--tree.end())) - (*tree.begin()) - heap.top().val; n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000051; n long long n; n string c; n struct btree { n   int chnum; n   int child[2]; n   int num; n   int typ; n   int id; n } tre[N]; n int dfx[N][2]; n int tot = 0; n int has[N]; n void predfs(int x) { n   if (tre[x].typ == 0) return; n   if (tre[x].typ == 1) { n     predfs(tre[x].child[0]); n     predfs(tre[x].child[1]); n     tre[x].num = tre[tre[x].child[0]].num & tre[tre[x].child[1]].num; n   } n   if (tre[x].typ == 2) { n     predfs(tre[x].child[0]); n     predfs(tre[x].child[1]); n     tre[x].num = tre[tre[x].child[0]].num | tre[tre[x].child[1]].num; n   } n   if (tre[x].typ == 3) { n     predfs(tre[x].child[0]); n     predfs(tre[x].child[1]); n     tre[x].num = tre[tre[x].child[0]].num ^ tre[tre[x].child[1]].num; n   } n   if (tre[x].typ == 4) { n     predfs(tre[x].child[0]); n     tre[x].num = !tre[tre[x].child[0]].num; n   } n } n void dfs(int x) { n   if (tre[x].typ == 0) has[tre[x].id] = dfx[tot][tre[x].num ^ 1]; n   if (tre[x].typ == 1) { n     tot++; n     dfx[tot][0] = dfx[tot - 1][0 & tre[tre[x].child[1]].num]; n     dfx[tot][1] = dfx[tot - 1][1 & tre[tre[x].child[1]].num]; n     dfs(tre[x].child[0]); n     dfx[tot][0] = dfx[tot - 1][0 & tre[tre[x].child[0]].num]; n     dfx[tot][1] = dfx[tot - 1][1 & tre[tre[x].child[0]].num]; n     dfs(tre[x].child[1]); n     tot--; n   } n   if (tre[x].typ == 2) { n     tot++; n     dfx[tot][0] = dfx[tot - 1][0 | tre[tre[x].child[1]].num]; n     dfx[tot][1] = dfx[tot - 1][1 | tre[tre[x].child[1]].num]; n     dfs(tre[x].child[0]); n     dfx[tot][0] = dfx[tot - 1][0 | tre[tre[x].child[0]].num]; n     dfx[tot][1] = dfx[tot - 1][1 | tre[tre[x].child[0]].num]; n     dfs(tre[x].child[1]); n     tot--; n   } n   if (tre[x].typ == 3) { n     tot++; n     dfx[tot][0] = dfx[tot - 1][0 ^ tre[tre[x].child[1]].num]; n     dfx[tot][1] = dfx[tot - 1][1 ^ tre[tre[x].child[1]].num]; n     dfs(tre[x].child[0]); n     dfx[tot][0] = dfx[tot - 1][0 ^ tre[tre[x].child[0]].num]; n     dfx[tot][1] = dfx[tot - 1][1 ^ tre[tre[x].child[0]].num]; n     dfs(tre[x].child[1]); n     tot--; n   } n   if (tre[x].typ == 4) { n     tot++; n     dfx[tot][0] = dfx[tot - 1][1]; n     dfx[tot][1] = dfx[tot - 1][0]; n     dfs(tre[x].child[0]); n     tot--; n   } n } n void init() { n   cin >> n; n   for (int i = 1; i <= n; i++) has[i] = -1; n   for (int i = 1; i <= n; i++) { n     cin >> c; n     tre[i].id = i; n     if (c ==  IN ) { n       tre[i].chnum = 0; n       tre[i].typ = 0; n       scanf( %d , &tre[i].num); n     } n     if (c ==  AND ) { n       tre[i].chnum = 2; n       tre[i].typ = 1; n       tre[i].num = -1; n       scanf( %d%d , &tre[i].child[0], &tre[i].child[1]); n     } n     if (c ==  OR ) { n       tre[i].chnum = 2; n       tre[i].typ = 2; n       tre[i].num = -1; n       scanf( %d%d , &tre[i].child[0], &tre[i].child[1]); n     } n     if (c ==  XOR ) { n       tre[i].chnum = 2; n       tre[i].typ = 3; n       tre[i].num = -1; n       scanf( %d%d , &tre[i].child[0], &tre[i].child[1]); n     } n     if (c ==  NOT ) { n       tre[i].chnum = 1; n       tre[i].typ = 4; n       tre[i].num = -1; n       scanf( %d , &tre[i].child[0]); n     } n   } n   dfx[0][0] = 0; n   dfx[0][1] = 1; n   predfs(1); n   dfs(1); n   for (int i = 1; i <= n; i++) n     if (has[i] != -1) printf( %d , has[i]); n   printf(  n ); n } n int main() { n   int T; n   T = 1; n   while (T--) init(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 2e5 + 15; n inline long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 1) + (x << 3) + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n long long T, n, tot, last, len[maxn], size[maxn], link[maxn], nxt[maxn][30]; n inline long long extend(long long last, long long x) { n   long long now = ++tot, pos = last, tmp, cln; n   len[now] = len[pos] + 1; n   size[now]++; n   while (pos != 0 && nxt[pos][x] == 0) nxt[pos][x] = now, pos = link[pos]; n   if (!pos) { n     link[now] = 1; n     return now; n   } n   tmp = nxt[pos][x]; n   if (len[tmp] == len[pos] + 1) { n     link[now] = tmp; n     return now; n   } n   cln = ++tot; n   len[cln] = len[pos] + 1; n   for (long long i = 1; i <= 26; i++) nxt[cln][i] = nxt[tmp][i]; n   link[cln] = link[tmp]; n   link[tmp] = link[now] = cln; n   while (pos != 0 && nxt[pos][x] == tmp) nxt[pos][x] = cln, pos = link[pos]; n   return now; n } n string s; n long long beg[maxn], nex[maxn], to[maxn], e; n inline void add(long long x, long long y) { n   e++; n   nex[e] = beg[x]; n   beg[x] = e; n   to[e] = y; n } n long long val[maxn], k; n inline void dfs(long long x) { n   for (long long i = beg[x]; i; i = nex[i]) dfs(to[i]), size[x] += size[to[i]]; n   val[size[x]] += (len[x] - len[link[x]]); n } n inline void pre() { n   for (long long i = 0; i <= tot; i++) { n     val[i] = beg[i] = len[i] = size[i] = link[i] = 0; n     for (long long j = 1; j <= 26; j++) nxt[i][j] = 0; n   } n   e = tot = 0; n } n signed main() { n   T = read(); n   while (T--) { n     pre(); n     cin >> s; n     n = s.size(); n     s =     + s; n     last = ++tot; n     for (long long i = 1; i <= n; i++) last = extend(last, s[i] - 96); n     for (long long i = 2; i <= tot; i++) add(link[i], i); n     dfs(1); n     long long ans = 0; n     for (long long i = n; i >= 1; i--) ans += val[i] * i * i; n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct poi { n   int x, y; n   poi operator-(poi p) { return (poi){x - p.x, y - p.y}; } n   long long operator*(poi p) { return 1ll * x * p.y - 1ll * y * p.x; } n } A[205], a[205]; n bool cmp(poi x, poi y) { return x * y > 0; } n bool turn(int x, int y, int z) { return (a[y] - a[x]) * (a[z] - a[y]) > 0; } n int b[205 << 1], v[205 * 205], f[205 * 205], tot; n int q[205][205], l[205], r[205]; n int n, nn, m; n long long d[205][205][55], w[55], ans; n void add(int x, int y) { v[++tot] = y, f[tot] = b[x], b[x] = tot; } n void link(int x, int y) { n   for (; l[x] < r[x] && turn(q[x][l[x]], x, y); ++l[x]) link(q[x][l[x]], y); n   add(x + nn, y); n   add(y, x); n   q[y][r[y]++] = x; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d%d , &A[i].x, &A[i].y); n   ans = 0; n   for (int i = 1; i <= n; ++i) { n     nn = 0; n     for (int j = 1; j <= n; ++j) n       if (i != j && A[i].x <= A[j].x) a[++nn] = A[j] - A[i]; n     sort(a + 1, a + nn + 1, cmp); n     memset(b, 0, sizeof b); n     tot = 0; n     memset(l, 0, sizeof l); n     memset(r, 0, sizeof r); n     for (int j = 1; j <= nn - 1; ++j) link(j, j + 1); n     for (int j = 1; j <= nn; ++j) n       for (int k = b[j + nn]; k; k = f[k]) n         for (int p = 0; p <= m; ++p) d[j][v[k]][p] = 0; n     for (int j = nn; j; --j) { n       memset(w, 0, sizeof w); n       int k = b[j + nn]; n       for (int p = b[j]; p; p = f[p]) { n         d[v[p]][j][0] = 0; n         d[v[p]][j][1] = a[v[p]] * a[j]; n         for (int u = 2; u <= m; ++u) n           d[v[p]][j][u] = w[u - 1] > 0 ? w[u - 1] + a[v[p]] * a[j] : 0; n         for (; k && turn(v[p], j, v[k]); k = f[k]) n           for (int u = 1; u <= m; ++u) n             if (d[j][v[k]][u - 1] > w[u - 1]) n               w[u - 1] = d[j][v[k]][u - 1], n                     d[v[p]][j][u] = w[u - 1] + a[v[p]] * a[j]; n       } n     } n     for (int j = 1; j <= nn; ++j) n       for (int k = b[j + nn]; k; k = f[k]) ans = max(ans, d[j][v[k]][m - 2]); n   } n   printf( %lld , ans >> 1); n   puts(ans & 1 ?  .50  :  .00 ); 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 t; n   cin >> t; n   while (t--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     cout << max(a + b, c + d) <<   n ; n   } n   return 0; n } n