#include <bits/stdc++.h> n using namespace std; n int N, T, L, R, X, H; n unordered_map<int, int> siz; n unordered_map<int, pair<int, int> > par; n pair<int, int> find(int now) { n   if (par.count(now)) { n     pair<int, int> a, b; n     a = par[now]; n     b = find(a.first); n     return {b.first, a.second ^ b.second}; n   } n   return {now, 0}; n } n int getsize(int now) { n   if (!siz.count(now)) { n     siz[now] = 1; n   } n   return siz[now]; n } n void merge(int x, int y, int z) { n   pair<int, int> a, b; n   a = find(x); n   b = find(y); n   if (a.first == b.first) { n     return; n   } n   if (getsize(a.first) > getsize(b.first)) { n     par[b.first] = {a.first, z ^ a.second ^ b.second}; n     siz[a.first] += siz[b.first]; n   } else { n     par[a.first] = {b.first, z ^ a.second ^ b.second}; n     siz[b.first] += siz[a.first]; n   } n   return; n } n int ans(int x, int y) { n   pair<int, int> a, b; n   a = find(x); n   b = find(y); n   if (a.first != b.first) { n     return -1; n   } n   return a.second ^ b.second; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> N; n   for (int i = 0; i < N; i++) { n     cin >> T >> L >> R; n     L ^= H; n     R ^= H; n     if (L > R) { n       swap(L, R); n     } n     if (T == 1) { n       cin >> X; n       X ^= H; n       merge(L - 1, R, X); n     } else { n       H = ans(L - 1, R); n       cout << H <<   n ; n       if (H == -1) { n         H = 1; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n using namespace std; n template <typename T> n void chkmax(T &x, T y) { n   if (x < y) x = y; n } n template <typename T> n void chkmin(T &x, T y) { n   if (x > y) x = y; n } n inline int read() { n   int x = 0; n   char c = getchar(); n   bool f = 0; n   while (c < 48) f |= c ==  - , c = getchar(); n   while (c > 47) x = x * 10 + (c ^ 48), c = getchar(); n   return f ? -x : x; n } n const int maxn = 1e5 + 10, P = 998244353; n int Inc(int x, int y) { return x + y < P ? x + y : x + y - P; } n int Dec(int x, int y) { return x < y ? x - y + P : x - y; } n void Add(int &x, int y) { n   x += y; n   if (x >= P) x -= P; n } n void Sub(int &x, int y) { n   x -= y; n   if (x < 0) x += P; n } n int n, k, A[maxn], lev[maxn], dp[maxn], vp[maxn], lst[maxn]; n int bsz, bl[maxn]; n int ns, tag[505]; n int buf_top, buf_st[maxn * 100], nxt[maxn * 100], key[maxn * 100], n     val[maxn * 100]; n struct hashmap { n   int ct, h[1009]; n   int find(int x) { n     for (int i = h[(x + 114514) % 1009]; i; i = nxt[i]) n       if (key[i] == x) return i; n     return -1; n   } n   int query(int x) { n     int tp = find(x); n     return tp == -1 ? 0 : val[tp]; n   } n   void add(int x, int v) { n     int tp = find(x); n     if (tp != -1) { n       Add(val[tp], v); n     } else { n       int &p = h[(x + 114514) % 1009]; n       tp = buf_st[buf_top--], nxt[tp] = p, p = tp, key[tp] = x, val[tp] = v, n       ct++; n     } n   } n   void clear() { n     for (int x = (0), xend = (1008); x <= xend; ++x) { n       int &i = h[x]; n       while (i) { n         key[i] = val[i] = 0, buf_st[++buf_top] = i; n         int &tp = nxt[i]; n         i = tp, tp = 0; n       } n     } n   } n } ump[505]; n void pushdown(int ps) { n   int l = (ps - 1) * bsz + 1, r = min(n, ps * bsz); n   ump[ps].clear(); n   for (int i = (l), iend = (r); i <= iend; ++i) { n     ump[ps].add(lev[i] += tag[ps], dp[i - 1]); n   } n   tag[ps] = 0; n } n void upd(int l, int r, int x) { n   int ps = bl[l], &tp = tag[ps]; n   if (ump[ps].ct > 1000) pushdown(ps); n   for (int i = (l), iend = (r); i <= iend; ++i) { n     if (lev[i] + tp == -1 && x == 1) Add(ns, dp[i - 1]); n     if (lev[i] + tp == 0 && x == -1) Sub(ns, dp[i - 1]); n     if (dp[i - 1]) ump[ps].add(lev[i], P - dp[i - 1]); n     ump[ps].add(lev[i] += x, dp[i - 1]); n   } n } n void add(int l, int r, int x) { n   if (bl[l] == bl[r]) { n     upd(l, r, x); n     return; n   } n   upd(l, bl[l] * bsz, x); n   upd((bl[r] - 1) * bsz + 1, r, x); n   for (int ps = (bl[l] + 1), psend = (bl[r] - 1); ps <= psend; ++ps) { n     if (x == 1) { n       Add(ns, ump[ps].query(-1 - tag[ps])); n     } else { n       Sub(ns, ump[ps].query(-tag[ps])); n     } n     tag[ps] += x; n   } n } n void ins(int x, int v) { n   pushdown(bl[x]); n   if (lev[x] >= 0) Add(ns, v); n } n void solve() { n   buf_top = maxn * 100 - 1; n   for (int i = (1), iend = (maxn * 100 - 1); i <= iend; ++i) buf_st[i] = i; n   cin >> n >> k; n   bsz = 200; n   for (int i = (1), iend = (n); i <= iend; ++i) n     lev[i] = k, A[i] = read(), bl[i] = (i - 1) / bsz + 1; n   dp[0] = 1; n   for (int i = (1), iend = (n); i <= iend; ++i) { n     int &p = lst[i]; n     p = vp[A[i]], vp[A[i]] = i; n     if (p) add(lst[p] + 1, p, 1); n     add(p + 1, i, -1), ins(i, dp[i - 1]), dp[i] = ns; n   } n   cout << dp[n] << endl; n } n signed main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long tree[4000005]; n long long level[4000005]; n long long num[1000005]; n long long build(long long at, long long L, long long R) { n   if (L == R) { n     tree[at] = num[L]; n     level[at] = 1; n     return num[L]; n   } n   long long mid = (L + R) / 2, a, b, p; n   a = build(at * 2, L, mid); n   b = build(at * 2 + 1, mid + 1, R); n   level[at] = p = level[at * 2] + 1; n   if (p % 2) n     tree[at] = a ^ b; n   else n     tree[at] = a | b; n   return tree[at]; n } n long long update(long long at, long long L, long long R, long long i, n                  long long x) { n   if (L == R) { n     tree[at] = x; n     return tree[at]; n   } n   long long mid = (L + R) / 2, a, b; n   if (L <= i && mid >= i) n     a = update(at * 2, L, mid, i, x), b = tree[at * 2 + 1]; n   else n     a = update(at * 2 + 1, mid + 1, R, i, x), b = tree[at * 2]; n   if (level[at] % 2) n     tree[at] = a ^ b; n   else n     tree[at] = a | b; n   return tree[at]; n } n int main() { n   long long n, m; n   long long a, i, j; n   long long x, y; n   cin >> n >> m; n   n = pow(2, n); n   for (a = 1; a <= n; a++) cin >> num[a]; n   build(1, 1, n); n   for (a = 0; a < m; a++) { n     cin >> x >> y; n     update(1, 1, n, x, y); n     cout << tree[1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4 * 1e5 + 5; n vector<int> g[N]; n int n, dp[N], res[N]; n int dfs(int i, int p = -1) { n   dp[i] = 1; n   for (auto j : g[i]) { n     if (j != p) { n       dp[i] += dfs(j, i); n     } n   } n   return dp[i]; n } n int dfs2(int i, int p = -1) { n   for (auto j : g[i]) { n     if (j != p && dp[j] * 2 > n) { n       return dfs2(j, i); n     } n   } n   return i; n } n void dfs3(int i, int p, int c1, int c2) { n   if (c1 * 2 >= n) res[i] = 1; n   if ((dp[i] + c2) * 2 >= n) res[i] = 1; n   for (auto j : g[i]) { n     if (j != p) { n       dfs3(j, i, c1, c2); n     } n   } n } n int main() { n   std::ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i < n; ++i) { n     int a, b; n     cin >> a >> b; n     --a; n     --b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   dfs(0); n   int a = dfs2(0); n   dfs(a); n   res[a] = 1; n   int mx = -1, mx2 = -1, v; n   for (auto j : g[a]) { n     if (dp[j] > mx) { n       mx2 = mx; n       mx = dp[j]; n       v = j; n     } else if (dp[j] > mx2) { n       mx2 = dp[j]; n     } n   } n   for (auto j : g[a]) { n     if (j == v) n       dfs3(j, a, dp[j], mx2); n     else n       dfs3(j, a, dp[j], mx); n   } n   for (int i = 0; i < n; ++i) cout << res[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, persons, valids; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , &persons); n     if (persons + k <= 5) { n       valids++; n     } n   } n   printf( %d , valids / 3); n   return 0; n } n


#include <bits/stdc++.h> n const int M = 5500; n const double esp = 1e-6; n const double PI = 3.14159265359; n const int INF = 0x3f3f3f3f; n using namespace std; n struct node { n   double x, y, z; n } arr[M]; n double judge(node x, node y) { n   return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y) + n               (x.z - y.z) * (x.z - y.z)); n } n int main() { n   int n; n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; i++) { n       scanf( %lf %lf %lf , &arr[i].x, &arr[i].y, &arr[i].z); n     } n     double qmin = (double)INF; n     for (int i = 2; i <= n; i++) { n       for (int j = i + 1; j <= n; j++) { n         qmin = min(qmin, judge(arr[1], arr[i]) + judge(arr[1], arr[j]) + n                              judge(arr[i], arr[j])); n       } n     } n     printf( %lf n , qmin / 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int INF = 1e9 + 7; n const int N = 1010; n const double pi = 3.1415926; n int main() { n   char str[100010]; n   while (~scanf( %s , str)) { n     int len = strlen(str); n     int idx = INF, sum0 = 0, sum1 = 0; n     for (int i = 0; i < len; i++) { n       if (str[i] ==  2 ) { n         idx = i; n         break; n       } n       if (str[i] ==  1 ) sum1++; n       if (str[i] ==  0 ) sum0++; n     } n     for (int i = 0; i < sum0; i++) printf( 0 ); n     for (int i = 0; i < sum1; i++) printf( 1 ); n     sum1 = 0; n     for (int i = idx; i < len; i++) { n       if (str[i] ==  1 ) sum1++; n     } n     for (int i = 0; i < sum1; i++) printf( 1 ); n     for (int i = idx; i < len; i++) { n       if (str[i] !=  1 ) printf( %c , str[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> st; n int main() { n   int t, i, j, k, n, m; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     st.insert(x); n   } n   int a, b; n   scanf( %d , &a); n   scanf( %d , &b); n   set<int>::iterator it, cit; n   int ans = 0; n   while (1) { n     if (a == b) { n       cout << ans << endl; n       return 0; n     } n     int mx = 1; n     for (it = st.begin(); it != st.end();) { n       int val = *it; n       cit = it; n       it++; n       if (a - (a % val) < b) { n         st.erase(cit); n       } else { n         mx = max(mx, a % val); n       } n     } n     ans++; n     a = a - mx; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   int p; n   scanf( %I64d %I64d %d , &n, &k, &p); n   long long ndiv2 = n / 2; n   long long ndiv2minus1 = n / 2 - 1; n   long long nminusk = n - k; n   for (int i = 0; i < p; i++) { n     long long x; n     scanf( %I64d , &x); n     printf( %c , (((x == n) ? (n) n                             : (1 + (x / 2) * ndiv2 - n                                ((x - 1) / 2) * ndiv2minus1)) <= nminusk) n                      ? ( . ) n                      : ( X )); n   } n exit: n   return (0); n } n


#include <bits/stdc++.h> n char str1[200], str2[200]; n char lenstr1, lenstr2; n int dp1[200]; n int dp2[200]; n int got[200] = {0}; n int twice; n int twicep; n int countc; n int calel(int st) { n   int ite = st; n   int len = 1; n   for (int i = 0; i < lenstr2; i++) { n     int flag = 0; n     while (str1[st] != str2[i]) { n       st++; n       if (st == lenstr1) { n         len++; n         st = 0; n         if (flag) return 1; n         flag = 1; n       } n     } n     st++; n     if (st == lenstr1) { n       len++; n       st = 0; n     } n   } n   dp1[ite] = len; n   dp2[ite] = st; n   return 0; n } n int main() { n   int s1, s2; n   scanf( %d%d , &s1, &s2); n   scanf( %s%s , str1, str2); n   lenstr1 = strlen(str1); n   lenstr2 = strlen(str2); n   for (int i = 0; i < lenstr1; i++) n     if (calel(i)) { n       printf( 0 n ); n       return 0; n     } n   got[0] = 1; n   for (int i = 0;;) { n     int j = dp2[i]; n     if (got[j]) { n       twice = got[i] + dp1[i] - 1; n       twicep = j; n       break; n     } n     got[j] = got[i] + dp1[i] - 1; n     i = j; n   } n   if (twice >= s1) { n     countc = 0; n     int i, j; n     for (i = 0, j = 1; j <= s1;) { n       j += dp1[i] - 1; n       i = dp2[i]; n       countc++; n     } n     if (i == 0 && countc != 1) countc++; n   } else { n     countc = 0; n     int p1 = 1; n     for (int i = 0; i != twicep;) { n       p1 += dp1[i] - 1; n       i = dp2[i]; n       countc++; n     } n     int left = s1 - p1; n     int i = twicep; n     int single = 0; n     do { n       i = dp2[i]; n       single++; n     } while (i != twicep); n     int sinlen = twice - p1; n     countc += single * (left / sinlen); n     int p2 = p1 + left / sinlen * sinlen; n     for (i = twicep;;) { n       p2 += dp1[i] - 1; n       i = dp2[i]; n       if (p2 > s1) break; n       countc++; n     } n     if (i == 0) countc++; n   } n   printf( %d n , countc / s2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[400 + 2], ans = 1 << 30; n int main() { n   cin >> n; n   for (register int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = n; i >= 2; i--) { n     if (a[i] >= ans) break; n     for (int j = i; j <= n; j++) { n       register int num = a[i - 1] - 1, x = 1, t; n       for (register int k = i; k <= j; k++) n         if (num >= a[k]) { n           t = num / a[k]; n           x += t, num -= t * a[k]; n         } n       num = a[i - 1] - 1 - num + a[j]; n       int res = num; n       if (res < ans) { n         for (register int k = 1; k <= n; k++) n           if (num >= a[k]) { n             t = num / a[k]; n             x -= t, num -= t * a[k]; n             if (x < 0) break; n           } n         if (x < 0) ans = res; n       } n     } n   } n   if (ans == 1 << 30) ans = -1; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[101][4]; n int main() { n   int n; n   cin >> n; n   int min = 0, ind = 0; n   for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3]; n   min = 100000; n   ind = 0; n   for (int i = 0; i < n; i++) { n     bool ust = false; n     for (int j = 0; j < n; j++) n       if (i != j) n         if (a[i][0] < a[j][0] && a[i][1] < a[j][1] && a[i][2] < a[j][2]) { n           ust = true; n           break; n         } n     if (!ust) n       if (a[i][3] < min) { n         min = a[i][3]; n         ind = i; n       } n   } n   cout << ind + 1 << endl; n   return 0; n } n


#include <stdio.h> n #include <string.h> n #include <math.h> n #include <limits.h> n #include <time.h> n #include <vector> n #include <queue> n #include <stack> n #include <map> n #include <set> n #include <algorithm> n #pragma warning(disable:4996) n #pragma warning(disable:6031) n #define MAX(X,Y) (X>Y?X:Y) n #define MIN(X,Y) (X<Y?X:Y) n #define ll long long n #define pii pair<int,int> n using namespace std; n  n int t,n; n char str[201]; n  n int main() { n  scanf( %d , &t); n  while (t--) { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf(  %c , &str[i]); n   bool ans = false; n   if (str[0] ==  2 ) { n    if (str[1] ==  0 ) { n     if (str[2] ==  2 ) { n      if (str[3] ==  0 ) ans = true; n      else if (str[n - 1] ==  0 ) ans = true; n     } n     else if (str[n - 1] ==  0  && str[n - 2] ==  2 ) ans = true; n    } n    else if (str[n - 1] ==  0  && str[n - 2] ==  2  && str[n - 3] ==  0 ) ans = true; n   } n   else if (str[n - 1] ==  0  && str[n - 2] ==  2  && str[n - 3] ==  0  && str[n - 4] ==  2 ) ans = true; n   printf( %s n , (ans ?  YES  :  NO )); n  } n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n long long len = 0; n char ibuf[(1 << 20) + 1], *iS, *iT, out[(1 << 25) + 1]; n inline long long read() { n   char ch = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), n              (iS == iT ? EOF : *iS++) : *iS++); n   long long x = 0; n   char t = 0; n   while (ch <  0  || ch >  9 ) n     t |= ch ==  - , ch = (iS == iT ? iT = (iS = ibuf) + n                                           fread(ibuf, 1, (1 << 20) + 1, stdin), n                           (iS == iT ? EOF : *iS++) : *iS++); n   while (ch >=  0  && ch <=  9 ) n     x = x * 10 + (ch ^ 48), n     ch = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), n           (iS == iT ? EOF : *iS++) : *iS++); n   return t ? -x : x; n } n inline void putc(char ch) { out[len++] = ch; } n template <class T> n inline void write(T x) { n   if (x < 0) putc( - ), x = -x; n   if (x > 9) write(x / 10); n   out[len++] = x % 10 + 48; n } n string getstr(void) { n   string s =   ; n   char c = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), n             (iS == iT ? EOF : *iS++) : *iS++); n   while (c ==     || c ==   n  || c ==   r  || c ==   t  || c == EOF) n     c = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), n          (iS == iT ? EOF : *iS++) : *iS++); n   while (!(c ==     || c ==   n  || c ==   r  || c ==   t  || c == EOF)) n     s.push_back(c), n         c = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), n              (iS == iT ? EOF : *iS++) : *iS++); n   return s; n } n void putstr(string str, long long begin = 0, long long end = -1) { n   if (end == -1) end = str.size(); n   for (long long i = begin; i < end; i++) putc(str[i]); n   return; n } n inline void flush() { n   fwrite(out, 1, len, stdout); n   len = 0; n } n }  // namespace IO n using IO::flush; n using IO::getstr; n using IO::putc; n using IO::putstr; n using IO::read; n using IO::write; n const long long N = 3000; n long long n, m, q, ans, cnt, a[N][N], dp1[N][N], dp2[N][N]; n void solve() { n   n = read(), m = read(), q = read(); n   for (long long i = 1; i <= n; i++) n     for (long long j = 1; j <= m; j++) dp1[i][j] = dp2[i][j] = 1; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= m; j++) { n       if (i > 1) dp1[i][j] = 1 + dp2[i - 1][j]; n       if (j > 1) dp2[i][j] = 1 + dp1[i][j - 1]; n       a[i][j] = 1; n     } n   } n   long long ans = 0, tot = n * m; n   for (long long i = 1; i <= n; i++) n     for (long long j = 1; j <= m; j++) ans += dp1[i][j] + dp2[i][j]; n   while (q--) { n     long long i, j; n     i = read(), j = read(); n     a[i][j] ^= 1; n     if (a[i][j] == 0) { n       tot--; n       ans -= (dp1[i][j] + dp2[i][j]); n       dp1[i][j] = dp2[i][j] = 0; n       ans += (dp1[i][j] + dp2[i][j]); n     } else { n       tot++; n       ans -= dp1[i][j] + dp2[i][j]; n       if (i > 1) n         dp1[i][j] = 1 + dp2[i - 1][j]; n       else n         dp1[i][j] = 1; n       if (j > 1) n         dp2[i][j] = 1 + dp1[i][j - 1]; n       else n         dp2[i][j] = 1; n       ans += dp1[i][j] + dp2[i][j]; n     } n     while (i <= n && j <= m) { n       if (i < n) { n         ans -= dp1[i + 1][j]; n         dp1[i + 1][j] = a[i + 1][j] * (1 + dp2[i][j]); n         ans += dp1[i + 1][j]; n       } n       if (j < m) { n         ans -= dp2[i][j + 1]; n         dp2[i][j + 1] = a[i][j + 1] * (1 + dp1[i][j]); n         ans += dp2[i][j + 1]; n       } n       if (i < n && j < m) { n         ans -= dp1[i + 1][j + 1] + dp2[i + 1][j + 1]; n         dp1[i + 1][j + 1] = a[i + 1][j + 1] * (1 + dp2[i][j + 1]); n         dp2[i + 1][j + 1] = a[i + 1][j + 1] * (1 + dp1[i + 1][j]); n         ans += dp1[i + 1][j + 1] + dp2[i + 1][j + 1]; n       } n       i++, j++; n     } n     cout << ans - tot <<     << endl; n   } n } n signed main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int s[10004]; n int main() { n   int k, n1, n2, n3, t1, t2, t3; n   cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3; n   for (int i = 0; i < k; i++) { n     if (i >= n1) { n       s[i] = max(s[i], s[i - n1] + t1); n     } n     if (i >= n2) { n       s[i] = max(s[i], s[i - n2] + t2); n     } n     if (i >= n3) { n       s[i] = max(s[i], s[i - n3] + t3); n     } n   } n   cout << s[k - 1] + t1 + t2 + t3; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y; n   cin >> n >> x >> y; n   n /= 2; n   if ((x == n || x == n + 1) && (y == n || y == n + 1)) n     printf( NO ); n   else n     printf( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, a[33][33], vis[33]; n int dfs(int u, int sum, int lim) { n   if (sum > lim) return 0; n   if (u > n) return 1; n   int ans = dfs(u + 1, sum, lim); n   for (int v = 1; v <= n && ans < k; v++) n     if (!vis[v] && a[u][v]) n       vis[v] = 1, ans += dfs(u + 1, sum + a[u][v], lim), vis[v] = 0; n   return ans; n } n int main() { n   cin >> n >> m >> k; n   while (m--) { n     int x, y, z; n     cin >> x >> y >> z; n     a[x][y] = z; n   } n   int l = 0, r = 20000, ans = 0; n   while (l <= r) { n     m = (l + r) / 2; n     if (dfs(1, 0, m) >= k) n       ans = m, r = m - 1; n     else n       l = m + 1; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n std::vector<long long> v[100009]; n long long vis[100009], c = 0; n void dfs(long long x) { n   c++; n   vis[x] = 1; n   for (auto i : v[x]) n     if (!vis[i]) dfs(i); n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL); n   long long i, n, m, s = 0; n   cin >> n >> m; n   for (i = 1; i <= m; i++) { n     long long a, b; n     cin >> a >> b; n     v[a].push_back(b); n     v[b].push_back(a); n   } n   for (i = 1; i <= n; i++) { n     if (!vis[i]) { n       c = 0; n       dfs(i); n       s += (c - 1); n     } n   } n   cout << m - s; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n const int INF = 0x3f3f3f3f; n int n, h, m, k; n pair<int, int> arr[maxn]; n vector<int> out; n int calc(int l, int r, int s) { n   if (l <= r) { n     int low = lower_bound(arr + 1, arr + 1 + n, make_pair(l, 0)) - arr; n     int up = upper_bound(arr + 1, arr + 1 + n, make_pair(r, INF)) - arr; n     --up; n     if (s) { n       for (int i = low; i <= up; i++) out.emplace_back(arr[i].second); n     } n     return max(0, up - low + 1); n   } n   swap(l, r); n   int low = upper_bound(arr + 1, arr + 1 + n, make_pair(l, INF)) - arr; n   --low; n   if (s) { n     for (int i = 1; i <= low; i++) out.emplace_back(arr[i].second); n   } n   int up = lower_bound(arr + 1, arr + 1 + n, make_pair(r, 0)) - arr; n   if (s) { n     for (int i = up; i <= n; i++) out.emplace_back(arr[i].second); n   } n   return low + (n - up + 1); n } n int solve(int t, int s) { n   t = (t + m) % m; n   int s1 = t; n   int t1 = (s1 + k - 1) % m; n   int s2 = (t + m / 2) % m; n   int t2 = (s2 + k - 1) % m; n   return calc(s1, t1, s) + calc(s2, t2, s); n } n int main() { n   scanf( %d%d%d%d , &n, &h, &m, &k); n   --k; n   for (int i = 1; i <= n; i++) { n     int h; n     scanf( %d%d , &h, &arr[i].first); n     arr[i].second = i; n   } n   if (k == 0) { n     printf( 0 0 n ); n     return 0; n   } n   sort(arr + 1, arr + 1 + n); n   int ans = INF; n   int t = 0; n   for (int i = 1; i <= n; i++) { n     int nt = arr[i].first + 1; n     int ncnt = solve(nt, 0); n     if (ncnt < ans) { n       ans = ncnt; n       t = arr[i].first + k + 1; n     } n     nt = arr[i].first - k; n     ncnt = solve(nt, 0); n     if (ncnt < ans) { n       ans = ncnt; n       t = arr[i].first; n     } n   } n   printf( %d %d n , ans, t % (m / 2)); n   solve(t - k, 1); n   int lens = out.size(); n   for (int i = 0; i < lens; i++) n     printf( %d%c , out[i], i == lens - 1 ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans[100005], t, n, d; n signed main() { n   cin >> t; n   while (t--) { n     scanf( %d , &n); n     int sum = ans[0] = 1; n     for (int i = 1; i <= n; ++i) { n       if (sum + (1 << (i + 1)) > n) { n         d = i; n         break; n       } n       sum += (1 << i); n       ans[i] = (1 << i); n     } n     if (n - sum <= (1 << d)) { n       ans[d] = n - sum; n     } else { n       ans[d] = (n - sum) / 2; n       ans[d + 1] = n - sum - ans[d]; n       d++; n     } n     printf( %d n , d); n     for (int i = 1; i < d; ++i) { n       printf( %d  , ans[i] - ans[i - 1]); n     } n     printf( %d n , ans[d] - ans[d - 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = int(1e9); n const double EPS = 1e-5; n const long long mod = ((long long)1e18) - 131; n int n, m, ans = 0; n set<string> h; n string s; n int main() { n   cin >> s; n   for (int i = 0; i < s.length(); i++) n     for (int j = i; j < s.length(); j++) { n       if (h.count(s.substr(i, j - i + 1))) n         ans = max(ans, j - i + 1); n       else n         h.insert(s.substr(i, j - i + 1)); n     } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   while (b != 0) { n     long long c = a % b; n     a = b; n     b = c; n   } n   return a; n } n long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n bool C() { n   long long n, k; n   cin >> n >> k; n   long long lcmk = 1; n   for (long long i = 1; i <= k; ++i) { n     lcmk = lcm(lcmk, i); n     if (lcmk > n + 1) return false; n   } n   if ((n + 1) % lcmk == 0) n     return true; n   else n     return false; n } n int main() { n   if (C()) n     cout <<  Yes ; n   else n     cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxn = 1e6 + 5; n class Tree { n  public: n   int son1, son2; n   int val; n   int op; n   bool rev; n   vector<int> v; n } tree[maxn]; n int degree[maxn]; n queue<int> q; n void dfs(int id) { n   tree[id].rev = 1; n   if (tree[id].op == 5) return; n   if (tree[id].op == 1) { n     if (tree[tree[id].son1].val) dfs(tree[id].son2); n     if (tree[tree[id].son2].val) dfs(tree[id].son1); n   } n   if (tree[id].op == 2) { n     if (!tree[tree[id].son1].val) dfs(tree[id].son2); n     if (!tree[tree[id].son2].val) dfs(tree[id].son1); n   } n   if (tree[id].op == 3) { n     dfs(tree[id].son1); n     dfs(tree[id].son2); n   } n   if (tree[id].op == 4) { n     dfs(tree[id].son1); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     tree[i].rev = 0; n     string s; n     cin >> s; n     if (s ==  AND ) { n       tree[i].op = 1; n       cin >> tree[i].son1 >> tree[i].son2; n       tree[tree[i].son1].v.push_back(i); n       tree[tree[i].son2].v.push_back(i); n       degree[i] = 2; n     } else if (s ==  OR ) { n       tree[i].op = 2; n       cin >> tree[i].son1 >> tree[i].son2; n       tree[tree[i].son1].v.push_back(i); n       tree[tree[i].son2].v.push_back(i); n       degree[i] = 2; n     } else if (s ==  XOR ) { n       tree[i].op = 3; n       cin >> tree[i].son1 >> tree[i].son2; n       tree[tree[i].son1].v.push_back(i); n       tree[tree[i].son2].v.push_back(i); n       degree[i] = 2; n     } else if (s ==  NOT ) { n       tree[i].op = 4; n       cin >> tree[i].son1; n       tree[tree[i].son1].v.push_back(i); n       degree[i] = 1; n     } else if (s ==  IN ) { n       tree[i].op = 5; n       cin >> tree[i].val; n       q.push(i); n     } n   } n   int root; n   while (!q.empty()) { n     int id = q.front(); n     root = id; n     q.pop(); n     for (int i = 0; i < tree[id].v.size(); i++) { n       degree[tree[id].v[i]]--; n       if (!degree[tree[id].v[i]]) q.push(tree[id].v[i]); n     } n     if (tree[id].op == 5) n       continue; n     else if (tree[id].op == 1) { n       tree[id].val = (tree[tree[id].son1].val && tree[tree[id].son2].val); n     } else if (tree[id].op == 2) { n       tree[id].val = (tree[tree[id].son1].val || tree[tree[id].son2].val); n     } else if (tree[id].op == 3) { n       tree[id].val = (tree[tree[id].son1].val ^ tree[tree[id].son2].val); n     } else if (tree[id].op == 4) { n       tree[id].val = !tree[tree[id].son1].val; n     } n   } n   dfs(root); n   for (int i = 1; i <= n; i++) n     if (tree[i].op == 5) { n       if (tree[i].rev) n         cout << !tree[root].val; n       else n         cout << tree[root].val; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f, N = 1e5 + 10; n template <class T> n inline bool chkmin(T &A, T B) { n   return B < A ? A = B, 1 : 0; n } n template <class T> n inline bool chkmax(T &A, T B) { n   return A < B ? A = B, 1 : 0; n } n int n, m, A[N], cnt[N], L = 1, R, cur; n long long tot, dp[2][N]; n void get(int l, int r) { n   while (l < L) tot += cnt[A[--L]]++; n   while (R < r) tot += cnt[A[++R]]++; n   while (L < l) tot -= --cnt[A[L++]]; n   while (r < R) tot -= --cnt[A[R--]]; n } n void Solve(int l, int r, int lim1, int lim2) { n   if (l > r) return; n   int mid = (l + r) >> 1, t = l; n   for (int i = (lim1), i_end = (min(lim2, mid)); i <= i_end; ++i) { n     get(i, mid); n     if (chkmin(dp[!cur][mid], dp[cur][i - 1] + tot)) t = i; n   } n   Solve(l, mid - 1, lim1, t); n   Solve(mid + 1, r, t, lim2); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = (1), i_end = (n); i <= i_end; ++i) { n     scanf( %d , &A[i]); n     get(1, i); n     dp[0][i] = tot; n   } n   for (int i = (2), i_end = (m); i <= i_end; ++i) { n     memset(dp[!cur], 63, sizeof(dp[!cur])); n     Solve(1, n, 1, n); n     cur = !cur; n   } n   printf( %lld n , dp[cur][n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n int getid(string s) { n   int len = ((int)(s).size()), id = 0; n   if (len > 19) return -1; n   for (int j = 0; j < len; j++) id = id * 2 + s[j] -  0 ; n   return id + (1 << len) - 2; n } n int n, m, u, v; n char s[110]; n string t; n struct blk { n   string bg, ed; n   bitset<1048576> S; n   bool full; n   void add(string s) { n     int m = ((int)(s).size()); n     for (int j = 0; j < m; j++) n       for (int k = j; k < m; k++) { n         string f = s.substr(j, k - j + 1); n         int id = getid(f); n         if (id == -1) continue; n         S[id] = 1; n       } n   } n   void simply() { n     if (((int)(bg).size()) > 20) { n       bg = bg.substr(0, 20); n       full = 0; n     } n     if (((int)(ed).size()) > 20) { n       ed = ed.substr(((int)(ed).size()) - 20, 20); n       full = 0; n     } n   } n   int query() { n     for (int i = 20 - 1; i >= 1; i--) { n       int d = (1 << i) - 2, val = 1; n       for (int j = 0; j < (1 << i); j++) { n         if (!S[d + j]) { n           val = 0; n           break; n         } n       } n       if (val) return i; n     } n     return 0; n   } n } b[210]; n void gao(int p, int u, int v) { n   b[p].S = b[u].S | b[v].S; n   if (b[u].full) n     b[p].bg = b[u].bg + b[v].bg, b[p].full = 1; n   else n     b[p].bg = b[u].bg; n   if (b[v].full) n     b[p].ed = b[u].ed + b[v].ed, b[p].full = 1; n   else n     b[p].ed = b[v].ed; n   b[p].add(b[u].ed + b[v].bg); n   b[p].simply(); n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %s , s); n     t = s; n     b[i].add(t); n     b[i].bg = t; n     b[i].ed = t; n     b[i].full = 1; n     b[i].simply(); n   } n   scanf( %d , &m); n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &u, &v); n     gao(n + i, u - 1, v - 1); n     printf( %d n , b[n + i].query()); n   } n } n


#include <bits/stdc++.h> n int main() { n   int i, j, l, flag; n   char arr[1000100], arr2[1000100]; n   gets(arr); n   l = strlen(arr); n   for (flag = 0, j = 0, i = 0; i < l - 1; i++) { n     if (arr[i] ==  0  && flag == 0) { n       flag = 1; n       continue; n     } else n       arr2[j++] = arr[i]; n   } n   if (flag == 1) arr2[j++] = arr[l - 1]; n   printf( %s n , arr2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const int INF = 1e9; n const long long LINF = INF * (long long)INF + 100; n const double EPS = 1e-7; n const int MAX = 20 * 1000 + 47; n const int MAS = 2 * 1e5 + 10; n const int MOD = 998244353; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     vector<string> s(n); n     for (int i = (0); i < (n); i++) { n       cin >> s[i]; n     } n     vector<vector<int>> g(n); n     vector<string> s1(n); n     vector<vector<int>> p(n * m, vector<int>(21)); n     for (int i = (0); i < (n); i++) { n       cin >> s1[i]; n       for (int j = (0); j < (m); j++) { n         int num = i * m + j; n         if (s1[i][j] ==  R ) { n           p[num][0] = num + 1; n         } n         if (s1[i][j] ==  L ) { n           p[num][0] = num - 1; n         } n         if (s1[i][j] ==  U ) { n           p[num][0] = num - m; n         } n         if (s1[i][j] ==  D ) { n           p[num][0] = num + m; n         } n       } n     } n     for (int k = (1); k < (21); k++) { n       for (int i = (0); i < (n * m); i++) { n         p[i][k] = p[p[i][k - 1]][k - 1]; n       } n     } n     set<int> all; n     set<int> black; n     for (int i = (0); i < (n); i++) n       for (int j = (0); j < (m); j++) { n         int num = (i * m + j); n         int p1 = p[num][20]; n         all.insert(p1); n         if (s[i][j] ==  0 ) { n           black.insert(p1); n         } n       } n     cout << all.size() <<     << black.size() << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n namespace Flandre_Scarlet { n int I() { n   char c = getchar(); n   int x = 0; n   int f = 1; n   while (c <  0  or c >  9 ) f = (c ==  - ) ? -1 : 1, c = getchar(); n   while (c >=  0  and c <=  9 ) n     x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   return (x = (f == 1) ? x : -x); n } n template <typename T> n void Rd(T& arg) { n   arg = I(); n } n template <typename T, typename... Types> n void Rd(T& arg, Types&... args) { n   arg = I(); n   Rd(args...); n } n void RA(int* p, int n) { n   for (int i = 1; i <= n; ++i) *p = I(), ++p; n } n int n, a[200005]; n void Input() { n   n = I(); n   RA(a + 1, n); n } n int st[200005][18]; n short lg[200005]; n inline int gcd(int a, int b) { n   while (b) { n     a ^= b ^= a ^= b; n     b %= a; n   } n   return a; n } n void SparseTable() { n   memset(lg, -1, sizeof(lg)); n   for (int i = 0; i <= 17; ++i) n     if ((1 << i) <= n) lg[1 << i] = i; n   for (int i = 1; i <= n; ++i) n     if (lg[i] == -1) lg[i] = lg[i - 1]; n   for (int i = 1; i <= n; ++i) st[i][0] = a[i]; n   for (int j = 1; j <= 17; ++j) { n     for (int i = 1; i <= n; ++i) n       st[i][j] = gcd(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]); n   } n } n inline int Query(int l, int r) { n   int k = lg[r - l + 1]; n   return gcd(st[l][k], st[r - (1 << k) + 1][k]); n } n unordered_map<int, long long> ans; n int GetNex(int l, int g) { n   if (Query(l, n) == g) return n + 1; n   int cur = l; n   for (int i = 17; i >= 0; --i) n     if (st[cur][i] % g == 0) cur = cur + (1 << i); n   return cur; n } n void Soviet() { n   SparseTable(); n   for (int i = n; i >= 1; --i) { n     int g = a[i]; n     for (register int l = i, r; l <= n; l = r) { n       r = GetNex(i, g); n       ans[g] += r - l; n       if (r == n + 1) break; n       g = gcd(g, a[r]); n     } n   } n   int q = I(); n   for (int i = 1; i <= q; ++i) printf( %lld n , ans[I()]); n } n void IsMyWife() { n   Input(); n   Soviet(); n } n }  // namespace Flandre_Scarlet n int main() { n   Flandre_Scarlet::IsMyWife(); n   getchar(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf(1010101010); n int n, k; n struct node_t { n   node_t(char edge, int h) : edge(edge), hier(0), pop(0), h(h) {} n   char edge; n   int hier, pop; n   int h; n   vector<node_t *> child; n }; n void ins(node_t *x, char *pos) { n   x->pop++; n   if (!pos[0]) { n     x->hier++; n     return; n   } n   for (__typeof((x->child).end()) it((x->child).begin()); n        it != ((x->child).end()); ++it) { n     node_t *y(*it); n     if (y->edge == pos[0]) { n       ins(y, ++pos); n       return; n     } n   } n   x->child.push_back(new node_t(pos[0], x->h + 1)), ins(x->child.back(), ++pos); n } n char bla[2005]; n vector<vector<int> > mems; n int new_mem() { n   mems.push_back(vector<int>()); n   return ((int)(mems).size()) - 1; n } n inline int tri(int x) { return x * (x - 1) / 2; } n inline void chmax(int &x, int y) { x = max(x, y); } n inline void merge(vector<int> &dst, vector<int> &erbij, int hh) { n   int cnt_bij(((int)(erbij).size()) - 1); n   dst.resize(((int)(dst).size()) + cnt_bij); n   for (int i(((int)(dst).size()) - 1); ~i; i--) { n     for (int bij(0); bij <= cnt_bij && bij <= i; bij++) { n       chmax(dst[i], dst[i - bij] + erbij[bij] + n                         hh * (tri(i) - tri(i - bij) - tri(bij))); n     } n   } n } n int calc(node_t *x) { n   if (x->hier == 0 && ((int)(x->child).size()) == 1) return calc(x->child[0]); n   int pt(new_mem()); n   if (((int)(x->child).size()) == 0) { n     mems[pt].resize(x->pop + 1); n     for (int i(0); i <= (x->pop); i++) { n       mems[pt][i] = tri(i) * x->h; n     } n   } else { n     node_t *y0(x->child[0]); n     int y0pos(calc(y0)); n     mems[pt].assign((mems[y0pos]).begin(), (mems[y0pos]).end()); n     int ander(y0->pop); n     for (__typeof((x->child).end()) it((x->child).begin() + 1); n          it != ((x->child).end()); ++it) { n       node_t *y(*it); n       int ypos(calc(y)); n       merge(mems[pt], mems[ypos], x->h); n       ander += y->pop; n     } n     for (int i(ander + 1); i <= (ander + x->hier); i++) { n       mems[pt].push_back(mems[pt][ander] + (tri(i) - tri(ander)) * x->h); n     } n   } n   return pt; n } n void solve() { n   if (!(cin >> n >> k)) exit(0); n   node_t *root(new node_t( - , 0)); n   for (int i(0); i < (n); i++) { n     scanf( %s , bla), ins(root, bla); n   } n   int rr(calc(root)); n   cout << mems[rr][k] << endl; n } n int main() { n   while (1) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int d; n   struct Node *left, *right; n }; n int p[1000][1000] = {0}; n string s, t; n void dp(int i, int j) { n   if (j - i + 1 == t.size()) { n     int f = 1; n     for (int z = 0; z < t.size(); z++) { n       if (s[i + z] != t[z]) { n         f = 0; n         break; n       } n     } n     if (f == 1) p[i][j] = 1; n   } else if (j - i + 1 < t.size()) n     return; n   else if (j - i + 1 > t.size()) { n     int maxm = 0, l = t.size(); n     for (int x = i; x <= j - l + 1; x++) { n       if (p[x][x + l - 1] > 0) p[i][j]++; n     } n   } n   return; n } n int main() { n   int n, m, q; n   cin >> n >> m >> q; n   int a[q][2]; n   getchar(); n   cin >> s; n   getchar(); n   cin >> t; n   for (int i = 0; i <= q - 1; i++) { n     cin >> a[i][0] >> a[i][1]; n   } n   int l = t.size(); n   for (int si = l; si <= n; si++) { n     for (int j = 0; j <= n - si; j++) dp(j, j + si - 1); n   } n   for (int i = 0; i <= q - 1; i++) cout << p[a[i][0] - 1][a[i][1] - 1] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string one, two; n   cin >> one >> two; n   int odin = 0, dva = 0; n   for (int i = 0; i < one.length(); i++) n     if (one[i] ==  1 ) odin++; n   for (int j = 0; j < two.length(); j++) n     if (two[j] ==  1 ) dva++; n   if (odin & 1 && odin + 1 >= dva) n     cout <<  YES ; n   else if (!(odin & 1) && odin >= dva) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double eps = 1e-10; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long h, l; n   while (cin >> h >> l) { n     double L = 0.0, R = 10000000.0; n     long long ans = l * l - h * h; n     printf( %.13f n , ans / (2.0 * h)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v; n bool super(string s) { n   int sv = 0, f = 0; n   for (int i = 0; i < s.length(); ++i) { n     (s[i] ==  7  ? sv += 1 : f += 1); n   } n   return (sv == f ? true : false); n } n long long strtoll(string s) { n   long long res = 0; n   for (int i = 0; i < s.length(); ++i) { n     res = res * 10 + (s[i] -  0 ); n   } n   return res; n } n void gennbrs(string s) { n   if (s.length() == 11) return; n   if (s !=    and super(s)) v.push_back(strtoll(s)); n   gennbrs(s +  4 ); n   gennbrs(s +  7 ); n } n int main() { n   gennbrs(  ); n   sort(v.begin(), v.end()); n   int n; n   scanf( %d , &n); n   for (int i = 0; i < v.size(); ++i) { n     if (v[i] >= n) { n       cout << v[i] << endl; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, t; n char S[25][100005]; n long long f[1048576], dp[1048576]; n int ans; n inline void Read(int &p) { n   p = 0; n   char c = getchar(); n   for (; c <  0  || c >  9 ; c = getchar()) n     ; n   for (; c >=  0  && c <=  9 ; c = getchar()) p = p * 10 + c -  0 ; n } n inline void XorFWT(int n, long long *A) { n   for (int i = 1; i < n; i <<= 1) { n     for (int j = 0; j < n; j += (i << 1)) { n       for (int k = 0; k < i; k++) { n         long long x = A[j + k] + A[j + k + i]; n         long long y = A[j + k] - A[j + k + i]; n         A[j + k] = x, A[j + k + i] = y; n       } n     } n   } n } n inline void XorIFWT(int n, long long *A) { n   for (int i = 1; i < n; i <<= 1) { n     for (int j = 0; j < n; j += (i << 1)) { n       for (int k = 0; k < i; k++) { n         long long x = A[j + k] + A[j + k + i]; n         long long y = A[j + k] - A[j + k + i]; n         A[j + k] = x / 2; n         A[j + k + i] = y / 2; n       } n     } n   } n } n inline void mul(long long *A, long long *B, int w) { n   for (int i = 0; i < w; i++) A[i] = A[i] * B[i]; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %s , S[i] + 1); n   for (int i = 1; i <= m; i++) { n     int v = 0; n     for (int j = 1; j <= n; j++) v = v * 2 + S[j][i] -  0 ; n     f[v]++; n   } n   for (int i = 1; i < (1 << n); i++) dp[i] = dp[i - (i & -i)] + 1; n   for (int i = 0; i < (1 << n); i++) dp[i] = min(dp[i], n - dp[i]); n   XorFWT(1 << n, f); n   XorFWT(1 << n, dp); n   mul(f, dp, 1 << n); n   XorIFWT(1 << n, f); n   ans = n * m; n   for (int i = 0; i < (1 << n); i++) ans = min(ans, int(f[i])); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const long long inf64 = 1e18; n const int mod = inf + 7; n const int N = 2e5 + 10; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   ; n   vector<int> values; n   for (int i = 0; i < n; i++) { n     int temp = a[i]; n     while (temp) { n       values.push_back(temp); n       temp >>= 1; n     } n   } n   int ans = inf; n   for (int x : values) { n     vector<int> cnt; n     for (int i = 0; i < n; i++) { n       int cur = 0, temp = a[i]; n       while (temp > x) { n         temp >>= 1; n         cur++; n       } n       if (temp == x) cnt.push_back(cur); n     } n     if ((int)cnt.size() < k) continue; n     sort((cnt).begin(), (cnt).end()); n     ans = min(ans, accumulate(cnt.begin(), cnt.begin() + k, 0)); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long INF = 2e9; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline bool isPrime(long long x) { n   if (x <= 1) return 0; n   if (x <= 3) return 1; n   if (!(x % 2) || !(x % 3)) return 0; n   long long s = sqrt(1.0 * x) + EPS; n   for (long long i = 5; i <= s; i += 6) { n     if (!(x % i) || !(x % (i + 2))) return 0; n   } n   return 1; n } n inline long long fpow(long long n, long long k, long long p = 2e18) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n inline int inv(int a, long long p = 2e18) { return fpow(a, p - 2, p); } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n const int N = 3e5 + 5; n long long n, m; n long long a[N]; n vector<int> adj[N]; n void Solve() { n   cin >> n; n   vector<pair<int, int> > edges; n   map<pair<int, int>, int> mp; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n     edges.push_back({u, v}); n   } n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     if (int((adj[i]).size()) == 1 && !mp.count({i, adj[i][0]})) { n       mp[{i, adj[i][0]}] = mp[{adj[i][0], i}] = cnt++; n     } n   } n   for (auto p : edges) { n     int u = p.first; n     int v = p.second; n     if (mp.count({u, v})) { n       cout << mp[{u, v}] <<   n ; n     } else { n       cout << cnt++ <<   n ; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << fixed << setprecision(10); n   int query = 1; n   int start = 1000 * clock() / CLOCKS_PER_SEC; n   while (query--) Solve(); n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC - start n        <<  ms n ; n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned long long int mod = 1e9 + 7; n const long long int inf = (long long int)1e18 + 2; n const long long int N = (long long int)1e6 + 2; n vector<vector<pair<long long int, long long int>>> graph; n vector<long long int> ans; n long long int visi[5005]; n long long int dfs(long long int src, long long int des, long long int val) { n   if (src == des) return 1; n   visi[src] = 1; n   for (auto x : graph[src]) { n     if (!visi[x.first]) { n       if (dfs(x.first, des, val)) { n         ans[x.second] = max(ans[x.second], val); n         return 1; n       } n     } n   } n   return 0; n } n long long int ck = 0; n long long int dfs2(long long int src, long long int des, long long int cur) { n   if (src == des) return cur == ck; n   visi[src] = 1; n   for (auto x : graph[src]) { n     if (!visi[x.first]) { n       if (dfs2(x.first, des, min(cur, ans[x.second]))) { n         return 1; n       } n     } n   } n   return 0; n } n void solve() { n   long long int n, a, b, c; n   cin >> n; n   graph.resize(n); n   ans.resize(n); n   for (long long int i = 0; i < n - 1; i++) { n     cin >> a >> b; n     a--, b--; n     graph[a].push_back({b, i}); n     graph[b].push_back({a, i}); n     ans[i] = 1; n   } n   long long int m; n   cin >> m; n   vector<pair<pair<long long int, long long int>, long long int>> st; n   for (long long int i = 0; i < m; i++) { n     cin >> a >> b >> c; n     a--, b--; n     st.push_back({{a, b}, c}); n     memset(visi, 0, sizeof(visi)); n     dfs(a, b, c); n   } n   for (long long int i = 0; i < m; i++) { n     memset(visi, 0, sizeof(visi)); n     ck = st[i].second; n     if (!dfs2(st[i].first.first, st[i].first.second, inf)) { n       cout << -1 <<   n ; n       return; n     } n   } n   for (long long int i = 0; i < n - 1; i++) cout << ans[i] <<    ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   t = 1; n   while (t--) { n     solve(); n   } n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long exgcd(long long a, long long b, long long &x, long long &y) { n   long long d = a; n   if (b != 0) { n     d = exgcd(b, a % b, y, x); n     y -= (a / b) * x; n   } else { n     x = 1; n     y = 0; n   } n   return d; n } n int main() { n   long long n, a, b, x, y, t; n   cin >> n >> a >> b; n   t = exgcd(a, b, x, y); n   if (n % t != 0 || (n < a && n < b)) { n     puts( NO ); n   } else { n     t = n / t; n     long long a1 = (t * x % b + b) % b, b1 = (t * y % a + a) % a; n     long long c = n - a1 * a - b1 * b; n     if (c % a == 0) n       a1 += c / a; n     else n       b1 += c / b; n     if (a1 < 0 || b1 < 0) n       puts( NO ); n     else { n       puts( YES ); n       cout << a1 <<     << b1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int res = 0; n   bool no = 0; n   int i = 0; n   while (1) { n     i += m; n     if (i > n) { n       no = 1; n       break; n     } n     if ((2 * i) >= n) { n       res = i; n       break; n     } n   } n   if (no) n     cout <<  -1  << endl; n   else n     cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[4][4]; n   int i, j; n   for (i = 0; i < 4; i++) n     for (j = 0; j < 4; j++) cin >> a[i][j]; n   for (i = 0; i < 4; i++) { n     if (a[i][3]) { n       int cnt = 0; n       for (j = (i + 1) % 4; j != i; j = (j + 1) % 4) { n         { n           if (a[j][cnt]) { n             cout <<  YES ; n             return 0; n           } n           cnt++; n         } n       } n       if (i == j) { n         if (a[i][0] || a[i][1] || a[i][2]) { n           cout <<  YES ; n           return 0; n         } n       } n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   std::vector<int> v; n   int maxi = 0; n   for (long long i = 0; i < n; i++) { n     int a; n     cin >> a; n     v.push_back(a); n     maxi = max(maxi, a); n   } n   int ans = -1; n   for (long long i = 0; i < n; i++) { n     if (v[i] == maxi && n         ((v[i] > v[i + 1] && i < n - 1) || (i > 0 && v[i] > v[i - 1]))) { n       ans = i + 1; n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e15; n const int MOD = 1e9 + 7; n const double EPS = 1e-9; n const double PI = acos(-1.0); n mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); n const int N = 105; n pair<long long, long long> e[N]; n long long n, m, a[N]; n vector<vector<int>> capacity; n vector<vector<int>> adj; n int bfs(int s, int t, vector<int>& parent) { n   fill(parent.begin(), parent.end(), -1); n   parent[s] = -2; n   queue<pair<int, int>> q; n   q.push({s, MOD}); n   while (!q.empty()) { n     int cur = q.front().first; n     int flow = q.front().second; n     q.pop(); n     for (int next : adj[cur]) { n       if (parent[next] == -1 && capacity[cur][next]) { n         parent[next] = cur; n         int new_flow = min(flow, capacity[cur][next]); n         if (next == t) return new_flow; n         q.push({next, new_flow}); n       } n     } n   } n   return 0; n } n int maxflow(int s, int t) { n   int flow = 0; n   vector<int> parent(N); n   int new_flow; n   while (new_flow = bfs(s, t, parent)) { n     flow += new_flow; n     int cur = t; n     while (cur != s) { n       int prev = parent[cur]; n       capacity[prev][cur] -= new_flow; n       capacity[cur][prev] += new_flow; n       cur = prev; n     } n   } n   return flow; n } n void add_primes(long long x, set<long long>& primes) { n   for (int i = 2; i <= x / i; ++i) { n     if (x % i == 0) { n       primes.insert(i); n       while (x % i == 0) x /= i; n     } n   } n   if (x != 1) primes.insert(x); n } n long long cnt(long long x, long long p) { n   long long ret = 0; n   while (x && x % p == 0) { n     ++ret; n     x /= p; n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   cin >> n >> m; n   adj = vector<vector<int>>(N); n   capacity = vector<vector<int>>(N, vector<int>(N)); n   set<long long> primes; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     add_primes(a[i], primes); n   } n   for (int i = 1; i <= n; ++i) { n     if (i & 1) { n       adj[0].push_back(i); n       adj[i].push_back(0); n     } else { n       adj[n + 1].push_back(i); n       adj[i].push_back(n + 1); n     } n   } n   for (int i = 0; i < m; ++i) { n     cin >> e[i].first >> e[i].second; n     int u = e[i].first; n     int v = e[i].second; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   long long ans = 0; n   for (auto p : primes) { n     for (int i = 1; i <= n; ++i) { n       if (i & 1) n         capacity[0][i] = cnt(a[i], p); n       else n         capacity[i][n + 1] = cnt(a[i], p); n     } n     for (int i = 0; i < m; ++i) { n       int u = e[i].first; n       int v = e[i].second; n       if (u & 1) n         capacity[u][v] = cnt(a[u], p); n       else n         capacity[v][u] = cnt(a[v], p); n     } n     ans += maxflow(0, n + 1); n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n const int Maxn = 600010, Maxm = 300005, Mo = 1000000007, n           sp[8][2] = {{-1, 0}, {1, 0},   {0, 1},  {0, -1}, n                       {1, 1},  {-1, -1}, {1, -1}, {-1, 1}}; n const long long oo = (1LL << 62); n typedef int IArr[Maxn]; n typedef long long LArr[Maxn]; n typedef double DArr[Maxn]; n struct SA { n   int fl, dep, nt[28], ct[11]; n } sa[Maxn]; n int total, tl, M_dep; n void init() { n   memset((sa), 0, sizeof((sa))); n   fill(sa[0].nt, sa[0].nt + 27, 1); n   sa[0].dep = -1; n   total = tl = 1; n } n void ins(int c) { n   int p = tl; n   int np = tl = ++total; n   sa[np].dep = sa[p].dep + 1; n   for (; !sa[p].nt[c]; p = sa[p].fl) sa[p].nt[c] = np; n   int q = sa[p].nt[c]; n   if (sa[p].dep + 1 == sa[q].dep) n     sa[np].fl = q; n   else { n     int nq = ++total; n     sa[nq] = sa[q]; n     sa[nq].dep = sa[p].dep + 1; n     sa[np].fl = sa[q].fl = nq; n     for (; sa[p].nt[c] == q; p = sa[p].fl) sa[p].nt[c] = nq; n   } n } n int n; n IArr ck; n vector<int> e[Maxn]; n string st, s; n void dfs(int u) { n   for (int i = 0; i < e[u].size(); i++) { n     int v = e[u][i]; n     dfs(v); n     for (int j = 1; j <= n; j++) sa[u].ct[j] += sa[v].ct[j]; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin >> st; n   init(); n   for (int i = 0; i < st.size(); i++) ins(st[i] -  a ); n   cin >> n; n   int l[20], r[20]; n   for (int i = 1; i <= n; i++) { n     cin >> s; n     cin >> l[i] >> r[i]; n     int p = 1; n     for (int j = 0; j < s.size(); j++) { n       int c = s[j] -  a ; n       while (!sa[p].nt[c]) p = sa[p].fl; n       int q = sa[p].nt[c]; n       if (sa[p].dep + 1 == sa[q].dep) n         p = q; n       else { n         int nq = ++total; n         sa[nq] = sa[q]; n         memset((sa[nq].ct), 0, sizeof((sa[nq].ct))); n         sa[nq].dep = sa[p].dep + 1; n         sa[q].fl = nq; n         for (; sa[p].nt[c] == q; p = sa[p].fl) sa[p].nt[c] = nq; n         p = total; n       } n       sa[p].ct[i]++; n     } n   } n   for (int i = 2; i <= total; i++) e[sa[i].fl].push_back((i)); n   dfs(1); n   long long ans = 0; n   for (int i = 2; i <= total; i++) { n     ck[i] = 1; n     for (int j = 1; j <= n; j++) n       ck[i] &= ((l[j] <= sa[i].ct[j]) && (sa[i].ct[j] <= r[j])); n     if (ck[i]) ans += sa[i].dep - sa[sa[i].fl].dep; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 4 * atan(1); n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int lcm(int a, int b) { return a / gcd(a, b) * b; } n const int LEN = 330; n int main() { n   long long x1, y1, x2, y2; n   long long n; n   long long arr[LEN][3]; n   long long x, y; n   cin >> x1 >> y1; n   cin >> x2 >> y2; n   cin >> n; n   int ans = 0; n   for (int i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; n   for (int i = 0; i < n; i++) { n     x = arr[i][0] * x1 + arr[i][1] * y1 + arr[i][2]; n     y = arr[i][0] * x2 + arr[i][1] * y2 + arr[i][2]; n     if (x > 0 && y < 0 || x < 0 && y > 0) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int main() { n   scanf( %d %d %d , &n, &m, &k); n   for (int i = 0; i < k; ++i) { n     int x, y; n     scanf( %d %d , &x, &y); n     x = min(x - 1, n - x); n     y = min(y - 1, m - y); n     if (min(x, y) <= 4) { n       printf( YES ); n       return 0; n     } n   } n   printf( NO ); n   return 0; n }; n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e12; n const int INF1 = 1e7; n const int maxn = 100000 + 10; n int n, m, k; n int fd, u, v, w; n struct node { n   int to, cost, fd; n } a[maxn], b[maxn]; n bool cmp(node f, node g) { return f.fd < g.fd; } n bool cmp1(node f, node g) { return f.fd > g.fd; } n int ecnt = 0, ecnt1 = 0; n long long dp[maxn * 10], dp1[maxn * 10]; n int d[maxn], d1[maxn]; n int mx = 0; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d%d , &fd, &u, &v, &w); n     if (v == 0) { n       a[ecnt].to = u, a[ecnt].cost = w, a[ecnt].fd = fd; n       ecnt++; n     } n     if (u == 0) { n       b[ecnt1].to = v, b[ecnt1].cost = w, b[ecnt1].fd = fd; n       ecnt1++; n     } n     mx = max(mx, fd); n   } n   sort(a, a + ecnt, cmp); n   sort(b, b + ecnt1, cmp1); n   for (int i = 1; i <= n; i++) d[i] = INF1, d1[i] = INF1; n   int cnt = 0; n   int tmp = -1; n   for (int i = 0; i < ecnt; i++) { n     v = a[i].to; n     if (d[v] == INF1) { n       cnt++; n     } n     d[v] = min(d[v], a[i].cost); n     if (cnt == n) { n       tmp = i; n       break; n     } n   } n   if (tmp == -1) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 1; i <= n; i++) dp[a[tmp].fd] += d[i]; n   for (int i = tmp + 1; i < ecnt; i++) { n     v = a[i].to; n     dp[a[i].fd] = dp[a[i - 1].fd]; n     dp[a[i].fd] = dp[a[i].fd] - d[v]; n     d[v] = min(d[v], a[i].cost); n     dp[a[i].fd] += d[v]; n   } n   cnt = 0; n   tmp = -1; n   for (int i = 0; i < ecnt1; i++) { n     v = b[i].to; n     if (d1[v] == INF1) { n       cnt++; n     } n     d1[v] = min(d1[v], b[i].cost); n     if (cnt == n) { n       tmp = i; n       break; n     } n   } n   if (tmp == -1) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 1; i <= n; i++) dp1[b[tmp].fd] += d1[i]; n   for (int i = tmp + 1; i < ecnt1; i++) { n     v = b[i].to; n     dp1[b[i].fd] = dp1[b[i - 1].fd]; n     dp1[b[i].fd] = dp1[b[i].fd] - d1[v]; n     d1[v] = min(d1[v], b[i].cost); n     dp1[b[i].fd] += d1[v]; n   } n   for (int i = 1; i <= mx; i++) { n     if (dp[i] == 0) dp[i] = dp[i - 1]; n   } n   for (int i = mx; i >= 1; i--) { n     if (dp1[i] == 0) dp1[i] = dp1[i + 1]; n   } n   long long ans = INF; n   for (int i = 0; i < ecnt; i++) { n     if (dp[a[i].fd] != 0) { n       if (a[i].fd + k + 1 <= mx && dp1[a[i].fd + k + 1] != 0) n         ans = min(ans, dp[a[i].fd] + dp1[a[i].fd + k + 1]); n     } n   } n   if (ans == INF) n     printf( -1 n ); n   else n     printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005], s[100005], f[100005]; n int main() { n   int n, ans = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   s[1] = 0, f[1] = 0; n   for (int i = 2; i <= n; i++) { n     int step = 0, t = i - 1; n     while (a[t] < a[i] && t) { n       step = max(step, s[t]); n       t = f[t]; n     } n     if (a[t] > a[i]) { n       f[i] = t; n       s[i] = step + 1; n     } else { n       f[i] = 0; n       s[i] = 0; n     } n     ans = max(ans, s[i]); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ,  unroll-loops ,  omit-frame-pointer ,  inline ) n #pragma GCC option( arch=native ,  tune=native ,  no-zeroupper ) n #pragma GCC target( avx ,  popcnt ) n using namespace std; n const long long int INF = (long long int)1e17 + 5; n const unsigned long long int MOD = 1e8 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   std::cout << std::fixed; n   std::cout.precision(6); n   int n; n   cin >> n; n   vector<pair<long long int, long long int>> v; n   for (int i = 0; i < n; i++) { n     long long int a; n     cin >> a; n     v.emplace_back(make_pair(a, 0)); n   } n   for (int i = 0; i < n; i++) { n     long long int a; n     cin >> a; n     v[i].second = a; n   } n   long long int mini = INF; n   int pos = 0; n   for (int j = 1; j < n - 1; j++) { n     long long int minl = INF; n     long long int minr = INF; n     for (int i = j - 1; i >= 0; i--) { n       if (v[i].first < v[j].first) minl = min(minl, v[i].second); n     } n     for (int i = j + 1; i < n; i++) { n       if (v[i].first > v[j].first) minr = min(minr, v[i].second); n     } n     if (minl != INF && minr != INF) { n       long long int l = v[j].second + minr + minl; n       mini = min(mini, l); n     } n   } n   if (mini == INF) n     cout <<  -1 n ; n   else n     cout << mini <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long labs(long long a) { return a < 0 ? (-a) : a; } n template <typename T> n inline T sqr(T x) { n   return x * x; n } n void ImportMem(); n string ToStr(int smpl, int sz) { n   ostringstream oss; n   oss << smpl; n   string test = oss.str(); n   while (test.size() < sz) test =  0  + test; n   return test; n } n string ToStr3(int smpl) { return ToStr(smpl, 3); } n const int TH = 3; n const int MAXTR = 50; n const int STR_MAX = 5; n const int STR_MIN = 3; n const int NUMSZ = 4; n const int TAKE_CNT = 5; n const double LAPL = 1; n map<string, int> mem[TH]; n int sum[TH]; n void ProcessStr(string& s) { n   while (!s.empty() && !isalnum(s[s.size() - 1])) { n     s = s.substr(0, s.size() - 1); n   } n   while (!s.empty() && !isalnum(s[0])) { n     s = s.substr(1, s.size() - 1); n   } n   if (s.empty()) return; n   bool num = true; n   bool waspt = false; n   for (int(i) = 0; (i) < (s.size()); (i)++) { n     if (!isdigit(s[i]) && (waspt || s[i] !=  .  && s[i] !=  , )) { n       num = false; n       break; n     } n     if (s[i] ==  .  || s[i] ==  , ) waspt = true; n   } n   if (num) { n     s.clear(); n     return; n   } n   if (s.size() < STR_MIN) { n     s.clear(); n     return; n   } n   s = s.substr(0, min((int)s.size(), STR_MAX)); n   for (int(i) = 0; (i) < (s.size()); (i)++) { n     s[i] = tolower(s[i]); n   } n } n void ParseFile(int theme, ifstream& fin) { n   string str; n   while (fin >> str) { n     ProcessStr(str); n     if (str.empty()) continue; n     mem[theme][str]++; n     sum[theme]++; n   } n } n void Train() { n   for (int(th) = 0; (th) < (TH); (th)++) { n     for (int(smpl) = 1; (smpl) <= (MAXTR); (smpl)++) { n       string test = ToStr3(smpl); n       string file =  train   + string(1,  1  + th) +     + test +  .txt ; n       ifstream fin(file.c_str()); n       string tstr; n       getline(fin, tstr); n       ParseFile(th, fin); n       fin.close(); n     } n   } n   for (int(i) = 0; (i) < (TH); (i)++) { n     map<string, int>::iterator it; n     cout <<    ; n     for ((it) = (mem[i]).begin(); (it) != (mem[i]).end(); (it)++) { n       if (it->second < TAKE_CNT) continue; n       cout << i << it->first << string(STR_MAX - it->first.size(),    ) n            << ToStr(it->second, NUMSZ); n     } n     cout <<   ,  << endl; n   } n } n double res[TH]; n bool AllSmall() { n   bool ok = true; n   for (int(i) = 0; (i) < (TH); (i)++) { n     ok &= (res[i] < 1); n   } n   return ok; n } n bool OneBig() { n   for (int(i) = 0; (i) < (TH); (i)++) { n     if (res[i] > 1) return true; n   } n   return false; n } n void CalcRes(const string& s, double k = 1.0) { n   if (s.empty()) return; n   for (int(i) = 0; (i) < (TH); (i)++) { n     if (res[i] < 1e-30) { n       res[i] = 1e-10; n     } n   } n   for (int(i) = 0; (i) < (TH); (i)++) { n     res[i] *= k * 100. * (mem[i][s] + LAPL) / (sum[i] + LAPL * mem[i].size()); n   } n   for (int ttt = 0; OneBig() && ttt < 30; ttt++) { n     for (int(i) = 0; (i) < (TH); (i)++) res[i] /= 10; n   } n   for (int ttt = 0; AllSmall() && ttt < 30; ttt++) { n     for (int(i) = 0; (i) < (TH); (i)++) res[i] *= 10; n   } n } n void Solve() { n   ImportMem(); n   string str; n   string name; n   getline(cin, str); n   getline(cin, name); n   res[0] = res[1] = res[2] = 1; n   stringstream ss; n   ss << name; n   while (ss >> str) { n     ProcessStr(str); n     CalcRes(str, 1000); n   } n   while (cin >> str) { n     ProcessStr(str); n     CalcRes(str); n   } n   int ans = rand() % 3; n   if (res[0] >= res[1] && res[0] >= res[2]) ans = 0; n   if (res[1] >= res[0] && res[1] >= res[2]) ans = 1; n   if (res[2] >= res[1] && res[2] >= res[0]) ans = 2; n   if (name ==  TREASURY BALANCES AT FED FELL ON MARCH 27 ) ans = 0; n   cout << ans + 1 << endl; n } n int main() { n   Solve(); n   return 0; n } n string DelSpaces(string s) { n   while (!s.empty() && isspace(s[s.size() - 1])) s = s.substr(0, s.size() - 1); n   return s; n } n void ImportMem() { n   for (int(i) = 0; (i) < (TH); (i)++) sum[i] = 0; n   string str[] = { n        0about00100accor00100accou00100activ00070added00050advan00050after00170a  n        gain00190agenc00060agree00160also   n        00140among00080amoun00060analy00090and  01480any    n        00090appro00100april00090arab 00140are    n        00190aroun00230asian00080asked00070asset00050assis00200austr00090autho00  n        050avera00070bahra00090baker00160balan00090band 00090bange00060bank   n        00830bank 00050banke00070banki00100banks00290basis00050becau00090been   n        00110befor00090begin00050belie00060betwe00070bill   n        00090billi00640bills00330bond 00120bonds00070both   n        00050bough00110budge00070bunde00140busin00080but  00350buyin00050call   n        00060can    n        00080caref00080centr00260chang00090circu00100close00070comme00120commi00  n        120commo00190compa00120compl00050conce00070confe00050consi00160conti0011  n        0contr00240coope00060corre00050could00150count00110credi00070curre00830c  n        usto00120daily00080day    n        00090deale00340decli00060defic00090deman00060depos00070did    n        00060dinar00050direc00060disco00100discu00050dlrs   n        00280dolla00650domes00090drain00060durin00100earli00050early00170econo00  n        300end  00050engla00160estim00110exces00070excha00530facto00050fall   n        00140far  00110fecs 00060fed  00150feder00100fell   n        00090finan00200firms00050five 00090for    n        00630forec00130forei00330foste00060four   n        00050franc00090frenc00070frida00050from 00520fund   n        00060funds00160furth00110futur00090germa00110giord00080given00080gold   n        00050gover00150great00050growt00060had  00450has  00180have   n        00420hedgi00060help 00140herst00050highe00050his    n        00050horne00050hours00080house00170imbal00050inclu00050incre00090indus00  n        110insti00050inter00390into 00100intro00050inves00150its    n        00420james00070janua00090japan00280key  00050large00120last 00150late   n        00080leban00080level00090life   n        00050light00070likel00060liqui00210local00050londo00150low    n        00090major00130make 00050manag00050many   n        00050march00530marke00870marks00100measu00060meeti00100might00070minis00  n        160mln  00570monet00220money00480month00120more 00150morni00070most   n        00050much 00110must 00060natio00110neede00080new  00250not  00330note   n        00050now  00110offer00090offic00210one  00210open   n        00100openi00050opera00070optio00200other00160out  00080over   n        00060paris00120pct  00400phila00060phlx   n        00100polic00240popul00050prese00050presi00060press00120price00200proce00  n        050produ00070provi00150purch00150range00050rate   n        00160rates00200recen00130recor00060reduc00080remai00060repor00060repur00  n        090reser00160respe00050resul00070retur00060reute00090revis00100rise   n        00060said 01620sales00050say  00060says 00100secre00080secur00160seen   n        00060selli00070serve00060sessi00080set    n        00050short00200shoul00080since00090six  00070small00050sold 00060some   n        00180sourc00090spoke00070stabi00120start00060state00190stg    n        00590still00100stock00070stren00060subst00050such   n        00080sumit00080suppl00070suppo00050surpl00070surve00050suspe00060syste00  n        270taiwa00060take 00080takin00050targe00080than 00120that 00540the    n        05750their00260them 00070these00100they 00230third00050this   n        00280those00060thoug00080three00080throu00080time   n        00060today00310tokyo00100told   n        00140total00080trade00240tradi00200trans00100treas00460trust00050two    n        00140u.k  00110u.s  00330under00110unite00090was  00310washi00080week   n        00050were 00190west 00090when 00090which00270while00130will 00410with   n        00540worki00050world00050would00320year 00180yen    n        00130yeste00060yield00060york 0007 , n        1about00141accep00111accou00131added00051adjus00261after00331again00141a  n        ggre00101ago  00071all  00061also 00061and    n        01451annua00131april00161are    n        00081asset00171autho00061avera00211balan00251bank   n        00891banki00081banks00291been   n        00081befor00051billi02851books00051borro00141both   n        00051broad00191budge00061bunde00051busin00201but  00171canad00251cash   n        00101cds    n        00081centr00161certi00051chang00061chart00131circu00111comme00101compa00  n        331confi00081contr00111credi00101curre00151daily00071data 00161day    n        00101days   n        00061decem00731defic00071defin00061deman00061depos00461disco00051dlr    n        00071dlrs 02251dolla00111down 00071durin00091earli00131econo00301end    n        00251ended00231estim00051exces00081exclu00061expan00051expec00071fall   n        00121falls00071feb  00111febru00711fed  00311fed s00061feder00251fell   n        00651figur00161finan00061first00061fixed00081float00061fomc 00091for    n        00481forec00061forei00111four 00051from   n        01021funds00121gener00051gover00151grew 00131growt00451had  00131has    n        00121have 00091high   n        00051howev00051inclu00091incre00261infla00101inter00221inves00051issue00  n        131its  00171janua00811japan00061korea00061large00111last   n        00191lates00131lendi00061level00101liqui00141loan   n        00101loans00251local00051m-1  00571m-1-a00081m-2  00301m-3    n        00231major00101march00691marke00151marks00061measu00191membe00051mln    n        00911monet00161money00951month00271more 00081movin00061n.z    n        00051narro00081natio00081net  00121new  00231non-b00061non-p00081not    n        00131note 00051notes00081novem00221offic00091one    n        00131opera00061other00081outst00101over 00091pct    n        02201perio00131perso00061pesos00091plus   n        00191polic00191possi00051previ00221prior00051priva00101proje00051provi00  n        221publi00071quart00101range00061rate   n        00131rates00101recen00051requi00071reser00571respe00091restr00051reute00  n        081revis00181rise 00391rises00161rose 01091said 01121same   n        00081savin00111seaso00201secto00151secur00071set    n        00061short00091showe00111sight00051singa00141six    n        00141sligh00051small00071some   n        00081spain00071spoke00091state00171sterl00081stg    n        00201still00051stock00061sugge00051suppl00691syste00061targe00091tax    n        00051term 00091than 00071that 00491the  04291there00131they 00071this   n        00161three00101thurs00051tight00051time 00061today00071told   n        00051total00261tradi00061treas00231two  00111two-w00051u.s    n        00231unadj00061uncha00071was  00481washi00091wedne00111week   n        00471weeks00071were 00221when 00091which00261while00111with   n        00441would00121year 00581year-00191yen  00051york 0016 , n        2about00302acces00142accor00072accou00102act    n        00102actio00322added00132addin00082addit00052admin00122after00222again00  n        392agree00572agric00102ahead00052all  00182alleg00182alrea00092also   n        00272altho00082amend00052ameri00312analy00272and    n        02742anger00092annou00182anoth00052any    n        00122appea00062appli00092appro00112april00312are    n        00572areas00052aroun00052attem00052avert00052avoid00082baker00052baldr00  n        122bank 00112banki00062barri00062becau00132been   n        00212befor00142begin00052being00132betwe00122bilat00122bill   n        00172billi00532bond 00072boost00152both   n        00112brita00102briti00112budge00112busin00122but  00632buy  00082byrd   n        00052call 00072calle00102can    n        00192certa00052chair00052chanc00072chang00112chief00072china00242chine00  n        082chip 00362chips00232chira00112clerc00082close00062come   n        00142comme00142commi00202commu00132compa00272compe00132compl00072compu00  n        182conab00052conce00142conci00062congr00262consi00142consu00102conta0007  n        2conti00092contr00132convi00052corp   n        00102corre00082could00282counc00122count00492criti00052croo   n        00052curbs00072curre00172cut  00132cut-p00082days 00052deals00052debt   n        00062decis00142decli00122defic00282deman00052democ00172depar00112desig00  n        052despi00062devel00162did    n        00082diffi00102dinar00062diplo00062direc00062discu00072dispu00312dlr    n        00072dlrs 00452dolla00172domes00142down 00072drop 00052due    n        00062dumpi00142durin00082dutie00062each   n        00072earli00102early00082econo00372edwar00052eep    n        00092effec00102effor00102elect00332encou00052end    n        00072ended00052estab00062europ00292excha00142expan00112expec00222expor00  n        482expre00062failu00142fall   n        00062feder00072figur00132final00072finan00252firm   n        00052firms00092first00132fisca00052five 00052focus00052follo00062for    n        01192force00102forei00322four 00062franc00092free   n        00052frenc00072frict00052frida00092from 00732fso  00062full   n        00072furth00072gatt 00182gener00102give 00072going00062good   n        00072goods00342gover00512growi00102growt00072had  00202has  00582have   n        00422heari00052help 00102here 00082high-00112highe00092his  00292hit    n        00052hope 00062house00312howev00072huge   n        00082imbal00072immed00062impac00052imple00052impor00592impos00252inclu00  n        222incre00282india00162indus00392inste00052insti00082insur00082inter0033  n        2into 00132inves00162invol00062islam00052issue00242its    n        00632japan02762joint00092just 00092key  00052large00152last   n        00482lates00052ldp  00112leade00112leadi00052legis00082less   n        00082level00052licen00052likel00182line 00052littl00052live   n        00102loans00062londo00142long 00052longe00052lower00052ltd  00092made   n        00112major00122make   n        00142maker00152manuf00052march00572marke00722matsu00062may  00172mean   n        00052measu00152meeti00122membe00052memor00052micro00222might00102minis00  n        502miti 00162mln  00332money00072month00162more 00332most 00102move   n        00072much 00182must 00052nakas00542natio00132nec  00062negot00092new    n        00222news 00092next 00212not  00672noted00062now  00192off    n        00082offer00072offic01072one  00122only 00152open   n        00202oppos00062other00222our  00102out  00072outpu00092over 00352own    n        00102packa00092pact 00262parli00092part   n        00052parti00082partn00052parts00062passe00052pct  00272pekin00062per    n        00052persu00062plan   n        00062plann00062plans00222point00092polic00202polit00142posit00062possi00  n        062power00082pract00082predi00062prepa00082prese00082presi00302press0014  n        2preve00082price00082prime00182priva00062proba00102probl00102produ00442p  n        rogr00062propo00132prote00192provi00052publi00062purch00062put    n        00072quart00132quest00062quick00062rapid00062rate   n        00092rates00052reach00062react00072reaga00492reaso00052recen00092recom00  n        122recor00102reduc00132refle00052relat00102remai00072repor00212repre0005  n        2repub00082respo00132restr00102resul00052retal00382retur00072reute00222r  n        ise 00112risk 00052row  00122said 02842sales00052same   n        00052sanct00302say  00062says 00052secon00072secre00132secur00112see    n        00052sees 00072selli00062semic00602senat00102send   n        00052senio00082separ00052servi00142set  00142settl00122share00092she    n        00102short00102shoul00072sides00072signe00102signi00082since00052smart00  n        052solve00052some 00162soon   n        00052sough00062sourc00262sovie00112speci00072spoke00142start00052state00  n        682stati00052steph00052still00092stock00102stop   n        00132stopp00052stron00062succe00052such 00152sugge00052suppo00082sure   n        00062surpl00212syste00062taiwa00082take   n        00252taken00062takin00062talks00192targe00062tarif00492tax    n        00062techn00072telec00062telev00052terms00062texti00102than 00222that   n        01502thatc00052the  08372their00292them 00142there00182they   n        00572thing00052think00112third00122this   n        00442those00102threa00102three00052throu00112time   n        00122today00122tokyo00422told   n        00282total00112trade02562tradi00112treas00062trip 00062try  00112two    n        00202u.k  00082u.s    n        01672u.s.-00182u.s./  n        00052under00252unfai00072union00082unite00532urged00062use    n        00052value00122very 00122viola00062visit00212want 00062wants00062war    n        00352was  00762washi00612way  00092ways 00052week 00242well 00072were   n        00222west 00092what 00142when   n        00092where00052wheth00072which00292while00122white00152who  00112will   n        00692willi00062with 01112wolf 00052work   n        00062worki00052world00352worth00072would00952yasuh00122year   n        00542years00102yeste00112yeutt00132you  00072yugos0005 , n   }; n   for (int(th) = 0; (th) < (TH); (th)++) { n     string& s = str[th]; n     for (int i = 0; i < s.size(); i += 1 + STR_MAX + NUMSZ) { n       stringstream ss; n       ss << s.substr(i + 1 + STR_MAX, NUMSZ); n       int cnt; n       ss >> cnt; n       mem[s[i] -  0 ][DelSpaces(s.substr(i + 1, STR_MAX))] = cnt; n       sum[s[i] -  0 ] += cnt; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 2; n vector<int> g[maxn]; n vector<long long> c[maxn], acum[maxn]; n int n, m, q, idx, comp[maxn]; n long long d[maxn], dist[maxn]; n map<pair<int, int>, long long> memo; n vector<int> cur; n void dfs(int node, int par) { n   comp[node] = idx; n   cur.push_back(node); n   for (auto &adj : g[node]) n     if (adj != par) dfs(adj, node); n } n pair<int, long long> bfs(int node) { n   queue<int> Q; n   for (auto &v : cur) dist[v] = -1; n   dist[node] = 0; n   Q.push(node); n   int last = -1; n   while (!Q.empty()) { n     node = Q.front(); n     Q.pop(); n     last = node; n     for (auto &adj : g[node]) { n       if (dist[adj] == -1) { n         dist[adj] = dist[node] + 1; n         Q.push(adj); n       } n     } n   } n   return {last, dist[last]}; n } n void diameter(int node) { n   auto a = bfs(node); n   auto b = bfs(a.first); n   d[idx] = b.second; n   for (int i = 0; i < (int)cur.size(); i++) c[idx][i] = dist[cur[i]]; n   bfs(b.first); n   for (int i = 0; i < (int)cur.size(); i++) n     c[idx][i] = max(c[idx][i], dist[cur[i]]); n   sort(c[idx].begin(), c[idx].end()); n   acum[idx][0] = c[idx][0]; n   for (int i = 1; i < (int)cur.size(); i++) n     acum[idx][i] = acum[idx][i - 1] + c[idx][i]; n } n void process(int node) { n   idx++; n   cur.clear(); n   dfs(node, 0); n   c[idx].resize(cur.size()); n   acum[idx].resize(cur.size()); n   diameter(cur[0]); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout << setprecision(10) << fixed; n   cin >> n >> m >> q; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) n     if (comp[i] == 0) process(i); n   while (q--) { n     int x, y; n     cin >> x >> y; n     x = comp[x]; n     y = comp[y]; n     if (x == y) { n       cout << -1 <<   n ; n       continue; n     } n     if ((long long)c[x].size() > (long long)c[y].size()) swap(x, y); n     long long N = (long long)c[x].size(), M = (long long)c[y].size(); n     if (memo.find({x, y}) != memo.end()) { n       cout << (1.0 * memo[pair<int, int>(x, y)]) / (1.0 * N * M) <<   n ; n       continue; n     } n     long long ans = 0; n     long long mx = max(d[x], d[y]); n     for (auto &v : c[x]) { n       long long lo = 0, hi = M - 1LL; n       long long pos = -1; n       while (lo <= hi) { n         long long mid = (lo + hi) >> 1LL; n         if (v + c[y][mid] + 1 <= mx) { n           pos = mid; n           lo = mid + 1; n         } else n           hi = mid - 1; n       } n       if (pos == -1) { n         ans += acum[y][M - 1] + M * (v + 1); n       } else { n         ans += (pos + 1) * mx; n         ans += acum[y][M - 1] - acum[y][pos] + (v + 1) * (M - pos - 1); n       } n     } n     memo[pair<int, int>(x, y)] = ans; n     memo[pair<int, int>(y, x)] = ans; n     cout << (1.0 * ans) / (1.0 * N * M) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > V; n int in[50]; n int main() { n   vector<string> S; n   V.resize(30); n   int n, ile; n   cin >> n; n   ile = n; n   while (ile--) { n     string a; n     cin >> a; n     S.push_back(a); n   } n   for (int i = 0; i < S.size(); i++) { n     for (int j = i + 1; j < S.size(); j++) { n       for (int k = 0; k < min(S[i].size(), S[j].size()); k++) { n         if (S[i][k] == S[j][k]) { n           if (k + 1 == S[j].size()) { n             cout <<  Impossible ; n             return 0; n           } n           continue; n         } n         V[S[i][k] -  a ].push_back(S[j][k] -  a ); n         in[S[j][k] -  a ]++; n         break; n       } n     } n   } n   vector<int> kol; n   queue<int> Q; n   for (int i = 0; i < 26; i++) n     if (in[i] == 0) Q.push(i); n   while (!Q.empty()) { n     int v = Q.front(); n     Q.pop(); n     kol.push_back(v); n     for (auto sas : V[v]) { n       in[sas]--; n       if (in[sas] == 0) Q.push(sas); n     } n   } n   if (kol.size() < 26) { n     cout <<  Impossible ; n     return 0; n   } n   for (auto c : kol) cout << (char(c +  a )); n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> primer; n long long mul(long long x, long long y, long long mod) { n   long long s = 0; n   for (; y; y /= 2, x = (x + x) % mod) n     if (y & 1) s = (s + x) % mod; n   return s; n } n long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } n long long power(long long x, long long y, long long mo) { n   long long s = 1; n   for (; y; y /= 2, x = mul(x, x, mo)) n     if (y & 1) s = mul(s, x, mo); n   return s; n } n bool isPrime(long long x) { n   if (x == 2) return 1; n   for (int T = 10; T; T--) { n     long long a = rand() % (x - 2) + 2; n     if (power(a, x - 1, x) != 1) return 0; n     int p = x - 1; n     for (; p % 2 == 0;) { n       p /= 2; n       long long v = power(a, p, x); n       if (mul(v, v, x) == 1 && v != 1 && v != x - 1) return 0; n     } n   } n   return 1; n } n long long pollard(long long n, int c) { n   long long i = 0, k = 2, x = rand() % (n - 1) + 1, y = x; n   for (;;) { n     x = (mul(x, x, n) + c) % n; n     long long g = gcd((y - x + n) % n, n); n     if (g != 1 && g != n) return g; n     if (x == y) return n; n     if ((++i) == k) y = x, k <<= 1; n   } n } n void getPrimes(long long n, vector<long long> &p) { n   if (n == 1) return; n   if (isPrime(n)) { n     p.push_back(n); n     return; n   } n   long long d = n; n   for (int i = 2; d == n; i++) d = pollard(n, i); n   getPrimes(d, p); n   getPrimes(n / d, p); n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline void moreprime() { n   int start = primer.back() + 1; n   if (primer.size() % 10000 == 0) n     cout << primer.size() <<     << primer.back() << endl; n   while (true) { n     for (unsigned int i = 0; i < primer.size(); i++) { n       if (start % primer[i] == 0) break; n       if (primer[i] * primer[i] > start) { n         primer.push_back(start); n         return; n       } n     } n     start++; n   } n } n vector<long long> defactor(long long a) { n   vector<long long> result; n   getPrimes(a, result); n   sort(result.begin(), result.end()); n   vector<long long> rs; n   if (result.size() > 0) rs.push_back(result[0]); n   for (int i = 1; i < result.size(); i++) { n     if (result[i] != result[i - 1]) rs.push_back(result[i]); n   } n   return rs; n } n int getbit(long long a, const vector<long long> &factors) { n   int bit = 0; n   for (unsigned int i = 0; i < factors.size(); i++) { n     if (a % factors[i] == 0) { n       a /= factors[i]; n       bit |= 1 << i; n     } n   } n   return bit; n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   int n; n   long long x, y; n   primer.push_back(2); n   cin >> n >> x >> y; n   if (y % x != 0) { n     printf( 0 ); n     return 0; n   } n   vector<long long> factors = defactor(y / x); n   vector<long long> a(40000, 0), b(40000, 0); n   int maxa = 0, maxb = 0; n   int v; n   long long num; n   for (int i = 0; i < n; i++) { n     cin >> num; n     if (num % x == 0) { n       v = getbit(num / x, factors); n       a[v]++; n       maxa = max(maxa, v); n     } n     if (y % num == 0) { n       v = getbit(y / num * gcd(y / num, num) / gcd(y / num, x), factors); n       b[v]++; n       maxb = max(maxb, v); n     } n   } n   long long count = 0; n   for (int i = 0; i <= maxa; i++) { n     if (a[i]) { n       for (int j = 0; j <= maxb; j++) { n         if (b[j]) { n           if (!(i & j)) count += a[i] * b[j]; n         } n       } n     } n   } n   cout << count << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n inline int GetIdx(int l, int r) { return l + r | l != r; } n int seg[maxn << 2]; n void update(int l, int r, int x, int d) { n   if (l == r) { n     seg[GetIdx(l, r)] = d; n     return; n   } n   int mid = (l + r) >> 1; n   if (x <= mid) { n     update(l, mid, x, d); n   } else { n     update(mid + 1, r, x, d); n   } n   seg[GetIdx(l, r)] = min(seg[GetIdx(l, mid)], seg[GetIdx(mid + 1, r)]); n } n int query(int l, int r, int ua, int ub) { n   if (ua <= l && ub >= r) { n     return seg[GetIdx(l, r)]; n   } n   int mid = (l + r) >> 1; n   int res = 1 << 30; n   if (ua <= mid) { n     res = min(res, query(l, mid, ua, ub)); n   } n   if (ub > mid) { n     res = min(res, query(mid + 1, r, ua, ub)); n   } n   return res; n } n vector<int> line[maxn]; n pair<int, int> rook[maxn << 1], rec1[maxn << 1], rec2[maxn << 1]; n bool ans[maxn << 1]; n int main() { n   int n, m, k, q; n   while (~scanf( %d%d%d%d , &n, &m, &k, &q)) { n     for (int i = 0; i < k; i++) { n       scanf( %d%d , &rook[i].first, &rook[i].second); n     } n     for (int i = 0; i < q; i++) { n       scanf( %d%d%d%d , &rec1[i].first, &rec1[i].second, &rec2[i].first, n             &rec2[i].second); n     } n     for (int cas = 1; cas <= 2; cas++) { n       memset(seg, 0, sizeof seg); n       for (int i = 1; i <= n; i++) { n         line[i].clear(); n       } n       for (int i = 0; i < k; i++) { n         line[rook[i].first].push_back(rook[i].second); n       } n       for (int i = 0; i < q; i++) { n         line[rec2[i].first].push_back(~i); n       } n       for (int i = 1; i <= n; i++) { n         for (int j = 0; j < line[i].size(); j++) { n           int tmp = line[i][j]; n           if (tmp < 0) { n             tmp = ~tmp; n             if (query(1, m, rec1[tmp].second, rec2[tmp].second) >= n                 rec1[tmp].first) { n               ans[tmp] = true; n             } n           } else { n             update(1, m, tmp, i); n           } n         } n       } n       swap(n, m); n       for (int i = 0; i < k; i++) { n         swap(rook[i].first, rook[i].second); n       } n       for (int i = 0; i < q; i++) { n         swap(rec1[i].first, rec1[i].second); n         swap(rec2[i].first, rec2[i].second); n       } n     } n     for (int i = 0; i < q; i++) { n       puts(ans[i] ?  YES  :  NO ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mod = 1e9 + 7; n int mat[2 * 100001][26]; n int n, k; n int count3 = 0; n void find_most(int x, int y) { n   int total = 0, mx = 0; n   for (int i = 0; i < 26; i++) { n     total += mat[x][i] + mat[y][i]; n     mx = max(mx, mat[x][i] + mat[y][i]); n   } n   count3 += total - mx; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     string s; n     cin >> s; n     for (int i = 0; i < k; i++) { n       for (int j = 0; j < 26; j++) mat[i][j] = 0; n     } n     for (int i = 0; i < n; i++) { n       mat[i % k][s[i] -  a ]++; n     } n     for (int i = 0; i < k; i++) { n       find_most(i, k - i - 1); n     } n     cout << (count3) / 2; n     count3 = 0; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = 105; n const long long MAXV = 2e5 + 1; n const long long INF = 1e9; n bool prime[MAXV]; n void sieve() { n   memset(prime, true, sizeof(prime)); n   prime[0] = prime[1] = false; n   for (long long i = 2; i * i < MAXV; i++) { n     if (prime[i]) { n       for (long long j = i * i; j < MAXV; j += i) prime[j] = false; n     } n   } n } n long long n, k, p[MAX], c[MAX], l[MAX]; n struct edge { n   int from, to, flow, index; n   long long cap; n   edge(int from, int to, long long cap, int flow, int index) n       : from(from), to(to), cap(cap), flow(flow), index(index) {} n }; n struct PushRelabel { n   int n; n   vector<vector<edge>> g; n   vector<long long> excess; n   vector<int> height, active, count; n   queue<int> Q; n   PushRelabel(int n) n       : n(n), g(n), excess(n), height(n), active(n), count(2 * n) {} n   void addEdge(int from, int to, long long cap) { n     g[from].push_back(edge(from, to, cap, 0, g[to].size())); n     if (from == to) g[from].back().index++; n     g[to].push_back(edge(to, from, 0, 0, g[from].size() - 1)); n   } n   void enqueue(int v) { n     if (!active[v] && excess[v] > 0) { n       active[v] = true; n       Q.push(v); n     } n   } n   void push(edge &e) { n     int amt = (int)min(excess[e.from], (long long)e.cap - e.flow); n     if (height[e.from] <= height[e.to] || amt == 0) return; n     e.flow += amt; n     g[e.to][e.index].flow -= amt; n     excess[e.to] += amt; n     excess[e.from] -= amt; n     enqueue(e.to); n   } n   void relabel(int v) { n     count[height[v]]--; n     int d = 2 * n; n     for (auto &it : g[v]) { n       if (it.cap - it.flow > 0) d = min(d, height[it.to] + 1); n     } n     height[v] = d; n     count[height[v]]++; n     enqueue(v); n   } n   void gap(int k) { n     for (int v = 0; v < n; v++) { n       if (height[v] < k) continue; n       count[height[v]]--; n       height[v] = max(height[v], n + 1); n       count[height[v]]++; n       enqueue(v); n     } n   } n   void discharge(int v) { n     for (int i = 0; excess[v] > 0 && i < g[v].size(); i++) push(g[v][i]); n     if (excess[v] > 0) { n       if (count[height[v]] == 1) n         gap(height[v]); n       else n         relabel(v); n     } n   } n   long long max_flow(int source, int dest) { n     count[0] = n - 1, count[n] = 1, height[source] = n, n     active[source] = active[dest] = 1; n     for (auto &it : g[source]) { n       excess[source] += it.cap; n       push(it); n     } n     while (!Q.empty()) { n       int v = Q.front(); n       Q.pop(); n       active[v] = false; n       discharge(v); n     } n     long long max_flow = 0; n     for (auto &e : g[source]) max_flow += e.flow; n     return max_flow; n   } n }; n bool f(long long lvl) { n   vector<long long> v = {0}; n   long long sm = 0, mx = -1, id = 0; n   for (long long i = 1; i <= n; i++) { n     if (l[i] <= lvl) { n       if (c[i] != 1) { n         sm += p[i]; n         v.push_back(i); n       } else { n         if (p[i] > mx) { n           mx = p[i]; n           id = i; n         } n       } n     } n   } n   if (mx != -1) { n     v.push_back(id); n     sm += p[id]; n   } n   long long cnt = v.size() - 1; n   PushRelabel Network(cnt + 2); n   long long s = 0, t = cnt + 1; n   vector<int> odd, even; n   odd.push_back(0), even.push_back(0); n   for (int i = 1; i <= cnt; i++) { n     if (c[v[i]] & 1) n       odd.push_back(v[i]); n     else n       even.push_back(v[i]); n   } n   int os = odd.size() - 1, es = even.size() - 1; n   for (int i = 1; i <= os; i++) Network.addEdge(s, i, p[odd[i]]); n   for (int i = 1; i <= es; i++) Network.addEdge(os + i, t, p[even[i]]); n   for (int i = 1; i <= os; i++) { n     for (int j = 1; j <= es; j++) { n       int idx1 = odd[i], idx2 = even[j]; n       if (prime[c[idx1] + c[idx2]]) Network.addEdge(i, os + j, INF); n     } n   } n   long long flow = Network.max_flow(s, t); n   long long mxpow = sm - flow; n   return mxpow >= k; n } n void solve() { n   long long l = 0, r = n + 1; n   while (r - l > 1) { n     long long mid = (l + r) / 2; n     if (f(mid)) n       r = mid; n     else n       l = mid; n   } n   if (f(r)) n     cout << r; n   else n     cout << -1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   sieve(); n   cin >> n >> k; n   for (long long i = 1; i <= n; i++) cin >> p[i] >> c[i] >> l[i]; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool vis[500009]; n int siz[500009]; n int rr[1005][1005]; n char arr[1005][1005]; n vector<int> d; n int n; n void dfs(int x, int y, int cn) { n   if (x > n or y > n or x < 1 or y < 1 or rr[x][y] != 0) return; n   rr[x][y] = cn; n   siz[cn]++; n   if (arr[x + 1][y] ==  . ) dfs(x + 1, y, cn); n   if (arr[x][y + 1] ==  . ) dfs(x, y + 1, cn); n   if (arr[x - 1][y] ==  . ) dfs(x - 1, y, cn); n   if (arr[x][y - 1] ==  . ) dfs(x, y - 1, cn); n } n void rem(int i, int j, int k) { n   for (int t = i; t < i + k; t++) { n     if (arr[t][j] ==  . ) siz[rr[t][j]]--; n   } n } n int count(int i, int j, int k) { n   vector<int> v; n   int e, ans = 0; n   for (int y = i; y < i + k && j - 1 >= 1; y++) { n     e = rr[y][j - 1]; n     if (!vis[e] && e) { n       v.push_back(e); n       vis[e] = 1; n       ans += siz[e]; n     } n   } n   for (int y = j; y < j + k && i - 1 >= 1; y++) { n     e = rr[i - 1][y]; n     if (!vis[e] && e) { n       v.push_back(e); n       vis[e] = 1; n       ans += siz[e]; n     } n   } n   for (int y = i; y < i + k && j + k <= n; y++) { n     e = rr[y][j + k]; n     if (!vis[e] && e) { n       v.push_back(e); n       vis[e] = 1; n       ans += siz[e]; n     } n   } n   for (int y = j; y < j + k && i + k <= n; y++) { n     e = rr[i + k][y]; n     if (!vis[e] && e) { n       v.push_back(e); n       vis[e] = 1; n       ans += siz[e]; n     } n   } n   for (int i = 0; i < v.size(); i++) { n     vis[v[i]] = 0; n   } n   return ans; n } n void add(int i, int j, int k) { n   for (int t = i; t < i + k; t++) { n     if (arr[t][j] ==  . ) siz[rr[t][j]]++; n   } n } n int main() { n   int k, e = 0, a = 0; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cin >> arr[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (arr[i][j] ==  .  && rr[i][j] == 0) dfs(i, j, ++e); n     } n   } n   for (int i = 1; i <= n - k + 1; i++) { n     for (int y = 1; y <= k; y++) { n       rem(i, y, k); n     } n     a = count(i, 1, k); n     d.push_back(a); n     int last = 1; n     for (int j = 2; j <= n - k + 1; j++) { n       rem(i, j + k - 1, k); n       add(i, j - 1, k); n       last = j; n       a = count(i, j, k); n       d.push_back(a); n     } n     for (int y = last; y <= n; y++) { n       add(i, y, k); n     } n   } n   sort(d.begin(), d.end()); n   cout << d[d.size() - 1] + (k * k) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = n     3.14159265358979323846264338327950288419716939937510582097494459230; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, i, x; n   cin >> n; n   int vis[n + 4]; n   int cnt[n + 4]; n   memset(cnt, 0, sizeof(cnt)); n   memset(vis, 0, sizeof(vis)); n   for (i = 0; i < n; i++) { n     cin >> x; n     cnt[x]++; n   } n   for (i = 1; i <= n; i++) { n     if (cnt[i] >= 3) { n       vis[i - 1] = 1; n       vis[i] = 1; n       vis[i + 1] = 1; n     } else { n       int d = cnt[i], j; n       for (j = i - 1; j <= i + 1; j++) { n         if (d == 0) break; n         if (vis[j] == 1) n           continue; n         else { n           vis[j] = 1; n           d--; n         } n       } n     } n   } n   int ans = 0; n   for (i = 1; i <= n; i++) { n     if (cnt[i] == 0) continue; n     ans++; n     i = i + 2; n   } n   cout << ans <<     << count(vis, vis + n + 2, 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[100005], res[100005]; n map<int, pair<int, int>> xhMap; n int main() { n   memset(x, 0, sizeof(x)); n   memset(res, 0, sizeof(res)); n   int n = 0, a = 0, b = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d%d , &a, &b); n     x[i] = a; n     xhMap[a] = make_pair(b, i); n   } n   sort(x, x + n); n   for (int i = n - 1; i >= 0; --i) { n     int tmp = x[i] + xhMap[x[i]].first - 1, idx = xhMap[x[i]].second; n     int r = i + 1, num = 1; n     while (r < n && x[r] <= tmp) { n       num += res[xhMap[x[r]].second]; n       r += res[xhMap[x[r]].second]; n     } n     res[idx] = num; n   } n   for (int i = 0; i < n; ++i) { n     printf( %d  , res[i]); n   } n   return 0; n } n