#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   long long int sum = 0; n   cin >> n; n   int a, b; n   int max = INT_MIN; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     sum = sum - a + b; n     if (max < sum) max = sum; n   } n   cout << max; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n const int mod = 1e9 + 7; n using namespace std; n template <class T> n void cinn(T& x) { n   cin >> x; n } n template <class H, class... T> n void cinn(H& h, T&... t) { n   cinn(h); n   cinn(t...); n } n template <class A> n void cinn(vector<A>& x) { n   for (auto& a : x) cinn(a); n } n void Shazam() { n   long long n, k; n   cinn(n, k); n   vector<long long> a(n); n   cinn(a); n   long long ans = 0; n   for (long long i = k; i < 101; i++) { n     long long cnt = 0; n     for (long long j = 0; j < n; j++) { n       cnt += (a[j] / i); n     } n     ans = max(ans, cnt * i); n   } n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long t = 1; n   while (t--) Shazam(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 1e5 + 13; n int const INF = 1e9 + 13; n int n, m; n set<int> p[N]; n int l[N], r[N]; n int pos[N], x[N]; n int tsz; n int a[N]; n int type[N]; n vector<int> t[N * 4], tright[N * 4]; n vector<long long> F[N * 4]; n vector<int> qid; n vector<pair<int, int>> qpos[N]; n vector<int> lposes; n bool cmpl(int i, int j) { return l[i] < l[j]; } n void merge(vector<int> &v, vector<int> &l, vector<int> &r) { n   int lp = 0; n   int rp = 0; n   int ln = l.size(); n   int rn = r.size(); n   while (lp < ln || rp < rn) { n     if (rp == rn || (lp < ln && ::r[l[lp]] < ::r[r[rp]])) { n       v.push_back(l[lp++]); n     } else { n       v.push_back(r[rp++]); n     } n   } n } n void build(int v, int tl, int tr) { n   if (tl == tr) { n     t[v].push_back(qid[tl]); n     F[v].assign(1, 0LL); n     for (int i = 0; i < t[v].size(); ++i) { n       qpos[t[v][i]].push_back(make_pair(v, i)); n     } n     tright[v].push_back(r[qid[tl]]); n   } else { n     int tm = (tl + tr) / 2; n     build(v * 2 + 1, tl, tm); n     build(v * 2 + 2, tm + 1, tr); n     merge(t[v], t[v * 2 + 1], t[v * 2 + 2]); n     for (int i = 0; i < t[v].size(); ++i) { n       qpos[t[v][i]].push_back(make_pair(v, i)); n       tright[v].push_back(r[t[v][i]]); n     } n     F[v].assign(t[v].size(), 0LL); n   } n } n void updF(vector<long long> &F, int x, int v) { n   int n = F.size(); n   while (x < n) { n     F[x] += v; n     x |= (x + 1); n   } n } n long long getF(vector<long long> &F, int x) { n   long long res = 0; n   while (x >= 0) { n     res += F[x]; n     x = (x & (x + 1)) - 1; n   } n   return res; n } n void upd(vector<long long> &F, int l, int r, int val) { n   if (l > r) return; n   updF(F, l, val); n   updF(F, r + 1, -val); n } n int getLeft(vector<int> &v, int val) { n   int l = -1; n   int r = v.size(); n   while (r - l > 1) { n     int m = (l + r) / 2; n     if (v[m] >= val) n       r = m; n     else n       l = m; n   } n   return r; n } n int getRight(vector<int> &v, int val) { n   int l = -1; n   int r = v.size(); n   while (r - l > 1) { n     int m = (l + r) / 2; n     if (v[m] <= val) n       l = m; n     else n       r = m; n   } n   return l; n } n void upd(int v, int tl, int tr, int ll, int lr, int rl, int rr, int val) { n   if (tl > lr || ll > tr) return; n   if (ll <= tl && tr <= lr) { n     int left = getLeft(tright[v], rl); n     int right = getRight(tright[v], rr); n     upd(F[v], left, right, val); n     return; n   } n   int tm = (tl + tr) / 2; n   upd(v * 2 + 1, tl, tm, ll, lr, rl, rr, val); n   upd(v * 2 + 2, tm + 1, tr, ll, lr, rl, rr, val); n } n long long answer(int id) { n   long long res = 0; n   for (int i = 0; i < qpos[id].size(); ++i) { n     res += getF(F[qpos[id][i].first], qpos[id][i].second); n   } n   return res; n } n void push(int pos, int val) { n   set<int>::iterator bef, aft; n   bef = p[val].lower_bound(pos); n   aft = p[val].upper_bound(pos); n   if (bef != p[val].begin()) { n     --bef; n     int lp = (*bef); n     int dist = pos - lp; n     lp = getRight(lposes, lp); n     int rp = (aft == p[val].end() ? INF : (*aft) - 1); n     upd(0, 0, tsz - 1, 0, lp, pos, rp, dist); n   } n   bef = p[val].lower_bound(pos); n   aft = p[val].upper_bound(pos); n   if (aft != p[val].end()) { n     int lp; n     if (bef != p[val].begin()) { n       --bef; n       lp = (*bef) + 1; n     } else { n       lp = 0; n     } n     lp = getLeft(lposes, lp); n     int rp = getRight(lposes, pos); n     int rpp = (*aft); n     int dist = rpp - pos; n     upd(0, 0, tsz - 1, lp, rp, rpp, INF, dist); n   } n   p[val].insert(pos); n } n void pop(int pos, int val) { n   p[val].erase(pos); n   set<int>::iterator bef, aft; n   bef = p[val].lower_bound(pos); n   aft = p[val].upper_bound(pos); n   if (bef != p[val].begin()) { n     --bef; n     int lp = (*bef); n     int dist = pos - lp; n     lp = getRight(lposes, lp); n     int rp = (aft == p[val].end() ? INF : (*aft) - 1); n     upd(0, 0, tsz - 1, 0, lp, pos, rp, -dist); n   } n   bef = p[val].lower_bound(pos); n   aft = p[val].upper_bound(pos); n   if (aft != p[val].end()) { n     int lp; n     if (bef != p[val].begin()) { n       --bef; n       lp = (*bef) + 1; n     } else { n       lp = 0; n     } n     lp = getLeft(lposes, lp); n     int rp = getRight(lposes, pos); n     int rpp = (*aft); n     int dist = rpp - pos; n     upd(0, 0, tsz - 1, lp, rp, rpp, INF, -dist); n   } n } n void solve() { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < m; ++i) { n     cin >> type[i]; n     if (type[i] == 1) { n       cin >> pos[i] >> x[i]; n       --pos[i]; n     } else { n       cin >> l[i] >> r[i]; n       --l[i]; n       --r[i]; n       qid.push_back(i); n     } n   } n   tsz = qid.size(); n   if (tsz == 0) return; n   sort(qid.begin(), qid.end(), cmpl); n   for (int i = 0; i < qid.size(); ++i) lposes.push_back(l[qid[i]]); n   build(0, 0, tsz - 1); n   for (int i = 0; i < n; ++i) push(i, a[i]); n   for (int i = 0; i < m; ++i) { n     if (type[i] == 1) { n       pop(pos[i], a[pos[i]]); n       a[pos[i]] = x[i]; n       push(pos[i], a[pos[i]]); n     } else { n       long long ans = answer(i); n       cout << ans << endl; n     } n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long bigmod(long long p, long long e, long long M) { n   long long ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return ret; n } n long long extended(long long a, long long b, long long &x, long long &y) { n   a = abs(a); n   b = abs(b); n   long long g, x1, y1; n   if (!b) { n     x = 1; n     y = 0; n     g = a; n     return g; n   } n   g = extended(b, a % b, x1, y1); n   x = y1; n   y = x1 - (a / b) * y1; n   return g; n } n long long modinverse(long long a, long long M) { return bigmod(a, M - 2, M); } n long long bpow(long long p, long long e) { n   long long ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p); n     p = (p * p); n   } n   return ret; n } n int toInt(string s) { n   int sm; n   stringstream ss(s); n   ss >> sm; n   return sm; n } n int toLlint(string s) { n   long long int sm; n   stringstream ss(s); n   ss >> sm; n   return sm; n } n string convertInt(long long number) { n   if (number == 0) return  0 ; n   string temp =   ; n   string returnvalue =   ; n   while (number > 0) { n     temp += number % 10 + 48; n     number /= 10; n   } n   for (int i = 0; i < temp.length(); i++) n     returnvalue += temp[temp.length() - i - 1]; n   return returnvalue; n } n long long ar[550], n, m, b, modd; n long long dp[550][550]; n int main() { n   long long n, m, b, modd; n   cin >> n >> m >> b >> modd; n   for (int i = 1; i <= n; i++) { n     cin >> ar[i]; n   } n   for (int i = 1; i <= n; i++) { n     if (ar[i] <= b) dp[1][ar[i]]++; n     dp[1][ar[i]] %= 1000000007; n     for (int j = 0; j <= b; j++) { n       for (int k = 1; k <= m; k++) { n         if (ar[i] + j > b) continue; n         dp[k][ar[i] + j] += dp[k - 1][j]; n         dp[k][ar[i] + j] %= modd; n       } n     } n   } n   long long ans = 0; n   for (int i = 0; i <= b; i++) { n     ans += dp[m][i]; n     ans %= modd; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a; n   cin >> a; n   int result; n   result = 26 + 25 * a.length(); n   cout << result; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, pos[200001]; n struct node { n   node *l, *r; n   long long int lazy, lazy2; n }; n node *root[200001]; n int build(int s, int e, node *n) { n   if (s == e) { n     n->l = n->r = NULL; n     n->lazy = -1, n->lazy2 = 1; n     return 0; n   } n   int mid = (s + e) / 2; n   n->l = new node, n->r = new node; n   build(s, mid, n->l), build(mid + 1, e, n->r); n   n->lazy = n->lazy2 = 0; n   return 0; n } n pair<long long int, long long int> query(int s, int e, int q, node *n) { n   if (s == e) return make_pair(n->lazy, n->lazy2); n   int mid = (s + e) / 2; n   pair<long long int, long long int> p; n   if (q <= mid) n     p = query(s, mid, q, n->l); n   else n     p = query(mid + 1, e, q, n->r); n   return make_pair(p.first + n->lazy, p.second + n->lazy2); n } n int update(int s, int e, int as, int ae, node *o, node *n, int x, int t) { n   if ((s >= as) && (e <= ae)) { n     n->l = o->l, n->r = o->r; n     n->lazy = o->lazy + x, n->lazy2 = o->lazy2 + (long long int)x * t; n     return 0; n   } n   int mid = (s + e) / 2; n   if (ae <= mid) { n     n->r = o->r, n->l = new node; n     update(s, mid, as, ae, o->l, n->l, x, t); n   } else if (as > mid) { n     n->l = o->l, n->r = new node; n     update(mid + 1, e, as, ae, o->r, n->r, x, t); n   } else { n     n->l = new node, n->r = new node; n     update(s, mid, as, ae, o->l, n->l, x, t); n     update(mid + 1, e, as, ae, o->r, n->r, x, t); n   } n   n->lazy = o->lazy, n->lazy2 = o->lazy2; n   return 0; n } n int tree[1 << 19]; n int build2(int s, int e, int i) { n   if (s == e) { n     tree[i] = -1; n     return 0; n   } n   int mid = (s + e) / 2; n   build2(s, mid, 2 * i + 1), build2(mid + 1, e, 2 * i + 2); n   tree[i] = -1; n   return 0; n } n int query2(int s, int e, int qs, int qe, int i) { n   if ((s > qe) || (e < qs)) n     return 1e9; n   else if ((s >= qs) && (e <= qe)) n     return tree[i]; n   int mid = (s + e) / 2; n   return min(query2(s, mid, qs, qe, 2 * i + 1), n              query2(mid + 1, e, qs, qe, 2 * i + 2)); n } n int update2(int s, int e, int ai, int i, int num) { n   if ((s > ai) || (e < ai)) n     return 0; n   else if (s == e) { n     tree[i] = num; n     return 0; n   } n   int mid = (s + e) / 2; n   update2(s, mid, ai, 2 * i + 1, num), update2(mid + 1, e, ai, 2 * i + 2, num); n   tree[i] = min(tree[2 * i + 1], tree[2 * i + 2]); n   return 0; n } n int update3(int s, int e, int as, int ae, int i, int ol, int nl, int t) { n   if ((s > ae) || (e < as)) n     return 0; n   else if (ol == nl) n     return 0; n   else if ((s >= as) && (e <= ae)) { n     if (s == e) { n       nl = min(nl, tree[i]), ol = min(ol, tree[i]); n       if (nl > ol) { n         node *r2 = new node; n         update(0, n, s, e, root[t + 1], r2, nl - ol, t); n         root[t + 1] = r2; n       } n       return 0; n     } else if (nl <= tree[i]) { n       node *r2 = new node; n       update(0, n, s, e, root[t + 1], r2, nl - ol, t); n       root[t + 1] = r2; n       return 0; n     } n   } n   int mid = (s + e) / 2; n   update3(s, mid, as, ae, 2 * i + 1, ol, nl, t); n   update3(mid + 1, e, as, ae, 2 * i + 2, min(ol, tree[2 * i + 1]), n           min(nl, tree[2 * i + 1]), t); n   return 0; n } n long long int getAns(int l, int r, int k) { n   if (k == -1) return (long long int)(r - l + 1) * (r - l + 2) / 2; n   int s = 0, e = r + 1; n   while (s < e) { n     int m = (s + e) / 2; n     pair<long long int, long long int> p = query(0, n, k, root[m + 1]); n     if (p.first < l) n       s = m + 1; n     else n       e = m; n   } n   if (s > r) n     return 0; n   else { n     pair<long long int, long long int> p = query(0, n, k, root[r + 1]); n     pair<long long int, long long int> p2 = query(0, n, k, root[s]); n     return (p.first * (r + 1) - p.second) - (p2.first * s - p2.second) - n            (long long int)(r - s + 1) * (l - 1); n   } n } n int main() { n   int i; n   int a, l, r, k; n   long long int lans = 0; n   scanf( %d , &n); n   for (i = 0; i <= n; i++) pos[i] = -1; n   root[0] = new node; n   build(0, n, root[0]), build2(0, n, 0); n   for (i = 0; i < n; i++) { n     scanf( %d %d %d %d , &a, &l, &r, &k); n     a = (a + lans) % (n + 1); n     l = (l + lans) % (i + 1); n     r = (r + lans) % (i + 1); n     if (l > r) swap(l, r); n     k = (k + lans) % (n + 1); n     int q = query2(0, n, 0, a, 0); n     if (q != pos[a]) n       pos[a] = i, update2(0, n, a, 0, i), root[i + 1] = root[i]; n     else { n       pos[a] = i, update2(0, n, a, 0, i); n       int q2 = query2(0, n, 0, a, 0); n       root[i + 1] = root[i]; n       update3(0, n, a, n, 0, q, q2, i); n     } n     lans = getAns(l, r, k - 1) - getAns(l, r, k); n     printf( %I64d n , lans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class node { n  public: n   int lo, hi, value; n   node *left, *right; n   node(const int _lo, const int _hi) { n     left = right = NULL; n     lo = _lo, hi = _hi, value = 0; n   } n   void build() { n     if (lo == hi) return; n     const int mid = (lo + hi) >> 1; n     left = new node(lo, mid), left->build(); n     right = new node(mid + 1, hi), right->build(); n   } n   void update(const int idx) { n     if (lo > idx or hi < idx) return; n     if (lo == idx and hi == idx) { n       ++value; n       return; n     } n     left->update(idx); n     right->update(idx); n     value = left->value + right->value; n   } n   int query(const int _lo, const int _hi) { n     if (lo > _hi or hi < _lo) return 0; n     if (lo >= _lo and hi <= _hi) return value; n     int a = left->query(_lo, _hi); n     int b = right->query(_lo, _hi); n     return a + b; n   } n   int leftmost() { n     if (lo == hi) return lo; n     if (left->value) return left->leftmost(); n     return right->leftmost(); n   } n   int rightmost() { n     if (value == hi - lo + 1) return lo - 1; n     if (lo == hi) return lo; n     if (right->value < right->hi - right->lo + 1) return right->rightmost(); n     return left->rightmost(); n   } n }; n int main() { n   printf( 1 ); n   int n; n   scanf( %d , &n); n   node root = node(1, n); n   root.build(); n   for (int i = 0; i < n; ++i) { n     int x; n     scanf( %d , &x); n     root.update(x); n     printf(  %d , root.query(root.leftmost(), root.rightmost()) + 1); n   } n   return !printf(  n ); n }; n


#include <bits/stdc++.h> n using namespace std; n int tree[(1 << 20)]; n void add(int x, int val) { n   for (int i = x; i < (1 << 20); i = ((i) | (i + 1))) tree[i] += val; n } n int sum(int x) { n   int ans = 0; n   for (int i = x; i > 0; i = ((i) & (i - 1))) ans += tree[i - 1]; n   return ans; n } n int N, Q; n map<int, int> idtohook; n map<int, int> appearance; n priority_queue<pair<int, int> > segments; n map<int, int> nextL, nextR; n vector<pair<int, pair<int, int> > > query; n map<int, int> zip; n vector<int> ans; n int input(void) { n   int ans; n   scanf( %d , &ans); n   return ans; n } n void count_query(int low, int high) { n   query.push_back(make_pair(0, make_pair(low, high))); n   zip[low] = zip[high] = 0; n } n void enter_query(int id) { n   int hook = -1; n   while (1) { n     pair<int, int> p = segments.top(); n     segments.pop(); n     int L = p.second; n     int R = L + p.first; n     if (nextR[L] != R || nextL[R] != L) continue; n     hook = (L + R + 1) / 2; n     nextL[hook] = L; n     nextL[R] = hook; n     nextR[L] = hook; n     nextR[hook] = R; n     segments.push(make_pair(hook - L, L)); n     segments.push(make_pair(R - hook, hook)); n     break; n   } n   query.push_back(make_pair(1, make_pair(hook, 1))); n   idtohook[id] = hook; n   zip[hook] = 0; n } n void leave_query(int id) { n   int hook = idtohook[id]; n   int L = nextL[hook], R = nextR[hook]; n   nextL[hook] = nextR[hook] = -1; n   nextL[R] = L; n   nextR[L] = R; n   segments.push(make_pair(R - L, L)); n   query.push_back(make_pair(1, make_pair(hook, -1))); n } n void solve(void) { n   int i; n   i = 0; n   for (__typeof((zip).begin()) itr = (zip).begin(); itr != (zip).end(); itr++) { n     (itr->second) = i; n     i++; n   } n   for ((i) = 0; (i) < (int)(query.size()); (i)++) { n     int type = query[i].first; n     if (type == 0) { n       int low = zip[query[i].second.first]; n       int high = zip[query[i].second.second]; n       int tmp = sum(high + 1); n       if (low > 0) tmp -= sum(low); n       ans.push_back(tmp); n     } else { n       int pos = zip[query[i].second.first]; n       add(pos, query[i].second.second); n     } n   } n } n int main(void) { n   int i; n   N = input(); n   Q = input(); n   segments.push(make_pair(N + 1, 0)); n   nextR[0] = N + 1; n   nextL[N + 1] = 0; n   zip[0] = zip[N + 1] = 0; n   for ((i) = 0; (i) < (int)(Q); (i)++) { n     int x = input(); n     if (x == 0) { n       int low = input(), high = input(); n       count_query(low, high); n     } else { n       appearance[x]++; n       int tmp = appearance[x]; n       if (tmp % 2 == 1) { n         enter_query(x); n       } else { n         leave_query(x); n       } n     } n   } n   solve(); n   for ((i) = 0; (i) < (int)(ans.size()); (i)++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int x; n   int n, m; n   scanf( %d %d , &n, &m); n   if (m == 3 && n > 4) { n     printf( -1 n ); n     return 0; n   } n   for (x = 0; x < m; ++x) printf( %d %d n , x, x * x + 10001); n   for (x = 0; x < n - m; ++x) printf( %d %d n , x, -x * x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, tp; n int a[2000002]; n int main() { n   scanf( %d , &tp); n   int p = 1, i, j; n   for (i = 0; i <= 100; i++) { n     n++; n     if (p == tp) break; n     p *= 4; n   } n   for (i = 0; i < tp; i++) scanf( %d , &a[i]); n   sort(a, a + tp); n   long long ans = 0; n   p = 1; n   for (i = 0; i < n; i++) { n     for (j = 0; j < p; j++) ans += (long long)a[tp - j - 1]; n     p *= 4; n   } n   printf( %I64d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int mod = 1000000007; n const int inf = 1034567891; n const long long LL_INF = 1234567890123456789ll; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cout << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n template <typename T> n T GCD(T a, T b) { n   long long t; n   while (a) { n     t = a; n     a = b % a; n     b = t; n   } n   return b; n } n template <typename T> n string toString(T a) { n   return to_string(a); n } n template <typename T> n void toInt(string s, T& x) { n   stringstream str(s); n   str >> x; n } n inline int add(int x, int y) { n   x += y; n   if (x >= mod) x -= mod; n   return x; n } n inline int sub(int x, int y) { n   x -= y; n   if (x < 0) x += mod; n   return x; n } n inline int mul(int x, int y) { return (x * 1ll * y) % mod; } n inline int powr(int a, long long b) { n   int x = 1 % mod; n   while (b) { n     if (b & 1) x = mul(x, a); n     a = mul(a, a); n     b >>= 1; n   } n   return x; n } n inline int inv(int a) { return powr(a, mod - 2); } n string str; n long long give(int l, int r) { n   long long ans = 0, p = 0; n   for (int i = r; i >= l; i--) { n     ans += (1ll << p) * (str[i] - 48); n     p++; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int test; n   cin >> test; n   while (test--) { n     cin >> str; n     int n = str.size(); n     long long ans = 0; n     int nxt = -1; n     bool ok = false; n     for (int i = n - 1; i >= 0; i--) { n       if (!ok) { n         nxt = i; n       } n       if (str[i] ==  1 ) { n         nxt = i; n       } n       int e = nxt - i; n       for (int j = nxt; j < nxt + 20 && j < n; j++) { n         long long num = give(nxt, j); n         if (num == (j - nxt + 1 + e)) { n           ans++; n         } n       } n       if (str[i] ==  1 ) { n         ok = true; n         nxt = i; n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long res = 1; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i < n; ++i) { n     res += i * 12; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 7; n const double pi = acos(-1), EPS = 1e-8; n int n; n string str; n map<deque<char>, deque<char>> mp; n bool is(deque<char> ck, string s) { n   if (ck.size() != s.size()) return 0; n   for (int i = 0; i < s.size(); ++i) n     if (ck[i] != s[i]) return 0; n   return 1; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   deque<char> t; n   t.push_back( v ); n   t.push_back( o ); n   t.push_back( i ); n   t.push_back( d ); n   mp[t] = t; n   cin >> n; n   cin.ignore(); n   while (n--) { n     getline(cin, str); n     bool out = 0; n     deque<char> tmp, s; n     for (int i = 0; i < str.size(); ++i) { n       if (str[i] ==    ) { n         if (tmp.size()) { n           if (is(tmp,  typeof )) n             out = 1; n           else n             s = tmp; n         } n         tmp.clear(); n       } else n         tmp.push_back(str[i]); n     } n     deque<char> var = tmp; n     if (out) { n       int And = 0, pointer = 0; n       while (var.front() ==  & ) ++And, var.pop_front(); n       while (var.back() ==  * ) ++pointer, var.pop_back(); n       if (mp[var].size() == 0) { n         cout <<  errtype n ; n         continue; n       } n       var = mp[var]; n       while (var.back() ==  * ) ++pointer, var.pop_back(); n       int x = min(And, pointer); n       And -= x; n       pointer -= x; n       if (And) n         cout <<  errtype n ; n       else if (mp[var].size()) { n         for (char go : mp[var]) cout << go; n         while (pointer--) cout <<  * ; n         cout <<   n ; n       } else n         cout <<  errtype n ; n     } else { n       int And = 0, pointer = 0; n       while (s.front() ==  & ) { n         ++And; n         s.pop_front(); n       } n       while (s.back() ==  * ) { n         ++pointer; n         s.pop_back(); n       } n       int x = min(And, pointer); n       pointer -= x; n       And -= x; n       if (mp[s].size()) { n         s = mp[s]; n         while (s.back() ==  *  && And) { n           --And; n           s.pop_back(); n         } n         while (s.front() ==  &  && pointer) { n           --pointer; n           s.pop_front(); n         } n         if (And && mp[var].size()) n           mp.erase(var); n         else if (And == 0) { n           while (pointer--) s.push_back( * ); n           mp[var] = s; n         } n       } else if (mp[var].size()) n         mp.erase(var); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct debugger { n   template <typename T> n   debugger& operator,(const T& v) { n     cerr << v <<   t ; n     return *this; n   } n } dbg; n template <class A, class B> n ostream& operator<<(ostream& o, const pair<A, B>& p) { n   return o <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <class T> n ostream& operator<<(ostream& o, const vector<T>& v) { n   o <<  [ ; n   for (__typeof((v).end()) it = (v).begin(); it != (v).end(); ++it) n     o << *it <<  ,  ; n   return o <<  ] ; n } n template <class T> n ostream& operator<<(ostream& o, const set<T>& v) { n   o <<  [ ; n   for (__typeof((v).end()) it = (v).begin(); it != (v).end(); ++it) n     o << *it <<  ,  ; n   return o <<  ] ; n } n template <class T> n inline void MAX(T& a, T b) { n   if (a < b) a = b; n } n template <class T> n inline void MIN(T& a, T b) { n   if (a > b) a = b; n } n template <class T> n inline bool read(T& x) { n   int c = getchar(); n   int sgn = 1; n   while (~c && c <  0  || c >  9 ) { n     if (c ==  - ) sgn = -1; n     c = getchar(); n   } n   for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ; n   x *= sgn; n   return ~c; n } n int a[15], l = 0; n int main() { n   memset(a, 0, sizeof a); n   for (__typeof((6) - 1) i = (0); i <= (6) - 1; ++i) { n     int x = ({ n       int a; n       scanf( %d , &a); n       a; n     }); n     a[x]++; n     if (a[x] >= 4) l = x; n   } n   if (!l) n     puts( Alien ); n   else { n     a[l] -= 4; n     int c = 0; n     for (__typeof((10) - 1) i = (0); i <= (10) - 1; ++i) n       if (a[i]) c++; n     if (c > 1) n       puts( Bear ); n     else n       puts( Elephant ); n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,unroll-loops ) n #pragma loop - opt(on) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native ) n using namespace std; n const long long mxN = 1e5 + 5; n long long n, m, Q; n bitset<mxN> vis, in, incy; n long long dsu[mxN], lca[mxN], eu[mxN], ev[mxN], tag[mxN], sum[mxN]; n vector<long long> g[mxN], q[mxN]; n long long get(long long x) { return x == dsu[x] ? x : dsu[x] = get(dsu[x]); } n void tarjan(long long u, long long p = -1) { n   dsu[u] = u; n   in[u] = 1; n   for (long long v : g[u]) n     if (!in[v]) tarjan(v, u); n   for (long long i : q[u]) { n     long long v = u ^ eu[i] ^ ev[i]; n     if (vis[v]) { n       lca[i] = get(v); n     } n     if (v == u) lca[v] = u; n   } n   vis[u] = 1; n   dsu[u] = p; n } n vector<long long> stk; n void dfs(long long u, long long p = -1) { n   vis[u] = in[u] = 1; n   stk.emplace_back(u); n   for (long long v : g[u]) { n     if (v == p) continue; n     if (in[v]) { n       tag[v]++; n       incy[v] = 1; n       while (!stk.empty() and stk.back() != v) { n         incy[stk.back()] = 1, stk.pop_back(); n       } n       stk.pop_back(); n     } n     if (vis[v]) continue; n     dfs(v, u); n   } n   if (!stk.empty() and stk.back() == u) stk.pop_back(); n   in[u] = 0; n } n void add(long long u) { n   vis[u] = 1; n   sum[u] += tag[u]; n   for (long long v : g[u]) { n     if (vis[v]) continue; n     sum[v] += sum[u]; n     add(v); n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   cin >> n >> m; n   while (m--) { n     long long a, b; n     cin >> a >> b; n     g[a].emplace_back(b); n     g[b].emplace_back(a); n   } n   dfs(1, 0); n   vis = 0; n   add(1); n   cin >> Q; n   for (long long i = 0; i < Q; i++) { n     cin >> eu[i] >> ev[i]; n     q[eu[i]].emplace_back(i); n     q[ev[i]].emplace_back(i); n   } n   vis = 0; n   in = 0; n   tarjan(1, 0); n   vector<long long> p2(n + 1); n   p2[0] = 1; n   for (long long i = 1; i <= n; i++) p2[i] = (p2[i - 1] << 1) % 1000000007; n   for (long long i = 0; i < Q; i++) { n     cout << p2[sum[eu[i]] + sum[ev[i]] - 2 * sum[lca[i]] + incy[lca[i]]] n          <<   n ; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n char in[100000 + 1]; n int main() { n   vector<array<int, 4> > cur, nex; n   cur.push_back(array<int, 4>{{}}); n   int n; n   scanf( %d , &n); n   scanf( %s , in); n   for (int i = 0; i < n; i++) { n     int p = -1; n     switch (in[i]) { n       case  G : n         p = 0; n         break; n       case  H : n         p = 1; n         break; n       case  R : n         p = 2; n         break; n       case  S : n         p = 3; n         break; n     } n     if (p >= 0) { n       for (int i = 0; i < cur.size(); i++) { n         cur[i][p]++; n       } n       continue; n     } n     nex.clear(); n     for (auto a : cur) { n       int m = a[0]; n       for (int i = 1; i < 4; i++) { n         m = min(m, a[i]); n       } n       for (int i = 0; i < 4; i++) { n         if (a[i] == m) { n           nex.push_back(a); n           nex.back()[i]++; n         } n       } n     } n     sort(nex.begin(), nex.end()); n     nex.resize(unique(nex.begin(), nex.end()) - nex.begin()); n     nex.swap(cur); n   } n   const char* str[] = { Gryffindor ,  Hufflepuff ,  Ravenclaw ,  Slytherin }; n   for (int i = 0; i < 4; i++) { n     for (auto a : cur) { n       int m = a[0]; n       for (int i = 1; i < 4; i++) { n         m = min(m, a[i]); n       } n       if (a[i] == m) { n         puts(str[i]); n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cross(pair<long long, long long> a, pair<long long, long long> b, n                 pair<long long, long long> c) { n   pair<long long, long long> v1 = n       make_pair(b.first - a.first, b.second - a.second); n   pair<long long, long long> v2 = n       make_pair(c.first - a.first, c.second - a.second); n   if ((long long)v1.first * (long long)v2.second - n           (long long)v2.first * (long long)v1.second > n       0) n     return 1; n   else if ((long long)v1.first * (long long)v2.second - n                (long long)v2.first * (long long)v1.second < n            0) n     return -1; n   return 0; n } n int main(int argc, char* argv[]) { n   long long n; n   cin >> n; n   vector<long long> arr(n); n   for (long long i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   vector<pair<long long, long long> > p; n   p.push_back(make_pair(-1, 0)); n   long long s = 0; n   for (long long i = 0; i < n; i++) { n     s += arr[i]; n     p.push_back(make_pair(i, s)); n   } n   stack<pair<long long, long long> > ch; n   ch.push(p[0]); n   ch.push(p[1]); n   for (long long i = 2; i < n + 1; i++) { n     pair<long long, long long> top = ch.top(); n     ch.pop(); n     while (ch.size() > 0 && cross(ch.top(), top, p[i]) == -1) { n       top = ch.top(); n       ch.pop(); n     } n     ch.push(top); n     ch.push(p[i]); n   } n   vector<pair<long long, long long> > vec; n   while (ch.size()) { n     vec.push_back(ch.top()); n     ch.pop(); n   } n   reverse(vec.begin(), vec.end()); n   vector<double> cev; n   long long cur = 0; n   for (long long i = -1; i < n; i++) { n     if (vec[cur].first == i) n       cev.push_back(vec[cur].second); n     else { n       if (cur < vec.size() - 1 && vec[cur + 1].first <= i) { n         cur++; n         i--; n         continue; n       } n       long long x1 = vec[cur + 1].first - vec[cur].first; n       long long y1 = vec[cur + 1].second - vec[cur].second; n       long long x2 = i - vec[cur].first; n       cev.push_back((((double)x2 * (double)y1) / (double)x1) + vec[cur].second); n     } n   } n   for (long long i = 0; i < cev.size() - 1; i++) { n     cout << setprecision(13) << double(cev[i + 1] - cev[i]) <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n bool func(deque<int>& v) { n   int x = v.back(); n   if (x > 1) { n     v.pop_back(); n     int y = x / 2; n     int y2 = x - y; n     if (y == 1) n       v.push_front(y); n     else n       v.push_back(y); n     if (y2 == 1) n       v.push_front(y2); n     else n       v.push_back(y2); n     return true; n   } n   return false; n } n void printv(deque<int>& v) { n   for (int i = 0; i < v.size(); i++) cout << v[i] <<    ; n   cout << endl; n } n int main() { n   int k; n   int xyz[3]; n   cin >> xyz[0] >> xyz[1] >> xyz[2] >> k; n   sort(xyz, xyz + 3); n   deque<int> first, second, third; n   first.push_back(xyz[2]); n   second.push_back(xyz[1]); n   third.push_back(xyz[0]); n   int i = 0; n   while (i < k) { n     if (func(first)) n       i++; n     else n       break; n     if (i < k && func(second)) i++; n     if (i < k && func(third)) i++; n   } n   cout << (long long int)first.size() * second.size() * third.size(); n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int cnt = 0; n   vector<int> v; n   char last =  * ; n   for (int i = 0, to = n; i < to; i++) { n     if (last != s[i]) { n       if (cnt > 0) v.push_back(cnt); n       cnt = 1; n       last = s[i]; n     } else { n       cnt++; n     } n   } n   v.push_back(cnt); n   int ans = 0; n   int resto = 0; n   for (int i = 0, to = (int)v.size(); i < to; i++) { n     if (v[i] > 1) { n       resto -= (v[i] - 2); n       resto = max(resto, 0); n       ans++; n     } else { n       resto++; n       ans++; n     } n   } n   cout << ans - resto / 2 <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   int t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k = 0; n   cin >> n; n   int arr[n + 2]; n   arr[0] = arr[n + 1] = 0; n   for (int i = 1; i <= n; i++) cin >> arr[i]; n   for (int i = 1; i <= n; i++) n     if (arr[i - 1] == 1 && arr[i + 1] == 1 && arr[i] == 0) arr[i + 1] = 0, k++; n   cout << k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long int read() { n   char C = getchar(); n   long long int N = 0, F = 1; n   while (( 0  > C || C >  9 ) && (C !=  - )) C = getchar(); n   if (C ==  - ) F = -1, C = getchar(); n   while ( 0  <= C && C <=  9 ) n     N = (N << 1) + (N << 3) + (C - 48), C = getchar(); n   return F * N; n } n long long int D[250005], NEXT[250005], ST[250005], LIM; n long long int F[250005][2], SUM[250005]; n struct DQ { n   priority_queue<long long int> A, B; n   void push(long long int x) { A.push(x); } n   void condense() { n     while (A.size() && B.size() && A.top() == B.top()) { n       A.pop(); n       B.pop(); n     } n   } n   void pop() { n     condense(); n     A.pop(); n   } n   long long int top() { n     condense(); n     return A.top(); n   } n   void del(long long int x) { B.push(x); } n   long long int size() { return A.size() - B.size(); } n } H[250005]; n bool vis[250005]; n vector<long long int> VECD[250005]; n vector<pair<long long int, long long int> > E[250005]; n bool cmp(pair<long long int, long long int> A, n          pair<long long int, long long int> B) { n   return D[A.first] < D[B.first]; n } n void dele(long long int wch) { n   vis[wch] = true; n   for (long long int i = ST[wch]; i < E[wch].size(); i++) { n     if (vis[E[wch][i].first]) continue; n     long long int to = E[wch][i].first, wei = E[wch][i].second; n     H[to].push(wei); n     SUM[to] += wei; n   } n } n void upd(long long int wch, long long int num, vector<long long int>& cont) { n   while (H[wch].size() > num) { n     cont.push_back(H[wch].top()); n     SUM[wch] -= H[wch].top(); n     H[wch].pop(); n   } n } n void upd(long long int wch, long long int num) { n   while (H[wch].size() > num) { n     SUM[wch] -= H[wch].top(); n     H[wch].pop(); n   } n } n void dfs(long long int wch) { n   long long int tot = 0, ned; n   ned = D[wch] - LIM; n   vector<long long int> DEL, ADD; n   upd(wch, ned); n   vis[wch] = true; n   while (ST[wch] < E[wch].size() && D[E[wch][ST[wch]].first] <= LIM) ST[wch]++; n   for (long long int i = ST[wch]; i < E[wch].size(); i++) { n     long long int to = E[wch][i].first, wei = E[wch][i].second; n     if (vis[to]) continue; n     dfs(to); n     if (F[to][0] + wei <= F[to][1]) { n       tot += F[to][0] + wei; n       ned--; n     } else { n       long long int c = F[to][0] + wei - F[to][1]; n       tot += F[to][1]; n       DEL.push_back(c); n       H[wch].push(c); n       SUM[wch] += c; n     } n   } n   upd(wch, max(ned, (long long int)0), ADD); n   F[wch][1] = tot + SUM[wch]; n   upd(wch, max((long long int)0, ned - 1), ADD); n   F[wch][0] = tot + SUM[wch]; n   for (long long int i = 0; i < ADD.size(); i++) n     H[wch].push(ADD[i]), SUM[wch] += ADD[i]; n   for (long long int i = 0; i < DEL.size(); i++) n     H[wch].del(DEL[i]), SUM[wch] -= DEL[i]; n } n int main() { n   long long int N, ans = 0; n   N = read(); n   for (long long int i = 1; i < N; i++) { n     long long int a, b, c; n     a = read(), b = read(), c = read(); n     D[a]++, D[b]++; n     E[a].push_back({b, c}); n     E[b].push_back({a, c}); n     ans += c; n   } n   printf( %I64d , ans); n   for (long long int i = 1; i <= N; i++) { n     sort(E[i].begin(), E[i].end(), cmp); n     VECD[D[i]].push_back(i); n   } n   NEXT[N - 1] = N; n   for (long long int i = N - 2; i >= 1; i--) { n     if (VECD[i + 1].size()) n       NEXT[i] = i + 1; n     else n       NEXT[i] = NEXT[i + 1]; n   } n   for (LIM = 1; LIM < N; LIM++) { n     for (long long int j = 0; j < VECD[LIM].size(); j++) dele(VECD[LIM][j]); n     long long int sum = 0; n     for (long long int j = LIM + 1; j < N; j = NEXT[j]) { n       for (long long int k = 0; k < VECD[j].size(); k++) { n         if (vis[VECD[j][k]]) continue; n         dfs(VECD[j][k]); n         sum += F[VECD[j][k]][1]; n       } n     } n     printf(  %I64d , sum); n     for (long long int j = LIM + 1; j < N; j = NEXT[j]) n       for (long long int k = 0; k < VECD[j].size(); k++) n         vis[VECD[j][k]] = false; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e5 + 3; n struct edge { n   int v, nxt; n } g[N + N]; n int n, head[N], k; n double ans; n inline void Insert(int u, int v) { n   g[++k] = (edge){v, head[u]}; n   head[u] = k; n } n void Dfs(int u, int dep, int fa) { n   int v; n   ans += 1.0 / dep; n   for (int i = head[u]; i; i = g[i].nxt) n     if ((v = g[i].v) != fa) Dfs(v, dep + 1, u); n } n int main() { n   int u, v; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) scanf( %d%d , &u, &v), Insert(u, v), Insert(v, u); n   Dfs(1, 1, 0); n   printf( %.9lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int test; n   cin >> test; n   int n; n   string rakh1, rakh2, rakh, ch, ch_min; n   while (test--) { n     cin >> n; n     cin >> ch; n     ch_min = ch; n     int pos = 1; n     for (int i = 1; i < (n - 1); i++) { n       rakh1 = ch.substr(0, i); n       rakh2 = ch.substr(i, n - 1); n       if ((n % 2 != 0 && i % 2 == 0) || (n % 2 == 0 && i % 2 != 0)) n         reverse(rakh1.begin(), rakh1.end()); n       rakh = rakh2 + rakh1; n       if (ch_min > rakh) { n         pos = i + 1; n         ch_min = rakh; n       } n     } n     reverse(ch.begin(), ch.end()); n     if (ch_min > ch) { n       pos = n; n       ch_min = ch; n     } n     cout << ch_min << endl; n     cout << pos << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } n int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } n void solve() { n   long long int x, y, z; n   cin >> x >> y >> z; n   long long int x1, y1, z1; n   cin >> x1 >> y1 >> z1; n   long long int a1, a2, a3, a4, a5, a6; n   cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6; n   long long int ans = 0; n   if (x > x1) n     ans += a6; n   else if (x < 0) n     ans += a5; n   if (y > y1) n     ans += a2; n   else if (y < 0) n     ans += a1; n   if (z > z1) n     ans += a4; n   else if (z < 0) n     ans += a3; n   cout << ans << endl; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int t; n   t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX; n const long long INFL = LLONG_MAX; n int N, M, ans[200100], n, m; n int main() { n   cin >> N >> M; n   n = m = 0; n   ans[0] = 0; n   n++; n   for (int(i) = 1; (i) <= (N + M - 1); (i)++) { n     if (i & 1) { n       if (ans[i - 1]) { n         if (n < N) { n           ans[i] = 0; n           n++; n         } else { n           ans[i] = 1; n           m++; n         } n       } else { n         if (m < M) { n           ans[i] = 1; n           m++; n         } else { n           ans[i] = 0; n           n++; n         } n       } n     } else { n       if (ans[i - 1]) { n         if (m < M) { n           ans[i] = 1; n           m++; n         } else { n           ans[i] = 0; n           n++; n         } n       } else { n         if (n < N) { n           ans[i] = 0; n           n++; n         } else { n           ans[i] = 1; n           m++; n         } n       } n     } n   } n   int s11 = 0; n   int s12 = 0; n   for (int(i) = 1; (i) <= (N + M - 1); (i)++) { n     if (ans[i - 1] == ans[i]) n       s11++; n     else n       s12++; n   } n   n = m = 0; n   ans[0] = 1; n   m++; n   for (int(i) = 1; (i) <= (N + M - 1); (i)++) { n     if (i & 1) { n       if (ans[i - 1]) { n         if (n < N) { n           ans[i] = 0; n           n++; n         } else { n           ans[i] = 1; n           m++; n         } n       } else { n         if (m < M) { n           ans[i] = 1; n           m++; n         } else { n           ans[i] = 0; n           n++; n         } n       } n     } else { n       if (ans[i - 1]) { n         if (m < M) { n           ans[i] = 1; n           m++; n         } else { n           ans[i] = 0; n           n++; n         } n       } else { n         if (n < N) { n           ans[i] = 0; n           n++; n         } else { n           ans[i] = 1; n           m++; n         } n       } n     } n   } n   int s21 = 0; n   int s22 = 0; n   for (int(i) = 1; (i) <= (N + M - 1); (i)++) { n     if (ans[i - 1] == ans[i]) n       s21++; n     else n       s22++; n   } n   if (s11 < s21) { n     cout << s21 <<     << s22 << endl; n   } else { n     cout << s11 <<     << s12 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, mod; n pair<long long, long long> a[200100]; n long long d[200100]; n long long first(int t, int k) { n   long long res = 1; n   for (int i = 1; i <= k; i++) d[i] = i; n   for (int j = 2; t;) n     if (d[j] % 2) n       j += 2; n     else n       while (d[j] % 2 == 0 && t) { n         d[j] /= 2; n         t--; n       } n   for (int i = 1; i <= k; i++) res = (res * d[i]) % mod; n   return res; n } n int main() { n   cin >> n; n   for (int i = 0; i < 2 * n; ++i) { n     cin >> a[i].first; n     a[i].second = (i % n) + 1; n   } n   sort(a, a + 2 * n); n   cin >> mod; n   long long r = 1; n   for (int i = 0; i < 2 * n; i++) { n     long long k, t = 0; n     for (k = i + 1; k < 2 * n && a[k].first == a[i].first; k++) n       if (a[k].second == a[k - 1].second) t++; n     k--; n     r = (r * first(t, k - i + 1)) % mod; n     i = k; n   } n   cout << r; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 5; n long long n, k, z, a[N]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     cin >> n >> k >> z; n     long long sum = 0; n     for (long long i = 1; i <= n; i++) cin >> a[i]; n     long long ans = 0; n     for (long long j = 0; j <= z; j++) { n       long long s = k - j; n       if (s < j) break; n       long long sum = 0; n       long long mx = 0; n       for (long long i = 1; i <= s - j + 1; i++) n         sum += a[i], mx = max(a[i] + a[i + 1], mx); n       ans = max(ans, sum + mx * j); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char a[60][60]; n bool isRowChecked[60]; n bool isColChecked[60]; n bool doCheck(int r, int c) { n   bool isRowRegard[60]; n   bool isColRegard[60]; n   memset(isRowRegard, false, sizeof(isRowRegard)); n   memset(isColRegard, false, sizeof(isColRegard)); n   std::vector<int> rows; n   std::vector<int> cols; n   for (int rr = r; rr < n; rr++) { n     if (a[rr][c] ==  # ) { n       isRowRegard[rr] = true; n       rows.push_back(rr); n     } n   } n   for (int cc = c; cc < m; cc++) { n     if (a[r][cc] ==  # ) { n       isColRegard[cc] = true; n       cols.push_back(cc); n     } n   } n   for (int i = 0; i < rows.size(); i++) { n     for (int cc = 0; cc < m; cc++) { n       if ((a[rows[i]][cc] ==  . ) && (isColRegard[cc] == true)) return false; n       if ((a[rows[i]][cc] ==  # ) && (isColRegard[cc] == false)) return false; n     } n   } n   for (int j = 0; j < cols.size(); j++) { n     for (int rr = 0; rr < n; rr++) { n       if ((a[rr][cols[j]] ==  . ) && (isRowRegard[rr] == true)) return false; n       if ((a[rr][cols[j]] ==  # ) && (isRowRegard[rr] == false)) return false; n     } n   } n   for (int i = 0; i < rows.size(); i++) isRowChecked[rows[i]] = true; n   for (int j = 0; j < cols.size(); j++) isColChecked[cols[j]] = true; n   return true; n } n int main() { n   scanf( %d%d n , &n, &m); n   for (int i = 0; i < n; i++) scanf( %s n , a[i]); n   memset(isRowChecked, false, sizeof(isRowChecked)); n   memset(isColChecked, false, sizeof(isColChecked)); n   for (int r = 0; r < n; r++) { n     if (isRowChecked[r]) continue; n     for (int c = 0; c < m; c++) { n       if (isColChecked[c]) continue; n       if (a[r][c] ==  # ) { n         if (doCheck(r, c) == false) { n           printf( No n ); n           return 0; n         } n       } n     } n   } n   printf( Yes n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long x, long long y, long long md = 1000000007) { n   long long res = 1; n   x %= md; n   while (y > 0) { n     if (y & 1) res = (res * x) % md; n     x = (x * x) % md; n     y = y >> 1; n   } n   return res % md; n } n signed main() { n   long long n, m; n   cin >> n >> m; n   long long root = sqrt(n) + 1; n   std::vector<long long> factors; n   std::vector<pair<int, int> > v(m); n   for (int i = 1; i < root; i++) { n     if (n % i) continue; n     long long temp = n / i; n     factors.push_back(i); n     if (i != temp && temp != n) factors.push_back(temp); n   } n   std::vector<long long> check(m, 0); n   std::map<pair<long long, long long>, long long> map; n   for (int i = 0; i < m; i++) { n     long long a, b; n     cin >> a >> b; n     a--; n     b--; n     if (b < a) swap(a, b); n     v[i] = make_pair(a, b); n     map[v[i]] = i; n   } n   for (int i = 0; i < factors.size(); i++) { n     for (int j = 0; j < m; j++) check[i] = 0; n     long long x = factors[i]; n     long long first = 1; n     for (int j = 0; j < m; j++) { n       long long a = min((v[j].first + x) % n, (v[j].second + x) % n); n       long long b = max((v[j].first + x) % n, (v[j].second + x) % n); n       std::map<pair<long long, long long>, long long>::iterator it = n           map.find(make_pair(a, b)); n       if (it == map.end()) { n         first = 0; n         break; n       } n     } n     if (first) { n       cout <<  Yes ; n       return 0; n     } n   } n   cout <<  No ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e17; n struct Node { n   int to; n   long long dis; n   int type; n   Node(int a = 0, long long b = 0, int c = 0) { n     to = a; n     dis = b; n     type = c; n   } n   friend bool operator<(Node a, Node b) { n     if (a.dis != b.dis) return a.dis > b.dis; n     return a.type > b.type; n   } n }; n int n, m, k; n int vis[100005], p[100005]; n long long dis[100005]; n vector<Node> v[100005]; n void djs(int x) { n   memset(vis, 0, sizeof(vis)); n   memset(p, 0, sizeof(p)); n   for (int i = 0; i <= n; i++) dis[i] = INF; n   priority_queue<Node> q; n   q.push(Node(x, 0, 0)); n   dis[x] = 0; n   Node u, w; n   while (!q.empty()) { n     u = q.top(); n     q.pop(); n     if (u.dis != dis[u.to] || vis[u.to]) continue; n     vis[u.to] = 1; n     for (int i = 0; i < v[u.to].size(); i++) { n       w = v[u.to][i]; n       if (!vis[w.to]) { n         if (u.dis + w.dis < dis[w.to]) { n           dis[w.to] = u.dis + w.dis; n           q.push(Node(w.to, dis[w.to], 0)); n           p[w.to] = w.type; n         } else if (u.dis + w.dis == dis[w.to] && w.type == 0) { n           p[w.to] = w.type; n         } n       } n     } n   } n } n int main() { n   while (~scanf( %d%d%d , &n, &m, &k)) { n     for (int i = 0; i <= n; i++) { n       while (!v[i].empty()) v[i].clear(); n     } n     int a, b; n     long long c; n     for (int i = 0; i < m; i++) { n       scanf( %d%d%lld , &a, &b, &c); n       v[a].push_back(Node(b, c, 0)); n       v[b].push_back(Node(a, c, 0)); n     } n     for (int i = 0; i < k; i++) { n       scanf( %d%lld , &b, &c); n       v[1].push_back(Node(b, c, 1)); n       v[b].push_back(Node(1, c, 1)); n     } n     djs(1); n     for (int i = 2; i <= n; i++) { n       k -= p[i]; n     } n     printf( %d n , k); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   int arr[m]; n   for (int i = 0; i < m; i++) cin >> arr[i]; n   long long res = arr[0]; n   for (int i = 1; i < m; i++) { n     if (arr[i] - arr[i - 1] < 0) { n       res += (n - arr[i - 1]) + arr[i]; n     } else n       res += (arr[i] - arr[i - 1]); n   } n   cout << res - 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a1, a2, a3, sum = 0, a12, a23, a31; n int main() { n   cin >> a1 >> a2 >> a3; n   sum = a1 + a2 + a3; n   if (sum % 2) { n     cout <<  Impossible ; n     return 0; n   } n   sum /= 2; n   a12 = sum - a3; n   a23 = sum - a1; n   a31 = sum - a2; n   if (a12 < 0 || a23 < 0 || a31 < 0) { n     cout <<  Impossible ; n     return 0; n   } else n     cout << a12 <<     << a23 <<     << a31; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400005; n char a[N]; n int n, k, delta, top, st[N]; n bool vis[N]; n int main() { n   scanf( %d%d , &n, &k), scanf( %s , a + 1); n   delta = (n - k) / 2, top = 0; n   for (int i = 1; i <= n; ++i) { n     if (a[i] ==  ( ) n       st[++top] = i; n     else { n       if (delta) { n         --delta, vis[i] = 1; n         vis[st[top]] = 1; n       } n       --top; n     } n   } n   for (int i = 1; i <= n; ++i) n     if (!vis[i]) printf( %c , a[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dist[600 + 15][600 + 15]; n int start[200 + 15]; n int MAX_ = INT_MAX / 2 - 5; n vector<pair<int, int> > sas[1000]; n int cap[250000 + 15]; n int v, e, n, k; n int pop_w[1000]; n int pop_kr[1000]; n int group[1000]; n int last_checked[1000]; n int dead[1000]; n int res; n int num = 0; n bool b = 0; n int to_add; n bool DFS(int w, int bneck) { n   if (w == n + v + 2) { n     to_add = bneck; n     res += to_add; n     return 1; n   } n   for (int i = last_checked[w] + 1; i < sas[w].size(); i++) { n     int do_ = sas[w][i].first; n     int neck = min(bneck, cap[sas[w][i].second]); n     last_checked[w] = i; n     if (neck && !dead[do_]) n       if (DFS(do_, neck)) { n         cap[sas[w][i].second] -= to_add; n         cap[sas[w][i].second ^ 1] += to_add; n         return 1; n       } n   } n   return 0; n } n int DINIC() { n   for (int i = 0; i <= n + v + 3; i++) { n     group[i] = -1; n     dead[i] = 0; n     last_checked[i] = -1; n   } n   queue<pair<int, int> > q; n   q.push({0, 0}); n   group[0] = 0; n   while (!q.empty()) { n     int top_w = q.front().first; n     int top_g = q.front().second; n     q.pop(); n     for (int i = 0; i < sas[top_w].size(); i++) n       if (group[sas[top_w][i].first] == -1) { n         group[sas[top_w][i].first] = top_g + 1; n         q.push({sas[top_w][i].first, top_g + 1}); n       } n   } n   int ile = 0; n   while (DFS(0, INT_MAX)) ile++; n   return ile; n } n bool CHECK(int t) { n   for (int i = 0; i <= n + v + 3; i++) sas[i].clear(); n   int place; n   num = 0; n   for (int i = 1; i <= n; i++) { n     place = start[i]; n     for (int j = 1; j <= v; j++) { n       if (dist[place][j] <= t) { n         sas[i].push_back({j + n, num}); n         sas[j + n].push_back({i, num + 1}); n         cap[num] = 1; n         cap[num + 1] = 0; n         num += 2; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     sas[0].push_back({i, num}); n     sas[i].push_back({0, num + 1}); n     cap[num] = 1; n     cap[num + 1] = 0; n     num += 2; n   } n   for (int i = n + 1; i <= n + v; i++) { n     sas[i].push_back({n + v + 2, num}); n     sas[n + v + 2].push_back({i, num + 1}); n     cap[num] = 1; n     cap[num + 1] = 0; n     num += 2; n   } n   res = 0; n   while (DINIC()) { n   }; n   if (res >= k) return 1; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> v >> e >> n >> k; n   for (int i = 1; i <= n; i++) cin >> start[i]; n   for (int i = 1; i <= v; i++) n     for (int j = 1; j <= v; j++) dist[i][j] = MAX_; n   for (int i = 1; i <= v; i++) dist[i][i] = 0; n   int h, j, r; n   for (int i = 1; i <= e; i++) { n     cin >> h >> j >> r; n     dist[h][j] = min(dist[h][j], r); n     dist[j][h] = min(dist[j][h], r); n   } n   for (int mid = 1; mid <= v; mid++) n     for (int x = 1; x <= v; x++) n       for (int y = 1; y <= v; y++) n         dist[x][y] = min(dist[x][y], dist[x][mid] + dist[mid][y]); n   if (!CHECK(1731311)) { n     cout << -1; n     return 0; n   } n   int b = 0; n   int e = 1731311; n   while (b <= e) { n     int mid = (b + e) / 2; n     if (CHECK(mid)) n       e = mid - 1; n     else n       b = mid + 1; n   } n   cout << b; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const double eps = 1e-9; n const int maxn = 100000 + 10; n int go[maxn][26], fail[maxn]; n int I[maxn], F[maxn], S[maxn], FIN[maxn]; n int total; n void push(string &s, int index, int freq) { n   int u = 0; n   for (auto c : s) { n     int x = c -  a ; n     if (!go[u][x]) go[u][x] = total++; n     u = go[u][x]; n   } n   I[u] = index, F[u] = freq, S[u] = s.length(), FIN[u] = u; n } n void build() { n   queue<pair<int, int> > q; n   for (int i = 0; i < 26; ++i) { n     if (go[0][i]) q.push({go[0][i], 0}); n   } n   while (!q.empty()) { n     auto x = q.front(); n     q.pop(); n     int u = x.first, f = x.second; n     fail[u] = f; n     if (!FIN[u]) FIN[u] = FIN[f]; n     for (int i = 0; i < 26; ++i) { n       if (go[u][i]) n         q.push({go[u][i], go[f][i]}); n       else n         go[u][i] = go[f][i]; n     } n   } n } n int ANSWER[maxn]; n queue<int> deq[maxn]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   total = 1; n   string s; n   cin >> s; n   int q; n   cin >> q; n   for (int i = 1; i <= q; ++i) { n     int f; n     string t; n     cin >> f >> t; n     push(t, i, f); n   } n   build(); n   memset(ANSWER, 0x3f, sizeof ANSWER); n   for (int i = 0, u = 0; i < (int)s.length(); ++i) { n     u = go[u][s[i] -  a ]; n     int v = FIN[u]; n     while (v) { n       int idx = I[v]; n       deq[idx].push(i); n       if (deq[idx].size() > F[v]) deq[idx].pop(); n       if (deq[idx].size() == F[v]) { n         int beg = deq[idx].front(); n         ANSWER[idx] = min(ANSWER[idx], i - beg + S[v]); n       } n       v = FIN[fail[v]]; n     } n   } n   for (int i = 1; i <= q; ++i) { n     if (ANSWER[i] == oo) n       cout << -1 <<   n ; n     else n       cout << ANSWER[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e18; n const long long mod = 1e9; n long long dp[100005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     long long i; n     long long a[n]; n     set<long long> s; n     long long c = 0; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       s.insert(a[i]); n       if (i > 0) { n         if (a[i] != a[i - 1]) { n           c++; n         } n       } n     } n     long long d = s.size(); n     if (d <= k) { n       cout << 1 << endl; n     } else { n       if (k == 1 && (d != k)) { n         cout <<  -1  << endl; n       } else { n         cout << (((c % (k - 1)) == 0) ? (c / (k - 1)) : (c / (k - 1) + 1)) n              << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 3e5 + 10, M = 2097152 + 10; n long long n, x, ans, ar[N], mark[M][2]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (long long i = 0; i < n; i++) cin >> ar[i]; n   mark[0][1]++; n   for (long long i = 0; i < n; i++) { n     x ^= ar[i]; n     mark[x][i & 1]++; n   } n   for (long long i = 0; i < M; i++) { n     ans += (mark[i][0] * (mark[i][0] - 1)) / 2; n     ans += (mark[i][1] * (mark[i][1] - 1)) / 2; n   } n   cout << ans; 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 a, b, c, d, e, y = 0, x = 0, l = 0, z = 0, k = 0, m = 0; n     cin >> a >> b >> c >> d >> e; n     if (d > e) { n       while (a > 1 && b > 0) { n         y++; n         a = a - 2; n         b = b - 1; n       } n       while (a > 1 && c > 0) { n         x++; n         a = a - 2; n         c = c - 1; n       } n       l = (d * y) + (x * e); n       cout << l << endl; n     } else { n       while (a > 1 && c > 0) { n         z++; n         a = a - 2; n         c = c - 1; n       } n       while (a > 1 && b > 0) { n         k++; n         a = a - 2; n         b = b - 1; n       } n       m = (e * z) + (k * d); n       cout << m << endl; n     } n     y = 0, x = 0, l = 0, z = 0, k = 0, m = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll MOD = 1e9 + 7, N = 1e5 + 10; n const ll MX = 1e8; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   string s; n   cin >> s; n   ll ans = 0; n   for (ll i = 0; i < MX; i += 25) { n     string k = to_string(i); n     if (k.length() != s.length()) continue; n     set<ll> se; n     ll bad = 1; n     42; n     for (ll j = 0; j < k.length(); j++) { n       if (s[j] ==  _ ) continue; n       if (s[j] ==  X ) { n         se.insert(k[j] -  0 ); n         if (se.size() > 1) break; n         continue; n       } n       if (s[j] != k[j]) bad = 0; n     } n     ans += (se.size() <= 1 and bad); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char c1[1005], c2[1005]; n long long f[100005][2], ans, k, l; n bool pd; n int main() { n   scanf( %s , c1); n   scanf( %s , c2); n   scanf( %lld , &k); n   l = strlen(c1); n   f[0][0] = 1; n   for (register long long i = 1; i <= k; i = -~i) { n     f[i][0] = ((l - 1) * f[i - 1][1]) % 1000000007; n     f[i][1] = (((l - 2) * f[i - 1][1]) % 1000000007 + f[i - 1][0]) % 1000000007; n   } n   for (register long long i = 0; i < l; i = -~i) { n     pd = false; n     for (register long long j = 0; j < l; j = -~j) n       if (c1[(i + j) % l] != c2[j]) { n         pd = true; n         break; n       } n     if (!pd) { n       if (i) n         ans = (ans + f[k][1]) % 1000000007; n       else n         ans = (ans + f[k][0]) % 1000000007; n     } n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct LCA { n   int logn; n   vector<int> depth; n   vector<vector<int> > lca; n   vector<vector<int> > *edges; n   LCA(int n, vector<vector<int> > *edges) { n     logn = log(n) / log(2) + 1; n     depth.resize(n + 1, 0); n     lca.resize(n + 1, vector<int>(logn, 0)); n     this->edges = edges; n     build(); n   } n   void dfs(int u, int p) { n     lca[u][0] = p; n     for (int i = 1; i < logn; i++) { n       lca[u][i] = lca[lca[u][i - 1]][i - 1]; n     } n     depth[u] = depth[p] + 1; n     for (auto &v : (*edges)[u]) { n       if (p != v) { n         dfs(v, u); n       } n     } n   } n   int parent(int v, int h) { n     for (int i = logn - 1; i >= 0; i--) { n       if (h & (1 << i)) { n         v = lca[v][i]; n       } n     } n     return v; n   } n   int lessParent(int u, int p) { return parent(u, depth[u] - depth[p] - 1); } n   int get(int u, int v) { n     if (depth[u] > depth[v]) { n       swap(u, v); n     } n     int h = depth[v] - depth[u]; n     v = parent(v, h); n     if (u == v) { n       return u; n     } n     for (int i = logn - 1; i >= 0; i--) { n       if (lca[u][i] != lca[v][i]) { n         u = lca[u][i]; n         v = lca[v][i]; n       } n     } n     return lca[u][0]; n   } n   void build() { dfs(1, 0); } n } * lca; n struct GraphBuilder { n   enum DIRECT { n     UP = 0, n     DOWN, n   }; n   int n; n   int k; n   vector<vector<int> > *e; n   vector<pair<int, int> > edges; n   set<pair<int, int> > cache; n   vector<vector<int> > addedVertices; n   vector<vector<int> > deletedVertices; n   LCA *lca; n   struct Node { n     int id; n     Node *leftChild; n     Node *rightChild; n     Node(int v, Node *l, Node *r) { n       id = v; n       leftChild = l; n       rightChild = r; n     } n   }; n   vector<pair<Node *, Node *> > root; n   GraphBuilder(int m, vector<vector<int> > *e) { n     k = 2 * m - 1; n     n = 2 * m - 1; n     this->e = e; n     lca = new LCA(e->size() - 1, e); n     addedVertices.resize(e->size()); n     deletedVertices.resize(e->size()); n     for (int i = 0; i < m; i++) { n       for (int j = 0; j < 2; j++) { n         int u, v; n         scanf( %d %d , &u, &v); n         int p = lca->get(u, v); n         if (u != p) { n           addedVertices[u].push_back((i << 1) | j); n           deletedVertices[lca->lessParent(u, p)].push_back((i << 1) | j); n         } n         if (v != p) { n           addedVertices[v].push_back((i << 1) | j); n           deletedVertices[lca->lessParent(v, p)].push_back((i << 1) | j); n         } n       } n     } n     root.resize(e->size(), {0, 0}); n     dfs(1, 0); n   } n   void dfs(int u, int p) { n     for (auto &v : (*e)[u]) { n       if (v != p) { n         dfs(v, u); n         root[u].first = merge(root[u].first, root[v].first, DOWN); n         root[u].second = merge(root[u].second, root[v].second, UP); n       } n     } n     for (auto &x : addedVertices[u]) { n       root[u].first = addVertex(0, n, root[u].first, (x ^ 1), DOWN); n       root[u].second = addVertex(0, n, root[u].second, x, UP); n     } n     for (auto &x : deletedVertices[u]) { n       root[u].first = delVertex(0, n, root[u].first, (x ^ 1), DOWN); n       root[u].second = delVertex(0, n, root[u].second, x, UP); n       if (root[u].first) { n         add(x, root[u].first->id); n       } n       if (root[u].second) { n         add(root[u].second->id, (x ^ 1)); n       } n     } n   } n   void add(int u, int v) { edges.push_back({u, v}); } n   void addEdge(Node *p, int direct) { n     if (direct == DOWN) { n       if (p->leftChild) { n         add(p->id, p->leftChild->id); n       } n       if (p->rightChild) { n         add(p->id, p->rightChild->id); n       } n     } else { n       if (p->leftChild) { n         add(p->leftChild->id, p->id); n       } n       if (p->rightChild) { n         add(p->rightChild->id, p->id); n       } n     } n   } n   Node *addVertex(int l, int r, Node *p, int v, int direct) { n     if (!p) { n       p = new Node(0, 0, 0); n     } n     if (l == r) { n       return new Node(v, 0, 0); n     } else { n       int mid = (l + r) >> 1; n       Node *newNode = new Node(++k, p->leftChild, p->rightChild); n       if (v <= mid) { n         newNode->leftChild = addVertex(l, mid, p->leftChild, v, direct); n       } else { n         newNode->rightChild = addVertex(mid + 1, r, p->rightChild, v, direct); n       } n       addEdge(newNode, direct); n       return newNode; n     } n   } n   Node *delVertex(int l, int r, Node *p, int v, int direct) { n     if (l == r) { n       return 0; n     } else { n       int mid = (l + r) >> 1; n       Node *newNode = new Node(++k, p->leftChild, p->rightChild); n       if (v <= mid) { n         newNode->leftChild = delVertex(l, mid, p->leftChild, v, direct); n       } else { n         newNode->rightChild = delVertex(mid + 1, r, p->rightChild, v, direct); n       } n       if (!newNode->leftChild && !newNode->rightChild) { n         return 0; n       } n       addEdge(newNode, direct); n       return newNode; n     } n   } n   Node *merge(Node *p1, Node *p2, int direct) { n     if (!p1 || !p2) { n       return p1 ? p1 : p2; n     } else { n       Node *left = merge(p1->leftChild, p2->leftChild, direct); n       Node *right = merge(p1->rightChild, p2->rightChild, direct); n       Node *newNode = new Node(++k, left, right); n       addEdge(newNode, direct); n       return newNode; n     } n   } n }; n struct SAT { n   int n; n   vector<int> st; n   vector<int> mark; n   vector<int> group; n   vector<vector<int> > edges; n   vector<vector<int> > revEdges; n   SAT(int n, vector<pair<int, int> > &e) { n     this->n = n + 1; n     mark.resize(n + 1, 0); n     group.resize(n + 1, 0); n     edges.resize(n + 1); n     revEdges.resize(n + 1); n     for (auto &p : e) { n       addEdge(p.first, p.second); n     } n   } n   void addEdge(int u, int v) { n     edges[u].push_back(v); n     revEdges[v].push_back(u); n   } n   void dfs1(int u) { n     mark[u] = 1; n     for (auto &v : edges[u]) { n       if (mark[v] == 0) { n         dfs1(v); n       } n     } n     st.push_back(u); n   } n   void dfs2(int u, int k) { n     group[u] = k; n     for (auto &v : revEdges[u]) { n       if (group[v] == 0) { n         dfs2(v, k); n       } n     } n   } n   void solve() { n     for (int i = 0; i < n; i++) { n       if (mark[i] == 0) { n         dfs1(i); n       } n     } n     int k = 0; n     for (int i = st.size() - 1; i >= 0; i--) { n       int u = st[i]; n       if (group[u] == 0) { n         k++; n         dfs2(u, k); n       } n     } n   } n   void answer(int m) { n     for (int i = 0; i < 2 * m; i += 2) { n       if (group[i] == group[i | 1]) { n         printf( NO ); n         return; n       } n     } n     printf( YES n ); n     for (int i = 0; i < 2 * m; i += 2) { n       printf( %d n , (group[i] > group[i | 1]) ? 1 : 2); n     } n   } n }; n int main() { n   int n; n   scanf( %d , &n); n   vector<vector<int> > edges(n + 1); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     edges[u].push_back(v); n     edges[v].push_back(u); n   } n   int m; n   scanf( %d , &m); n   GraphBuilder builder(m, &edges); n   SAT solver(builder.k, builder.edges); n   solver.solve(); n   solver.answer(m); n } n


#include <bits/stdc++.h> n using namespace std; n const int mxn = 257; n string rec[mxn][3]; n bool been[mxn][3]; n inline int G(string s) { n   int t = 0; n   for (int i = 0; i < s.size(); ++i) t = t * 2 + s[i] -  0 ; n   return t; n } n priority_queue<pair<int, int> > pq; n bool changed; n string Min(string a, string b) { n   if (a.size() != b.size()) { n     if (a.size() < b.size()) n       return a; n     else n       return b; n   } n   return min(a, b); n } n inline void upd(string& a, string b) { n   if (a == b) return; n   if (Min(a, b) == b) { n     changed = 1; n     a = b; n   } n } n inline void prep() { n   int n = 256; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < 3; ++j) n       rec[i][j] =  zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz ; n   rec[G( 00001111 )][0] =  x ; n   rec[G( 00110011 )][0] =  y ; n   rec[G( 01010101 )][0] =  z ; n   for (changed = 1; changed;) { n     changed = 0; n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < 2; ++j) upd(rec[i][j + 1], rec[i][j]); n     for (int i = 0; i < n; ++i) upd(rec[i ^ 255][0],  !  + rec[i][0]); n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < n; ++j) n         upd(rec[i & j][1], rec[i][1] +  &  + rec[j][0]), n             upd(rec[i | j][2], rec[i][2] +  |  + rec[j][1]); n     for (int i = 0; i < n; ++i) upd(rec[i][0],  (  + rec[i][2] +  ) ); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   int T = 1; n   cin >> T; n   prep(); n   for (; T--;) { n     string s; n     cin >> s; n     int t = G(s); n     cout << Min(Min(rec[t][0], rec[t][1]), rec[t][2]) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 4e6 + 5; n const int inf = 0x3f3f3f3f; n int main() { n   int n; n   scanf( %d , &n); n   char a; n   getchar(); n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %c , &a); n     if (a ==  - ) n       ans--; n     else n       ans++; n     ans = max(0, ans); n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s = 0; n   cin >> n; n   int a[n]; n   for (int x = 0; x < n; ++x) { n     cin >> a[x]; n     s += a[x] * (x + 1); n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[200005]; n int n, k; n int main() { n   scanf( %d%d , &n, &k); n   scanf( %s , s); n   if (n == 1) { n     if (k == 0) n       printf( %c n , s[0]); n     else n       printf( 0 n ); n   } else { n     if (k == 0) n       printf( %s n , s); n     else { n       if (s[0] !=  1 ) k--; n       s[0] =  1 ; n       int t = 1; n       while (t < n && k) { n         if (s[t] !=  0 ) { n           s[t] =  0 ; n           k--; n         } n         t++; n       } n       printf( %s , s); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n const long long LINF = (1LL << 62); n const int INF = 1 << 30; n const int NS = 100010; n const int MS = 19; n const int MOD = 1000000007; n const double PI = acos(-1.0); n int n, m, q, h[NS]; n pair<int, int> s[NS]; n int L[NS], R[NS]; n int solve() {} n int main() { n   while (~scanf( %d %d , &n, &q)) { n     m = n - 1; n     for (int i = 1; i <= n; i++) { n       scanf( %d , &h[i]); n       if (i > 1) { n         h[i - 1] = abs(h[i - 1] - h[i]); n         s[i - 1] = make_pair(h[i - 1], i - 1); n       } n     } n     sort(s + 1, s + m + 1); n     set<int> idSet; n     idSet.insert(0); n     idSet.insert(n); n     for (int i = m; i >= 1; i--) { n       int pos = s[i].second; n       idSet.insert(pos); n       __typeof(idSet.begin()) it = idSet.find(pos); n       L[pos] = *(--it); n       it++, it++; n       R[pos] = *(it); n     } n     int x, y; n     for (int qi = 0; qi < q; qi++) { n       scanf( %d %d , &x, &y); n       long long ans = 0; n       for (int i = x; i < y; i++) { n         int lb = i - max(L[i], x - 1); n         int rb = min(R[i], y) - i; n         ans += 1LL * h[i] * lb * rb; n       } n       printf( %I64d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 2 * 1e5 + 10; n int a[M]; n int main() { n   long long s, n, p1, c, pos1, pos2, p2, i, ans = 1, d, x, j; n   scanf( %I64d , &n); n   for (i = 0; i < n; i++) scanf( %I64d , &a[i]); n   if (a[0] != -1) { n     p1 = a[0]; n     pos1 = 0; n     c = 1; n   } else n     c = 0; n   s = 0; n   ans = 1; n   for (i = 1; i < n; i++) { n     if (i == 10) i = 10; n     if (c == 0) { n       if (a[i] != -1) { n         c = 1; n         p1 = a[i]; n         pos1 = i; n       } n       continue; n     } n     if (c == 1) { n       if (a[i] != -1) { n         if ((a[i] - p1) % (i - pos1) != 0) { n           ans++; n           s = i; n           c = 1; n           p1 = a[i]; n           pos1 = i; n         } else { n           c = 2; n           p2 = a[i]; n           pos2 = i; n           d = (p2 - p1) / (pos2 - pos1); n           x = p1 + d * (s - pos1); n           if (x <= 0) { n             ans++; n             c = 1; n             p1 = a[i]; n             pos1 = i; n             s = i; n           } n         } n       } n       continue; n     } n     d = (p2 - p1) / (pos2 - pos1); n     x = p1 + d * (i - pos1); n     if (a[i] == -1) { n       if (x <= 0) { n         ans++; n         c = 0; n         s = i; n       } n       continue; n     } else { n       if (x != a[i]) { n         ans++; n         s = i; n         c = 1; n         p1 = a[i]; n         pos1 = i; n       } n     } n   } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (a == 0) { n     return b; n   } else { n     return gcd(b % a, a); n   } n } n int main() { n   int l_a, r_a, t_a; n   int l_b, r_b, t_b; n   int l_x, r_x, t_x; n   cin >> l_a >> r_a >> t_a; n   cin >> l_b >> r_b >> t_b; n   if (r_b - l_b < r_a - l_a) { n     l_x = l_b, r_x = r_b, t_x = t_b; n     l_b = l_a, r_b = r_a, t_b = t_a; n     l_a = l_x, r_a = r_x, t_a = t_x; n   } n   int g = gcd(t_a, t_b); n   int c = l_b - l_a; n   int c_1, c_2; n   if (l_b - l_a >= 0) { n     c_1 = c % g; n     c_2 = (-(c % g - g)) % g; n   } else { n     c_1 = g - (-c) % g; n     c_2 = (-(c_1 - g)) % g; n   } n   int answer = r_a - l_a + 1 - c_1; n   answer = max(answer, min(r_b - l_b + 1 - c_2, r_a - l_a + 1)); n   cout << max(answer, 0); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 10000; n const long long M = 60; n vector<long long> v; n long long n, first, t, a[N], second, cn, p; n void val(long long first) { n   long long second, z; n   second = first; n   first = upper_bound((v).begin(), (v).end(), first) - v.begin() - 1; n   ; n   second = (second - v[first] + a[first]) % v[first]; n   z = second + v[first]; n   while (1) { n     second = z - v[first]; n     p = (second - a[first] >= 0) ? (v[first] + (second - a[first])) n                                  : (v[first] * 2 - (a[first] - second)); n     cout << p <<    ; n     if (p == 1) break; n     first--; n     z >>= 1; n   } n } n int main() { n   cin >> n; n   for (long long i = (long long)0; i <= (long long)M; i++) n     v.push_back((1LL << i)); n   for (long long i = (long long)1; i <= (long long)n; i++) { n     cin >> t; n     if (t <= 2) { n       cin >> first >> second; n       first = upper_bound((v).begin(), (v).end(), first) - v.begin() - 1; n       ; n       for (long long j = (long long)first; j <= (long long)M; j++) { n         a[j] += (second % v[j]) * (1LL << (j - first)); n         if (a[j] < 0) a[j] %= v[j], a[j] += v[j]; n         a[j] %= v[j]; n         if (t == 1) break; n       } n     } else { n       cn++; n       cin >> first; n       val(first); n       cout <<    n            <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( Ofast,no-stack-protector ) n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<   n ; n   err(++it, args...); n } n function<void(void)> ____ = []() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n }; n template <typename T> n vector<T> &operator<<(vector<T> &__container, T x) { n   __container.push_back(x); n   return __container; n } n template <typename T> n ostream &operator<<(ostream &out, vector<T> &__container) { n   for (T _ : __container) out << _ <<    ; n   return out; n } n void sci() {} n template <typename... Args> n void sci(int &x, Args &...args) { n   scanf( %d , &x); n   sci(args...); n } n void scl() {} n template <typename... Args> n void scl(long long int &x, Args &...args) { n   scanf( %lld , &x); n   scl(args...); n } n const int MAXN = 2e5 + 7; n double ret; n int rt; n int n, w[MAXN], root, sz[MAXN], maxsz[MAXN]; n double derivative[MAXN]; n bool vis[MAXN]; n vector<pair<int, int> > G[MAXN]; n void findroot(int u, int par, int tot) { n   sz[u] = 1; n   maxsz[u] = 0; n   for (auto &e : G[u]) { n     int v = e.first, c = e.second; n     if (vis[v] or v == par) continue; n     findroot(v, u, tot); n     sz[u] += sz[v]; n     ((maxsz[u]) = (maxsz[u]) > (sz[v]) ? (maxsz[u]) : (sz[v])); n   } n   ((maxsz[u]) = (maxsz[u]) > (tot - sz[u]) ? (maxsz[u]) : (tot - sz[u])); n   if (maxsz[u] < maxsz[root]) root = u; n } n double cost; n void dfs(int u, int par, int wt) { n   cost += pow(wt, 1.5) * w[u]; n   derivative[u] = w[u] * 1.5 * pow(wt, 0.5); n   for (auto &e : G[u]) { n     int v = e.first, c = e.second; n     if (v == par) continue; n     dfs(v, u, wt + c); n     derivative[u] += derivative[v]; n   } n } n void divide(int u) { n   if (vis[u]) return; n   vis[u] = true; n   cost = 0; n   double sd = 0; n   for (auto &e : G[u]) { n     int v = e.first, c = e.second; n     dfs(v, u, c); n     sd += derivative[v]; n   } n   if (cost < ret) ret = cost, rt = u; n   for (auto &e : G[u]) { n     int v = e.first; n     if (sd - 2 * derivative[v] >= 0) continue; n     root = 0; n     findroot(v, u, sz[v]); n     divide(root); n     return; n   } n } n void solve() { n   sci(n); n   for (int i = 1; i <= n; i++) sci(w[i]); n   for (int i = 1; i < n; i++) { n     int u, v, c; n     sci(u, v, c); n     G[u] << pair<int, int>(v, c); n     G[v] << pair<int, int>(u, c); n   } n   ret = LLONG_MAX; n   maxsz[root = 0] = 0x3f3f3f3f; n   findroot(1, 0, n); n   divide(root); n   cout << rt <<     << fixed << setprecision(10) << ret <<   n ; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353, maxn = 5e5 + 79; n void upd(int& a, const int& b) { a = (a + b) % mod; } n int mul(const int& a, const int& b) { return (a * 1ll * b) % (long long)mod; } n vector<vector<int> > dp(maxn, vector<int>(2, 0)); n vector<vector<int> > g(maxn); n vector<int> pw2(maxn, 1); n int sum = 0, n; n int dfs(int u, int p = -1) { n   dp[u][0] = 1; n   int e = 0; n   for (int v : g[u]) { n     if (v == p) continue; n     e += 1 + dfs(v, u); n     vector<int> dp2(2, 0); n     upd(dp2[1], mul(dp[u][0], dp[v][0])); n     upd(sum, mul(2, mul(mul(dp[u][0], dp[v][0]), pw2[n - 1 - e]))); n     upd(dp2[0], mul(dp[u][0], dp[v][1])); n     upd(dp2[1], mul(dp[u][1], dp[v][0])); n     upd(dp2[1], mul(dp[u][1], dp[v][1])); n     upd(dp2[0], mul(dp[u][0], dp[v][0])); n     upd(dp2[0], mul(dp[u][0], dp[v][1])); n     upd(dp2[1], mul(dp[u][1], dp[v][0])); n     upd(dp2[1], mul(dp[u][1], dp[v][1])); n     dp[u] = dp2; n   } n   return e; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   for (int i = 1; i < maxn; i++) pw2[i] = mul(pw2[i - 1], 2); n   cin >> n; n   for (int i = 0, u, v; i < n - 1; i++) { n     cin >> u >> v; n     g[--u].push_back(--v), g[v].push_back(u); n   } n   dfs(0); n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sum[1000000 + 10][27]; n char c1[1000000 + 10], c2[1000000 + 10]; n long long n, m; n long long len1, len2; n long long gcd(long long a, long long b) { n   long long t = a; n   while (b) { n     a = b; n     b = t % b; n     t = a; n   } n   return a; n } n int main() { n   cin >> n >> m; n   scanf( %s%s , c1, c2); n   len1 = strlen(c1), len2 = strlen(c2); n   long long t = gcd(len1, len2); n   long long k = n / (len2 / t); n   long long res = 0; n   for (int i = 0; i < len2; ++i) sum[i % t][c2[i] -  a ]++; n   for (int i = 0; i < len1; ++i) n     for (int j = 0; j < 26; ++j) n       if (j != c1[i] -  a ) res += sum[i % t][j]; n   res *= k; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string x; n   cin >> x; n   int c1 = 0, c0 = 0; n   bool f = 0; n   for (int i = 0; i < x.size(); i++) { n     if (x[i] ==  0 ) { n       c0++; n     } else if (x[i] ==  1 ) { n       c1++; n     } n     if (c0 < 7 && x[i] ==  1 ) { n       c0 = 0; n     } n     if (c1 < 7 && x[i] ==  0 ) { n       c1 = 0; n     } n   } n   if (c1 >= 7 || c0 >= 7) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y; n   while (scanf( %d %d , &x, &y) != EOF) { n     while (x >= 0 && y >= 0) { n       if (x >= 2 && y >= 2) { n         x -= 2; n         y -= 2; n       } else if (x == 1 && y >= 12) { n         x -= 1; n         y -= 12; n       } else if (x == 0 && y >= 22) { n         y -= 22; n       } else { n         puts( Hanako ); n         break; n       } n       if (y >= 22) { n         y -= 22; n       } else if (y >= 12 && x >= 1) { n         x -= 1; n         y -= 12; n       } else if (x >= 2 && y >= 2) { n         x -= 2; n         y -= 2; n       } else { n         puts( Ciel ); n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10, LEN = 5e3 + 10, S = 51, INF = 1e18; n long long f[N], l[N], r[N], sum[N]; n long long lq[S], rq[S], sq[S], mq[S]; n long long a[LEN], sx[LEN], mx[LEN]; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   memset(mq, -0x3f, sizeof mq); n   for (int i = 1, s; i <= n; i++) { n     scanf( %d , &s); n     for (int j = 1; j <= s; j++) scanf( %lld , &a[j]); n     for (int j = 1; j <= s; j++) sx[j] = sx[j - 1] + a[j]; n     for (int j = 1; j <= s; j++) { n       mx[j] = max(mx[j - 1] + a[j], a[j]); n       mq[i] = max(mq[i], mx[j]); n     } n     lq[i] = a[1]; n     for (int j = 2; j <= s; j++) lq[i] = max(lq[i], sx[j]); n     rq[i] = a[n]; n     for (int j = s - 2; j >= 0; j--) rq[i] = max(rq[i], sx[s] - sx[j]); n     sq[i] = sx[s]; n   } n   long long res = -INF; n   for (int i = 1, x; i <= m; i++) { n     scanf( %d , &x); n     l[i] = lq[x]; n     r[i] = rq[x]; n     sum[i] = sum[i - 1] + sq[x]; n     res = max(res, mq[x]); n   } n   f[1] = l[1]; n   long long maxv = r[1] - sum[1], ans = f[1]; n   for (int i = 2; i <= m; i++) { n     f[i] = sum[i - 1] + l[i] + maxv; n     maxv = max(maxv, r[i] - sum[i]); n     ans = max(ans, f[i]); n   } n   printf( %lld n , max(ans, res)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b; n   cin >> a >> b; n   long long ships = 0; n   while (a != 0 && b != 0) { n     if (b > a) { n       ships += b / a; n       b = b % a; n     } else { n       ships += a / b; n       a = a % b; n     } n   } n   cout << ships << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int getsum(string st) { n   int rest = 0; n   for (int i = 0; i < st.size(); i++) { n     rest += st[i] -  0 ; n   } n   return rest; n } n string streverse(string st) { n   for (int i = 0; i < st.size() / 2; i++) { n     char tmp = st[i]; n     st[i] = st[st.size() - 1 - i]; n     st[st.size() - 1 - i] = tmp; n   } n   return st; n } n string getGreater(int a, int num, string st) { n   int increase = a - num; n   for (int i = st.size() - 1; i >= 0; i--) { n     if (st[i] -  0  < 9) { n       int increment = min(9 - (st[i] -  0 ), increase); n       st[i] += increment; n       increase -= increment; n     } n     if (increase == 0) return st; n   } n   string rest =   ; n   for (int i = 0; i < a / 9; i++) rest = rest +  9 ; n   if (a % 9 > 0) { n     rest = rest + (char)( 0  + a % 9); n   } n   return streverse(rest); n } n string getLess(int a, int num, string st) { n   int decrease = num - a; n   decrease++; n   int sum = 0; n   for (int i = st.size() - 1; i >= 1; i--) { n     sum += st[i] -  0 ; n     if (sum >= decrease) { n       if (st[i - 1] -  0  < 9) { n         st[i - 1]++; n         sum = sum - decrease; n         for (int j = i; j < st.size(); j++) st[j] =  0 ; n         int indx = st.size() - 1; n         while (sum > 0) { n           if (sum > 9) { n             st[indx] += 9; n             sum -= 9; n           } else { n             st[indx] += sum; n             sum = 0; n           } n           indx--; n         } n         return st; n       } n     } n   } n   st =  1  + st; n   for (int i = 1; i < st.size(); i++) { n     st[i] =  0 ; n   } n   a--; n   int k; n   for (k = 0; k < a / 9; k++) { n     st[st.size() - 1 - k] =  9 ; n   } n   if (a % 9) { n     for (int i = st.size() - 1; i >= 0; i--) { n       if (st[i] ==  0 ) { n         st[i] = (char)( 0  + a % 9); n         break; n       } n     } n   } n   return st; n } n string getnum(int a, string st) { n   int num = getsum(st); n   if (a > num) { n     return getGreater(a, num, st); n   } n   return getLess(a, num, st); n } n int main() { n   getnum(13,  1093 ); n   int n; n   cin >> n; n   string pre =   ; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     string rest = getnum(a, pre); n     cout << rest << endl; n     pre = rest; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e9 + 10, N = 2e5 + 10, mod = 998244353, lg = 20, n                 sq = 450; n long long t, n, k, first[N], ans; n inline long long power(long long x, long long y) { n   long long ret = 1; n   x %= mod; n   while (y) { n     if (y & 1) ret = (ret * x) % mod; n     x = (x * x) % mod; n     y >>= 1; n   } n   return ret; n } n inline long long C(long long x, long long y) { n   long long ret = first[y]; n   ret = (ret * power(first[x], mod - 2)) % mod; n   ret = (ret * power(first[y - x], mod - 2)) % mod; n   return ret; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   first[0] = 1; n   for (int i = 1; i < N; i++) first[i] = (first[i - 1] * i) % mod; n   cin >> n >> k; n   if (k >= n) return cout << 0, 0; n   for (int i = 0; i <= n - k; i += 2) n     ans = (ans + ((power(n - k - i, n) * C(n - k - i, n - k)) % mod)) % mod; n   for (int i = 1; i <= n - k; i += 2) n     ans = n         (mod + ans - ((power(n - k - i, n) * C(n - k - i, n - k)) % mod)) % mod; n   ans = (ans * C(n - k, n)) % mod; n   if (k) ans = (ans * 2) % mod; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long Deci(int arr[], int base, int n) { n   long long power = 1; n   long long num = 0; n   for (int i = n - 1; i >= 0; i--) { n     num += arr[i] * power; n     power = power * base; n   } n   return num; n } n int main() { n   int n, m, x, y; n   cin >> n >> x; n   int arr[n + 3]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   cin >> m >> y; n   int brr[m + 3]; n   for (int i = 0; i < m; i++) { n     cin >> brr[i]; n   } n   long long X = Deci(arr, x, n); n   long long Y = Deci(brr, y, m); n   if (X < Y) n     cout <<  < n ; n   else if (X > Y) n     cout <<  > n ; n   else n     cout <<  = n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long x, long long y, long long m) { n   if (y == 0) return 1; n   long long p = power(x, y / 2, m) % m; n   p = (p * p) % m; n   return (y % 2 == 0) ? p : (x * p) % m; n } n long long gcd(long long a, long long b) { n   if (a > b) swap(a, b); n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long modInverse(long long a, long long m) { return power(a, m - 2, m); } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   srand(time(NULL)); n   ; n   long long t; n   cin >> t; n   while (t--) { n     long long x; n     cin >> x; n     string s; n     cin >> s; n     long long c = 1, ans = s.size(); n     while (c <= x) { n       long long k = s[c - 1] -  1 ; n       if (s.size() < x) { n         string a; n         a = s.substr(c, s.size()); n         ans += a.size() * k; n         while (k--) s += a; n         c++; n         ans = ans % 1000000007; n       } else { n         ans += (ans - c) * k; n         ans = ans % 1000000007; n         c++; n       } n     } n     cout << (ans + 1000000007) % 1000000007 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> v; n int a[26] = {0}; n int main() { n   int n, i, j, co = 0, F = -1; n   string s, s2; n   cin >> s; n   for (i = 0; i < s.size(); i++) { n     a[s[i] -  a ] = 1; n   } n   cin >> s2 >> n; n   while (n--) { n     cin >> s; n     v.push_back(s); n   } n   for (i = 0; i < v.size(); i++) { n     co = 0; n     if (v[i].size() < s2.size() - 1) { n       cout <<  NO  << endl; n       continue; n     } n     for (j = 0; j < s2.size(); j++) { n       if (s2[j] ==  * ) { n         F = j; n         break; n       } n       if ((s2[j] != v[i][j] && s2[j] !=  ? ) || n           (s2[j] ==  ?  && a[v[i][j] -  a ] == 0)) { n         cout <<  NO  << endl; n         co = 1; n         break; n       } n     } n     if (co != 1) { n       int K = v[i].size() - 1; n       for (j = s2.size() - 1; j >= 0; j--) { n         if (s2[j] ==  * ) break; n         if ((s2[j] != v[i][K] && s2[j] !=  ? ) || n             (s2[j] ==  ?  && a[v[i][K] -  a ] == 0)) { n           cout <<  NO  << endl; n           co = 1; n           break; n         } n         K--; n       } n     } n     if (co != 1 && v[i].size() >= s2.size() && F != -1) { n       int p = v[i].size() - (s2.size() - 1); n       for (j = F; p != 0; j++) { n         if (a[v[i][j] -  a ] == 1) { n           cout <<  NO  << endl; n           co = 1; n           break; n         } n         p--; n       } n     } n     if (F == -1 && v[i].size() > s2.size() && co != 1) { n       cout <<  NO  << endl; n       co = 1; n     } n     if (co == 0) cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, ans = 0, res = 0; n   cin >> n >> m; n   vector<pair<long long, long long>> v; n   set<pair<long long, long long>> s; n   for (int i = 0; i < n; i++) { n     long long p, q; n     cin >> p >> q; n     v.push_back(make_pair(q, p)); n   } n   sort(v.begin(), v.end(), greater<pair<long long, long long>>()); n   for (int i = 0; i < n; i++) { n     res += v[i].second; n     s.insert(make_pair(v[i].second, i)); n     while (s.size() > m) { n       auto it = s.begin(); n       res -= it->first; n       s.erase(it); n     } n     ans = max(ans, res * v[i].first); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long double E = 1e-9; n char ccc; n bool _minus = false; n inline void read(int &n) { n   n = 0; n   _minus = false; n   while (true) { n     ccc = getchar(); n     if (ccc ==     || ccc ==   n ) break; n     if (ccc ==  - ) { n       _minus = true; n       continue; n     } n     n = n * 10 + ccc -  0 ; n   } n   if (_minus) n *= -1; n } n char wwww[12]; n int kkkk; n inline void write(int x) { n   kkkk = 0; n   if (!x) ++kkkk, wwww[kkkk] =  0 ; n   while (x) { n     ++kkkk; n     wwww[kkkk] = char(x % 10 +  0 ); n     x /= 10; n   } n   for (int i = kkkk; i >= 1; --i) putchar(wwww[i]); n   putchar(   ); n } n template <typename T> n inline T sqr(T t) { n   return t * t; n } n const int MAX = 1e5; n vector<int> v1[MAX], v2[MAX]; n bool ok1[MAX], ok2[MAX]; n int ar[MAX]; n void dfs1(int pos) { n   ok1[pos] = true; n   for (int i = 0; i < (int)v1[pos].size(); i++) { n     if (!ok1[v1[pos][i]]) { n       dfs1(v1[pos][i]); n     } n   } n } n void dfs2(int pos) { n   ok2[pos] = true; n   if (ar[pos] == 1) return; n   for (int i = 0; i < (int)v2[pos].size(); i++) { n     if (!ok2[v2[pos][i]]) { n       dfs2(v2[pos][i]); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   srand(time(NULL)); n   cout.precision(15); n   cout << fixed; n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> ar[i]; n   while (m--) { n     int a, b; n     cin >> a >> b; n     a--, b--; n     v1[a].push_back(b); n     v2[b].push_back(a); n   } n   for (int i = 0; i < n; i++) { n     if (ar[i] == 1 && !ok1[i]) { n       dfs1(i); n     } else if (ar[i] == 2 && !ok2[i]) { n       dfs2(i); n     } n   } n   for (int i = 0; i < n; i++) cout << (ok1[i] && ok2[i] ? 1 : 0) <<   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 t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     map<int, int> m; n     bool f = true; n     vector<int> v; n     while (n--) { n       int a; n       cin >> a; n       v.push_back(a); n       m[a] += 1; n       if (m[a] > 1) f = false; n     } n     if (!f || !m[1]) { n       cout << -1 << endl; n       continue; n     } n     vector<int> o; n     set<int> s; n     for (int a : v) { n       o.push_back(a); n       s.insert(a); n       for (int i = a + 1; i < 201; i++) n         if (!m[i] && s.find(i) == s.end()) { n           o.push_back(i); n           s.insert(i); n           m[i] += 1; n           break; n         } n     } n     bool r = true; n     int p; n     for (int a : s) { n       if (f) p = a, f = false; n       if (a - p > 1) { n         r = false; n         break; n       } n       p = a; n     } n     f = false; n     if (r) n       for (int a : o) { n         if (f) cout <<    ; n         cout << a; n         f = true; n       } n     else n       cout << -1; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   int x, y; n } v[300005]; n inline bool cmp(data d1, data d2) { n   if (d1.x != d2.x) return d1.x < d2.x; n   return d1.y < d2.y; n } n inline bool cmp2(data d1, data d2) { return d1.y < d2.y; } n int n; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &v[i].x); n     v[i].y = i; n   } n   sort(v + 1, v + n + 1, cmp); n   int minv = 0; n   for (int i = 1; i <= n; i++) { n     if (minv < v[i].x) { n       minv = v[i].x + 1; n     } else { n       v[i].x = minv; n       minv++; n     } n   } n   sort(v + 1, v + n + 1, cmp2); n   for (int i = 1; i <= n; i++) printf( %d  , v[i].x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using VI = vector<int>; n using PII = pair<int, int>; n using ll = long long; n const int M = 1e9 + 7; n const int N = 2010; n VI d{1110111, 10010,   1011101, 1011011, 111010, n      1101011, 1101111, 1010010, 1111111, 1111011}; n int GetDiff(int x, int y) { n   return __builtin_popcount(x) - __builtin_popcount(y); n } n int Convert(int x) { n   int s = 0, k = 1; n   while (x) { n     if (x % 10) s += k; n     x /= 10; n     k <<= 1; n   } n   return s; n } n int main() { n   for (auto& v : d) v = Convert(v); n   int n, k; n   scanf( %d %d , &n, &k); n   vector<VI> f(n + 1, VI(k + 1, -1)); n   VI a(n); n   vector<vector<PII>> g(n); n   for (int i = 0; i < n; ++i) { n     int t; n     scanf( %d , &t); n     a[i] = t = Convert(t); n     for (int j = 9; j >= 0; --j) { n       if ((d[j] & t) == t) g[i].push_back({j, GetDiff(d[j], t)}); n     } n   } n   for (auto& v : g[n - 1]) n     f[n - 1][v.second] = max(f[n - 1][v.second], v.first); n   for (int i = n - 2; i >= 0; --i) { n     for (auto& v : g[i]) { n       for (int j = 0; j < k + 1 - v.second; ++j) { n         if (f[i + 1][j] != -1) n           f[i][j + v.second] = max(f[i][j + v.second], v.first); n       } n     } n   } n   if (f[0][k] == -1) n     puts( -1 ); n   else { n     for (int i = 0; i < n; ++i) { n       printf( %d , f[i][k]); n       k -= GetDiff(d[f[i][k]], a[i]); n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, s1, s2, t1, t2, l1, l2; n vector<int> adj[3333]; n int dist[3333][3333]; n void bfs(int index) { n   queue<int> q; n   q.push(index); n   dist[index][index] = 0; n   while (!q.empty()) { n     int cur = q.front(); n     q.pop(); n     for (int to : adj[cur]) { n       if (dist[index][to] != -1) continue; n       dist[index][to] = dist[index][cur] + 1; n       q.push(to); n     } n   } n } n int main() { n   while (scanf( %d %d , &n, &m) == 2) { n     memset(dist, -1, sizeof dist); n     for (int i = 0; i < n; i++) adj[i].clear(); n     for (int i = 0; i < m; i++) { n       int a, b; n       scanf( %d %d , &a, &b); n       adj[--a].push_back(--b); n       adj[b].push_back(a); n     } n     scanf( %d %d %d , &s1, &t1, &l1); n     --s1, --t1; n     scanf( %d %d %d , &s2, &t2, &l2); n     --s2, --t2; n     for (int i = 0; i < n; i++) bfs(i); n     if (dist[s1][t1] > l1 || dist[s2][t2] > l2) { n       puts( -1 ); n       continue; n     } n     int ans = dist[s1][t1] + dist[s2][t2]; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) { n         { n           int p1 = dist[s1][i] + dist[i][j] + dist[j][t1]; n           int p2 = dist[s2][i] + dist[i][j] + dist[j][t2]; n           if (p1 <= l1 && p2 <= l2) ans = min(ans, p1 + p2 - dist[i][j]); n         } n         { n           int p1 = dist[t1][i] + dist[i][j] + dist[j][s1]; n           int p2 = dist[s2][i] + dist[i][j] + dist[j][t2]; n           if (p1 <= l1 && p2 <= l2) ans = min(ans, p1 + p2 - dist[i][j]); n         } n       } n     ans = m - ans; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const double INF = 1e20; n const int N = 102; n const int M = 1010; n const int K = 10; n int n; n double C, T; n const double Y = 1. / 0.9; n pair<int, int> a[N]; n double dp[N][M]; n void read() { n   scanf( %d , &n); n   scanf( %lf%lf , &C, &T); n   for (int i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second); n   sort(a, a + n); n } n int solve() { n   read(); n   dp[0][0] = 0; n   for (int it = 1; it <= n; it++) { n     for (int j = 0; j <= it * K; j++) dp[it][j] = INF; n     for (int i = it - 1; i >= 0; i--) n       for (int j = 0; j <= i * K; j++) { n         if (dp[i][j] >= INF / 2) continue; n         dp[i + 1][j + a[it - 1].second] = min(dp[i + 1][j + a[it - 1].second], n                                               dp[i][j] * Y + a[it - 1].first); n       } n   } n   for (int x = n * K; x >= 0; x--) n     for (int p = 0; p <= n; p++) { n       if (p * K < x || dp[p][x] >= INF / 2) continue; n       double X = dp[p][x] * Y; n       double t = X; n       if (C * X >= 1) t = 2 * sqrt(X / C) - 1. / C; n       t += p * 10; n       if (t <= T) return x; n     } n   throw; n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) printf( %d n , solve()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-10; n const long long N = 2e5 + 10; n ; n long long n, p[N], t[N], a[N], b[N], Ma[N], Mi[N], T; n long long check(double m) { n   double M = 0.0; n   for (long long i = 1, j = 1; i <= n; i++) { n     while (j <= n && p[b[j]] < p[b[i]]) n       M = max(M, (1.0 - m * Mi[b[j]] / T) * p[b[j]]), j++; n     if ((1.0 - m * Ma[b[i]] / T) * p[b[i]] < M) return 0; n   } n   return 1; n } n signed main() { n   scanf( %lld n , &n); n   for (long long i = 1; i <= n; i++) scanf( %lld , &p[i]), a[i] = i; n   for (long long i = 1; i <= n; i++) scanf( %lld , &t[i]), b[i] = i; n   sort(a + 1, a + n + 1, n        [&](long long i, long long j) { return p[i] * t[j] > p[j] * t[i]; }); n   sort(b + 1, b + n + 1, [&](long long i, long long j) { return p[i] < p[j]; }); n   for (long long i = 1, j, s; i <= n; i = j) { n     for (j = i + 1, s = 0; j <= n; j++) n       if (p[a[i]] * t[a[j]] != p[a[j]] * t[a[i]]) break; n     for (long long k = i; k < j; k++) s += t[a[k]]; n     for (long long k = i; k < j; k++) Mi[a[k]] = T + t[a[k]], Ma[a[k]] = T + s; n     T += s; n   } n   double l = 0, r = 1; n   while (r - l > eps) { n     double mid = (l + r) / 2.0; n     if (!check(mid)) n       r = mid; n     else n       l = mid; n   } n   printf( %.10f n , l); n   return 0; n } n