#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long n; n   cin >> n; n   long long ar[n + 1]; n   for (long long i = 0; i < n; i++) { n     cin >> ar[i]; n   } n   ar[n] = n + 1; n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     long long x = ar[i]; n     long long y = ar[i + 1]; n     if (x > y) { n       ans += (x - y) * (n - x + 1); n     } n     if (x < y) { n       ans += x * (y - x); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n const int mod = 1000000007; n const int gmod = 3; n const int inf = 1039074182; n const double eps = 1e-9; n const long long llinf = 2LL * inf * inf; n template <typename T1, typename T2> n inline void chmin(T1 &x, T2 b) { n   if (b < x) x = b; n } n template <typename T1, typename T2> n inline void chmax(T1 &x, T2 b) { n   if (b > x) x = b; n } n inline void chadd(int &x, int b) { n   x += b - mod; n   x += (x >> 31 & mod); n } n template <typename T1, typename T2> n inline void chadd(T1 &x, T2 b) { n   x += b; n   if (x >= mod) x -= mod; n } n template <typename T1, typename T2> n inline void chmul(T1 &x, T2 b) { n   x = 1LL * x * b % mod; n } n template <typename T1, typename T2> n inline void chmod(T1 &x, T2 b) { n   x %= b, x += b; n   if (x >= b) x -= b; n } n template <typename T> n inline T mabs(T x) { n   return (x < 0 ? -x : x); n } n using namespace std; n using namespace std; n template <typename T> n ostream &operator<<(ostream &cout, vector<T> vec) { n   cout <<  { ; n   for (int i = 0; i < (int)vec.size(); i++) { n     cout << vec[i]; n     if (i != (int)vec.size() - 1) cout <<  , ; n   } n   cout <<  } ; n   return cout; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &cout, pair<T1, T2> p) { n   cout <<  (  << p.first <<  ,  << p.second <<  ) ; n   return cout; n } n template <typename T, typename T2> n ostream &operator<<(ostream &cout, set<T, T2> s) { n   vector<T> t; n   for (auto x : s) t.push_back(x); n   cout << t; n   return cout; n } n template <typename T, typename T2> n ostream &operator<<(ostream &cout, multiset<T, T2> s) { n   vector<T> t; n   for (auto x : s) t.push_back(x); n   cout << t; n   return cout; n } n template <typename T> n ostream &operator<<(ostream &cout, queue<T> q) { n   vector<T> t; n   while (q.size()) { n     t.push_back(q.front()); n     q.pop(); n   } n   cout << t; n   return cout; n } n template <typename T1, typename T2, typename T3> n ostream &operator<<(ostream &cout, map<T1, T2, T3> m) { n   for (auto &x : m) { n     cout <<  Key:   << x.first <<     <<  Value:   << x.second << endl; n   } n   return cout; n } n template <typename T1, typename T2> n void operator+=(pair<T1, T2> &x, const pair<T1, T2> y) { n   x.first += y.first; n   x.second += y.second; n } n template <typename T1, typename T2> n pair<T1, T2> operator+(const pair<T1, T2> &x, const pair<T1, T2> &y) { n   return make_pair(x.first + y.first, x.second + y.second); n } n template <typename T1, typename T2> n pair<T1, T2> operator-(const pair<T1, T2> &x, const pair<T1, T2> &y) { n   return make_pair(x.first - y.first, x.second - y.second); n } n template <typename T1, typename T2> n pair<T1, T2> operator-(pair<T1, T2> x) { n   return make_pair(-x.first, -x.second); n } n template <typename T> n vector<vector<T>> operator~(vector<vector<T>> vec) { n   vector<vector<T>> v; n   int n = vec.size(), m = vec[0].size(); n   v.resize(m); n   for (int i = 0; i < m; i++) { n     v[i].resize(n); n   } n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       v[i][j] = vec[j][i]; n     } n   } n   return v; n } n void print0x(int x) { n   std::vector<int> vec; n   while (x) { n     vec.push_back(x & 1); n     x >>= 1; n   } n   std::reverse(vec.begin(), vec.end()); n   for (int i = 0; i < (int)vec.size(); i++) { n     std::cout << vec[i]; n   } n   std::cout <<    ; n } n template <typename T> n void print0x(T x, int len) { n   std::vector<int> vec; n   while (x) { n     vec.push_back(x & 1); n     x >>= 1; n   } n   reverse(vec.begin(), vec.end()); n   for (int i = (int)vec.size(); i < len; i++) { n     putchar( 0 ); n   } n   for (size_t i = 0; i < vec.size(); i++) { n     std::cout << vec[i]; n   } n   std::cout <<    ; n } n vector<string> vec_splitter(string s) { n   s +=  , ; n   vector<string> res; n   while (!s.empty()) { n     res.push_back(s.substr(0, s.find( , ))); n     s = s.substr(s.find( , ) + 1); n   } n   return res; n } n void debug_out(vector<string> __attribute__((unused)) args, n                __attribute__((unused)) int idx, n                __attribute__((unused)) int LINE_NUM) { n   cerr << endl; n } n template <typename Head, typename... Tail> n void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { n   if (idx > 0) n     cerr <<  ,  ; n   else n     cerr <<  Line(  << LINE_NUM <<  )  ; n   stringstream ss; n   ss << H; n   cerr << args[idx] <<   =   << ss.str(); n   debug_out(args, idx + 1, LINE_NUM, T...); n } n struct DSUAE { n   int *f; n   inline void clear(int n) { n     for (int i = 0; i < n; i++) { n       f[i] = i; n     } n   } n   inline void init(int n) { n     f = new int[n + 5]; n     clear(n); n   } n   inline int find(int x) { return (f[x] == x ? x : f[x] = find(f[x])); } n   inline void merge(int x, int y) { n     x = find(x); n     y = find(y); n     if (x == y) return; n     if (x & 1) n       f[x] = y; n     else n       f[y] = x; n   } n }; n struct DSU { n   int *f; n   int *depth; n   int *sz; n   inline void clear(int n) { n     for (int i = 0; i < n; i++) { n       f[i] = i; n       depth[i] = 1; n       sz[i] = 1; n     } n   } n   inline void init(int n) { n     f = new int[n + 5]; n     depth = new int[n + 5]; n     sz = new int[n + 5]; n     clear(n); n   } n   inline int find(int x) { return (f[x] == x ? x : f[x] = find(f[x])); } n   inline int getSize(int x) { return sz[find(x)]; } n   inline int merge(int x, int y) { n     x = find(x); n     y = find(y); n     if (x == y) return false; n     if (depth[x] > depth[y]) { n       f[y] = x; n       sz[x] += sz[y]; n     } else if (depth[y] > depth[x]) { n       f[x] = y; n       sz[y] += sz[x]; n     } else { n       sz[y] += sz[x]; n       f[x] = y; n       depth[y]++; n     } n     return true; n   } n   inline int same(int x, int y) { return (find(x) == find(y)); } n   ~DSU() { n     delete f; n     delete depth; n     delete sz; n   } n }; n struct PersistentDSU : public DSU { n   int find(int x) { return (x == f[x] ? x : find(f[x])); } n   inline int merge(int x, int y) { n     x = find(x); n     y = find(y); n     if (x == y) return false; n     if (depth[x] > depth[y]) { n       f[y] = x; n       sz[x] += sz[y]; n     } else if (depth[y] > depth[x]) { n       f[x] = y; n       sz[y] += sz[x]; n     } else { n       sz[y] += sz[x]; n       f[x] = y; n       depth[y]++; n     } n     return true; n   } n }; n using namespace std; n int n; n char c[55][55]; n DSUAE dsu; n vector<int> scc[55]; n vector<vector<int>> a; n int b[55][55]; n int p[55]; n int main() { n   double t = clock(); n   scanf( %d , &n); n   dsu.init(n); n   for (int i = 0; i < n; i++) scanf( %s , c[i]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (c[i][j] ==  A ) dsu.merge(i, j); n     } n   } n   for (int i = 0; i < n; i++) scc[dsu.find(i)].push_back(i); n   int now = 0; n   for (int i = 0; i < n; i++) { n     if (scc[i].empty()) continue; n     for (auto x : scc[i]) { n       for (auto y : scc[i]) { n         if (c[x][y] ==  X ) { n           cout <<  -1  << endl; n           exit(0); n         }; n       } n     } n     if (scc[i].size() > 1) n       now += scc[i].size(); n     else n       now += 1; n     if (scc[i].size() > 1) a.push_back(scc[i]); n   } n   n = a.size(); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i == j) continue; n       bool noXor = true; n       for (auto x : a[i]) { n         for (auto y : a[j]) { n           noXor &= (c[x][y] !=  X ); n         } n       } n       if (!noXor) n         b[i][j] = 1; n       else n         b[i][j] = 0; n     } n   } n   for (int i = 0; i < n; i++) p[i] = i; n   int res = inf; n   while ((clock() - t) / CLOCKS_PER_SEC <= 0.001) { n     random_shuffle(p, p + n); n     vector<vector<int>> v; n     for (int i = 0; i < n; i++) { n       int x = p[i]; n       int found = false; n       for (auto &vv : v) { n         int ok = true; n         for (auto &u : vv) { n           ok &= (b[u][x] == 0); n         } n         if (ok) { n           found = true; n           vv.push_back(x); n           break; n         } n       } n       if (!found) { n         v.push_back(vector<int>{x}); n       } n     } n     chmin(res, v.size()); n   } n   cout << res + now - 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   multiset<long long> v; n   vector<pair<string, long long>> ans; n   for (int i = 0; i < n; ++i) { n     string s; n     cin >> s; n     if (s ==  insert ) { n       long long x; n       cin >> x; n       ans.push_back({ insert , x}); n       v.insert(x); n     } n     if (s ==  removeMin ) { n       if (v.size() == 0) { n         ans.push_back({ insert , 1}); n         v.insert(1); n       } n       ans.push_back({ removeMin , 0}); n       v.erase(v.begin()); n     } n     if (s ==  getMin ) { n       long long x; n       cin >> x; n       if (v.find(x) == v.end()) { n         ans.push_back({ insert , x}); n         v.insert(x); n       } n       while (*(v.begin()) != x) { n         ans.push_back({ removeMin , 0}); n         v.erase(v.begin()); n       } n       ans.push_back({ getMin , x}); n     } n   } n   cout << ans.size() <<   n ; n   for (auto i : ans) { n     cout << i.first <<    ; n     if (i.first !=  removeMin ) { n       cout << i.second; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using INT = long long; n const int NN = 111; n string tar; n string s[NN]; n int n; n void dfs(int len) { n   if (!len) { n     for (int i = 1; i <= n; i++) { n       for (int j = 0; j < s[i].length(); j++) { n         int f = 1; n         for (int k = j; k < s[i].length(); k++) { n           if (k - j == tar.length()) { n             puts( YES ); n             exit(0); n           } n           if (tar[k - j] != s[i][k]) { n             f = 0; n             break; n           } n         } n         if (f) dfs(s[i].length() - j); n       } n     } n     return; n   } n   for (int i = 1; i <= n; i++) { n     int j = 0; n     for (; j < s[i].length(); j++) { n       if (tar[len + j] != s[i][j]) break; n     } n     if (len + j == tar.length()) { n       puts( YES ); n       exit(0); n     } n     if (j == s[i].length()) dfs(len + j); n   } n } n int main() { n   cin >> tar; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> s[i]; n   dfs(0); n   puts( NO ); n } n


#include <bits/stdc++.h> n const long long N = 2e5 + 7; n const long long M = 2e4 + 5; n const double eps = 1e-8; n const long long mod = 1e9 + 7; n const long long inf = 0x7fffffff; n const double pi = 3.1415926; n using namespace std; n vector<long long> v[N], num; n long long n; n long long dfs(long long x, long long fa) { n   long long sum = 1; n   for (long long i = 0; i < v[x].size(); i++) { n     if (v[x][i] == fa) continue; n     sum += dfs(v[x][i], x); n   } n   if (x != 1) num.push_back((n - sum) * sum); n   return sum; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) { n     cin >> n; n     for (long long i = 0; i <= n; i++) v[i].clear(); n     num.clear(); n     for (long long i = 1; i < n; i++) { n       long long x, y; n       cin >> x >> y; n       v[x].push_back(y); n       v[y].push_back(x); n     } n     long long m; n     cin >> m; n     vector<long long> p; n     for (long long i = 0; i < m; i++) { n       long long c; n       cin >> c; n       p.push_back(c); n     } n     dfs(1, -1); n     if (m < n - 1) { n       for (long long i = 0; i < n - 1 - m; i++) p.push_back(1); n     } n     sort(num.begin(), num.end()); n     sort(p.begin(), p.end()); n     long long ans = 0; n     if (m <= n - 1) { n       for (long long i = 0; i < n - 1; i++) { n         ans += (num[i] * p[i]) % mod; n         ans %= mod; n       } n     } else { n       for (long long i = 0; i < n - 2; i++) { n         ans += (num[i] * p[i]) % mod; n         ans %= mod; n       } n       long long add = 1; n       for (long long i = n - 2; i < m; i++) { n         add = (add * p[i]) % mod; n       } n       ans += (add * num[n - 2]) % mod; n       ans %= mod; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long nums[100005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   long long potL = 1000000000; n   long long total = 0; n   for (int i = 0; i < n; i++) { n     long long num; n     cin >> num; n     if (num % 2 == 1 && num < potL) potL = num; n     total += num; n     nums[i] = num; n   } n   if (total % 2 == 1) total -= potL; n   cout << total << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, n, x[110], y[110], f[110], j, ans; n bool b[110]; n int find(int x) { n   if (f[x] == x) n     return x; n   else n     return f[x] = find(f[x]); n } n void Union(int x, int y) { f[find(x)] = find(y); } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) f[i] = i; n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &x[i], &y[i]); n   } n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) n       if (find(i) != find(j)) n         if (x[i] == x[j] || y[i] == y[j]) Union(i, j); n   memset(b, 0, sizeof(b)); n   for (i = 1; i <= n; i++) n     if (!b[find(i)]) b[find(i)] = 1, ans++; n   printf( %d n , ans - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 2e5 + 7; n int N, M, head[maxN], cnt; n struct Eddge { n   int nex, to, id; n   Eddge(int a = -1, int b = 0, int c = 0) : nex(a), to(b), id(c) {} n } edge[maxN << 1]; n inline void addEddge(int u, int v, int id) { n   edge[cnt] = Eddge(head[u], v, id); n   head[u] = cnt++; n } n inline void _add(int u, int v, int id) { n   addEddge(u, v, id); n   addEddge(v, u, id); n } n inline void init() { n   cnt = 0; n   for (int i = 1; i <= N; i++) head[i] = -1; n } n struct node { n   int u, v, op; n   node(int a = 0, int b = 0, int c = -1) : u(a), v(b), op(c) {} n } t[maxN]; n struct Point { n   int id, op; n   Point(int a = 0, int b = 0) : id(a), op(b) {} n }; n queue<Point> Q; n bool bfs() { n   t[1].op = 1; n   Q.push(Point(t[1].u, 1)); n   while (!Q.empty()) { n     Point now = Q.front(); n     Q.pop(); n     int u = now.id; n     for (int i = head[u], v, id; ~i; i = edge[i].nex) { n       id = edge[i].id; n       if (~t[id].op) { n         if (t[id].u == u) { n           if (t[id].op == 0 && now.op == 1) return false; n           if (t[id].op == 1 && now.op == -1) return false; n         } else { n           if (t[id].op == 0 && now.op == -1) return false; n           if (t[id].op == 1 && now.op == 1) return false; n         } n         continue; n       } n       v = edge[i].to; n       if (now.op == 1) { n         Q.push(Point(v, -1)); n         if (t[id].u == u) n           t[id].op = 1; n         else n           t[id].op = 0; n       } else { n         Q.push(Point(v, 1)); n         if (t[id].u == u) n           t[id].op = 0; n         else n           t[id].op = 1; n       } n     } n   } n   Q.push(Point(t[1].v, -1)); n   while (!Q.empty()) { n     Point now = Q.front(); n     Q.pop(); n     int u = now.id; n     for (int i = head[u], v, id; ~i; i = edge[i].nex) { n       id = edge[i].id; n       if (~t[id].op) { n         if (t[id].u == u) { n           if (t[id].op == 0 && now.op == 1) return false; n           if (t[id].op == 1 && now.op == -1) return false; n         } else { n           if (t[id].op == 0 && now.op == -1) return false; n           if (t[id].op == 1 && now.op == 1) return false; n         } n         continue; n       } n       v = edge[i].to; n       if (now.op == 1) { n         Q.push(Point(v, -1)); n         if (t[id].u == u) n           t[id].op = 1; n         else n           t[id].op = 0; n       } else { n         Q.push(Point(v, 1)); n         if (t[id].u == u) n           t[id].op = 0; n         else n           t[id].op = 1; n       } n     } n   } n   return true; n } n int main() { n   scanf( %d%d , &N, &M); n   init(); n   for (int i = 1, u, v; i <= M; i++) { n     scanf( %d%d , &u, &v); n     t[i] = node(u, v, -1); n     _add(u, v, i); n   } n   if (bfs()) { n     printf( YES n ); n     for (int i = 1; i <= M; i++) printf( %d , t[i].op); n     printf(  n ); n   } else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n map<string, int> mid, pid; n std::vector<string> hostname; n vector<int> a[100000]; n char s[1000]; n int m_total = 0, p_total = 0; n int b[100000]; n std::vector<std::vector<int> > ans; n bool cmp(int i, int j) { return a[i] < a[j]; } n int main(int argc, char const *argv[]) { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %s , s); n     int j = 7; n     for (; s[j]; ++j) n       if (s[j] ==  / ) break; n     string host =   , path =   ; n     for (int k = 0; k < j; ++k) host += s[k]; n     for (int k = j; s[k]; ++k) path += s[k]; n     if (mid.count(host) == 0) { n       mid[host] = m_total++; n       hostname.push_back(host); n     } n     if (pid.count(path) == 0) { n       pid[path] = p_total++; n     } n     a[mid[host]].push_back(pid[path]); n   } n   for (int i = 0; i < m_total; ++i) { n     sort(a[i].begin(), a[i].end()); n     a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end()); n     b[i] = i; n   } n   sort(b, b + m_total, cmp); n   int l = 0; n   for (int i = 1; i < m_total; ++i) { n     if (a[b[i]] != a[b[l]]) { n       if (i - l > 1) { n         std::vector<int> v; n         v.clear(); n         for (int j = l; j < i; ++j) v.push_back(b[j]); n         ans.push_back(v); n       } n       l = i; n     } n   } n   if (m_total - l > 1) { n     std::vector<int> v; n     v.clear(); n     for (int j = l; j < m_total; ++j) v.push_back(b[j]); n     ans.push_back(v); n   } n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); ++i) { n     for (int j = 0; j < ans[i].size(); ++j) { n       printf( %s%c , hostname[ans[i][j]].c_str(), n              j < ans[i].size() - 1 ?     :   n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int maxn = 1e4 + 5; n int n, b, q; n int a[maxn], c[maxn]; n inline int f(int x, int j) { return (x / 5) + (x % 5 >= j); } n inline int calc(int j, int l, int r) { return f(r, j) - f(l - 1, j); } n int main() { n   scanf( %d%d%d , &n, &b, &q); n   memset(a, -1, sizeof(a)); n   for (int i = (0); i < (q); ++i) { n     int x, k; n     scanf( %d%d , &x, &k); n     if (~a[x] && a[x] != k) { n       puts( unfair ); n       return 0; n     } n     a[x] = k; n   } n   if (~a[b] && a[b] != n) { n     puts( unfair ); n     return 0; n   } n   a[b] = n; n   a[0] = 0; n   for (int msk = (0); msk < (1 << 5); ++msk) { n     int x, g = 0, lst = 0; n     for (int i = (1); i <= (b); ++i) n       if (~a[i]) { n         int sub = 0, nin = 0; n         if (a[i] < a[lst]) { n           puts( unfair ); n           return 0; n         } n         for (int j = (0); j < (5); ++j) { n           if (msk >> j & 1) n             sub += calc(j, lst + 1, i); n           else n             nin += calc(j, lst + 1, i); n         } n         g += min(a[i] - a[lst], sub); n         if (a[i] - a[lst] > i - lst) { n           puts( unfair ); n           return 0; n         } n         lst = i; n       } n     x = __builtin_popcount(msk) * n / 5; n     if (x > g) { n       puts( unfair ); n       return 0; n     } n   } n   puts( fair ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ins[300]; n struct Rec { n   int n, p; n   int a[10]; n } st[1000000]; n void Print(int now) { n   int i, j, x, pre, ret; n   if (now == 0) return; n   pre = st[now].p; n   ret = st[now].a[st[now].n - 1]; n   for (i = 0; i < st[pre].n; i++) n     for (x = 2; x <= 8; x <<= 1) n       if (st[pre].a[i] * x == ret) { n         Print(pre); n         printf( lea e%cx, [%d*e%cx] n , st[now].n +  a  - 1, x,  a  + i); n         return; n       } n   for (i = 0; i < st[pre].n; i++) n     for (j = 0; j < st[pre].n; j++) n       for (x = 1; x <= 8; x <<= 1) n         if (st[pre].a[i] + st[pre].a[j] * x == ret) { n           Print(pre); n           printf( lea e%cx, [e%cx + %d*e%cx] n , st[now].n +  a  - 1, i +  a , n                  x, j +  a ); n           return; n         } n } n int main() { n   int i, j, n, x, low, top, lim, ret; n   scanf( %d , &n); n   if (n == 1) { n     puts( 0 ); n     return 0; n   } n   st[0].n = 1; n   st[0].a[0] = 1; n   for (low = top = 0; low <= top; low++) { n     memset(ins, 0, sizeof(ins)); n     lim = st[low].a[st[low].n - 1]; n     for (i = 0; i < st[low].n; i++) n       for (x = 2; x <= 8; x <<= 1) { n         ret = st[low].a[i] * x; n         if (ret <= lim || ret > n) continue; n         ins[ret] = 1; n       } n     for (i = 0; i < st[low].n; i++) n       for (j = 0; j < st[low].n; j++) n         for (x = 1; x <= 8; x <<= 1) { n           ret = st[low].a[i] + st[low].a[j] * x; n           if (ret <= lim || ret > n) continue; n           ins[ret] = 1; n         } n     for (i = lim + 1; i <= n; i++) n       if (ins[i]) { n         st[++top].n = st[low].n; n         for (j = 0; j < st[low].n; j++) st[top].a[j] = st[low].a[j]; n         st[top].a[st[top].n++] = i; n         st[top].p = low; n         if (i == n) { n           printf( %d n , st[top].n - 1); n           Print(top); n           return 0; n         } n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n queue<long long> q1; n long long a[20005]; n long long l, r; n int main(void) { n   int i = 0; n   int j; n   cin >> l >> r; n   q1.push(0); n   while (1) { n     a[i] = q1.front() * 10 + 4; n     i++; n     if (a[i - 1] >= r) break; n     q1.push(a[i - 1]); n     a[i] = q1.front() * 10 + 7; n     i++; n     if (a[i - 1] >= r) break; n     q1.push(a[i - 1]); n     q1.pop(); n   } n   long long sum = 0; n   for (j = 0; j < i; j++) { n     if (l <= a[j] && r > a[j]) { n       sum += a[j] * (a[j] + 1 - l); n       l = a[j] + 1; n     } else if (l <= a[j] && r <= a[j]) { n       sum += a[j] * (r + 1 - l); n       break; n     } n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = (long long)1e9 + 7; n const long double PI = 3.141592653589793238462643383279502884197; n long long fac[1] = {1}, inv[1] = {1}; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long mp(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = ret * a % MOD; n     a = a * a % MOD; n     b >>= 1; n   } n   return ret; n } n long long cmb(long long r, long long c) { n   return fac[r] * inv[c] % MOD * inv[r - c] % MOD; n } n vector<int> v[1000000], rv[1000000]; n char visit[1000000], mark[1000000]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   while (m--) { n     int a, b; n     scanf( %d %d , &a, &b); n     a--; n     b--; n     v[a].push_back(b); n     rv[b].push_back(a); n   } n   for (int i = 0; i < n; i++) { n     if (visit[i] == 0) { n       visit[i] = 1; n       mark[i] = 1; n       for (int j : v[i]) visit[j] = 1; n     } n   } n   int cnt = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (mark[i]) { n       for (int j : rv[i]) n         if (mark[j]) mark[i] = 0; n       cnt += mark[i]; n     } n   } n   printf( %d n , cnt); n   for (int i = 0; i < n; i++) n     if (mark[i]) printf( %d  , i + 1); n } n


///====================== TEMPLATE STARTS HERE =====================/// n #include <bits/stdc++.h> n using namespace std; n  n #define endl   n  n #define pb push_back n #define MP make_pair n #define ff first n #define ss second n #define ABS(x) ((x)<0?-(x):(x)) n #define FABS(x) ((x)+eps<0?-(x):(x)) n #define LCM(x,y) (((x)/gcd((x),(y)))*(y)) n #define POPCOUNT __builtin_popcountll n #define Set(N,p) ((N)|((1LL)<<(p))) n #define Reset(N,p) ((N)&(~((1LL)<<(p)))) n #define Check(N,p) (!(((N)&((1LL)<<(p)))==(0))) n #define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL) n  n #define LL long long n #define LLU long long unsigned int n typedef pair < int, int > pii; n typedef pair < LL, LL > pll; n typedef vector<int> vi; n typedef vector<LL> vl; n typedef vector<pll> vll; n  n #ifdef s_da_sailor n     #define line                    cout <<   n=================== n  n     #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ ) n     template <typename Arg1> n     void __f(const char* name, Arg1&& arg1){ n         cerr << name <<   =   << arg1 <<   n ; n     } n     template <typename Arg1, typename... Args> n     void __f(const char* names, Arg1&& arg1, Args&&... args){ n         const char* comma = strchr(names + 1,  , ); n         cerr.write(names, comma - names) <<   =   << arg1 <<   ,  ; n     __f(comma + 1, args...); n     } n #else n     #define line n     #define trace(...) n #endif // s_da_sailor n  n inline LL gcd ( LL a, LL b ) { n     a = ABS ( a ); b = ABS ( b ); n     while ( b ) { a = a % b; swap ( a, b ); } return a; n } n  n LL ext_gcd ( LL A, LL B, LL *X, LL *Y ){ n     LL x2, y2, x1, y1, x, y, r2, r1, q, r; n     x2 = 1; y2 = 0; n     x1 = 0; y1 = 1; n     for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) { n         q = r2 / r1; n         r = r2 % r1; n         x = x2 - (q * x1); n         y = y2 - (q * y1); n     } n     *X = x2; *Y = y2; n     return r2; n } n  n inline LL modInv ( LL a, LL m ) { n     LL x, y; n     ext_gcd( a, m, &x, &y ); n     x %= m; n     if ( x < 0 ) x += m; n     return x; n } n  n inline LL bigmod ( LL a, LL p, LL m ) { n     LL res = 1 % m, x = a % m; n     while ( p ) { n         if ( p & 1 ) res = ( res * x ) % m; n         x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod n     } n     return res; n } n  n  n //int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} }; n //int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; n //int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}}; n const LL inf = 2147383647; n const LL mod = 1000000007; n const double pi = 2 * acos ( 0.0 ); n const double eps = 1e-11; n //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers n  n ///======================  TEMPLATE ENDS HERE  =====================/// n  n #define SIZE 100005 n  n int ks; n  n string S; n int n, A[SIZE]; n  n void solve() { n     cin >> S; n  n     n = S.size(); n     for(int i=0; i<n; i++) { n         A[i] = S[i] -  a ; n     } n  n     int curr = 30; n  n     for(int i=0; i<n; i++) { n         if(i>=1 && A[i-1]==A[i]) { n             A[i] = curr; n             curr++; n         } n         else if(i>=2 && A[i-2]==A[i]) { n             A[i] = curr; n             curr++; n         } n     } n  n     cout << curr-30 << endl; n } n  n int main () { n     #ifdef s_da_sailor n     freopen (  input.txt ,  r , stdin ); n     //freopen (  output.txt ,  w , stdout ); n     #endif // s_da_sailor n  n     fast_cin; n  n     int tc; n     cin >> tc; n  n     for(ks=1; ks<=tc; ks++) { n         solve(); n     } n  n     return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n char s[105], pos[105], p[105], cmp[105]; n int main() { n   int n = 0, k = 0; n   scanf( %d%d , &n, &k); n   scanf( %s , p); n   scanf( %s , pos); n   for (int i = 0; i < n; ++i) { n     s[i] =  * ; n   } n   int lenp = strlen(p); n   for (int i = 0; i < n - lenp + 1; ++i) { n     if (pos[i] ==  1 ) { n       for (int j = 0; j < lenp; ++j) { n         s[i + j] = p[j]; n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     bool isSame = true; n     for (int j = 0; j < lenp && i + j < n; ++j) { n       if (s[i + j] ==  * ) { n         s[i + j] = p[j] ==  a  ?  b  :  a ; n         isSame = false; n         break; n       } else if (s[i + j] != p[j]) { n         if (pos[i] ==  1 ) { n           printf( No solution ); n           return 0; n         } else { n           isSame = false; n           break; n         } n       } n     } n     if (isSame && pos[i] ==  0 ) { n       printf( No solution ); n       return 0; n     } n   } n   for (int i = 0; i < n; ++i) { n     printf( %c , s[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v); n template <typename A, typename B> n ostream &operator<<(ostream &cout, pair<A, B> const &p) { n   return cout <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v) { n   cout <<  [ ; n   for (int i = 0; i < v.size(); i++) { n     if (i) cout <<  ,  ; n     cout << v[i]; n   } n   return cout <<  ] ; n } n template <typename A, typename B> n istream &operator>>(istream &cin, pair<A, B> &p) { n   cin >> p.first; n   return cin >> p.second; n } n mt19937 rng(steady_clock::now().time_since_epoch().count()); n void usaco(string filename) { n   freopen((filename +  .in ).c_str(),  r , stdin); n   freopen((filename +  .out ).c_str(),  w , stdout); n } n const long double pi = 3.14159265358979323846; n const long long mod = 1000000007; n long long n, m, k, q, Q, T, l, r, x, y, z; n long long a[1000005]; n long long b[1000005]; n long double c[1000005]; n string second, t; n long long ans = 0; n double shoelace(double X[], double Y[], int n) { n   double area = 0.0; n   int j = n - 1; n   for (int i = 0; i < n; i++) { n     area += (X[j] + X[i]) * (Y[j] - Y[i]); n     j = i; n   } n   return abs(area / 2.0); n } n int main() { n   { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     cout.tie(NULL); n   }; n   for (int ele = 0; ele < 6; ele++) cin >> a[ele]; n   ; n   double X[6], Y[6]; n   double ang = 0; n   double x = 0, y = 0; n   for (long long i = 0; i < (6); i++) { n     X[i] = x; n     Y[i] = y; n     x += a[i] * cos(ang); n     y += a[i] * sin(ang); n     ang += pi / 3; n   } n   cout << (long long)(2 * shoelace(X, Y, 6) / 0.86602540378 + 0.5) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void lwr(string& s) { n   for (int i = 0; i < s.size(); i++) { n     if (s[i] >=  A  and s[i] <=  Z ) s[i] = s[i] -  A  +  a ; n   } n } n pair<int, int> _rank(const string& s) { n   int ret = 0; n   for (int i = 0; i < s.size(); i++) ret += s[i] ==  r ; n   return pair<int, int>(ret, (int)s.size()); n } n map<string, int> who; n const int N = 300010; n pair<int, int> val[N]; n vector<int> g[N], gt[N]; n int vis[N]; n int c[N]; n vector<int> ts; n void dfs(int u) { n   vis[u] = 1; n   for (int v : g[u]) n     if (!vis[v]) dfs(v); n   ts.push_back(u); n } n pair<int, int> valc[N]; n void dfst(int u, int cmp) { n   vis[u] = 2; n   c[u] = cmp; n   valc[cmp] = min(valc[cmp], val[u]); n   for (int v : gt[u]) n     if (vis[v] != 2) dfst(v, cmp); n } n vector<int> gc[N]; n pair<int, int> best[N]; n pair<int, int> solve(int u) { n   if (best[u].first != 0x3f3f3f3f) return best[u]; n   best[u] = valc[u]; n   for (int v : gc[u]) best[u] = min(best[u], solve(v)); n   return best[u]; n } n int main() { n   ios::sync_with_stdio(0); n   int m, cnt = 0; n   cin >> m; n   vector<int> vv; n   for (int i = 0; i < m; i++) { n     string s; n     cin >> s; n     lwr(s); n     if (!who.count(s)) { n       who[s] = cnt; n       val[cnt] = _rank(s); n       cnt++; n     } n     vv.push_back(who[s]); n   } n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string u, v; n     cin >> u >> v; n     lwr(u); n     lwr(v); n     if (!who.count(u)) { n       who[u] = cnt; n       val[cnt] = _rank(u); n       cnt++; n     } n     if (!who.count(v)) { n       who[v] = cnt; n       val[cnt] = _rank(v); n       cnt++; n     } n     int uu = who[u], vv = who[v]; n     g[uu].push_back(vv); n     gt[vv].push_back(uu); n   } n   for (int i = 0; i < cnt; i++) { n     if (!vis[i]) dfs(i); n   } n   int comp = 0; n   fill(valc, valc + N, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f)); n   for (int i = cnt - 1; i >= 0; i--) { n     if (vis[ts[i]] != 2) dfst(ts[i], comp++); n   } n   for (int u = 0; u < cnt; u++) { n     for (int v : g[u]) { n       if (c[u] != c[v]) gc[c[u]].push_back(c[v]); n     } n   } n   fill(best, best + N, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f)); n   pair<long long, long long> ans(0LL, 0LL); n   for (int i = 0; i < m; i++) { n     pair<int, int> ret = solve(c[vv[i]]); n     ans.first += ret.first; n     ans.second += ret.second; n   } n   cout << ans.first <<     << ans.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int n, m, p, r[605], c[605], f[605], g[605][605], a[605][605], b[605][605]; n void tuopu() { n   int h = 0, t = 0; n   for (int i = 1; i <= n; i++) n     if (!r[i]) f[++t] = i, g[i][t] = 1; n   m = t; n   while (h < t) { n     int x = f[++h]; n     for (int i = 1; i <= n; i++) n       if (b[x][i]) { n         r[i] -= b[x][i]; n         if (!r[i]) f[++t] = i; n         for (int j = 1; j <= m; j++) n           g[i][j] = (g[i][j] + (long long)g[x][j] * b[x][i]) % p; n       } n   } n   int now = 0; n   for (int j = 1; j <= n; j++) n     if (!c[j]) { n       ++now; n       for (int i = 1; i <= m; i++) a[i][now] = g[j][i]; n     } n } n void swap(int &x, int &y) { n   int tmp = x; n   x = y; n   y = tmp; n } n void work() { n   int flag = 1; n   for (int i = 1; i <= m; i++) { n     if (!a[i][i]) n       for (int j = i + 1; j <= m; j++) n         if (a[j][i]) { n           for (int k = i; k <= m; k++) swap(a[i][k], a[j][k]); n           flag = -flag; n           break; n         } n     for (int j = i + 1; j <= m; j++) n       while (a[j][i]) { n         long long z; n         if (a[i][i]) n           z = a[j][i] / a[i][i]; n         else n           z = 0; n         flag = -flag; n         for (int k = i; k <= m; k++) n           a[j][k] = (a[j][k] - z * a[i][k]) % p, swap(a[j][k], a[i][k]); n       } n   } n   long long ans = flag; n   for (int i = 1; i <= m; i++) ans = ans * a[i][i] % p; n   printf( %d n , (ans + p) % p); n } n int main() { n   scanf( %d%d%d , &n, &m, &p); n   int x, y; n   for (int i = 1; i <= m; i++) scanf( %d%d , &x, &y), b[x][y]++, c[x]++, r[y]++; n   tuopu(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n, a[100005]; n vector<int> v[100005]; n int val[100005]; n int k[100005]; n int main() { n   for (int i = 2; i <= 100000; i++) { n     v[i].push_back(1); n     for (int j = i + i; j <= 100000; j += i) { n       v[j].push_back(i); n     } n   } n   scanf( %d , &t); n   while (t--) { n     memset(k, 0, sizeof(k)); n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) { n       scanf( %d , &a[i]); n     } n     for (int i = n; i >= 1; i--) { n       if (k[i] == 0) k[i] = 1; n       int p = v[i].size(); n       for (int j = 0; j < p; j++) { n         if (a[i] > a[v[i][j]]) k[v[i][j]] = max(k[v[i][j]], k[i] + 1); n       } n     } n     int mx = 0; n     for (int i = 1; i <= n; i++) { n       mx = max(mx, k[i]); n     } n     printf( %d n , mx); n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[500005][9] = {0}; n int nnf[500005] = {0}; n int pn[200005] = {0}; n int val[200005]; n int x, in; n void print(int *a, int n) { n   int i; n   for (i = 0; i < n; i++) printf( %d  , a[i]); n   printf(  n ); n } n long long int check(int cnt, int val, int d) { n   if (in == -1) nnf[val] += in; n   long long int q = d * nnf[val], i; n   for (i = cnt + 1; i <= a[x][0]; i++) q += check(i, val * a[x][i], -d); n   if (in == 1) nnf[val] += in; n   return q; n } n int main() { n   a[1][0] = 1; n   a[1][1] = 1; n   int i, j; n   for (i = 1; i < 500001; i++) { n     if (a[i][0] == 1) { n       for (j = i; j < 500001; j += i) { n         a[j][0] += 1; n         a[j][a[j][0]] = i; n       } n     } n   } n   a[1][0] = 1; n   int n, q; n   long long int ans = 0; n   scanf( %d %d , &n, &q); n   for (i = 1; i <= n; i++) scanf( %d , &val[i]); n   for (i = 0; i < q; i++) { n     scanf( %d , &j); n     if (pn[j] == 1) n       in = -1; n     else n       in = 1; n     pn[j] = pn[j] ^ 1; n     x = val[j]; n     ans += check(1, 1, in); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K, L; n int pre[1000005]; n long long dp[1000005]; n int cnt[1000005]; n string s; n pair<int, int> chk(long long C) { n   fill(dp + 1, dp + 1 + N, 0); n   fill(cnt + 1, cnt + 1 + N, 0); n   for (int i = 1; i <= N; i++) { n     dp[i] = dp[i - 1]; n     cnt[i] = cnt[i - 1]; n     if (i >= L) { n       long long v = dp[i - L] + pre[i] - pre[i - L] - C; n       if ((dp[i] == v && cnt[i - L] + 1 < cnt[i]) || (dp[i] < v)) { n         dp[i] = v; n         cnt[i] = cnt[i - L] + 1; n       } n     } else { n       long long v = pre[i] - C; n       if ((dp[i] < v)) { n         dp[i] = v; n         cnt[i] = 1; n       } n     } n   } n   return {dp[N], cnt[N]}; n } n int solve(char lb, char ub) { n   for (int i = 1; i <= N; i++) { n     pre[i] = (s[i - 1] >= lb && s[i - 1] <= ub); n     pre[i] += pre[i - 1]; n   } n   long long l = 0, r = N + 1; n   int ret = 0; n   while (l <= r) { n     long long mid = (l + r) / 2; n     auto res = chk(mid); n     if (res.second <= K) { n       ret = mid; n       r = mid - 1; n     } else { n       l = mid + 1; n     } n   } n   return pre[N] - (chk(ret).first + 1LL * K * ret); n } n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin >> N >> K >> L >> s; n   int ret = min(solve( a ,  z ), solve( A ,  Z )); n   cout << ret << endl; n } n


#include <bits/stdc++.h> n const int N = 1010; n int n, k, a[N], a2[N], used[N], m, d, ans; n std::list<int> list; n int t; n void spendTimeUntil(int setSz) { n   while (list.size() > setSz) { n     d = round(100 * (double)m / (double)n); n     for (int x : list) { n       if (a2[x] + 1 == d && !used[x]) { n         used[x] = 1; n         ans++; n       } n     } n     for (auto it = list.begin(); it != list.end();) { n       if (++a2[*it] != a[*it]) n         it++; n       else { n         it = list.erase(it); n         m++; n       } n     } n   } n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n     if (list.size() < k) n       list.push_back(i); n     else { n       spendTimeUntil(k - 1); n       list.push_back(i); n     } n   } n   spendTimeUntil(0); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fun() {} n const long long int inf = 1e18; n const long long int md = 1e9 + 7; n const long long int N = 300050; n long long int __gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return __gcd(b, a % b); n } n long long int poww(long long int a, long long int b, long long int md) { n   if (b < 0) return 0; n   if (a == 0) return 0; n   long long int res = 1; n   while (b) { n     if (b & 1) { n       res = (1ll * res * a) % md; n     } n     a = (1ll * a * a) % md; n     b >>= 1; n   } n   return res; n } n long long int poww(long long int a, long long int b) { n   if (b < 0) return 0; n   if (a == 0) return 0; n   long long int res = 1; n   while (b) { n     if (b & 1) { n       res = (1ll * res * a); n     } n     a = (1ll * a * a); n     b >>= 1; n   } n   return res; n } n long long int divide(long long int a, long long int b, long long int md) { n   long long int rr = a * (poww(b, md - 2, md)); n   rr %= md; n   return rr; n } n long long int lcm(long long int a, long long int b) { n   return (a * b) / __gcd(a, b); n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int t; n   cin >> t; n   while (t--) { n     long long int l, r; n     cin >> l >> r; n     if (2 * l > r) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[27]; n bool vis[27]; n vector<pair<int, int> > pr; n int cnt, flag; n void dfs(int nod, int dest) { n   int i; n   vis[nod] = 1; n   if (nod == dest) { n     flag = 1; n     return; n   } n   for (i = 0; i < v[nod].size(); i++) { n     int curr = v[nod][i]; n     if (vis[curr] == 0) { n       dfs(curr, dest); n     } n   } n   return; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, i; n   cin >> n; n   string s1, s2; n   cin >> s1 >> s2; n   for (i = 0; i < n; i++) { n     flag = 0; n     memset(vis, 0, sizeof(vis)); n     int nod = s1[i] -  a  + 1; n     int dest = s2[i] -  a  + 1; n     dfs(nod, dest); n     if (flag == 0) { n       cnt++; n       pr.push_back(make_pair(nod, dest)); n       v[nod].push_back(dest); n       v[dest].push_back(nod); n     } n   } n   cout << cnt << endl; n   for (i = 0; i < pr.size(); i++) { n     char ch1 = pr[i].first +  a  - 1, ch2 = pr[i].second +  a  - 1; n     cout << ch1 <<     << ch2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   string s; n   vector<int> a; n   while (t--) { n     int x; n     cin >> x >> s; n     a.resize(x); n     int sz = s.size(); n     for (int i = 0; i < sz && i < x; ++i) { n       a[i] = s[i] -  0 ; n     } n     long long sol = s.size(); n     for (int i = 1; i <= x; ++i) { n       int r = sz; n       for (int j = 1; j < a[i - 1] && sz < x; ++j) { n         for (int k = i; k < r && sz < x; ++k) { n           a[sz] = a[k]; n           ++sz; n         } n       } n       sol = ((sol - i + MOD) % MOD * a[i - 1] + i) % MOD; n     } n     cout << sol <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int N = 1e6 + 7; n long long p[N]; n int main() { n   int a, b, c, d; n   scanf( %d , &a), scanf( %d , &b), scanf( %d , &c), scanf( %d , &d); n   for (int i = a; i < (int)b + 1; i++) { n     p[i + b] += 1; n     p[i + c + 1] -= 1; n   } n   for (int i = 1; i < (int)N; i++) p[i] += p[i - 1]; n   for (int i = 1; i < (int)N; i++) p[i] += p[i - 1]; n   long long val = 0; n   for (int i = c; i < (int)d + 1; i++) val += p[N - 1] - p[i]; n   printf( %lld n , val); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ,  unroll-loops ,  no-stack-protector ) n using namespace std; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long test = 1; n   while (test--) { n     long long x, y; n     cin >> x >> y; n     long long n; n     cin >> n; n     long long hash[7]; n     hash[0] = 0; n     hash[1] = x; n     hash[2] = y; n     hash[3] = (y - x + 1000000007) % 1000000007; n     hash[4] = (-1 * x + 1000000007) % 1000000007; n     hash[5] = (-1 * y + 1000000007) % 1000000007; n     hash[6] = (x - y + 1000000007) % 1000000007; n     long long rem = (n) % 6; n     if (rem == 0) rem = 6; n     long long ans = hash[rem]; n     cout << (ans + 1000000007) % 1000000007; n   } n   cerr << endl n        <<  Time:   << (clock() * 1000. / CLOCKS_PER_SEC) <<   ms  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long leftBinarySearch(long long* color, long long size, long long target) { n   int l = 0; n   int r = size - 1; n   int idx = -1; n   while (l <= r) { n     int m = l + (r - l) / 2; n     if (color[m] <= target) { n       l = m + 1; n       idx = m; n     } else { n       r = m - 1; n     } n   } n   return idx; n } n long long rightBinarySearch(long long* color, long long size, n                             long long target) { n   int l = 0; n   int r = size - 1; n   int idx = -1; n   while (l <= r) { n     int m = l + (r - l) / 2; n     if (color[m] >= target) { n       r = m - 1; n       idx = m; n     } else { n       l = m + 1; n     } n   } n   return idx; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long r, g, b; n     cin >> r >> g >> b; n     long long red[r], green[g], blue[b]; n     for (int i = 0; i < r; i++) cin >> red[i]; n     for (int i = 0; i < g; i++) cin >> green[i]; n     for (int i = 0; i < b; i++) cin >> blue[i]; n     sort(red, red + r); n     sort(green, green + g); n     sort(blue, blue + b); n     long long ans = LLONG_MAX; n     long long left, right; n     for (int i = 0; i < r; i++) { n       left = leftBinarySearch(green, g, red[i]); n       right = rightBinarySearch(blue, b, red[i]); n       if (left != -1 and right != -1) n         ans = n             min(ans, (green[left] - blue[right]) * (green[left] - blue[right]) + n                          (red[i] - green[left]) * (red[i] - green[left]) + n                          (red[i] - blue[right]) * (red[i] - blue[right])); n       left = leftBinarySearch(blue, b, red[i]); n       right = rightBinarySearch(green, g, red[i]); n       if (left != -1 and right != -1) n         ans = n             min(ans, (blue[left] - green[right]) * (blue[left] - green[right]) + n                          (red[i] - blue[left]) * (red[i] - blue[left]) + n                          (red[i] - green[right]) * (red[i] - green[right])); n     } n     for (int i = 0; i < g; i++) { n       left = leftBinarySearch(red, r, green[i]); n       right = rightBinarySearch(blue, b, green[i]); n       if (left != -1 and right != -1) n         ans = min(ans, (red[left] - blue[right]) * (red[left] - blue[right]) + n                            (green[i] - red[left]) * (green[i] - red[left]) + n                            (green[i] - blue[right]) * (green[i] - blue[right])); n       left = leftBinarySearch(blue, b, green[i]); n       right = rightBinarySearch(red, r, green[i]); n       if (left != -1 and right != -1) n         ans = min(ans, (blue[left] - red[right]) * (blue[left] - red[right]) + n                            (green[i] - blue[left]) * (green[i] - blue[left]) + n                            (green[i] - red[right]) * (green[i] - red[right])); n     } n     for (int i = 0; i < b; i++) { n       left = leftBinarySearch(red, r, blue[i]); n       right = rightBinarySearch(green, g, blue[i]); n       if (left != -1 and right != -1) n         ans = min(ans, (red[left] - green[right]) * (red[left] - green[right]) + n                            (blue[i] - red[left]) * (blue[i] - red[left]) + n                            (blue[i] - green[right]) * (blue[i] - green[right])); n       left = leftBinarySearch(green, g, blue[i]); n       right = rightBinarySearch(red, r, blue[i]); n       if (left != -1 and right != -1) n         ans = min(ans, (green[left] - red[right]) * (green[left] - red[right]) + n                            (blue[i] - green[left]) * (blue[i] - green[left]) + n                            (blue[i] - red[right]) * (blue[i] - red[right])); n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, k, i, tt = 1, a, b; n   cin >> n >> k; n   vector<pair<int, int> > p; n   for (i = 0; i < n; i++) { n     cin >> a >> b; n     p.push_back(make_pair(-a, b)); n   } n   sort(p.begin(), p.end()); n   for (i = k - 1; i < n - 1; i++) { n     if (p[i].first == p[i + 1].first && p[i].second == p[i + 1].second) n       tt += 1; n     else n       break; n   } n   for (i = k - 1; i > 0; i--) { n     if (p[i].first == p[i - 1].first && p[i].second == p[i - 1].second) n       tt += 1; n     else n       break; n   } n   cout << tt; n } n


#include <bits/stdc++.h> n using namespace std; n  n const int N = (int) 1e7 + 100; n  n long long s[N]; n int d[N]; n int ans[N]; n  n int main() { n   fill(d, d + N, -1); n   d[1] = 1; n   for (int i = 2; i * i < N; i++) { n     if (d[i] == -1) { n       d[i] = i; n       for (int j = i * i; j < N; j += i) { n         if (d[j] == -1) { n           d[j] = i; n         } n       } n     } n   } n   s[1] = 1; n   for (int i = 2; i < N; i++) { n     if (d[i] == -1) { n       d[i] = i; n       s[i] = i + 1; n     } else { n       int j = i; n       s[i] = 1; n       while (j % d[i] == 0) { n         j /= d[i]; n         s[i] = s[i] * d[i] + 1; n       } n       s[i] *= s[j]; n     } n   } n   fill(ans, ans + N, -1); n   for (int i = N - 1; i > 0; i--) { n     if(s[i]<N){  // avoiding overflow. n     ans[s[i]] = i;   n  } n        n      n   } n   int tests; n   cin >> tests; n   while (tests-- > 0) { n     int c; n     cin >> c; n     cout << ans[c] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 2e5 + 5; n vector<vector<int> > adj(N); n long long a[N]; n pair<pair<long long, long long>, long long> dfs(int u, int prt = 0) { n   if (adj[u].empty()) return {{1, a[u]}, a[u]}; n   pair<pair<long long, long long>, long long> ret = {{0, 0}, 0}; n   for (int v : adj[u]) { n     if (v == prt) continue; n     auto ch = dfs(v, u); n     ret.first.first += ch.first.first, ret.first.second += ch.first.second; n     ret.second = max(ret.second, ch.second); n   } n   long long k = ret.second * ret.first.first - ret.first.second; n   long long rem = a[u] - min(a[u], k); n   ret.second += rem / ret.first.first + (rem % ret.first.first != 0); n   ret.first.second += a[u]; n   return ret; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   for (int i = 2; i <= n; i++) { n     int p; n     cin >> p; n     adj[p].push_back(i); n   } n   for (int i = 1; i <= n; i++) cin >> a[i]; n   cout << dfs(1).second << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int n; n char cmd[1000001]; n bool sym(int p) { n   int rm = 0, cur = 0; n   for (int i = 0; i < n - 1; ++i) { n     if (cur > p + 1 && cmd[i] ==  L ) n       cur--; n     else if (cmd[i] ==  R ) n       rm = max(rm, ++cur); n   } n   return cur + 1 > rm; n } n int main() { n   scanf( %s , cmd); n   n = strlen(cmd); n   if (cmd[n - 1] ==  L ) n     for (int i = 0; i < n; ++i) cmd[i] = cmd[i] ==  R  ?  L  :  R ; n   if (sym(-mod)) n     puts( 1 ); n   else { n     int a = -mod, b = 0; n     while (b - a > 1) { n       int m = (a + b) >> 1; n       if (sym(m)) n         b = m; n       else n         a = m; n     } n     printf( %d n , -b); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     vector<long long int> a(n); n     for (int i = 0; i < n; i++) cin >> a[i]; n     vector<long long int> pks; n     for (int i = 1; i < n - 1; i++) { n       if (a[i] > a[i - 1] && a[i] > a[i + 1]) pks.push_back(i); n     } n     long long int maxi = 0, l = 0; n     for (long long int i = 0; i <= n - k; i++) { n       long long int tmp1 = upper_bound(pks.begin(), pks.end(), i) - pks.begin(); n       long long int tmp2 = n           lower_bound(pks.begin(), pks.end(), i + k - 1LL) - pks.begin(); n       long long int cnt = tmp2 - tmp1; n       if (cnt > maxi) { n         maxi = cnt; n         l = i; n       } n     } n     cout << maxi + 1 <<     << l + 1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, x; n   scanf( %d %d %d , &a, &b, &x); n   if (a != 0 && a >= b) { n     a = a - (a / b) * b; n   } n   a *= 10; n   int cont = 0; n   vector<int> v; n   while (cont <= b && a != 0) { n     if (a < b) { n       v.push_back(0); n     } else { n       v.push_back(a / b); n       a = a - (a / b) * b; n     } n     a *= 10; n     cont++; n   } n   if (a == 0) v.push_back(0); n   if (find(v.begin(), v.end(), x) != v.end()) { n     printf( %d n , (find(v.begin(), v.end(), x) - v.begin()) + 1); n   } else n     puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n int ans; n void solve(long long n, long long l1, long long r1, long long l, long long r) { n   if (n == 0 || l1 > r || r1 < l) return; n   long long mid = (l1 + r1) >> 1; n   if (mid >= l && mid <= r) ans += (n % 2); n   solve(n / 2, l1, mid - 1, l, r); n   solve(n / 2, mid + 1, r1, l, r); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, l, r; n   cin >> n, cin >> l, cin >> r; n   long long tmp = n, var = 0; n   while (tmp > 0) { n     tmp /= 2; n     var++; n   } n   long long num = (1LL << var) - 1; n   solve(n, 1, num, l, r); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   cout << (n % 4 == 0 ?  YES  :  NO ) <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[300000]; n int main() { n   long long n, m; n   scanf( %lld %lld , &n, &m); n   for (long long i = 1; i <= n; i++) { n     scanf( %lld , &arr[i]); n   } n   string s; n   cin >> s; n   long long len = s.size(); n   long long ans = 0; n   for (long long i = 0; i < len; i++) { n     char c = s[i]; n     priority_queue<long long> q; n     long long j = i; n     while (s[j] == c && j < len) { n       q.push(arr[j + 1]); n       i = j; n       j++; n     } n     long long temp = m; n     while (temp > 0 && !q.empty()) { n       long long keep = q.top(); n       ans += keep; n       q.pop(); n       temp--; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod(long long int x) { n   return (((x) % 1000000007) + 1000000007) % 1000000007; n } n long long int mod1(long long int x, long long int m) { n   return (((x) % m) + m) % m; n } n long long int solve() { n   long long int n, k; n   cin >> n >> k; n   long long int s[n + 1]; n   for (long long int i = 1; i < n + 1; i++) { n     long long int p; n     cin >> p; n     if (p == 0) n       s[i] = (k < i - 1 ? k : i - 1) + 1; n     else n       s[i] = s[p] + (2 * k < i - p - 1 ? 2 * k : i - p - 1) + 1; n     cout << s[i] + (k < n - i ? k : n - i) <<   n ; n   } n   return 0; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, len; n char str[55][25]; n long long f[(1 << 20) + 10], bin[55]; n double ans[(1 << 20) + 10]; n double res; n int main() { n   int i, j, k, c; n   bin[0] = 1; n   for (i = 1; i < 55; i++) bin[i] = (bin[i - 1] << 1); n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %s , str[i]); n   len = strlen(str[1]); n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       if (i != j) { n         int same = 0; n         for (k = 0; k < len; k++) { n           if (str[i][k] == str[j][k]) same |= bin[k]; n         } n         f[same] |= bin[j]; n       } n     } n   } n   for (i = bin[len] - 1; i >= 0; i--) { n     for (j = 0; j < len; j++) { n       if (i & bin[j]) { n         f[i ^ bin[j]] |= f[i]; n       } n     } n   } n   ans[0] = 1; n   for (i = 0; i < bin[len]; i++) { n     for (c = j = 0; j < len; j++) { n       if (i & bin[j]) c++; n     } n     for (j = 0; j < len; j++) { n       if (!(i & bin[j])) ans[i | bin[j]] += ans[i] / (len - c); n     } n     for (j = 0; j < n; j++) { n       if (f[i] & bin[j]) res += ans[i]; n     } n   } n   printf( %.10f n , res / n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long long int n, k; n   cin >> n >> k; n   int a[n + 1]; n   for (int i = (1); i <= (n); i++) cin >> a[i]; n   long long int d = 1 + 8 * k; n   long long int x = (long long int)floor(((sqrt(d) - 1) / 2)); n   if (n == 1) n     cout << a[1] << endl; n   else { n     if ((x * (x + 1)) / 2 == k) n       cout << a[x] << endl; n     else n       cout << a[k - (x * (x + 1)) / 2] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check_prime(long long n) { n   long long flag = 0; n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       flag = 1; n       break; n     } n   } n   if (n == 1) n     return false; n   else if (flag == 0 || n == 2 || n == 3) { n     return true; n   } else { n     return false; n   } n } n long long BE(long long x, long long n, long long m) { n   long long result = 1; n   while (n > 0) { n     if (n % 2 == 1) result = result * x % m; n     x = x * x % m; n     n = n / 2; n   } n   return result; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   long long n; n   cin >> n; n   long long x[n], h[n]; n   long long cnt = 2; n   for (long long i = 0; i < n; i++) { n     cin >> x[i] >> h[i]; n   } n   for (long long i = 1; i < n - 1; i++) { n     if (x[i] - x[i - 1] - 1 >= h[i]) { n       cnt++; n     } else if (x[i] + h[i] < x[i + 1]) { n       cnt++; n       x[i] += h[i]; n     } n   } n   if (n == 1) { n     cout << 1 <<   n ; n   } else n     cout << cnt <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   int val; n   int col; n   vector<int> vec; n } arr[100005]; n void connect(int a, int b) { n   arr[a].vec.push_back(b); n   arr[b].vec.push_back(a); n } n int goal[100005]; n vector<int> ans; n void dfs(int n, int fl, int flip, int flip1) { n   arr[n].col = 1; n   if (fl % 2 == 0) { n     if (flip % 2 == 0) { n       if (arr[n].val != goal[n]) { n         if (arr[n].val == 0) n           arr[n].val = 1; n         else n           arr[n].val = 0; n         ans.push_back(n); n         flip++; n       } else { n       } n     } else { n       if (arr[n].val == 0) n         arr[n].val = 1; n       else n         arr[n].val = 0; n       if (arr[n].val != goal[n]) { n         if (arr[n].val == 0) n           arr[n].val = 1; n         else n           arr[n].val = 0; n         ans.push_back(n); n         flip++; n       } n     } n   } else { n     if (flip1 % 2 == 0) { n       if (arr[n].val != goal[n]) { n         if (arr[n].val == 0) n           arr[n].val = 1; n         else n           arr[n].val = 0; n         ans.push_back(n); n         flip1++; n       } n     } else { n       if (arr[n].val == 0) n         arr[n].val = 1; n       else n         arr[n].val = 0; n       if (arr[n].val != goal[n]) { n         if (arr[n].val == 0) n           arr[n].val = 1; n         else n           arr[n].val = 0; n         ans.push_back(n); n         flip1++; n       } n     } n   } n   fl++; n   for (int i = 0; i < arr[n].vec.size(); i++) { n     if (arr[arr[n].vec[i]].col == 0) dfs(arr[n].vec[i], fl, flip, flip1); n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int aa, bb; n     cin >> aa >> bb; n     connect(aa, bb); n   } n   for (int i = 1; i <= n; i++) { n     int v; n     cin >> v; n     arr[i].val = v; n     arr[i].col = 0; n   } n   for (int i = 1; i <= n; i++) { n     cin >> goal[i]; n   } n   dfs(1, 0, 0, 0); n   int si = ans.size(); n   cout << si << endl; n   for (int i = 0; i < si; i++) { n     cout << ans[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double p, d, t, f, c; n   scanf( %lf %lf %lf %lf %lf , &p, &d, &t, &f, &c); n   if (p >= d) return puts( 0 ), 0; n   double now = t * p, bizo = 0; n   while (now <= c) { n     double step = now / (d - p); n     if (now + p * step >= c) break; n     bizo++; n     now = now + (p * step) * 2; n     now += p * f; n     if (now >= c) break; n   } n   printf( %.0f n , bizo); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool arr[1000][1000]; n void change(int n) { n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       arr[i][j] = !arr[i][j]; n     } n   } n } n int main() { n   int n, x, y; n   int orig_x; n   cin >> n >> x >> y; n   orig_x = x; n   if (x == 1 && y == 1) { n     if (n == 2 || n == 3) { n       cout <<  NO  << endl; n       return 0; n     } n     cout <<  YES  << endl; n     for (int i = 0; i < n; i++) { n       arr[i][(i + 1) % n] = arr[(i + 1) % n][i] = 1; n     } n     arr[n - 1][0] = arr[0][n - 1] = 0; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         cout << arr[i][j]; n       } n       cout << endl; n     } n     return 0; n   } n   if (x == 1 || y == 1) { n     if (x + y > n + 1) { n       cout <<  NO  << endl; n       return 0; n     } n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n     return 0; n   } n   if (x == 1 && y == 1) { n     for (int i = 0; i < n; i++) { n       arr[i][(i + 1) % n] = 1; n       arr[(i + 1) % n][i] = 1; n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         cout << arr[i][j]; n       } n       cout << endl; n     } n     return 0; n   } n   int temp1 = min(x, y); n   int temp2 = max(x, y); n   x = temp1; n   y = temp2; n   int cycL = n - y + 1; n   for (int i = 0; i < cycL; i++) { n     arr[i][(i + 1) % cycL] = 1; n     arr[(i + 1) % cycL][i] = 1; n   } n   if (orig_x == 1) change(n); n   for (int i = 0; i < n; i++) { n     arr[i][i] = 0; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cout << arr[i][j]; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005], b[100005]; n long long int n, m, k; n long long int judge(long long int x) { n   long long int sum = 0; n   for (int t = 0; t < x; t++) { n     if (a[n - x + t] < b[t]) { n       sum = sum + b[t] - a[n - x + t]; n     } n   } n   return sum; n } n int main() { n   cin >> n >> m >> k; n   for (int t = 0; t < n; t++) { n     scanf( %d , &a[t]); n   } n   sort(a, a + n); n   for (int t = 0; t < m; t++) { n     scanf( %d , &b[t]); n   } n   sort(b, b + m); n   long long int s1 = 0; n   long long int left = 0; n   long long int right = min(n, m); n   while (left <= right) { n     long long int mid = (left + right) >> 1; n     if (judge(mid) <= k) { n       left = mid + 1; n       s1 = mid; n     } else n       right = mid - 1; n   } n   long long int ans = 0; n   for (int t = 0; t < s1; t++) { n     ans += b[t]; n   } n   if (ans - k > 0) n     ans = ans - k; n   else n     ans = 0; n   printf( %lld %lld n , s1, ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n vector<int> G[N]; n vector<pair<int, pair<int, int> > > query; n int color[N], Ecolor[2 * N], f[N], s[2 * N], start[N], finish[N], ans[N]; n int n, m, u, v, cnt; n int block_size; n void dfs(int u) { n   start[u] = ++cnt; n   Ecolor[cnt] = color[u]; n   for (int i = 0; i < G[u].size(); ++i) { n     int v = G[u][i]; n     if (!start[v]) dfs(v); n   } n   finish[u] = ++cnt; n   Ecolor[cnt] = color[u]; n } n bool mo_cmp(pair<int, pair<int, int> > p, pair<int, pair<int, int> > q) { n   u = p.second.first, v = q.second.first; n   if (start[u] / block_size == start[v] / block_size) n     return finish[u] < finish[v]; n   return start[u] / block_size < start[v] / block_size; n } n void add(int pos) { n   f[Ecolor[pos]]++; n   s[f[Ecolor[pos]]]++; n } n void rem(int pos) { n   s[f[Ecolor[pos]]]--; n   f[Ecolor[pos]]--; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m; n   block_size = sqrt(n); n   for (int i = 1; i <= n; ++i) cin >> color[i]; n   for (int i = 1; i < n; ++i) { n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   dfs(1); n   for (int i = 0; i < m; ++i) { n     cin >> u >> v; n     query.push_back(pair<int, pair<int, int> >(i, pair<int, int>(u, v))); n   } n   sort(query.begin(), query.end(), mo_cmp); n   int curL = 1, curR = 1; n   add(1); n   for (int i = 0; i < query.size(); ++i) { n     int p = query[i].second.first; n     while (curL < start[p]) { n       rem(curL); n       curL++; n     } n     while (curL > start[p]) { n       curL--; n       add(curL); n     } n     while (curR < finish[p]) { n       curR++; n       add(curR); n     } n     while (curR > finish[p]) { n       rem(curR); n       curR--; n     } n     ans[query[i].first] = s[query[i].second.second * 2]; n   } n   for (int i = 0; i < m; ++i) cout << ans[i] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int test; n   cin >> test; n   for (int i = 0; i < test; i++) { n     int n, k; n     cin >> n >> k; n     if ((n % 2 != 0 && k % 2 == 0) || k > n) n       cout <<  NO  << endl; n     else { n       if (n % 2 == 0) { n         if (k % 2 != 0) { n           if (k * 2 > n) n             cout <<  NO  << endl; n           else { n             cout <<  YES  << endl; n             for (int j = 0; j < k - 1; j++) n               cout <<  2  n                    <<    ; n             cout << n - (2 * (k - 1)) << endl; n           } n         } else { n           cout <<  YES  << endl; n           for (int j = 0; j < k - 1; j++) n             cout <<  1  n                  <<    ; n           cout << n - (k - 1) << endl; n         } n       } else { n         cout <<  YES  << endl; n         for (int j = 0; j < k - 1; j++) n           cout <<  1  n                <<    ; n         cout << n - (k - 1) << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t; n   cin >> n >> t; n   if (t <= 203) { n     int dp[n * t + 1][301]; n     memset(dp, 0, sizeof(dp)); n     int ar[n * t]; n     int N = n * t; n     for (int ctr1 = 0; ctr1 < N; ctr1++) { n       if (ctr1 < n) n         cin >> ar[ctr1]; n       else n         ar[ctr1] = ar[ctr1 - n]; n     } n     for (int ctr1 = 1; ctr1 <= N; ctr1++) { n       for (int ctr2 = 0; ctr2 <= ar[ctr1 - 1]; ctr2++) { n         dp[ctr1][ar[ctr1 - 1]] = n             max(dp[ctr1][ar[ctr1 - 1]], 1 + dp[ctr1 - 1][ctr2]); n       } n       for (int ctr2 = 0; ctr2 <= 300; ctr2++) n         dp[ctr1][ctr2] = max(dp[ctr1][ctr2], dp[ctr1 - 1][ctr2]); n     } n     int r = 0; n     for (int ctr1 = 0; ctr1 <= 300; ctr1++) r = max(r, dp[N][ctr1]); n     cout << r << endl; n     return 0; n   } else { n     int dp[n * 101 + 1][301]; n     memset(dp, 0, sizeof(dp)); n     int ar[n * 101]; n     int N = n * 101; n     int poj[301]; n     memset(poj, 0, sizeof(poj)); n     for (int ctr1 = 0; ctr1 < N; ctr1++) { n       if (ctr1 < n) { n         cin >> ar[ctr1]; n         poj[ar[ctr1]]++; n       } else n         ar[ctr1] = ar[ctr1 - n]; n     } n     for (int ctr1 = 1; ctr1 <= N; ctr1++) { n       for (int ctr2 = 0; ctr2 <= ar[ctr1 - 1]; ctr2++) { n         dp[ctr1][ar[ctr1 - 1]] = n             max(dp[ctr1][ar[ctr1 - 1]], 1 + dp[ctr1 - 1][ctr2]); n       } n       for (int ctr2 = 0; ctr2 <= 300; ctr2++) n         dp[ctr1][ctr2] = max(dp[ctr1][ctr2], dp[ctr1 - 1][ctr2]); n     } n     int dp2[n * 101 + 1][301]; n     memset(dp2, 0, sizeof(dp2)); n     for (int ctr1 = N - 1; ctr1 >= 0; ctr1--) { n       for (int ctr2 = 300; ctr2 >= ar[ctr1]; ctr2--) { n         dp2[ctr1][ar[ctr1]] = max(dp2[ctr1][ar[ctr1]], 1 + dp2[ctr1 + 1][ctr2]); n       } n       for (int ctr2 = 1; ctr2 <= 300; ctr2++) n         dp2[ctr1][ctr2] = max(dp2[ctr1][ctr2], dp2[ctr1 + 1][ctr2]); n     } n     int r = 0; n     int nt = t - 202; n     for (int ctr1 = 1; ctr1 <= 300; ctr1++) n       r = max(r, dp[N][ctr1] + dp2[0][ctr1] + nt * poj[ctr1]); n     cout << r << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans = 0; n string s; n void go(vector<char> k, pair<int, int> start, vector<string> a) { n   for (int i = 0; i < s.size(); i++) { n     if (s[i] == k[0]) { n       start.first--; n     } n     if (s[i] == k[1]) { n       start.first++; n     } n     if (s[i] == k[2]) { n       start.second--; n     } n     if (s[i] == k[3]) { n       start.second++; n     } n     if (start.first >= n || start.first < 0) { n       return; n     } n     if (start.second >= m || start.second < 0) { n       return; n     } n     if (a[start.first][start.second] ==  # ) { n       return; n     } n     if (a[start.first][start.second] ==  E ) { n       ans++; n       return; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   pair<int, int> start; n   vector<string> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  S ) { n         start.first = i; n         start.second = j; n       } n     } n   } n   cin >> s; n   vector<char> k = { 0 ,  1 ,  2 ,  3 }; n   do { n     go(k, start, a); n   } while (next_permutation(k.begin(), k.end())); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1 << 17; n pair<int, int> v[MAXN]; n set<pair<int, int> > ans; n queue<int> Q; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> v[i].first >> v[i].second; n     if (v[i].first == 1) Q.push(i); n   } n   while (!Q.empty()) { n     int k = Q.front(); n     Q.pop(); n     if (v[k].first == 0) continue; n     int id = v[k].second; n     v[id].first--, v[id].second ^= k; n     ans.insert(make_pair(k, id)); n     if (v[id].first == 1) Q.push(id); n   } n   cout << ans.size() << endl; n   for (auto it = ans.begin(); it != ans.end(); it++) { n     pair<int, int> a = *it; n     cout << a.first <<     << a.second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <class T> n void print(vector<T>& v, bool spaced = true) { n   int n = v.size(); n   string space = (spaced ?     :   ); n   for (int i = 0; i < n; ++i) { n     cout << v[i] << space; n   } n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n; n   cin >> n; n   string s, t; n   cin >> s >> t; n   map<char, int> m1; n   map<char, int> m2; n   for (int i = 0; i < n; ++i) { n     m1[s[i]]++; n     m2[t[i]]++; n   } n   for (int i = 0; i < n; ++i) { n     if (find((t).begin(), (t).end(), s[i]) == t.end()) { n       cout << -1 <<   n ; n       return 0; n     } n   } n   for (int i = 0; i < n; ++i) { n     if (m1[s[i]] != m2[s[i]]) { n       cout << -1 <<   n ; n       return 0; n     } n   } n   vector<int> moves; n   for (int i = 0; i < n; ++i) { n     for (int j = i; j < n; ++j) { n       if (t[i] == s[j]) { n         for (int k = j - 1; k > i - 1; --k) { n           swap(s[k], s[k + 1]); n           moves.push_back(k + 1); n         } n         break; n       } n     } n   } n   cout << moves.size() <<   n ; n   print(moves); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:66777216 ) n using namespace std; n map<char, int> mp; n vector<pair<string, int>> lex; n vector<string> lvl[1000001]; n int lex_p = -1; n int max_l = 0; n void rec(int l, int cnt) { n   if (l > max_l) max_l = l; n   lvl[l].push_back(lex[lex_p].first); n   for (int i = 0; i < cnt; i++) { n     lex_p++; n     rec(l + 1, lex[lex_p].second); n   } n } n int main() { n   string s; n   cin >> s; n   int lex_cnt = 0; n   string cur_lex =   ; n   string str =   ; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  ,  || i == s.length() - 1) { n       lex_cnt++; n       if (lex_cnt % 2 == 0) { n         int val = 0; n         int mn = 1; n         for (int j = cur_lex.length() - 1; j >= 0; j--) { n           val += (cur_lex[j] -  0 ) * mn; n           mn *= 10; n         } n         lex.push_back(make_pair(str, val)); n         str =   ; n         cur_lex =   ; n       } else { n         str = cur_lex; n         cur_lex =   ; n       } n     } else n       cur_lex += s[i]; n   } n   while (lex_p < int(lex.size()) - 1) { n     lex_p++; n     rec(0, lex[lex_p].second); n   } n   cout << max_l + 1 << endl; n   for (int i = 0; i < 1000001; i++) { n     for (int j = 0; j < lvl[i].size(); j++) cout << lvl[i][j] <<    ; n     if (lvl[i].size() > 0) cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n const int mx = 999999; n int n, k, q; n long long f[6], dp[N]; n int main() { n   scanf( %d , &k); n   for (int i = 0; i < 6; ++i) scanf( %d , &f[i]); n   for (int i = 1; i <= mx; ++i) { n     int tmp = i, ct = 0; n     while (tmp) { n       int x = tmp % 10; n       if (x % 3 == 0) dp[i] += f[ct] * (x / 3); n       ct++; n       tmp /= 10; n     } n   } n   for (int i = 0, x = 3; i < 6; ++i, x = x * 10) { n     int tmp = min(3 * (k - 1), mx / x); n     for (int j = 1; j <= tmp; tmp -= j, j <<= 1) n       for (int w = mx; w >= j * x; --w) n         dp[w] = max(dp[w], dp[w - j * x] + j * f[i]); n     if (tmp) { n       for (int w = mx; w >= tmp * x; --w) n         dp[w] = max(dp[w], dp[w - tmp * x] + tmp * f[i]); n     } n   } n   scanf( %d , &q); n   while (q--) { n     int x; n     scanf( %d , &x); n     printf( %lld n , dp[x]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i, n, lns, t = 0, pos = -1, posl = 0; n   string s, ot; n   cin >> s; n   lns = s.length(); n   ot.clear(); n   for (i = 0; i < lns; ++i) { n     if (s[i] ==  a ) n       t++; n     else n       posl++; n   } n   if (t == lns) { n     cout << s; n     return 0; n   } n   if (posl & 1) { n     cout <<  :( ; n     return 0; n   } n   t = 0; n   for (i = 0; i < lns; ++i) { n     if (s[i] !=  a ) t++; n     if (t * 2 > posl) { n       pos = i; n       break; n     } n   } n   for (i = pos; i < lns; ++i) { n     if (s[i] ==  a ) { n       cout <<  :( ; n       return 0; n     } n   } n   i = 0; n   t = pos; n   while (i < pos) { n     if (s[i] ==  a ) n       i++; n     else if (s[i] != s[t]) { n       cout <<  :( ; n       return 0; n     } else n       i++, t++; n   } n   for (i = 0; i < pos; ++i) { n     cout << s[i]; n   } n   cout << ot; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct camel { n   int pos; n   int tof; n }; n int main() { n   cout << setprecision(8) << fixed; n   double l, d, v, g, r; n   cin >> l >> d >> v >> g >> r; n   double temp; n   double T; n   temp = d / v; n   double q; n   bool yer = 1; n   while (temp >= 0) { n     if (yer) { n       temp -= g; n       T = 0; n       yer = !yer; n     } else { n       T = r - temp; n       temp -= r; n       yer = !yer; n     } n   } n   cout << ((l / v) + T); n } n


#include <bits/stdc++.h> n using namespace std; n const long long o = 1e4 + 1; n long long n, m, q, a[o], b[o]; n long long qwq(long long x) { n   long long s = 0; n   for (long long i = 1; i <= n; i++) { n     if (1.0 * x * a[i] > b[i] * (m + 100)) return m + 1000; n     s += 1 + x * a[i] / b[i]; n   } n   return s; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   bool q = 1; n   long long x, y; n   for (long long i = 1; i <= n; i++) cin >> a[i] >> b[i], q &= !a[i]; n   if (q) return cout << (n == m ? -1 : 0), 0; n   long long l = 1, r = 1e18; n   while (l < r) { n     long long mid = (l + r + 1) >> 1; n     if (qwq(mid) > m) n       r = mid - 1; n     else n       l = mid; n   } n   if (qwq(l) != m) return cout << 0, 0; n   x = l, l = 1, r = 1e18; n   while (l < r) { n     long long mid = (l + r) >> 1; n     if (qwq(mid) < m) n       l = mid + 1; n     else n       r = mid; n   } n   y = l; n   cout << max(0ll, x - y + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   pair<int, int> a[n], b[m]; n   for (int i = 0; i < n; i++) { n     cin >> a[i].first >> a[i].second; n   } n   for (int i = 0; i < m; i++) { n     cin >> b[i].first >> b[i].second; n   } n   set<int> s; n   for (int i = 0; i < n; i++) { n     int f = 0; n     for (int j = 0; j < m; j++) { n       if (((a[i].first == b[j].first) || (a[i].first == b[j].second)) && n           ((a[i].second == b[j].first) || (a[i].second == b[j].second))) { n         continue; n       } else if ((a[i].first == b[j].first) || (a[i].first == b[j].second)) { n         f = 1; n       } n     } n     int tr = 1; n     if (f) { n       s.insert(a[i].first); n       tr = 0; n     } n     for (int j = 0; j < m; j++) { n       if (((a[i].first == b[j].first) || (a[i].first == b[j].second)) && n           ((a[i].second == b[j].first) || (a[i].second == b[j].second))) { n         continue; n       } else if ((a[i].second == b[j].first) || (a[i].second == b[j].second)) { n         f += 1; n         break; n       } n     } n     if (f > 1) { n       cout <<  -1 n ; n       exit(0); n     } n     if (f && tr) { n       s.insert(a[i].second); n     } n   } n   for (int j = 0; j < m; j++) { n     int f = 0; n     int tr = 1; n     for (int i = 0; i < n; i++) { n       if (((a[i].first == b[j].first) || (a[i].first == b[j].second)) && n           ((a[i].second == b[j].first) || (a[i].second == b[j].second))) { n         continue; n       } else if ((b[j].first == a[i].first) || (b[j].first == a[i].second)) { n         f = 1; n       } n     } n     if (f) { n       s.insert(b[j].first); n       tr = 0; n     } n     for (int i = 0; i < n; i++) { n       if (((a[i].first == b[j].first) || (a[i].first == b[j].second)) && n           ((a[i].second == b[j].first) || (a[i].second == b[j].second))) { n         continue; n       } else if ((b[j].second == a[i].first) || (b[j].second == a[i].second)) { n         f += 1; n         break; n       } n     } n     if (f > 1) { n       cout <<  -1 n ; n       exit(0); n     } n     if (f && tr) { n       s.insert(b[j].second); n     } n   } n   if (s.size() == 1) { n     auto it = s.begin(); n     cout << (*it); n   } else { n     cout <<  0 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n int main() { n   solve(); n   return 0; n } n void solve() { n   long long int n, x, y; n   cin >> n >> x >> y; n   if (n > y) { n     cout << -1; n     return; n   } n   if ((y - n + 1) * (y - n + 1) + n - 1 >= x) { n     for (int i = 1; i < n; ++i) { n       cout << 1 <<    ; n     } n     cout << y - n + 1; n   } else n     cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 210; n int n, m, ans[maxn]; n string s[maxn]; n int solve(string s) { n   for (int i = 10; i >= 0; i--) { n     bool flag = 0; n     for (int j = 0; j < (1 << i); j++) { n       string t; n       for (int k = 0; k < i; k++) n         if (j & (1 << k)) n           t +=  1 ; n         else n           t +=  0 ; n       if (s.find(t) == s.npos) { n         flag = 1; n         break; n       } n     } n     if (!flag) return i; n   } n   return 0; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) cin >> s[i]; n   scanf( %d , &m); n   for (int i = n + 1; i <= n + m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     s[i] = s[a] + s[b]; n     if (s[i].length() > 1000) n       s[i] = s[i].substr(0, 500) + s[i].substr(s[i].length() - 500, 500); n     ans[i] = max(solve(s[i]), max(ans[a], ans[b])); n     printf( %d n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n int A[N]; n long long sum = 0, ans = 0; n bool state; n map<int, int> cnt; n int main() { n   cnt[0] = 1; n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n   } n   for (int i = 0; i < n; i++) { n     if (A[i] > m) n       sum++; n     else if (A[i] < m) n       sum--; n     state = state | (A[i] == m); n     if (state) { n       ans += (cnt[sum] + cnt[sum - 1]); n       continue; n     } n     cnt[sum]++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n); n     for (auto& i : a) { n       cin >> i; n     } n     vector<int> ops; n     for (int i = 0; i < n - 2; ++i) { n       if (a[i] == 0) { n         continue; n       } n       int j = i + 1; n       while (j < n and a[j] == 1) { n         ++j; n       } n       int sz = j - i; n       if (sz % 2 == 0 or j + 1 >= n) { n         i = j; n       } else if (a[j + 1] == 0) { n         ops.push_back(j - 1); n         a[j] = a[j + 1] = 1; n         i = j; n       } else { n         ops.push_back(j - 1); n         a[j - 1] = a[j + 1] = 0; n         i = j; n       } n     } n     for (int i = 0; i < n - 2; ++i) { n       if (a[i] + a[i + 1] + a[i + 2] == 2) { n         ops.push_back(i); n         a[i] = a[i + 1] = a[i + 2] = 0; n       } n     } n     for (int i = n - 1; i >= 2; --i) { n       if (a[i] + a[i - 1] + a[i - 2] == 2) { n         ops.push_back(i - 2); n         a[i] = a[i - 1] = a[i - 2] = 0; n       } n     } n     if (count(a.begin(), a.end(), 1)) { n       cout <<  NO n ; n     } else { n       cout <<  YES n ; n       cout << ops.size() <<   n ; n       for (auto& i : ops) { n         cout << i + 1 <<    ; n       } n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n char buf_[1 << 21], *p1_ = buf_, *p2_ = buf_; n inline long long in() { n   long long s = 0, f = 1; n   char x = (p1_ == p2_ && (p2_ = (p1_ = buf_) + fread(buf_, 1, 1 << 21, stdin), n                            p1_ == p2_) n                 ? EOF n                 : *p1_++); n   for (; x <  0  || x >  9 ; n        x = (p1_ == p2_ && (p2_ = (p1_ = buf_) + fread(buf_, 1, 1 << 21, stdin), n                           p1_ == p2_) n                 ? EOF n                 : *p1_++)) n     if (x ==  - ) f = -1; n   for (; x >=  0  && x <=  9 ; n        x = (p1_ == p2_ && (p2_ = (p1_ = buf_) + fread(buf_, 1, 1 << 21, stdin), n                           p1_ == p2_) n                 ? EOF n                 : *p1_++)) n     s = (s * 10) + (x & 15); n   return f == 1 ? s : -s; n } n char _buf[1 << 21]; n long long _pos = -1; n inline void flush() { fwrite(_buf, 1, _pos + 1, stdout), _pos = -1; } n inline void pc(char x) { n   if (_pos == (1 << 21) - 1) flush(); n   _buf[++_pos] = x; n } n inline void out(long long x) { n   char k[30]; n   long long pos = 0; n   if (!x) return pc( 0 ); n   if (x < 0) pc( - ), x = -x; n   while (x) k[++pos] = (x % 10) | 48, x /= 10; n   for (long long i = pos; i; i--) pc(k[i]); n } n inline void out(string x) { n   long long len = x.size(); n   for (long long i = 0; i < len; i++) pc(x[i]); n } n }  // namespace IO n using namespace IO; n const long long A = 5e5 + 5; n long long n; n long long head[A], tot_road; n struct Road { n   long long nex, to; n } road[2 * A]; n inline void edge(long long x, long long y) { n   road[++tot_road] = (Road){head[x], y}, head[x] = tot_road; n } n long long sz[A], res[A]; n inline void prepare(long long fa, long long x) { n   sz[x] = 1; n   for (long long y = head[x]; y; y = road[y].nex) { n     long long z = road[y].to; n     if (z == fa) continue; n     prepare(x, z); n     sz[x] += sz[z]; n   } n   return; n } n inline void DFS(long long fa, long long x) { n   for (long long y = head[x]; y; y = road[y].nex) { n     long long z = road[y].to; n     if (z == fa) continue; n     res[z] = res[x] + (sz[x] - sz[z]) * sz[z]; n     DFS(x, z); n   } n   return; n } n signed main() { n   n = in(); n   for (long long i = 1; i < n; i++) { n     long long u = in(), v = in(); n     edge(u, v), edge(v, u); n   } n   prepare(0, 1); n   res[1] = n * (n - 1) / 2; n   DFS(0, 1); n   long long rt = 0; n   for (long long i = 1; i <= n; i++) n     if (res[i] > res[rt]) rt = i; n   prepare(0, rt); n   res[rt] = n * (n - 1) / 2; n   DFS(0, rt); n   long long ans = 0; n   for (long long i = 1; i <= n; i++) ans = max(ans, res[i]); n   out(ans), pc(  n ); n   flush(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> tt[1005], kk[1005]; n int n1, n2, top; n vector<int> vv[1005]; n int main() { n   int k, i, j, n, a, tmp; n   long long ans = 0, sum = 0; n   scanf( %d %d , &n, &k); n   for (i = 0; i < n; i++) { n     scanf( %d %d , &a, &tmp); n     if (tmp == 1) n       tt[n1++] = make_pair(a, i + 1); n     else n       kk[n2++] = make_pair(a, i + 1); n     sum += (long long)a; n   } n   sort(tt, tt + n1); n   sort(kk, kk + n2); n   if (n1 < k) { n     for (i = n1 - 1; i >= 0; i--) { n       vv[top++].push_back(tt[i].second); n       ans += (long long)tt[i].first; n     } n     for (i = 0; top < k; i++) vv[top++].push_back(kk[i].second); n     for (; i < n2; i++) vv[top - 1].push_back(kk[i].second); n   } else { n     for (i = n1 - 1; top < k - 1; i--) { n       vv[top++].push_back(tt[i].second); n       ans += (long long)tt[i].first; n     } n     if (n1 > 0 && n2 > 0) n       ans += (long long)min(tt[0].first, kk[0].first); n     else if (n1 > 0) n       ans += (long long)tt[0].first; n     else n       ans += (long long)kk[0].first; n     for (; i >= 0; i--) vv[top].push_back(tt[i].second); n     for (i = 0; i < n2; i++) vv[top].push_back(kk[i].second); n   } n   printf( %I64d. , sum - (ans + 1) / 2); n   if (ans & 1) n     printf( 5 ); n   else n     printf( 0 ); n   putchar(  n ); n   for (i = 0; i < k; i++) { n     printf( %d  , (int)vv[i].size()); n     for (j = 0; j < (int)vv[i].size(); j++) printf( %d  , vv[i][j]); n     putchar(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000005; n struct Node { n   int left, right; n   long long sum; n } L[N << 2]; n void bulid(int step, int l, int r) { n   L[step].left = l; n   L[step].right = r; n   L[step].sum = 0; n   if (l == r) return; n   int m = (l + r) >> 1; n   bulid(step << 1, l, m); n   bulid(step << 1 | 1, m + 1, r); n } n void update(int step, int pos, long long val) { n   if (L[step].left == L[step].right) { n     L[step].sum = (val) % 1000000007; n     return; n   } n   int m = (L[step].left + L[step].right) >> 1; n   if (pos <= m) n     update(step << 1, pos, val); n   else n     update(step << 1 | 1, pos, val); n   L[step].sum = (L[step << 1].sum + L[step << 1 | 1].sum) % 1000000007; n } n long long query(int step, int l, int r) { n   if (L[step].left == l && L[step].right == r) return L[step].sum; n   int m = (L[step].left + L[step].right) >> 1; n   if (r <= m) n     return query(step << 1, l, r); n   else if (l > m) n     return query(step << 1 | 1, l, r); n   else n     return (query(step << 1, l, m) + query(step << 1 | 1, m + 1, r)) % n            1000000007; n } n long long a[N]; n int main() { n   int n; n   scanf( %d , &n); n   bulid(1, 1, 1000000); n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     scanf( %I64d , &a[i]); n     long long sub = query(1, a[i], a[i]); n     long long sum = (a[i] + a[i] * query(1, 1, a[i])) % 1000000007; n     ans = ((ans + sum - sub) % 1000000007 + 1000000007) % 1000000007; n     update(1, a[i], sum); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000][1000]; n int main() { n   int n, ans = 0; n   cin >> n; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) cin >> a[i][j]; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) { n       int sum1 = 0, sum2 = 0; n       for (int k = 1; k <= n; ++k) sum1 += a[k][j]; n       for (int k = 1; k <= n; ++k) sum2 += a[i][k]; n       if (sum1 > sum2) ans++; n     } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > a[5001]; n int n, t; n int main() { n   int m, u, v, w; n   cin >> n >> m >> t; n   vector<vector<int> > f(n + 1, vector<int>(2, 0)); n   vector<vector<int> > p(n + 1, vector<int>(2, 2e9 + 1)); n   vector<vector<int> > track(n + 1, vector<int>(n + 1, 0)); n   for (int i = 1; i <= m; i++) { n     cin >> u >> v >> w; n     a[v].push_back(make_pair(u, w)); n   } n   f[1][0] = 1; n   p[1][0] = 0; n   int id = 1; n   int res = 0; n   for (int j = 2; j <= n; j++) { n     for (int i = 2; i <= n; i++) n       for (int k = 0; k < a[i].size(); k++) { n         v = a[i][k].first; n         w = a[i][k].second; n         if (f[v][1 - id] && n             ((f[i][id] < f[v][1 - id] + 1 && p[v][1 - id] + w <= t) || n              (f[i][id] == f[v][1 - id] + 1 && p[v][1 - id] + w < p[i][id]))) { n           f[i][id] = f[v][1 - id] + 1; n           p[i][id] = p[v][1 - id] + w; n           track[i][j] = v; n           if (i == n) res = max(res, j); n         } n       } n     id ^= 1; n   } n   vector<int> road; n   cout << res << endl; n   u = n; n   do { n     u = track[u][res--]; n     road.push_back(u); n   } while (u > 1); n   for (int i = road.size() - 1; i >= 0; i--) cout << road[i] <<    ; n   cout << n; n } n


#include <bits/stdc++.h> n using namespace std; n namespace jumpmelon { n const int MAXN = 52; n int A[MAXN + 1], B[MAXN + 1]; n bool F[MAXN + 1]; n void work() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &A[i]); n   vector<vector<int>> Ans; n   while (1) { n     memset(F + 1, 0, sizeof(bool[n])); n     for (int i = 1; i < n; i++) n       if (A[i] + 1 == A[i + 1]) F[i] = 1; n     int x = 0, y = 0; n     for (int i = 1; i <= n; i++) n       if (!F[i]) n         for (int j = 1; j < i; j++) n           if (A[j] == A[i] + 1) { n             x = i; n             y = j; n           } n     if (x == 0 && y == 0) break; n     int p = x; n     while (p > 1 && F[p - 1]) p--; n     vector<int> D; n     if (y > 1) D.push_back(y - 1); n     D.push_back(p - y); n     D.push_back(x - p + 1); n     if (x < n) D.push_back(n - x); n     Ans.push_back(D); n     int l = 1, r = n; n     for (int v : D) { n       r -= v; n       for (int i = 1; i <= v; i++) B[r + i] = A[l + i - 1]; n       l += v; n     } n     memcpy(A + 1, B + 1, sizeof(int[n])); n   } n   printf( %d n , (int)Ans.size()); n   for (auto &&D : Ans) { n     printf( %d , (int)D.size()); n     for (int v : D) printf(  %d , v); n     putchar(  n ); n   } n } n }  // namespace jumpmelon n int main() { n   jumpmelon::work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int n, m, cnt = 0; n   cin >> n >> m; n   char mat[n][m]; n   for (int i = 0; i < (int)(n); i++) { n     for (int j = 0; j < (int)(m); j++) { n       cin >> mat[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int f = 0; n       char x = mat[i][j]; n       for (int k = 0; k < n; k++) { n         if (x >= mat[k][j]) n           continue; n         else { n           f = 1; n           break; n         } n       } n       if (f == 0) { n         cnt++; n         break; n       } n     } n   } n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int N = 1000005; n const double PI = 4 * atan(1); n long long m, x, y, n, p, z, k; n long long h1, m1, h2, m2; n char c, cc; n int main() { n   ios::sync_with_stdio(0); n   cin >> h1 >> c >> m1 >> h2 >> cc >> m2; n   x = (h2 - h1) * 60 + m2 - m1; n   x /= 2; n   x += m1; n   if ((h1 + x / 60) < 10) cout << 0; n   cout << h1 + x / 60 <<  : ; n   if (((x) % 60 < 10)) cout << 0; n   cout << x % 60; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= 500; i++) putchar( 9 ); n   for (int i = 1; i <= 500; i++) putchar( 0 ); n   putchar( 1 ); n   putchar(  n ); n   for (int i = 1; i <= 501; i++) putchar( 9 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100005; n const int oo = 1e9 + 7; n const long long mod = 1e9 + 7; n const double eps = 1e-11; n long long n; n int main() { n   cin.sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   cout << (n - 2LL) * (n - 2LL) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int y, b, r; n   int l, m, n; n   int ans; n   cin >> y >> b >> r; n   l = y; n   m = b; n   n = r; n   int mins = min(min(y, b), r); n   if (mins == r) { n     ans = r + (r - 1) + (r - 2); n   } else if (mins == b) { n     y = b - 1; n     r = b + 1; n     ans = y + b + r; n   } else if (mins == y) { n     b = y + 1; n     r = y + 2; n     if (r > n) { n       y--; n       ans = y + (y + 1) + (y + 2); n     } else { n       ans = y + b + r; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n int win(long long s, long long e) { n   if (e % 2 == 1) { n     if (s % 2 == 1) n       return 0; n     else n       return 1; n   } else { n     if (2 * s > e) { n       if (s % 2 == 1) n         return 1; n       else n         return 0; n     } else if (2 * s <= e && 4 * s > e) { n       return 1; n     } else n       return win(s, e / 4); n   } n } n int lose(long long s, long long e) { n   if (2 * s > e) n     return 1; n   else n     return win(s, e / 2); n } n int Win[N], Lose[N]; n int get_lose(int x); n int get_win(int x); n int get_win(int x) { n   if (x == 1) return Win[1]; n   return Win[x] ? get_lose(x - 1) : get_win(x - 1); n } n int get_lose(int x) { n   if (x == 1) return Lose[1]; n   return Lose[x] ? get_lose(x - 1) : get_win(x - 1); n } n void io() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n int main(int argc, char const *argv[]) { n   io(); n   int t; n   cin >> t; n   long long s, e; n   for (int i = 1; i <= t; i++) { n     cin >> s >> e; n     Win[i] = win(s, e); n     Lose[i] = lose(s, e); n   } n   cout << get_win(t) <<     << get_lose(t) << 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(NULL); n   cout.tie(NULL); n   ; n   int c, v0, v1, a, l; n   cin >> c >> v0 >> v1 >> a >> l; n   int ans = 1; n   c -= min(v0, v1); n   int p = 0; n   while (c > 0) { n     v0 = v0 + a; n     p = min(v0, v1); n     p -= l; n     c -= p; n     ans++; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3005; n vector<int> flist[maxn], rlist[maxn], clist[maxn]; n int n, m, q; n int component[maxn], cptr = 0; n int visited[maxn]; n stack<int> etime; n void fdfs(int cur, vector<int> adj[]) { n   visited[cur] = 1; n   for (auto u : adj[cur]) { n     if (visited[u] != 1) fdfs(u, adj); n   } n   etime.push(cur); n } n void rdfs(int cur, vector<int> adj[]) { n   visited[cur] = 1; n   component[cur] = cptr; n   for (auto u : adj[cur]) { n     if (visited[u] != 1) rdfs(u, adj); n   } n } n void kosaraju() { n   for (int i = 1; i < maxn; i++) { n     if (visited[i] != 1) fdfs(i, flist); n   } n   memset(visited, 0, sizeof(visited)); n   while (!etime.empty()) { n     int cur = etime.top(); n     etime.pop(); n     if (visited[cur] == 1) continue; n     cptr++; n     rdfs(cur, rlist); n   } n } n struct query { n   int u, v, k, id, ans; n }; n bool ucomp(query a, query b) { return a.u < b.u; } n bool idcomp(query a, query b) { return a.id < b.id; } n int done[maxn]; n const int logN = 13; n int parent[maxn][logN], depth[maxn]; n void buildLCA() { n   for (long long j = 1; j < logN; j++) { n     for (long long i = 1; i <= n; i++) { n       if (parent[i][j - 1] != 0) { n         parent[i][j] = parent[parent[i][j - 1]][j - 1]; n       } n     } n   } n } n int getNode(int u, int p) { n   if (p < 0 || parent[u][0] == 0 || visited[u] == 0) return -1; n   for (int i = logN - 1; i >= 0; i--) { n     int shift = 1 << i; n     if (shift <= p) { n       p -= shift; n       u = parent[u][i]; n     } n   } n   return (u == 0 ? -1 : u); n } n void remove(int cur) { n   visited[cur] = 1; n   for (auto u : flist[cur]) { n     if (visited[u]) continue; n     remove(u); n   } n } n void ddffss(int cur) { n   visited[cur] = 1; n   for (int i = 0; i < flist[cur].size(); i++) { n     int u = flist[cur][i]; n     if (visited[u]) continue; n     if (i >= clist[cur].size()) { n       remove(u); n       continue; n     } n     parent[u][0] = cur; n     depth[u] = 1 + depth[cur]; n     ddffss(u); n   } n } n void prep(int cur) { n   memset(visited, 0, sizeof(visited)); n   memset(parent, 0, sizeof(parent)); n   memset(depth, 0, sizeof(depth)); n   ddffss(cur); n   buildLCA(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n >> m >> q; n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     flist[u].push_back(v); n     rlist[v].push_back(u); n   } n   kosaraju(); n   for (int i = 1; i <= n; i++) sort(flist[i].begin(), flist[i].end()); n   for (int i = 1; i <= n; i++) { n     for (auto u : flist[i]) { n       clist[i].push_back(u); n       if (component[i] == component[u]) { n         break; n       } n     } n   } n   query Q[q]; n   for (int i = 0; i < q; i++) { n     cin >> Q[i].u >> Q[i].v >> Q[i].k; n     Q[i].id = i; n   } n   sort(Q, Q + q, ucomp); n   for (int i = 0; i < q; i++) { n     if (done[Q[i].u] == 0) prep(Q[i].u); n     done[Q[i].u] = 1; n     Q[i].ans = getNode(Q[i].v, depth[Q[i].v] + 1 - Q[i].k); n   } n   sort(Q, Q + q, idcomp); n   for (int i = 0; i < q; i++) { n     cout << Q[i].ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[105]; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   long long n, m; n   cin >> n >> m; n   long long maxi = 0, mini = 107; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     maxi = max(maxi, a[i]); n   } n   long long temp = m; n   for (long long i = 0; i < n; i++) { n     if (m > 0) { n       m -= (maxi - a[i]); n       a[i] = maxi; n       if (m <= 0) { n         mini = maxi; n         break; n       } n     } n   } n   if (m > 0) mini = maxi + ceil(m / (n + 0.0)); n   cout << mini <<     << maxi + temp <<   n ; n   return 0; n } n