#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   map<int, int> m; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     m[a[i]]++; n   } n   int chek[32]; n   chek[0] = 2; n   for (int i = 1; i < 32; i++) { n     chek[i] = chek[i - 1] * 2; n   } n   int sm = 0, coun = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 32; j++) { n       int h = chek[j] - a[i]; n       if (m.find(h) != m.end()) { n         if (h == a[i] && m[a[i]] > 1) { n           coun++; n           break; n         } n         if (h != a[i]) { n           coun++; n           break; n         } n       } n     } n   } n   cout << n - coun << endl; n   return 0; n } n


#include <bits/stdc++.h> n #define testCase int T; cin>>T; while(T--) n #define int long long n #define Endl endl n  n using namespace std; n  n /* n  */ n const int N = 1e5+13, LMAX  = 3e18 + 13, IMAX = 1e9 + 5, mod  = 1e9 + 7; //998244353; n  n int32_t main() { n     ios_base::sync_with_stdio(false); n     cin.tie(nullptr); n  n     testCase { n         int mn = 101; n         int n, x; n         cin >> n; n         for (int i = 0; i < n; ++i) { n             cin >> x; n             mn = min(mn, x); n         } n         if (mn < 0) cout <<  NO n ; n         else { n             cout <<  YES n ; n             cout <<  101 n ; n             for (int i = 0; i <=100; ++i) { n                 cout << i <<    ; n             }cout <<   n ; n         } n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k, a[300001], seti = 0, l, r, z = 0, maxi = 0, fz, lt = -1, n                              rt = -1; n   cin >> n >> k; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   l = 0; n   for (long long i = 0; i < n; i++) { n     if (a[i] == 0) { n       z++; n       if (z == k + 1) { n         r = i - 1; n         if (r - l + 1 > maxi) { n           maxi = r - l + 1; n           lt = l; n           rt = r; n         } n         z--; n         if (a[l] == 0) { n           l++; n         } else { n           for (long long j = l + 1; j < n; j++) { n             if (a[j] == 0) { n               l = j + 1; n               break; n             } n           } n         } n       } n     } n   } n   if (n - l > maxi) { n     lt = l; n     rt = n - 1; n     maxi = n - l; n   } n   cout << maxi << endl; n   if (lt != -1) n     for (long long i = lt; i <= rt; i++) a[i] = 1; n   for (long long i = 0; i < n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cout << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n inline int sbt(int x) { return __builtin_popcount(x); } n inline long long gl(long long a, long long b) { return (b - a + 1); } n inline long long mul(long long a, long long b, n                      long long m = (long long)(1e9 + 7)) { n   return ((a % m) * (b % m)) % m; n } n inline long long add(long long a, long long b, n                      long long m = (long long)(1e9 + 7)) { n   return (a + b) % m; n } n inline long long sub(long long a, long long b, n                      long long m = (long long)(1e9 + 7)) { n   return (a - b + m) % m; n } n long long fastpow(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = mul(res, a); n     a = mul(a, a); n     b >>= 1; n   } n   return res; n } n long long modinv(long long a) { return fastpow(a, (long long)(1e9 + 7) - 2); } n void get_ac() { n   long long n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   vector<vector<long long>> v; n   bool f; n   long long mink = 0, maxk = 0; n   while (1) { n     f = 0; n     vector<long long> va; n     for (int i = 0; i < n - 1; i++) { n       if (s[i] ==  R  && s[i + 1] ==  L ) { n         swap(s[i], s[i + 1]); n         f = 1; n         va.push_back(i); n         i++; n       } n     } n     if (!f) break; n     v.push_back(va); n     maxk += (long long)(va.size()); n     mink++; n   } n   if (k < mink || k > maxk) { n     cout << -1; n     return; n   } n   long long i = 0, j = 0; n   while (k > mink - i) { n     cout << 1 <<     << v[i][j] + 1; n     cout <<   n ; n     j++; n     if (j == (long long)(v[i].size())) { n       i++; n       j = 0; n     } n     k--; n   } n   for (int l = i; l < mink; l++) { n     cout << ((long long)(v[l].size()) - j) <<    ; n     for (int m = j; m < (long long)(v[l].size()); m++) { n       cout << v[l][m] + 1 <<    ; n     } n     j = 0; n     cout <<   n ; n   } n } n int main() { n   cin.sync_with_stdio(false); n   cout.sync_with_stdio(false); n   cin.tie(NULL); n   { get_ac(); } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n struct Point { n   int x; n   int y; n }; n int direction(Point a, Point b, Point c) { n   return (c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x); n } n bool onsegment(Point a, Point b, Point c) { n   return (min(a.x, b.x) <= c.x && max(a.x, b.x) >= c.x && n           min(a.y, b.y) <= c.y && max(a.y, b.y) >= c.y); n } n bool intersects(Point a, Point b, Point c, Point d) { n   int d1 = direction(c, d, a), d2 = direction(c, d, b), d3 = direction(a, b, c), n       d4 = direction(a, b, d); n   if (d1 * d2 < 0 && d3 * d4 < 0) { n     return true; n   } else if (d1 == 0 && onsegment(c, d, a)) { n     return true; n   } else if (d2 == 0 && onsegment(c, d, b)) { n     return true; n   } else if (d3 == 0 && onsegment(a, b, c)) { n     return true; n   } else if (d4 == 0 && onsegment(a, b, d)) { n     return true; n   } else { n     return false; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   Point a[5], b[5]; n   for (int i = 0; i < 4; i++) { n     int x, y; n     cin >> x >> y; n     a[i] = {x, y}; n   } n   a[4] = a[0]; n   for (int i = 0; i < 4; i++) { n     int x, y; n     cin >> x >> y; n     b[i] = {x, y}; n   } n   b[4] = b[0]; n   for (int i = 0; i < 4; i++) { n     if (intersects(b[i], b[i + 1], a[0], a[2]) || n         intersects(b[i], b[i + 1], a[1], a[3])) { n       return cout <<  YES n , 0; n     } n   } n   for (int i = 0; i < 4; i++) { n     if (b[i].x >= min(min(a[0].x, a[1].x), min(a[2].x, a[3].x)) && n         b[i].x <= max(max(a[0].x, a[1].x), max(a[2].x, a[3].x)) && n         b[i].y >= min(min(a[0].y, a[1].y), min(a[2].y, a[3].y)) && n         b[i].y <= max(max(a[0].y, a[1].y), max(a[2].y, a[3].y))) { n       return cout <<  YES n , 0; n     } n   } n   for (int i = 0; i < 5; i++) { n     a[i] = {a[i].x - a[i].y, a[i].x + a[i].y}; n     b[i] = {b[i].x - b[i].y, b[i].x + b[i].y}; n   } n   for (int i = 0; i < 4; i++) { n     if (a[i].x >= min(min(b[0].x, b[1].x), min(b[2].x, b[3].x)) && n         a[i].x <= max(max(b[0].x, b[1].x), max(b[2].x, b[3].x)) && n         a[i].y >= min(min(b[0].y, b[1].y), min(b[2].y, b[3].y)) && n         a[i].y <= max(max(b[0].y, b[1].y), max(b[2].y, b[3].y))) { n       return cout <<  YES n , 0; n     } n   } n   return cout <<  NO n , 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a; n   while (n) { n     int x = n, p = 1, m = 0; n     while (x) { n       if (x % 10) m += p; n       x /= 10; n       p *= 10; n     } n     n -= m; n     a.push_back(m); n   } n   cout << a.size() << endl; n   for (int &i : a) cout << i <<    ; n } n


#include <bits/stdc++.h> n int main() { n   long long n; n   scanf( %lld , &n); n   long long a[1000005] = {0}; n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     ans = ans + a[i] * i - (i - 1); n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using lint = long long; n using ld = long double; n template <class T> n using numr = std::numeric_limits<T>; n struct input_t { n   template <class T> n   operator T() { n     T t; n     std::cin >> t; n     return t; n   } n } input; n namespace ns { n using namespace std; n template <int mod> n struct NumberTheoreticTransform { n   vector<int> rev, rts; n   int base, max_base, root; n   NumberTheoreticTransform() : base(1), rev{0, 1}, rts{0, 1} { n     assert(mod >= 3 && mod % 2 == 1); n     auto tmp = mod - 1; n     max_base = 0; n     while (tmp % 2 == 0) tmp >>= 1, max_base++; n     root = 2; n     while (mod_pow(root, (mod - 1) >> 1) == 1) ++root; n     assert(mod_pow(root, mod - 1) == 1); n     root = mod_pow(root, (mod - 1) >> max_base); n   } n   inline int mod_pow(int x, int n) { n     int ret = 1; n     while (n > 0) { n       if (n & 1) ret = mul(ret, x); n       x = mul(x, x); n       n >>= 1; n     } n     return ret; n   } n   inline int inverse(int x) { return mod_pow(x, mod - 2); } n   inline unsigned add(unsigned x, unsigned y) { n     x += y; n     if (x >= mod) x -= mod; n     return x; n   } n   inline unsigned mul(unsigned a, unsigned b) { n     return 1ull * a * b % (unsigned long long)mod; n   } n   void ensure_base(int nbase) { n     if (nbase <= base) return; n     rev.resize(1 << nbase); n     rts.resize(1 << nbase); n     for (int i = 0; i < (1 << nbase); i++) { n       rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1)); n     } n     assert(nbase <= max_base); n     while (base < nbase) { n       int z = mod_pow(root, 1 << (max_base - 1 - base)); n       for (int i = 1 << (base - 1); i < (1 << base); i++) { n         rts[i << 1] = rts[i]; n         rts[(i << 1) + 1] = mul(rts[i], z); n       } n       ++base; n     } n   } n   void ntt(vector<int> &a) { n     const int n = (int)a.size(); n     assert((n & (n - 1)) == 0); n     int zeros = __builtin_ctz(n); n     ensure_base(zeros); n     int shift = base - zeros; n     for (int i = 0; i < n; i++) { n       if (i < (rev[i] >> shift)) { n         swap(a[i], a[rev[i] >> shift]); n       } n     } n     for (int k = 1; k < n; k <<= 1) { n       for (int i = 0; i < n; i += 2 * k) { n         for (int j = 0; j < k; j++) { n           int z = mul(a[i + j + k], rts[j + k]); n           a[i + j + k] = add(a[i + j], mod - z); n           a[i + j] = add(a[i + j], z); n         } n       } n     } n   } n   vector<int> multiply(vector<int> a, vector<int> b) { n     int need = a.size() + b.size() - 1; n     int nbase = 1; n     while ((1 << nbase) < need) nbase++; n     ensure_base(nbase); n     int sz = 1 << nbase; n     a.resize(sz, 0); n     b.resize(sz, 0); n     ntt(a); n     ntt(b); n     int inv_sz = inverse(sz); n     for (int i = 0; i < sz; i++) { n       a[i] = mul(a[i], mul(b[i], inv_sz)); n     } n     reverse(a.begin() + 1, a.end()); n     ntt(a); n     a.resize(need); n     return a; n   } n }; n }  // namespace ns n constexpr int mod = 998244353; n lint inverse(lint x) { n   assert(x % mod); n   lint y = 1, u = mod, v = 0; n   while (x) { n     lint q = u / x; n     u -= q * x; n     std::swap(u, x); n     v -= q * y; n     std::swap(v, y); n   } n   assert(x == 0 && std::abs(u) == 1 && std::abs(y) == mod && std::abs(v) < mod); n   return v < 0 ? v + mod : v; n } n lint normalized(lint x) { n   if (x <= -mod || mod <= x) x %= mod; n   if (x < 0) x += mod; n   return x; n } n struct mint { n   lint value; n   mint() = default; n   mint(lint x) : value(normalized(x)) {} n }; n std::ostream &operator<<(std::ostream &os, mint x) { return os << x.value; } n mint operator+(mint x, mint y) { n   lint z = x.value + y.value; n   if (mod <= z) z -= mod; n   return mint{z}; n } n mint operator-(mint x, mint y) { n   lint z = x.value - y.value; n   if (z < 0) z += mod; n   return mint{z}; n } n mint operator*(mint x, mint y) { return mint{x.value * y.value % mod}; } n mint operator/(mint x, mint y) { n   return mint{x.value * inverse(y.value) % mod}; n } n mint &operator+=(mint &x, mint y) { return x = x + y; } n mint &operator-=(mint &x, mint y) { return x = x - y; } n mint &operator*=(mint &x, mint y) { return x = x * y; } n mint &operator/=(mint &x, mint y) { return x = x / y; } n bool operator==(mint x, mint y) { return x.value == y.value; } n bool operator!=(mint x, mint y) { return x.value != y.value; } n mint power(mint x, lint y) { n   mint z = 1; n   for (; y; y >>= 1) { n     if (y & 1) z *= x; n     x *= x; n   } n   return z; n } n int main() { n   std::cin.tie(nullptr); n   std::ios_base::sync_with_stdio(false); n   std::cout.setf(std::ios_base::fixed); n   std::cout.precision(15); n   lint n = (lint)input / 2, k = input; n   std::vector<int> a(10); n   while (k--) { n     int x = input; n     a.at(x) = 1; n   } n   while (!a.back()) a.pop_back(); n   ns::NumberTheoreticTransform<mod> ntt; n   std::vector<int> b = {1}; n   for (; n; n >>= 1) { n     if (n & 1ll) b = ntt.multiply(a, b); n     a = ntt.multiply(a, a); n   } n   std::vector<mint> c(b.size()); n   std::transform(std::begin(b), std::end(b), c.begin(), n                  [](int x) { return x; }); n   std::cout << std::accumulate(std::begin(c), std::end(c), mint{0}, n                                [](mint acc, mint x) { return acc + x * x; }) n             <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 500; n const int inf = 1e9 + 5; n struct node { n   int l, r; n } b[N]; n bool cmp(node a, node b) { return a.l < b.l; } n bool rcmp(node a, node b) { return a.r > b.r; } n int n, m, a[N], cnt, rt, ls[N * 32], rs[N * 32], sz[N * 32], vl[N * 32], Big[N], n     Small[N], flag, b1[N], b2[N]; n bool tag[N * 32]; n void add(int &x, int l, int r, int pos) { n   if (!x) x = ++cnt; n   sz[x]++; n   vl[x]++; n   if (l == r) return; n   int mi = (l + r) >> 1; n   if (pos <= mi) n     add(ls[x], l, mi, pos); n   else n     add(rs[x], mi + 1, r, pos); n } n void Pd(int x) { n   if (x) tag[x] ^= 1, vl[x] = sz[x] - vl[x]; n } n void pd(int x) { n   if (tag[x]) Pd(ls[x]), Pd(rs[x]), tag[x] = 0; n } n void modify(int x, int l, int r, int pos) { n   if (!x) return; n   if (r <= pos) { n     Pd(x); n     return; n   } n   int mi = (l + r) >> 1; n   pd(x); n   modify(ls[x], l, mi, pos); n   if (mi < pos) modify(rs[x], mi + 1, r, pos); n   vl[x] = vl[ls[x]] + vl[rs[x]]; n } n int ask(int x, int l, int r, int pos) { n   if (!x) return 0; n   if (l >= pos) return vl[x]; n   int mi = (l + r) >> 1, ans = 0; n   pd(x); n   if (pos <= mi) ans += ask(ls[x], l, mi, pos); n   ans += ask(rs[x], mi + 1, r, pos); n   return ans; n } n void modifyy(int x, int l, int r, int pos) { n   if (!x) return; n   if (l >= pos) { n     Pd(x); n     return; n   } n   int mi = (l + r) >> 1; n   pd(x); n   if (pos <= mi) modifyy(ls[x], l, mi, pos); n   modifyy(rs[x], mi + 1, r, pos); n   vl[x] = vl[ls[x]] + vl[rs[x]]; n } n int askk(int x, int l, int r, int pos) { n   if (!x) return 0; n   if (r <= pos) return vl[x]; n   int mi = (l + r) >> 1, ans = 0; n   pd(x); n   ans += askk(ls[x], l, mi, pos); n   if (mi < pos) ans += askk(rs[x], mi + 1, r, pos); n   return ans; n } n int main() { n   scanf( %d%d , &n, &m); n   long long ans = 1ll * n * (n - 1) / 2 * (n - 2) / 3; n   long long spc = 0; n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   for (int i = 1; i <= m; i++) scanf( %d%d , &b[i].l, &b[i].r); n   sort(b + 1, b + m + 1, cmp); n   sort(a + 1, a + n + 1); n   for (int i = 1, j = 1; i <= n; i = j) { n     while (j <= n && a[i] == a[j]) ++j; n     for (int k = i; k <= j - 1; k++) b1[k] = j - k - 1, b2[k] = k - i; n     ans -= 1ll * (j - i) * (j - i - 1) / 2 * (j - i - 2) / 3; n     spc += 1ll * (j - i) * (j - i - 1) / 2 * (n - j + i); n   } n   cnt = rt = 0; n   for (int i = 1; i <= n; i++) add(rt, 0, inf, a[i]); n   int j = 1; n   for (int i = 1; i <= n; i++) { n     while (j <= m && b[j].l <= a[i]) { n       modify(rt, 0, inf, b[j].r), ++j; n     } n     int t = ask(rt, 0, inf, a[i] + 1); n     Big[i] += t; n     Small[i] += n - i - b1[i] - t; n   } n   cnt = rt = 0; n   memset(sz, 0, sizeof(sz)); n   memset(vl, 0, sizeof(vl)); n   memset(ls, 0, sizeof(ls)); n   memset(rs, 0, sizeof(rs)); n   memset(tag, 0, sizeof(tag)); n   for (int i = 1; i <= n; i++) add(rt, 0, inf, a[i]); n   sort(b + 1, b + m + 1, rcmp); n   j = 1; n   for (int i = n; i >= 1; i--) { n     while (j <= m && b[j].r >= a[i]) modifyy(rt, 0, inf, b[j].l), ++j; n     int t = askk(rt, 0, inf, a[i] - 1); n     Small[i] += t; n     Big[i] += i - 1 - b2[i] - t; n   } n   long long tmp = 0; n   for (int i = 1; i <= n; i++) { n     tmp += 1ll * Big[i] * (Big[i] - 1) / 2; n     tmp += 1ll * Small[i] * (Small[i] - 1) / 2; n   } n   tmp = (tmp + spc) / 2; n   printf( %I64d n , ans - tmp); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long LL; n typedef pair<int, int> PII; n typedef pair<LL,LL> PLL; n const int INF = 0x3f3f3f3f, N = 1e5 + 10; n inline int lc(int u) {return u << 1;} n inline int rc(int u) {return u << 1 | 1;} n inline int lowbit(int x) {return x & (-x);} n int y[27] = {10010,11020,20011,21012,11011,21021,22022,12021,11011,12012,10120,11130,20121,21122,11121,21131,22132,12131,11121,12122,10221,11231,12113,20222,21223,11222}; n char x[30000]; n inline void solve() { n     for (int i = 0; i < 26; i ++ ) { n         if (x[y[i]] == 0) x[y[i]] = i +  a ; n     } n     int n; cin >> n; n     for (int i = 1; i <= n; i ++ ) { n         int res = 0; n         for (int j = 0; j < 5; j ++ ) { n             int tmp; cin >> tmp; n             res = res * 10 + tmp; n         } n         cout << x[res]; n     } n } n int main() { n //    ios::sync_with_stdio(false), cin.tie(nullptr); n //    int t; cin >> t; n //    while (t -- ) n         solve(); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n int n, k, root, ans; n vector<int> g[N]; n int dfs(int u, int f) { n   if (g[u].size() == 1) return 0; n   vector<int> d; n   for (int v : g[u]) n     if (v != f) d.push_back(dfs(v, u) + 1); n   sort(d.begin(), d.end()); n   int sz = d.size(); n   while (sz >= 2) { n     if (d[sz - 1] + d[sz - 2] <= k) break; n     ans++, sz--; n     d.pop_back(); n   } n   int ret = d.back(); n   d.clear(); n   return ret; n } n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) n     if (g[i].size() > 1) { n       root = i; n       break; n     } n   dfs(root, -1); n   printf( %d , ans + 1); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) n #pragma GCC optimize( no-stack-protector,fast-math ) n using namespace std; n const long long N = 1e6 + 100, OO = 724249387, T = (1 << 20) + 10, n                 M = 998244353, P = 6151, SQ = 280, lg = 64; n long long n, m, k, num, ed, t; n vector<long long> v[N]; n bool mark[N]; n void dfs(long long x) { n   mark[x] = 1; n   num++; n   for (auto u : v[x]) n     if (!mark[u]) dfs(u); n } n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> m >> k; n   for (long long i = 0; i < m; i++) { n     long long x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   for (long long i = 1; i <= n; i++) { n     if (!mark[i]) { n       num = 0; n       dfs(i); n       ed += min(num, k); n       t++; n     } n   } n   ed /= 2; n   if (k == 1) return cout << max((long long)0, t - 2), 0; n   cout << max((long long)0, t - 1 - ed); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   char ch = getchar(); n   int res = 0, flag = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) flag = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     res = res * 10 + ch -  0 ; n     ch = getchar(); n   } n   return res * flag; n } n int r, c, n, k, p[3005][3005], x, y, cnt[3005], nxt[3005], lst[3005], tmp[3005]; n long long ans; n int main() { n   r = read(); n   c = read(); n   n = read(); n   k = read(); n   for (register int i = 1; i <= n; ++i) { n     x = read(); n     y = read(); n     p[x][++p[x][0]] = y; n   } n   for (register int i = 1; i <= r; ++i) sort(p[i] + 1, p[i] + p[i][0] + 1); n   for (register int i = r; i; --i) { n     int h = 1, t = 0, s = 0; n     long long now = 0; n     for (register int j = 1; j <= p[i][0]; ++j) ++cnt[p[i][j]]; n     while (1) { n       while (t < c && s < k) { n         ++t; n         s += cnt[t]; n       } n       if (s < k) break; n       while (h <= t && s >= k) { n         s -= cnt[h]; n         ++h; n         now += c - t + 1; n       } n     } n     nxt[0] = 1; n     lst[c + 1] = c; n     for (register int j = 1; j <= c; ++j) { n       nxt[j] = j + 1; n       lst[j] = j - 1; n     } n     for (register int j = 1; j <= c; ++j) n       if (!cnt[j]) { n         nxt[lst[j]] = nxt[j]; n         lst[nxt[j]] = lst[j]; n       } n     memcpy(tmp, cnt, sizeof(cnt)); n     for (register int j = r; j >= i; --j) { n       ans += now; n       for (register int u = 1; u <= p[j][0]; ++u) { n         h = t = p[j][u]; n         int s1 = tmp[h], s2 = 0; n         while (nxt[t] <= c && s1 + s2 + tmp[nxt[t]] <= k) { n           t = nxt[t]; n           s2 += tmp[t]; n         } n         while (1) { n           if (s1 + s2 == k) now -= (h - lst[h]) * (nxt[t] - t); n           h = lst[h]; n           s1 += tmp[h]; n           if (!h || s1 > k) break; n           while (s1 + s2 > k) { n             s2 -= tmp[t]; n             t = lst[t]; n           } n         } n         --tmp[p[j][u]]; n         if (!tmp[p[j][u]]) { n           nxt[lst[p[j][u]]] = nxt[p[j][u]]; n           lst[nxt[p[j][u]]] = lst[p[j][u]]; n         } n       } n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = int(1e9 + 5); n const long long MAXL = long long(1e18 + 5); n const long long MOD = long long(1e9 + 7); n const long long MOD2 = long long(998244353); n void fastio() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   return; n } n void precision(int x) { n   cout.setf(ios::fixed | ios::showpoint); n   cout.precision(x); n   return; n } n long long gcd(long long a, long long b) { n   if (a > b) { n     swap(a, b); n   } n   if (a == 0) { n     return b; n   } n   if (a == b) { n     return a; n   } n   return gcd(b % a, a); n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n bool is_prime(long long a) { n   if (a == 1) { n     return false; n   } n   long long i; n   for (i = 2; i * i <= a; i++) { n     if (a % i == 0) { n       return false; n     } n   } n   return true; n } n bool is_square(long long a) { n   long long b = long long(sqrt(a)); n   return (b * b == a); n } n bool is_cube(long long a) { n   long long b = long long(cbrt(a)); n   return (b * b * b == a); n } n int digit_sum(long long a) { n   int sum = 0; n   while (a) { n     sum += int(a % 10); n     a /= 10; n   } n   return sum; n } n long long binpow(long long a, int b) { n   long long ans = 1; n   while (b) { n     if ((b & 1) == 1) { n       ans *= a; n     } n     b >>= 1; n     a *= a; n   } n   return ans; n } n long long binpow_by_mod(long long a, long long b, long long mod) { n   long long ans = 1; n   while (b) { n     if ((b & 1) == 1) { n       ans *= a; n       ans %= mod; n     } n     b >>= 1; n     a *= a; n     a %= mod; n   } n   return ans; n } n long long factorial(int a) { n   int i; n   long long ans = 1; n   for (i = 2; i <= a; i++) { n     ans *= long long(i); n   } n   return ans; n } n long long factorial_by_mod(int a, long long mod) { n   int i; n   long long ans = 1; n   for (i = 2; i <= a; i++) { n     ans *= long long(i); n     ans %= mod; n   } n   return ans; n } n const int N = 200005; n int a[N]; n int n; n void solve() { n   int i, j; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + n + 1); n   for (i = 2; i <= (n / 2) + 1; i++) { n     cout << a[i] <<     << a[1] << endl; n   } n   return; n } n void precalc() { return; } n int main() { n   fastio(); n   precalc(); n   int tests = 1, tc; n   cin >> tests; n   for (tc = 1; tc <= tests; tc++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e3 + 10; n long long n, m, ans, h[N][N]; n char ar[N][N]; n bool get(long long i, long long j) { n   long long x = h[i][j]; n   i -= x; n   if (i < 0) return 0; n   if (h[i][j] != x) return 0; n   i -= x; n   if (i < 0) return 0; n   return h[i][j] >= x; n } n bool ok(long long row, long long l, long long r) { n   long long x = h[row][l]; n   if (ar[row][l] != ar[row][r]) return 0; n   row -= x; n   if (ar[row][l] != ar[row][r]) return 0; n   row -= x; n   return ar[row][l] == ar[row][r]; n } n long long choose2(long long x) { return (x * (x - 1)) / 2; } n long long solve(vector<bool> &vec, long long row) { n   assert(vec.size() == m); n   long long res = 0; n   for (long long i = 0; i < vec.size(); i++) { n     if (!vec[i]) continue; n     long long r = i + 1; n     while (r < vec.size() && vec[r] && h[row][i] == h[row][r] && ok(row, i, r)) n       r++; n     res += choose2(r - i + 1); n     i = r - 1; n   } n   return res; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < m; j++) cin >> ar[i][j]; n   for (long long j = 0; j < m; j++) h[0][j] = 1; n   for (long long i = 1; i < n; i++) n     for (long long j = 0; j < m; j++) { n       if (ar[i][j] == ar[i - 1][j]) n         h[i][j] = h[i - 1][j] + 1; n       else n         h[i][j] = 1; n     } n   for (long long i = 0; i < n; i++) { n     vector<bool> vec; n     for (long long j = 0; j < m; j++) vec.push_back(get(i, j)); n     ans += solve(vec, i); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(int test_case) { n   int a, b; n   cin >> a >> b; n   cout << b % max(b / 2 + 1, a) <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int t; n   cin >> t; n   for (int test_case = 1; test_case <= t; ++test_case) { n     solve(test_case); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000001]; n int mod = 1000000007; n int f(int x, int y) { n   int res = 1; n   long long xx = x; n   while (y > 0) { n     if (y % 2) res = (res * xx) % mod; n     xx = (xx * xx) % mod; n     y = y / 2; n   } n   return res; n } n int main() { n   int t, p; n   int n, ba; n   int i, j; n   scanf( %d , &t); n   for (p = 1; p <= t; p++) { n     scanf( %d%d , &n, &ba); n     for (i = 1; i <= n; i++) scanf( %d , &a[i]); n     if (ba == 1) { n       printf( %d n , n % 2); n       continue; n     } n     sort(a + 1, a + n + 1); n     long long cur = 1; n     for (i = n - 1; i >= 1; i--) { n       if (a[i] == a[i + 1]) { n         if (cur == 0) n           cur++; n         else n           cur--; n       } else { n         if (cur == 0) n           cur++; n         else { n           while (a[i + 1] > a[i] && cur < i) { n             a[i + 1]--; n             cur = cur * ba; n           } n           if (cur < i) n             cur--; n           else n             break; n         } n       } n     } n     if (i == 0) n       printf( %d n , (cur * f(ba, a[1])) % mod); n     else { n       int res = (cur * f(ba, a[i + 1])) % mod; n       for (; i >= 1; i--) res = ((res - f(ba, a[i])) % mod + mod) % mod; n       printf( %d n , res); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char grid[101][101]; n bool rw[101], cl[101]; n int main() { n   bool f, r = 0, c = 0; n   int cnt; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %s , grid[i]); n     f = 1; n     for (int j = 0; j < n; ++j) { n       f &= (grid[i][j] ==  E ); n       if (grid[i][j] ==  . ) rw[i] = cl[j] = 1; n     } n     c |= f; n   } n   for (int j = 0; j < n; ++j) { n     f = 1; n     for (int i = 0; i < n; ++i) { n       f &= (grid[i][j] ==  E ); n     } n     r |= f; n   } n   if (r && c) { n     printf( -1 n ); n   } else { n     cnt = 0; n     for (int i = 0; i < n; ++i) cnt += rw[i]; n     if (cnt == n) { n       for (int i = 0; i < n; ++i) { n         for (int j = 0; j < n; ++j) { n           if (grid[i][j] ==  . ) { n             printf( %d %d n , i + 1, j + 1); n             break; n           } n         } n       } n     } else { n       for (int j = 0; j < n; ++j) { n         for (int i = 0; i < n; ++i) { n           if (grid[i][j] ==  . ) { n             printf( %d %d n , i + 1, j + 1); n             break; n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, k, a[4] = {2, 3, 4, 5}, x, min = 250; n   scanf( %d %d , &n, &k); n   if (n * 5 == k || n * 3 == k || n * 4 == k) { n     printf( 0 ); n     return 0; n   } n   for (int i = n; i >= 0; i--) { n     x = i * 5; n     if (x > k) continue; n     for (int j = n; j >= 0; j--) { n       x = i * 5 + j * 4; n       if (x > k) continue; n       for (int z = n; z >= 0; z--) { n         x = i * 5 + j * 4 + z * 3; n         if (x > k) continue; n         for (int l = 0; l <= n; l++) { n           x = i * 5 + j * 4 + z * 3 + l * 2; n           if (x > k) break; n           if (x == k && l < min && (i + j + z + l == n)) min = l; n         } n       } n     } n   } n   printf( %d , min); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(vector<vector<int>> &a, int n, int x) { n   deque<pair<int, int>> q; n   map<pair<int, int>, bool> was; n   q.push_back({1, 1}); n   was[{1, 1}] = true; n   int dx[] = {1, 0, -1, 0}; n   int dy[] = {0, 1, 0, -1}; n   while (!q.empty()) { n     auto u = q.front(); n     q.pop_front(); n     for (int i = 0; i < 4; i++) { n       int xx = u.first + dx[i]; n       int yy = u.second + dy[i]; n       if (xx == n && yy == n) return false; n       if (a[xx][yy] == x && !was[{xx, yy}]) { n         q.push_back({xx, yy}); n         was[{xx, yy}] = true; n       } n     } n   } n   return true; n } n void v(vector<vector<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 void solve() { n   vector<vector<int>> a; n   int n; n   cin >> n; n   a = vector<vector<int>>(n + 2, vector<int>(n + 2, 2)); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       char x; n       cin >> x; n       if (x !=  S  && x !=  F ) { n         a[i][j] = x -  0 ; n       } n     } n   } n   vector<pair<int, int>> c = { n       {n - 1, n - 1}, {n - 1, n}, {n, n - 1}, {n - 2, n}, {n, n - 2}}; n   if (check(a, n, 1) && check(a, n, 0)) { n     cout << 0 << endl; n     return; n   } n   for (int i = 0; i < c.size(); i++) { n     a[c[i].first][c[i].second] = 1 - a[c[i].first][c[i].second]; n     if (check(a, n, 1) && check(a, n, 0)) { n       cout << 1 <<   n ; n       cout << c[i].first <<     << c[i].second << endl; n       return; n     } n     a[c[i].first][c[i].second] = 1 - a[c[i].first][c[i].second]; n   } n   for (int i = 0; i < c.size(); i++) { n     for (int j = i + 1; j < c.size(); j++) { n       a[c[i].first][c[i].second] = 1 - a[c[i].first][c[i].second]; n       a[c[j].first][c[j].second] = 1 - a[c[j].first][c[j].second]; n       if (check(a, n, 1) && check(a, n, 0)) { n         cout << 2 <<   n ; n         cout << c[i].first <<     << c[i].second << endl; n         cout << c[j].first <<     << c[j].second << endl; n         return; n       } n       a[c[i].first][c[i].second] = 1 - a[c[i].first][c[i].second]; n       a[c[j].first][c[j].second] = 1 - a[c[j].first][c[j].second]; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t = 1; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long t[5005], c[5005], ans[5005], n, i, l, b, v; n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) cin >> t[i]; n   for (l = 1; l <= n; l++) { n     for (i = 1; i <= n; i++) c[i] = 0; n     b = 0; n     for (i = l; i <= n; i++) { n       v = t[i]; n       c[v]++; n       if (c[v] > c[b] || (c[v] == c[b] && v < b)) b = v; n       ans[b]++; n     } n   } n   for (i = 1; i <= n - 1; i++) cout << ans[i] <<    ; n   cout << ans[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int l, r, a, n; n   scanf( %d %d %d , &l, &r, &a); n   if (l > r) { n     if (r + a < l) { n       printf( %d n , 2 * (r + a)); n     } else { n       n = r + a - l; n       printf( %d n , 2 * (l + n / 2)); n     } n   } else { n     if (l + a < r) { n       printf( %d n , 2 * (l + a)); n     } else { n       n = l + a - r; n       printf( %d n , 2 * (r + n / 2)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n pair<int, int> bug[N]; n pair<int, pair<int, int> > stud[N]; n set<pair<int, int> > smart; n int ans[N]; n int studs, bugs, exams; n long long solve(int days) { n   long long sum = 0; n   smart.clear(); n   int last = 0; n   for (int i = 0; i < bugs; i += days) { n     while (last < studs && stud[last].first >= bug[i].first) { n       smart.insert(stud[last].second); n       last++; n     } n     if (smart.empty()) { n       return (long long)1e18; n     } n     pair<int, int> t = *(smart.begin()); n     smart.erase(smart.begin()); n     sum += t.first; n     for (int j = i; j < bugs && j < i + days; j++) { n       ans[bug[j].second] = t.second; n     } n   } n   return sum; n } n int main() { n   scanf( %d%d%d , &studs, &bugs, &exams); n   for (int i = 0; i < bugs; i++) { n     scanf( %d , &(bug[i].first)); n     bug[i].second = i; n   } n   for (int i = 0; i < studs; i++) { n     scanf( %d , &(stud[i].first)); n   } n   for (int i = 0; i < studs; i++) { n     scanf( %d , &(stud[i].second.first)); n     stud[i].second.second = i; n   } n   sort(bug, bug + bugs); n   reverse(bug, bug + bugs); n   sort(stud, stud + studs); n   reverse(stud, stud + studs); n   int ll = 1, rr = bugs + 1; n   while (ll < rr) { n     int mid = (ll + rr) >> 1; n     if (solve(mid) <= exams) n       rr = mid; n     else n       ll = mid + 1; n   } n   if (ll > bugs) { n     cout <<  NO n ; n     return 0; n   } n   solve(ll); n   printf( YES n ); n   for (int i = 0; i < bugs; i++) { n     printf( %d  , ans[i] + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, b, mn = 1e12; n   cin >> a >> b; n   int n; n   cin >> n; n   while (n--) { n     double x, y, v, dis; n     cin >> x >> y >> v; n     dis = sqrt((a - x) * (a - x) + (b - y) * (b - y)); n     dis /= v; n     mn = min(mn, dis); n   } n   cout << fixed << setprecision(7) << mn << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int to, id; n }; n vector<node> E[10005]; n vector<int> Ans; n int dep[10005], fa[10005][15], Id[10005], S1[10005], S0[10005], Stk[10005], cnt, n     n1, n, m; n bool mk[10005], Mk[10005]; n void dfs(int x, int f) { n   mk[x] = 1; n   dep[x] = dep[f] + 1, fa[x][0] = f; n   for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) { n     int y = E[x][i].to; n     if (!mk[y]) { n       Stk[++cnt] = y; n       Id[y] = E[x][i].id; n       dfs(y, x); n     } n   } n } n int LCA(int x, int y) { n   if (dep[x] > dep[y]) swap(x, y); n   int d = dep[y] - dep[x]; n   for (int i = (0), i_ = (13); i <= i_; i++) n     if (d & (1 << i)) y = fa[y][i]; n   for (int i = (13), i_ = (0); i >= i_; i--) n     if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i]; n   return x == y ? x : fa[x][0]; n } n void Init() { n   for (int j = (1), j_ = (13); j <= j_; j++) n     for (int i = (1), i_ = (cnt); i <= i_; i++) n       fa[Stk[i]][j] = fa[fa[Stk[i]][j - 1]][j - 1]; n } n void Dfs(int x) { n   for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) { n     int y = E[x][i].to; n     if (Id[y] == E[x][i].id) n       Dfs(y); n     else if (dep[y] < dep[x] && y != fa[x][0]) { n       if ((dep[x] & 1) == (dep[y] & 1)) { n         n1++; n         S1[x]++, S1[y]++, S1[LCA(x, y)] -= 2; n         Mk[E[x][i].id] = 1; n       } else n         S0[x]++, S0[y]++, S0[LCA(x, y)] -= 2; n     } n   } n } n void DFS(int x) { n   for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) { n     int y = E[x][i].to; n     if (Id[y] == E[x][i].id) { n       DFS(y); n       S0[x] += S0[y], S1[x] += S1[y]; n     } n   } n } n void Deal() { n   if (!n1) { n     for (int i = (1), i_ = (m); i <= i_; i++) Ans.push_back(i); n     return; n   } n   for (int i = (1), i_ = (n); i <= i_; i++) n     if (S1[i] == n1 && !S0[i]) Ans.push_back(Id[i]); n   if (n1 == 1) n     for (int i = (1), i_ = (m); i <= i_; i++) n       if (Mk[i]) Ans.push_back(i); n } n int main() { n   int a, b; n   scanf( %d%d , &n, &m); n   for (int i = (1), i_ = (m); i <= i_; i++) { n     scanf( %d%d , &a, &b); n     E[a].push_back((node){b, i}); n     E[b].push_back((node){a, i}); n   } n   for (int i = (1), i_ = (n); i <= i_; i++) n     if (!mk[i]) cnt = 0, dfs(i, 0), Init(), Dfs(i), DFS(i); n   Deal(); n   printf( %d n , Ans.size()); n   sort(Ans.begin(), Ans.end()); n   for (int i = (0), i_ = (Ans.size() - 1); i <= i_; i++) printf( %d  , Ans[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const int N = 1e6 + 5; n int f[N]; n int a[] = {1, 2}; n int na = 2; n int main() { n   int cnt; n   cin >> cnt; n   if (cnt == 1) { n     cout <<  1 1 n1 ; n     return 0; n   } n   int x = 1; n   for (int i = 2; i < N; i++) { n     if (i % 2 == 0) x++; n     if (x == cnt) { n       cout << i <<   2 n1 2 ; n       return 0; n     } n   } n   return 0; n } n


#include <cstdio> n #include <cmath> n long long T, n; n bool flag; n int main() n { n  scanf( %d , &T); n  for(int t = 1; t <= T; t ++) n  { n   scanf( %lld , &n); n   flag = false; n   for(long long i = 2; i <= n; i *= 2) n   { n    if(n == i)  n    { n     printf( NO n ); n     flag = true; n     break; n    } n   } n   if(!flag) printf( YES n ); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3020; n long long a[maxn], b[maxn]; n long long dp1[maxn][maxn]; n int n; n bool cmp(int x, int y) { return x > y; } n int main() { n   while (cin >> n) { n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) { n       a[i] -= i; n       b[i] = a[i]; n     } n     sort(b, b + n); n     memset(dp1, 0, sizeof(dp1)); n     for (int i = 0; i < n; i++) { n       long long minx = dp1[i][0]; n       for (int j = 0; j < n; j++) { n         minx = min(minx, dp1[i][j]); n         dp1[i + 1][j] = minx + abs(a[i] - b[j]); n       } n     } n     long long min_up = dp1[n][0]; n     for (int i = 1; i < n; i++) { n       min_up = min(min_up, dp1[n][i]); n     } n     cout << min_up << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2,unroll-loops ) n using namespace std; n const int inf = 1000000010; n const long long INF = 1000000000000001000LL; n const int mod = 1000000007; n const int MAXN = 100200, SQ = 320, NSQ = MAXN / SQ + 1; n int n, m, w, u, v, x, y, t, a, b, maxb; n int A[MAXN], B[MAXN], ans[MAXN], lazy[NSQ]; n pair<long long, long long> X[MAXN]; n vector<int> vec[MAXN]; n struct CHT { n   pair<long long, int> cht[SQ]; n   int L, R; n   inline long long Inter(pair<long long, long long> x, n                          pair<long long, long long> y) { n     if (x.first == y.first) return (x <= y ? -INF : INF); n     return (x.second - y.second) / (y.first - x.first) + n            ((x.second - y.second) % (y.first - x.first) > 0); n   } n   inline void Add(int a) { n     while (R && Inter(X[cht[R - 1].second], X[a]) <= cht[R - 1].first) R--; n     if (!R) n       cht[R++] = {-INF, a}; n     else n       cht[R] = {Inter(X[cht[R - 1].second], X[a]), a}, R++; n   } n   inline pair<long long, long long> Get(long long x) { n     while (L + 1 < R && cht[L + 1].first <= x) L++; n     int i = cht[L].second; n     return {X[i].first * x + X[i].second, i}; n   } n } cht[NSQ]; n void Build(int id) { n   int tl = id * SQ, tr = min(MAXN, tl + SQ); n   cht[id].L = cht[id].R = 0; n   for (int i = tl; i < tr; i++) { n     X[i].second += lazy[id] * X[i].first; n     cht[id].Add(i); n   } n   lazy[id] = 0; n } n void Add(int l, int r, int val) { n   int idl = -1, idr = -1; n   while (l < r && l % SQ) idl = l / SQ, X[l].second += val * l, l++; n   while (l < r && r % SQ) idr = r / SQ, r--, X[r].second += val * r; n   while (l < r) lazy[l / SQ] += val, l += SQ; n   if (idl != -1) Build(idl); n   if (idr != -1) Build(idr); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> w; n   for (int i = 1; i <= n; i++) { n     cin >> A[i] >> B[i]; n     vec[B[i]].push_back(i); n     maxb = max(maxb, B[i]); n   } n   for (int i = 0; i < MAXN; i++) X[i].first = i; n   for (int i = 0; i * SQ < MAXN; i++) Build(i); n   int ted = n; n   for (int i = 0; i <= maxb + 1; i++) { n     pair<long long, long long> p = {-inf, -1}; n     for (int j = 0; j * SQ + SQ <= MAXN; j++) p = max(p, cht[j].Get(lazy[j])); n     cout << p.first + 1ll * ted * i * w <<     << p.second <<   n ; n     for (int j : vec[i]) Add(0, A[j] + 1, +1), ted--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n long long mod = 1000000007; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void init() {} n void solve() { n   long long x, y, n, i, j; n   cin >> n; n   vector<pair<long long, long long> > adj(n - 1); n   vector<long long> deg(n + 1, 0); n   for (i = 0; i < n - 1; i++) { n     cin >> x >> y; n     deg[x]++; n     deg[y]++; n     adj[i] = {x, y}; n   } n   vector<long long> edge; n   for (i = 0; i < n + 1; i++) { n     if (deg[i] == 1) { n       edge.push_back(i); n     } n   } n   if ((int)edge.size() == 2) { n     for (i = 0; i < n - 1; i++) { n       cout << i << endl; n     } n   } else { n     long long ep = 0, elp = 3; n     for (i = 0; i < n - 1; i++) { n       bool flag = false; n       for (j = 0; j < 3; j++) { n         if (edge[j] == adj[i].first or edge[j] == adj[i].second) { n           flag = true; n         } n       } n       if (flag) { n         cout << ep << endl; n         ep++; n       } else { n         cout << elp << endl; n         elp++; n       } n     } n   } n } n int main() { n   init(); n   auto start = high_resolution_clock::now(); n   int T = 1; n   while (T--) { n     solve(); n   } n   auto stop = high_resolution_clock::now(); n   auto duration = duration_cast<milliseconds>(stop - start); n } n


#include <bits/stdc++.h> n #define int long long n #define f(i,a,n) for (int i = a; i < n; ++i) n #define f1(i,a,n) for(int i=n-1;i>=a;i--) n #define ff first n #define ss second n #define pb push_back n #define mp make_pair n #define all(x) x.begin(), x.end() n #define sortall(x) sort(all(x)) n #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL); n #define w1 solve(); n #define mod (int)(1e9 + 7) n #define prq priority_queue n #define gcd __gcd n #define sz(x) (int)x.size() n #define w(t) int t; cin>>t; while (t--) { solve(); } n #define N 1000001 n  n using namespace std; n  n void __print(int x) {cerr << x;} n void __print(float x) {cerr << x;} n void __print(double x) {cerr << x;} n void __print(long double x) {cerr << x;} n void __print(char x) {cerr <<      << x <<     ;} n void __print(const char *x) {cerr <<     << x <<    ;} n void __print(const string &x) {cerr <<     << x <<    ;} n void __print(bool x) {cerr << (x ?  true  :  false );} n  n template<typename T, typename V> n void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;} n template<typename T> n void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;} n void _print() {cerr <<  ] n ;} n template <typename T, typename... V> n void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);} n  n #ifdef Avash_Local_Machine n #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x) n #else n #define debug(x...) n #endif n  n typedef vector<int> vi; n typedef pair<int, int> pii; n typedef vector<pii> vpi; n typedef vector<string> vs; n typedef vector<char> vc; n  n const int INF = (int)(1e17); n const double PI = 3.141592653589793; n  n int dx[4] = { -1, 0, 1, 0}; n int dy[4] = {0, 1, 0, -1}; n string path =  URDL ; n  n  n void solve() n { n  int q; n  cin >> q; n  char c; int n , id = 1; n  set<pii> set1, set2; n  //set1 for price,id n  //set2 for id,price n  while (q--) n  { n   cin >> c; n   if (c ==  1 ) n   { n    cin >> n; n    set1.insert(mp(n, id)); n    set2.insert(mp(id, n)); n    ++id; n   } n   if (c ==  2 ) n   { n    auto it = *set2.begin(); n    cout << it.ff <<   n ; n    auto ind = set1.lower_bound(mp(it.ss, it.ff)); n    set1.erase(ind); n    set2.erase(set2.begin()); n   } n   if (c ==  3 ) n   { n    auto it = *set1.rbegin(); n    // debug(it); n    auto ind = set1.lower_bound(mp(it.ff, -INF)); n    // debug(ind); n    cout << (*ind).ss <<   n ; n    auto ind1 = set2.lower_bound(mp((*ind).ss, (*ind).ff)); n    // debug(*ind1); n    set2.erase(ind1); n    set1.erase(ind); n    // debug(set2); n   } n  } n } n  n int32_t main() n { n  n  fastio n  w1 n  // w(t) n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int tt; n int n, m; n int main() { n   scanf( %d , &tt); n   while (tt--) { n     scanf( %d %d , &n, &m); n     long long z = (n - m), g = m + 1; n     long long k = z / g; n     long long ans = n         (n * 1ll * (n + 1) / 2) - (k * (k + 1) / 2) * g - (k + 1) * (z % g); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, F[500007], wartosc[500007], Fat[500007]; n bool valid_number[500007], valid_edges[300007], query_node[500007]; n int Find(int a) { return (a == Fat[a] ? a : Fat[a] = Find(Fat[a])); } n inline void Union(int a, int b) { n   a = Find(a); n   b = Find(b); n   F[a] = F[b] = ++n; n   Fat[a] = Fat[b] = F[n] = Fat[n] = n; n } n vector<int> G[500007]; n int pre[500007], pos[500007], order[500007], nr; n bool visited[500007]; n void DFS(int v) { n   visited[v] = 1; n   pre[v] = ++nr; n   order[nr] = v; n   for (auto i : G[v]) n     if (!visited[i]) DFS(i); n   pos[v] = nr; n } n int tree[1 << 20], M = 1; n inline void zrob_drzewa() { n   for (int i = 1; i <= n; i++) n     if (F[i] != i) { n       G[i].push_back(F[i]); n       G[F[i]].push_back(i); n     } n   for (int i = 1; i <= n; i++) n     if (F[i] == i) DFS(i); n   while (M < n) M *= 2; n   for (int i = 1; i <= n; i++) tree[i + M - 1] = wartosc[order[i]]; n   for (int i = M - 1; i > 0; i--) tree[i] = max(tree[i * 2], tree[i * 2 + 1]); n } n void remove_invalid(int v) { n   if (valid_number[tree[v]]) return; n   tree[v] = 0; n   if (v >= M) return; n   remove_invalid(v * 2); n   remove_invalid(v * 2 + 1); n   tree[v] = max(tree[v * 2], tree[v * 2 + 1]); n } n int maks(int a, int b, int v = 1, int p = 1, int k = M) { n   if (p > b || k < a) return 0; n   if (p >= a && k <= b) { n     remove_invalid(v); n     return tree[v]; n   } n   return max(maks(a, b, v * 2, p, (p + k) / 2), n              maks(a, b, v * 2 + 1, (p + k) / 2 + 1, k)); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int m, q; n   cin >> n >> m >> q; n   n = n; n   for (int i = 1, a; i <= n; i++) { n     cin >> wartosc[i]; n     valid_number[wartosc[i]] = true; n     F[i] = i; n     Fat[i] = i; n   } n   vector<pair<int, int>> edges(m + 1); n   for (int i = 1; i <= m; i++) { n     cin >> edges[i].first >> edges[i].second; n     valid_edges[i] = true; n   } n   vector<pair<int, int>> queries(q); n   for (int i = 0; i < q; i++) { n     cin >> queries[i].first >> queries[i].second; n     if (queries[i].first == 2) valid_edges[queries[i].second] = false; n   } n   for (int i = 1; i <= m; i++) n     if (valid_edges[i]) Union(edges[i].first, edges[i].second); n   int Res[q]; n   for (int i = q - 1; i >= 0; i--) { n     if (queries[i].first == 1) { n       int v = queries[i].second; n       v = Find(v); n       Res[i] = v; n     } else { n       int j = queries[i].second; n       int a = edges[j].first, b = edges[j].second; n       Union(a, b); n     } n   } n   zrob_drzewa(); n   for (int i = 0; i < q; i++) { n     if (queries[i].first == 2) continue; n     int v = Res[i]; n     int res = maks(pre[v], pos[v]); n     cout << res <<   n ; n     valid_number[res] = false; n     valid_number[0] = true; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[200005]; n int main() { n   int t, k, i, j, n, m, x, y, q, c; n   cin >> n >> k; n   if ((n - 1) % k >= 2) { n     printf( %d n , 2 * ((n - 1) / k) + 2); n   } else if ((n - 1) % k == 1) { n     printf( %d n , 2 * ((n - 1) / k) + 1); n   } else { n     printf( %d n , 2 * ((n - 1) / k)); n   } n   for (i = 0; i < k; i++) a[i] = 1; n   for (i = 2; i <= n; i++) { n     j = (i - 2) % k; n     printf( %d %d n , i, a[j]); n     a[j] = i; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, Y[50001]; n set<int> pos[50001]; n set<int> used; n priority_queue<int> q; n int next(int x) { n   int temp = x; n   while (x != 0) { n     if (used.count(x) == 0) return x; n     x /= 2; n   } n   return temp; n } n int main() { n   cin >> N; n   for (int i = 0; i < N; i++) { n     cin >> Y[i]; n     used.insert(Y[i]); n     q.push(Y[i]); n   } n   for (;;) { n     int num = next(q.top()); n     if (q.top() == num) break; n     used.erase(num); n     used.insert(num); n     q.pop(); n     q.push(num); n   } n   while (!q.empty()) { n     cout << q.top() <<    ; n     q.pop(); n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 3; n int a[maxn], b[maxn], c[maxn], sum; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   int ans = 0, cnt = 0; n   for (int i = 1; i <= n; i++) { n     ans += a[i]; n     cnt -= a[i]; n     b[i] = max(max(cnt, ans), b[i - 1] + a[i]); n   } n   ans = 0, cnt = 0; n   for (int i = n; i > 0; i--) { n     ans += a[i]; n     cnt -= a[i]; n     c[i] = max(max(cnt, ans), c[i + 1] + a[i]); n   } n   int mx = 0; n   for (int i = 0; i <= n; i++) mx = max(c[i + 1] + b[i], mx); n   cout << mx; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, l, r, c, pl, pr, cl, cr; n   cin >> a >> b >> l >> r; n   c = a + b; n   cl = --l / c; n   cr = --r / c; n   pl = l % c; n   pr = r % c; n   if (cl == cr) { n     if (pl < a && pr < a) { n       cout << pr - pl + 1 << endl; n     } else if (pl < a && pr >= a) { n       cout << a - pl << endl; n     } else { n       cout << 1 << endl; n     } n   } else if (a <= b) { n     if (cl < cr - 1) { n       cout << a + 1 << endl; n     } else { n       if (pr >= a) { n         cout << a + 1 << endl; n       } else { n         if (pl >= a) { n           cout << pr + 1 + 1 << endl; n         } else { n           int left = a - pl; n           int right = pr + 1; n           if (left + right > a) { n             cout << a + (right == a) << endl; n           } else { n             cout << left + right + (right == a) << endl; n           } n         } n       } n     } n   } else { n     int d = a - b; n     if (cl == cr - 1) { n       if (pr >= a && pl >= a) { n         cout << a + 1 << endl; n       } else if (pr < a && pl >= a) { n         cout << pr + 1 + 1 << endl; n       } else if (pr >= a && pl < a) { n         cout << min((a + a - pl), a + a - b) << endl; n       } else if (pr < a && pl < a) { n         if (pl > b) { n           cout << pr + 1 + a - pl << endl; n         } else { n           cout << pr + 1 + a - b << endl; n         } n       } n     } else if (cl == cr - 2) { n       if (pr >= a && pl >= a) { n         cout << a + a - b << endl; n       } else if (pr >= a && pl < a) { n         cout << a + a - b << endl; n       } else if (pr < a && pl < a) { n         cout << min((a + pr + 1 + a - pl + 1), a + a - b) << endl; n       } else { n         cout << a + max(1, d + min(0, pr - a + 1 + max(0, a - pl))); n       } n     } else { n       cout << a + d << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int x, int y) { return (!y ? x : gcd(y, x % y)); } n const int maxn = 2e5; n vector<int> g[maxn], tree[maxn]; n map<pair<int, int>, int> we; n int par[maxn]; n int gpar(int v) { return (par[v] == v ? v : par[v] = gpar(par[v])); } n bool mrg(int u, int v) { n   u = gpar(u); n   v = gpar(v); n   if (u == v) return false; n   par[v] = u; n   return true; n } n int h[maxn]; n void dfs(int v, int p) { n   for (auto u : tree[v]) { n     if (u == p) continue; n     par[u] = v; n     h[u] = h[v] + 1; n     dfs(u, v); n   } n } n vector<int> get_path(int u, int v) { n   if (h[u] < h[v]) swap(u, v); n   vector<int> p, rig; n   while (h[u] > h[v]) { n     p.push_back(u); n     u = par[u]; n   } n   while (u != v) { n     p.push_back(u); n     rig.push_back(v); n     u = par[u], v = par[v]; n   } n   p.push_back(u); n   reverse(rig.begin(), rig.end()); n   for (auto i : rig) p.push_back(i); n   return p; n } n const int maxb = 18; n int mods[2] = {int(1e9 + 7), int(1e9 + 9)}; n int mod; n const int N = (1 << maxb); n int bpw(int a, int b) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = 1LL * ans * a % mod; n     a = 1LL * a * a % mod; n     b >>= 1; n   } n   return ans; n } n void fwht(int* a, int val) { n   for (int len = 2; len <= N; len *= 2) n     for (int i = 0; i < N; i += len) { n       int nxt = len / 2; n       for (int j = 0; j < nxt; j++) { n         int x = a[i + j], y = a[i + j + nxt]; n         a[i + j] = (x + y) % mod; n         a[i + j + nxt] = (x - y + mod) % mod; n       } n     } n   if (val == -1) { n     int inv = bpw(N, mod - 2); n     for (int i = 0; i < N; i++) a[i] = 1LL * a[i] * inv % mod; n   } n } n int ans[2][N], cnt[N]; n int32_t main() { n   ios::sync_with_stdio(0), cin.tie(0); n   int n, m; n   cin >> n >> m; n   int tot = 0; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     u--, v--; n     g[u].push_back(v); n     g[v].push_back(u); n     we[{u, v}] = we[{v, u}] = w; n     tot ^= w; n   } n   for (int i = 0; i < n; i++) par[i] = i; n   vector<pair<int, int> > bads; n   for (int i = 0; i < n; i++) { n     for (auto j : g[i]) { n       if (mrg(i, j)) { n         tree[i].push_back(j); n         tree[j].push_back(i); n       } else if (i < j) n         bads.push_back({i, j}); n     } n   } n   if (bads.size() == 0) { n     cout << tot <<     << 1 <<   n ; n     return 0; n   } n   dfs(0, 0); n   for (int it = 0; it < 2; it++) { n     mod = mods[it]; n     for (int i = 0; i < N; i++) ans[it][i] = 1; n     for (auto t : bads) { n       vector<int> p = get_path(t.first, t.second); n       p.push_back(p[0]); n       memset(cnt, 0, sizeof cnt); n       for (int i = 0; i + 1 < p.size(); i++) { n         int w = we[{p[i], p[i + 1]}]; n         cnt[w]++; n       } n       fwht(cnt, 1); n       for (int i = 0; i < N; i++) ans[it][i] = 1LL * ans[it][i] * cnt[i] % mod; n     } n     fwht(ans[it], -1); n   } n   int jav = 1e9, who = -1; n   for (int i = 0; i < N; i++) n     if (ans[0][i] || ans[1][i]) { n       if ((i ^ tot) < jav) { n         jav = i ^ tot; n         who = i; n       } n     } n   assert(who != -1); n   cout << jav <<     << ans[0][who] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long bbuy(long long* c, long long l, int n); n int main() { n   long long n, l; n   cin >> n >> l; n   long long c[n]; n   for (int i = 0; i < n; ++i) { n     cin >> c[i]; n   } n   long long bp = c[0]; n   for (int i = 0; i < n; ++i) { n     bp *= 2; n     bp = min(bp, c[i]); n     if (bp != c[i]) c[i] = -1; n   } n   long long bcost = 0; n   bcost += bbuy(c, l, n); n   cout << bcost; n   return 0; n } n long long bbuy(long long* c, long long l, int n) { n   int i = int(log2(l)); n   long long gcost = 0; n   long long cost = 0, buy; n   long long prev = l; n   while (i >= n || c[i] == -1) i--; n   buy = l / pow(2, i); n   l -= buy * pow(2, i); n   cost = buy * c[i]; n   if (l > 0) cost += bbuy(c, l, n); n   for (int j = i + 1; j < n; ++j) { n     l = prev; n     if (c[j] == -1) continue; n     buy = (l / pow(2, j)) + 1; n     if (cost > buy * c[j]) { n       cost = buy * c[j]; n       l -= buy * pow(2, j); n     } n   } n   gcost += cost; n   return gcost; n } n


#include <bits/stdc++.h> n using namespace std; n namespace std { n template <> n struct hash<pair<int, int>> { n   size_t operator()(const pair<int, int> &x) const { n     long long P = 38923, Q = 109797901; n     return (size_t)((x.first * P + x.second) % Q); n   } n }; n };  // namespace std n template <class T> n using pqg = priority_queue<T, vector<T>, greater<T>>; n template <typename T> n void print(T t) { n   cout << t << endl; n } n template <typename T, typename... Args> n void print(T t, Args... args) { n   cout << t <<    ; n   print(args...); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long x, y, z; n   cin >> x >> y >> z; n   if (x > y + z) n     print( + ); n   else if (y > x + z) n     print( - ); n   else if (x == y && z == 0) n     print( 0 ); n   else n     print( ? ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T qmin(const T a, const T b) { n   return a < b ? a : b; n } n template <typename T> n inline T qmax(const T a, const T b) { n   return a > b ? a : b; n } n template <typename T> n inline void getmin(T &a, const T b) { n   if (a > b) a = b; n } n template <typename T> n inline void getmax(T &a, const T b) { n   if (a < b) a = b; n } n inline void fileio(string s) { n   freopen((s +  .in ).c_str(),  r , stdin); n   freopen((s +  .out ).c_str(),  w , stdout); n } n const int inf = 1e9; n const long long linf = 1e17 + 7; n const int N = 2e5 + 7; n struct seg { n   int h, l, r; n   seg() {} n   seg(int _h, int _l, int _r) : h(_h), l(_l), r(_r) {} n   bool operator<(const seg &b) const { return h < b.h; } n } a[N]; n struct node { n   int l, r, v; n   seg s; n   node() {} n   node(int _l, int _r, int _v, seg _s) : l(_l), r(_r), v(_v), s(_s) {} n   bool operator<(const node &b) const { return l < b.l; } n }; n inline int overlap(int l1, int r1, int l2, int r2) { n   return qmax(0, qmin(r1, r2) - qmax(l1, l2)); n } n inline bool canget(const seg &a, set<node>::iterator it) { n   set<node>::iterator ul = it, ur = it; n   --ul; n   ++ur; n   seg pre = ul->s, nxt = ur->s, cur = it->s; n   if (pre.h < a.h && pre.h > cur.h && overlap(a.l, a.r, pre.l, pre.r) && n       overlap(pre.l, pre.r, cur.l, cur.r)) n     return false; n   if (nxt.h < a.h && nxt.h > cur.h && overlap(a.l, a.r, nxt.l, nxt.r) && n       overlap(nxt.l, nxt.r, cur.l, cur.r)) n     return false; n   return true; n } n set<node> s; n int n, t; n int main() { n   scanf( %d%d , &n, &t); n   for (int i = 1; i <= n; ++i) scanf( %d%d%d , &a[i].h, &a[i].l, &a[i].r); n   a[++n] = seg(t, -inf, inf); n   sort(a + 1, a + n + 1); n   node bot(-inf, inf, inf << 1, seg(0, -inf, inf)); n   node left(-inf - 1, -inf, 0, seg()); n   node right(inf, inf + 1, 0, seg()); n   s.insert(bot); n   s.insert(left); n   s.insert(right); n   for (int i = 1; i <= n; ++i) { n     set<node>::iterator ul = s.upper_bound(node(a[i].l, a[i].r, 0, seg())), ur; n     int ans = 0; n     for (--ul; ul->r <= a[i].l; ++ul) n       ; n     for (ur = ul; ur->l < a[i].r; ++ur) { n       if (!canget(a[i], ur)) continue; n       getmax(ans, qmin(overlap(a[i].l, a[i].r, ur->l, ur->r), ur->v)); n     } n     --ur; n     int l = ul->l, r = ur->r, v1 = ul->v, v2 = ur->v; n     seg s1 = ul->s, s2 = ur->s; n     ++ur; n     s.erase(ul, ur); n     s.insert(node(a[i].l, a[i].r, ans, a[i])); n     if (l < a[i].l) s.insert(node(l, a[i].l, v1, s1)); n     if (r > a[i].r) s.insert(node(a[i].r, r, v2, s2)); n   } n   set<node>::iterator ite = s.begin(); n   ++ite; n   printf( %d n , ite->v); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000000000 ) n using namespace std; n const long long int INF = 2e9; n void init(vector<int> &dsu) { n   for (int i = 0; i < ((int)(dsu).size()); i++) { n     dsu[i] = i; n   } n } n int find_p(vector<int> &dsu, int id) { n   if (dsu[id] == id) return id; n   return dsu[id] = find_p(dsu, dsu[id]); n } n bool unite(vector<int> &dsu, int f, int s) { n   f = find_p(dsu, f); n   s = find_p(dsu, s); n   if (f == s) return true; n   dsu[f] = s; n   return false; n } n inline bool in(long double f, long double s, long double d) { n   return s >= f && s <= d; n } n bool intr(pair<long double, long double> f, pair<long double, long double> s, n           long double time) { n   if (time == INF) return true; n   long double a1 = -1, b1 = -1, c1 = -(a1 * f.first + b1 * f.second); n   long double a2 = 1, b2 = -1, c2 = -(a2 * s.first + b2 * s.second); n   long double x = (b1 * c2 - b2 * c1) / (a1 * b2 - b1 * a2), n               y = (c1 * a2 - a1 * c2) / (a1 * b2 - b1 * a2); n   return in(f.first - time, x, f.first + time) && n          in(f.second - time, y, f.second + time) && n          in(s.first - time, x, s.first + time) && n          in(s.second - time, y, s.second + time); n } n bool ini(long double f, long double s, long double time) { n   return (f - s) <= time * 2; n } n bool intr2(pair<long double, long double> f, pair<long double, long double> s, n            int q, long double time) { n   if (!q && !(f.first + f.second == s.first + s.second)) return false; n   if (q && !(f.first - f.second == s.first - s.second)) return false; n   if (time == INF) return true; n   long double x = min(f.first, s.first), x2 = max(f.first, s.first); n   long double y = min(f.second, s.second), y2 = max(f.second, s.second); n   return ini(x, x2, time) && ini(y, y2, time); n } n bool can(vector<pair<long double, long double> > p1, n          vector<pair<long double, long double> > p2, long long int time) { n   int n = (int)(p1).size(), m = (int)(p2).size(); n   for (int q = 0; q < (2); q++) { n     vector<int> with(n, -1); n     vector<int> dsu(m); n     init(dsu); n     for (int i = 0; i < (n); i++) { n       for (int j = 0; j < (m); j++) { n         if (intr(!q ? p1[i] : p2[j], !q ? p2[j] : p1[i], time)) { n           if (with[i] == -1) n             with[i] = j; n           else { n             if (unite(dsu, j, with[i])) { n               return true; n             } n           } n         } n       } n       for (int j = 0; j < (i); j++) { n         if (i == j) continue; n         if (with[j] == -1 || with[i] == -1) continue; n         if (intr2(p1[i], p1[j], q, time)) { n           if (unite(dsu, with[i], with[j])) { n             return true; n           } n         } n       } n     } n     swap(n, m); n     swap(p1, p2); n   } n   return false; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<pair<long double, long double> > p1(n), p2(m); n   bool yes = false; n   for (int i = 0; i < (n); i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     p1[i] = make_pair(a, b); n     if (i && a + b != p1[i - 1].first + p1[i - 1].second) yes = true; n   } n   bool yes2 = false; n   for (int i = 0; i < (m); i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     p2[i] = make_pair(a, b); n     if (i && a - b != p2[i - 1].first - p2[i - 1].second) yes2 = true; n   } n   if ((!yes || !yes2) || !can(p1, p2, INF)) { n     cout <<  Poor Sereja! ; n     return 0; n   } n   long long int l = 0, r = INF; n   while (l != r) { n     long long int m = (l + r) / 2; n     if (can(p1, p2, m)) { n       r = m; n     } else n       l = m + 1; n   } n   cout << l; n } n


#include <bits/stdc++.h> n using namespace std; n template <class A, class B> n inline bool mina(A &first, B second) { n   return (first > second) ? (first = second, 1) : 0; n } n template <class A, class B> n inline bool maxa(A &first, B second) { n   return (first < second) ? (first = second, 1) : 0; n } n const int MAXN = 150005; n int N; n int in[MAXN]; n bool good(int a, int b) { n   swap(in[a], in[b]); n   bool bad = false; n   for (int(i) = 0; (i) < (N - 1); ++(i)) { n     if (i % 2 == 0) { n       if (in[i] >= in[i + 1]) { n         bad = true; n         break; n       } n     } else { n       if (in[i] <= in[i + 1]) { n         bad = true; n         break; n       } n     } n   } n   swap(in[a], in[b]); n   return !bad; n } n bool check2(int p) { n   if (p < 0 || p >= N) return true; n   if (p % 2 == 0) { n     if (p + 1 < N && in[p] >= in[p + 1]) return false; n     if (p - 1 >= 0 && in[p] >= in[p - 1]) return false; n   } else { n     if (p + 1 < N && in[p] <= in[p + 1]) return false; n     if (p - 1 >= 0 && in[p] <= in[p - 1]) return false; n   } n   return true; n } n bool check_local(int a, int b) { n   swap(in[a], in[b]); n   bool g1 = true; n   for (int i = -1; i <= 1; i++) { n     g1 &= check2(a + i); n     g1 &= check2(b + i); n   } n   swap(in[a], in[b]); n   return g1; n } n int main() { n   scanf( %d , &N); n   for (int(i) = 0; (i) < (N); ++(i)) { n     scanf( %d , &in[i]); n   } n   set<int> bad; n   int num_bad_local = 0; n   int xx = -1; n   for (int(i) = 0; (i) < (N - 1); ++(i)) { n     if (i % 2 == 0) { n       if (in[i] >= in[i + 1]) { n         bad.insert(i); n         bad.insert(i + 1); n         num_bad_local++; n         xx = i; n         i++; n       } n     } else { n       if (in[i] <= in[i + 1]) { n         bad.insert(i); n         bad.insert(i + 1); n         num_bad_local++; n         xx = i; n         i++; n       } n     } n   } n   if (((int)(bad).size()) > 10) { n     printf( 0 n ); n     return 0; n   } n   set<pair<int, int> > ans; n   for (int first : bad) { n     for (int second : bad) { n       if (first < second) { n         if (good(first, second)) { n           ans.insert(pair<int, int>(first, second)); n         } n       } n     } n   } n   if (num_bad_local == 1) { n     for (int(g) = 0; (g) < (N); ++(g)) { n       if (g != xx && g != xx + 1) { n         if (check_local(g, xx)) { n           int a = g; n           int b = xx; n           if (a > b) swap(a, b); n           ans.insert(pair<int, int>(a, b)); n         } n         if (check_local(g, xx + 1)) { n           int a = g; n           int b = xx + 1; n           if (a > b) swap(a, b); n           ans.insert(pair<int, int>(a, b)); n         } n       } n     } n   } n   cout << ((int)(ans).size()) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9 + 7; n const double pi = 3.14159265358979323846; n template <class T> n T sqr(T x) { n   return x * x; n } n double len(const pair<int, int> &p1, const pair<int, int> &p2) { n   return sqrt(sqr((long long)p1.first - p2.first) + n               sqr((long long)p1.second - p2.second)); n } n double foo(const vector<pair<int, int>> &pol, int l, int r, bool side) { n   static vector<vector<vector<double>>> dp( n       2, vector<vector<double>>(2500, vector<double>(2501, -1))); n   if (r <= l + 1) return 0; n   if (l > (int)pol.size() / 2) n     return foo(pol, l - (pol.size() + 1) / 2, r - (pol.size() + 1) / 2, side); n   if (dp[side][l][r - l] == -1) n     if (side) n       dp[side][l][r - l] = n           max(len(pol[r - 1], pol[l]) + foo(pol, l, r - 1, 0), n               len(pol[r - 1], pol[r - 2]) + foo(pol, l, r - 1, 1)); n     else n       dp[side][l][r - l] = max(len(pol[l], pol[l + 1]) + foo(pol, l + 1, r, 0), n                                len(pol[l], pol[r - 1]) + foo(pol, l + 1, r, 1)); n   return dp[side][l][r - l]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   vector<pair<int, int>> pol(n); n   for (auto &it : pol) cin >> it.first >> it.second; n   for (int i = 0; i < n - 1; i++) pol.push_back(pol[i]); n   double best = numeric_limits<double>::lowest(); n   for (int i = 0; i < n - 1; i++) n     best = max(best, max(foo(pol, i, i + n, 0), foo(pol, i, i + n, 1))); n   cout.precision(20); n   cout << fixed << best << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e5 + 4; n string s; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   ; n   cin >> s; n   long long n = s.size(); n   long long sub = 0; n   for (int k = 1; k <= 8; k++) { n     for (int i = 0; i + k <= n; i++) { n       bool flag = false; n       for (int j = 1; 2 * j < k; j++) { n         for (int st = i; st + 2 * j < i + k; st++) { n           if (s[st] == s[st + j] && s[st] == s[st + 2 * j]) { n             flag = true; n           } n         } n       } n       if (!flag) sub++; n     } n   } n   cout << n * (n + 1) / 2 - sub <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3E4 + 7; n int x[N], y[N]; n void solve() { n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   x[0] = a[0], y[0] = 0; n   for (int i = 1; i < n; i++) { n     x[i] = min(x[i - 1], a[i]), y[i] = a[i] - x[i]; n     if (y[i] >= y[i - 1]) continue; n     y[i] = y[i - 1], x[i] = a[i] - y[i]; n     if (x[i] < 0) { n       cout <<  NO n ; n       return; n     } n   } n   cout <<  YES n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200000 + 10; n struct Tree { n   int tl, tr; n   int mx; n } tree[maxn << 2]; n set<int> st[maxn]; n int ve[maxn], n, m; n void build(int id, int l, int r) { n   tree[id].tl = l; n   tree[id].tr = r; n   tree[id].mx = -1; n   if (l == r) return; n   int mid = (l + r) >> 1; n   build(id << 1, l, mid); n   build(id << 1 | 1, mid + 1, r); n } n void update(int id, int pos, int val, int y) { n   int l = tree[id].tl, r = tree[id].tr; n   if (l == r) { n     if (st[pos].size()) n       tree[id].mx = *(--st[pos].end()); n     else n       tree[id].mx = -1; n     return; n   } n   int mid = (l + r) >> 1; n   if (pos <= mid) n     update(id << 1, pos, val, y); n   else n     update(id << 1 | 1, pos, val, y); n   tree[id].mx = max(tree[id << 1].mx, tree[id << 1 | 1].mx); n } n int query(int id, int ql, int qr, int y) { n   int l = tree[id].tl, r = tree[id].tr; n   if (tree[id].mx <= y || ql > qr) { n     return -1; n   } n   int mid = (l + r) >> 1; n   if (l == r) return l; n   if (qr <= mid) n     return query(id << 1, ql, qr, y); n   else if (ql > mid) n     return query(id << 1 | 1, ql, qr, y); n   else { n     int tmp = query(id << 1, ql, mid, y); n     if (tmp != -1) return tmp; n     return query(id << 1 | 1, mid + 1, qr, y); n   } n } n struct Point { n   int x, y; n   char op[5]; n   void init() { scanf( %s%d%d , op, &x, &y); } n } q[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     q[i].init(); n     ve[i] = q[i].x; n   } n   sort(ve + 1, ve + 1 + n); n   int m = unique(ve + 1, ve + 1 + n) - (ve + 1); n   build(1, 1, m); n   for (int i = 1; i <= n; i++) { n     int pos = lower_bound(ve + 1, ve + 1 + m, q[i].x) - ve; n     if (q[i].op[0] ==  a ) { n       st[pos].insert(q[i].y); n       update(1, pos, 1, q[i].y); n     } else if (q[i].op[0] ==  r ) { n       st[pos].erase(q[i].y); n       update(1, pos, 1, q[i].y); n     } else { n       int ans = query(1, pos + 1, m, q[i].y); n       if (ans == -1) n         printf( -1 n ); n       else n         printf( %d %d n , ve[ans], *st[ans].upper_bound(q[i].y)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n, k; n   cin >> n >> k; n   string s[n + 1]; n   set<string> ar; n   for (int x = 0; x < n; x++) { n     cin >> s[x]; n     ar.insert(s[x]); n   } n   char a[3] = { S ,  E ,  T }; n   long long int ans = 0; n   for (int x = 0; x < n; x++) { n     for (int y = x + 1; y < n; y++) { n       string d; n       for (int z = 0; z < k; z++) { n         if (s[x][z] == s[y][z]) { n           d += s[x][z]; n         } else { n           for (int i = 0; i < 3; i++) { n             if (a[i] != s[x][z] && a[i] != s[y][z]) { n               d += a[i]; n               break; n             } n           } n         } n       } n       if (d.length() != 0) n         if (ar.count(d)) ++ans; n     } n   } n   cout << ans / 3 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } n long long power(long long a, long long n) { n   long long p = 1; n   while (n > 0) { n     if (n & 1) { n       p = p * a; n     } n     n >>= 1; n     a *= a; n   } n   return p; n } n long long power(long long a, long long n, long long mod) { n   long long p = 1; n   while (n > 0) { n     if (n & 1) { n       p = p * a; n       p %= mod; n     } n     n >>= 1; n     a *= a; n     a %= mod; n   } n   return p % mod; n } n const int N = 300005; n long long x[N]; n long long d[N], a[N]; n long long find(int i, int j) { n   if (i == 0) return x[j]; n   return (x[j] - x[i - 1] + 1000000007) % 1000000007; n } n int main() { n   int i, j; n   int n; n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %lld , &a[i]); n   sort(a, a + n); n   x[0] = 1; n   for (i = 1; i < n; i++) { n     d[i] = a[i] - a[i - 1]; n     x[i] = (power(2ll, i, 1000000007) + x[i - 1]) % 1000000007; n   } n   long long ans = 0; n   for (i = 1; i < n; i++) { n     ans += (d[i] * find(i - 1, n - 2)) % 1000000007; n   } n   long long z = ans; n   for (i = 2; i < n; i++) { n     z = (z - (d[i - 1] * x[n - i]) % 1000000007 + 1000000007) % 1000000007; n     z = (z * power(2, 1000000007 - 2, 1000000007)) % 1000000007; n     ans = (ans + z) % 1000000007; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, y; n int n, m, k; n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < k; i++) { n     cin >> x >> y; n     if (x <= 5 || y <= 5 || n - x <= 4 || m - y <= 4) { n       cout <<  YES  << endl; n       return 0; n     } n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:100000000 ) n using namespace std; n const int N = 155; n const int INF = 1000000000; n struct Edge { n   int to, flow, cap, cost; n   Edge() {} n   Edge(int to, int flow, int cap, int cost) n       : to(to), flow(flow), cap(cap), cost(cost) {} n }; n vector<Edge> g[N]; n void add_edge(int from, int to, int cap, int cost) { n   g[from].push_back(Edge(to, 0, cap, cost)); n   g[to].push_back(Edge(from, cap, cap, -cost)); n } n int* count_letters(string s) { n   int* a = new int[26]; n   memset(a, 0, 26 * sizeof(int)); n   for (int(i) = 0; (i) < ((int)(s).size()); (i)++) a[s[i] -  a ]++; n   return a; n } n int d[N], p[N], id[N]; n void find_flow(int src, int goal, int need) { n   int flow = 0, n = goal + 1, cost = 0; n   while (flow < need) { n     for (int(i) = 0; (i) < (n); (i)++) d[i] = INF, p[i] = id[i] = -1; n     d[src] = 0; n     for (int(i) = 0; (i) < (n - 1); (i)++) { n       for (int(a) = 0; (a) < (n); (a)++) { n         for (int(j) = 0; (j) < ((int)(g[a]).size()); (j)++) { n           int b = g[a][j].to; n           if (g[a][j].flow < g[a][j].cap && d[b] > d[a] + g[a][j].cost) { n             d[b] = d[a] + g[a][j].cost; n             p[b] = a; n             id[b] = j; n           } n         } n       } n     } n     if (d[goal] == INF) { n       puts( -1 ); n       return; n     } n     int push = INF, cur = goal; n     while (cur != src) { n       push = min(push, g[p[cur]][id[cur]].cap - g[p[cur]][id[cur]].flow); n       cur = p[cur]; n     } n     cur = goal; n     flow += push; n     while (cur != src) { n       g[p[cur]][id[cur]].flow += push; n       cost += push * g[p[cur]][id[cur]].cost; n       for (int(i) = 0; (i) < ((int)(g[cur]).size()); (i)++) { n         if (g[cur][i].to == p[cur]) { n           g[cur][i].flow -= push; n           break; n         } n       } n       cur = p[cur]; n     } n   } n   printf( %d n , cost); n } n int main() { n   string t; n   cin >> t; n   int* a = count_letters(t); n   int n; n   cin >> n; n   for (int(i) = 0; (i) < (26); (i)++) add_edge(n + 1 + i, n + 27, a[i], 0); n   for (int(i) = 0; (i) < (n); (i)++) { n     string s; n     int cap; n     cin >> s >> cap; n     int* b = count_letters(s); n     add_edge(0, i + 1, cap, i + 1); n     for (int(j) = 0; (j) < (26); (j)++) add_edge(i + 1, n + 1 + j, b[j], 0); n   } n   find_flow(0, n + 27, (int)(t).size()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, t, c, sum = 0; n   cin >> t; n   long long int a[t]; n   for (i = 0; i < t; i++) { n     cin >> a[i]; n   } n   for (i = 0; i < t; i++) { n     sum += a[i]; n   } n   if (sum % 2 == 0) { n     cout << sum << endl; n   } else { n     long long int min = 1000000001; n     for (i = 0; i < t; i++) { n       if (a[i] <= min && a[i] % 2 != 0) { n         min = a[i]; n       } n     } n     sum = sum - min; n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, s[10001], ss[10001]; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &s[i]); n   for (int i = 1; i < n; i++) { n     ss[i] = abs(s[i] - s[i + 1]); n   } n   ss[n] = abs(s[n] - s[1]); n   int t, min = 999999; n   for (int i = 1; i <= n; i++) { n     if (min > ss[i]) { n       min = ss[i]; n       t = i; n     } n   } n   if (t != n) n     printf( %d %d n , t, t + 1); n   else n     printf( %d %d n , t, 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 132700; n int n; n tuple<int, int, int, int> esq[N], dir[N]; n vector<tuple<int, int, int, int>> v; n int main(void) { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     v.emplace_back(a, b, c, d); n   } n   esq[0] = make_tuple(-0x3f3f3f3f, -0x3f3f3f3f, +0x3f3f3f3f, +0x3f3f3f3f); n   for (int i = 1; i <= n; i++) { n     int xb, yb, xu, yu; n     tie(xb, yb, xu, yu) = v[i - 1]; n     get<0>(esq[i]) = max(get<0>(esq[i - 1]), xb); n     get<1>(esq[i]) = max(get<1>(esq[i - 1]), yb); n     get<2>(esq[i]) = min(get<2>(esq[i - 1]), xu); n     get<3>(esq[i]) = min(get<3>(esq[i - 1]), yu); n   } n   dir[n + 1] = make_tuple(-0x3f3f3f3f, -0x3f3f3f3f, +0x3f3f3f3f, +0x3f3f3f3f); n   for (int i = n; i >= 1; i--) { n     int xb, yb, xu, yu; n     tie(xb, yb, xu, yu) = v[i - 1]; n     get<0>(dir[i]) = max(get<0>(dir[i + 1]), xb); n     get<1>(dir[i]) = max(get<1>(dir[i + 1]), yb); n     get<2>(dir[i]) = min(get<2>(dir[i + 1]), xu); n     get<3>(dir[i]) = min(get<3>(dir[i + 1]), yu); n   } n   for (int i = 1; i <= n; i++) { n     int xb, yb, xu, yu; n     xb = max(get<0>(esq[i - 1]), get<0>(dir[i + 1])); n     yb = max(get<1>(esq[i - 1]), get<1>(dir[i + 1])); n     xu = min(get<2>(esq[i - 1]), get<2>(dir[i + 1])); n     yu = min(get<3>(esq[i - 1]), get<3>(dir[i + 1])); n     if (xb <= xu and yb <= yu) { n       cout << xb <<     << yb << endl; n       return 0; n     } n   } n   assert(0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b; n int main() { n   cin >> a >> b; n   if (abs(a - b) <= 1 && (a || b)) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Q_Q() { n   ios::sync_with_stdio(0); n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n } n map<int, bool> mp; n int main() { n   Q_Q(); n   int n, k; n   double t; n   cin >> n >> k >> t; n   int arr[n]; n   long long int sum = 0; n   for (int i = 0; i < n; i++) { n     arr[i] = k; n     sum += k; n   } n   int j = n - 1; n   while ((sum * 1.0 / ((n * k) * 1.0)) > t / 100) { n     arr[j]--; n     if (arr[j] == 0) j--; n     sum--; n   } n   for (int i = 0; i < n; i++) cout << arr[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unsigned int n, m, l; n   cin >> n >> m >> l; n   int s = 0; n   while (l--) { n     s += 2 * (n + m - 2); n     n -= 4; n     m -= 4; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 2; n long long d, k, a, b, t; n int main() { n   cin >> d >> k >> a >> b >> t; n   if (d <= k) { n     cout << d * a; n   } else if (t + k * a > k * b) { n     cout << k * a + (d - k) * b; n   } else { n     long long cnt = d / k; n     long long ans = n         k * a * cnt + (cnt - 1) * t + min(t + (d % k) * a, (d % k) * b); n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i; n   scanf( %I64d , &n); n   if (n <= 3) { n     printf( 1 ); n     return 0; n   } n   if (n == 4) { n     printf( 2 ); n     return 0; n   } n   if (n % 2 == 0) n     printf( 2 ); n   else { n     bool u = 1; n     for (i = 2; i * i <= n; i++) n       if (n % i == 0) { n         u = 0; n         break; n       } n     if (u) n       printf( 1 ); n     else { n       n = n - 2; n       bool v = 1; n       for (i = 2; i * i <= n; i++) n         if (n % i == 0) { n           v = 0; n           break; n         } n       if (v) n         printf( 2 ); n       else n         printf( 3 ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n long long inf = 4e18; n const long long N = 2e5 + 5; n long long ans[N]; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long tt = 1; n   while (tt--) { n     long long n; n     cin >> n; n     long long l, r; n     map<long long, long long> mp; n     for (long long i = 0; i < n; ++i) { n       cin >> l >> r; n       ++mp[l]; n       --mp[r + 1]; n     } n     long long cnt = 0; n     l = -1; n     for (auto it : mp) { n       if (l == -1) { n         l = it.first; n         cnt += it.second; n       } else { n         ans[cnt] += (it.first - l); n         l = it.first; n         cnt += it.second; n       } n     } n     for (long long i = 1; i <= n; ++i) cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int a[6] = {3, 3, 3, 2, 2, 1}; n const int b[6] = {2, 1, 0, 1, 0, 0}; n const int inf = 1000000000; n const double eps = 1e-6; n int Dist[6]; n double X[7]; n int Round(double X) { n   int T = (int)X; n   if (T + 1 - X < eps) T++; n   return T; n } n bool Check(int Len) { n   static double G[7][7], A[7]; n   memset(G, 0, sizeof(G)); n   for (int i = 0; i < 6; i++) n     for (int j = 0; j < 7; j++) { n       bool F0 = (j + 1) & (1 << a[i]); n       bool F1 = (j + 1) & (1 << b[i]); n       G[i][j] = F0 ^ F1; n     } n   for (int i = 0; i < 7; i++) G[6][i] = 1; n   for (int i = 0; i < 6; i++) A[i] = Dist[i]; n   A[6] = Len; n   for (int i = 0; i < 7; i++) { n     if (!G[i][i]) { n       int P = i + 1; n       while (!G[P][i]) P++; n       for (int j = i; j < 7; j++) swap(G[i][j], G[P][j]); n       swap(A[i], A[P]); n     } n     for (int j = i + 1; j < 7; j++) n       if (G[j][i]) { n         double T = G[j][i] / G[i][i]; n         for (int k = i; k < 7; k++) G[j][k] -= G[i][k] * T; n         A[j] -= A[i] * T; n       } n   } n   for (int i = 6; i >= 0; i--) { n     X[i] = A[i] / G[i][i]; n     for (int j = 0; j < i; j++) A[j] -= X[i] * G[j][i]; n   } n   for (int i = 0; i < 7; i++) n     if (fabs(X[i] - Round(X[i])) > eps || X[i] < -eps) return false; n   return true; n } n int main() { n   for (int i = 0; i < 6; i++) scanf( %d , &Dist[i]); n   int Ans = -1, Sum = 0; n   for (int i = 0; i < 6; i++) Sum += Dist[i]; n   for (int i = Sum / 4; Ans == -1 && i <= Sum / 3; i++) n     if (Check(i)) Ans = i; n   printf( %d n , Ans); n   if (Ans == -1) return 0; n   string S[4]; n   for (int i = 0; i < 7; i++) { n     int M = Round(X[i]); n     for (int j = 0; j < M; j++) { n       S[0] +=  a ; n       for (int k = 1; k < 4; k++) n         S[k] += ((i + 1) & (1 << (3 - k))) ?  b  :  a ; n     } n   } n   for (int i = 0; i < 4; i++) cout << S[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MO = 1e9 + 7; n int n, K; n long long dp[105][44], tt[44]; n vector<int> e[105]; n void add(long long &x, long long y) { x = (x + y) % MO; } n void mul(long long &x, long long y) { x = x * y % MO; } n void dfs(int u, int f) { n   dp[u][K + 1] = 1; n   dp[u][0] = 1; n   for (auto v : e[u]) n     if (v != f) { n       dfs(v, u); n       for (int i = 0; i <= 2 * K; ++i) n         for (int j = 0; j <= 2 * K; ++j) n           add(tt[i + j <= 2 * K ? min(i, j + 1) : max(i, j + 1)], n               dp[u][i] * dp[v][j]); n       memcpy(dp[u], tt, sizeof tt); n       memset(tt, 0, sizeof tt); n     } n } n int main() { n   cin >> n >> K; n   for (int i = 1, x, y; i < n; ++i) { n     cin >> x >> y; n     e[x].push_back(y); n     e[y].push_back(x); n   } n   dfs(1, 0); n   long long ans = 0; n   for (int i = 0; i <= K; ++i) add(ans, dp[1][i]); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, val[105], c[105][105], pref[105][105], calc[105][105], n     dp[105][10005]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (long long i = 1; i <= n; ++i) { n     cin >> val[i]; n     for (long long j = 1; j <= val[i]; ++j) n       cin >> c[i][j], pref[i][j] = pref[i][j - 1] + c[i][j]; n   } n   for (long long i = 1; i <= n; ++i) n     for (long long j = 1; j <= min(m, val[i]); ++j) n       for (long long k = 0; k <= j; ++k) n         calc[i][j] = max(calc[i][j], pref[i][k] + pref[i][val[i]] - n                                          pref[i][val[i] - (j - k)]); n   long long tot = 0; n   for (long long i = 1; i <= n; ++i) { n     tot += val[i]; n     for (long long j = 1; j <= min(tot, m); ++j) { n       for (long long k = 0; k <= min(j, val[i]); ++k) { n         dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + calc[i][k]); n       } n     } n   } n   cout << dp[n][m] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t[90]; n   bool ans = false; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> t[i]; n   } n   if (t[0] > 15) { n     cout << 15; n     ans = true; n   } n   for (int i = 0; i < n - 1 && ans == false; i++) { n     t[i] += 15; n     if (t[i] < t[i + 1]) { n       cout << t[i]; n       ans = true; n     } n   } n   t[n - 1] += 15; n   if (t[n - 1] >= 90 && ans == false) { n     cout << 90; n   } n   if (t[n - 1] < 90 && ans == false) { n     cout << t[n - 1]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Abel> n struct BIT2D { n   vector<vector<Abel>> dat[4]; n   BIT2D(int h, int w) { n     for (int which = 0; which < 4; which++) n       dat[which].assign(h + 1, vector<Abel>(w + 1)); n   } n   inline void sub_add(int which, int a, int b, Abel x) { n     int h = dat[which].size(), w = dat[which][0].size(); n     for (int i = a; i < h; i += i & -i) n       for (int j = b; j < w; j += j & -j) dat[which][i][j] += x; n   } n   inline void add(int si, int sj, Abel x) { n     sub_add(0b00, si, sj, x * (si - 1) * (sj - 1)); n     sub_add(0b10, si, sj, -x * (si - 1)); n     sub_add(0b01, si, sj, -x * (sj - 1)); n     sub_add(0b11, si, sj, x); n   } n   inline void add(int si, int ti, int sj, int tj, Abel x) { n     add(si, sj, x), add(si, tj, -x), add(ti, sj, -x), add(ti, tj, x); n   } n   inline Abel sub_sum(int which, int a, int b) { n     Abel res = Abel(0); n     for (int i = a; i > 0; i -= i & -i) n       for (int j = b; j > 0; j -= j & -j) res += dat[which][i][j]; n     return res; n   } n   inline Abel sum(int si, int sj) { n     Abel res = Abel(0); n     res += sub_sum(0b00, si - 1, sj - 1); n     res += sub_sum(0b10, si - 1, sj - 1) * (sj - 1); n     res += sub_sum(0b01, si - 1, sj - 1) * (si - 1); n     res += sub_sum(0b11, si - 1, sj - 1) * (si - 1) * (sj - 1); n     return res; n   } n   inline Abel sum(int si, int ti, int sj, int tj) { n     return sum(ti, tj) - sum(si, tj) - sum(ti, sj) + sum(si, sj); n   } n }; n struct Xor { n   long long val; n   Xor(long long val_ = 0) : val(val_) {} n   Xor operator=(long long val_) { n     this->val = val_; n     return *this; n   } n   Xor operator-() { return val; } n   const Xor &operator+=(const Xor &x); n   const Xor &operator-=(const Xor &x); n   friend ostream &operator<<(ostream &os, const Xor &a) { return os << a.val; } n }; n Xor operator+(Xor x, Xor y) { return x.val ^ y.val; } n Xor operator-(Xor x, Xor y) { return x.val ^ y.val; } n Xor operator*(Xor x, int p) { return p & 1 ? x : 0; } n const Xor &Xor::operator+=(const Xor &x) { return *this = *this + x; } n const Xor &Xor::operator-=(const Xor &x) { return *this = *this - x; } n int main() { n   cin.tie(nullptr); n   ios::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   BIT2D<Xor> bit(n, n); n   while (m--) { n     int op; n     cin >> op; n     int si, sj, ti, tj; n     cin >> si >> sj >> ti >> tj; n     if (op == 1) { n       cout << bit.sum(si, ti + 1, sj, tj + 1) << endl; n     } n     if (op == 2) { n       long long v; n       cin >> v; n       bit.add(si, ti + 1, sj, tj + 1, v); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   long long x = n * (n * n + 1) / 2; n   vector<long long> a[101]; n   for (long long j = 0; j < n / 2; j++) n     for (long long i = 1; i < n + 1; i++) { n       long long x = n * j + i; n       a[i].push_back(x); n       a[i].push_back(n * n - x + 1); n     } n   for (long long i = 1; i < n + 1; i++) { n     for (auto x : a[i]) cout << x <<    ; n     cout <<   n ; n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long TESTS = 1; n   while (TESTS--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T power(T a, T b) { n   T x; n   if (b == 0) n     x = 1; n   else n     x = a; n   for (size_t i = 1; i < b; i++) x *= a; n   return x; n } n long long int gcd(long long int a, long long int b) { n   return b == 0 ? a : gcd(b, a % b); n } n long long int n, m, a, b, c, ab, ba, x, y, z, avg, total, ans, sum; n long long int arr2[300001], arr3[100001], arr4[100001], arr5[100001]; n char c1, c2; n vector<pair<string, long long int> > vec; n vector<long long int> v; n bool f, f1, f2, found; n string str, s1, s2, s3, s4; n map<long long int, long long int> mp, mp1; n set<int> seto; n double d, d1; n long long int x1, x2, y11, y2; n long long int mini = 10000000000, maxi = 0; n set<string> sets; n void rec(int n, string s) { n   if (n == 11) return; n   sets.insert(s); n   rec(n + 1, s +  4 ); n   rec(n + 1, s +  7 ); n } n int main() { n   rec(0,   ); n   for (set<string>::iterator i = sets.begin(); i != sets.end(); i++) { n     string s = *i; n     if (!s.empty()) arr2[x++] = stoll(s); n   } n   sort(arr2, arr2 + x); n   cin >> n >> m; n   y = n; n   for (long long int i = 0; i < x; i++) { n     if (y <= arr2[i]) { n       sum += (min(arr2[i] - y, m - y) + 1) * arr2[i]; n       y = arr2[i] + 1; n     } n     if (y > m) break; n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   scanf( %i%i , &n, &k); n   if (k * 2 >= n) n     printf( -1 n ); n   else { n     printf( %i n , n * k); n     for (int i = 0; i < n; i++) n       for (int j = 0; j < k; j++) printf( %i %i n , i + 1, (i + j + 1) % n + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> lucky; n void backtrack(long long num) { n   if (num > 10000000000) return; n   lucky.push_back(num); n   backtrack(num * 10 + 4); n   backtrack(num * 10 + 7); n } n int main() { n   backtrack(0); n   sort(lucky.begin(), lucky.end()); n   pair<long long, long long> P, V; n   int k; n   cin >> P.first >> P.second; n   cin >> V.first >> V.second; n   cin >> k; n   long long denominator = n       1LL * (P.second - P.first + 1) * (V.second - V.first + 1); n   long long numerator = 0; n   for (int i = k; i + 1 < (int)lucky.size(); i++) { n     long long pLo = max(lucky[i - k] + 1, P.first); n     long long pHi = min(lucky[i - k + 1], P.second); n     long long vLo = max(lucky[i], V.first); n     long long vHi = min(lucky[i + 1] - 1, V.second); n     vLo = max(vLo, max(pLo, pHi)); n     long long yo = 1LL * max(0LL, pHi - pLo + 1) * max(0LL, vHi - vLo + 1); n     numerator += yo; n     pLo = max(lucky[i], P.first); n     pHi = min(lucky[i + 1] - 1, P.second); n     vLo = max(lucky[i - k] + 1, V.first); n     vHi = min(lucky[i - k + 1], V.second); n     pLo = max(pLo, max(vLo, vHi)); n     yo = 1LL * max(0LL, pHi - pLo + 1) * max(0LL, vHi - vLo + 1); n     numerator += yo; n   } n   if (k == 1) n     for (int i = 0; i < (int)lucky.size(); i++) n       if (lucky[i] >= max(P.first, V.first) && n           lucky[i] <= min(P.second, V.second)) n         numerator -= 1; n   printf( %.9lf n , (1.0 * numerator) / denominator); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> Neighbors[2000000]; n bool Visited[2000000]; n bool Leaf[2000000]; n char Color[500001]; n queue<int> Queue; n void bfs(int i) { n   Visited[i] = true; n   Queue.push(i); n   while (Queue.empty() == false) { n     int u = Queue.front(); n     Queue.pop(); n     Leaf[u] = true; n     for (int v = 0; v < Neighbors[u].size(); v++) n       if (Visited[Neighbors[u][v]] == false) { n         Visited[Neighbors[u][v]] = true; n         Queue.push(Neighbors[u][v]); n         Leaf[u] = false; n       } n   } n } n int main() { n   int T; n   scanf( %d , &T); n   for (int t = 1; t <= T; t++) { n     int n; n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) Neighbors[i].clear(); n     int u, v; n     for (int i = 0; i + 1 < n; i++) { n       scanf( %d %d , &u, &v); n       Neighbors[u].push_back(v); n       Neighbors[v].push_back(u); n     } n     scanf( %s , Color); n     if (n < 3) { n       printf( Draw n ); n       continue; n     } n     int n_ = n; n     for (int i = 1; i <= n; i++) n       if (Color[i - 1] ==  W ) { n         Neighbors[n_ + 1].clear(); n         Neighbors[n_ + 2].clear(); n         Neighbors[n_ + 3].clear(); n         Neighbors[i].push_back(n_ + 1); n         Neighbors[n_ + 1].push_back(i); n         Neighbors[n_ + 1].push_back(n_ + 2); n         Neighbors[n_ + 1].push_back(n_ + 3); n         Neighbors[n_ + 2].push_back(n_ + 1); n         Neighbors[n_ + 3].push_back(n_ + 1); n         n_ += 3; n       } n     n = n_; n     int won = 0; n     for (int i = 1; i <= n; i++) n       if (Neighbors[i].size() >= 4) { n         printf( White n ); n         won = 1; n         break; n       } n     if (won) continue; n     for (int i = 1; i <= n; i++) Visited[i] = 0; n     bfs(1); n     if (Neighbors[1].size() == 1) Leaf[1] = true; n     for (int i = 1; i <= n; i++) n       if (Neighbors[i].size() >= 3) { n         int leaves = 0; n         for (int j = 0; j < Neighbors[i].size(); j++) n           if (Leaf[Neighbors[i][j]]) leaves++; n         if (Neighbors[i].size() - leaves >= 2) { n           printf( White n ); n           won = 1; n           break; n         } n       } n     if (won) continue; n     int left = 1; n     while (left <= n && Neighbors[left].size() < 3) left++; n     int right = n; n     while (right > 0 && Neighbors[right].size() < 3) right--; n     if (left <= n && right > 0 && left < right) { n       int curr, prev = left; n       int len = 2; n       for (int i = 0; i < Neighbors[prev].size(); i++) n         if (Leaf[Neighbors[prev][i]] == 0) curr = Neighbors[prev][i]; n       while (curr != right) { n         if (Neighbors[curr][0] != prev) { n           prev = curr; n           curr = Neighbors[curr][0]; n         } else { n           prev = curr; n           curr = Neighbors[curr][1]; n         } n         len++; n       } n       if (len % 2 == 1) { n         printf( White n ); n         continue; n       } n     } n     printf( Draw n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i < 100000; i++) { n     n *= 3; n     m *= 2; n     if (n > m) { n       cout << i << endl; n       return 0; n     } n   } n } n