#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n using vi = vector<int>; n const int N = 3e5 + 3; n const int mod = 1e9 + 7; n int n; n ll a[N]; n template <class T> n struct FT { n   vector<T> tree; n   int sz; n   FT(int n) { sz = n, tree.resize(n + 1); } n   T get(int i) { n     if (i <= 0 || i > sz) return T(0); n     T sum = T(0); n     for (; i; i -= (i & -i)) sum += tree[i]; n     return sum; n   } n   void upd(int i, T val) { n     for (; i <= sz; i += (i & -i)) tree[i] += val; n   } n   void init(T *arr, int n) { n     sz = n; n     for (int i = 1; i <= n; i++) upd(i, arr[i - 1]); n   } n }; n ll ans[N]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   FT<ll> tree1(N); n   FT<ll> tree2(N); n   ll sum = 0; n   for (int i = 0; i < n; i++) { n     ans[i] = 1ll * i * a[i] + sum; n     ans[i] -= tree1.get(a[i]); n     sum += a[i]; n     int mul = a[i]; n     while (mul < N) { n       tree1.upd(mul, 1ll * a[i]); n       mul += a[i]; n     } n     mul = (300000 / a[i]) * a[i]; n     ll cnt = 0; n     while (mul != 0) { n       ll cur = i - tree2.get(mul - 1); n       ll how_many = cur - cnt; n       ans[i] -= 1ll * mul * how_many; n       cnt = cur; n       mul -= a[i]; n     } n     tree2.upd(a[i], 1ll); n   } n   for (int i = 0; i < n; i++) { n     printf( %lld  , ans[i]); n     ans[i + 1] += ans[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, v; n   cin >> a >> v; n   double l, d, w; n   cin >> l >> d >> w; n   w = min(w, v); n   double s = w / a; n   double t = a * s * s / 2; n   double thead = 0; n   double vhead = 0; n   if (t < d) { n     double t1 = v / a; n     double t2 = (v - w) / a; n     double dd = t1 * v / 2 + t2 * (v + w) / 2; n     if (dd < d) { n       double t3 = (d - dd) / v; n       thead = t1 + t2 + t3; n       vhead = w; n     } else { n       double vv = sqrt((2 * a * d + w * w) / 2); n       thead = vv / a + (vv - w) / a; n       vhead = w; n     } n   } else { n     thead = sqrt(2 * d / a); n     vhead = a * thead; n   } n   double ttail = 0; n   double tt = (-vhead + sqrt(vhead * vhead + 2 * a * (l - d))) / a; n   if (vhead + tt * a < v) { n     ttail = tt; n   } else { n     double t1 = (v - vhead) / a; n     double rest = (l - d) - (vhead + v) * t1 / 2; n     double t2 = rest / v; n     ttail = t1 + t2; n   } n   cout << setiosflags(ios::fixed) << setprecision(12); n   cout << thead + ttail << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = 1; n long long MOD = 1e9 + 7; n const int N = 2e5 + 10; n map<int, vector<int>> mpe, mps; n int nonred[N]; n int n; n set<int> st; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     int l, r; n     scanf( %d%d , &l, &r); n     mpe[l].push_back(i + 1); n     mps[r + 1].push_back(i + 1); n     st.insert(l); n     st.insert(r + 1); n   } n   set<int> at; n   for (auto &tempo : st) { n     for (auto &it : mpe[tempo]) { n       at.insert(it); n     } n     for (auto &it : mps[tempo]) { n       if (!nonred[it]) { n         cout << it << endl; n         return 0; n       } n       at.erase(it); n     } n     if (at.size() == 1) { n       nonred[*at.begin()] = 1; n     } n   } n   cout << -1 << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const unsigned long long key = 31; n const int MB = 1e5 + 5; n int n, m; n string s; n unsigned long long p[100008]; n unsigned long long h[100008]; n vector<int> v[100005]; n vector<int> vv[100005]; n int a[100005]; n map<unsigned long long, int> pos; n string b[100005]; n inline void build(int len) { n   unsigned long long cur = 0; n   for (int i = 0; i < v[len].size(); ++i) { n     cur = 0; n     for (int j = 0; j < len; ++j) n       cur = (cur + (b[v[len][i]][j] -  a  + 1) * p[j + 1]); n     cur = (cur * p[MB - 1]); n     pos[cur] = v[len][i]; n   } n   for (int i = 1; i <= n - len + 1; ++i) { n     cur = h[i + len - 1] - h[i - 1]; n     cur *= p[MB - i]; n     if (pos.count(cur)) vv[pos[cur]].push_back(i); n   } n   pos.clear(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> s; n   n = s.size(); n   p[0] = 1; n   for (int i = 1; i <= MB; ++i) p[i] = p[i - 1] * key; n   for (int i = 1; i <= n; ++i) h[i] = h[i - 1] + (s[i - 1] -  a  + 1) * p[i]; n   cin >> m; n   for (int i = 1; i <= m; ++i) { n     cin >> a[i]; n     cin >> b[i]; n     v[b[i].size()].push_back(i); n   } n   for (int i = 1; i <= n; ++i) n     if (v[i].size() > 0) { n       build(i); n     } n   for (int i = 1; i <= m; ++i) { n     if (vv[i].size() < a[i]) { n       cout << -1 <<   n ; n       continue; n     } n     int cur = n; n     int z; n     for (int j = a[i]; j <= vv[i].size(); ++j) { n       z = vv[i][j - 1] - vv[i][j - a[i]] + b[i].size(); n       if (z < cur) cur = z; n     } n     cout << cur <<   n ; n   } n } n


#include <bits/stdc++.h> n long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; n long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; n using namespace std; n class pa3 { n  public: n   long long x; n   long long y, z; n   pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} n   bool operator<(const pa3 &p) const { n     if (x != p.x) return x < p.x; n     if (y != p.y) return y < p.y; n     return z < p.z; n   } n   bool operator>(const pa3 &p) const { n     if (x != p.x) return x > p.x; n     if (y != p.y) return y > p.y; n     return z > p.z; n   } n   bool operator==(const pa3 &p) const { n     return x == p.x && y == p.y && z == p.z; n   } n   bool operator!=(const pa3 &p) const { n     return !(x == p.x && y == p.y && z == p.z); n   } n }; n class pa4 { n  public: n   long long x; n   long long y, z, w; n   pa4(long long x = 0, long long y = 0, long long z = 0, long long w = 0) n       : x(x), y(y), z(z), w(w) {} n   bool operator<(const pa4 &p) const { n     if (x != p.x) return x < p.x; n     if (y != p.y) return y < p.y; n     if (z != p.z) return z < p.z; n     return w < p.w; n   } n   bool operator>(const pa4 &p) const { n     if (x != p.x) return x > p.x; n     if (y != p.y) return y > p.y; n     if (z != p.z) return z > p.z; n     return w > p.w; n   } n   bool operator==(const pa4 &p) const { n     return x == p.x && y == p.y && z == p.z && w == p.w; n   } n }; n class pa2 { n  public: n   long long x, y; n   pa2(long long x = 0, long long y = 0) : x(x), y(y) {} n   pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); } n   pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); } n   bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; } n   bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; } n   bool operator==(const pa2 &p) const { n     return abs(x - p.x) == 0 && abs(y - p.y) == 0; n   } n   bool operator!=(const pa2 &p) const { n     return !(abs(x - p.x) == 0 && abs(y - p.y) == 0); n   } n }; n string itos(long long i) { n   ostringstream s; n   s << i; n   return s.str(); n } n long long gcd(long long v, long long b) { n   if (v > b) return gcd(b, v); n   if (v == b) return b; n   if (b % v == 0) return v; n   return gcd(v, b % v); n } n long long mod; n long long extgcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   long long d = extgcd(b, a % b, y, x); n   y -= a / b * x; n   return d; n } n pair<long long, long long> operator+(const pair<long long, long long> &l, n                                      const pair<long long, long long> &r) { n   return {l.first + r.first, l.second + r.second}; n } n pair<long long, long long> operator-(const pair<long long, long long> &l, n                                      const pair<long long, long long> &r) { n   return {l.first - r.first, l.second - r.second}; n } n long long pr[1000010]; n long long inv[1000010]; n long long beki(long long wa, long long rr, long long warukazu) { n   if (rr == 0) return 1 % warukazu; n   if (rr == 1) return wa % warukazu; n   wa %= warukazu; n   if (rr % 2 == 1) n     return ((long long)beki(wa, rr - 1, warukazu) * (long long)wa) % warukazu; n   long long zx = beki(wa, rr / 2, warukazu); n   return (zx * zx) % warukazu; n } n long long comb(long long nn, long long rr) { n   if (rr < 0 || rr > nn || nn < 0) return 0; n   long long r = pr[nn] * inv[rr]; n   r %= mod; n   r *= inv[nn - rr]; n   r %= mod; n   return r; n } n void gya(long long ert) { n   pr[0] = 1; n   for (long long i = 1; i <= ert; i++) { n     pr[i] = (pr[i - 1] * i) % mod; n   } n   inv[ert] = beki(pr[ert], mod - 2, mod); n   for (long long i = ert - 1; i >= 0; i--) { n     inv[i] = inv[i + 1] * (i + 1) % mod; n   } n } n long long sita[1010]; n long long oya[1010]; n vector<long long> G[1010], H1[1010], H2[1010]; n long long dfs1(long long r, long long p) { n   oya[r] = p; n   sita[r] = 1; n   for (auto v : G[r]) n     if (v != p) { n       sita[r] += dfs1(v, r); n     } n   return sita[r]; n } n long long dep[1011]; n void dfs2(long long r, long long p, long long d = 1) { n   oya[r] = p; n   dep[r] = d; n   for (auto v : G[r]) n     if (v != p) { n       dfs2(v, r, d + 1); n       H1[r].push_back(v); n     } n } n void dfs3(long long r, long long p, long long d = 1) { n   oya[r] = p; n   dep[r] = d; n   for (auto v : G[r]) n     if (v != p) { n       dfs3(v, r, d + 1); n       H2[r].push_back(v); n     } n } n long long dp[1010][1010]; n long long mae[1010][1011]; n long long wei[1010]; n signed main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   long long n; n   cin >> n; n   for (long long i = 0; i < n - 1; i++) { n     long long y, yy; n     cin >> y >> yy; n     G[y].push_back(yy); n     G[yy].push_back(y); n   } n   if (n == 1) { n     return 0; n   } n   if (n == 2) { n     cout <<  1 2 1  << endl; n     return 0; n   } n   dfs1(1, 1); n   long long root = -1; n   for (long long i = 2; i <= n; i++) { n     long long wa = n - 1; n     bool ok = true; n     for (auto v : G[i]) n       if (v != oya[i]) { n         if (!(sita[v] <= n / 2)) ok = 0; n         wa -= sita[v]; n       } n     if (!ok) continue; n     if (wa <= n / 2) root = i; n   } n   if (root == -1) root = 1; n   dfs1(root, root); n   vector<pair<long long, long long> > ve; n   for (auto v : G[root]) ve.push_back({v, sita[v]}); n   long long m = ve.size(); n   dp[0][0] = 1; n   mae[0][0] = -1; n   for (long long i = 0; i < m; i++) { n     for (long long j = 0; j <= n; j++) n       if (dp[i][j]) { n         dp[i + 1][j] = 1; n         mae[i + 1][j] = mae[i][j]; n         dp[i + 1][j + ve[i].second] = 1; n         mae[i + 1][j + ve[i].second] = i; n       } n   } n   vector<long long> V1, V2; n   for (long long j = n / 2; j >= 0; j--) n     if (dp[m][j]) { n       long long imaval = j; n       long long imaind = m; n       while (1) { n         V1.push_back(ve[mae[imaind][imaval]].first); n         long long ee = imaval; n         imaval -= ve[mae[imaind][imaval]].second; n         imaind = mae[imaind][ee]; n         if (mae[imaind][imaval] == -1) break; n       } n       break; n     } n   for (auto v : ve) { n     bool bo = 0; n     for (auto w : V1) n       if (v.first == w) { n         bo = 1; n         break; n       } n     if (!bo) V2.push_back(v.first); n   } n   for (auto v : V1) dfs2(v, root), H1[root].push_back(v); n   for (auto v : V2) dfs3(v, root), H2[root].push_back(v); n   long long h1 = 0, h2 = 0; n   for (long long i = 1; i <= n; i++) h1 += H1[i].size(); n   for (long long i = 1; i <= n; i++) h2 += H2[i].size(); n   assert(h1 + h2 == n - 1); n   ve.clear(); n   for (long long i = 1; i <= n; i++) n     for (auto v : H1[i]) ve.push_back({dep[v], v}); n   sort(ve.begin(), ve.end()); n   for (long long i = 0; i < ve.size(); i++) { n     wei[ve[i].second] = (i + 1) * (h2 + 1); n   } n   ve.clear(); n   for (long long i = 1; i <= n; i++) n     for (auto v : H2[i]) ve.push_back({dep[v], v}); n   sort(ve.begin(), ve.end()); n   for (long long i = 0; i < ve.size(); i++) { n     wei[ve[i].second] = i + 1; n   } n   for (long long i = 1; i <= n; i++) n     if (i != root) { n       cout << i <<     << oya[i] <<     << wei[i] - wei[oya[i]] << endl; n     } n   for (long long i = 1; i <= n; i++) n     if (i != root) { n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:16777216 ) n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:16777216 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n const int inf = 2e9; n const long long linf = 5000000000000000000; n const long double LDINF = 2e18; n template <typename T> n void print(vector<T>& a) { n   for (int i = 0; i < a.size(); i++) cout << a[i] <<    ; n   cout <<   n ; n } n template <typename T> n void print(deque<T>& a) { n   for (int i = 0; i < a.size(); i++) cout << a[i] <<    ; n   cout <<   n ; n } n template <typename T> n void print(vector<vector<T>>& a) { n   for (int i = 0; i < a.size(); i++) { n     for (int j = 0; j < a[i].size(); j++) cout << a[i][j] <<    ; n     cout <<   n ; n   } n } n template <typename T> n void input(vector<T>& a) { n   for (int i = 0; i < a.size(); i++) cin >> a[i]; n } n template <typename T> n void input(deque<T>& a) { n   for (int i = 0; i < a.size(); i++) cin >> a[i]; n } n template <typename T> n void input(vector<vector<T>>& a) { n   for (int i = 0; i < a.size(); i++) n     for (int j = 0; j < a[i].size(); j++) cin >> a[i][j]; n } n long long mod = 998244353; n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n vector<int> p, rang; n void CreateSet(int v) { n   p[v] = v; n   rang[v] = 1; n } n int FindSet(int v) { n   if (p[v] == v) return v; n   return p[v] = FindSet(p[v]); n } n vector<pair<int, int>> ans; n void UnionSet(int a, int b) { n   a = FindSet(a); n   b = FindSet(b); n   if (a == b) return; n   if (rang[a] < rang[b]) swap(a, b); n   p[b] = a; n   if (rang[a] == rang[b]) rang[a]++; n   ans.push_back({a, b}); n } n void solve() { n   long long n, d; n   cin >> n; n   long long a = 0, b = 0; n   for (int i = 0; i < n; i++) { n     cin >> d; n     a |= d; n   } n   for (int i = 0; i < n; i++) { n     cin >> d; n     b |= d; n   } n   cout << a + b; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int tst = 1; n   while (tst--) solve(); n } n


#include <bits/stdc++.h> n struct Data { n   std::vector<int> nums; n   std::string str; n }; n struct Interval { n   int start; n   int end; n   std::string* data; n }; n bool compareIntervals(const Interval& a, const Interval& b) { n   if (a.start < b.start) return true; n   if (a.start > b.start) return false; n   return a.end < b.end; n } n int main() { n   std::cin.tie(0); n   std::ios_base::sync_with_stdio(0); n   int numSteps; n   std::cin >> numSteps; n   size_t finalLength = 0; n   std::vector<Data> steps(numSteps); n   int numIntervals = 0; n   for (int i = 0; i < steps.size(); ++i) { n     std::cin >> steps[i].str; n     int occurrences; n     std::cin >> occurrences; n     steps[i].nums.resize(occurrences); n     numIntervals += occurrences; n     for (int k = 0; k < occurrences; ++k) std::cin >> steps[i].nums[k]; n     finalLength = n         std::max(finalLength, steps[i].nums.back() - 1 + steps[i].str.size()); n   } n   std::vector<Interval> intervals(numIntervals); n   int intervalsIdx = 0; n   for (int i = 0; i < steps.size(); ++i) { n     for (int j = 0; j < steps[i].nums.size(); ++j) { n       Interval& curr = intervals[intervalsIdx]; n       curr.start = steps[i].nums[j] - 1; n       curr.end = curr.start + steps[i].str.size(); n       curr.data = &steps[i].str; n       ++intervalsIdx; n     } n   } n   std::sort(intervals.begin(), intervals.end(), compareIntervals); n   std::string out(finalLength,  a ); n   int doneIdx = 0; n   for (int i = 0; i < intervals.size(); ++i) { n     for (int idx = std::max(doneIdx, intervals[i].start); n          idx < intervals[i].end; ++idx) { n       out[idx] = (*intervals[i].data)[idx - intervals[i].start]; n     } n     doneIdx = std::max(doneIdx, intervals[i].end); n   } n   std::cout << out <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<bool> isprime(1005, true); n vector<long long> spf(1005, 0); n vector<long long> prime; n void sieve() { n   isprime[0] = isprime[1] = false; n   for (long long i = 2; i < 1005; i++) { n     if (isprime[i]) { n       for (long long j = 2 * i; j < 1005; j += i) { n         isprime[j] = false; n         if (spf[j] == 0) { n           spf[j] = i; n         } n       } n       prime.push_back(i); n     } n   } n } n long long power(long long k, long long n, long long m = 1000000007) { n   long long res = 1; n   while (n) { n     if (n % 2 != 0) { n       res = (res * k) % m; n     } n     k = (k * k) % m; n     n = n / 2; n   } n   return (res); n } n void READ(vector<long long> &v, long long n) { n   long long a; n   for (long long i = 0; i < n; i = i + 1) { n     cin >> a; n     v.push_back(a); n   } n } n void PRINT(vector<long long> &v, long long a = 0) { n   for (long long i = a; i < v.size(); i = i + 1) { n     cout << v[i] <<    ; n   } n   cout <<   n ; n } n long long n, m, k; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   std::cout.unsetf(std::ios::floatfield); n   std::cout.precision(12); n   long long a, b, c, d, e, x, i, j, t, y, w, z, x1, y1, z1, f; n   string str, str1, str2, str4; n   cin >> n >> a >> b; n   if (a * b >= 6 * n) { n     cout << a * b <<   n  << a <<     << b; n     exit(0); n   } n   x = y = 1e18; n   d = 0; n   for (j = 0;; j++) { n     c = 0; n     for (i = min(a, b); i * i <= 6 * n + j; i++) { n       if ((6 * n + j) % i == 0) { n         if (i >= a && (6 * n + j) / i >= b) { n           x = i; n           y = (6 * n + j) / i; n           c = 1; n           break; n         } n         if (i >= b && (6 * n + j) / i >= a && n             i - b + (6 * n + j) / i - a < x - a + y - b) { n           y = i; n           x = (6 * n + j) / i; n           c = 1; n           break; n         } n       } n     } n     if (c) { n       break; n     } n   } n   cout << x * y <<   n  << x <<     << y; n } n


#include <bits/stdc++.h> n const double pi = 3.1415926535897932384626433832795; n int gcd(int a, int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n using namespace std; n void ifd() {} n void tme() {} n int n, k, h; n vector<pair<int, pair<int, int> > > l; n vector<int> answer; n bool can(double time) { n   int cnt = 0; n   int pos = 0; n   while (pos < n && cnt < k) { n     if (((double)l[pos].second.first * time) >= ((double)(cnt + 1) * h)) { n       pos++; n       cnt++; n     } else { n       pos++; n     } n   } n   return cnt == k; n } n double bs() { n   double low = 0, high = 1e10, mid; n   for (int i = (0); i < (200); ++i) { n     mid = (low + high) / 2; n     if (can(mid)) n       high = mid; n     else n       low = mid; n   } n   return high; n } n int main() { n   ifd(); n   cin >> n >> k >> h; n   l.resize(n); n   for (int i = (0); i < (n); ++i) { n     cin >> l[i].first; n   } n   for (int i = (0); i < (n); ++i) { n     cin >> l[i].second.first; n     l[i].second.second = i + 1; n   } n   sort(l.begin(), l.end()); n   double time = bs(); n   int cnt = 0; n   int pos = 0; n   while (pos < n && cnt < k) { n     if (((double)l[pos].second.first * time) >= ((double)(cnt + 1) * h)) { n       answer.push_back(l[pos].second.second); n       pos++; n       cnt++; n     } else { n       pos++; n     } n   } n   for (int i = (0); i < (k - 1); ++i) cout << answer[i] <<    ; n   cout << answer[k - 1] << endl; n   tme(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 110; n const int INF = 1e9; n int _w; n int n, a[MAXN], b[MAXN]; n namespace MCMF { n const int MAXV = 1000000; n const int MAXE = 1000000; n struct Edge { n   int u, v, c, f, w; n   Edge() {} n   Edge(int u, int v, int c, int f, int w) : u(u), v(v), c(c), f(f), w(w) {} n }; n int n, m, s, t; n int head[MAXV], nxt[MAXE << 1]; n Edge edge[MAXE << 1]; n void init(int nn) { n   n = nn, m = 0; n   for (int i = 1; i <= n; ++i) head[i] = -1; n } n void adde(int u, int v, int c, int w) { n   edge[m] = Edge(u, v, c, 0, w); n   nxt[m] = head[u], head[u] = m++; n   edge[m] = Edge(v, u, 0, 0, -w); n   nxt[m] = head[v], head[v] = m++; n } n queue<int> q; n int inq[MAXV], dis[MAXV], res[MAXV], pre[MAXV]; n bool spfa() { n   for (int i = 1; i <= n; ++i) inq[i] = 0, dis[i] = -INF; n   q.push(s), inq[s] = 1, dis[s] = 0, res[s] = INF; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     inq[u] = 0; n     for (int i = head[u]; ~i; i = nxt[i]) { n       Edge &e = edge[i]; n       if (e.c > e.f && dis[e.v] < dis[u] + e.w) { n         dis[e.v] = dis[u] + e.w; n         res[e.v] = min(res[u], e.c - e.f); n         pre[e.v] = i; n         if (!inq[e.v]) { n           inq[e.v] = 1; n           q.push(e.v); n         } n       } n     } n   } n   return dis[t] != -INF; n } n void augment() { n   int u = t, f = res[t]; n   while (u != s) { n     int i = pre[u]; n     edge[i].f += f; n     edge[i ^ 1].f -= f; n     u = edge[i].u; n   } n } n int solve(int ss, int tt) { n   s = ss, t = tt; n   int ans = 0, flow = 0; n   while (spfa()) { n     augment(); n     ans += dis[t] * res[t]; n     flow += res[t]; n   } n   return ans; n } n }  // namespace MCMF n int id1[27], id2[27][MAXN], id3[MAXN], s, t, nid; n void solve() { n   for (int i = 1; i <= 26; ++i) id1[i] = ++nid; n   for (int i = 1; i <= 26; ++i) n     for (int j = 1; j <= n / 2; ++j) id2[i][j] = id2[i][n - j + 1] = ++nid; n   for (int i = 1; i <= n; ++i) id3[i] = ++nid; n   s = ++nid, t = ++nid; n   MCMF::init(nid); n   for (int i = 1; i <= n; ++i) MCMF::adde(s, id1[a[i]], 1, 0); n   for (int i = 1; i <= 26; ++i) n     for (int j = 1; j <= n / 2; ++j) MCMF::adde(id1[i], id2[i][j], 1, 0); n   for (int i = 1; i <= 26; ++i) n     for (int j = 1; j <= n; ++j) n       MCMF::adde(id2[i][j], id3[j], 1, a[j] == i ? b[j] : 0); n   for (int i = 1; i <= n; ++i) MCMF::adde(id3[i], t, 1, 0); n   printf( %d n , MCMF::solve(s, t)); n } n int main() { n   _w = scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     char c; n     _w = scanf(  %c , &c); n     a[i] = c -  a  + 1; n   } n   for (int i = 1; i <= n; ++i) _w = scanf( %d , b + i); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef int *arrint; n const int maxn = 2e3 + 55; n int main() { n   int h1, h2, a, b, i, j, k; n   scanf( %d , &h1), scanf( %d , &h2); n   scanf( %d , &a), scanf( %d , &b); n   k = 0; n   i = h1; n   j = 1; n   while (i < h2) { n     if (j == 1) { n       i = i + a * 8; n       j = 0; n       if (a <= b && i < h2) { n         k = -1; n         break; n       } n     } else { n       i = i + a * 12; n     } n     if (i >= h2) { n       break; n     } else { n       k++; n       i -= b * 12; n     } n   } n   printf( %d , k), printf( %c ,   n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   long long n = s.length(); n   reverse(s.begin(), s.end()); n   set<string> ans; n   vector<bool> dp2(n + 1, 0), dp3(n + 1, 0); n   dp2[1] = 1; n   dp3[2] = 1; n   for (long long i = 3; i < n - 5; ++i) { n     dp2[i] = dp3[i - 2] || n              (dp2[i - 2] && !(s[i] == s[i - 2] && s[i - 1] == s[i - 3])); n     dp3[i] = dp3[i] || dp2[i - 3]; n     if (i - 5 >= 0) n       dp3[i] = n           dp3[i] || (dp3[i - 3] && !(s[i] == s[i - 3] && s[i - 1] == s[i - 4] && n                                      s[i - 2] == s[i - 5])); n   } n   for (long long i = 0; i < n - 5; ++i) { n     if (dp2[i]) { n       string temp = s.substr(i - 1, 2); n       reverse(temp.begin(), temp.end()); n       ans.insert(temp); n     } n     if (dp3[i]) { n       string temp = s.substr(i - 2, 3); n       reverse(temp.begin(), temp.end()); n       ans.insert(temp); n     } n   } n   cout << ans.size() <<   n ; n   for (string i : ans) cout << i <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, i; n   cin >> n; n   int ara[n]; n   for (int i = 0; i < n; ++i) { n     cin >> ara[i]; n   } n   for (i = 1; i < n; i++) { n     if (ara[i] != ara[i - 1]) { n       cout <<  1 n ; n       return; n     } n   } n   cout << n << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using ll = long long; n using namespace std; n const int N = 1e6 + 10; n const int Mod = 0; n ll a[N], sum[N], p[N]; n int n, m, T, q; n int Read(); n void update(ll x) { n   vector<ll> v; n   x--; n   int cnt = 0; n   if (n <= 14) { n     for (int i = 1; i <= 14; i++) v.push_back(i); n   } else { n     for (int i = 1; i <= 14; i++) v.push_back(n - 14 + i); n   } n   for (int i = min(13, n - 1); i >= 0; i--) { n     int j = x / p[i]; n     a[++cnt] = v[j]; n     x %= p[i]; n     v.erase(v.begin() + j); n   } n   int st = max(n - 13, 1); n   for (int i = st, xx = 1; i <= n; i++, xx++) { n     sum[i] = sum[i - 1] + a[xx]; n   } n } n int main() { n   n = Read(), q = Read(); n   for (int i = 1; i <= n; ++i) { n     a[i] = i; n     sum[i] = sum[i - 1] + i; n   } n   p[0] = 1; n   for (int i = 1; i <= 14; i++) p[i] = p[i - 1] * i; n   ll now = 1; n   for (int i = 1; i <= q; i++) { n     int opt; n     opt = Read(); n     if (opt == 1) { n       int x = Read(), y = Read(); n       printf( %lld n , sum[y] - sum[x - 1]); n     } else { n       int x = Read(); n       now += x; n       update(now); n     } n   } n   return 0; n } n int Read() { n   int val = 0, opt = 1; n   char ch; n   while (!isdigit(ch = getchar())) n     if (ch ==  - ) opt = -1; n   while (isdigit(ch)) (val *= 10) += ch -  0 , ch = getchar(); n   return val * opt; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n   long long n, k; n   cin >> n >> k; n   string s; n   long long lo = 1, hi = n; n   while (1) { n     long long mid = lo + hi >> 1; n     if (hi - lo <= 50) { n       long long guess = rng() % (hi - lo + 1) + lo; n       cout << guess <<     << guess << endl; n       cin >> s; n       if (s ==  Yes ) exit(0); n       lo = max(1ll, lo - k), hi = min(n, hi + k); n       continue; n     } n     cout << lo <<     << mid << endl; n     cin >> s; n     if (s ==  Yes ) n       lo = max(lo - k, 1ll), hi = min(mid + k, n); n     else n       lo = max(mid - k, 1ll), hi = min(hi + k, n); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 50; n char s[N], t[N]; n int n, a[N], b[N], c[N]; n int main(void) { n   scanf( %d , &n); n   scanf( %s , s); n   scanf( %s , t); n   for (int i = 0; i < n; i++) { n     a[i] = s[i] -  a ; n     b[i] = t[i] -  a ; n   } n   for (int i = 0; i < n; i++) { n     c[i] += (a[i] + b[i]) / 2; n     if ((a[i] + b[i]) % 2) { n       c[i + 1] += 13; n     } n   } n   for (int i = n - 1; i >= 0; i--) { n     c[i - 1] += c[i] / 26; n     c[i] %= 26; n   } n   for (int i = 0; i < n; i++) { n     printf( %c , (char)( a  + c[i])); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j; n   int dif; n   int n, m; n   bool ans = true; n   char flag[100][101]; n   cin >> n >> m; n   for (i = 0; i < n; i++) cin >> flag[i]; n   for (i = 0; i < n; i++) { n     dif = flag[i][0]; n     for (j = 1; j < m; j++) n       if (flag[i][j] != dif) ans = false; n   } n   for (i = 1; i < n - 1; i++) n     for (j = 0; j < m; j++) n       if (flag[i][j] == flag[i - 1][j] || flag[i][j] == flag[i + 1][j]) { n         ans = false; n         break; n       } n   if (ans) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, e[111111], x, y, s, t, l, r, c, cc, yy[555555], pp[555555], n     xx[555555], f[111111], rr[111111], q1, q2, kk, p[111111], ll; n int qx[444444], qc[444444], ql[444444]; n int find(int x) { n   int y = x; n   while (x != p[x]) x = p[x]; n   while (x != y) { n     int t = p[y]; n     p[y] = x; n     y = x; n   } n   return x; n } n void add(int x, int cc, int l) { n   if (f[x]) { n     if (rr[x] + l <= c) p[find(cc)] = find(f[x] - 1); n     return; n   } n   rr[x] = l; n   f[x] = cc + 1; n   qx[q1] = x; n   qc[q1] = cc; n   ql[q1++] = l; n } n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < k; i++) cin >> e[i], e[i]--; n   for (int i = 0; i < m; i++) { n     cin >> x >> y; n     x--; n     y--; n     yy[++kk] = y; n     pp[kk] = xx[x]; n     xx[x] = kk; n     yy[++kk] = x; n     pp[kk] = xx[y]; n     xx[y] = kk; n   } n   cin >> s >> t; n   e[k++] = t - 1; n   l = 1; n   r = n + 5; n   while (l < r) { n     c = (l + r) / 2; n     for (int i = 0; i < n; i++) p[i] = i; n     memset(f, 0, sizeof(f)); n     q1 = q2 = 0; n     for (int i = 0; i < k; i++) add(e[i], e[i], 0); n     while (q1 != q2) { n       x = qx[q2]; n       cc = qc[q2]; n       ll = ql[q2++]; n       for (int w = xx[x]; w; w = pp[w]) add(yy[w], cc, ll + 1); n     } n     if (find(s - 1) == find(t - 1)) n       r = c; n     else n       l = c + 1; n   } n   if (l == n + 5) n     puts( -1 ); n   else n     cout << (l) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned long long MOD = 1e9 + 7; n const int INF = 1e9; n const unsigned long long INF64 = 9e18; n const long double EPS = 1e-9; n const long double PI = 3.14159265358979310000; n const unsigned long long MD = 535355424; n const unsigned long long T = 25342; n const int N = 200001; n const int M = 501; n int n, k; n bool prov(unsigned long long v) { n   unsigned long long s = 0, kk = 1; n   while (v / kk > 0) { n     s += v / kk; n     kk *= k; n   } n   if (s >= n) n     return 1; n   else n     return 0; n } n int main() { n   cin >> n >> k; n   if (k == 1) { n     cout << 1 << endl; n     return 0; n   } n   unsigned long long l, r, m; n   l = 0; n   r = INF64; n   while (l + 1 < r) { n     m = (l + r) / 2; n     if (prov(m)) n       r = m; n     else n       l = m; n   } n   cout << r; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int arr[100010]; n vector<int> v; n int main(void) { n   int n, k, i, j, totalcnt; n   scanf( %d %d , &n, &k); n   for (i = 1; i <= n; i++) { n     scanf( %d , &arr[i]); n     v.push_back(arr[i]); n     ; n   } n   if (k == 1) { n     sort(v.begin(), v.end()); n     printf( 1 n ); n   } else { n     int cnt = 0, sum = 0, mn = (1 << 29), indx, flag = 0; n     totalcnt = 0; n     for (i = 1; i <= n; i++) { n       sum = 0; n       cnt = 0; n       for (j = i;; j += k) { n         if (j > n) j %= n; n         sum += arr[j]; n         totalcnt++; n         cnt++; n         if (cnt == (n / k)) { n           break; n         } n       } n       if (mn > sum) { n         indx = i; n         mn = sum; n       } n       if (totalcnt == n) break; n     } n     printf( %d n , indx); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int n; n int k; n map<int, int> mp; n int S; n long long res; n struct linetree { n   map<int, int> rot; n   int s[22 * N][2]; n   int v[22 * N]; n   int ct; n   inline void ins(int p, int l, int r, int pos) { n     v[p]++; n     if (r - l == 1) { n       return; n     } n     int mid = (l + r) / 2; n     if (pos <= mid) n       ins(s[p][0] = s[p][0] ? s[p][0] : ++ct, l, mid, pos); n     else n       ins(s[p][1] = s[p][1] ? s[p][1] : ++ct, mid, r, pos); n   } n   inline int qry(int p, int l, int r, int dl, int dr) { n     if ((dl == l && dr == r) || p == 0) { n       return v[p]; n     } n     int mid = (l + r) / 2; n     int res = 0; n     if (dl < mid) res += qry(s[p][0], l, mid, dl, min(dr, mid)); n     if (mid < dr) res += qry(s[p][1], mid, r, max(dl, mid), dr); n     return res; n   } n   inline void cins(int q, int x) { n     if (rot.count(q) == 0) rot[q] = ++ct; n     ins(rot[q], 0, S, x); n   } n   inline int cqr(int q, int dl, int dr) { n     if (rot.count(q) == 0) return 0; n     return qry(rot[q], 0, S, dl, dr); n   } n } lt; n struct data { n   int x; n   int r; n   int q; n   friend bool operator<(data a, data b) { return a.r > b.r; } n } a[N]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d%d%d , &a[i].x, &a[i].r, &a[i].q); n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) { n     mp[a[i].x] = 1; n     mp[a[i].x + a[i].r] = 1; n     mp[a[i].x - a[i].r] = 1; n   } n   map<int, int>::iterator it, it1; n   for (it = mp.begin(), it1 = it, ++it1; it1 != mp.end(); ++it, ++it1) n     it1->second += it->second; n   S = mp.size(); n   for (int i = 1; i <= n; i++) { n     for (int j = a[i].q - k; j <= a[i].q + k; j++) n       res += lt.cqr(j, mp[a[i].x - a[i].r] - 1, mp[a[i].x + a[i].r]); n     lt.cins(a[i].q, mp[a[i].x]); n   } n   printf( %I64d , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n const int OO = INT_MAX, P = 10000; n int xd[] = {1, 0, -1, 0, -1, 1, 1, -1}; n int yd[] = {0, -1, 0, 1, 1, 1, -1, -1}; n int main() { n   ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   long long int t; n   cin >> t; n   while (t--) { n     long long int l, r; n     cin >> l >> r; n     if (l * 2 > r) n       cout << -1 <<     << -1 <<   n ; n     else n       cout << l <<     << 2 * l <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> a(n + 1, 0), ans(n + 1, -1), visited(n + 1, 0); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] > a[i - 1]) { n       ans[i] = a[i - 1]; n       visited[a[i]] = 1; n     } n   } n   int j = 1; n   for (int i = 1; i <= n; i++) { n     if (ans[i] == -1) { n       while (j <= n && visited[j]) j++; n       ans[i] = j; n       visited[j] = 1; n     } n   } n   for (int i = 1; i <= n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, a[1005], b[1005], c[1005], d[1005], ans, tot; n ; n char s[1005]; n long long calc() { n   long long cc = 0; n   for (long long i = 1; i <= n; i++) n     if (c[i]) { n       ans += (c[i] - 1) * (m - c[i]) * 4; n       for (long long j = i + 1; j <= n; j++) n         if (!c[j] || c[j] < c[j - 1]) n           break; n         else n           cc += (c[i] - 1) * (m - c[j]) * 4; n       for (long long j = i + 1; j <= n; j++) n         if (!c[j] || c[j] > c[j - 1]) n           break; n         else n           cc += (c[j] - 1) * (m - c[i]) * 4; n     } n   return cc; n } n int main() { n   scanf( %I64d%I64d , &n, &m); n   for (long long i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     for (long long j = 1; j <= m; j++) n       if (s[j] ==  . ) n         tot++, a[i]++, b[j]++; n       else n         c[i] = j, d[j] = i; n   } n   long long o, ct, su; n   o = ct = su = 0; n   for (long long i = 1; i <= n; i++) o += su * a[i], ct += a[i], su += ct; n   ans = o * 2; n   o = ct = su = 0; n   for (long long i = 1; i <= m; i++) o += su * b[i], ct += b[i], su += ct; n   ans += o * 2; n   ans += calc(); n   swap(n, m); n   for (long long i = 1; i <= n; i++) c[i] = d[i]; n   ans += calc(); n   printf( %.16lf , ((double)ans) / tot / tot); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sa[1007], n, t, x, d[1007], s; n bool f[1007], c[1007]; n int main() { n   scanf( %d%d , &n, &x); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &t), sa[t] = i; n     if (t == 0) c[i] = 1; n   } n   for (int i = 1; i <= n; ++i) { n     if (!c[i]) continue; n     int kt = 1, t2 = 1, j = i; n     while (j) { n       if (j == x) kt = 0, t = t2; n       j = sa[j], ++t2; n     } n     if (kt) d[++s] = t2 - 1; n   } n   f[0] = 1; n   for (int i = 1; i <= s; ++i) n     for (int j = 1000; j >= d[i]; --j) n       if (f[j - d[i]]) f[j] = 1; n   for (int i = 0; i + t <= n; ++i) n     if (f[i]) printf( %d n , t + i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> v; n   int n, i, j, k, value; n   cin >> n; n   int x = n; n   while (x--) { n     cin >> value; n     v.push_back(value); n   } n   for (i = 0; i < n; i++) n     for (j = 0; j < n; j++) { n       if (i == j) j++; n       for (k = j + 1; k <= n - 1; k++) { n         if (k == i) k++; n         if (k == n) break; n         if (v[i] == v[j] + v[k]) { n           cout << i + 1 <<     << k + 1 <<     << j + 1; n           return 0; n         } n       } n     } n   cout <<  -1 ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   int ans = 0; n   int n = s.length(); n   for (int i = 0; i < n; i++) { n     if (s[i] != s[n - i - 1]) { n       ans = -1; n       break; n     } n   } n   if (ans != -1) n     cout << 0 << endl; n   else { n     cout << 3 << endl; n     cout <<  R   << 2 << endl; n     cout <<  L   << s.length() << endl; n     cout <<  L   << s.length() - 1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string second, pre, suf; n int main() { n   ios::sync_with_stdio(false); n   cin >> second; n   int n = (int)second.size(); n   int l = 0; n   int r = n - 1; n   while (l + 1 < r - 1) { n     if (second[l] == second[r]) { n       pre += second[l]; n       suf += second[r]; n     } else { n       if (second[l] == second[r - 1]) n         pre += second[l], suf += second[r - 1]; n       else if (second[l + 1] == second[r]) n         pre += second[l + 1], suf += second[r]; n       else n         pre += second[l + 1], suf += second[r - 1]; n     } n     l += 2; n     r -= 2; n   } n   if (n % 4 != 0) { n     pre += second[n / 2]; n   } n   reverse(suf.begin(), suf.end()); n   pre = pre + suf; n   cout << pre; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1e6 + 42; n int k; n int f[6]; n long long dp[MX]; n long long eval(int val) { n   long long ret = 0; n   for (int dig = 0; dig < 6; dig++) { n     int d = val % 10; n     if (d % 3 == 0) ret = ret + 1LL * d / 3 * f[dig]; n     val = val / 10; n   } n   return ret; n } n void push(long long object, long long gain) { n   if (object >= MX) return; n   for (int i = MX - 1; i >= object; i--) n     dp[i] = max(dp[i], dp[i - object] + gain); n } n void prec() { n   for (int i = 0; i < MX; i++) dp[i] = -1e18; n   dp[0] = 0; n   for (int dig = 0; dig < 6; dig++) { n     int mult = 1; n     for (int t = 0; t < dig; t++) mult = mult * 10; n     mult = mult * 3; n     long long remain = 3 * (k - 1), object = mult, gain = f[dig]; n     while (remain) { n       if (remain % 2 == 0) { n         push(object, gain); n         remain--; n       } n       if (remain % 2 == 1) { n         push(object, gain); n         remain--; n       } n       object = object * 2; n       gain = gain * 2; n       remain = remain / 2; n     } n   } n } n long long solve(int cur) { n   long long ret = 0; n   for (int i = 0; i <= cur; i++) ret = max(ret, dp[i] + eval(cur - i)); n   return ret; n } n int main() { n   scanf( %i , &k); n   for (int i = 0; i < 6; i++) scanf( %i , &f[i]); n   prec(); n   int q; n   scanf( %i , &q); n   for (int i = 1; i <= q; i++) { n     int val; n     scanf( %i , &val); n     printf( %lld n , solve(val)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int logx = 30; n const long long int N = 1e6 + 5; n const long long int INF = 1e18 + 5; n const long long int mod = 321555123; n const double PI = 3.14159265358979323846; n inline long long int mul(long long int a, long long int b) { n   return (a * 1ll * b) % mod; n } n inline long long int sub(long long int a, long long int b) { n   long long int c = a - b; n   if (c < 0) c += mod; n   return c; n } n inline long long int add(long long int a, long long int b) { n   long long int c = a + b; n   if (c > mod) c -= mod; n   return c; n } n template <typename T> n T power(T x, T y, long long int m) { n   T ans = 1; n   while (y > 0) { n     if (y & 1LL) ans = (ans * x) % m; n     y >>= 1ll; n     x = (x * x) % m; n   } n   return ans % m; n } n vector<long long int> bit[N]; n long long int n, q, a[N], b[N]; n void Update(long long int idx, long long int val) { n   idx++; n   while (idx <= n) { n     bit[idx].push_back(val); n     idx += (idx & -idx); n   } n } n long long int Query(long long int idx, long long int val) { n   long long int sum = 0; n   idx++; n   while (idx > 0) { n     long long int lb = n         lower_bound(bit[idx].begin(), bit[idx].end(), val) - bit[idx].begin(); n     sum += lb; n     idx -= (idx & -idx); n   } n   return sum; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   cin >> n; n   long long int sum = 0; n   map<long long int, long long int> first; n   for (long long int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (long long int i = n - 1; i >= 0; i--) { n     first[a[i]]++; n     b[i] = first[a[i]]; n   } n   for (long long int i = 0; i < n; i++) { n     Update(i, b[i]); n   } n   for (long long int i = 1; i <= n + 1; i++) { n     sort(bit[i].begin(), bit[i].end()); n   } n   first.clear(); n   for (long long int i = 0; i < n; i++) { n     long long int l = i + 1; n     long long int r = n - 1; n     first[a[i]]++; n     sum += Query(r, first[a[i]]) - Query(l - 1, first[a[i]]); n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 50100; n int n, l[MAXN], p[MAXN], idx[MAXN]; n double ev[MAXN], el[MAXN]; n int idxCMP(int i, int j) { n   return p[i] * l[i] * (100 - p[j]) > p[j] * l[j] * (100 - p[i]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> l[i] >> p[i]; n     idx[i] = i; n   } n   sort(idx, idx + n, idxCMP); n   for (int i = 1; i <= n; i++) { n     ev[i] = n         ev[i - 1] + (el[i - 1] * (100 - p[idx[i - 1]]) / 100.0) + l[idx[i - 1]]; n     el[i] = el[i - 1] + l[idx[i - 1]] * p[idx[i - 1]] / 100.0; n   } n   cout << fixed << setprecision(10) << ev[n] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct segtree { n   vector<vector<int>> t; n   vector<int> d; n   int h, n, sz; n   inline void build_node(const int& x) { n     for (int j = 0; j < 26; ++j) { n       t[x][j] = t[x << 1][j] + t[x << 1 | 1][j]; n     } n   } n   inline void build(int x) { n     for (x /= 2; x > 0; x /= 2) { n       build_node(x); n     } n   } n   segtree(const string& s) { n     sz = s.size(); n     h = sizeof(int) * 8 - __builtin_clz(sz); n     n = 1 << h; n     d = vector<int>(n << 1, 0); n     t = vector<vector<int>>(n << 1, vector<int>(26, 0)); n     for (int i = 0; i < sz; ++i) { n       ++t[i + n][s[i] -  a ]; n     } n     for (int i = n - 1; i > 0; --i) { n       build_node(i); n     } n   } n   void apply(int x, int v) { n     if (x < n) { n       d[x] = v; n     } n   } n   void fill_nodes(const vector<int>& ind, vector<int> char_count, int dir) { n     for (const int& x : ind) { n       for (int i = 0; i < 26; ++i) { n         t[x][i] = 0; n       } n     } n     int ch_type = (dir == 1 ? 0 : 25); n     for (int i = (dir == 1 ? 0 : 0); i < ind.size(); ++i) { n       int x = ind[i]; n       int my_sz = 1 << (h - (sizeof(int) * 8 - __builtin_clz(x)) + 1); n       int have = 0; n       for (; have < my_sz; (dir == 1 ? ++ch_type : --ch_type)) { n         int take = min(my_sz - have, char_count[ch_type]); n         t[x][ch_type] += take; n         char_count[ch_type] -= take; n         have += take; n         if (have == my_sz) break; n       } n     } n   } n   void sort_nodes(const vector<int>& ind, int dir) { n     vector<int> char_count(26, 0); n     for (const int& x : ind) { n       for (int i = 0; i < 26; ++i) { n         char_count[i] += t[x][i]; n       } n     } n     fill_nodes(ind, char_count, dir); n   } n   void push_node(int x) { n     if (d[x] != 0) { n       fill_nodes(vector<int>({x << 1, x << 1 | 1}), t[x], d[x]); n       apply(x << 1, d[x]); n       apply(x << 1 | 1, d[x]); n       d[x] = 0; n     } n   } n   void push(int x) { n     for (int s = h; s > 0; --s) { n       int i = x >> s; n       if (d[i] != 0) { n         push_node(i); n       } n     } n   } n   void set(int l, int r, int dir) { n     int l0 = l + n; n     int r0 = r + n; n     push(l0); n     push(r0 - 1); n     vector<int> front, back; n     for (l += n, r += n; l < r; l /= 2, r /= 2) { n       if (l % 2) { n         front.push_back(l); n         apply(l, dir); n         ++l; n       } n       if (r % 2) { n         --r; n         back.push_back(r); n         apply(r, dir); n       } n     } n     reverse(back.begin(), back.end()); n     front.insert(front.end(), back.begin(), back.end()); n     sort_nodes(front, dir); n     push(l0); n     push(r0 - 1); n     build(l0); n     build(r0 - 1); n   } n   string to_string() { n     for (int i = 1; i < n; ++i) { n       push_node(i); n     } n     static char cstr[100010]; n     for (int i = 0; i < sz; ++i) { n       for (int j = 0; j < 26; ++j) { n         if (t[i + n][j] != 0) { n           cstr[i] = j +  a ; n         } n       } n     } n     cstr[sz] = 0; n     return string(cstr); n   } n }; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int N, Q; n   cin >> N >> Q; n   string s; n   cin >> s; n   segtree st(s); n   for (int qq = 0; qq < Q; ++qq) { n     int i, j, k; n     cin >> i >> j >> k; n     st.set(i - 1, j, (k == 1 ? 1 : -1)); n   } n   cout << st.to_string() <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int id, k; n }; n const int N = 2e5 + 10; n int a[N]; n int C[N]; n Node b[N]; n int n; n int lowbit(int x) { return (x & -x); } n int sum(int x) { n   int ret = 0; n   while (x > 0) { n     ret += C[x]; n     x -= lowbit(x); n   } n   return ret; n } n void add(int x, int d) { n   while (x <= n) { n     C[x] += d; n     x += lowbit(x); n   } n } n bool cmp(const Node& x, const Node& y) { n   if (x.k == y.k) return x.id < y.id; n   return x.k < y.k; n } n int main() { n   long long tot; n   int p; n   scanf( %d , &n); n   memset(C, 0, sizeof(C)); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   if (n == 1) { n     printf( 0 n ); n     return 0; n   } n   for (int i = 2; i <= n; i++) { n     b[i].k = min(a[i], i - 1); n     b[i].id = i; n   } n   sort(b + 2, b + n + 1, cmp); n   p = 2; n   tot = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] > i) { n       add(i + 1, 1); n       add(min(a[i], n) + 1, -1); n     } n     while (p <= n && b[p].k == i) { n       tot += sum(b[p].id); n       p++; n     } n     if (p > n) break; n   } n   printf( %I64d n , tot); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<long long int, long long int> p[300002]; n int see(long long int a, long long int b, long long int c) { n   for (long long int i = 0; i < c; i++) { n     if (p[i].first == a || p[i].first == b || p[i].second == a || n         p[i].second == b) n       continue; n     if (b == -1) n       return see(a, p[i].first, c) || see(a, p[i].second, c); n     else n       return 0; n   } n   return 1; n } n int main() { n   long long int n, m, i; n   cin >> n >> m; n   for (i = 0; i < m; i++) cin >> p[i].first >> p[i].second; n   if (see(p[0].first, -1, m) || see(p[0].second, -1, m)) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int num = 0; n int main() { n   cin >> n; n   int pre[n + 1]; n   pre[0] = 0; n   vector<int> all; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     pre[i + 1] = pre[i] + a; n   } n   for (int i = 1; i <= n; i++) { n     for (int k = 0; k < i; k++) { n       all.push_back(pre[i] - pre[k]); n     } n   } n   vector<pair<int, int>> op; n   for (auto i : all) { n     int cnt = 0; n     vector<pair<int, int>> top; n     for (int k = 0; k < n;) { n       map<int, int> m; n       m.insert(make_pair(pre[k], k)); n       bool findone = false; n       while (!findone && k < n) { n         int t = pre[k + 1] - i; n         if (m.count(t)) { n           findone = true; n           cnt++; n           top.push_back(make_pair(k + 1, m[t] + 1)); n         } n         m.insert(make_pair(pre[k + 1], k + 1)); n         k++; n       } n     } n     if (cnt > num) { n       num = cnt; n       op = top; n     } n   } n   cout << num << endl; n   for (auto v : op) cout << v.second <<     << v.first << endl; n } n


#include <bits/stdc++.h> n int N, XL, XR, YL, YR, SX, SY, VX, VY; n long long LN, LD = 1, RN = 1000000000000LL, RD = 1; n inline bool cmp(long long a, long long b, long long c, long long d) { n   return a * d < b * c; n } n void LIM(int v, int s, int l, int r) { n   if (v == 0) { n     if (s <= l || s >= r) { n       puts( -1 ); n       exit(0); n     } n   } else { n     l -= s; n     r -= s; n     if (v < 0) { n       int tmp = l; n       l = r; n       r = tmp; n       l = -l; n       r = -r; n       v = -v; n     } n     if (cmp(LN, LD, l, v)) { n       LN = l; n       LD = v; n     } n     if (cmp(r, v, RN, RD)) { n       RN = r; n       RD = v; n     } n   } n } n int main() { n   for (scanf( %d%d%d%d%d , &N, &XL, &YL, &XR, &YR); N--;) { n     scanf( %d%d%d%d , &SX, &SY, &VX, &VY); n     LIM(VX, SX, XL, XR); n     LIM(VY, SY, YL, YR); n   } n   if (cmp(LN, LD, RN, RD)) n     printf( %.12f n , (double)LN / LD); n   else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[200200], sum[200200]; n long long n; n void init() { n   f[0] = 1LL; n   for (int i = 1; i <= n; i++) f[i] = f[i - 1] * 10LL % 998244353; n   return; n } n void solve() { n   for (long long i = 1; i <= n; i++) { n     long long ans = 0; n     if (i == n) n       ans = 10; n     else if (i == n - 1) n       ans = 180; n     else { n       ans += (10LL * 9LL * 9LL * (n - i - 1) * f[n - i - 2]) % 998244353; n       ans += (10LL * 9LL * 2LL * f[n - i - 1]) % 998244353; n       ans %= 998244353; n     } n     printf( %lld  , ans); n     if (i != n) printf(   ); n   } n   return; n } n int main() { n   scanf( %lld , &n); n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1> n void deb(T1 e) { n   cout << e << endl; n } n template <class T1, class T2> n void deb(T1 e1, T2 e2) { n   cout << e1 <<     << e2 << endl; n } n template <class T1, class T2, class T3> n void deb(T1 e1, T2 e2, T3 e3) { n   cout << e1 <<     << e2 <<     << e3 << endl; n } n template <class T1, class T2, class T3, class T4> n void deb(T1 e1, T2 e2, T3 e3, T4 e4) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl; n } n template <class T1, class T2, class T3, class T4, class T5> n void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl; n } n template <class T1, class T2, class T3, class T4, class T5, class T6> n void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6 n        << endl; n } n template <class T> n T Abs(T x) { n   return x > 0 ? x : -x; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n long long Pow(long long B, long long P) { n   long long R = 1; n   while (P > 0) { n     if (P % 2 == 1) R = (R * B); n     P /= 2; n     B = (B * B); n   } n   return R; n } n long long BigMod(long long B, long long P, long long M) { n   long long R = 1; n   while (P > 0) { n     if (P % 2 == 1) { n       R = (R * B) % M; n     } n     P /= 2; n     B = (B * B) % M; n   } n   return R; n } n long long n, m; n vector<pair<long long, long long> > v; n long long mod = 1000000007LL; n long long stree[4 * 200050]; n map<long long, int> M; n set<long long> S; n void update(int node, int left, int right, int pos, long long val) { n   if (pos < left || right < pos) return; n   if (left == right) { n     stree[node] = val; n     return; n   } n   int mid = (left + right) / 2; n   update(node * 2, left, mid, pos, val); n   update(node * 2 + 1, mid + 1, right, pos, val); n   stree[node] = stree[node * 2] % mod + stree[node * 2 + 1] % mod; n   return; n } n long long query(int node, int left, int right, int srch_l, int srch_r) { n   if (srch_l <= left && right <= srch_r) return stree[node]; n   if (right < srch_l || left > srch_r) return 0; n   int mid = (left + right) / 2; n   long long ret1 = query(node * 2, left, mid, srch_l, srch_r); n   ret1 %= mod; n   long long ret2 = query(node * 2 + 1, mid + 1, right, srch_l, srch_r); n   ret2 %= mod; n   long long ret = (ret1 + ret2) % mod; n   return ret; n } n vector<int> adj[200050]; n int main(void) { n   long long a, b; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> a >> b, v.push_back(make_pair(a, b)); n     S.insert(a); n     S.insert(b); n   } n   S.insert(0); n   S.insert(n); n   int track = 0; n   for (__typeof((S).begin()) it = (S.begin()); it != (S).end(); ++it) n     M[*it] = track++; n   n = (int)M.size() - 1; n   update(1, 0, n, 0, 1); n   for (int i = 0; i < (int)v.size(); i++) { n     long long right = v[i].second; n     right = M[right]; n     adj[right].push_back(i); n   } n   for (int i = 1; i < (int)M.size(); i++) { n     long long val = 0; n     for (int j = 0; j < (int)adj[i].size(); j++) { n       int indx = adj[i][j]; n       int left = v[indx].first; n       int right = v[indx].second; n       left = M[left]; n       right = M[right]; n       val += query(1, 0, n, left, right); n       val %= mod; n     } n     update(1, 0, n, i, val); n   } n   deb(query(1, 0, n, 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 t; n   cin >> t; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     long long int a[n * k], c = 0; n     for (long long int i = 0; i < n * k; i++) { n       cin >> a[i]; n     } n     long long int m = (ceil)((double)n / 2); n     for (long long int i = (m - 1) * k; i < n * k; i += n - m + 1) { n       c += a[i]; n     } n     cout << c << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n namespace IO { n inline bool read() { return true; } n template <class T1, class... T2> n bool read(T1 &a, T2 &...rest) { n   return (cin >> a) ? read(rest...) : 0; n } n template <class... T> n bool read(char *a, T &...rest) { n   return (cin >> a) ? read(rest...) : 0; n } n template <class... T> n bool read(char *a, char *b, T &...rest) { n   return (cin >> a >> b) ? read(rest...) : 0; n } n template <class... T> n bool read(char *a, char *b, char *c, T &...rest) { n   return (cin >> a >> b >> c) ? read(rest...) : 0; n } n void put() { cout <<   n ; } n template <class T1, class... T2> n void put(const T1 num, const T2... rest) { n   cout << num <<    ; n   put(rest...); n } n void yes() { put( YES ); } n void no() { put( NO ); } n void ff() { cout.flush(); } n }  // namespace IO n using namespace IO; n using db = double; n using vi = vector<int>; n using pii = pair<int, int>; n using ll = long long; n using cp = complex<double>; n const int mod = 998244353, inv2 = (mod + 1) / 2; n const int maxn = 1e3 + 10; n const int inf = 1e9 + 3; n short d[41][maxn][maxn]; n ll n, m, k; n void prepare() {} n short a[maxn][maxn]; n queue<pair<short, short> > q[41]; n vector<pair<short, short> > c[41]; n short fff = 2e4; n short dx[4] = {1, -1, 0, 0}; n short dy[4] = {0, 0, 1, -1}; n void bfs(int k, short (&d)[maxn][maxn], queue<pair<short, short> > &q) { n   vi vis(44); n   vis[k] = 1; n   while (!q.empty()) { n     auto x = q.front().first, y = q.front().second; n     q.pop(); n     if (!vis[a[x][y]]) n       for (auto g : c[a[x][y]]) { n         auto x1 = g.first, y1 = g.second; n         if (d[x1][y1] == fff) { n           d[x1][y1] = d[x][y] + 1; n           q.push(make_pair(x1, y1)); n         } n       } n     vis[a[x][y]] = 1; n     for (int i = 0; i < 4; i++) { n       auto xx = x + dx[i], yy = y + dy[i]; n       if (d[xx][yy] != fff) continue; n       d[xx][yy] = d[x][y] + 1; n       q.push(make_pair(xx, yy)); n     } n   } n } n void Solve(int cas = 1) { n   read(n, m, k); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       for (int q = 1; q <= k; q++) { n         d[q][i][j] = fff; n       } n       read(a[i][j]); n       c[a[i][j]].emplace_back(i, j); n       d[a[i][j]][i][j] = 0; n       q[a[i][j]].push(make_pair(i, j)); n     } n   } n   for (int i = 1; i <= k; i++) { n     bfs(1, d[i], q[i]); n   } n   int q; n   read(q); n   while (q--) { n     short r1, c1, r2, c2; n     read(r1, c1, r2, c2); n     int min1 = abs(r1 - r2) + abs(c1 - c2); n     for (int i = 1; i <= k; i++) { n       min1 = min(min1, d[i][r1][c1] + 1 + d[i][r2][c2]); n     } n     put(min1); n   } n } n void Solvem() { n   int T; n   read(T); n   for (int i = 1; i <= T; i++) Solve(i); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   prepare(); n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long l1, l2, r1, r2, q; n long long p1, p2; n int main() { n   scanf( %lld , &q); n   for (int i = 1; i <= q; i++) { n     scanf( %lld%lld%lld%lld , &l1, &r1, &l2, &r2); n     p1 = l1; n     p2 = l2; n     if (p1 == p2) p2 = r2; n     printf( %lld %lld n , p1, p2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long x, long long y) { return (!y ? x : gcd(y, x % y)); } n long long lcm(long long x, long long y) { return x / gcd(x, y) * y; } n void file() {} n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   file(); n } n int dx[] = {-1, 0, 1, 0}; n int dy[] = {0, 1, 0, -1}; n const double eps = 1e-9; n const int mod = 1e9 + 7; n const int N = 1e5 + 5; n int n; n string s; n int dp[N][10][2]; n int upd(int x) { n   int sum = 0; n   while (x) sum += x % 10, x /= 10; n   return sum; n } n int solve(int idx, int sum, bool ok) { n   if (idx == n) { n     if (sum % 3 == 0) return 0; n     return 1e9; n   } n   int &ret = dp[idx][sum][ok]; n   if (~ret) return ret; n   ret = solve(idx + 1, sum, ok) + 1; n   if (ok || s[idx] !=  0 ) n     ret = min(ret, solve(idx + 1, upd(sum + s[idx] - 48), 1)); n   return ret; n } n void solve2(int idx, int sum, bool ok) { n   if (idx == n) { n     return; n   } n   int &ret = dp[idx][sum][ok]; n   if (ret == solve(idx + 1, sum, ok) + 1) { n     solve2(idx + 1, sum, ok); n     return; n   } n   cout << s[idx]; n   solve2(idx + 1, upd(sum + s[idx] - 48), 1); n   return; n } n int main() { n   fast(); n   memset((dp), -1, sizeof(dp)); n   cin >> s; n   n = (int)s.size(); n   bool ok = 0; n   for (int i = 0; i < (int)s.size(); i++) { n     ok |= s[i] ==  0 ; n   } n   int x = solve(0, 0, 0); n   if (x == n) { n     if (!ok) n       cout << -1; n     else n       cout << 0; n     return 0; n   } n   solve2(0, 0, 0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double x[111111]; n double sX, sY; n int n, K; n double Solve(int l, int r) { n   if (l > r) return 0; n   return min(hypot(x[l] - sX, sY), hypot(x[r] - sX, sY)) + x[r] - x[l]; n } n int main() { n   scanf( %d%d , &n, &K); n   K--; n   for (int i = 0; i < n; ++i) scanf( %lf , x + i); n   scanf( %lf%lf , &sX, &sY); n   double ans = 1e100; n   if (K == n) { n     sort(x, x + n); n     ans = Solve(0, n - 1); n     return printf( %.9f n , ans), 0; n   } n   K = x[K]; n   sort(x, x + n); n   K = lower_bound(x, x + n, K) - x; n   for (int l = 0; l <= K; l++) { n     double a = x[K] - x[l], b = x[n - 1] - x[K], t; n     ans = min(ans, 2 * b + a + hypot(x[l] - sX, sY) + Solve(0, l - 1)); n     ans = min(ans, 2 * a + b + hypot(x[n - 1] - sX, sY) + Solve(0, l - 1)); n   } n   for (int r = K; r < n; r++) { n     double a = x[K] - x[0], b = x[r] - x[K], t; n     ans = min(ans, 2 * b + a + hypot(x[0] - sX, sY) + Solve(r + 1, n - 1)); n     ans = min(ans, 2 * a + b + hypot(x[r] - sX, sY) + Solve(r + 1, n - 1)); n   } n   printf( %.9f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const int mod = 998244353; n using namespace std; n int a[200010], b[200010]; n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   int x; n   for (int i = 1; i <= n; i++) cin >> x, b[i] = a[i] - x; n   sort(b + 1, b + n + 1); n   long long ans = 0; n   for (int i = 1; i <= n - 1; i++) { n     if (b[i] > 0) n       ans += n - i; n     else { n       int j = upper_bound(b + 1, b + n + 1, -b[i]) - b; n       ans += max(0, n - j + 1); n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(nullptr); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void swapll(long long *a, long long *b) { n   long long tmp = *a; n   *a = *b; n   *b = tmp; n } n void swapc(char *a, char *b) { n   char tmp = *a; n   *a = *b; n   *b = tmp; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, t; n   cin >> n; n   cin >> t; n   vector<long long> v(n, 0); n   for (long long i = 0; i < n; i++) cin >> v[i]; n   ; n   long long count = 0; n   for (long long i = 0; i < n; i++) { n     t -= (86400 - v[i]); n     count++; n     if (t <= 0) { n       break; n     } n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x = 0, y; n   int a[100]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     x = max(x, a[i]); n   } n   y = a[n - 1]; n   printf( %d , y ^ x); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 250; n int t, a[N]; n void read_input() { n   for (int i = 0; i < N; i++) cin >> a[i]; n } n void solve() { n   int sum = 0; n   for (int i = 0; i < N; i++) sum += a[i] * a[i]; n   double P = sqrt(1. * sum / N); n   for (int i = 0; i < N; i++) n     if (abs(a[i]) > 2 * P) { n       cout <<  poisson n ; n       return; n     } n   cout <<  uniform n ; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   for (cin >> t; t--; read_input(), solve()) n     ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, m; n     cin >> n >> m; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         if (j == 1 || i == 1) n           cout <<  B ; n         else { n           cout <<  W ; n         } n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q; n long long s[101000], d[101000], ad[101000]; n int find(int l, int r, long long v) { n   int re = 0; n   while (l <= r) { n     int mid = (l + r) / 2; n     if (d[mid] <= v) { n       re = max(re, mid); n       l = mid + 1; n     } else { n       r = mid - 1; n     } n   } n   return re; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %I64d , &s[i]); n   sort(s + 1, s + n + 1); n   for (int i = 1; i < n; i++) { n     d[i] = s[i + 1] - s[i]; n   } n   d[0] = 0; n   d[n] = 1000000000000000010LL; n   sort(d + 1, d + n + 1); n   for (int i = 1; i <= n; i++) ad[i] = ad[i - 1] + d[i]; n   scanf( %d , &q); n   for (int i = 1; i <= q; i++) { n     long long l, r; n     scanf( %I64d%I64d , &l, &r); n     long long len = r - l; n     int k = find(0, n, len); n     printf( %I64d  , (len + 1) * (n - k) + ad[k]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1E6 + 10; n int n, a[maxn][20], b[maxn][20], c[maxn], LOG[maxn]; n bool Judge(int l, int r) { n   int len = LOG[r - l + 1]; n   int A = 100 * max(a[l][len], a[r - (1 << len) + 1][len]); n   int B = min(b[l][len], b[r - (1 << len) + 1][len]); n   return A < B; n } n int main() { n   int k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i][0]); n   for (int i = 1; i <= n; i++) scanf( %d , &b[i][0]); n   for (int j = 1; j < 20; j++) n     for (int i = 1; i <= n; i++) { n       if (i + (1 << j - 1) > n) break; n       a[i][j] = max(a[i][j - 1], a[i + (1 << (j - 1))][j - 1]); n       b[i][j] = min(b[i][j - 1], b[i + (1 << (j - 1))][j - 1]); n     } n   int now = 0, sum = 1; n   for (int i = 1; i <= n; i++) { n     if (sum >= i) n       LOG[i] = now - 1; n     else { n       sum <<= 1; n       ++now; n       LOG[i] = now - 1; n     } n   } n   LOG[1] = 0; n   for (int i = 1; i <= n; i++) { n     int L, R; n     L = i; n     R = n; n     while (R - L > 1) { n       int mid = (L + R) >> 1; n       if (Judge(i, mid)) n         L = mid; n       else n         R = mid; n     } n     int len = LOG[L - i + 1]; n     int A = 100 * max(a[i][len], a[L - (1 << len) + 1][len]); n     int B = min(b[i][len], b[L - (1 << len) + 1][len]); n     c[i] = min(A, B); n     len = LOG[R - i + 1]; n     A = 100 * max(a[i][len], a[R - (1 << len) + 1][len]); n     B = min(b[i][len], b[R - (1 << len) + 1][len]); n     c[i] = max(c[i], min(A, B)); n   } n   sort(c + 1, c + n + 1); n   double ans = 0; n   double N = n - 1; n   double M = k - 1; n   double v = (double)(k) / (double)(n); n   for (int i = 1; i <= n; i++) { n     if (n - i < k - 1) break; n     ans += v * (double)(c[i]); n     v = v / N * (N - M); n     N -= 1.00; n   } n   printf( %.10f , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool found; n int n, x, nums[1000], smaller, larger, eq; n void Naive() { n   int median = ((n + 1) / 2); n   sort(nums, nums + n); n   if (nums[--median] == x) { n     printf( 0 ); n     return; n   } n   if (found) { n     for (int i = 0; i < n && nums[i] <= x; i++) n       if (x == nums[i] && abs(smaller - median) > abs(i - median)) smaller = i; n   } n   larger = n - smaller - found; n } n void Smart() { n   larger = n - smaller - eq; n   if (found) { n     eq--; n     int diff = abs(smaller - larger); n     if (larger <= smaller) { n       if (diff <= eq) { n         larger = smaller; n         eq -= diff; n         larger += eq / 2 + (eq % 2); n         smaller += eq / 2; n       } else { n         larger += eq; n         eq = 0; n       } n     } else { n       if (diff <= eq) { n         smaller = larger; n         eq -= diff; n         larger += eq / 2 + (eq % 2); n         smaller += eq / 2; n       } else { n         smaller += eq; n         eq = 0; n       } n     } n   } n } n void Greedy() { n   Smart(); n   printf( %d , !found + abs(smaller - larger) - (larger > smaller)); n } n int main() { n   found = false; n   scanf( %d %d , &n, &x); n   for (int i = 0; i < n; i++) { n     scanf( %d , &nums[i]); n     smaller += (nums[i] < x); n     eq += (nums[i] == x); n     found |= (nums[i] == x); n   } n   Greedy(); n } n


#include <bits/stdc++.h> n using namespace std; n const int NN = 5050; n const int MM = 27272; n int a[MM], b[MM]; n vector<int> adj[NN]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , a + i, b + i); n     adj[a[i]].push_back(b[i]); n   } n   int mx = 0; n   for (int i = 1; i <= n; i++) { n     mx = max(mx, (int)adj[i].size()); n     sort(adj[i].begin(), adj[i].end()); n   } n   for (int i = 1; i <= n; i++) { n     int ans = 0; n     for (int j = 1; j <= n; j++) n       if (!adj[j].empty()) { n         int it = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin(); n         if (it == adj[j].size()) it = 0; n         int ed = adj[j][it]; n         if (ed < j) ed += n; n         if (j < i) ed += n; n         int sz = adj[j].size(); n         ans = max(ans, (sz - 1) * n + ed - i); n       } n     cout << ans <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f(long long x) { n   long long ans = x; n   while (ans) { n     x *= 10; n     x += (ans % 10); n     ans /= 10; n   } n   return x; n } n int main() { n   long long k, p; n   cin >> k; n   cin >> p; n   long long sum = 0; n   for (long long i = 1; i <= k; i++) sum += f(i); n   sum %= p; n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n using ll = long long; n using ld = long double; n  n int a[25][50005]; n  n const int MOD = 998244353; n  n int add(int a, int b){ n     a += b; n     if(a >= MOD) a -= MOD; n     return a; n } n  n int mul(int a, int b){ n     return (1LL*a*b)%MOD; n  n } n  n int pw(int a, int b){ n     if(b == 0) return 1; n     int res = pw(a, b/2); n     res = mul(res, res); n     if(b%2) res = mul(res, a); n     return res; n } n  n int main(){ n     ios_base::sync_with_stdio(false), cin.tie(0); n     cout.precision(10); n     cout << fixed; n  n     int n, m; n     cin >> n >> m; n     for(int i=1; i<=n; i++){ n         for(int j=1; j<=m; j++){ n             cin >> a[i][j]; n             a[i][j]--; n         } n     } n     int res = 0; n     for(int j=1; j<=m; j++){ n         vector <int> vec; n         for(int i=1; i<=n; i++){ n             vec.push_back(a[i][j]); n         } n         sort(vec.begin(), vec.end()); n         int ways = 1; n         for(int g=0; g<vec.size(); g++){ n             ways = mul(ways, vec[g] - g); n         } n         if(ways == 0) continue; n         res = add(res, ways); n     } n     int fact = 1; n     for(int i=1; i<=n; i++) fact = mul(fact, i); n     int p = add(mul(fact, m), MOD - res); n     p = mul(p, pw(fact, MOD-2)); n     cout << p; n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, x, cnt; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   cin >> n >> x; n   for (int i = 1; i <= n; i++) { n     if (x % i == 0 && x / i <= n) { n       cnt++; n     } n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int num; n   cin >> num; n   if (num <= 9) { n     cout << num << endl; n   } else if (10 < num && num <= 189) { n     num = num - 9; n     int tmp = num / 2; n     tmp = 9 + tmp + num % 2; n     if (num % 2) n       cout << tmp / 10 << endl; n     else n       cout << tmp % 10 << endl; n   } else if (190 <= num) { n     num = num - 189; n     int tmp = num / 3; n     if (num % 3 != 0) n       tmp = 100 + tmp; n     else n       tmp = 99 + tmp; n     if (num % 3 == 0) { n       cout << tmp % 10 << endl; n     } else if (num % 3 == 1) { n       cout << tmp / 100 << endl; n     } else { n       tmp = tmp / 10; n       tmp = tmp % 10; n       cout << tmp << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, ans1 = 0, ans2 = 0; n   cin >> n; n   vector<int> c(n); n   for (int i = 0; i < n; i++) cin >> c[i]; n   cin >> a >> b; n   if (a > b) swap(a, b); n   a--; n   b--; n   for (int i = a; i < b; i++) { n     ans1 += c[i]; n   } n   for (int i = 0; i < a; i++) { n     ans2 += c[i]; n   } n   for (int i = b; i < n; i++) { n     ans2 += c[i]; n   } n   cout << min(ans1, ans2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 5; n const int MOD = 1e9 + 7; n vector<int> g[N + N]; n int mat[N][N], p[N + N], sub[N + N], vis[N + N]; n int ans[N + N], instack[N + N], go = true, ct = 0; n vector<pair<int, int>> extime; n void putNumbers(int node) { n   vis[node] = 1; n   instack[node] = true; n   ct++; n   for (auto it : g[node]) { n     if (!vis[it]) { n       putNumbers(it); n     } else if (instack[it]) n       go = false; n   } n   instack[node] = false; n   extime.push_back({ct, node}); n   ct++; n } n void getAns(int node) { n   vis[node] = 1; n   ans[node] = max(ans[node], 1); n   for (auto it : g[node]) n     if (!vis[it]) { n       ans[it] = max(ans[it], ans[node] + 1); n     } n } n int root(int u) { n   while (p[u] != u) { n     p[u] = p[p[u]]; n     u = p[u]; n   } n   return u; n } n void merge(int uu, int vv) { n   int u = root(uu), v = root(vv); n   if (u == v) return; n   if (sub[u] < sub[v]) swap(u, v); n   p[v] = u; n   sub[u] += sub[v]; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m, i, j; n   cin >> n >> m; n   for (i = 1; i <= n + m; i++) { n     p[i] = i; n     sub[i] = 1; n   } n   for (i = 1; i <= n; i++) { n     string s; n     cin >> s; n     for (j = 0; j < m; j++) { n       if (s[j] ==  < ) n         mat[i][j + 1] = -1; n       else if (s[j] ==  = ) { n         merge(i, n + j + 1); n         mat[i][j + 1] = 0; n       } else n         mat[i][j + 1] = 1; n     } n   } n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) { n       int u = root(i), v = root(n + j); n       if (mat[i][j] < 0) { n         if (u == v) { n           cout <<  No n ; n           return 0; n         } n         g[u].push_back(v); n       } n       if (mat[i][j] > 0) { n         if (u == v) { n           cout <<  No n ; n           return 0; n         } n         g[v].push_back(u); n       } n     } n   for (i = 1; i <= n + m; i++) n     if (!vis[i] && p[i] == i) { n       putNumbers(i); n       if (!go) { n         cout <<  No n ; n         return 0; n       } n     } n   sort(extime.begin(), extime.end()); n   reverse(extime.begin(), extime.end()); n   memset(vis, 0, sizeof(vis)); n   for (auto it : extime) n     if (!vis[it.second]) { n       getAns(it.second); n     } n   cout <<  Yes n ; n   for (i = 1; i <= n + m; i++) { n     cout << ans[root(i)] <<    ; n     if (i == n) cout <<   n ; n   } n   cout <<   n ; n   return 0; n } n


#include<iostream> n #include<string> n #include<cstring> n #include<cmath> n #include<algorithm> n #include<queue> n #include<iomanip> n #include<map> n #include<cstdio> n #include<stack> n #include<set> n using namespace std; n #define endl    n  n #define IOS ios::sync_with_stdio(false),cin.tie(0), cout.tie(0) n typedef long long ll; n typedef unsigned long long ull; n typedef pair<int, int> pii; n typedef pair<long, long>pll; n const int inf = 0x3f3f3f3f; n const ll lnf = 0x3f3f3f3f3f3f3f3f; n const double pi = acos(-1.0); n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } n #define re(i,a,b) for(int i = a;i <= b;i++) n #define rre(i,a) for(int i = 0;i < a;i++) n #define prre(i,a) for(int i = a;i >= 0;i--) n #define pre(i,a) for(int i = a;i > 0;i--) n #define bug system( pause ) n const double eps = 1e-6; n const int N = 1e6 + 10; n const int M = 2e6 + 10; n const int mod = 1e9 + 7; n  n int n, t, x; n map<pii, int>mp; n int ask(int l, int r) n { n  if (mp.count(make_pair(l, r)))return mp[make_pair(l, r)]; n  cout <<  ?   << l <<     << r << endl; n  cout.flush(); n  int sum; n  cin >> sum; n  int num = r - l + 1 - sum; n  mp[make_pair(l, r)] = num; n  return num; n } n  n int query(int l, int r, int k) n { n  if (l == r)return l; n  int mid = (l + r) >> 1; n  int v = ask(l, mid); n  if (v < k)return query(mid + 1, r, k - v); n  else return query(l, mid, k); n } n  n void update(int l, int r, int pos) n { n  if (mp.count(make_pair(l, r)))mp[make_pair(l, r)]--; n  if (l == r)return; n  int mid = (l + r) >> 1; n  if (pos <= mid)update(l, mid, pos); n  if (pos > mid)update(mid + 1, r, pos); n } n  n int main() n { n  cin >> n >> t; n  for (int i = 1; i <= t; i++) n  { n   cin >> x; n   int pos = query(1, n, x); n   update(1, n, pos); n   cout <<  !   << pos << endl; n   cout.flush(); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 5; n const int LOGN = 31; n int fwt[MAXN]; n int P[MAXN] = {0}; n int n; n void update(int v, int d) { n   v++; n   for (; v <= n; v += v & -v) fwt[v] += d; n } n int query(int v) { n   int sum = 0; n   for (; v > 0; v -= v & -v) sum += fwt[v]; n   return sum; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int j = 0; j < 2; j++) { n     memset(fwt, 0, sizeof(fwt)); n     for (int i = 0; i < n; i++) { n       int v; n       cin >> v; n       P[i] += v - query(v); n       update(v, 1); n     } n   } n   int c = 0; n   for (int i = n - 1; i >= 0; i--) { n     int mod = n - i; n     if (P[i] >= mod) { n       P[i] -= mod; n       if (i) P[i - 1]++; n     } n   } n   memset(fwt, 0, sizeof(fwt)); n   for (int i = 0; i < n; i++) update(i, 1); n   for (int i = 0; i < n; i++) { n     int sum = 0; n     int pos = 0; n     for (int j = LOGN; j >= 0; j--) { n       if (pos + (1LL << j) < n && sum + fwt[pos + (1LL << j)] < P[i] + 1) { n         sum += fwt[pos + (1LL << j)]; n         pos += (1LL << j); n       } n     } n     cout << (pos) <<    ; n     update(pos, -1); n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int count = 0, size; n   cin >> size; n   char c; n   vector<char> num; n   for (int i = 0; i < size; i++) { n     cin >> c; n     num.push_back(c); n   } n   for (int i = 0; i < num.size(); i++) { n     if (num[i] ==  8 ) count++; n     if ((size / 11) < count) count = (size / 11); n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3000; n vector<int> E[MAXN]; n long long dp[MAXN][MAXN]; n int P[MAXN][MAXN]; n int T[MAXN][MAXN]; n int n; n bool cmp(int a, int b) { return dp[a] > dp[b]; } n void dfs(int x, int p, int r) { n   P[r][x] = p; n   int d = 1; n   for (int i = 0; i < E[x].size(); ++i) { n     int v = E[x][i]; n     if (v != p) { n       dfs(v, x, r); n       d += T[r][v]; n     } n   } n   T[r][x] = d; n } n long long dp_get(int u, int v) { n   if (u == v || dp[u][v] != 0) return dp[u][v]; n   long long d = n       max(dp_get(u, P[u][v]), dp_get(v, P[v][u])) + T[u][v] * 1LL * T[v][u]; n   dp[u][v] = d; n   dp[v][u] = d; n   return d; n } n void solve() { n   scanf( %d , &n); n   for (int i = 1; i < n; ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     --x, --y; n     E[x].push_back(y); n     E[y].push_back(x); n   } n   for (int i = 0; i < n; ++i) dfs(i, -1, i); n   long long bestres = 0; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < i; ++j) bestres = max(bestres, dp_get(i, j)); n   printf( %I64d n , bestres); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class ReverseBit { n  public: n   ReverseBit(int size) : bit_(size + 1, 0) {} n   void Add(int pos, int num); n   int GetMax(int pos) const; n  n  private: n   static int Lsb(int num) { return num & -num; } n   vector<int> bit_; n }; n void ReverseBit::Add(int pos, int num) { n   pos = bit_.size() - pos; n   while (pos < (int)bit_.size()) { n     bit_[pos] = max(bit_[pos], num); n     pos += Lsb(pos); n   } n } n int ReverseBit::GetMax(int pos) const { n   pos = bit_.size() - pos; n   int res = 0; n   while (pos > 0) { n     res = max(res, bit_[pos]); n     pos -= Lsb(pos); n   } n   return res; n } n struct Receipt { n   int sum; n   int time; n }; n int main() { n   int n; n   cin >> n; n   vector<Receipt> last_receipts(n); n   for (auto &r : last_receipts) { n     cin >> r.sum; n     r.time = 0; n   } n   int updates; n   cin >> updates; n   ReverseBit bit(updates + 2); n   for (int i = 1; i <= updates; i += 1) { n     int type; n     cin >> type; n     if (type == 1) { n       int id, sum; n       cin >> id >> sum; n       last_receipts[id - 1] = Receipt{.sum = sum, .time = i}; n     } else { n       int sum; n       cin >> sum; n       bit.Add(i, sum); n     } n   } n   for (const auto &r : last_receipts) { n     cout << max(r.sum, bit.GetMax(r.time + 1)) <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1000010]; n int main() { n   int k; n   cin >> k; n   scanf( %s , s); n   int n = strlen(s); n   int a[n + 1]; n   a[0] = 0; n   for (int i = 1; i < n + 1; i++) { n     a[i] = a[i - 1] + ((s[i - 1] ==  1 ) ? 1 : 0); n   } n   long long int ans = 0; n   for (int i = 1; i < n + 1; i++) { n     int ss = a[i - 1] + k; n     if (a[n] < ss) continue; n     int g = lower_bound(a + i, a + n + 1, ss) - a; n     int h = upper_bound(a + i, a + n + 1, ss) - a; n     ans += (h - g); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(long long x) { cerr << x; } n void __print(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   long long 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 long long Power(long long a, long long n, long long mod) { n   long long res = 1; n   while (n) { n     if (n % 2 != 0) { n       res = ((res % mod) * (a % mod)) % mod; n       n--; n     } else { n       a = ((a % mod) * (a % mod)) % mod; n       n /= 2; n     } n   } n   return res; n } n void AllPossibilities(vector<long long> &arr, vector<long long> &answers, n                       long long index, long long sum) { n   if (index == arr.size()) { n     answers.push_back(sum); n     return; n   } n   AllPossibilities(arr, answers, index + 1, sum + arr[index]); n   AllPossibilities(arr, answers, index + 1, sum); n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long getSum(long long n) { n   long long sum = 0; n   while (n != 0) { n     sum = sum + n % 10; n     n = n / 10; n   } n   return sum; n } n long long myceil(long long n, long long x) { n   long long y; n   if (n % x == 0) { n     y = n / x; n     return y; n   } else { n     y = n / x + 1; n     return y; n   } n } n long long md = 1000000007; n vector<long long> fact, inv; n void inverse(long long n) { n   if (n >= inv.size()) { n     long long size = inv.size(); n     size = size == 0 ? 1 : size; n     inv.resize(n + 1); n     inv[0] = 1; n     for (long long i = size; i <= n; i++) inv[i] = Power(fact[i], md - 2, md); n   } n } n void factorial(long long n) { n   if (n >= fact.size()) { n     long long size = fact.size(); n     size = size == 0 ? 1 : size; n     fact.resize(n + 1); n     fact[0] = 1; n     for (long long i = size; i <= n; i++) fact[i] = (fact[i - 1] * i) % md; n   } n } n long long ncr(long long n, long long r) { n   return (((fact[n] * inv[r]) % md) * inv[n - r]) % md; n } n long long primes[1300000]; n void Sieve() { n   bool IsPrime[1300000]; n   memset(IsPrime, true, sizeof(IsPrime)); n   for (long long p = 2; p * p < 1300000; p++) { n     if (IsPrime[p] == true) { n       for (long long i = p * p; i < 1300000; i += p) IsPrime[i] = false; n     } n   } n   long long index = 0; n   for (long long p = 2; p < 1300000; p++) n     if (IsPrime[p]) { n       primes[index] = p; n       index++; n     } n } n void q1(); n void q2(); n void q3(); n void q4(); n void q5(); n void pr(vector<vector<long long>> v); n int32_t main() { n   q1(); n   return 0; n } n void q1() { n   long long n; n   cin >> n; n   long long sum = 0; n   for (long long i = 0; i < n; i++) { n     long long x; n     cin >> x; n     sum += x; n   } n   long long resp = 0; n   for (long long i = 1; i <= 5; i++) n     if ((i + sum) % (n + 1) != 1) resp++; n   cout << resp; n } n void pr(vector<vector<long long>> v) {} n void q2() { n   long long n; n   cin >> n; n   long long arr[n]; n   for (long long i = 0; i < n; i++) cin >> arr[i]; n   sort(arr, arr + n); n   bool set = true; n   for (long long i = 0; i < n - 1; i++) { n     if (arr[i] == arr[i + 1]) { n       set = false; n       break; n     } n   } n   if (set) n     cout <<  NO  n          <<   n ; n   else { n     cout <<  YES  n          <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxx = 1e6 + 7; n const long long maxn = 1e6 + 7; n const long long mod = 998244353; n const long long maxs = 500000 + 7; n const long long maxm = 400000 + 7; n const long long maxk = 1008 + 7; n const long long maxw = 100 + 7; n const long long maxh = 100 + 7; n const double pi = 3.1415926; n const long long ten = 10; n const long long ooi = 1000000; n const long long ool = 1e18 + 7; n const long double eps = 1e-8; n const int apsz = 26; n long long n; n void init() { cin >> n; } n void solve() { n   vector<long long> a(n, 0); n   vector<long long> b(n, 0); n   vector<long long> pos(n); n   for (long long i = (0); i < (n); i++) cin >> a[i]; n   for (long long i = (0); i < (n); i++) cin >> b[i]; n   sort(b.begin(), b.end()); n   for (long long i = (0); i < (n); i++) { n     long long ans = 0; n     long long lt = i; n     long long rt = n - i - 1; n     ans = (lt + 1) * (rt + 1); n     ans *= a[i]; n     pos[i] = ans; n   } n   sort(pos.begin(), pos.end(), greater<long long>()); n   long long ans = 0; n   long long p1 = 0; n   while (p1 < n) { n     pos[p1] %= mod; n     ans += (b[p1] * pos[p1]) % mod; n     ans %= mod; n     p1++; n   } n   cout << ans << endl; n } n int main(void) { n   ios::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(0); n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string int_to_string(int a) { n   stringstream ss; n   ss << a; n   return ss.str(); n } n string double_to_string(double a) { n   stringstream ss; n   ss << a; n   return ss.str(); n } n string float_to_string(float a) { n   stringstream ss; n   ss << a; n   return ss.str(); n } n string long_to_string(long a) { n   stringstream ss; n   ss << a; n   return ss.str(); n } n string long_long_to_string(long long a) { n   stringstream ss; n   ss << a; n   return ss.str(); n } n int string_to_int(string s) { return atoi(s.c_str()); } n float string_to_float(string s) { return atof(s.c_str()); } n long string_to_long(string s) { return atol(s.c_str()); } n long long string_to_long_long(string s) { return atoll(s.c_str()); } n int main() { n   long long n, c = 0; n   cin >> n; n   for (long long i = 1; i <= n; i *= 10) c += (n - (i - 1)); n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 1, INF = 1e9 + 1; n int n, q, a, b, p, t; n pair<long double, long double> st[N], lf, rg; n pair<long double, long double> merge(pair<long double, long double> a, n                                      pair<long double, long double> b) { n   long double l1 = a.first, r1 = a.second, l2 = b.first, r2 = b.second; n   if (a.first < 0 and a.second < 0) return b; n   if (b.first < 0 and b.second < 0) return a; n   return pair<long double, long double>( n       l1 * l2 / (1 - r1 * (1 - l2)), n       r2 + r1 * l2 * (1 - r2) / (1 - (r1 * (1 - l2)))); n } n pair<long double, long double> query(int l, int r) { n   lf = rg = pair<long double, long double>(-1, -1); n   l += n - 1, r += n; n   while (l < r) { n     if (l & 1) lf = merge(lf, st[l++]); n     if (r & 1) rg = merge(st[--r], rg); n     l /= 2, r /= 2; n   } n   return merge(lf, rg); n } n void update(int k, long double v) { n   k += n - 1; n   st[k] = pair<long double, long double>(v, v); n   while (k) k /= 2, st[k] = merge(st[2 * k], st[2 * k + 1]); n } n int main() { n   scanf( %d%d , &n, &q); n   for (int i = n; i < 2 * n; ++i) { n     scanf( %d%d , &a, &b); n     st[i] = pair<long double, long double>(1.0 * a / b, 1.0 * a / b); n   } n   for (int i = n - 1; i >= 0; --i) st[i] = merge(st[2 * i], st[2 * i + 1]); n   for (int i = 0; i < q; ++i) { n     scanf( %d , &t); n     if (t == 1) { n       scanf( %d%d%d , &p, &a, &b); n       update(p, 1.0L * a / b); n     } else { n       scanf( %d%d , &a, &b); n       printf( %lf n , (double)query(a, b).first); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   register int num = 0; n   register char ch = getchar(); n   while (ch >  9  || ch <  0 ) ch = getchar(); n   while (ch <=  9  && ch >=  0 ) num = num * 10 + ch -  0 , ch = getchar(); n   return num; n } n int num[10]; n inline void write(int x) { n   register int cnt = 0; n   if (!x) { n     printf( 0 ); n     return; n   } n   while (x) num[++cnt] = x % 10, x /= 10; n   while (cnt) putchar(num[cnt--] +  0 ); n } n struct node { n   int next, to, w; n } e[300020 * 2]; n int n, m; n int head[300020], cnt; n int sz[300020], fa[300020], tag[300020], a[300020], tot, flag; n long long dth[300020], ans, mx[300020], dis[300020]; n inline void adde(int x, int y, int w) { n   e[++cnt].to = y; n   e[cnt].next = head[x]; n   e[cnt].w = w; n   head[x] = cnt; n } n void dfs(int x) { n   for (int i = head[x]; i; i = e[i].next) { n     if (e[i].to == fa[x]) continue; n     dth[e[i].to] = dth[x] + e[i].w; n     fa[e[i].to] = x; n     dfs(e[i].to); n   } n } n void dfs2(int x) { n   sz[x] = 1; n   for (int i = head[x]; i; i = e[i].next) { n     if (e[i].to == fa[x] || tag[e[i].to]) continue; n     dis[x] = max(dis[x], dis[e[i].to] + e[i].w); n     dfs2(e[i].to); n     sz[x] += sz[e[i].to]; n   } n } n void init() { n   dfs(1); n   int x = n; n   while (x) tag[x] = 1, a[++tot] = x, x = fa[x]; n   for (register int i = 1; i <= tot + 1; i++) mx[i] = -1e16; n   for (register int i = tot; i >= 1; i--) { n     int x = a[i]; n     dfs2(x); n     if (sz[x] > 1) mx[i] = max(mx[i + 1], dis[x] + dth[x]); n     if (i < tot) { n       ans = max(ans, dth[n] + dis[x] - dth[x] + mx[i + 1]); n       if (sz[x] > 1) n         ans = max(ans, dth[n] + dis[x] - dth[x] + dth[a[i + 1]]); n       else if (i < tot - 1) n         ans = max(ans, dth[n] + dis[x] - dth[x] + dth[a[i + 2]]); n     } n     if (sz[x] > 2) flag = 1; n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (register int i = 1; i <= n - 1; i++) { n     int x, y, w; n     scanf( %d %d %d , &x, &y, &w); n     adde(x, y, w), adde(y, x, w); n   } n   init(); n   while (m--) { n     int l = read(); n     long long cur = min(dth[n], ans + l); n     if (flag) cur = max(cur, dth[n]); n     printf( %I64d n , cur); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   char ch = getchar(); n   int ret = 0, f = 1; n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar(); n   return ret * f; n } n const double inf = 1e30, eps = 1e-10; n const int mx = 100005, md = 1e6; n struct P { n   double x, y; n   bool operator<(const P& a) const { return x == a.x ? y < a.y : x < a.x; } n   bool operator==(const P& a) const { n     return fabs(x - a.x) < eps && fabs(y - a.y) < eps; n   } n   bool operator!=(const P& a) const { n     return fabs(x - a.x) > eps || fabs(y - a.y) > eps; n   } n   double operator*(const P& a) const { return x * a.y - y * a.x; } n   P operator-(const P& a) const { return (P){x - a.x, y - a.y}; } n } t[mx], st, ed; n int f[mx], s[mx][2], rt, tot; n inline void rot(int x) { n   int y = f[x], z = f[y], p = y[s][0] == x; n   if (z) n     z[s][z[s][1] == y] = x; n   else n     rt = x; n   f[x] = z, f[y] = x, s[x][p][f] = y; n   s[y][p ^ 1] = s[x][p], s[x][p] = y; n } n inline void spl(int x, int o = 0) { n   for (int y = 0; f[x] ^ o; rot(x)) n     if (f[y = f[x]] ^ o) rot((s[y][0] == x) == (s[f[y]][0] == y) ? y : x); n } n inline int ins(P x) { n   int cu = rt, ls = 0; n   while (cu) { n     if (t[cu] == x) { n       spl(cu); n       return cu; n     } n     ls = cu, cu = s[cu][t[cu] < x]; n   } n   f[++tot] = ls, s[ls][t[ls] < x] = tot, t[tot] = x; n   spl(tot); n   return tot; n } n inline int fnd(P x) { n   int cu = rt; n   while (cu) { n     if (t[cu] == x) return cu; n     cu = s[cu][t[cu] < x]; n   } n   return -1; n } n inline int pre(int id) { n   spl(id); n   int cu = s[rt][0]; n   while (s[cu][1]) cu = s[cu][1]; n   return cu; n } n inline int nxt(int id) { n   spl(id); n   int cu = s[rt][1]; n   while (s[cu][0]) cu = s[cu][0]; n   return cu; n } n inline void del(int id) { n   int pr = pre(id), nx = nxt(id); n   spl(pr), spl(nx, rt), s[s[rt][1]][0] = 0; n } n inline void add(P a) { n   int id = ins(a); n   int pr = pre(id), nx = nxt(id), ppr, nnx; n   if (pr && nx && t[nx] != ed && ((t[pr] - a) * (t[nx] - a)) > 0) { n     del(fnd(a)); n     return; n   } n   while (1) { n     pr = pre(id); n     ppr = pre(pr); n     if (ppr && ((t[pr] - t[ppr]) * (a - t[ppr])) <= 0) n       del(pr); n     else n       break; n   } n   while (1) { n     nx = nxt(id); n     nnx = nxt(nx); n     if (t[nx] != ed && nnx && t[nnx] != ed && ((t[nx] - a) * (t[nnx] - a)) <= 0) n       del(nx); n     else n       break; n   } n } n inline int qry(double a) { n   int cu = rt, re = 0; n   t[0].x = -1; n   while (cu) { n     if (t[cu].x <= a + eps && t[re].x < t[cu].x) re = cu; n     cu = s[cu][t[cu].x <= a + eps]; n   } n   return re; n } n int n, ls; n double m; n int main() { n   cin >> n >> m; n   st = (P){0, 0}, ed = (P){inf, inf}; n   t[rt = tot = 1] = st; n   ins(ed); n   for (int i = 1; i <= n; i++) { n     int op = read(), a = (ls + read()) % md + 1, b = (ls + read()) % md + 1; n     if (op == 1) { n       add((P){(double)a, (double)b}); n     } else { n       double x = (double)b / a, y = (double)m / a; n       int po = qry(x), nx = nxt(po); n       if (fabs(t[po].x - x) < eps && t[po].y < y + eps) n         ls = i, printf( YES n ); n       else if (t[nx] == ed) n         printf( NO n ); n       else { n         double inc = n             t[po].y + (t[nx].y - t[po].y) / (t[nx].x - t[po].x) * (x - t[po].x); n         if (inc <= y + eps) n           ls = i, printf( YES n ); n         else n           printf( NO n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)7 + (int)1e9; n const int N = 1000005; n const double PI = 4 * atan(1); n const double eps = 1e-10; n const long long oo = 1e10; n const int K = 26; n struct query { n   int a, t, x; n   query() { a = -1, t = -1, x = -1; } n   query(int _a, int _t, int _x) { n     a = (_a); n     t = (_t); n     x = (_x); n   } n }; n int n; n unordered_map<int, int> ma; n vector<query> qu; n set<int> ss; n set<int> t[N]; n unordered_map<int, int> maa[N]; n int mx = 1; n int mt = 0; n int sz[N]; n vector<int> tree[N]; n void update(int val, int pos, int upd) { n   for (; pos <= sz[val]; pos += (pos) & (-pos)) { n     tree[val][pos] += upd; n   } n } n int get(int val, int pos) { n   int to = 0; n   for (; pos; pos -= (pos) & (-pos)) { n     to += tree[val][pos]; n   } n   return to; n } n void ins(int x, int t) { update(x, t, 1); } n void rem(int x, int t) { update(x, t, -1); } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x, y, w; n     cin >> x >> y >> w; n     qu.push_back(query(x, y, w)); n     ss.insert(w); n   } n   for (int u : ss) { n     ma[u] = mx++; n   } n   for (query& q : qu) { n     q.x = ma[q.x]; n     t[q.x].insert(q.t); n   } n   for (int i = 1; i <= mx; i++) { n     if (t[i].size() == 0) continue; n     mt = 1; n     for (int u : t[i]) { n       maa[i][u] = mt++; n     } n     sz[i] = mt; n     tree[i].resize(sz[i] + 1); n   } n   for (query& q : qu) { n     q.t = maa[q.x][q.t]; n   } n   for (query q : qu) { n     if (q.a == 1) { n       ins(q.x, q.t); n     } else if (q.a == 2) { n       rem(q.x, q.t); n     } else { n       cout << get(q.x, q.t) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(pair<int, int> a, pair<int, int> b) { n   return (a.first == b.first) ? a.second < b.second : a.first < b.first; n } n long long int modInverse(long long int a) { n   long long int m = 1000000007; n   long long int y = 0, x = 1; n   while (a > 1) { n     long long int q = a / m; n     long long int t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += 1000000007; n   return x; n } n long long int binpow(long long int a, long long int p) { n   if (p == 0) return 1; n   long long int ret = binpow(a, p / 2); n   ret *= ret; n   ret %= 1000000007; n   if (p % 2) { n     ret *= a; n     ret %= 1000000007; n   } n   return ret; n } n int f[54][54][54][54]; n char a[100], b[100]; n int n; n bool check(int x, int y) { return (a[x] == a[y] || b[x] == b[y]); } n int dfs(int i, int j, int l, int r) { n   if (f[i][j][l][r]) return 0; n   if (i == 3) return check(j, r) && check(l, r); n   if (check(l, r)) n     if (dfs(i - 1, i - 3, j, r)) return 1; n   if (check(i - 3, r)) n     if (dfs(i - 1, r, j, l)) return 1; n   f[i][j][l][r] = 1; n   return 0; n } n void solve() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; n   if (n == 1 || dfs(n, n - 2, n - 1, n)) n     cout <<  YES ; n   else n     cout <<  NO ; n   return; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int t = 1; n   while (t--) { n     solve(); n   } n } n