#include <bits/stdc++.h> n using namespace std; n bool comp(long long x, long long y) { return x > y; } n int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; n int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; n int n, k; n char s[100000 + 5]; n int prefix[100000 + 5]; n bool check(int x, int i) { n   int tmp = prefix[min(n - 1, i + x)]; n   if (i - x > 0) tmp -= prefix[i - x - 1]; n   if (tmp >= k + 1) return true; n   return false; n } n int main() { n   cin >> n >> k; n   cin >> s; n   for (int i = 0; i < n; i++) { n     if (i != 0) prefix[i] = prefix[i - 1]; n     prefix[i] += (s[i] ==  0 ); n   } n   int res = 1e9; n   for (int i = 0; i < n; i++) { n     int ans = 1e9; n     if (s[i] ==  0 ) { n       int l = 0, r = 1e9; n       while (l != r) { n         int mid = (l + r - 1) / 2; n         if (check(mid, i)) { n           r = mid; n           ans = min(ans, mid); n         } else n           l = mid + 1; n       } n       res = min(res, ans); n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const int maxn = 3000 + 10; n int n, m, A[maxn], B[maxn]; n long long f[maxn][maxn]; n void init() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &A[i]); n     A[i] -= i; n     B[i] = A[i]; n   } n } n void solve() { n   sort(B + 1, B + n + 1); n   m = 1; n   for (int i = 2; i <= n; ++i) n     if (B[m] != B[i]) B[++m] = B[i]; n   for (int i = 1; i <= n; ++i) n     for (int j = 0; j <= m; ++j) f[i][j] = inf; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       f[i][j] = min(f[i][j - 1], f[i - 1][j] + abs(A[i] - B[j])); n   long long ans = inf; n   for (int i = 1; i <= m; ++i) ans = min(ans, f[n][i]); n   printf( %I64d n , ans); n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i != n; ++i) { n     cin >> v[i]; n     v[i] -= (n - i); n   } n   sort(v.begin(), v.end()); n   for (int i = 0; i != n - 1; ++i) { n     if (v[i] + 1 > v[i + 1]) { n       cout <<  :( n ; n       return 0; n     } n   } n   for (int i = 0; i != n; ++i) { n     cout << v[i] + (n - i) <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, x, a[100]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (i == 1) m = a[1]; n     m = min(m, a[i]); n   } n   for (int i = 1; i <= n; i++) { n     x += (a[i] == m); n   } n   if (x <= n / 2) n     printf( Alice ); n   else n     printf( Bob ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1 << 20; n const int mod = 1e9 + 7; n void fwht(long long f[], int n) { n   for (int b = 0; b < n; ++b) n     for (int i = 0; i < (1 << n); i += (1 << (b + 1))) n       for (int j = 0; j < (1 << b); ++j) { n         int u = f[i + j]; n         int v = f[i + j + (1 << b)]; n         f[i + j] = (u + v) % mod; n         f[i + j + (1 << b)] = (u - v + mod) % mod; n       } n } n int n; n long long f[N], g[N], mark[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0; i < (1 << n); ++i) mark[i] = f[i] = s[i] -  0 ; n   for (int i = 0; i < (1 << n); ++i) g[i] = 1 << (n - __builtin_popcount(i)); n   fwht(f, n); n   fwht(g, n); n   for (int i = 0; i < (1 << n); ++i) f[i] = f[i] * g[i] % mod; n   fwht(f, n); n   long long res = 0; n   for (int i = 0; i < (1 << n); ++i) res = (res + mark[i] * f[i]) % mod; n   for (int i = 0; i < n; ++i) res = res * ((mod + 1) / 2) % mod; n   cout << res * 3 % mod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const signed long long llf = (signed long long)(~0ull >> 1); n const signed int inf = (signed)(~0u >> 1); n template <typename T> n T __abs(T x) { n   return (x < 0) ? (-x) : (x); n } n template <typename T> n void pfill(T* pst, const T* ped, T val) { n   for (; pst != ped; *(pst++) = val) n     ; n } n template <typename T> n void pcopy(T* pst, const T* ped, T* pv) { n   for (; pst != ped; *(pst++) = *(pv++)) n     ; n } n typedef class Edge { n  public: n   int ed, nx, cap, f; n   Edge() {} n   Edge(int ed, int nx, int cap, int f) : ed(ed), nx(nx), cap(cap), f(f) {} n } Edge; n typedef class MapManager { n  public: n   int* h; n   vector<Edge> es; n   MapManager() {} n   MapManager(int n) { n     h = new int[(n + 1)]; n     pfill(h, h + n + 1, -1); n   } n   void addEdge(int u, int v, int cap, int f) { n     es.push_back(Edge(v, h[u], cap, f)); n     h[u] = (signed)es.size() - 1; n   } n   void addArc(int u, int v, int cap) { n     addEdge(u, v, cap, 0); n     addEdge(v, u, cap, cap); n   } n   Edge& operator[](int p) { return es[p]; } n   void clear() { n     delete[] h; n     es.clear(); n   } n } MapManager; n const int N = 605; n int n, m, K; n int s = 0, t; n int mxcap; n int deg[N]; n MapManager g; n inline void init() { n   scanf( %d%d%d , &n, &m, &K); n   pfill(deg, deg + n + 1, 0); n   g = MapManager(n + m + 1); n   for (int i = 1, u, v; i <= m; i++) { n     scanf( %d%d , &u, &v); n     deg[u]++, deg[v]++; n     g.addArc(0, i, 1); n     g.addArc(i, u + m, 1); n     g.addArc(i, v + m, 1); n   } n   t = n + m + 1, mxcap = 0; n   for (int i = 1; i <= n; i++) n     if (deg[i] > K) g.addArc(i + m, t, (deg[i] - K) << 1), mxcap += deg[i] - K; n   mxcap <<= 1; n } n int cur[N << 1], _div[N << 1]; n int dfs(int p, int mf) { n   if (p == t || !mf) return mf; n   int f, flow = 0; n   for (int &i = cur[p], e; ~i; i = g[i].nx) { n     e = g[i].ed; n     if (g[i].f < g[i].cap && _div[e] == _div[p] + 1 && n         (f = dfs(e, min(mf, g[i].cap - g[i].f))) > 0) { n       g[i].f += f; n       g[i ^ 1].f -= f; n       mf -= f; n       flow += f; n       if (!mf) break; n     } n   } n   return flow; n } n queue<int> que; n bool bfs() { n   pfill(_div, _div + t + 1, -1); n   _div[s] = 0; n   que.push(s); n   while (!que.empty()) { n     int e = que.front(); n     que.pop(); n     for (int i = g.h[e], eu; ~i; i = g[i].nx) { n       eu = g[i].ed; n       if (g[i].cap == g[i].f) continue; n       if (~_div[eu]) continue; n       _div[eu] = _div[e] + 1; n       que.push(eu); n     } n   } n   return _div[t] != -1; n } n int dinic() { n   int rt = 0; n   while (bfs()) { n     pcopy(cur, cur + t + 1, g.h); n     rt += dfs(s, inf); n   } n   return rt; n } n int lab[N]; n vector<int> mat[N]; n inline void solve() { n   int flow = dinic(), used = 0; n   if (flow != mxcap) { n     for (int i = 1; i <= m; i++) printf( 0  ); n     putchar(  n ); n     return; n   } n   for (int i = 1; i <= n; i++) mat[i].clear(); n   for (int i = 1; i <= m; i++) n     for (int j = g.h[i]; ~j; j = g[j].nx) n       if (g[j].cap == g[j].f && g[j].ed > m) { n         mat[g[j].ed - m].push_back(i); n         break; n       } n   pfill(lab + 1, lab + m + 1, 0); n   for (int i = 1, a, b; i <= n; i++) n     while (!mat[i].empty()) { n       a = mat[i].back(); n       mat[i].pop_back(); n       b = mat[i].back(); n       mat[i].pop_back(); n       lab[a] = lab[b] = ++used; n     } n   for (int i = 1; i <= m; i++) { n     if (!lab[i]) lab[i] = ++used; n     printf( %d  , lab[i]); n   } n   putchar(  n ); n } n inline void clear() { g.clear(); } n int T; n int main() { n   scanf( %d , &T); n   while (T--) { n     init(); n     solve(); n     clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double low = 0, high = 0, mid = 0; n int binary_sear(const vector<int>& v, int x) { n   while (1) { n     mid = floor((low + high) / 2); n     if (low > high) break; n     if (v[mid] == x) { n       return mid; n       break; n     } else if (v[mid] < x) { n       low = mid + 1; n     } else { n       high = mid - 1; n     } n   } n   return -1; n } n int binary(vector<int> v, int x) { n   mid = floor((low + high) / 2); n   cout << low <<     << mid <<     << high << endl; n   if (low > high) return -1; n   if (v[mid] == x) n     return mid; n   else if (v[mid] < x) { n     low = mid + 1; n     return binary(v, x); n   } else { n     high = mid - 1; n     return binary(v, x); n   } n } n string decToBinary(int n) { n   string s = {}; n   int i = 0; n   while (n > 0) { n     s += (n % 2) + 48; n     n = n / 2; n     i++; n   } n   reverse(s.begin(), s.end()); n   return s; n } n int main() { n   long long int a, b = 0, c = 1, n, m, mx = 0, mn = 0; n   vector<int> v; n   bool flag = true, flag2 = true; n   cin >> n; n   while (n--) { n     cin >> m; n     for (int i = 0; i < m; i++) { n       cin >> a; n       if (i == 0) { n         b = a; n         c = a; n         continue; n       } n       b += a; n       c ^= a; n     } n     cout << 2 << endl; n     cout << c <<     << c + b << endl; n     b = 0; n     c = 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int W, N, M; n vector<int> freq; n vector<uint16_t> quick_count; n int needed(char bit_gate, int bit) { n   switch (bit_gate) { n     case  A : n       return bit == 0 ? 2 : 0; n     case  O : n       return bit == 0 ? 0 : -1; n     case  X : n       return bit; n     case  a : n       return bit == 0 ? -1 : 1; n     case  o : n       return bit == 0 ? 1 : 2; n     case  x : n       return bit ^ 1; n   } n   assert(false); n } n int recurse(string &gate, int position, int mask, int extended) { n   if (position >= W) return freq[mask] * quick_count[extended]; n   int opt0 = needed(gate[position], 0); n   int opt1 = needed(gate[position], 1); n   int answer = 0; n   if (opt0 != -1) n     answer += n         recurse(gate, position + 1, mask, extended + (opt0 << 2 * position)); n   if (opt1 != -1) n     answer += recurse(gate, position + 1, mask + (1 << position), n                       extended + (opt1 << 2 * position)); n   return answer; n } n int solve(string gate) { n   reverse(gate.begin(), gate.end()); n   return recurse(gate, 0, 0, 0); n } n int main() { n   scanf( %d %d %d , &W, &N, &M); n   freq.resize(1 << W); n   for (int i = 0; i < N; i++) { n     int v; n     scanf( %d , &v); n     freq[v]++; n   } n   quick_count.resize(1 << 2 * W); n   for (int a = 0; a < 1 << W; a++) { n     int expanded = 0; n     for (int i = 0; i < W; i++) n       if (a & 1 << i) expanded += 1 << 2 * i; n     quick_count[expanded] = freq[a]; n   } n   int a = 0; n   while (a < 1 << 2 * W) { n     for (int i = 0; i < W; i++) n       if ((a >> 2 * i) % 4 == 2) { n         quick_count[a] = n             quick_count[a - (2 << 2 * i)] + quick_count[a - (1 << 2 * i)]; n         break; n       } n     int index = W; n     for (int i = 0; i < W; i++) n       if ((a >> 2 * i) % 4 == 2) { n         a ^= a & 3 << 2 * i; n       } else { n         index = i; n         break; n       } n     a += 1 << 2 * index; n   } n   for (int i = 0; i < M; i++) { n     char gate[100]; n     scanf( %s , gate); n     printf( %d n , solve(gate)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int inf = 1000000000000000; n string s; n vector<long long> prim; n set<long long> prim2; n void primeFactors(int n) { n   while (n % 2 == 0) { n     prim.push_back(2); n     prim2.insert(2); n     n = n / 2; n   } n   for (int i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       prim.push_back(i); n       prim2.insert(i); n       n = n / i; n     } n   } n   if (n > 2) { n     prim.push_back(n); n     prim2.insert(n); n   } n } n long long dp[3001][3001]; n long long n; n pair<long long, long long> arr[4000]; n long long get_ans(long long i, long long prev) { n   if (i > n) { n     return 0; n   } n   if (dp[i][prev] != -inf) return dp[i][prev]; n   long long x = 0, y = 0; n   x = get_ans(i + 1, i) + arr[i].second; n   y = abs(arr[prev].first - arr[i].first) + get_ans(i + 1, prev); n   return dp[i][prev] = min(x, y); n } n void func() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     long long a, b; n     cin >> a >> b; n     arr[i] = {a, b}; n   } n   sort(arr + 1, arr + n + 1); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       dp[i][j] = -inf; n     } n   } n   cout << get_ans(2, 1) + arr[1].second <<   n ; n } n int main() { n   { n     ios ::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n   } n   { func(); } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl; n   return 0; n } n void solve() { n   long long n; n   cin >> n; n   long long a[n]; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   long long s = 0; n   for (long long i = 1; i < n; i++) { n     if (a[i] == a[i - 1]) s++; n   } n   if (s) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n; n int check(long long k) { n   long long patsum = 0, nn = n, pat; n   while (nn > 0) { n     nn = nn - k; n     pat = nn / 10; n     nn = nn - pat; n     patsum += pat; n     if (patsum > n / 2) { n       return 1; n     } n   } n   return 0; n } n long long bs() { n   long long left = 1, right = n, k; n   while (left < right) { n     k = (right + left) / 2; n     if (check(k)) { n       left = k + 1; n     } else n       right = k; n   } n   return left; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1, k, pat, patsum = 0, ori, flag = 0; n   while (t--) { n     cin >> n; n     long long ans = bs(); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   std::cout.tie(0); n   int32_t n; n   std::cin >> n; n   std::set<std::pair<int32_t, int32_t> > segments; n   for (int32_t i = 0; i < n; i++) { n     int32_t left, right; n     std::cin >> left >> right; n     auto it = segments.lower_bound({left, 0}); n     if (it != segments.begin()) { n       it--; n       if (it->second < left) it++; n     } n     int32_t min_left = left, max_right = right; n     while (it != segments.end() && n            ((it->second >= left && it->second <= right) || n             (it->first >= left && it->first <= right) || n             (it->first <= left && it->second >= right))) { n       min_left = std::min(min_left, it->first); n       max_right = std::max(max_right, it->second); n       auto next = it; n       next++; n       segments.erase(it); n       it = next; n     } n     segments.emplace(min_left, max_right); n     std::cout << segments.size() <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> magic(string t, string s, int sk) { n   int tl = t.length(); n   string x = t +  @  + s; n   int n = x.length(); n   vector<int> pi(n), r(sk + 1, -1); n   r[0] = sk - 1; n   for (int i = 1, k = 0; i < n; ++i) { n     while (k && x[i] != x[k]) k = pi[k - 1]; n     k += x[i] == x[k]; n     pi[i] = k; n     if (i >= tl + sk) { n       while (k > sk) k = pi[k - 1]; n       for (int j = k; r[j] == -1; j = pi[j - 1]) r[j] = i - tl - 1; n     } n   } n   return r; n } n vector<int> pi_function(const string &s) { n   int n = s.length(); n   vector<int> pi(n); n   for (int i = 1, k = 0; i < n; ++i) { n     while (k && s[i] != s[k]) k = pi[k - 1]; n     k += s[i] == s[k]; n     pi[i] = k; n   } n   return pi; n } n vector<int> kmp(const string &text, const string &patt) { n   int n = text.length(), m = patt.length(); n   vector<int> ans, pi = pi_function(patt); n   for (int i = 0, k = 0; i < n; ++i) { n     while (k && text[i] != patt[k]) k = pi[k - 1]; n     k += text[i] == patt[k]; n     if (k == m) { n       ans.push_back(i - k + 1); n       k = pi[k - 1]; n     } n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n, m, k; n   string s, t; n   cin >> n >> m >> k >> s >> t; n   if (m <= k) { n     auto p = kmp(s, t); n     for (auto i : p) { n       int l = max(k, i + m); n       if (l + k <= n) { n         cout <<  Yes n  << l - k + 1 <<     << l + 1 <<   n ; n         return 0; n       } n       int r = min(i + 1, n - k + 1); n       if (r - 1 >= k) { n         cout <<  Yes n  << r - k <<     << r <<   n ; n         return 0; n       } n     } n   } n   auto l = magic(t, s, k); n   reverse(t.begin(), t.end()); n   reverse(s.begin(), s.end()); n   auto r = magic(t, s, k); n   for (auto &i : r) n     if (i != -1) i = n - 1 - i; n   for (int i = 0; i <= m; ++i) n     if (i <= k && m - i <= k && l[i] != -1 && r[m - i] != -1 && n         l[i] < r[m - i]) { n       cout <<  Yes n  << l[i] - k + 2 <<     << r[m - i] + 1 <<   n ; n       return 0; n     } n   cout <<  No n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:102400000,102400000 ) n inline void read(int &x) { n   x = 0; n   char ch = getchar(); n   while (ch <  0 ) ch = getchar(); n   while (ch >=  0 ) { n     x = x * 10 + ch - 48; n     ch = getchar(); n   } n } n int a[100010], ans; n bool f[100010]; n int main() { n   int n; n   scanf( %d , &n); n   if (n == 1) n     puts( 1 ); n   else if (n == 2) n     puts( -1 ); n   else if (n % 4 > 1) n     puts( -1 ); n   else { n     if (n & 1) a[n / 2 + 1] = n / 2 + 1; n     for (int i = 1; i <= n / 2; ++i) { n       if (!a[i]) { n         a[i] = i + 1; n         a[i + 1] = n + 1 - i; n         a[n + 1 - i] = n - i; n         a[n - i] = i; n       } n     } n     for (int i = 1; i <= n; ++i) printf( %d%c , a[i], (i == n) ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n vector<pair<int, int>> ans, packs; n void sp2(int st, int n) { n   if (n < 2) return; n   sp2(st, n / 2); n   sp2(st + n / 2, n / 2); n   for (int i = 0; i < n / 2; ++i) { n     ans.push_back({st + i, st + n / 2 + i}); n   } n } n void getp0(int st, int now, int need) { n   while (now < need) { n     for (int i = 0; i < now; ++i) { n       ans.push_back({st + i, st + now + i}); n     } n     now *= 2; n   } n } n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   N = n; n   for (int t = 16384, u = 0; t > 0; t /= 2) { n     if (n & t) { n       sp2(u, t); n       packs.push_back({u, t}); n       u += t; n     } n   } n   int p0 = 0; n   while (packs.size() > 2) { n     int psz = packs.size(); n     getp0(packs.back().first, packs.back().second, packs[psz - 2].second); n     packs.pop_back(); n     int nsz = packs.back().second, nst = packs.back().first; n     packs.back().second *= 2; n     for (int i = 0; i < nsz; ++i) { n       ans.push_back({nst + i, nst + nsz + i}); n     } n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); ++i) { n     cout << (ans[i].first % n) + 1 <<     << (ans[i].second % n) + 1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const int BIG = 1e9 + 555; n const int maxN = 100 * 1000 + 9; n long long n, m; n pair<long long, long long> a[maxN]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     long long q, w; n     cin >> q >> w; n     a[i] = make_pair(w, q); n   } n   sort(a + 1, a + m + 1); n   long long res = 0; n   for (long long i = m; i > 0; i--) { n     long long j = m - i; n     long long foo = 0; n     if (j & 1) { n       foo = (j * (j + 1)) / 2 + j / 2 + 1; n     } else { n       foo = (j * (j + 1)) / 2 + 1; n     } n     if (foo > n) { n       break; n     } n     res += a[i].first; n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5; n int mod = 1e9 + 7; n long long qpow(long long a, long long b) { n   long long ans = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) ans = ans * a % mod; n     a = a * a % mod; n   } n   return ans; n } n long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; } n int n, m, T; n int a[maxn]; n int fac[maxn]; n void init() { n   fac[0] = 1; n   for (int i = 1; i <= n; i++) { n     fac[i] = 1ll * fac[i - 1] * i % mod; n   } n } n int main() { n   cin >> n >> mod; n   init(); n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     ans = (ans + 1ll * (n - i + 1) * fac[n - i + 1] % mod * fac[i] % mod) % mod; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n struct Edge { n   long long to, dis, next; n } edge[100100]; n long long n, num_edge; n long long first1[100100]; n long long a[100100], b[100100]; n double tem; n void dfs(long long x, long long fa, long long p) { n   long long k = first1[x]; n   while (k != 0) { n     dfs(edge[k].to, x, edge[k].dis); n     k = edge[k].next; n   } n   if (a[x] < b[x]) n     b[fa] += b[x] - a[x]; n   else if (a[x] > b[x]) { n     tem = (double)(b[x] - a[x]) * p; n     if (tem < -110000000000000000) { n       printf( NO ); n       exit(0); n     } n     b[fa] -= p * (a[x] - b[x]); n     if (b[fa] < -110000000000000000) { n       printf( NO ); n       exit(0); n     } n   } n } n int main() { n   long long i, x, k; n   scanf( %lld , &n); n   for (i = 1; i <= n; i++) scanf( %lld , &b[i]); n   for (i = 1; i <= n; i++) scanf( %lld , &a[i]); n   for (i = 2; i <= n; i++) { n     scanf( %lld%lld , &x, &k); n     edge[++num_edge].to = i; n     edge[num_edge].dis = k; n     edge[num_edge].next = first1[x]; n     first1[x] = num_edge; n   } n   k = first1[1]; n   while (k != 0) { n     dfs(edge[k].to, 1, edge[k].dis); n     k = edge[k].next; n   } n   if (b[1] < a[1]) n     printf( NO ); n   else n     printf( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A, B, q; n long long l, t, m; n bool check(long long len) { n   long long ind_left = l; n   long long ind_righ = ind_left + len - 1; n   long long num_left = A + (ind_left - 1) * B; n   long long num_righ = A + (ind_righ - 1) * B; n   long long need_time; n   if (len > m) n     need_time = ((num_left + num_righ) * len / 2 + m - 1) / m; n   else n     need_time = num_righ; n   return need_time <= t && num_righ <= t; n } n void work() { n   scanf( %d %d %d , &A, &B, &q); n   while (q--) { n     scanf( %lld %lld %lld , &l, &t, &m); n     long long lpt = 0, rpt = 1e6; n     while (lpt < rpt) { n       long long mid = (lpt + rpt + 1) >> 1; n       if (check(mid)) { n         lpt = mid; n       } else { n         rpt = mid - 1; n       } n     } n     if (lpt == 0) { n       puts( -1 ); n     } else { n       printf( %lld n , l + rpt - 1); n     } n   } n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1123456; n template <typename T> n T sqr(T x) { n   return x * x; n } n template <typename T> n void vout(T s) { n   cout << s <<   n ; n   exit(0); n } n long long bp(long long a, long long n) { n   long long res = 1; n   while (n) { n     if (n % 2) res *= a; n     a *= a; n     n >>= 1; n   } n   return res; n } n char akel_sosat[1001][1001]; n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   long long n; n   cin >> n; n   string a; n   cin >> a; n   long long kol = 0, mx = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] ==  [ ) n       kol++; n     else n       kol--; n     mx = max(mx, kol); n   } n   long long m = mx * 2 + 3; n   long long l = 1, len = mx; n   for (int i = 1; i <= 1000; i++) n     for (int j = 0; j < 1001; j++) akel_sosat[i][j] =    ; n   long long st = 0; n   for (int i = 0; i < n; i++, st++) { n     if (a[i] ==  [ ) { n       akel_sosat[l][st] =  + ; n       akel_sosat[l][st + 1] =  - ; n       long long l1 = len * 2 - 1; n       for (int j = l + 1; j <= l + l1; j++) akel_sosat[j][st] =  | ; n       akel_sosat[l + l1 + 1][st] =  + ; n       akel_sosat[l + l1 + 1][st + 1] =  - ; n       len--; n       l++; n     } else { n       if (a[i] != a[i - 1]) st += 3; n       l--; n       len++; n       akel_sosat[l][st] =  + ; n       akel_sosat[l][st - 1] =  - ; n       long long l1 = len * 2 - 1; n       for (int j = l + 1; j <= l + l1; j++) akel_sosat[j][st] =  | ; n       akel_sosat[l + l1 + 1][st] =  + ; n       akel_sosat[l + l1 + 1][st - 1] =  - ; n     } n   } n   for (int i = 1; i <= m; i++) { n     for (int j = 0; j < st; j++) cout << akel_sosat[i][j]; n     cout <<   n ; n   } n   cerr <<  Time execute:   << clock() / (double)CLOCKS_PER_SEC <<   sec  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n long long sum(long long val) { n   if (val % 2) return (val + 1) / 2 * val; n   return val / 2 * (val + 1); n } n int main() { n   long long n, x, d[200005], i, xx, l, ans = 0, now, tmp; n   scanf( %lld%lld , &n, &x); n   for (i = 0; i < n; i++) scanf( %lld , &d[i]); n   l = n - 1; n   xx = x; n   now = 0; n   for (i = n - 1; i >= 0; i--) { n     while (xx >= d[l]) { n       xx -= d[l]; n       now += sum(d[l]); n       l--; n       if (l < 0) l += n; n     } n     tmp = now - sum(d[l] - xx) + sum(d[l]); n     if (tmp > ans) ans = tmp; n     xx += d[i]; n     now -= sum(d[i]); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void umax(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n inline void umin(T &a, T b) { n   if (a > b) a = b; n } n template <class T> n inline T abs(T a) { n   return a > 0 ? a : -a; n } n template <class T> n inline T gcd(T a, T b) { n   return __gcd(a, b); n } n template <class T> n inline T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n long long modpow(long long a, long long n, long long temp) { n   long long res = 1, y = a; n   while (n > 0) { n     if (n & 1) res = (res * y) % temp; n     y = (y * y) % temp; n     n /= 2; n   } n   return res % temp; n } n long long ison(long long mask, long long pos) { return (mask & (1 << pos)); } n long long cbit(long long n) { n   long long k = 0; n   while (n) n &= (n - 1), k++; n   return k; n } n long long nbit(long long n) { n   long long k = 0; n   while (n) n /= 2, k++; n   return k; n } n long long mod = 1e9 + 7; n int sgn(long long x) { return x < 0 ? -1 : !!x; } n long long xo(long long i) { n   if ((i & 3) == 0) return i; n   if ((i & 3) == 1) return 1; n   if ((i & 3) == 2) return i + 1; n   return 0; n } n long long a[200005]; n int main() { n   long long n, i, j, k, l, m, ans = 0; n   long long pr = 0; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   for (i = 1; i <= n; i++) { n     if (a[i] != pr) { n       ans += abs(a[i] - pr); n       pr = a[i]; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   bool t = true; n   int n; n   cin >> n; n   int a[200001] = {0}; n   vector<int> voz; n   vector<int> yb; n   for (int i = 0; i < n; i++) { n     int c; n     cin >> c; n     a[c]++; n     if (a[c] > 2) { n       cout <<  NO ; n       t = false; n       break; n     } else if (a[c] == 1) { n       yb.push_back(c); n     } else if (a[c] == 2) { n       voz.push_back(c); n     } n   } n   if (t) { n     sort(voz.begin(), voz.end()); n     sort(yb.begin(), yb.end()); n     cout <<  YES  <<   n ; n     cout << voz.size() <<   n ; n     for (int i = 0; i < voz.size(); i++) { n       cout << voz[i] <<    ; n     } n     cout <<   n ; n     cout << yb.size() <<   n ; n     reverse(yb.begin(), yb.end()); n     for (int i = 0; i < yb.size(); i++) { n       cout << yb[i] <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a; n vector<vector<int>> graph; n vector<vector<int>> residual; n set<int> primes; n map<pair<int, int>, int> factors; n void sieve(int SQRTN) { n   vector<int> isPrime(SQRTN, 1); n   for (int i = 2; i < SQRTN; i++) { n     if (!isPrime[i]) continue; n     primes.insert(i); n     for (int j = i * i; j < SQRTN; j += i) { n       isPrime[j] = 0; n     } n   } n   for (int i = 0; i < a.size(); i++) { n     int num = a[i]; n     for (int p : primes) { n       int acc = 0; n       while (num % p == 0) { n         acc++; n         num /= p; n       } n       factors[{a[i], p}] = acc; n     } n     if (num != 1) { n       primes.insert(num); n       factors[{i, num}] = 1; n     } n   } n } n int bfs(int source, int sink) { n   queue<int> q; n   vector<int> anc(graph.size(), -1); n   q.push(source); n   bool reached = false; n   while (!q.empty()) { n     int curr = q.front(); n     q.pop(); n     if (curr == sink) { n       reached = true; n       break; n     } n     for (int neighbor : graph[curr]) { n       if (anc[neighbor] == -1 and residual[curr][neighbor] > 0) { n         q.push(neighbor); n         anc[neighbor] = curr; n       } n     } n   } n   if (!reached) { n     return 0; n   } n   int node = sink; n   int augment = 12312312; n   while (node != source) { n     int prev = anc[node]; n     augment = min(augment, residual[prev][node]); n     node = prev; n   } n   node = sink; n   while (node != source) { n     int prev = anc[node]; n     residual[prev][node] -= augment; n     residual[node][prev] += augment; n     node = prev; n   } n   return augment; n } n int edmondkarp(int source, int sink) { n   int res = 0; n   while (true) { n     int delta = bfs(source, sink); n     if (delta == 0) { n       break; n     } n     res += delta; n   } n   return res; n } n int main() { n   int n, m; n   cin >> n >> m; n   a.resize(n); n   int MAXN = -1; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     MAXN = max(MAXN, a[i]); n   } n   sieve(sqrt(MAXN)); n   int s = n; n   int t = n + 1; n   graph.resize(n + 2); n   residual.resize(n + 2, vector<int>(n + 2)); n   for (int i = 0; i < m; i++) { n     int n1, n2; n     cin >> n1 >> n2; n     --n1; n     --n2; n     if (!(n1 & 1)) { n       swap(n1, n2); n     } n     graph[n1].push_back(n2); n     graph[n2].push_back(n1); n     residual[n1][n2] = 12312312; n     residual[n2][n1] = 0; n   } n   for (int i = 0; i < n; i++) { n     if (i & 1) { n       graph[s].push_back(i); n     } else { n       graph[i].push_back(t); n     } n   } n   vector<vector<int>> residualCopy(residual); n   int sol = 0; n   for (int p : primes) { n     residual = residualCopy; n     for (int i = 0; i < n; i++) { n       int capacity = factors.count({a[i], p}) ? factors[{a[i], p}] : 0; n       if (i & 1) { n         residual[s][i] = capacity; n       } else { n         residual[i][t] = capacity; n       } n     } n     sol += edmondkarp(s, t); n   } n   cout << sol <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace io { n char ibuf[(1 << 18)], *iS, *iT, obuf[(1 << 18)], n     *oS = obuf, *oT = oS + (1 << 18) - 1, c, qu[55]; n int f, qr; n inline void flush(void) { n   fwrite(obuf, 1, oS - obuf, stdout); n   oS = obuf; n   return; n } n inline char getch(void) { n   return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, (1 << 18), stdin), n                       (iS == iT ? EOF : *iS++)) n                    : *iS++); n } n inline void putch(char x) { n   *oS++ = x; n   if (oS == oT) flush(); n   return; n } n void putstr(string str, int begin = 0, int end = -1) { n   if (end == -1) end = str.size(); n   for (register int i = begin; i < end; i++) putch(str[i]); n   return; n } n template <typename T> n inline T read() { n   register T x = 0; n   for (f = 1, c = getch(); c <  0  || c >  9 ; c = getch()) n     if (c ==  - ) f = -1; n   for (x = 0; c <=  9  && c >=  0 ; c = getch()) x = x * 10 + (c & 15); n   x *= f; n   return x; n } n template <typename T> n inline void write(const T& t) { n   register T x = t; n   if (!x) putch( 0 ); n   if (x < 0) putch( - ), x = -x; n   while (x) qu[++qr] = x % 10 +  0 , x /= 10; n   while (qr) putch(qu[qr--]); n   return; n } n struct Flusher_ { n   ~Flusher_() { flush(); } n } io_flusher_; n }  // namespace io n using io::getch; n using io::putch; n using io::putstr; n using io::read; n using io::write; n pair<int, int> a[100005]; n int f[100005]; n int main() { n   int n = read<int>(); n   for (register int i = 1; i <= n; i++) n     a[i].first = read<int>(), a[i].second = read<int>(); n   sort(a + 1, a + n + 1); n   int answer = f[1] = 1; n   for (register int i = 2; i <= n; i++) { n     f[i] = 1 + f[lower_bound(a + 1, a + i, n                              (pair<int, int>){a[i].first - a[i].second, 0}) - n                  a - 1]; n     answer = max(answer, f[i]); n   } n   write(n - answer), putch(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long N, Q, S[(int)1e5 + 5], i, L, R, p1, p2; n long long Putere(long long p1, long long ex) { n   long long i, sol = 1; n   for (i = 0; (1 << i) <= ex; i++) { n     if (((1 << i) & ex) > 0) sol = (sol * p1) % 1000000007; n     p1 = (p1 * p1) % 1000000007; n   } n   return sol; n } n string str; n int main() { n   cin >> N >> Q; n   cin >> str; n   for (i = 0; i < str.length(); i++) { n     if (str[i] ==  1 ) n       S[i + 1] = S[i] + 1; n     else n       S[i + 1] = S[i]; n   } n   while (Q--) { n     cin >> L >> R; n     p1 = S[R] - S[L - 1]; n     p2 = R - L + 1 - p1; n     cout << ((Putere(2, p1) - 1 + (Putere(2, p1) - 1) * (Putere(2, p2) - 1))) % n                 1000000007 n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct trip { n   int l; n   int len; n   int t; n   int id; n }; n const int INF = 1e9; n int main() { n   int n, p; n   scanf( %d%d , &n, &p); n   vector<trip> trips(n); n   for (int i = 0; i < n; i++) { n     scanf( %d%d%d , &trips[i].l, &trips[i].len, &trips[i].t); n     trips[i].id = i; n   } n   vector<trip> lorder = trips, torder = trips; n   sort(lorder.begin(), lorder.end(), n        [](const trip& a, const trip& b) { return a.l < b.l; }); n   sort(torder.begin(), torder.end(), n        [](const trip& a, const trip& b) { return a.t < b.t; }); n   vector<int> dp(1 << n, INF); n   vector<int> pj(1 << n, -1); n   vector<int> pt(1 << n, -1); n   dp[0] = 1; n   for (int i = 0; i < (1 << n); i++) { n     if (dp[i] == INF) continue; n     int c = dp[i]; n     auto ptr = lorder.begin(); n     auto ptr_same = lorder.begin(); n     for (auto j : torder) { n       int to = i | (1 << j.id); n       if (to == i) continue; n       while (true) { n         while (ptr != lorder.end() && ptr->l + ptr->len <= c) ptr++; n         while (ptr_same != lorder.end() && n                (ptr_same->l < c || ((i & (1 << ptr_same->id)) == 0))) n           ptr_same++; n         if (ptr != lorder.end() && ptr->l <= c) { n           c = ptr->l + ptr->len; n           continue; n         } n         if (ptr_same != lorder.end() && c + j.t >= ptr_same->l) { n           c = ptr_same->l + ptr->len; n           continue; n         } n         break; n       } n       if (c + j.t < j.l) { n         if (dp[to] > c + j.t) { n           dp[to] = c + j.t; n           pj[to] = j.id; n           pt[to] = c; n         } n       } n     } n   } n   vector<int> anst(n, -1); n   vector<int> ansp(n, -1); n   auto restore = [&](int mask, int p) { n     while (mask) { n       int last = pj[mask]; n       assert(last != -1 && (mask & (1 << last))); n       anst[last] = pt[mask]; n       ansp[last] = p; n       mask ^= (1 << last); n     } n   }; n   if (p == 1) { n     if (dp[(1 << n) - 1] != INF) { n       restore((1 << n) - 1, 1); n     } n   } else { n     for (int i = 0; i < (1 << n) - 1; i++) { n       if (dp[i] != INF && dp[(1 << n) - 1 - i] != INF) { n         restore(i, 1); n         restore((1 << n) - 1 - i, 2); n         break; n       } n     } n   } n   if (anst[0] == -1) { n     printf( NO n ); n   } else { n     printf( YES n ); n     for (int i = 0; i < n; i++) { n       printf( %d %d n , ansp[i], anst[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 10; n struct node { n   int t; n   int x; n   int y; n } tt[maxn]; n int main() { n   int n, m, s, f; n   while (~scanf( %d%d%d%d , &n, &m, &s, &f)) { n     memset(tt, 0, sizeof tt); n     for (int i = 0; i < m; i++) { n       scanf( %d%d%d , &tt[i].t, &tt[i].x, &tt[i].y); n     } n     int cnt = 0; n     int time = 1; n     int peo = s; n     int jj; n     if (f > s) n       jj = 1; n     else n       jj = -1; n     while (peo != f) { n       if (tt[cnt].t != time) { n         peo += jj; n         if (jj == 1) { n           printf( R ); n         } else n           printf( L ); n       } else if ((peo < tt[cnt].x || peo > tt[cnt].y) && n                  ((peo + jj) < tt[cnt].x || (peo + jj) > tt[cnt].y)) { n         peo += jj; n         if (jj == 1) { n           printf( R ); n         } else n           printf( L ); n         cnt++; n       } else { n         printf( X ); n         cnt++; n       } n       time++; n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char jak[1000005], tak[1000005]; n   gets(jak); n   gets(tak); n   int k, r, i, t, flag = 0, count = 0, fount = 0, f, x, y, j, p = 0; n   k = strlen(jak); n   r = strlen(tak); n   for (i = 0; i < k; i++) { n     t = jak[i] - 48; n     if (t != 0 && flag == 0) { n       flag = 1; n       x = i; n     } n     if (flag == 1) { n       count++; n     } n   } n   flag = 0; n   for (i = 0; i < r; i++) { n     f = tak[i] - 48; n     if (f != 0 && flag == 0) { n       flag = 1; n       y = i; n     } n     if (flag == 1) { n       fount++; n     } n   } n   if (count > fount) { n     printf( > ); n   } else if (count < fount) { n     printf( < ); n   } else if (count == 0) { n     printf( = ); n   } else { n     for (i = x, j = y; i < k, j < r; i++, j++) { n       if (jak[i] > tak[j]) { n         printf( > ); n         break; n       } else if (jak[i] < tak[j]) { n         printf( < ); n         break; n       } else { n         p++; n       } n     } n     if (p == count) { n       printf( = ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void dbg_out() { cerr <<   b b] n ; } n template <typename Head, typename... Tail> n void dbg_out(Head H, Tail... T) { n   cerr << H <<  ,  ; n   dbg_out(T...); n } n const int mod = 1e9 + 7; n long long power(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return res; n } n long long modMul(long long a, long long b) { return a * b % mod; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, k; n   cin >> n >> k; n   vector<int> A(n / k), B(n / k); n   for (int &i : A) cin >> i; n   for (int &i : B) cin >> i; n   long long ans = 1; n   long long tens = power(10, k - 1); n   for (int i = 0; i < n / k; ++i) { n     long long tot = (tens * 10 - 1) / A[i] + 1; n     long long lo = B[i] * tens; n     long long hi = B[i] * tens + tens - 1; n     long long invalid = hi / A[i] - lo / A[i] + (lo % A[i] == 0); n     tot -= invalid; n     ans = modMul(ans, tot); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int t, n, a[1000000], i, j, b = 0, c = 0, e, f, g, h, m[1000000]; n   cin >> t; n   for (i = 0; i < t; i++) { n     cin >> n; n     h = n; n     for (j = 1; j <= n; j++) { n       cin >> a[j]; n     } n     sort(a + 1, a + n + 1); n     for (j = 1; j <= n; j++) { n       if (b == 0) { n         m[j] = a[j - c]; n         b = 1; n       } else { n         m[j] = a[n - c]; n         b = 0; n         c++; n       } n     } n     for (j = n; j >= 1; j--) { n       cout << m[j] <<    ; n     } n     cout << endl; n     b = 0; n     c = 0; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n using namespace std; n const long long maxnodes = 1005; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   string t; n   cin >> t; n   long long n = t.size(); n   string s1(n,  a ), s2(n,  a ), s3(n,  a ); n   string t1, t2, t3; n   for (long long i = 0; i < n; i++) { n     s1[i] = char( a  + i % 26); n     s2[i] = char( a  + (i / 26) % 26); n     s3[i] = char( a  + ((i / 26) / 26) % 26); n   } n   cout <<  ?   << s1 << endl; n   cin >> t1; n   cout <<  ?   << s2 << endl; n   cin >> t2; n   cout <<  ?   << s3 << endl; n   cin >> t3; n   string s(n,  a ); n   for (long long i = 0; i < n; i++) { n     long long z = (t1[i] -  a ) + (t2[i] -  a ) * 26 + (t3[i] -  a ) * 26 * 26; n     s[z] = t[i]; n   } n   cout <<  !   << s << endl; 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(0); n   cout.tie(0); n   int n, p, q, temp; n   cin >> n; n   int levels[101] = {0}; n   cin >> p; n   for (int i = 0; i < p; i++) { n     cin >> temp; n     levels[temp]++; n   } n   cin >> q; n   for (int i = 0; i < q; i++) { n     cin >> temp; n     levels[temp]++; n   } n   for (int i = 1; i <= n; i++) n     if (levels[i] < 1) { n       cout <<  Oh, my keyboard! ; n       return 0; n     } n   cout <<  I become the guy. ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double dp[1010000][3]; n int n, m; n int ranks[1245]; n int Prank; n int main() { n   cout << fixed << setprecision(12); n   cin >> n >> m; n   if (m == 1) { n     cout <<  1 n ; n     return 0; n   } n   for (int i = 1; i <= (n); ++i) { n     cin >> ranks[i]; n     Prank += ranks[i]; n   } n   for (int i = 1; i <= (Prank); ++i) dp[i][0] = dp[i][1] = dp[i][2] = 0; n   for (int i = 1; i <= (m); ++i) { n     if (i == ranks[1]) continue; n     dp[i][0] = 1.0; n   } n   for (int i = 2; i <= (n); ++i) { n     for (int j = 1; j <= (Prank); ++j) { n       dp[j][1] = dp[j][0] + dp[j - 1][1]; n     } n     for (int j = Prank; j >= (1); --j) { n       dp[j][2] = dp[j - 1][1]; n       if (j - m > 0) dp[j][2] -= dp[j - m - 1][1]; n       if (j - ranks[i] > 0) dp[j][2] -= dp[j - ranks[i]][0]; n     } n     for (int j = 1; j <= (Prank); ++j) n       dp[j][0] = dp[j][2] / ((long double)(m - 1)); n   } n   long double sum = 0; n   for (int i = 1; i <= (Prank - 1); ++i) { n     sum += dp[i][0]; n   } n   sum += 1; n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100005], ac[100005]; n int last[100005]; n int main() { n   int n, m, t, x, v, y, q; n   string s; n   while (cin >> n >> m) { n     for (int i = 1; i <= n; i++) cin >> a[i]; n     for (int i = 1; i <= m; i++) { n       cin >> t; n       if (t == 1) { n         cin >> v >> x; n         a[v] = x; n         last[v] = i; n         ac[i] = ac[i - 1]; n       } else { n         if (t == 2) { n           cin >> y; n           ac[i] = ac[i - 1] + y; n         } else { n           cin >> q; n           cout << a[q] + ac[i - 1] - ac[last[q]] << endl; n           ac[i] = ac[i - 1]; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int maxn = 5100, inf = 1e17, mod = 1e9 + 7; n vector<long long int> f[maxn]; n long long int pref[maxn][maxn]; n signed main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   long long int n, m; n   cin >> n >> m; n   vector<long long int> mas(n, 0); n   for (long long int d = 0; d < n; d++) { n     cin >> mas[d]; n     mas[d]--; n   } n   for (long long int d = 0; d < m; d++) { n     long long int f1, h1; n     cin >> f1 >> h1; n     f1--; n     f[f1].push_back(h1); n   } n   for (long long int d = 0; d < n; d++) { n     if (f[d].size() > 0) { n       sort(f[d].begin(), f[d].end()); n     } n   } n   for (long long int d = 0; d < n; d++) { n     pref[0][d] = 0; n   } n   for (long long int d = 1; d <= n; d++) { n     for (long long int i = 0; i < n; i++) { n       pref[d][i] = pref[d - 1][i]; n     } n     pref[d][mas[d - 1]]++; n   } n   long long int max1 = 0, cnt = 1; n   for (long long int d = 0; d <= n; d++) { n     if (d == 0) { n       long long int raz = 0; n       long long int cnt1 = 1; n       for (long long int i = 0; i < n; i++) { n         long long int kol1 = pref[n][i] - pref[d][i]; n         long long int cnt2 = 1; n         bool check1 = 0; n         auto it1 = upper_bound(f[i].begin(), f[i].end(), kol1); n         if (it1 != f[i].begin()) { n           it1--; n           long long int dist = (it1 - f[i].begin()) + 1; n           cnt2 *= dist; n           check1 = 1; n         } n         if (check1) { n           raz += check1; n           cnt1 *= cnt2; n           cnt1 %= mod; n         } n       } n       if (raz == max1) { n         cnt += cnt1; n         cnt %= mod; n       } n       if (raz > max1) { n         max1 = raz; n         cnt = cnt1; n       } n       continue; n     } n     long long int f1 = mas[d - 1]; n     long long int tkol = pref[d][f1]; n     bool check = 0; n     auto it = lower_bound(f[f1].begin(), f[f1].end(), tkol); n     if (it != f[f1].end()) { n       if ((*it) == tkol) { n         check = 1; n       } n     } n     if (!check) { n       continue; n     } n     long long int raz = 0; n     long long int cnt1 = 1; n     for (long long int i = 0; i < n; i++) { n       long long int kol = pref[d][i]; n       long long int kol1 = pref[n][i] - pref[d][i]; n       auto it = upper_bound(f[i].begin(), f[i].end(), kol); n       long long int cnt2 = 1; n       long long int min1 = inf; n       bool check = 0; n       bool check1 = 0; n       long long int cn = 0; n       long long int dist1 = 0, dist2 = 0; n       if (i != f1) { n         if (it != f[i].begin()) { n           --it; n           dist1 = (it - f[i].begin()) + 1; n           cnt2 *= dist1; n           min1 = min(min1, dist1); n           check = 1; n         } else { n           min1 = 0; n         } n         auto it1 = upper_bound(f[i].begin(), f[i].end(), kol1); n         if (it1 != f[i].begin()) { n           it1--; n           dist2 = (it1 - f[i].begin()) + 1; n           cnt2 *= dist2; n           min1 = min(min1, dist2); n           check1 = 1; n         } else { n           min1 = 0; n         } n         cnt2 -= min1; n         long long int cn = check + check1; n         if (dist1 == 1 && dist2 == 1) { n           cn--; n           cnt2 = 2; n         } n         raz += cn; n         cnt1 *= cnt2; n         cnt1 %= mod; n       } else { n         check = 1; n         auto it = upper_bound(f[i].begin(), f[i].end(), kol1); n         if (it != f[i].begin()) { n           check1 = 1; n           it--; n           dist2 = (it - f[i].begin()) + 1; n           if ((*it) >= tkol) { n             dist2--; n           } n           if (dist2 == 0) { n             check1 = 0; n           } else { n             cnt2 *= dist2; n           } n         } n         if (check || check1) { n           raz += check; n           raz += check1; n           cnt1 *= cnt2; n           cnt1 %= mod; n         } n       } n     } n     if (raz == max1) { n       cnt += cnt1; n       cnt %= mod; n     } n     if (raz > max1) { n       max1 = raz; n       cnt = cnt1; n     } n   } n   if (max1 == 0) { n     cnt = 1; n   } n   cout << max1 <<     << cnt; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, i, j, k, x, y, t; n   long long a; n   cin >> a; n   n = 2 * a - 1; n   m = 2; n   cout << n <<     << m << endl; n   cout << 1 <<     << 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int freq[8]; n int main() { n   int n, a, p1 = 0, p2 = 0, p3 = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a; n     freq[a]++; n   } n   if (freq[5] > 0 || freq[7] > 0) { n     cout << -1; n     return 0; n   } n   while (freq[1] > 0 && freq[2] > 0 && freq[4] > 0) { n     p1++; n     freq[1]--; n     freq[2]--; n     freq[4]--; n   } n   if (freq[4] > 0) { n     cout << -1; n     return 0; n   } n   while (freq[1] > 0 && freq[3] > 0 && freq[6] > 0) { n     p2++; n     freq[1]--; n     freq[3]--; n     freq[6]--; n   } n   if (freq[3]) { n     cout << -1; n     return 0; n   } n   while (freq[1] > 0 && freq[2] > 0 && freq[6] > 0) { n     p3++; n     freq[1]--; n     freq[2]--; n     freq[6]--; n   } n   if (freq[1] > 0 || freq[2] > 0 || freq[6] > 0) { n     cout << -1; n     return 0; n   } n   while (p1--) { n     printf( 1 2 4 n ); n   } n   while (p2--) { n     printf( 1 3 6 n ); n   } n   while (p3--) { n     printf( 1 2 6 n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n pair<long long, long long> ar[100005]; n long long suf[100007] = {0}, pre[100007] = {0}, sbkoya[100007] = {0}, n           arr[100005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   ; n   long long n, a, cf, cm, m, temp, revi, cnt = 0; n   cin >> n >> a >> cf >> cm >> m; n   for (long long i = 0; i < n; ++i) { n     cin >> temp; n     if (temp == a) cnt++; n     ar[i] = make_pair(temp, i); n   } n   if (cf == 0 && cm == 0) { n     cout <<  0  << endl; n     for (long long i = 0; i < n; ++i) cout << ar[i].first <<    ; n     return 0; n   } n   sort(ar, ar + n); n   long long i; n   for (i = n - 1; i >= 0; i--) { n     long long tmp = suf[i + 1] + a - ar[i].first; n     if (tmp > m) break; n     suf[i] = tmp; n   } n   revi = i + 1; n   for (long long i = 0; i < n; ++i) { n     if (i == 0) n       pre[i] = ar[i].first; n     else n       pre[i] = pre[i - 1] + ar[i].first; n   } n   for (long long i = 1; i < n; ++i) { n     sbkoya[i] = (ar[i].first) * (i + 1) - pre[i]; n   } n   if (sbkoya[n - 1] + n * (a - ar[n - 1].first) <= m) { n     cout << n * cf + a * cm << endl; n     for (long long i = 0; i < n; ++i) cout << a <<    ; n     return 0; n   } n   long long j, ans = 0, indj, indk, remain, mini, k, rem, mi, tmp; n   rem = m; n   k = upper_bound(sbkoya, sbkoya + n, rem) - sbkoya; n   k--; n   rem -= sbkoya[k]; n   mi = (ar[k].first) + rem / (k + 1); n   tmp = mi * cm + cf * cnt; n   ans = tmp; n   indk = k; n   indj = n; n   remain = rem; n   mini = mi; n   for (j = n - 1; j >= revi; j--) { n     tmp = cf * max(n - j, cnt); n     rem = m - suf[j]; n     k = upper_bound(sbkoya, sbkoya + n, rem) - sbkoya; n     k--; n     if (k >= j) k = j - 1; n     rem -= sbkoya[k]; n     mi = (ar[k].first) + rem / (k + 1); n     tmp += mi * cm; n     if (tmp >= ans) { n       ans = tmp; n       indk = k; n       indj = j; n       remain = rem; n       mini = mi; n     } n   } n   cout << ans << endl; n   long long du; n   for (du = n - 1; du >= indj; du--) ar[du].first = a; n   long long ka = remain % (k + 1); n   for (du = indk; du >= 0; du--) { n     ar[du].first = mini; n   } n   for (long long i = 0; i < n; ++i) { n     arr[ar[i].second] = ar[i].first; n   } n   for (long long i = 0; i < n; ++i) cout << arr[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   int n; n   cin >> n; n   cout << n % 2; n } n


#include <bits/stdc++.h> n using namespace std; n using point = complex<long long>; n long long cross(point a, point b) { n   return a.real() * b.imag() - a.imag() * b.real(); n } n long long dot(point a, point b) { n   return a.real() * b.real() + a.imag() * b.imag(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout << fixed << setprecision(8); n   int n, px, py; n   cin >> n >> px >> py; n   point p = point(px, py); n   double maxi = 0.0, mini = HUGE_VAL; n   vector<point> polygon(n); n   for (auto &v : polygon) { n     int x, y; n     cin >> x >> y; n     v = point(x, y); n     maxi = max(maxi, M_PI * norm(v - p)); n   } n   for (int i = 0; i < n; ++i) { n     int j = (i + 1) % n; n     point a = polygon[i], b = polygon[j]; n     point v = a - b; n     if ((dot(v, a) < dot(v, p)) == (dot(v, p) < dot(v, b))) { n       mini = min(mini, M_PI * cross(v, p - b) * cross(v, p - b) / norm(v)); n     } else { n       mini = min(mini, M_PI * min(norm(a - p), norm(b - p))); n     } n   } n   cout << maxi - mini <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200005]; n int main() { n   int T; n   cin >> T; n   while (T--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) { n       int t; n       cin >> t; n       a[t] = i; n     } n     int l, r, num; n     string s =   ; n     for (int i = 1; i <= n; i++) { n       if (i == 1) { n         num = 0; n         l = r = a[i]; n         s +=  1 ; n         continue; n       } n       if (r < a[i]) n         num += a[i] - r - 1, r = a[i]; n       else if (l > a[i]) n         num += l - a[i] - 1, l = a[i]; n       else n         num--; n       if (!num) n         s +=  1 ; n       else n         s +=  0 ; n     } n     cout << s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n const int MX[4] = {0, 0, -1, 1}; n const int MY[4] = {-1, 1, 0, 0}; n int n, m, k; n bool z[26]; n bool Inside(int a, int b) { return 0 <= a && a < n && 0 <= b && b < m; } n char GetC(int a, int b, int c, int d, vector<vector<char>>& x) { n   memset(z, 0, sizeof(z)); n   for (int t = 0; t < 4; ++t) { n     int p = a + MX[t], q = b + MY[t]; n     if (Inside(p, q) && x[p][q] !=  + ) { n       z[x[p][q] -  a ] = true; n     } n     p = c + MX[t], q = d + MY[t]; n     if (Inside(p, q) && x[p][q] !=  + ) { n       z[x[p][q] -  a ] = true; n     } n   } n   for (int i = 0; i < 26; ++i) { n     if (!z[i]) return  a  + i; n   } n   return  a ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int times; n   cin >> times; n   while (times--) { n     cin >> n >> m >> k; n     vector<vector<char>> x(n, vector<char>(m,  + )); n     if (n & 1) { n       if (k < m / 2) { n         cout <<  NO n ; n         continue; n       } n       for (int i = 0; i < m; i += 2) { n         x[0][i] = x[0][i + 1] =  a  + (i / 2 % 2); n       } n       k -= m / 2; n       if (k & 1) { n         cout <<  NO n ; n         continue; n       } n       for (int j = 0; j < m; j += 2) { n         if (k == 0) break; n         for (int i = 1; i < n; ++i) { n           if (k == 0) break; n           char t = GetC(i, j, i, j + 1, x); n           x[i][j] = x[i][j + 1] = t; n           --k; n         } n       } n       for (int i = 0; i < n; ++i) { n         for (int j = 0; j < m; ++j) { n           if (x[i][j] !=  + ) continue; n           char t = GetC(i, j, i + 1, j, x); n           x[i][j] = x[i + 1][j] = t; n         } n       } n     } else if (m & 1) { n       if (k & 1) { n         cout <<  NO n ; n         continue; n       } n       if (k > n * (m - 1) / 2) { n         cout <<  NO n ; n         continue; n       } n       for (int j = 0; j < m; j += 2) { n         if (k == 0) break; n         for (int i = 0; i < n; ++i) { n           if (k == 0) break; n           char t = GetC(i, j, i, j + 1, x); n           x[i][j] = x[i][j + 1] = t; n           --k; n         } n       } n       for (int i = 0; i < n; ++i) { n         for (int j = 0; j < m; ++j) { n           if (x[i][j] !=  + ) continue; n           char t = GetC(i, j, i + 1, j, x); n           x[i][j] = x[i + 1][j] = t; n         } n       } n     } else { n       if (k & 1) { n         cout <<  NO n ; n         continue; n       } n       for (int j = 0; j < m; j += 2) { n         if (k == 0) break; n         for (int i = 0; i < n; ++i) { n           if (k == 0) break; n           char t = GetC(i, j, i, j + 1, x); n           x[i][j] = x[i][j + 1] = t; n           --k; n         } n       } n       for (int i = 0; i < n; ++i) { n         for (int j = 0; j < m; ++j) { n           if (x[i][j] !=  + ) continue; n           char t = GetC(i, j, i + 1, j, x); n           x[i][j] = x[i + 1][j] = t; n         } n       } n     } n     cout <<  YES n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct dbg_ { n   template <typename T> n   dbg_& operator,(const T& x) { n     cerr << x <<    ; n     return *this; n   } n } dbg_t; n struct cin_ { n   template <typename T> n   cin_& operator,(T& x) { n     cin >> x; n     return *this; n   } n } cin_; n template <typename T1, typename T2> n static inline ostream& operator<<(ostream& os, std::pair<T1, T2> const& p) { n   os <<  {  << p.first <<  ,   << p.second <<  } ; n   return os; n } n int main() { n   string str; n   getline(cin, str); n   int ret = 1; n   for (int i = (1), _i = (7); i < _i; ++i) { n     ret += str[i] -  0 ; n     if (str[i] ==  0 ) ret += 9; n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n  n #define mp make_pair n #define mt make_tuple n #define fi first n #define se second n #define pb push_back n #define all(x) (x).begin(), (x).end() n #define rall(x) (x).rbegin(), (x).rend() n #define forn(i, n) for (int i = 0; i < (int)(n); ++i) n #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) n #define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i) n #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) n  n using namespace std; n  n typedef pair<int, int> pii; n typedef vector<int> vi; n typedef vector<pii> vpi; n typedef vector<vi> vvi; n typedef long long i64; n typedef vector<i64> vi64; n typedef vector<vi64> vvi64; n typedef pair<i64, i64> pi64; n typedef double ld; n  n template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } n template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } n  n const int maxn = 200001, maxk = 30; n vector<pii> e[maxn]; n int ban[maxn]; n int fib[maxk]; n int w[maxn]; n  n void dfsw(int v, int p, int k, int &c) { n     bool isC = true; n     w[v] = 1; n     for (auto [u, id]: e[v]) { n         if (u == p || ban[id]) continue; n         dfsw(u, v, k, c); n         isC &= 2 * w[u] <= fib[k]; n         w[v] += w[u]; n     } n     isC &= 2 * (fib[k] - w[v]) <= fib[k]; n     if (isC) c = v; n } n  n void dfsw2(int v, int p, int k, vector<pii> &es) { n     w[v] = 1; n     for (auto [u, id]: e[v]) { n         if (u == p || ban[id]) continue; n         dfsw2(u, v, k, es); n         w[v] += w[u]; n         if (w[u] == fib[k - 2]) { n             es.pb({id, u}); n         } n     } n } n  n bool check(int v, int k) { n     if (k <= 3) return true; n     dfsw(v, -1, k, v); n     int trash; n     vector<pii> es; n     dfsw2(v, -1, k, es); n     for (auto [id, u]: es) { n         ban[id] = 1; n         if (check(u, k - 2) && check(v, k - 1)) return true; n     } n     return false; n } n  n int main() { n     ios::sync_with_stdio(false); n     cin.tie(nullptr); n     cout.precision(10); n     cout << fixed; n #ifdef LOCAL_DEFINE n     freopen( input.txt ,  rt , stdin); n #endif n  n     int n; n     cin >> n; n     forn(i, n - 1) { n         int u, v; n         cin >> u >> v; n         --u; --v; n         e[u].pb({v, i}); n         e[v].pb({u, i}); n     } n     fib[0] = fib[1] = 1; n     int p; n     for (p = 2; fib[p - 1] < n; ++p) { n         fib[p] = fib[p - 1] + fib[p - 2]; n     } n     --p; n     if (n == fib[p] && check(0, p)) cout <<  YES n ; n     else cout <<  NO n ; n  n #ifdef LOCAL_DEFINE n     cerr <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ; n #endif n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x, y, k, t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> x >> y >> k; n     long long br; n     br = (k * (y + 1) - 1) / (x - 1); n     if (((k * (y + 1) - 1) % (x - 1)) != 0) { n       br += 1; n     } n     br += k; n     cout << br << endl; 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 t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     vector<long long> v; n     for (int i = 0; i < n; i++) { n       long long x; n       cin >> x; n       v.push_back(x); n     } n     sort(v.begin(), v.end()); n     long long sum = 0; n     for (long long i = 0; n - k + i < n; i++) { n       sum += v[n - 2 * k + i] / v[n - k + i]; n     } n     for (long long i = 0; i < n - 2 * k; i++) { n       sum += v[i]; n     } n     cout << sum; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4010, K = 80; n const int p = 998244353; n int n1, n2, k, px[2][N], py[2][N], a1[K], a2[K], fac[K], inv[K], f[2][N]; n int tot, fi[N], a[N << 1], ne[N << 1], cnt; n inline void A(int &x, int y) { x = (x + y >= p ? x + y - p : x + y); } n inline int C(int x, int y) { n   return 1ll * fac[x] * inv[y] % p * inv[x - y] % p; n } n inline void Add(int x, int y) { n   a[++tot] = y; n   ne[tot] = fi[x]; n   fi[x] = tot; n } n inline void Dfs(int x, int fa, int ty) { n   for (int i = fi[x]; i; i = ne[i]) n     if (a[i] != fa) { n       ++cnt; n       px[ty][cnt] = x; n       py[ty][cnt] = a[i]; n       px[!ty][cnt] = a[i]; n       py[!ty][cnt] = x; n       Dfs(a[i], x, !ty); n     } n } n inline void Solve(int n, int k, int ans[]) { n   tot = 0; n   memset(fi + 1, 0, n * sizeof *fi); n   for (int i = 1, x, y; i < n; ++i) { n     scanf( %d%d , &x, &y); n     Add(x, y); n     Add(y, x); n   } n   ans[0] = n; n   for (int x = 1; x <= n; ++x) { n     cnt = 0; n     Dfs(x, 0, 1); n     memset(f[0] + 1, 0, n * sizeof *f[0]); n     f[0][x] = 1; n     for (int len = 1; len <= k; ++len) { n       memset(f[len & 1] + 1, 0, n * sizeof *f[len & 1]); n       for (int i = 1; i < n; ++i) n         A(f[len & 1][py[len & 1][i]], f[~len & 1][px[len & 1][i]]); n       A(ans[len], f[len & 1][x]); n     } n   } n } n int main() { n   scanf( %d%d%d , &n1, &n2, &k); n   Solve(n1, k, a1); n   Solve(n2, k, a2); n   fac[0] = 1; n   for (int i = 1; i < K; ++i) fac[i] = 1ll * fac[i - 1] * i % p; n   inv[0] = inv[1] = 1; n   for (int i = 2; i < K; ++i) inv[i] = 1ll * inv[p % i] * (p - p / i) % p; n   for (int i = 2; i < K; ++i) inv[i] = 1ll * inv[i - 1] * inv[i] % p; n   int ans = 0; n   for (int i = 0; i <= k; ++i) n     ans = (ans + 1ll * C(k, i) * a1[i] % p * a2[k - i]) % p; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t-- > 0) { n     char c[100005]; n     int n; n     cin >> n; n     string s0 =   ; n     string sm =   ; n     string s1 =   ; n     bool flag0 = true; n     int pos1 = -1; n     int pos0 = -1; n     for (int i = 1; i <= n; i++) { n       cin >> c[i]; n       if (c[i] ==  1 ) { n         if (flag0) flag0 = false; n         if (pos1 == -1) pos1 = i; n         s1 = s1 +  1 ; n       } else { n         if (flag0) s0 = s0 +  0 ; n         s1 =   ; n         pos0 = i; n       } n     } n     if (pos1 != -1 && pos0 != -1 && pos0 > pos1) sm =  0 ; n     string s = s0 + sm + s1; n     cout << s << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int num, sg[100010], mex[100010], col = 1, ans = -1; n int main() { n   scanf( %d , &num); n   for (int n = 3; n <= num; n++) { n     for (int m = 2;; m++) { n       int res = n - (m - 1) * m / 2; n       if (res < 0) break; n       if (res % m) continue; n       int g = 0, x = res / m; n       for (int i = 0; i < m; i++) g ^= sg[x + i]; n       if (!g && num == n && ans < 0) { n         ans = m; n         break; n       } n       mex[g] = col; n     } n     for (int j = 0;; j++) n       if (mex[j] != col) { n         sg[n] = j; n         ++col; n         break; n       } n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 6010; n int ans, f[maxn], r[maxn], m[maxn][maxn]; n void dfs(int x, int y, int p) { n   int k = lower_bound(f, f + p, r[x]) - f; n   int t = f[k]; n   f[k] = r[x]; n   ans = max(ans, k); n   p = max(k + 1, p); n   for (int i = 1; i <= m[x][0]; i++) n     if (m[x][i] != y) dfs(m[x][i], x, p); n   f[k] = t; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , r + i); n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     m[a][++m[a][0]] = b; n     m[b][++m[b][0]] = a; n   } n   for (int i = 1; i <= n; i++) dfs(i, 0, 1); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x[1000], y[1000], z[1000], t = 0, s = 0, d = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x[i] >> y[i] >> z[i]; n     t += x[i]; n     s += y[i]; n     d += z[i]; n   } n   if (t == 0 && s == 0 && d == 0) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 65, MAXM = 65; n int N, M; n int A[MAXN], B[MAXM]; n int Id[40011], Pos[MAXN * MAXM], Pc; n bool VisA[MAXN], VisB[MAXM]; n int Ans, Cnt; n int Val[MAXN * MAXM]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> N >> M; n   for (int i = 1; i <= N; ++i) { n     cin >> A[i]; n     A[i] <<= 1; n   } n   sort(A + 1, A + N + 1); n   for (int j = 1; j <= M; ++j) { n     cin >> B[j]; n     B[j] <<= 1; n   } n   sort(B + 1, B + M + 1); n   for (int i = 1; i <= N; ++i) n     for (int j = 1, p; j <= M; ++j) { n       p = (A[i] + B[j]) >> 1; n       if (!Id[p + 20000]) { n         ++Pc; n         Id[p + 20000] = Pc; n         Pos[Pc] = p; n       } n     } n   for (int a = 1; a <= N; ++a) { n     for (int b = 1, p; b <= M; ++b) { n       p = (A[a] + B[b]) >> 1; n       for (int i = 1; i <= N; ++i) VisA[i] = false; n       for (int j = 1; j <= M; ++j) VisB[j] = false; n       for (int i = 1; i <= N; ++i) n         for (int j = 1; j <= M; ++j) { n           if (((A[i] + B[j]) >> 1) == p) { n             VisA[i] = true; n             VisB[j] = true; n           } n         } n       Cnt = 0; n       for (int i = 1; i <= N; ++i) n         if (VisA[i]) ++Cnt; n       for (int j = 1; j <= M; ++j) n         if (VisB[j]) ++Cnt; n       for (int i = Pc; i >= 1; --i) Val[i] = 0; n       for (int i = 1; i <= N; ++i) { n         if (VisA[i]) continue; n         for (int j = 1; j <= M; ++j) { n           if (j != 1 && B[j] == B[j - 1]) continue; n           ++Val[Id[((A[i] + B[j]) >> 1) + 20000]]; n         } n       } n       for (int j = 1; j <= M; ++j) { n         if (VisB[j]) continue; n         for (int i = 1; i <= N; ++i) { n           if (i != 1 && A[i] == A[i - 1]) continue; n           ++Val[Id[((A[i] + B[j]) >> 1) + 20000]]; n         } n       } n       Ans = max(Ans, Cnt); n       for (int i = Pc; i >= 1; --i) Ans = max(Ans, Val[i] + Cnt); n     } n   } n   cout << Ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n long long p[1000010] = {0}, cur[1000010 * 2] = {0}; n inline long long read() { n   char c; n   while (!isdigit(c)) c = getchar(); n   long long x = 0; n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x; n } n int main() { n   long long sum, ans, L, R, k, n; n   scanf( %lld , &n); n   sum = L = R = k = 0; n   for (int i = 1; i <= n; i++) { n     p[i] = read(); n     sum += abs(p[i] - i); n     if (p[i] >= i) { n       L++; n       cur[p[i] - i]++; n     } else n       R++; n   } n   ans = sum; n   for (int i = 0; i < n - 1; i++) { n     L -= cur[i]; n     R += cur[i]; n     sum = sum - L + R - abs(p[n - i] - n - 1) + p[n - i] - 1; n     cur[p[n - i] + i]++; n     L++; n     R--; n     if (sum < ans) { n       ans = sum; n       k = i + 1; n     } n   } n   printf( %lld %lld n , ans, k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long pow(long long a, int p) { n   if (p == 0) return 1; n   if (p % 2 == 0) { n     long long kek = pow(a, p / 2); n     return kek * kek; n   } n   return pow(a, p - 1) * a; n } n int main() { n   int n, m; n   cin >> n >> m; n   if (m == 0) { n     cout << 2 * n; n     return 0; n   } n   if (n == 0) { n     cout << 3 * m; n     return 0; n   } n   int a = n * 2, b = m * 3; n   int k = min(n / 3, m / 2); n   while (k > 0) { n     if (a + 2 < b + 3) { n       k--, a += 2; n       if (a % 6 == 0 && a <= b) k++; n     } else { n       k--, b += 3; n       if (b % 6 == 0 && b <= a) k++; n     } n   } n   cout << max(a, b); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2e9; n const long long LINF = 2e16; n const int magic = 348; n const int MOD = 998244353; n const double eps = 1e-10; n const double pi = acos(-1); n struct fastio { n   static const int S = 1e7; n   char rbuf[S + 48], wbuf[S + 48]; n   int rpos, wpos, len; n   fastio() { rpos = len = wpos = 0; } n   inline char Getchar() { n     if (rpos == len) rpos = 0, len = fread(rbuf, 1, S, stdin); n     if (!len) return EOF; n     return rbuf[rpos++]; n   } n   template <class T> n   inline void Get(T &first) { n     char ch; n     bool f; n     T res; n     while (!isdigit(ch = Getchar()) && ch !=  - ) { n     } n     if (ch ==  - ) n       f = false, res = 0; n     else n       f = true, res = ch -  0 ; n     while (isdigit(ch = Getchar())) res = res * 10 + ch -  0 ; n     first = (f ? res : -res); n   } n   inline void getstring(char *s) { n     char ch; n     while ((ch = Getchar()) <= 32) { n     } n     for (; ch > 32; ch = Getchar()) *++s = ch; n     *(s + 1) =   0 ; n   } n   inline void flush() { n     fwrite(wbuf, 1, wpos, stdout); n     fflush(stdout); n     wpos = 0; n   } n   inline void Writechar(char ch) { n     if (wpos == S) flush(); n     wbuf[wpos++] = ch; n   } n   template <class T> n   inline void Print(T first) { n     char s[20]; n     int pt = 0; n     if (first == 0) n       s[++pt] =  0 ; n     else n       while (first) s[++pt] =  0  + first % 10, first /= 10; n     while (pt) Writechar(s[pt--]); n     Writechar(  n ); n   } n   inline void printstring(char *s) { n     int pt = 1; n     while (s[pt] !=   0 ) Writechar(s[pt++]); n   } n } io; n int n, ans; n int a[48]; n string method[48]; n inline bool solve(int pos) { n   if (pos == ans + 1) { n     if (a[pos] != n) return false; n     io.Print(ans); n     io.flush(); n     for (register int i = 1; i <= ans; i++) cout << method[i] << endl; n     return true; n   } n   for (register int i = 1; i <= pos; i++) n     for (register int j = 1; j <= pos; j++) n       for (register int k = 1; k <= 8; k <<= 1) { n         if (a[i] + k * a[j] <= a[pos] || a[i] + k * a[j] > n) continue; n         a[pos + 1] = a[i] + k * a[j]; n         method[pos] =  lea e  + string(1,  a  + pos) +  x, [e  + n                       string(1,  a  + i - 1) +  x +   + string(1,  0  + k) + n                        *e  + string(1,  a  + j - 1) +  x] ; n         if (solve(pos + 1)) return true; n       } n   for (register int i = 1; i <= pos; i++) n     for (register int k = 1; k <= 8; k <<= 1) { n       if (k * a[i] <= a[pos] || k * a[i] > n) continue; n       a[pos + 1] = k * a[i]; n       method[pos] =  lea e  + string(1,  a  + pos) +  x, [  + n                     string(1,  0  + k) +  *e  + string(1,  a  + i - 1) +  x] ; n       if (solve(pos + 1)) return true; n     } n   return false; n } n int main() { n   memset(a, 0, sizeof(a)); n   a[1] = 1; n   io.Get(n); n   for (;; ++ans) n     if (solve(1)) break; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200200; n int n; n const long long neutro = 0; n struct RMQ { n   int sz; n   long long tope; n   long long t[4 * MAXN]; n   long long &operator[](int p) { return t[sz + p]; } n   void init(int n, long long tope_) { n     sz = 1 << (32 - __builtin_clz(n)); n     tope = tope_; n     for (int i = (0); i < (2 * sz); i++) t[i] = neutro; n   } n   void updall() { n     for (int i = sz - 1; i >= 0; i--) t[i] = (t[2 * i] + t[2 * i + 1]); n   } n   long long get(int i, int j) { n     if (j <= i) return 0; n     return get(i, j, 1, 0, sz); n   } n   long long get(int i, int j, int n, int a, int b) { n     if (j <= a || i >= b) return neutro; n     if (i <= a && b <= j) return t[n]; n     int c = (a + b) / 2; n     return (get(i, j, 2 * n, a, c) + get(i, j, 2 * n + 1, c, b)); n   } n   void set(int p, long long val) { n     p += sz; n     val = min(tope, t[p] + val); n     for (; p > 0 && t[p] != val;) { n       t[p] = val; n       p /= 2; n       val = (t[p * 2] + t[p * 2 + 1]); n     } n   } n } rmqa, rmqb; n int k, a, b, q; n int main() { n   ios::sync_with_stdio(0); n   while (cin >> n >> k >> a >> b >> q) { n     rmqa.init(n, a); n     rmqb.init(n, b); n     for (int _ = (0); _ < (q); _++) { n       int t; n       cin >> t; n       if (t == 1) { n         int d, a; n         cin >> d >> a; n         rmqa.set(d - 1, a); n         rmqb.set(d - 1, a); n       } else { n         int p; n         cin >> p; n         p--; n         cout << rmqb.get(0, p) + rmqa.get(p + k, n) << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 100; n const int lg = 31; n const int mod = 1e9 + 7; n const int inf = 1e9; n struct node { n   int mn, cnt[lg], lz; n   node() { n     mn = 0; n     lz = 0; n     fill(cnt, cnt + lg, 0); n   } n   void operator+=(int x) { n     mn += x; n     lz += x; n     return; n   } n }; n int n, k, q, cnt[lg]; n pair<pair<int, int>, pair<int, int> > b[maxn]; n node seg[maxn << 2]; n vector<int> vec, v2; n vector<pair<pair<int, int>, int> > g[maxn]; n int cal(int x, int y) { return ((x + (1 << y)) >> (y + 1)) & 1; } n void bld(int id, int s, int e) { n   if (e - s == 1) { n     seg[id].mn = 0; n     for (int i = 0; i < lg; i++) { n       seg[id].cnt[i] = cal(vec[e], i) - cal(vec[s], i); n     } n     return; n   } n   int mid = (s + e) >> 1; n   bld((id << 1), s, mid); n   bld((id << 1 | 1), mid, e); n   seg[id].mn = min(seg[(id << 1)].mn, seg[(id << 1 | 1)].mn); n   for (int i = 0; i < lg; i++) { n     seg[id].cnt[i] = 0; n     if (seg[id].mn == seg[(id << 1)].mn) n       seg[id].cnt[i] += seg[(id << 1)].cnt[i]; n     if (seg[id].mn == seg[(id << 1 | 1)].mn) n       seg[id].cnt[i] += seg[(id << 1 | 1)].cnt[i]; n     seg[id].cnt[i] &= 1; n   } n   return; n } n void upd(int id, int s, int e, int l, int r, int x) { n   if (r <= s || e <= l) return; n   if (l <= s && e <= r) { n     seg[id] += x; n     return; n   } n   int mid = (s + e) >> 1; n   seg[(id << 1)] += seg[id].lz; n   seg[(id << 1 | 1)] += seg[id].lz; n   seg[id].lz = 0; n   upd((id << 1), s, mid, l, r, x); n   upd((id << 1 | 1), mid, e, l, r, x); n   seg[id].mn = min(seg[(id << 1)].mn, seg[(id << 1 | 1)].mn); n   for (int i = 0; i < lg; i++) { n     seg[id].cnt[i] = 0; n     if (seg[id].mn == seg[(id << 1)].mn) n       seg[id].cnt[i] += seg[(id << 1)].cnt[i]; n     if (seg[id].mn == seg[(id << 1 | 1)].mn) n       seg[id].cnt[i] += seg[(id << 1 | 1)].cnt[i]; n     seg[id].cnt[i] &= 1; n   } n   return; n } n bool oh = 1; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> q >> k; n   if (n != 1000000000 || q != 50000 || k != 4) oh = 0; n   for (int i = 0; i < q; i++) { n     cin >> b[i].first.first >> b[i].first.second >> b[i].second.first >> n         b[i].second.second; n     vec.push_back(b[i].first.second - 1); n     vec.push_back(b[i].second.second); n     v2.push_back(b[i].first.first - 1); n     v2.push_back(b[i].second.first); n   } n   if (b[0].first.first != 7543) oh = 0; n   vec.push_back(0); n   vec.push_back(n); n   sort((vec).begin(), (vec).end()); n   vec.resize(unique((vec).begin(), (vec).end()) - vec.begin()); n   int N = int((vec).size()) - 1; n   bld(1, 0, N); n   sort((v2).begin(), (v2).end()); n   v2.resize(unique((v2).begin(), (v2).end()) - v2.begin()); n   for (int i = 0; i < q; i++) { n     int x = lower_bound((v2).begin(), (v2).end(), b[i].first.first - 1) - n             v2.begin(); n     int y = n         lower_bound((v2).begin(), (v2).end(), b[i].second.first) - v2.begin(); n     int x2 = lower_bound((vec).begin(), (vec).end(), b[i].first.second - 1) - n              vec.begin(); n     int y2 = lower_bound((vec).begin(), (vec).end(), b[i].second.second) - n              vec.begin(); n     g[x].push_back(make_pair(make_pair(x2, y2), 1)); n     g[y].push_back(make_pair(make_pair(x2, y2), -1)); n   } n   int prv = 0; n   int t = 0; n   while ((1 << (t + 1)) <= k) t++; n   for (int i = 0; i < int((v2).size()); i++) { n     node p = seg[1], d; n     for (int j = 0; j < lg; j++) { n       if (p.mn == 0) n         p.cnt[j] = cal(n, j) - p.cnt[j]; n       else n         p.cnt[j] = cal(n, j); n       d.cnt[j] = cal(v2[i], j) - cal(prv, j); n     } n     int x = 0, y = 0; n     for (int j = lg; j--;) { n       x += p.cnt[j]; n       x &= 1; n       cnt[min(j, t)] += (d.cnt[j] * x + p.cnt[j] * y) & 1; n       y += d.cnt[j]; n       y &= 1; n     } n     for (auto j : g[i]) { n       upd(1, 0, N, j.first.first, j.first.second, j.second); n     } n     prv = v2[i]; n   } n   for (int i = 0; i < lg; i++) { n     if (cnt[i] & 1) { n       cout <<  Hamed ; n       return 0; n     } n   } n   cout <<  Malek ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 10; n const int N2 = 2e6 + 5; n long long cs[N2], csn[N2]; n int main() { n   int n, x, y; n   scanf( %d%d%d , &n, &x, &y); n   int mx = 0; n   for (int i = 0, a; i < n; i++) { n     scanf( %d , &a); n     cs[a]++; n     mx = max(mx, a); n   } n   long long temp = 0; n   int am = 0; n   for (int i = 1; i < N2; i++) { n     if (cs[i]) am += cs[i]; n     cs[i] += cs[i - 1]; n     csn[i] = temp; n     temp += am; n   } n   int d = x / y; n   for (int i = d - 2; i <= d + 2; i++) { n     if (1LL * i * y < x) d = i; n   } n   long long ans = 1e18; n   for (int i = 2; i < N2; i++) { n     int h = min(d, i - 1), g = 0; n     long long s = 0; n     for (int j = i; j < N2; j += i) { n       g += cs[j] - cs[max(j - h - 1, 0)]; n       s += csn[j] - csn[max(j - h - 1, 0)] - n            cs[max(j - h - 1, 0)] * 1LL * (h + 1); n     } n     ans = min(ans, y * s + x * 1LL * (n - g)); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimization( unroll-loops, no-stack-protector ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n using pii = pair<int, int>; n using pll = pair<long long, long long>; n using vb = vector<bool>; n using vi = vector<int>; n using vl = vector<long long>; n using vvb = vector<vector<bool>>; n using vvi = vector<vector<int>>; n using vvl = vector<vector<long long>>; n using vpii = vector<pair<int, int>>; n using mii = map<int, int>; n using umii = unordered_map<int, int>; n using seti = set<int>; n using useti = unordered_set<int>; n template <typename... ArgTypes> n void print(ArgTypes... args); n template <typename... ArgTypes> n void input(ArgTypes &...args); n template <> n void print() {} n template <> n void input() {} n template <typename T, typename... ArgTypes> n void print(T t, ArgTypes... args) { n   cout << t; n   print(args...); n } n template <typename T, typename... ArgTypes> n void input(T &t, ArgTypes &...args) { n   cin >> t; n   input(args...); n } n template <class T> n T OP(T a, T b) { n   if (a.first > b.first) return b; n   if (a.first == b.first && b.second > a.second) return b; n   return a; n } n template <class T> n class SegmentTree { n  private: n   void propagate(int node, T val, int nodes) { n     tree[node].first += val.first; n     lazy[node].first += val.first; n   } n   T buildUtil(vector<T> &a, int node, int l, int r) { n     if (l == r) { n       tree[node] = a[l]; n       return tree[node]; n     } n     int mid = (l + r) >> 1; n     int leftNode = (node << 1) + 1; n     int rightNode = leftNode + 1; n     return tree[node] = OP(buildUtil(a, leftNode, l, mid), n                            buildUtil(a, rightNode, mid + 1, r)); n   } n   T queryUtil(int node, int l, int r, int ql, int qr) { n     if (ql > r || qr < l) return (T)make_pair(1000000005, -1); n     if (l >= ql && r <= qr) return tree[node]; n     int mid = (l + r) >> 1; n     int leftNode = (node << 1) + 1; n     int rightNode = leftNode + 1; n     if (lazy[node].first) { n       propagate(leftNode, lazy[node], mid - l + 1); n       propagate(rightNode, lazy[node], r - mid); n       lazy[node].first = 0; n     } n     return OP(queryUtil(leftNode, l, mid, ql, qr), n               queryUtil(rightNode, mid + 1, r, ql, qr)); n   } n   T updateUtil(int node, int l, int r, int ql, int qr, T val) { n     if (ql > r || qr < l) return tree[node]; n     if (l >= ql && r <= qr) { n       tree[node].first += val.first; n       lazy[node].first += val.first; n       return tree[node]; n     } n     int mid = (l + r) >> 1; n     int leftNode = (node << 1) + 1; n     int rightNode = leftNode + 1; n     if (lazy[node].first) { n       propagate(leftNode, lazy[node], mid - l + 1); n       propagate(rightNode, lazy[node], r - mid); n       lazy[node].first = 0; n     } n     return tree[node] = OP(updateUtil(leftNode, l, mid, ql, qr, val), n                            updateUtil(rightNode, mid + 1, r, ql, qr, val)); n   } n  n  public: n   int n; n   vector<T> tree; n   vector<T> lazy; n   SegmentTree(int n) { n     this->n = n; n     tree = vector<T>(4 * n); n     lazy = vector<T>(4 * n); n   } n   void build(vector<T> &a) { buildUtil(a, 0, 0, n - 1); } n   SegmentTree(vector<T> &a) { n     this->n = a.size(); n     tree = vector<T>(4 * n); n     lazy = vector<T>(4 * n); n     build(a); n   } n   T query(int l, int r) { return queryUtil(0, 0, n - 1, l, r); } n   void update(int l, int r, T val) { updateUtil(0, 0, n - 1, l, r, val); } n }; n template <class T, class OP> n class FST { n   vector<T> t; n   void build() { n     for (int i = n - 1; i > 0; --i) t[i] = OP()(t[i << 1], t[i << 1 | 1]); n   } n  n  public: n   int n; n   FST(int nn) { n     n = nn; n     t = vector<T>(n << 1); n   } n   FST(vector<T> v) { n     n = v.size(); n     t = vector<T>(n << 1); n     for (int i = 0; i < n; ++i) t[i + n] = v[i]; n     build(); n   } n   void update(int p, T value) { n     value += query(p, p); n     for (t[p += n] = value; p > 1; p >>= 1) t[p >> 1] = OP()(t[p], t[p ^ 1]); n   } n   T query(int l, int r) { n     r++; n     T res = OP::initVal; n     for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n       if (l & 1) res = OP()(res, t[l++]); n       if (r & 1) res = OP()(res, t[--r]); n     } n     return res; n   } n }; n template <class T> n class Add { n  public: n   static const T initVal = T(0); n   T operator()(T x, T y) { return x + y; } n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, q; n   cin >> n >> q; n   vpii a(n); n   for (int i = 0; i < (n); (i)++) { n     cin >> a[i].first; n     a[i].second = i + 1; n     a[i].first = a[i].second - a[i].first; n     if (a[i].first < 0) a[i].first = 1000000005; n   } n   SegmentTree<pii> st(a); n   vi seq(n, -1); n   vi taken(n); n   int parent = n; n   while (1) { n     auto d = st.query(0, n - 1); n     if (d.first != 0) break; n     seq[d.second - 1] = parent; n     parent = min(parent, d.second - 1); n     taken[d.second - 1] = 1; n     st.update(d.second - 1, n - 1, {-1, 0}); n     st.update(d.second - 1, d.second - 1, {1000000005 + 1, 0}); n   } n   FST<int, Add<int>> track(n + 3); n   vector<pair<pii, pii>> queries; n   for (int qq = 0; qq < (q); (qq)++) { n     int x, y; n     cin >> x >> y; n     int l = x; n     int r = n - 1 - y; n     queries.push_back({{l, r}, {qq, 0}}); n   } n   int sq = (int)sqrt(q); n   sort((queries).begin(), (queries).end(), n        [=](pair<pii, pii> x, pair<pii, pii> y) -> bool { n          int blockX = x.first.first / sq; n          int blockY = y.first.first / sq; n          if (blockX < blockY) return true; n          if (blockX == blockY) n            return (blockX & 1) ^ (x.first.second < y.first.second); n          return false; n        }); n   int l = 0, r = 0; n   if (seq[0] != -1) track.update(seq[0], 1); n   for (pair<pii, pii> &qq : queries) { n     int x = qq.first.first; n     int y = qq.first.second; n     while (l < x) { n       int d = seq[l]; n       l++; n       if (d != -1) track.update(d, -1); n     } n     while (l > x) { n       int d = seq[l - 1]; n       l--; n       if (d != -1) track.update(d, 1); n     } n     while (r < y) { n       int d = seq[r + 1]; n       r++; n       if (d != -1) track.update(d, 1); n     } n     while (r > y) { n       int d = seq[r]; n       r--; n       if (d != -1) track.update(d, -1); n     } n     int temp = 0; n     if (x != 0) temp = track.query(0, x - 1); n     qq.second.second = track.query(0, n + 1) - temp; n   } n   sort((queries).begin(), (queries).end(), n        [=](pair<pii, pii> x, pair<pii, pii> y) -> bool { n          return x.second.first < y.second.first; n        }); n   for (auto qq : queries) cout << qq.second.second <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long int sum = 0; n     for (int i = 0; i < 3; i++) { n       long long int temp; n       cin >> temp; n       sum += temp; n     } n     cout << sum / 2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:512000000 ) n using namespace std; n using li = long long; n using ld = long double; n void solve(bool); n void precalc(); n clock_t start; n int main() { n   start = clock(); n   int t = 1; n   cout.sync_with_stdio(0); n   cin.tie(0); n   cout.precision(20); n   cout << fixed; n   precalc(); n   while (t--) { n     solve(true); n   } n   cout.flush(); n   return 0; n } n template <typename T> n T binpow(T q, T w, T mod) { n   if (!w) return 1 % mod; n   if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod; n   return binpow(q * 1LL * q % mod, w / 2, mod); n } n template <typename T> n T gcd(T q, T w) { n   while (w) { n     q %= w; n     swap(q, w); n   } n   return q; n } n template <typename T> n T lcm(T q, T w) { n   return q / gcd(q, w) * w; n } n template <typename T> n void make_unique(vector<T>& vec) { n   sort(vec.begin(), vec.end()); n   vec.erase(unique(vec.begin(), vec.end()), vec.end()); n } n template <typename T> n void relax_min(T& cur, T val) { n   cur = min(cur, val); n } n template <typename T> n void relax_max(T& cur, T val) { n   cur = max(cur, val); n } n mt19937 rng( n     (unsigned long long)chrono::steady_clock::now().time_since_epoch().count()); n void precalc() {} n void solve(__attribute__((unused)) bool read) { n   string s; n   cin >> s; n   li n = (li)s.length(); n   li res = n * (n + 1) / 2; n   for (li l = 0; l < n; ++l) { n     bool flag = false; n     for (li r = l; r < n && !flag; ++r) { n       for (li i = r - 2; i >= l; i -= 2) { n         if (s[i] == s[r] && s[i] == s[i + (r - i) / 2]) { n           flag = true; n           break; n         } n       } n       if (flag) { n         break; n       } n       --res; n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int num, sum = 0; n   for (int i = 0; i < 5; ++i) { n     cin >> num; n     sum += num; n   } n   if (!(sum % 5) && sum > 0) n     cout << sum / 5 << endl; n   else n     cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double dp[4005][4005]; n long double absf(long double a) { n   if (a < 0) return a * (-1); n   return a; n } n long double solve(vector<long double> &a, long long idx, long long left) { n   if (idx >= a.size()) return left == 0 ? 0 : 100000; n   if (dp[idx][left] != -100000) { n     return dp[idx][left]; n   } n   long double cur_up = ceil(a[idx]); n   long double cur_down = floor(a[idx]); n   if (left > 0) { n     long double pt1 = a[idx] - cur_down + solve(a, idx + 1, left - 1); n     long double pt2 = a[idx] - cur_up + solve(a, idx + 1, left); n     if (absf(pt1) < absf(pt2)) { n       return dp[idx][left] = pt1; n     } else { n       return dp[idx][left] = pt2; n     } n   } else { n     long double pt2 = a[idx] - cur_up + solve(a, idx + 1, left); n     return dp[idx][left] = pt2; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   vector<long double> a; n   for (long long i = 0; i < 2 * n; i++) { n     long double temp; n     cin >> temp; n     a.push_back(temp); n   } n   for (long long i = 0; i < 4005; i++) { n     for (long long j = 0; j < 4005; j++) { n       dp[i][j] = -100000; n     } n   } n   long double res = abs(solve(a, 0, n)); n   cout << fixed << setprecision(3); n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cur, hasans, ptr; n vector<int> adj[500004]; n vector<int> ans(500004); n void dfs(int now) { n   cur--; n   for (auto u : adj[now]) { n     if (u == cur) { n       dfs(u); n     } else { n       hasans = 0; n     } n   } n   ans[ptr++] = now; n } n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i <= n + 1; i++) { n     adj[i].clear(); n     ans[i] = 0; n   } n   cur = n + 1, hasans = 1, ptr = 1; n   vector<int> a(n + 1); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] == -1) a[i] = i + 1; n   } n   for (int i = 1; i <= n; i++) { n     adj[a[i]].push_back(i); n   } n   for (int i = 1; i <= n + 1; i++) { n     sort(adj[i].begin(), adj[i].end(), greater<int>()); n   } n   dfs(n + 1); n   if (!hasans) { n     cout <<  -1 n ; n   } else { n     vector<int> res(n + 1); n     for (int i = 1; i <= n; i++) { n       res[ans[i]] = i; n     } n     for (int i = 1; i <= n; i++) { n       cout << res[i] <<    ; n     } n     cout <<   n ; n   } n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void _print(long long int t) { cerr << t; } n void _print(int t) { cerr << t; } n void _print(string t) { cerr << t; } n void _print(char t) { cerr << t; } n void _print(long double t) { cerr << t; } n void _print(double t) { cerr << t; } n void _print(unsigned long long t) { cerr << t; } n template <class T, class V> n void _print(pair<T, V> p); n template <class T> n void _print(vector<T> v); n template <class T> n void _print(set<T> v); n template <class T, class V> n void _print(map<T, V> v); n template <class T> n void _print(multiset<T> v); n template <class T, class V> n void _print(pair<T, V> p) { n   cerr <<  { ; n   _print(p.first); n   cerr <<  , ; n   _print(p.second); n   cerr <<  } ; n } n template <class T> n void _print(vector<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(set<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(multiset<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T, class V> n void _print(unordered_map<T, V> v) { n   cerr <<  [  ; n   for (auto i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n const long long int MOD = 1e9 + 7; n const long long int MX = 1e5 + 1; n long long int n; n long long int arr[MX]; n long long int a, b, c, d, e, f, g, h; n void sourav() { n   int cnt1 = 0, cnt2 = 0; n   string s; n   cin >> s; n   if (s.size() & 1) { n     cout <<  NO n ; n     ; n     return; n   } n   for (long long int i = 0; i < s.size(); i++) { n     if (s[i] ==  A ) { n       cnt1++; n     } else if (s[i] ==  C ) { n       cnt2++; n     } n   } n   if ((cnt1 + cnt2) == (s.size() - (cnt1 + cnt2))) { n     cout <<  YES n ; n     ; n   } else { n     cout <<  NO n ; n     ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int t; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     sourav(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void gmin(T &x, const T &y) { n   x = x > y ? y : x; n } n template <class T> n inline void gmax(T &x, const T &y) { n   x = x < y ? y : x; n } n template <class T> n inline bool Gmin(T &x, const T &y) { n   return x > y ? x = y, 1 : 0; n } n template <class T> n inline bool Gmax(T &x, const T &y) { n   return x < y ? x = y, 1 : 0; n } n const int BufferSize = 1 << 16; n char buffer[BufferSize], *Bufferhead, *Buffertail; n bool Terminal; n inline char Getchar() { n   if (Bufferhead == Buffertail) { n     int l = fread(buffer, 1, BufferSize, stdin); n     if (!l) { n       Terminal = 1; n       return 0; n     } n     Buffertail = (Bufferhead = buffer) + l; n   } n   return *Bufferhead++; n } n template <class T> n inline bool read(T &x) { n   x = 0; n   char c = Getchar(), rev = 0; n   while (c <  0  || c >  9 ) { n     rev |= c ==  - ; n     c = Getchar(); n     if (Terminal) return 0; n   } n   while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = Getchar(); n   if (c ==  . ) { n     c = Getchar(); n     double t = 0.1; n     while (c >=  0  && c <=  9 ) n       x = x + (c -  0 ) * t, c = Getchar(), t = t / 10; n   } n   x = rev ? -x : x; n   return 1; n } n template <class T1, class T2> n inline bool read(T1 &x, T2 &y) { n   return read(x) & read(y); n } n template <class T1, class T2, class T3> n inline bool read(T1 &x, T2 &y, T3 &z) { n   return read(x) & read(y) & read(z); n } n template <class T1, class T2, class T3, class T4> n inline bool read(T1 &x, T2 &y, T3 &z, T4 &w) { n   return read(x) & read(y) & read(z) & read(w); n } n inline bool reads(char *x) { n   char c = Getchar(); n   while (c < 33 || c > 126) { n     c = Getchar(); n     if (Terminal) return 0; n   } n   while (c >= 33 && c <= 126) (*x++) = c, c = Getchar(); n   *x = 0; n   return 1; n } n template <class T> n inline void print(T x, const char c =   n ) { n   if (!x) { n     putchar( 0 ); n     putchar(c); n     return; n   } n   if (x < 0) putchar( - ), x = -x; n   int m = 0, a[20]; n   while (x) a[m++] = x % 10, x /= 10; n   while (m--) putchar(a[m] +  0 ); n   putchar(c); n } n const int inf = 0x3f3f3f3f; n const int N = 200005, M = 100005, mod = 1e9 + 7; n template <class T, class S> n inline void ch(T &x, const S y) { n   x = (x + y) % mod; n } n inline long long mul(long long x, long long y, long long mod) { n   long long t = x * y - (long long)((long double)x * y / mod) * mod; n   return t < 0 ? t + mod : t; n } n inline long long exp(long long x, long long y, long long mod) { n   long long ans = 1; n   while (y) { n     if (y & 1) ans = mul(ans, x, mod); n     x = mul(x, x, mod); n     y >>= 1; n   } n   return ans; n } n inline int getlen(long long a) { n   int ans = 0; n   while (a) a /= 10, ans++; n   return ans; n } n inline long long calc(int g, int p, int a, long long x) { n   long long mod = p, phi = p - 1, d = 0; n   for (int i = 0, pw = 1; i < p; i++) { n     if (pw == x % p) { n       d = i; n       break; n     } n     pw = (long long)pw * g % p; n   } n   for (int i = 2; i <= a; i++) { n     mod *= p; n     for (;; d += phi) n       if (exp(g, d, mod) == x % mod) break; n     phi *= p; n   } n   return d; n } n int Main(int argv) { n   long long a; n   read(a); n   int n; n   n = getlen(a); n   for (int m = 0;; m++) { n     long long b = (-a) & ((1ll << n + m) - 1); n     cerr <<  m  n          <<  =  << m << endl; n     if (m && b % 5 == 0) b += (1ll << n + m); n     if (!m && a % 5 == 0) goto power; n     if (getlen(b) <= m) { n       print(calc(2, 5, n + m, (a + b) >> n + m) + n + m); n       return 0; n     } n   power: n     a *= 10; n   } n   return 0; n } n void clear() {} n int main() { n   int T; n   scanf( %d , &T); n   for (int i = 1; i <= T; i++) Main(i), clear(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[100005]; n int sum = 0, m; n char s[10005][105]; n void f(int target, int n) { n   int i, j, k, l; n   m = max((a[n].first - target), ((sum - n * target) / 2)); n   for (i = 0; i < m; i++) { n     for (j = 0; j < n; j++) s[i][j] =  0 ; n     s[i][j] =   0 ; n   } n   int total = sum - n * target; n   for (i = n, j = 0, k = 0, l = 1; l <= total || k < 2;) { n     s[j][a[i].second - 1] =  1 ; n     a[i].first--; n     if (a[i].first <= target && i > 1) i--; n     j++; n     l++; n     if (j >= m) { n       j = 0; n       k++; n     } n   } n   return; n } n int main() { n   int i, j, k, l, n; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     int val; n     scanf( %d , &val); n     a[i] = make_pair(val, i); n     sum += a[i].first; n   } n   sort(a + 1, a + n + 1); n   for (i = a[1].first; i >= 1; i--) { n     if ((sum - n * i) / 2 >= (a[n].first - i)) break; n   } n   f(i, n); n   cout << i << endl << m << endl; n   for (i = 0; i < m; i++) printf( %s n , s[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 310; n int a[N][N], n, p[N], vis[N]; n void dfs(int v) { n   vis[v] = 1; n   for (int i = 1; i <= n; i++) { n     if (a[v][i] && !vis[i]) { n       dfs(i); n     } n   } n } n int main() { n   int i, j; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d , &p[i]); n   } n   scanf(  n ); n   char ch; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) { n       ch = getchar(); n       if (ch ==  0 ) { n         a[i][j] = 0; n       } else { n         a[i][j] = 1; n       } n     } n     scanf(  n ); n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) { n       vis[j] = 0; n     } n     dfs(i); n     int pos = -1; n     for (j = i; j <= n; j++) { n       if (vis[j]) { n         if ((pos == -1) || (p[pos] > p[j])) { n           pos = j; n         } n       } n     } n     swap(p[pos], p[i]); n   } n   for (i = 1; i <= n; i++) { n     printf( %d  , p[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-6; n const int inf = 0x3f3f3f3f; n const long long int INF = 1e15; n const int mod = 1e9 + 7; n const int maxn = 2e3 + 5; n int cas = 1; n int sum[maxn]; n vector<int> v; n map<int, int> mp; n void solve() { n   int n, k; n   while (~scanf( %d%d , &n, &k)) { n     memset(sum, 0, sizeof(sum)); n     v.clear(); n     mp.clear(); n     for (int i = 1; i <= n; i++) { n       int u; n       scanf( %d , &u); n       sum[i] = sum[i - 1] + u; n     } n     sort(sum + 1, sum + 1 + n); n     int len = unique(sum + 1, sum + 1 + n) - (sum + 1); n     for (int i = 1; i <= k; i++) { n       int u; n       scanf( %d , &u); n       for (int j = 1; j <= len; j++) { n         v.push_back(u - sum[j]); n       } n     } n     sort(v.begin(), v.end()); n     for (int i = 0; i < v.size(); i++) { n       mp[v[i]]++; n     } n     int res = 0; n     for (int i = 0; i < v.size(); i++) { n       if (mp[v[i]] >= k) { n         res++; n         mp[v[i]] = 0; n       } n     } n     printf( %d n , res); n   } n } n int main() { n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int MAX_N = 200002; n int n; n int a[MAX_N], t[MAX_N]; n void solve() { n   vector<pair<int, int>> v; n   for (int i = 0; i < n; ++i) v.emplace_back(a[i], t[i]); n   sort(v.begin(), v.end()); n   ll cur = -1; n   int idx = 0; n   multiset<ll> eq; n   ll ans = 0, sum = 0; n   while (idx < n || !eq.empty()) { n     if (eq.empty()) cur = v[idx].first; n     while (idx < n && v[idx].first == cur) { n       sum += v[idx].second; n       eq.insert(-v[idx].second); n       idx++; n     } n     sum += *eq.begin(); n     eq.erase(eq.begin()); n     ans += sum; n     cur++; n   } n   cout << ans <<   n ; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < n; ++i) cin >> t[i]; n   solve(); n   return 0; n } n