#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long int j, n, m, po, a, b, no, flag, cnt = 0, t, cnt2, ar[200001], x, y, n                                              i, co[200001], sum = 0, k, n                                              ans = INT_MIN, sum1 = 0; n   string str[1000], ptr, tr, rtr, rt; n   vector<long long int> v1, v2; n   set<string> s; n   set<long long int> si; n   queue<long long int> qui; n   queue<string> qus; n   set<string>::iterator it; n   cin >> t; n   while (t--) { n     cin >> n >> a >> b; n     string sr; n     for (i = 0; i < a; i++) { n       sr[i] = char( a  + i % b); n     } n     for (i = 0; i < n; i++) { n       cout << sr[i % a]; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long cnt[5], ans1, ans2; n int main() { n   int n, a[200010]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 1) n       cnt[1]++; n     else n       cnt[0]++; n   } n   for (int i = 0; i < n; i++) { n     if (a[i] == 0) n       cnt[0]--; n     else { n       ans1 += cnt[0]; n     } n   } n   cout << ans1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char s[200], t[200]; n int cnt[200], cnt2[200]; n int check(int p, char t[]) { n   int i; n   for (i = 0; i < 26; i++) { n     cnt2[i] = 0; n   } n   for (i = p; i < p + n; i++) { n     cnt2[t[i] -  a ]++; n   } n   for (i = 0; i < 26; i++) { n     if (cnt[i] != cnt2[i]) return 0; n   } n   return 1; n } n int main() { n   int T, flag, i; n   scanf( %d , &T); n   while (T--) { n     flag = 0; n     scanf( %s%s , s, t); n     n = strlen(s); n     m = strlen(t); n     for (i = 0; i < 26; i++) { n       cnt[i] = 0; n     } n     for (i = 0; i < n; i++) { n       cnt[s[i] -  a ]++; n     } n     for (i = 0; i <= m - n; i++) { n       if (check(i, t)) { n         flag = 1; n         break; n       } n     } n     if (flag) { n       printf( YES n ); n     } else { n       printf( NO n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n struct node { n   long long k[51][51]; n } a, ans; n long long t, n, m, q, op, x, y, z, s = 1, mp[26][26]; n inline long long read() { n   long long sum = 0, x = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) x = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     sum = sum * 10 + ch -  0 ; n     ch = getchar(); n   } n   return sum * x; n } n inline void write(long long x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n   return; n } n inline node mul(node a, node b) { n   node c; n   memset(c.k, 0, sizeof(c.k)); n   for (register long long i = 1; i <= t; ++i) n     for (register long long j = 1; j <= t; ++j) n       for (register long long p = 1; p <= t; p++) n         c.k[i][j] = (c.k[i][j] + a.k[i][p] * b.k[p][j]) % mod; n   return c; n } n inline void power(long long b) { n   for (; b; b >>= 1, a = mul(a, a)) n     if (b & 1) ans = mul(a, ans); n } n inline void build() { n   for (register long long i = 1; i <= t; ++i) n     for (register long long j = 1; j <= t; ++j) { n       long long aa = ((i - 1) / m) + 1, bb = (i - 1) % m + 1, n                 A = ((j - 1) / m) + 1, B = (j - 1) % m + 1; n       if (mp[aa][bb] == 0 && mp[A][B] == 0 && abs(A - aa) + abs(B - bb) <= 1) n         a.k[i][j] = 1; n       else n         a.k[i][j] = 0; n     } n } n signed main() { n   n = read(); n   m = read(); n   q = read(); n   t = n * m; n   ans.k[1][1] = 1; n   while (q--) { n     build(); n     op = read(); n     x = read(); n     y = read(); n     z = read(); n     power(z - s); n     s = z; n     if (op == 2 || op == 3) ans.k[(x - 1) * m + y][1] = 0; n     if (op == 2) mp[x][y] = 1; n     if (op == 3) mp[x][y] = 0; n     if (op == 1) { n       write(ans.k[(x - 1) * m + y][1]); n       putchar(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long base, long long exp) { n   long long res = 1; n   while (exp > 0) { n     if (exp % 2 == 1) res = (res * base); n     base = (base * base); n     exp /= 2; n   } n   return res; n } n long long mod(long long a, long long b) { return (a % b + b) % b; } n long long powerm(long long base, long long exp, long long mod) { n   long long ans = 1; n   while (exp) { n     if (exp & 1) ans = (ans * base) % mod; n     exp >>= 1, base = (base * base) % mod; n   } n   return ans; n } n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   t = 1; n   while (t--) { n     string s; n     cin >> s; n     cout << s; n     for (long long i = s.size() - 1; i >= 0; i--) cout << s[i]; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   set<int> s; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     if (x != 0) s.insert(x); n   } n   cout << s.size(); n } n


#include <bits/stdc++.h> n using namespace std; n const int MXN = 1024 * 1024; n int n; n int k; n int v[MXN]; n int c[MXN]; n int p[MXN]; n pair<int, int> vstk[MXN]; n pair<int, int> cstk[MXN]; n int vn, cn; n static pair<int, int> getxy(int iv) { n   int p1 = vstk[iv].first; n   auto cx = n       lower_bound(cstk, cstk + cn, p1, n                   [](const pair<int, int>& a, int b) { return a.first > b; }); n   return {vstk[iv].second, cx->second}; n } n static void calcP() { n   vn = 0; n   cn = 0; n   for (int i = n - 1; i >= 0; i--) { n     while (vn > 0 && vstk[vn - 1].second <= v[i]) vn--; n     vstk[vn++] = pair<int, int>(i, v[i]); n     while (cn > 0 && cstk[cn - 1].second >= c[i]) cn--; n     cstk[cn++] = pair<int, int>(i, c[i]); n     int l = 0, r = vn - 1; n     while (l < r) { n       int m = (l + r) / 2; n       pair<int, int> xy = getxy(m); n       if (xy.first < xy.second) n         r = m; n       else n         l = m + 1; n     } n     pair<int, int> a1 = getxy(l); n     int tans = min(a1.first, a1.second); n     if (l > 0) { n       a1 = getxy(l - 1); n       tans = max(tans, min(a1.first, a1.second)); n     } n     p[i] = tans; n   } n } n static double solve() { n   for (int i = 0; i < n; i++) v[i] *= 100; n   calcP(); n   sort(p, p + n); n   double prb = double(k) / n; n   double ans = p[0] * prb; n   for (int i = 1; i < n && n - k - i + 1 >= 0; i++) { n     prb *= n - k - i + 1; n     prb /= (n - i); n     ans += p[i] * prb; n   } n   return ans; n } n int main() { n   while (scanf( %d %d , &n, &k) == 2) { n     for (int i = 0; i < n; i++) scanf( %d , v + i); n     for (int i = 0; i < n; i++) scanf( %d , c + i); n     double ans = solve(); n     printf( %.7f n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int *input = new int[n]; n   for (int i = 0; i < n; i++) cin >> input[i]; n   sort(input, input + n); n   int over = input[n - 1] + 1; n   int ans = 1; n   for (int i = n - 2; i >= 0; i--) { n     if (input[i] + 1 < over) { n       over = input[i] + 1; n       ans++; n     } else if (input[i] < over) { n       over = input[i]; n       ans++; n     } else if (input[i] - 1 > 0 && input[i] - 1 < over) { n       over = input[i] - 1; n       ans++; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<string, string>, int> m, m1; n vector<pair<string, string> > ans; n int main() { n   string s1, s2; n   int n, t, i, d, j; n   scanf( %d%d , &n, &d); n   for (i = 1; i <= n; i++) { n     cin >> s1 >> s2 >> t; n     for (j = 0; j < ans.size(); j++) n       if ((ans[j].first == s1 && ans[j].second == s2) || n           (ans[j].first == s2 && ans[j].second == s1)) n         break; n     if (j != int(ans.size())) continue; n     t++; n     if ((m[make_pair(s2, s1)] != 0 && t - m[make_pair(s2, s1)] <= d && n          t - m[make_pair(s2, s1)] > 0) || n         (m1[make_pair(s2, s1)] != 0 && t - m1[make_pair(s2, s1)] <= d && n          t - m1[make_pair(s2, s1)] > 0)) n       ans.push_back(make_pair(s1, s2)); n     if (m[make_pair(s1, s2)] != t) m1[make_pair(s1, s2)] = m[make_pair(s1, s2)]; n     m[make_pair(s1, s2)] = t; n   } n   printf( %d , int(ans.size())); n   for (i = 0; i < ans.size(); i++) n     cout << endl << ans[i].first <<     << ans[i].second; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename V> n void bugp(const pair<T, V> &x) { n   cerr <<  {  << x.first <<  ,   << x.second <<  }  << endl; n } n template <typename T, typename U, typename V> n void bugpp(const pair<T, pair<U, V> > &x) { n   cerr <<  {  << x.first <<  , {  << x.second.first <<  ,   << x.second.second n        <<  }}  << endl; n } n template <typename T> n bool maximize(T &x, const T &y) { n   if (x < y) { n     x = y; n     return 1; n   } n   return 0; n } n template <typename T> n bool minimize(T &x, const T &y) { n   if (x > y) { n     x = y; n     return 1; n   } n   return 0; n } n const int N = 2002; n int n, C[N], A[N], subsz[N]; n bool chk[N], answer = 1; n vector<int> child[N]; n int getNext(int idx) { n   int ans = -1; n   for (int i = 1, _n = (n); i <= _n; ++i) { n     if (!chk[i]) --idx; n     if (!idx) { n       ans = i; n       break; n     } n   } n   return ans; n } n void DFS(int u) { n   subsz[u] = 1; n   A[u] = getNext(C[u] + 1); n   if (A[u] == -1) n     answer = 0; n   else n     chk[A[u]] = 1; n   for (int &v : child[u]) { n     DFS(v); n     subsz[u] += subsz[v]; n   } n   if (C[u] >= subsz[u]) answer = 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   int root; n   for (int i = 1, _n = (n); i <= _n; ++i) { n     int p; n     cin >> p >> C[i]; n     if (p) n       child[p].push_back(i); n     else n       root = i; n   } n   DFS(root); n   if (!answer) n     cout <<  NO ; n   else { n     cout <<  YES n ; n     for (int i = 1, _n = (n); i <= _n; ++i) cout << A[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace io { n inline char nc() { n   static char buf[100000], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n template <class I> n inline void fr(I &num) { n   num = 0; n   register char c = nc(); n   register int p = 1; n   while (c <  0  || c >  9 ) c ==  -  ? p = -1, c = nc() : c = nc(); n   while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = nc(); n   num *= p; n } n template <class I> n inline I Max(I p, I q) { n   return p > q ? p : q; n } n template <class I> n inline I Min(I p, I q) { n   return p < q ? p : q; n } n template <class I> n inline I A(I x) { n   return x < 0 ? -x : x; n } n template <class I> n inline void sp(I &p, I &q) { n   I x = p; n   p = q, q = x; n } n template <class I> n inline void ckMax(I &p, I q) { n   p = (p > q ? p : q); n } n template <class I> n inline void ckMin(I &p, I q) { n   p = (p < q ? p : q); n } n };  // namespace io n using io ::A; n using io ::ckMax; n using io ::ckMin; n using io ::fr; n using io ::Max; n using io ::Min; n using io ::nc; n using io ::sp; n const int N = 1000005; n map<pair<int, int>, int> mp; n int n, k, cn, d; n inline void gcd(const int a, const int b) { n   return !b ? d = a, void() : gcd(b, a % b); n } n inline double dis(const int x, const int y) { n   return sqrt(1.0 * x * x + 1.0 * y * y); n } n struct ky { n   int x, y; n   double ds; n   bool operator<(const ky &p) const { return ds < p.ds; } n }; n vector<ky> vec[N]; n vector<double> o; n int main() { n   scanf( %d%d , &n, &k); n   const int kk = k >> 1; n   register double ans = 0; n   for (register int i = 1, x, y; i <= n; ++i) { n     scanf( %d%d , &x, &y); n     if ((!x) && (!y)) { n       vec[++cn].push_back((ky){x, y, 0}); n       continue; n     } n     gcd(A(x), A(y)); n     pair<int, int> p = make_pair(x / d, y / d); n     if (!mp[p]) mp[p] = ++cn; n     vec[mp[p]].push_back((ky){x, y, dis(x, y)}); n   } n   for (register int j = 1, i; j <= cn; ++j) { n     const int sz = vec[j].size(); n     register int mn = Min(kk, sz); n     std::sort(vec[j].begin(), vec[j].end()); n     for (i = 1; i <= mn; ++i) n       o.push_back(vec[j][sz - i].ds * ((k - i) - (i - 1))); n     double s = 0; n     mn = Min(k, sz); n     for (i = kk + 1; i <= mn; ++i) n       o.push_back(vec[j][i - kk - 1].ds * ((k - kk - 1) - kk) - 2.0 * s), n           s += vec[j][i - kk - 1].ds; n   } n   std::sort(o.begin(), o.end()); n   for (register int i = o.size() - 1; (~i) && k; --i) ans += o[i], --k; n   printf( %.9lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n vector<int> val[100010]; n int x[100010]; n int td[100010 * 4], ti[100010 * 4]; n int queryd(int node, int lo, int hi, int l, int r) { n   if (l > hi or r < lo) return 0; n   if (lo >= l and hi <= r) return td[node]; n   int md = (lo + hi) >> 1; n   int p1 = queryd(node << 1, lo, md, l, r); n   int p2 = queryd(node << 1 | 1, md + 1, hi, l, r); n   return max(p1, p2); n } n void updated(int node, int lo, int hi, int idx, int val) { n   if (lo == hi) { n     td[node] = max(td[node], val); n     return; n   } n   int md = (lo + hi) >> 1; n   if (idx <= md) n     updated(node << 1, lo, md, idx, val); n   else n     updated(node << 1 | 1, md + 1, hi, idx, val); n   td[node] = max(td[node << 1], td[node << 1 | 1]); n } n int queryi(int node, int lo, int hi, int l, int r) { n   if (l > hi or r < lo) return 0; n   if (lo >= l and hi <= r) return ti[node]; n   int md = (lo + hi) >> 1; n   int p1 = queryi(node << 1, lo, md, l, r); n   int p2 = queryi(node << 1 | 1, md + 1, hi, l, r); n   return max(p1, p2); n } n void updatei(int node, int lo, int hi, int idx, int val) { n   if (lo == hi) { n     ti[node] = max(ti[node], val); n     return; n   } n   int md = (lo + hi) >> 1; n   if (idx <= md) n     updatei(node << 1, lo, md, idx, val); n   else n     updatei(node << 1 | 1, md + 1, hi, idx, val); n   ti[node] = max(ti[node << 1], ti[node << 1 | 1]); n } n int ai[100010], ad[100010], md[100010]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0, l, r; i < n; ++i) { n     cin >> l >> r; n     x[l]++; n     x[r + 1]--; n   } n   for (int i = 1; i <= m; ++i) { n     x[i] += x[i - 1]; n   } n   for (int i = 1; i <= m; ++i) { n     auto xz = queryi(1, 0, n, 0, x[i]); n     ai[i] = xz + 1; n     updatei(1, 0, n, x[i], xz + 1); n   } n   for (int i = m; i > 0; --i) { n     auto xz = queryd(1, 0, n, 0, x[i]); n     ad[i] = xz + 1; n     updated(1, 0, n, x[i], xz + 1); n   } n   md[m] = ad[m]; n   int ans = 0; n   for (int i = m - 1; i > 0; --i) { n     md[i] = max(ad[i], md[i + 1]); n   } n   for (int i = 1; i < m; ++i) { n     ans = max(ans, ai[i] + md[i + 1]); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const long long Inf = 1e18; n const int N = 1010; n const int mod = 0; n int gi() { n   int x = 0, o = 1; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) o = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * o; n } n template <typename T> n bool chkmax(T &a, T b) { n   return a < b ? a = b, 1 : 0; n }; n template <typename T> n bool chkmin(T &a, T b) { n   return a > b ? a = b, 1 : 0; n }; n int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } n int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } n void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); } n void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); } n string to_string(string s) { return     + s +    ; } n string to_string(const char *s) { return to_string((string)s); } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,  + to_string(p.second) +  ) ; n } n template <typename T> n string to_string(T v) { n   int fst = 1; n   string ret =  { ; n   for (auto x : v) { n     if (!fst) ret +=  , ; n     fst = 0, ret += to_string(x); n   } n   ret +=  } ; n   return ret; n } n void dbg_out() { cerr << endl; } n template <typename Head, typename... Tail> n void dbg_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   dbg_out(T...); n } n int n, m, c, a[N], h, t; n void print(int x) { n   cout << x <<   n ; n   fflush(stdout); n } n int place(int x) { n   if (x <= c / 2) { n     if (x >= a[h]) n       return ++h; n     else { n       int p = 1; n       while (a[p] <= x) ++p; n       return p; n     } n   } else { n     if (x <= a[t]) n       return --t; n     else { n       int p = n; n       while (a[p] >= x) --p; n       return p; n     } n   } n } n int main() { n   n = gi(), m = gi(), c = gi(); n   h = 0, t = n + 1; n   a[t] = c + 1; n   for (int i = 1; i <= m; i++) { n     int x = gi(), pos = place(x); n     print(pos); n     a[pos] = x; n     if (h + 1 == t) return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[60]; n int n; n long long f[60][10]; n int main() { n   gets(s + 1); n   n = strlen(s + 1); n   for (int j = 0; j < 10; ++j) f[1][j] = 1; n   for (int i = 1; i < n; ++i) n     for (int j = 0; j < 10; ++j) { n       int sum = j + s[i + 1] - 48; n       if (sum & 1) { n         f[i + 1][sum - 1 >> 1] += f[i][j]; n         f[i + 1][sum + 1 >> 1] += f[i][j]; n       } else n         f[i + 1][sum >> 1] += f[i][j]; n     } n   long long ans = 0; n   for (int j = 0; j < 10; ++j) ans += f[n][j]; n   bool flag = true; n   for (int i = 2; i <= n; ++i) { n     int sum = s[i - 1] + s[i] - 48 * 2; n     if (sum & 1) { n       if ((sum - 1 >> 1) != s[i] - 48 && (sum + 1 >> 1) != s[i] - 48) n         flag = false; n     } else if ((sum >> 1) != s[i] - 48) n       flag = false; n   } n   if (flag) --ans; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   long long a[n]; n   long long m = 1e9; n   long long sum = 0; n   for (long long i = 0; i < n; ++i) cin >> a[i], m = min(m, a[i]), sum += a[i]; n   for (long long i = 0; i < n; ++i) { n     if ((a[i] - m) % k != 0) { n       cout << -1; n       return 0; n     } n   } n   long long l = sum - m * n; n   cout << l / k; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c, d; n int ansa, ansb, ansc; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n int main() { n   a = read(); n   b = read(); n   c = read(); n   d = read(); n   if (c * 2 < d || d * 2 < c || a <= d || b <= d) { n     printf( -1 ); n     return 0; n   } n   printf( %d n%d n%d , a * 2, b * 2, min(c * 2, d * 2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   set<int> a; n   int n, t; n   cin >> n; n   while (n--) { n     cin >> t; n     a.insert(t); n   } n   cout << ((a.count(0) == 1) ? a.size() - 1 : a.size()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct myhash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n long long modpow(long long base, long long exp, long long modulus) { n   base %= modulus; n   long long result = 1; n   while (exp > 0) { n     if (exp & 1) result = (result * base) % modulus; n     base = (base * base) % modulus; n     exp >>= 1; n   } n   return result; n } n long long modinv(long long a, long long m) { n   long long m0 = m; n   long long y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     long long q = a / m; n     long long t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n int main() { n   long long n; n   cin >> n; n   vector<string> s(n); n   for (long long(i) = (0); i < (n); ++(i)) cin >> s[i]; n   map<long long, unordered_map<char, vector<string>>> m; n   vector<pair<string, string>> secondwords(0); n   vector<vector<string>> firstwords(0); n   unordered_map<long long, long long> fq; n   vector<long long> poss(0); n   for (long long(i) = (0); i < (n); ++(i)) { n     char lastvowel; n     long long numvowels = 0; n     for (long long(j) = (0); j < (s[i].length()); ++(j)) { n       switch (s[i][j]) { n         case  a : n         case  e : n         case  i : n         case  o : n         case  u : n           numvowels++; n           lastvowel = s[i][j]; n           break; n       } n     } n     if (!fq[numvowels]) { n       fq[numvowels] = 1; n       poss.push_back(numvowels); n     } n     m[numvowels][lastvowel].push_back(s[i]); n   } n   vector<char> st{ a ,  e ,  i ,  o ,  u }; n   for (long long(i) = (0); i < (poss.size()); ++(i)) { n     vector<string> ones(0); n     for (long long(j) = (0); j < (st.size()); ++(j)) { n       for (long long(k) = (0); k < (m[poss[i]][st[j]].size() / 2); ++(k)) { n         secondwords.push_back( n             {m[poss[i]][st[j]][k * 2], m[poss[i]][st[j]][k * 2 + 1]}); n       } n       if (m[poss[i]][st[j]].size() % 2 == 1) { n         ones.push_back(m[poss[i]][st[j]][m[poss[i]][st[j]].size() - 1]); n       } n     } n     firstwords.push_back(ones); n   } n   long long np = secondwords.size(); n   vector<pair<string, string>> fans(0); n   for (long long(i) = (0); i < (firstwords.size()); ++(i)) { n     for (long long(j) = (0); j < (firstwords[i].size() / 2); ++(j)) { n       fans.push_back({firstwords[i][j * 2], firstwords[i][j * 2 + 1]}); n     } n   } n   if (fans.size() >= secondwords.size()) { n     cout << secondwords.size() <<   n ; n     for (long long(i) = (0); i < (secondwords.size()); ++(i)) { n       cout << fans[i].first <<     << secondwords[i].first <<   n ; n       cout << fans[i].second <<     << secondwords[i].second <<   n ; n     } n   } else { n     long long sc = secondwords.size(), fw = fans.size(); n     while (sc > fw) { n       sc--; n       fw++; n       fans.push_back(secondwords[sc]); n     } n     cout << sc <<   n ; n     for (long long(i) = (0); i < (sc); ++(i)) { n       cout << fans[i].first <<     << secondwords[i].first <<   n ; n       cout << fans[i].second <<     << secondwords[i].second <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using db = long double; n using pl = pair<ll, ll>; n using pi = pair<int, int>; n vector<pi> viz[100010]; n pi p[100010]; n double num[100010]; n bool no; n set<int> val; n vector<int> in; n void dfs(int u) { n   in.push_back(u); n   for (auto x : viz[u]) { n     int v = x.first, c = x.second; n     if (p[v].first != 0) { n       if (p[v].first != p[u].first) { n         if ((p[v].second == c - p[u].second)) n           continue; n         else n           no = true; n       } n       if (p[v].first == p[u].first) { n         val.insert((c - p[v].second - p[u].second) * p[v].first); n       } n     } else { n       p[v].first = -p[u].first; n       p[v].second = c - p[u].second; n       dfs(v); n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     viz[a].push_back({b, c}); n     viz[b].push_back({a, c}); n   } n   no = false; n   for (int i = 1; i <= n; i++) { n     if (p[i].first == 0) { n       val.clear(); n       in.clear(); n       p[i] = {1, 0}; n       dfs(i); n       if (val.size() > 1) no = true; n       if (val.size() == 0) { n         vector<int> fd; n         for (auto x : in) fd.push_back(p[x].first * p[x].second); n         sort(begin(fd), end(fd)); n         int c = -fd[fd.size() / 2]; n         for (auto x : in) num[x] = (double)p[x].first * c + p[x].second; n       } else { n         double c = (double)*val.begin() / 2; n         for (auto x : in) num[x] = (double)p[x].first * c + p[x].second; n       } n     } n   } n   if (no) n     cout <<  NO  << endl; n   else { n     cout <<  YES  << endl; n     for (int i = 1; i <= n; i++) cout << num[i] <<    ; n     cout << endl; n   } n } n


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


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


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007, n, m, siz[100010], s[210][210], dp[100010][210], n           f[210], sum[210]; n vector<long long> g[100010]; n void jia(long long &x, long long y) { n   x += y; n   if (x >= mod) x -= mod; n } n void dfs(long long x, long long fa) { n   dp[x][0] = 2; n   siz[x] = 1; n   for (long long i = 0, v; i < g[x].size(); i++) { n     v = g[x][i]; n     if (v == fa) continue; n     dfs(v, x); n     for (long long j = 0; j <= m; j++) f[j] = 0; n     for (long long j = 0; j <= min(m, siz[x]); j++) n       for (long long k = 0; k <= min(m - j, siz[v]); k++) n         jia(f[j + k], dp[x][j] * dp[v][k] % mod); n     for (long long j = 0; j <= m; j++) dp[x][j] = f[j]; n     for (long long j = 0; j <= m; j++) jia(sum[j], mod - dp[v][j]); n     siz[x] += siz[v]; n   } n   for (long long j = 0; j <= m; j++) jia(sum[j], dp[x][j]); n   for (long long j = m; j >= 1; j--) jia(dp[x][j], dp[x][j - 1]); n   jia(dp[x][1], mod - 1); n } n int main() { n   scanf( %lld%lld , &n, &m); n   for (long long u, v, i = 1; i < n; i++) { n     scanf( %lld%lld , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   s[1][1] = 1; n   for (long long i = 2; i <= m; i++) n     for (long long j = 1; j <= i; j++) n       s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * j) % mod; n   dfs(1, 0); n   long long ans = 0; n   for (long long fac = 1, i = 1; i <= m; i++) { n     fac = fac * i % mod; n     jia(ans, fac * s[m][i] % mod * sum[i] % mod); n   } n   printf( %lld , ans); n   return 0; n } n


#include <algorithm> n #include <cmath> n #include <cstdio> n #include <cstring> n #include <fstream> n #include <iomanip> n #include <iostream> n #include <map> n #include <queue> n #include <random> n #include <set> n #include <stack> n #include <string> n #include <vector> n  n #ifndef ONLINE_JUDGE n //freopen( code.in ,  r , stdin); n //freopen( code.out , w ,stdout); n #endif n  n #define tplcf template <class c> n #define tplcfd template <class c, class b> n #define deout(X) operator<<(X) n #define recog(X) typename std::enable_if<sizeof dud<c>(0) X 1, debug &>::type n  n template <class c, class S = std::greater<c>, int L = 100000> n class sarr n { n public: n     c *a; n     int sa[L]; n     sarr(c *a, int sl, int sr) n     { n         for (int i = sl; i <= sr; ++i) n             sa[i] = i; n         sort(sa + sl, sa + sr + 1, S()); n     } n     c &operator[](const int &index) { return a[sa[index]]; } n }; n tplcf sarr<c> n sortarr(c *arr, int sl, int sr) n { n     return sarr<c>(arr, sl, sr); n } n  n tplcf class suba n { n public: n     suba(c *a, int l, int r) : a(a), l(l), r(r) {} n     int l, r; n     c *a; n     c &operator[](const int &index) { return a[l + index]; } n     inline uint32_t len() { return r - l + 1; } n }; n tplcf suba<c> n subarr(c *a, int l, int r) n { n     return suba<c>(a, l, r); n } n  n tplcf struct rge n { n     c b, e; n }; n tplcf rge<c> n range(c i, c j) { return rge<c>{i, j}; } n tplcf auto dud(c *x) -> decltype(std::cerr << *x, 0); n tplcf char dud(...); n struct debug n { n #ifndef ONLINE_JUDGE n     ~debug() n     { n         std::cerr << std::endl; n     } n     tplcf recog(!=) deout(c i) n     { n         std::cerr << std::boolalpha << i; n         return *this; n     } n     tplcf recog(==) deout(c i) n     { n         return *this << range(begin(i), end(i)); n     } n     tplcfd debug &operator<<(std::pair<b, c> d) n     { n         return *this <<  (  << d.first <<  ,   << d.second <<  ) ; n     } n     tplcf debug &deout(rge<c> d) n     { n         *this <<  [ ; n         for (auto it = d.b; it != d.e; ++it) n             *this << (char *) ,   + 2 * (it == d.b) << *it; n         return *this <<  ] ; n     } n     tplcf debug &deout(suba<c> sa) n     { n         *this <<  {  << sa.l <<  ,   << sa.r <<  }:  << range(sa.a + sa.l, sa.a + sa.r + 1); n         return *this; n     } n #else n     tplcf debug &deout(const c &) n     { n         return *this; n     } n #endif n }; n #include <chrono> n class Timer n { n public: n     Timer() : t1(clock::now()) {} n     void tic() n     { n         t1 = clock::now(); n     } n     void toc(const char *str) n     { n         t2 = clock::now(); n         std::cerr << str <<   time:   << std::chrono::duration_cast<res>(t2 - t1).count() / 1e3 <<  ms.  << std::endl; n     } n  n private: n     typedef std::chrono::high_resolution_clock clock; n     typedef std::chrono::microseconds res; n     clock::time_point t1, t2; n }; n  n typedef long long ll; n #define FILE(X, Y)     n     ifstream fin(X);   n     ofstream fout(Y) n #define FASTIO()                  n     cin.sync_with_stdio(false);   n     cin.tie(0);                   n     cout.tie(0) n #define MP(X, Y) make_pair(X, Y) n #define imie(X)   [  << #X  :   << (X) <<  ]   n #ifndef ONLINE_JUDGE n #define PAUSE()        n     system( pause );   n     return 0 n #else n #define PAUSE() return 0 n #endif n  n #define INF 0x3f3f3f3f n #define INFM 0x3f n  n using namespace std; n  n int n, m; n double p[10005]; n char s[10004]; n int las = 1; n  n mt19937 mtrand(time(0)); n  n int main(void) n { n     FASTIO(); n     cin >> n >> m; n     for (int i = 1; i <= n; ++i) n     { n         p[i] = 1; n     } n     char t[3]; n     for (int i = 1; i <= m; ++i) n     { n         cin >> s + 1; n         double c[2] = {0, 0}; n         for (int j = 1; j <= n; ++j) n         { n             c[s[j] -  0 ] += p[j]; n         } n         cout << ((double(mtrand() % RAND_MAX) / double(RAND_MAX)) > (c[0] / (c[0] + c[1])) ?  1  :  0 ) << endl; n         cin >> t; n         for (int j = 1; j <= n; ++j) n         { n             if (s[j] != t[0]) n                 p[j] *= 0.8; n         } n     } n     PAUSE(); n }


#include <bits/stdc++.h> n using namespace std;  n #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); n #define int long long int n #define ld long double n #define endl   n  n #define rep(i,a,b) for(int i=a;i<b;i++) n #define reprev(i,a,b) for(int i=b-1;i>=a;i--) n #define all(c) c.begin(),c.end() n #define sz(c) (int)c.size() n #define ff first n #define ss second n #define pii pair<int,int> n #define vi vector<int> n #define vii vector<pii> n #define vin(a,n) vi a(n); rep(k_,0,n) {cin>>a[k_];} n #define vout(a) rep(k_,0,sz(a)) {cout<<a[k_]<<   ;} cout<<endl; n #define pb push_back n #define mp  make_pair n #define mod 1000000007 n #define mod2 998244353 n #define inf 1e18 n #define pi 3.1415926535897932384626 n #define tr(container, it)   n for(auto it = container.begin(); it != container.end(); it++) n  n int power(int x, unsigned int y, int p)   n {   n     int res = 1;     // Initialize result   n    n     x = x % p; // Update x if it is more than or   n                 // equal to p  n     n     if (x == 0) return 0; // In case x is divisible by p;  n    n     while (y > 0)   n     {   n         // If y is odd, multiply x with result   n         if (y & 1)   n             res = (res*x) % p;   n    n         // y must be even now   n         y = y>>1; // y = y/2   n         x = (x*x) % p;   n     }   n     return res;   n } n  n int ceill(int a,int b) n { n     return (a+b-1)/b; n } n  n #define MAXN   100001 n    n // stores smallest prime factor for every number n int spf[MAXN]; n    n // Calculating SPF (Smallest Prime Factor) for every n // number till MAXN. n // Time Complexity : O(nloglogn) n void sieve() n { n     spf[1] = 1; n     for (int i=2; i<MAXN; i++) n    n         // marking smallest prime factor for every n         // number to be itself. n         spf[i] = i; n    n     // separately marking spf for every even n     // number as 2 n     for (int i=4; i<MAXN; i+=2) n         spf[i] = 2; n    n     for (int i=3; i*i<MAXN; i++) n     { n         // checking if i is prime n         if (spf[i] == i) n         { n             // marking SPF for all numbers divisible by i n             for (int j=i*i; j<MAXN; j+=i) n    n                 // marking spf[j] if it is not  n                 // previously marked n                 if (spf[j]==j) n                     spf[j] = i; n         } n     } n } n    n // A O(log n) function returning primefactorization n // by dividing by smallest prime factor at every step n vector<int> getFactorization(int x) n { n     vector<int> ret; n     while (x != 1) n     { n         ret.push_back(spf[x]); n         x = x / spf[x]; n     } n     return ret; n } n  n int modInverse(int n, int p)  n {  n     return power(n, p-2, p);  n }  n const int N=1000000; n int fac[N+1];  n void precomp(int p) n { n     fac[0] = 1;  n     for (int i=1 ; i<=N; i++)  n         fac[i] = fac[i-1]*i%p; n } n // Returns nCr % p using Fermat s little  n // theorem.  n int nCrModPFermat(int n, int r, int p)  n {  n    // Base case  n    if (r==0)  n       return 1;  n    n     // Fill factorial array so that we  n     // can find all factorial of r, n  n     // and n-r   n     return (fac[n]* modInverse(fac[r], p) % p *  n             modInverse(fac[n-r], p) % p) % p;  n } n signed main() n { n     #ifndef ONLINE_JUDGE n         freopen( ./input.txt ,  r , stdin); n         freopen( ./output.txt ,  w , stdout); n     #endif n     IOS n     int T; cin>>T; n     precomp(mod); n     rep(t,1,T+1) n     { n         int n; cin>>n; n         vin(a,n); n         int and_val=a[0]; n         rep(i,1,n) and_val = and_val&a[i]; n  n         int freq=0; n  n         rep(i,0,n) n         { n             if(a[i]==and_val) freq++; n         } n  n         int ans = freq*(freq-1); n         ans%=mod; n         ans*=fac[n-2]; ans%=mod; n         cout<<ans<<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n vector<int> edges[500000]; n bool vis[500000]; n int order[1000000]; n int first[500000], second[500000]; n int C; n void dfs(int i) { n   vis[i] = 1; n   first[i] = C; n   order[C++] = i; n   for (int j = 0; j < edges[i].size(); j++) n     if (!vis[edges[i][j]]) dfs(edges[i][j]); n   second[i] = C; n   order[C++] = i; n } n int segFill[2 * (1 << 20)], up[2 * (1 << 20)]; n int segEmpty[2 * (1 << 20)]; n int l[2 * (1 << 20)], r[2 * (1 << 20)]; n void init() { n   for (int i = (1 << 20); i < 2 * (1 << 20); i++) { n     segFill[i] = -1; n     up[i] = 0; n     segEmpty[i] = 0; n     l[i] = r[i] = i - (1 << 20); n   } n   for (int i = (1 << 20) - 1; i > 0; i--) { n     segFill[i] = -1; n     up[i] = 0; n     segEmpty[i] = 0; n     l[i] = l[2 * i]; n     r[i] = r[2 * i + 1]; n   } n } n void push(int i) { n   if (up[i] > 0) { n     if (i < (1 << 20)) { n       up[(i << 1)] = up[i]; n       up[(i << 1) + 1] = up[i]; n     } n     segFill[i] = up[i]; n     up[i] = 0; n   } n } n int getFill(int i, int loc) { n   push(i); n   if (i >= (1 << 20)) n     return segFill[i]; n   else if (r[(i << 1)] >= loc) n     return getFill((i << 1), loc); n   else n     return getFill((i << 1) + 1, loc); n } n int low, high; n void setFill(int i, int v) { n   push(i); n   if ((l[i] > high) || (r[i] < low)) return; n   if ((l[i] >= low) && (r[i] <= high)) { n     up[i] = v; n     push(i); n     return; n   } n   setFill((i << 1), v); n   setFill((i << 1) + 1, v); n   segFill[i] = max(segFill[(i << 1)], segFill[(i << 1) + 1]); n } n void setEmpty(int loc, int v) { n   loc += (1 << 20); n   segEmpty[loc] = v; n   for (loc /= 2; loc > 0; loc /= 2) n     segEmpty[loc] = max(segEmpty[2 * loc], segEmpty[2 * loc + 1]); n } n int getEmpty(int i) { n   if ((l[i] > high) || (r[i] < low)) return 0; n   if ((l[i] >= low) && (r[i] <= high)) return segEmpty[i]; n   return max(getEmpty((i << 1)), getEmpty((i << 1) + 1)); n } n int main() { n   int N, a, b; n   scanf( %d , &N); n   for (int i = 1; i < N; i++) { n     scanf( %d %d , &a, &b); n     a--, b--; n     edges[a].push_back(b); n     edges[b].push_back(a); n   } n   C = 0; n   dfs(0); n   init(); n   int Q, tp, v; n   scanf( %d , &Q); n   for (int i = 0; i < Q; i++) { n     scanf( %d %d , &tp, &v); n     v--; n     if (tp == 1) { n       low = first[v]; n       high = second[v]; n       setFill(1, i + 1); n     } n     if (tp == 2) setEmpty(first[v], i + 1); n     if (tp == 3) { n       low = first[v]; n       high = second[v]; n       a = getFill(1, first[v]); n       b = getEmpty(1); n       printf( %d n , a >= b); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class C> n void mini(C& a, C b) { n   a = min(a, b); n } n template <class C> n void maxi(C& a, C b) { n   a = max(a, b); n } n void a() { n   int n; n   cin >> n; n   vector<int> a(n), b(n), c(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   for (int i = 0; i < n; i++) cin >> c[i]; n   vector<int> p(n); n   p[0] = a[0]; n   for (int(i) = 1; i <= n - 2; i++) { n     if (a[i] == p[i - 1]) n       p[i] = b[i]; n     else n       p[i] = a[i]; n   } n   if (a.back() != p[0] and a.back() != p[n - 2]) n     p[n - 1] = a.back(); n   else if (b.back() != p[0] and b.back() != p[n - 2]) n     p[n - 1] = b.back(); n   else n     p[n - 1] = c.back(); n   for (int i = 0; i < n; i++) cout << p[i] <<    ; n   cout <<   n ; n } n void b() { 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   int diferentes = 1; n   for (int(i) = 1; i <= n - 1; i++) n     if (a[i] != a[i - 1]) diferentes++; n   if (k == 1 and diferentes != 1) { n     cout <<  -1 n ; n     return; n   } n   int res = 1; n   diferentes -= k; n   while (diferentes > 0) { n     res++; n     diferentes -= k - 1; n   } n   cout << res <<   n ; n } n void c() { n   int n; n   long long l; n   cin >> n >> l; n   vector<long long> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   double izq = 0; n   double izqVel = 1; n   double der = l; n   double derVel = 1; n   int i = 0; n   int j = n - 1; n   double time = 0.0; n   while (i <= j) { n     double ti = (double)(a[i] - izq) / (double)izqVel; n     double tj = (double)(der - a[j]) / (double)derVel; n     if (ti < tj) { n       izq = a[i]; n       i++; n       izqVel++; n       der -= ti * derVel; n       time += ti; n     } else { n       der = a[j]; n       j--; n       derVel++; n       izq += tj * izqVel; n       time += tj; n     } n   } n   time += (der - izq) / (izqVel + derVel); n   cout << setprecision(9) << fixed << time <<   n ; n } n void d() { n   int n, m; n   cin >> n >> m; n   vector<int> a(n), b(n), c(m), d(m); n   for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; n   for (int i = 0; i < m; i++) cin >> c[i] >> d[i]; n   vector<pair<int, int> > delta; n   int dx, dy; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       dx = c[j] - a[i]; n       dy = d[j] - b[i]; n       if (dx >= 0 and dy >= 0) delta.push_back({dx, dy}); n     } n   sort(delta.begin(), delta.end()); n   if (delta.empty()) { n     cout << 0 <<   n ; n     return; n   } n   int x = delta.back().first + 1; n   int maxy = -1; n   int res = x; n   for (int(i) = delta.size() - 1; i >= 1; i--) { n     x = delta[i - 1].first + 1; n     maxi(maxy, delta[i].second); n     mini(res, x + maxy + 1); n   } n   maxi(maxy, delta[0].second); n   mini(res, maxy + 1); n   cout << res <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   d(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, o = 0, z = 0; n   cin >> n; n   string s; n   cin >> s; n   for (i = 0; i < n; i++) { n     if (s[i] ==  1 ) n       o++; n     else n       z++; n   } n   if (z != o) { n     cout << 1 << endl << s; n   } else { n     cout << 2 << endl; n     for (i = 0; i < n - 1; i++) cout << s[i]; n     cout <<     << s[n - 1]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void Solves(); n void In(int **a, int n); n int main() { n   Solves(); n   return 0; n } n void Solves() { n   long long n, k; n   cin >> n >> k; n   if (k > n * n) { n     cout << -1; n     return; n   } n   int **a = new int *[n + 1]; n   for (int i = 0; i <= n; i++) { n     a[i] = new int[n + 1]; n   } n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= n; j++) { n       a[i][j] = 0; n     } n   } n   if (k == 0) { n     In(a, n); n     return; n   } n   if (n == 1 && k == 1) { n     cout << 1 << endl; n     return; n   } n   for (int i = 1; i <= n - 1; i++) { n     a[i][i] = 1; n     k--; n     for (int j = i + 1; j <= n; j++) { n       if (k >= 2) { n         a[i][j] = 1; n         a[j][i] = 1; n         k -= 2; n       } n       if (k == 1) { n         a[i + 1][i + 1] = 1; n         k--; n       } n       if (k == 0) { n         In(a, n); n         return; n       } n     } n   } n } n void In(int **a, int n) { n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cout << a[i][j] <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000000], l[1000000], r[1000000]; n int main() { n   int n; n   cin >> n; n   int minn = 10000000; n   int kol = 0; n   int ans = 0; n   int m = 2 * n - 1; n   for (int i = 0; i < m; i++) { n     cin >> a[i]; n     if (a[i] < 0) { n       kol++; n       a[i] = -a[i]; n     } n     ans += a[i]; n     if (a[i] < minn) minn = a[i]; n   } n   if (n % 2 == 1) n     cout << ans << endl; n   else { n     if (kol % 2 == 0) n       cout << ans << endl; n     else n       cout << ans - 2 * minn << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1000000001; n void run_case() { n   long long n; n   cin >> n; n   vector<pair<long long, long long>> v; n   for (long long i = 0; i < n; i++) { n     long long x; n     cin >> x; n     v.push_back({x, i}); n   } n   sort(v.begin(), v.end()); n   vector<long long> curr_max(n), maxi(n), ans(n); n   curr_max[0] = v[0].second; n   maxi[0] = v[0].second; n   ans[v[0].second] = -1; n   for (long long i = 1; i < n; i++) { n     curr_max[i] = max(curr_max[i - 1], v[i].second); n     if (v[i].first == v[i - 1].first) n       maxi[i] = maxi[i - 1]; n     else n       maxi[i] = curr_max[i]; n     ans[v[i].second] = maxi[i] - v[i].second - 1; n   } n   for (long long i = 0; i < n; i++) { n     cout << max(ans[i], -1ll) <<    ; n   } n   cout << endl; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long tc = 1; n   while (tc--) run_case(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n int A, B; n signed long long from[505]; n signed long long to[505]; n void solve() { n   int i, j, k, l, r, x, y; n   string s; n   cin >> N >> K; n   for (x = 0; x < (505); x++) n     for (y = 0; y < (505); y++) from[x] = -1LL << 60; n   from[0] = 0; n   int sum = 0; n   for (i = 0; i < (N); i++) { n     cin >> A >> B; n     for (x = 0; x < (505); x++) to[x] = -1LL << 60; n     for (x = 0; x < (K); x++) { n       y = (sum - x) % K; n       if (y < 0) y += K; n       for (j = 0; j < (K); j++) { n         if (j > A) continue; n         k = (A + B - j) % K; n         if (k > B) continue; n         int add = (A + B - j - k) / K; n         to[(x + j) % K] = max(to[(x + j) % K], n                               from[x] + add + ((x + j) >= K) + ((y + k) >= K)); n       } n     } n     (sum += A + B) %= K; n     swap(from, to); n   } n   signed long long ma = 0; n   for (i = 0; i < (K); i++) ma = max(ma, from[i]); n   cout << ma << endl; n } n int main(int argc, char** argv) { n   string s; n   int i; n   if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); n   for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ; n   for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   multiset<long long> x, y; n   long long n, closing = 0, count = 0, i, j, pair = 0; n   cin >> n; n   string ss; n   for (i = 0; i < n; i++) { n     stack<char> s; n     closing = 0; n     cin >> ss; n     for (j = 0; j < ss.length(); j++) { n       if (ss[j] ==  )  && s.size() == 0) closing++; n       if (ss[j] ==  ( ) s.push(ss[j]); n       if (ss[j] ==  )  && s.size() != 0) s.pop(); n     } n     if (closing == 0 && s.size() > 0) x.insert(s.size()); n     if (closing > 0 && s.size() == 0) y.insert(closing); n     if (closing == 0 && s.size() == 0) count++; n   } n   for (auto i : x) { n     if (y.find(i) != y.end()) { n       pair++; n       y.erase(y.find(i)); n     } n   } n   cout << pair + count / 2; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int n, m, i, j, a, b; n long long check(long long x, long long y) { n   if (x == i && y == j) return 0; n   if (abs(x - i) % a != 0 || abs(y - j) % b != 0) return inf; n   if (abs(abs(x - i) / a - abs(y - j) / b) & 1) return inf; n   if ((i - a < 1 && i + a > n) || (j - b < 1 && j + b > m)) n     return inf; n   else n     return max(abs(x - i) / a, abs(y - j) / b); n } n int main() { n   scanf( %d%d%d%d%d%d , &n, &m, &i, &j, &a, &b); n   long long ret = inf; n   ret = min(check(1, m), check(n, 1)); n   ret = min(ret, check(n, m)); n   ret = min(ret, check(1, 1)); n   if (ret == inf) n     printf( Poor Inna and pony! n ); n   else n     printf( %d n , ret); n } n


#include <bits/stdc++.h> n using namespace std; n long long C[20][20]; n long long dp[20]; n int cnt[16]; n int k, t; n long long solve(int l) { n   memset(dp, 0, sizeof(dp)); n   dp[0] = 1; n   for (int j = 0; j < 16; j++) { n     for (int i = l; i >= 0; i--) { n       for (int k = 1; k <= min(l - i, t - cnt[j]); k++) { n         dp[i + k] = (dp[i + k] + C[l - i][k] * dp[i]); n       } n     } n   } n   return dp[l]; n } n int main() { n   C[0][0] = 1; n   for (int i = 1; i < 20; i++) { n     C[i][0] = C[i][i] = 1; n     for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; n   } n   scanf( %d%d , &k, &t); n   for (int i = 1; i < 20; i++) { n     long long ways = 0; n     for (int j = 1; j < 16; j++) { n       cnt[j]++; n       ways += solve(i - 1); n       cnt[j]--; n     } n     if (ways < k) { n       k -= ways; n     } else { n       int l = i; n       for (int i = 1; i <= l; i++) { n         if (i == 1) { n           for (int j = 1; j < 16; j++) { n             cnt[j]++; n             long long ways = solve(l - i); n             if (ways < k) { n               k -= ways; n               cnt[j]--; n             } else { n               if (j < 10) n                 printf( %d , j); n               else n                 printf( %c ,  a  + (j - 10)); n               break; n             } n           } n         } else { n           for (int j = 0; j < 16; j++) { n             if (cnt[j] == t) continue; n             cnt[j]++; n             long long ways = solve(l - i); n             if (ways < k) { n               k -= ways; n               cnt[j]--; n             } else { n               if (j < 10) n                 printf( %d , j); n               else n                 printf( %c ,  a  + (j - 10)); n               break; n             } n           } n         } n       } n       break; n     } n   } n } n


/* n      n     Note        :           helluva implementation. n   n     Link        :        n   n     Boka hoye gelum... n */ n  n  n  n #include  bits/stdc++.h  n   n #define sp <<    n #define el <<  n  n #define S second n #define F first n #define pb push_back n #define all(ar) ar.begin(),ar.end()  n #define pii pair<ll,ll>  n   n  n using namespace std; n using ll = long long; n using ld = long double; n   n const ll mod = 1000000007; n const ll oo = 3372036000000000; n const ll si = 300005; n  n vector<pair<pii,char>> vec;  n ll ans[si],in[si],n,m; n char dir[si];   n bool don[si];  n  n void sm_dir(char q){ n  stack<pii> od,ev;  n  for(ll i = q ==  L  ? 0 : n - 1; i < n && i >=  0; q ==  L ? i++ : i--){ n   if(don[vec[i].F.S] || vec[i].S != q) continue;  n   pii da,cur = vec[i].F;  n   if(cur.F & 1){ n    if(od.empty()){ n     od.push(cur);  n     continue;  n    } n    da = od.top(); od.pop();  n   }else{ n    if(ev.empty()){ n     ev.push(cur); continue;  n    } n    da = ev.top(); ev.pop();  n   } n   ll tim = abs(da.F - cur.F)/2;  n   if(q ==  R ) tim += m - da.F;  n   else tim += da.F;  n   don[da.S] = don[cur.S] = 1;  n   ans[da.S] = ans[cur.S] = tim;  n  } n } n  n  n void baki(){ n  stack<pii> od,ev;  n  for(ll i = 0; i < n; i++){ n   if(don[vec[i].F.S]) continue;  n   if(vec[i].S ==  L ){ n    if(vec[i].F.F&1) od.push(vec[i].F);  n    else ev.push(vec[i].F);  n   } n  } n  for(ll i = n-1; i >= 0; i--){ n   if(don[vec[i].F.S]) continue;  n   if(vec[i].S ==  R ){ n    pii cur = vec[i].F,da;  n    if(cur.F & 1){ n     if(od.empty()) continue;  n     da = od.top(); od.pop();  n    }else{ n     if(ev.empty()) continue;  n     da = ev.top(); ev.pop();  n    } n    ll tim = 0;   n    if(m - cur.F > da.F){ n     ll wae = m - cur.F,nda = (wae - da.F); // sure?   n     ll dis = (m - nda)/2;  n     tim += wae;  n     tim += dis;  n    }else{ n     ll wae = da.F, nda = ((2 * m) - (cur.F + wae))/2;  n     tim += (wae + nda);  n    } n    ans[cur.S] = ans[da.S] = tim; n   } n  } n } n  n  n signed main(){ n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n //* n #ifndef ONLINE_JUDGE n     freopen( input.txt , r ,stdin); n     freopen( output.txt , w ,stdout); n #endif n //*/ n     ll t; cin>>t;  n     while(t--){ n      vec.clear(); n      memset(ans,-1,sizeof(ans)); n      memset(don,0,sizeof(don));    n      cin>>n>>m; n      for(ll i = 0; i < n; i++) cin>>in[i];  n      for(ll i = 0; i < n; i++) cin>>dir[i];  n      for(ll i = 0; i < n; i++){ n       ll x = in[i]; char d = dir[i];  n       vec.pb({{x,i},d});  n      }  n      sort(all(vec));  n      stack<pii> ev,od;   n      for(ll i = 0; i < n; i++){ n       if(vec[i].S ==  R ){ n        if(vec[i].F.F & 1) od.push(vec[i].F);  n        else ev.push(vec[i].F);  n       }else{ n        pii da,cur = vec[i].F;  n        if(vec[i].F.F & 1){ n         if(od.empty()) continue;  n         da = od.top(); od.pop();  n        }else{ n         if(ev.empty()) continue;  n         da = ev.top(); ev.pop();  n        } n        ll tim = (cur.F - da.F)/2;  n        don[cur.S] = don[da.S] = 1;  n        ans[cur.S] = ans[da.S] = tim;  n       } n      } n      sm_dir( L );  n      sm_dir( R ); n      baki();  n      for(ll i = 0; i < n; i++) cout<<ans[i] sp; cout el;  n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int a[1000010]; n int solution[1000010] = {0}; n int main() { n   ios::sync_with_stdio(0); n   int n; n   long long int sum = 0; n   long long int part; n   long long partSum = 0; n   long long int result = 0; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     sum += a[i]; n   } n   if (sum % 3) n     cout <<  0 ; n   else { n     part = sum / 3; n     for (int i = 0; i < n; ++i) { n       partSum += a[i]; n       if (partSum == part) solution[i] = 1; n     } n     for (int i = 0; i < n - 2; i++) solution[i + 1] += solution[i]; n     partSum = 0; n     for (int i = n - 1; i - 2 >= 0; --i) { n       partSum += a[i]; n       if (partSum == part) result += solution[i - 2]; n     } n     cout << result; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n const int N = 1e5 + 2; n vector<pair<int, int> > seg[3 * N][2]; n long long int sig[3 * N]; n int a[N]; n vector<pair<int, int> > m[2]; n int n, x; n inline long long int mrg(vector<pair<int, int> > z[2], n                          vector<pair<int, int> > y[2]) { n   if (z[0].size() == 0) { n     m[0] = y[0]; n     m[1] = y[1]; n     return 0; n   } n   if (y[0].size() == 0) { n     m[0] = z[0]; n     m[1] = z[1]; n     return 0; n   } n   long long int t = 0; n   for (auto i : z[1]) { n     for (auto j : y[0]) { n       if ((i.first | j.first) >= x) { n         t += 1LL * i.second * j.second; n       } n     } n   } n   m[1].clear(); n   m[0].clear(); n   m[1] = y[1]; n   int r = 0; n   r = y[1].back().first; n   for (auto i : z[1]) { n     long long int e = (i.first | r); n     if (m[1].size() == 0) { n       m[1].push_back({e, i.second}); n     } else if (e != m[1].back().first) n       m[1].push_back({e, i.second}); n     else { n       m[1].back().second += i.second; n     } n   } n   m[0] = z[0]; n   r = z[0].back().first; n   for (auto i : y[0]) { n     long long int e = (i.first | r); n     if (m[0].size() == 0) { n       m[0].push_back({e, i.second}); n     } else if (e != m[0].back().first) n       m[0].push_back({e, i.second}); n     else n       m[0].back().second += i.second; n   } n   return t; n } n void upd(int nod, int l, int r, int id, int val) { n   if (r - l == 1) { n     seg[nod][0].clear(); n     seg[nod][0].push_back({val, 1}); n     seg[nod][1].clear(); n     seg[nod][1].push_back({val, 1}); n     if (val >= x) n       sig[nod] = 1; n     else n       sig[nod] = 0; n     return; n   } n   int mid = (r + l) >> 1; n   if (mid > id) n     upd(nod << 1, l, mid, id, val); n   else n     upd(nod << 1 | 1, mid, r, id, val); n   sig[nod] = sig[nod << 1] + sig[nod << 1 | 1]; n   sig[nod] += mrg(seg[nod << 1], seg[nod << 1 | 1]); n   seg[nod][0] = m[0]; n   seg[nod][1] = m[1]; n } n void build(int nod, int l, int r) { n   if (r - l == 1) { n     seg[nod][0].clear(); n     seg[nod][0].push_back({a[l], 1}); n     seg[nod][1].clear(); n     seg[nod][1].push_back({a[l], 1}); n     if (a[l] >= x) n       sig[nod] = 1; n     else n       sig[nod] = 0; n     return; n   } n   int mid = (r + l) >> 1; n   build(nod << 1, l, mid); n   build(nod << 1 | 1, mid, r); n   sig[nod] = sig[nod << 1] + sig[nod << 1 | 1]; n   sig[nod] += mrg(seg[nod << 1], seg[nod << 1 | 1]); n   seg[nod][0] = m[0]; n   seg[nod][1] = m[1]; n } n vector<pair<int, int> > g[2]; n long long int ans = 0; n void get(int nod, int l, int r, int L, int R) { n   if (l >= R || L >= r) return; n   if (l >= L && r <= R) { n     ans += mrg(g, seg[nod]) + sig[nod]; n     g[0] = m[0]; n     g[1] = m[1]; n     return; n   } n   int mid = (r + l) >> 1; n   get(nod << 1, l, mid, L, R); n   get(nod << 1 | 1, mid, r, L, R); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int q; n   scanf( %d %d %d , &n, &q, &x); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   build(1, 1, N); n   for (int i = 0; i < q; i++) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       int id, val; n       scanf( %d %d , &id, &val); n       upd(1, 1, N, id, val); n     } else { n       int l, r; n       scanf( %d %d , &l, &r); n       ans = 0; n       get(1, 1, N, l, r + 1); n       printf( %lld  n , ans); n       g[0].clear(); n       g[1].clear(); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1500 + 5, INF = 2000 * 1000 * 1000; n vector<pair<int, int> > li[N]; n vector<int> adj[N]; n pair<pair<int, int>, int> po[N]; n pair<int, int> J; n int d[N], out[N]; n void dfs(const int &v, const int &pa) { n   d[v] = 1; n   for (int i = 0; i < (int)(adj[v]).size(); ++i) { n     if (adj[v][i] != pa) { n       dfs(adj[v][i], v); n       d[v] += d[adj[v][i]]; n       li[v].push_back(make_pair(d[adj[v][i]], adj[v][i])); n     } n   } n } n bool cmp(const pair<pair<int, int>, int> &R, n          const pair<pair<int, int>, int> &T) { n   long long a1 = J.first - R.first.first, a2 = J.first - T.first.first; n   long long b1 = J.second - R.first.second, b2 = J.second - T.first.second; n   return a1 * b2 > a2 * b1; n } n void ass(int f, int s, int x) { n   pair<int, int> ans = make_pair(-INF, -INF); n   int no; n   for (int i = f; i <= s; ++i) { n     if (po[i].first.second > ans.second) n       ans = make_pair(po[i].first.first, po[i].first.second), no = i; n     else if (po[i].first.second == ans.second && po[i].first.first < ans.first) n       ans = make_pair(po[i].first.first, po[i].first.second), no = i; n   } n   J = ans; n   out[po[no].second] = x; n   swap(po[no], po[s]); n   sort(po + f, po + s, cmp); n   for (int i = 0; i < (int)(li[x]).size(); ++i) { n     ass(f, f + li[x][i].first - 1, li[x][i].second); n     f += li[x][i].first; n   } n } n int main() { n   ios::sync_with_stdio(false); n   srand(time(0)); n   int n, a, b, root; n   int zero = 0; n   scanf( %d , &n); n   if (n >= 1300) n     root = 750; n   else n     root = rand() % n + 1; n   for (int i = 0; i < n - 1; ++i) { n     adj[i].reserve(N); n     li[i].reserve(N); n     scanf( %d%d , &a, &b); n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   dfs(root, zero); n   for (int i = 1; i <= n; ++i) n     scanf( %d%d , &po[i].first.first, &po[i].first.second), po[i].second = i; n   ass(1, n, root); n   for (int i = 1; i <= n; ++i) printf( %d  , out[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   long long int a[n + 2]; n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n   } n   long long int mx = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i != j) { n         mx = max(mx, a[i] | a[j]); n       } n       for (int k = 1; k <= n; k++) { n         if (i != j && i != k && j != k) { n           mx = max(mx, a[i] | a[j] | a[k]); n         } n       } n     } n   } n   printf( %lld , mx); n   return 0; n } n


#include<bits/stdc++.h> n #define pb push_back n #define F first n #define S second n using namespace std; n typedef long long ll; n typedef pair<int,int>pi; n typedef vector<int>vi; n const int maxn=1e6+10; n const int M=998244353; n ll t[1<<14][105]; n ll d[105][105],d2[105][14],d22[14][14]; n ll mind[1<<14][105],mind2[1<<14][14]; n ll xa[105],ya[105],xb[105],yb[105],T[105],ans; n struct node{ n     ll x,y,t; n }A[205]; n bool cmp(node u,node v){return u.t<v.t;} n void Min(ll &x,ll y){if (y<x)x=y;} n int n,m,f[1<<14][105]; n const ll inf=1e14; n int main(){ n     cin >> m >> n; n     for (int i=0;i<m;i++) cin >> xb[i] >> yb[i]; n     for (int i=0;i<n;i++) cin >> A[i].x >> A[i].y >> A[i].t; n     sort(A,A+n,cmp); n     for (int i=0;i<n;i++) xa[i]=A[i].x,ya[i]=A[i].y,T[i]=A[i].t; n     for (int i=0;i<n;i++) n         for (int j=0;j<n;j++) n             d[i][j]=abs(xa[i]-xa[j])+abs(ya[i]-ya[j]); n     for (int i=0;i<n;i++) n         for (int j=0;j<m;j++) n             d2[i][j]=abs(xa[i]-xb[j])+abs(ya[i]-yb[j]); n     for (int i=0;i<m;i++) n         for (int j=0;j<m;j++) n             d22[i][j]=abs(xb[i]-xb[j])+abs(yb[i]-yb[j]); n     for (int i=0;i<n;i++) n     for (int j=0;j<(1<<m);j++){ n         mind[j][i]=inf; n         for (int k=0;k<m;k++) if ((j>>k)&1) Min(mind[j][i],d2[i][k]); n     } n     for (int i=0;i<m;i++) n     for (int j=0;j<(1<<m);j++){ n         mind2[j][i]=inf; n         for (int k=0;k<m;k++) if ((j>>k)&1) Min(mind2[j][i],d22[i][k]); n     } n     memset(f,-1,sizeof(f)); n     for (int i=0;i<n;i++) f[0][i]=1; n     for (int i=0;i<=n;i++) n         for (int j=0;j<(1<<m);j++) n             t[j][i]=inf; n     for (int i=0;i<m;i++) t[1<<i][0]=0; n     int ans=0; n     for (int mask=0;mask<(1<<m);mask++){ n         for (int j=0;j<=n;j++) if (t[mask][j]<inf){ n             for (int i=0;i<m;i++) if (!((mask>>i)&1)){ n                 Min(t[mask|1<<i][j],t[mask][j]+mind2[mask][i]); n             } n             for (int i=0;i<n;i++) if (t[mask][j]+mind[mask][i]<=T[i]){ n                 f[mask][i]=max(f[mask][i],j+1); n             } n         } n         for (int i=0;i<n;i++) if (f[mask][i]!=-1){ n             int k=f[mask][i]; n             ans=max(ans,k); n             for (int j=0;j<m;j++) if (!((mask>>j)&1)){ n                 Min(t[mask|1<<j][k],T[i]+min(d2[i][j],mind2[mask][j])); n             } n             for (int j=i+1;j<n;j++) if (min(d[i][j],mind[mask][j])+T[i]<=T[j]){ n                 f[mask][j]=max(f[mask][j],k+1); n             } n         } n     } n     cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[200005]; n long long k; n int main() { n   scanf( %d%I64d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); n   int p; n   for (p = 1; p <= n && a[p] == 0; p++) n     ; n   p = n - p + 1; n   long long mx = 0; n   for (int i = 1; i <= n; i++) mx = max(mx, a[i]); n   if (p == 2) n     printf( %I64d n , (k - a[n] - 1) / a[n - 1] + 1); n   else if (p == 3) { n     long long l = 0, r = 1.5e9; n     while (l < r) { n       long long md = (l + r) / 2; n       long long res = md * (md + 1) / 2; n       if (res < 0 || res >= k) n         r = md; n       else { n         res *= a[n - 2]; n         if (res < 0 || res >= k) n           r = md; n         else { n           res += md * a[n - 1]; n           if (res < 0 || res >= k) n             r = md; n           else if (res + a[n] >= k) n             r = md; n           else n             l = md + 1; n         } n       } n     } n     printf( %I64d n , r); n   } else { n     p = n - p + 2; n     int ans = 0, i; n     while (mx < k) { n       for (i = p; i <= n; i++) a[i] += a[i - 1], mx = max(mx, a[i]); n       ans++; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1, s2; n   cin >> s1 >> s2; n   int h1 = stoi(s1.substr(0, 2)); n   int m1 = stoi(s1.substr(3, 2)); n   int h2 = stoi(s2.substr(0, 2)); n   int m2 = stoi(s2.substr(3, 2)); n   int m3 = (m1 + m2) / 2; n   int h3 = h1 + h2; n   if (h3 % 2 != 0) m3 += 30; n   h3 = h3 / 2; n   if (m3 >= 60) { n     h3++; n     m3 -= 60; n   } n   if (h3 < 10) cout <<  0 ; n   cout << h3 <<  : ; n   if (m3 < 10) cout <<  0 ; n   cout << m3; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, ans = 0, sch = 0, nm = -100000, pnm = 10000; n   vector<int> v; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int t; n     scanf( %d , &t); n     if ((t % 2 == 1) && (t > 0)) { n       pnm = ((pnm) < (t)) ? (pnm) : (t); n       ans += t; n     } else if (t % 2 == -1) { n       nm = ((nm) > (t)) ? (nm) : (t); n     } else if (t > 0) { n       sch += t; n     } n   } n   if (ans == 0) ans += nm; n   ans += sch; n   if (ans % 2 == 0) ans = ((ans - pnm) > (ans + nm)) ? (ans - pnm) : (ans + nm); n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n struct Edge { n   int u, v; n   int w; n }; n struct RowEdges { n   int sum; n   std::vector<Edge> vs; n   RowEdges() : sum(0) {} n   Edge &back() { return vs.back(); } n   Edge &front() { return vs.front(); } n   Edge &operator[](int i) { return vs[i]; } n   int size() { return (int)vs.size(); } n   void pop_back() { vs.pop_back(); } n   void push_back(Edge ae) { vs.push_back(ae); } n   bool operator<(RowEdges ot) const { return sum < ot.sum; } n }; n struct Graph { n   Graph(int n) : ves(n), vals(nullptr) {} n   ~Graph() { n     if (vals) { n       delete[] vals; n       vals = nullptr; n     } n   } n   void addTwoEdge(int a, int b, int awei = 0, int bwei = 0) { n     int minWei = std::min(awei, bwei); n     addEdge(a, b, minWei); n     addEdge(b, a, minWei); n   } n   void removeTwoEdge(int a, int b) { n     removeEdge(a, b); n     removeEdge(b, a); n   } n   void removeEdge(int a, int b) { n     auto &tv = ves[a]; n     for (int i = 0; i < (int)tv.size(); i++) { n       if (tv[i].v == b) { n         tv.sum -= std::min(vals[a], vals[b]); n         tv[i] = tv.back(); n         tv.pop_back(); n         break; n       } n     } n   } n   void addEdge(int a, int b, int addWeight = 0) { n     ves[a].push_back(Edge()); n     auto &bn = ves[a].back(); n     bn.u = a, bn.v = b; n     ves[a].sum += addWeight; n   } n   void sort(int off = 0) { n     std::sort(ves.begin() + off, ves.end()); n     std::vector<int> oldToNewId(ves.size()); n     std::vector<int> newToOldId(ves.size()); n     for (size_t i = off; i < ves.size(); i++) { n       if (ves[i].size()) { n         oldToNewId[ves[i].front().u] = i; n         newToOldId[i] = ves[i].front().u; n       } n     } n     for (size_t i = off; i < ves.size(); i++) { n       for (int j = 0; j < ves[i].size(); j++) { n         ves[i][j].u = oldToNewId[ves[i][j].u]; n         ves[i][j].v = oldToNewId[ves[i][j].v]; n       } n     } n     int n = ves.size(); n     int *varr = new int[n]; n     memcpy(varr, vals, n * sizeof(int)); n     for (int i = off; i < n; i++) { n       int j = newToOldId[i]; n       vals[i] = varr[j]; n     } n     delete[] varr; n   } n   int getAns() { n     int ans = 0; n     for (size_t i = 1; i < ves.size(); i++) { n       sort(i); n       if (ves[i].size()) { n         ans += ves[i].sum; n         while (ves[i].size()) { n           removeTwoEdge(i, ves[i].front().v); n         } n       } n     } n     return ans; n   } n   std::vector<RowEdges> ves; n   int *vals; n }; n int main() { n   int n = 0, m = 0, n1 = 0; n   scanf( %d %d , &n, &m); n   n1 = n + 1; n   int *v = new int[n1]; n   v[0] = 0; n   for (int i = 1; i < n1; i++) { n     scanf( %d , v + i); n   } n   Graph g(n1); n   g.vals = v; n   int a = 0, b = 0; n   for (int i = 0; i < m; i++) { n     scanf( %d %d , &a, &b); n     g.addTwoEdge(a, b, v[a], v[b]); n   } n   printf( %d , g.getAns()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   vector<pair<long long, long long>> ar(4); n   for (long long i = 1; i <= 3; i++) { n     long long a, b; n     cin >> a >> b; n     ar[i] = {a, b}; n   } n   sort(ar.begin() + 1, ar.end()); n   set<pair<long long, long long>> ans; n   for (long long i = ar[1].first; i <= ar[2].first; i++) { n     ans.insert({i, ar[1].second}); n   } n   long long dy = 1; n   if (ar[2].second < ar[1].second) dy = -1; n   for (long long i = ar[1].second; i != ar[2].second; i += dy) { n     ans.insert({ar[2].first, i}); n   } n   ans.insert({ar[2].first, ar[2].second}); n   long long low = ar[1].second, high = ar[2].second; n   long long temp = min(high, low); n   high = max(high, low); n   low = temp; n   if (ar[3].second >= low && ar[3].second <= high) { n     for (long long i = ar[3].first; i >= ar[2].first; i--) { n       ans.insert({i, ar[3].second}); n     } n   } else if (ar[3].second > high) { n     for (long long i = ar[3].first; i >= ar[2].first; i--) { n       ans.insert({i, ar[3].second}); n     } n     for (long long i = ar[3].second; i > high; i--) { n       ans.insert({ar[2].first, i}); n     } n   } else { n     for (long long i = ar[3].first; i >= ar[2].first; i--) { n       ans.insert({i, ar[3].second}); n     } n     for (long long i = ar[3].second; i < low; i++) { n       ans.insert({ar[2].first, i}); n     } n   } n   cout << signed(ans.size()) <<   n ; n   for (auto i : ans) cout << i.first <<     << i.second <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n long long a[2001], b[2001], n, m, x, sa[2001], sb[2001], ans; n long long max(long long a, long long b) { return a > b ? a : b; } n long long min(long long a, long long b) { return a < b ? a : b; } n int main() { n   std::cin >> n >> m; n   for (int i = 1; i <= n; i++) n     std::cin >> a[i], a[i] += a[i - 1], sa[i] = 100000000000; n   for (int i = 1; i <= m; i++) n     std::cin >> b[i], b[i] += b[i - 1], sb[i] = 100000000000; n   std::cin >> x; n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) n       sa[j - i + 1] = min(sa[j - i + 1], a[j] - a[i - 1]); n   for (int i = 1; i <= m; i++) n     for (int j = i; j <= m; j++) n       sb[j - i + 1] = min(sb[j - i + 1], b[j] - b[i - 1]); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (sa[i] * sb[j] <= x) ans = max(ans, i * j); n   std::cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n char mp[1000]; n int main() { n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   for (int i = 0; i < n; i++) { n     mp[s[i] -  a ]++; n     if (mp[s[i] -  a ] > k) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int nex = 2e5 + 5; n void solve() { n   int a, b; n   cin >> a >> b; n   string s; n   cin >> s; n   int cnt = 0; n   vector<int> v; n   for (int i = 0; i < ((int)s.size()); i++) { n     if (s[i] ==  X ) { n       if (cnt) v.push_back(cnt); n       cnt = 0; n     } else { n       cnt++; n     } n   } n   if (cnt) v.push_back(cnt); n   cnt = 0; n   int val = 0; n   for (int x : v) { n     if (x < a && x >= b) { n       cout <<  NO n ; n       return; n     } n     if (x >= a && x < 2 * b) n       cnt++; n     else if (x >= 2 * b) { n       if (val) { n         cout <<  NO n ; n         return; n       } n       val = x; n     } n   } n   cnt = cnt; n   for (int i = 0; i <= (val - a); i++) { n     int x = i, y = val - a - i, lcnt = cnt; n     if (x < 2 * b && y < 2 * b) { n       if (x < a && x >= b) continue; n       if (y < a && y >= b) continue; n       if (y >= a) lcnt++; n       if (x >= a) lcnt++; n       if (lcnt % 2 == 0) { n         cout <<  YES n ; n         return; n       } n     } n   } n   if (val == 0) { n     if (cnt % 2) n       cout <<  YES n ; n     else n       cout <<  NO n ; n     return; n   } n   cout <<  NO n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << fixed << setprecision(11); n   clock_t beg = clock(); n   int t = 1, n; n   cin >> t; n   while (t--) { n     solve(); n   } n   clock_t end = clock(); n   fprintf(stderr,  %lf sec n , (double)(end - beg) / (CLOCKS_PER_SEC)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace Quick_Function { n template <typename Temp> n void Read(Temp &x) { n   x = 0; n   char ch = getchar(); n   bool op = 0; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) op = 1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   if (op) x = -x; n } n template <typename T, typename... Args> n void Read(T &t, Args &...args) { n   Read(t); n   Read(args...); n } n template <typename Temp> n Temp Max(Temp x, Temp y) { n   return x > y ? x : y; n } n template <typename Temp> n Temp Min(Temp x, Temp y) { n   return x < y ? x : y; n } n template <typename Temp> n Temp Abs(Temp x) { n   return x < 0 ? (-x) : x; n } n template <typename Temp> n void Swap(Temp &x, Temp &y) { n   x ^= y ^= x ^= y; n } n }  // namespace Quick_Function n using namespace Quick_Function; n const int MAXN = 5e6 + 5; n bool vis[MAXN]; n int n, ans; n struct Splay_Node { n   int son[2], fa, val, tag; n }; n struct Splay_Tree { n   Splay_Node t[MAXN]; n   int root, tot, Top, stk[MAXN]; n   int Ident(int pos) { return t[t[pos].fa].son[1] == pos ? 1 : 0; } n   void Connect(int pos, int fa, int flag) { n     t[fa].son[flag] = pos, t[pos].fa = fa; n   } n   void Push_Down(int pos) { n     if (!t[pos].tag) return; n     if (t[pos].son[0]) { n       t[t[pos].son[0]].val += t[pos].tag, t[t[pos].son[0]].tag += t[pos].tag; n     } n     if (t[pos].son[1]) { n       t[t[pos].son[1]].val += t[pos].tag, t[t[pos].son[1]].tag += t[pos].tag; n     } n     t[pos].tag = 0; n   } n   int New(int val, int fa) { n     t[++tot].fa = fa, t[tot].val = val; n     return tot; n   } n   void Build() { n     root = New(-0x3f3f3f3f, 0); n     t[root].son[1] = New(0x3f3f3f3f, root); n   } n   void Rotate(int pos) { n     int fa = t[pos].fa, grand = t[fa].fa; n     int flag1 = Ident(pos), flag2 = Ident(fa); n     Connect(pos, grand, flag2); n     Connect(t[pos].son[flag1 ^ 1], fa, flag1); n     Connect(fa, pos, flag1 ^ 1); n   } n   void Splay(int pos, int to) { n     int tmp = pos; n     Top = 0; n     stk[++Top] = tmp; n     while (tmp) stk[++Top] = tmp = t[tmp].fa; n     while (Top) Push_Down(stk[Top--]); n     for (int fa = t[pos].fa; t[pos].fa != to; Rotate(pos), fa = t[pos].fa) n       if (t[fa].fa != to) Ident(pos) == Ident(fa) ? Rotate(fa) : Rotate(pos); n     if (!to) root = pos; n   } n   void Insert(int &pos, int val, int fa) { n     if (!pos) { n       ++ans; n       pos = New(val, fa); n       Splay(pos, 0); n       return; n     } n     Push_Down(pos); n     if (val < t[pos].val) n       Insert(t[pos].son[0], val, pos); n     else n       Insert(t[pos].son[1], val, pos); n   } n   void Erase(int pos) { n     Splay(pos, 0); n     vis[pos] = 1; n     int l = t[pos].son[0], r = t[pos].son[1]; n     while (t[l].son[1]) l = t[l].son[1]; n     while (t[r].son[0]) r = t[r].son[0]; n     Splay(l, 0); n     Splay(r, l); n     t[r].son[0] = 0; n     --ans; n   } n   int Get_Pre(int val) { n     int pos, res, newroot; n     pos = newroot = root; n     while (pos) { n       Push_Down(pos); n       if (t[pos].val < val) { n         res = pos; n         pos = t[pos].son[1]; n       } else n         pos = t[pos].son[0]; n     } n     Splay(newroot, 0); n     return res; n   } n   int Get_Nxt(int val) { n     int pos, res, newroot; n     pos = newroot = root; n     while (pos) { n       Push_Down(pos); n       if (t[pos].val > val) { n         res = pos; n         pos = t[pos].son[0]; n       } else n         pos = t[pos].son[1]; n     } n     Splay(newroot, 0); n     return res; n   } n   void Move(int l, int r) { n     int u = Get_Nxt(l - 1), v = Get_Pre(r); n     if (t[u].val > t[v].val) return; n     if (u == v) n       t[u].val++; n     else if (t[u].val < t[v].val) { n       Splay(u, 0); n       Splay(v, u); n       int rson = t[v].son[0]; n       ++t[u].val; n       ++t[v].val, t[rson].val++; n       if (rson) ++t[rson].tag; n     } n   } n   void Body() { n     int pos = rand() % tot + 1; n     if (!vis[pos]) { n       Splay(pos, 0); n       return; n     } n     pos = rand() % tot + 1; n     if (!vis[pos]) { n       Splay(pos, 0); n       return; n     } n     pos = rand() % tot + 1; n     if (!vis[pos]) { n       Splay(pos, 0); n       return; n     } n     pos = rand() % tot + 1; n     if (!vis[pos]) { n       Splay(pos, 0); n       return; n     } n     pos = rand() % tot + 1; n     if (!vis[pos]) { n       Splay(pos, 0); n       return; n     } n   } n }; n Splay_Tree tree; n int main() { n   srand(time(0)); n   Read(n); n   tree.Build(); n   tree.Insert(tree.root, 0, 0); n   ans = 0; n   for (int i = 1, l, r; i <= n; i++) { n     Read(l, r); n     int pos = tree.Get_Nxt(r - 1); n     if (pos && pos != 1 && pos != 2) tree.Erase(pos); n     tree.Move(l, r); n     tree.Insert(tree.root, l, 0); n     tree.Body(); n   } n   printf( %d , ans); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int gr[1005][1005], n, m, a[1005], x, y; n long long g[1005]; n bool vis[1005]; n int main() { n   scanf( %d , &n), scanf( %d , &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   int mi = 100000100, l1 = 0; n   int ans = 0; n   for (int i = 0; i < m; i++) { n     scanf( %d , &x), scanf( %d , &y); n     ans += min(a[x], a[y]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct _ { n   _() { ios_base::sync_with_stdio(0); } n } _; n template <class A, class B> n ostream &operator<<(ostream &o, pair<A, B> t) { n   o <<  (  << t.first <<  ,   << t.second <<  ) ; n   return o; n } n template <class T> n string tostring(T first, int len = 0, char c =  0 ) { n   stringstream ss; n   ss << first; n   string r = ss.str(); n   if (r.length() < len) r = string(len - r.length(), c) + r; n   return r; n } n template <class T> n void PV(T a, T b, int n = 0, int w = 0, string s =    ) { n   int c = 0; n   while (a != b) { n     cout << tostring(*a++, w,    ); n     if (a != b && (n == 0 || ++c % n)) n       cout << s; n     else n       cout << endl; n   } n } n template <class T> n inline bool chmin(T &a, T b) { n   return a > b ? a = b, 1 : 0; n } n template <class T> n inline bool chmax(T &a, T b) { n   return a < b ? a = b, 1 : 0; n } n const long long linf = 0x3f3f3f3f3f3f3f3fLL; n const int inf = 0x3f3f3f3f; n const int mod = int(1e9) + 7; n const int N = 111111; n vector<int> f(int n) { n   vector<int> r; n   if (n == 1) { n     r.push_back(1); n     return r; n   } n   if (n == 2) { n     r.push_back(3); n     r.push_back(4); n     return r; n   } n   for (int i = 0; i < n - 1; i++) r.push_back(2); n   r.push_back(n - 2); n   return r; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> A = f(n); n   vector<int> B = f(m); n   for (int i : A) { n     for (int j : B) cout << i * j <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math ) n #pragma GCC target( popcnt,abm,mmx,tune=native ) n using namespace std; n long long n, i, j; n int main() { n   [=]() { n     ios_base ::sync_with_stdio(false); n     cin.tie(nullptr); n   }(); n   cin >> n; n   for (; i < n; i++) { n     for (j ^= j; j < n; j++) cout <<  WB [(i + j) % 2]; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[2]; n int main() { n   int n, k, m; n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , &m); n     cnt[m % 2]++; n   } n   int r = n - k; n   if (r == 0) { n     if (cnt[1] % 2 == 1) n       puts( Stannis ); n     else n       puts( Daenerys ); n     return 0; n   } n   int sec = r / 2; n   int fst = r - sec; n   if (fst >= cnt[0] && k % 2 == 1) { n     puts( Stannis ); n     return 0; n   } n   if (sec >= cnt[1]) { n     puts( Daenerys ); n     return 0; n   } n   if (sec >= cnt[0] && k % 2 == 0) { n     puts( Daenerys ); n     return 0; n   } n   if (r % 2 == 0) { n     puts( Daenerys ); n     return 0; n   } n   puts( Stannis ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int sz = 317; n int t[100002], a[100002]; n int l[100002], r[100002]; n long long sum[2][100002]; n long long ans[100002]; n struct node { n   int b, r, i; n }; n bool cmp(node a, node b) { n   if (a.b != b.b) return a.b < b.b; n   return a.r < b.r; n } n int n, k, q; n long long res = 0; n node block[100002]; n int val[3][100002]; n int dp[300006]; n void add1(int i) { n   res += dp[val[1][i]]; n   dp[val[0][i]]++; n } n void del1(int i) { n   dp[val[0][i]]--; n   res -= dp[val[1][i]]; n } n void add2(int i) { n   res += dp[val[2][i]]; n   dp[val[0][i]]++; n } n void del2(int i) { n   dp[val[0][i]]--; n   res -= dp[val[2][i]]; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &t[i]), t[i]--; n   vector<long long> v; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     sum[0][i] = sum[0][i - 1]; n     sum[1][i] = sum[1][i - 1]; n     sum[t[i]][i] += a[i]; n     v.emplace_back(sum[0][i] - sum[1][i]); n     v.emplace_back(sum[0][i] - sum[1][i] - k); n     v.emplace_back(sum[0][i] - sum[1][i] + k); n   } n   v.emplace_back(0); n   v.emplace_back(-k); n   v.emplace_back(+k); n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   for (int i = 0; i <= n; i++) { n     val[0][i] = n         lower_bound(v.begin(), v.end(), sum[0][i] - sum[1][i]) - v.begin() + 1; n     val[1][i] = lower_bound(v.begin(), v.end(), sum[0][i] - sum[1][i] - k) - n                 v.begin() + 1; n     val[2][i] = lower_bound(v.begin(), v.end(), sum[0][i] - sum[1][i] + k) - n                 v.begin() + 1; n   } n   scanf( %d , &q); n   for (int i = 1; i <= q; i++) { n     scanf( %d%d , &l[i], &r[i]); n     l[i]--; n     block[i] = {l[i] / sz, r[i], i}; n   } n   sort(block + 1, block + 1 + q, cmp); n   int curl = 0, curr = 0; n   dp[val[0][0]]++; n   for (int i = 1; i <= q; i++) { n     int idx = block[i].i; n     int ll = l[idx], rr = r[idx]; n     while (curl < ll) del2(curl++); n     while (curl > ll) add2(--curl); n     while (curr < rr) add1(++curr); n     while (curr > rr) del1(curr--); n     ans[idx] = res; n   } n   for (int i = 1; i <= q; i++) printf( %lld n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int DAYS = 7; n int val[DAYS]; n void solve() { n   int k; n   cin >> k; n   int tot = 0; n   for (int i = 0; i < DAYS; ++i) { n     cin >> val[i]; n     tot += val[i]; n   } n   int res = 1 << 30; n   for (int start = 0; start < DAYS; ++start) { n     if (val[start]) { n       int tmp = k; n       int passed = 0; n       for (int j = start; j < DAYS && tmp > 0; ++j) { n         passed++; n         tmp -= val[j]; n       } n       if (tmp > tot) { n         tmp -= tot; n         int cycles = tmp / tot; n         passed += cycles * DAYS; n         tmp %= tot; n         tmp += tot; n       } n       int j = 0; n       while (tmp > 0) { n         tmp -= val[j]; n         passed++; n         j = (j + 1) % DAYS; n       } n       res = min(res, passed); n     } n   } n   cout << res << endl; n } n int main() { n   ios::sync_with_stdio(false); n   int T; n   cin >> T; n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 300000000 + 10; n bitset<MAXN> check; n void Get_prime(int n) { n   check.set(); n   check[0] = check[1] = 0; n   for (int i = 2; i <= sqrt(n + 0.5); ++i) { n     if (check[i]) n       for (int j = 2; i * j <= n; ++j) check[i * j] = 0; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int l, r; n   cin >> l >> r; n   Get_prime(r); n   int cnt = 0, i; n   if (l <= 2 && 2 <= r) ++cnt; n   if (l % 4 <= 1) n     i = l / 4 * 4 + 1; n   else n     i = (l / 4 + 1) * 4 + 1; n   for (i; i <= r; i += 4) n     if (check[i]) ++cnt; n   cout << cnt; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 100010; n long long n, S[maxn], top, ans[maxn], cnt; n int main() { n   cin >> n; n   for (long long i = 1; i * i <= n; i++) n     if (n % i == 0) { n       S[++top] = i; n       if (i * i != n) S[++top] = n / i; n     } n   for (long long i = 1; i <= top; i++) { n     long long temp = (n - 1) / S[i]; n     temp++; n     long long temp2 = (n - 1) / S[i]; n     temp2 = temp2 * S[i] + 2; n     temp = temp * temp2; n     ans[++cnt] = temp / 2; n   } n   sort(ans + 1, ans + 1 + cnt); n   cnt = unique(ans + 1, ans + 1 + cnt) - ans - 1; n   for (int i = 1; i <= cnt; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c, res; n void mo() { n   freopen( 1091A.inp ,  r , stdin); n   freopen( 1091A.out ,  w , stdout); n } n void nhap() { cin >> a >> b >> c; } n void xuli() { n   if (c - 1 <= b && c - 2 <= a) { n     res = max(res, c + c - 1 + c - 2); n   } n   if (b + 1 <= c && b - 1 <= a) { n     res = max(res, b + b + 1 + b - 1); n   } n   if (a + 1 <= b && a + 2 <= c) res = max(res, a + 1 + a + a + 2); n   cout << res; n } n int main() { n   nhap(); n   xuli(); n } n


#include <bits/stdc++.h> n using namespace std; n  n const int INF = 0x3f3f3f3f; n  n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<long long> t(n), x(n); n     for (int i = 0; i < n; i++) { n       cin >> t[i] >> x[i]; n     } n     long long start = 0, end = 0, from = 0, to = 0, ans = 0; n     for (int i = 0; i < n; i++) { n       if (end <= t[i]) { n         start = t[i]; n         end = t[i] + llabs(to - x[i]); n         from = to; n         to = x[i]; n       } n       if (min(from, to) <= x[i] && max(from, to) >= x[i]) { n         long long arrival = start + abs(from - x[i]); n         if (t[i] <= arrival && (i == n - 1 ? true : (arrival <= t[i + 1]))) { n           ans++; n         } n       } n     } n     cout << ans <<   n ; n   } n   return 0; n }


#include <bits/stdc++.h> n using namespace std; n pair<int, int> Max[3005][3005]; n struct ans { n   int a, b, c; n   int i, j, k; n   ans(int _a, int _b, int _c, int _i, int _j, int _k) { n     a = _a; n     b = _b; n     c = _c; n     i = _i; n     j = _j; n     k = _k; n   } n }; n bool operator<(const ans &a, const ans &b) { n   if (a.a != b.a) n     return a.a < b.a; n   else if (a.b != b.b) n     return a.b < b.b; n   else n     return a.c < b.c; n } n int main() { n   int n; n   scanf( %d , &n); n   pair<int, int> a[3005]; n   memset(Max, -1, sizeof(Max)); n   for (int i = 0; i < n; i++) { n     int first; n     scanf( %d , &first); n     a[i] = make_pair((first), (i)); n   } n   sort(a, a + n); n   reverse(a, a + n); n   a[n] = make_pair((0), (n)); n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j <= n; j++) { n       Max[i][j - 1] = n           max(Max[i][j - 2], make_pair((a[j - 1].first - a[j].first), (j))); n     } n   } n   ans aa = ans{-1, -1, -1, 0, 0, 0}; n   for (int i = 1; i <= n; i++) { n     for (int j = (i + 1) / 2; j <= i * 2 && i + j <= n; j++) { n       int l = max((i + 1) / 2, (j + 1) / 2), r = min(i * 2, j * 2); n       l += i + j; n       r += i + j; n       l--; n       r--; n       if (l >= n) continue; n       if (r >= n) r = n - 1; n       aa = max(aa, ans(a[i - 1].first - a[i].first, n                        a[i + j - 1].first - a[i + j].first, Max[l][r].first, i, n                        i + j, Max[l][r].second)); n     } n   } n   int ans[3005]; n   memset(ans, -1, sizeof(ans)); n   for (int i = 0; i < aa.i; i++) ans[a[i].second] = 1; n   for (int i = aa.i; i < aa.j; i++) ans[a[i].second] = 2; n   for (int i = aa.j; i < aa.k; i++) ans[a[i].second] = 3; n   for (int i = 0; i < n; i++) printf( %d  , ans[i]); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long x = 0; n   int zf = 1; n   char ch =    ; n   while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar(); n   if (ch ==  - ) zf = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * zf; n } n long long val[1000005]; n long long f[1000005]; n int n; n long long cnt[9]; n int main() { n   long long w = read(), tmp = w, sum = 0; n   for (int i = 1; i <= 8; ++i) cnt[i] = read(), sum += cnt[i] * i; n   if (sum < w) { n     printf( %lld , sum); n     return 0; n   } n   if (w > 900) { n     long long w2 = w - 900, use; n     for (int i = 8; i >= 1 && w2; --i) { n       if (cnt[i] * i <= w2) n         w2 -= cnt[i] * i; n       else { n         use = (w2 / i) + 1; n         cnt[i] -= use; n         w2 -= use * i; n         break; n       } n     } n     w = 900 + w2; n   } n   for (int i = 1; i <= 8; ++i) { n     long long j = 1; n     while (cnt[i] >= j) { n       cnt[i] -= j; n       val[++n] = i * j; n       j <<= 1; n     } n     if (cnt[i]) val[++n] = cnt[i] * i; n   } n   for (int i = 1; i <= n; ++i) n     for (int j = w; j >= val[i]; --j) f[j] = max(f[j - val[i]] + val[i], f[j]); n   printf( %lld , tmp - (w - f[w])); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int k1, k2, i; n } node[105]; n bool cmp1(const Node& a, const Node& b) { return a.k1 < b.k1; } n bool cmp2(const Node& a, const Node& b) { return a.i < b.i; } n int main() { n   int n, w; n   scanf( %d%d , &n, &w); n   for (int i = 0; i < n; i++) { n     scanf( %d , &node[i].k1); n     node[i].i = i; n   } n   sort(node, node + n, cmp1); n   for (int i = 0; i < n; i++) { n     int f = node[i].k1 / 2; n     if (node[i].k1 & 1) f++; n     node[i].k2 = f; n     w -= f; n   } n   if (w < 0) { n     puts( -1 ); n     return 0; n   } n   for (int i = n - 1; i >= 0 && w; i--) { n     if (w >= node[i].k1 - node[i].k2) { n       w -= node[i].k1 - node[i].k2; n       node[i].k2 = node[i].k1; n     } else { n       node[i].k2 += w; n       w = 0; n     } n   } n   sort(node, node + n, cmp2); n   for (int i = 0; i < n; i++) { n     if (i) n       printf(  %d , node[i].k2); n     else n       printf( %d , node[i].k2); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int y, l, r, x, rem; n   cin >> l >> r; n   for (x = l; x <= r; x++) { n     y = x; n     set<int> s; n     while (y != 0) { n       rem = y % 10; n       if (s.find(rem) == s.end()) n         s.insert(rem); n       else n         break; n       y /= 10; n     } n     if (y == 0) break; n   } n   if (y == 0) n     cout << x; n   else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ,  unroll-loops ) n using namespace std; n int a[100005]; n int n; n int solve() { n   sort(a, a + n); n   int i = n - 1; n   int sum = 0; n   while (i >= 0 and a[i] >= 0) sum += a[i--]; n   if (sum % 2) return sum; n   int j = i; n   while (j >= 0 and abs(a[j]) % 2 == 0) j--; n   i++; n   while (i < n and a[i] % 2 == 0) i++; n   if (j < 0) return sum - a[i]; n   if (i == n) return sum + a[j]; n   return sum - min(a[i], abs(a[j])); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   while (t) { n     cin >> n; n     for (int i = 0; i < n; i++) cin >> a[i]; n     cout << solve(); n     t--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   long long TC = 1; n   cin >> TC; n   while (TC--) { n     int n, f = 1, c = 0; n     cin >> n; n     int a[n], feq[110] = {0}; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       feq[a[i]]++; n     } n     sort(a, a + n); n     for (int i = 0; i < n - 1; i++) { n       if (a[i + 1] - a[i] > 1) f = 0; n     } n     if (f) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long i, j, k, n, m, ans = 0; n   string a, b; n   cin >> n >> a >> b; n   for (i = 0; i < n / 2; i++) { n     int j = n - i - 1; n     if (a[i] == b[i] && a[j] == b[j]) n       continue; n     else if (a[i] == b[i] && a[j] != b[j]) n       ans++; n     else if (a[i] != b[i] && a[j] == b[j]) n       ans++; n     else { n       set<char> se({a[i], b[i], a[j], b[j]}); n       if (se.size() == 4) n         ans += 2; n       else if (se.size() == 3) { n         ans++; n         if (a[i] == a[j]) ans++; n       } n     } n   } n   if (n % 2 == 1) ans += (a[n / 2] != b[n / 2]); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, z, t1, t2, t3, ts, te; n   cin >> x >> y >> z >> t1 >> t2 >> t3; n   ts = abs(x - y) * t1; n   te = t3 * 2 + abs(x - z) * t2 + t3 + abs(x - y) * t2; n   if (ts >= te) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n typedef struct Segment { n   int start; n   int last; n   int Xor; n } segment; n using namespace std; n vector<segment> V; n int score(segment s) { n   if (s.last == s.start) n     return s.Xor; n   else { n     int value = 0; n     for (int i = s.start + 1; i < s.last;) { n       if (V[i].start == -1) n         i++; n       else { n         value += score(V[i]); n         i = V[i].last + 1; n       } n     } n     return max(value, s.Xor); n   } n } n int cities_final[5010]; n int cities_first[5010]; n int cities[5010]; n int main() { n   int n; n   scanf( %d , &n); n   int people[n]; n   int cumulativeXOR[n + 1]; n   cumulativeXOR[0] = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , &people[i]); n     if (!cities[people[i]]) n       cumulativeXOR[i + 1] = cumulativeXOR[i] ^ people[i]; n     else n       cumulativeXOR[i + 1] = cumulativeXOR[i]; n     if (!cities[people[i]]) cities_first[people[i]] = i; n     cities[people[i]] = 1; n     cities_final[people[i]] = i; n   } n   int start; n   int last; n   int Xor; n   for (int i = 0; i < n; i++) { n     start = i; n     last = i; n     int flag = 0; n     if (cities[people[i]]) { n       for (int j = i; j <= last; j++) { n         if (cities_first[people[j]] < start) { n           flag = 1; n         } n         if (cities_final[people[j]] > last) last = cities_final[people[j]]; n       } n       Xor = cumulativeXOR[last + 1] ^ cumulativeXOR[start]; n       segment s; n       s.start = start; n       s.last = last; n       s.Xor = Xor; n       if (flag) s.start = -1; n       cities[people[i]] = 0; n       V.push_back(s); n     } else { n       segment s; n       s.start = -1; n       V.push_back(s); n     } n   } n   int ans = 0; n   for (int i = 0; i < n;) { n     ans += score(V[i]); n     i = V[i].last + 1; n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n bool ch1(int t, int da, int db, int a, int b, int x) { n   for (int i = 0; i <= t - 1; i++) { n     for (int j = 0; j <= t - 1; j++) { n       if (((a - i * da + b - j * db == x) && n            (a - i * da >= 0 && b - j * db >= 0)) || n           a - i * da == x || b - j * db == x) n         return true; n     } n   } n   return false; n } n int main() { n   int x, a, b, t, da, db, total; n   cin >> x >> t >> a >> b >> da >> db; n   total = a + b; n   if (x > total) n     cout <<  NO n ; n   else if (x == 0) n     cout <<  YES n ; n   else { n     if (ch1(t, da, db, a, b, x)) { n       cout <<  YES n ; n     } else { n       cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, f[2001] = {0}; n bool p, a[2001][2001]; n string st; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> st; n     for (int j = 0; j < m; j++) n       if (st[j] ==  1 ) { n         a[i][j + 1] = true; n         f[j + 1]++; n       } else n         a[i][j + 1] = false; n   } n   for (int i = 1; i <= n; i++) { n     p = true; n     for (int j = 1; j <= m; j++) n       if (f[j] == 1 && a[i][j] == 1) p = false; n     if (p) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n int main() { n   fast(); n   long long n; n   cin >> n; n   char a[n + 10]; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   long long func[15]; n   for (int i = 1; i <= 9; ++i) { n     cin >> func[i]; n   } n   for (int i = 1; i <= n; ++i) { n     if (func[a[i] -  0 ] > a[i] -  0 ) { n       for (int j = i; j <= n; ++j) { n         if (a[j] -  0  <= func[a[j] -  0 ]) n           a[j] = func[a[j] -  0 ] +  0 ; n         else n           break; n       } n       for (int j = 1; j <= n; ++j) cout << a[j]; n       return 0; n     } n   } n   for (int i = 1; i <= n; ++i) cout << a[i]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400005; n int n, m, k, s, t, a[N], b[N]; n int ans; n long long p; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   for (int j = 0; j < 25; ++j) { n     for (int i = 1; i <= n; ++i) p += ((a[i] >> j) & 1) * (n - 1); n     if (p & 1) ans += 1 << j; n     p = 0; n     for (int i = 1; i <= n; ++i) b[i] = a[i] % (1 << (j + 1)); n     sort(b + 1, b + 1 + n); n     int r = n; n     for (int l = 1; l < n; ++l) { n       while (r > l && b[l] + b[r] >= (1 << (j + 1))) --r; n       if (r <= l) r = l; n       p += n - r; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n long long l[200002], c[200002]; n long long minx, maxx, miny, maxy; n string s; n bool check(long long l[], int n) { n   int Min = 0, Max = 0; n   int last = 0, first = 0; n   for (int i = 1; i <= n; i++) { n     if (l[i] < Min) { n       first = i; n       Min = l[i]; n     } n     if (l[i] >= Max) { n       last = i; n       Max = l[i]; n     } n   } n   if (last < first) return 1; n   Min = 0, Max = 0; n   first = last = 0; n   for (int i = 1; i <= n; i++) { n     if (l[i] > Max) { n       first = i; n       Max = l[i]; n     } n     if (l[i] <= Min) { n       Min = l[i]; n       last = i; n     } n   } n   if (last < first) return 1; n   return 0; n } n int main() { n   cin >> t; n   while (t--) { n     cin >> s; n     minx = maxx = miny = maxy = 0; n     long long x = 0, y = 0; n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  D ) c[i + 1] = c[i] + 1; n       if (s[i] ==  A ) c[i + 1] = c[i] - 1; n       if (s[i] ==  W ) l[i + 1] = l[i] + 1; n       if (s[i] ==  S ) l[i + 1] = l[i] - 1; n       if (s[i] ==  W  || s[i] ==  S ) c[i + 1] = c[i]; n       if (s[i] ==  D  || s[i] ==  A ) l[i + 1] = l[i]; n       minx = min(minx, l[i + 1]); n       miny = min(miny, c[i + 1]); n       maxx = max(maxx, l[i + 1]); n       maxy = max(maxy, c[i + 1]); n     } n     long long ans = (maxx - minx + 1) * (maxy - miny + 1); n     if (check(l, s.size()) && maxx - minx + 1 > 2) n       ans = min(ans, (maxx - minx) * (maxy - miny + 1)); n     if (check(c, s.size()) && maxy - miny + 1 > 2) n       ans = min(ans, (maxx - minx + 1) * (maxy - miny)); n     cout << ans <<   n ; n   } n   return 0; n } n