#include <bits/stdc++.h> n using namespace std; n int const nmax = 100000; n int const domain = 1000000; n struct Person { n   int x; n   int v; n   bool operator<(Person other) const { return (x < other.x); } n }; n int n, nl, nr; n int s; n Person pl[1 + nmax], pr[1 + nmax]; n bitset<1 + domain> okl, okr; n double timetodest(int distp, int vp, int distray) { n   double timep = 1.0L * distp / vp; n   double timehit = 1.0L * (distray - distp) / (s - vp); n   if (timep <= timehit) n     return timep; n   else { n     double disthit = distp - timehit * vp; n     return timehit + (disthit / (vp + s)); n   } n } n void checktime(double target, Person *p, int np, bitset<1 + domain> *ok) { n   for (int i = 1; i <= np; i++) { n     if (p[i].x <= p[i].v * target) { n       for (int j = 1; j < domain; j++) (*ok)[j] = 1; n       return; n     } n   } n   int i = 1; n   for (int j = 1; j < domain; j++) { n     bool flag = false; n     while (flag == false && i <= np && p[i].x <= j) { n       if (timetodest(p[i].x, p[i].v, j) <= target) n         flag = true; n       else n         i++; n     } n     (*ok)[j] = flag; n   } n } n int main() { n   cin >> n >> s; n   for (int i = 0; i < n; i++) { n     int x, v, dir; n     cin >> x >> v >> dir; n     if (dir == 1) { n       nl++; n       pl[nl] = {x, v}; n     } else { n       nr++; n       pr[nr] = {domain - x, v}; n     } n   } n   sort(pl + 1, pl + nl + 1); n   sort(pr + 1, pr + nr + 1); n   double t1 = 0, t2 = domain, tmid; n   double deltat = 1; n   double stop = 0.0000000001L; n   while (stop < deltat) { n     tmid = (t1 + t2) / 2; n     deltat = (tmid - t1) / 2; n     checktime(tmid, pl, nl, &okl); n     checktime(tmid, pr, nr, &okr); n     int flag = 0, j = 1; n     while (flag == 0 && j < domain) { n       if (okl[j] == 1 && okr[domain - j] == 1) flag = 1; n       j++; n     } n     if (flag == 1) n       t2 = tmid; n     else n       t1 = tmid; n   } n   cout << fixed << setprecision(12) << tmid <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, a[N], maxi[4 * N]; n pair<int, int> p[N]; n vector<int> v[3]; n bool cmp(pair<int, int> p1, pair<int, int> p2) { n   if (p1.first == p2.first) n     return p1.second > p2.second; n   else n     return p1.first < p2.first; n } n void merge(int at) { maxi[at] = max(maxi[2 * at], maxi[2 * at + 1]); } n void build(int at, int L, int R) { n   if (L == R) { n     maxi[at] = 0; n     return; n   } n   int mid = (L + R) / 2; n   build(2 * at, L, mid); n   build(2 * at + 1, mid + 1, R); n   merge(at); n } n void update(int at, int L, int R, int pos, int val) { n   if (L == R) { n     maxi[at] = val; n     return; n   } n   int mid = (L + R) / 2; n   if (pos <= mid) n     update(2 * at, L, mid, pos, val); n   else n     update(2 * at + 1, mid + 1, R, pos, val); n   merge(at); n } n int query(int at, int L, int R, int l, int r) { n   if (r < L || l > R) return 0; n   if (l <= L && r >= R) return maxi[at]; n   int mid = (L + R) / 2; n   int x = query(2 * at, L, mid, l, r); n   int y = query(2 * at + 1, mid + 1, R, l, r); n   return max(x, y); n } n int main() { n   int n, n1, n2, n3, q, x; n   scanf( %d %d %d , &n1, &n2, &n3); n   ; n   n = n1 + n2 + n3; n   for (int j = 0; j < n1; j++) { n     scanf( %d , &x); n     v[0].push_back(x); n   } n   for (int j = 0; j < n2; j++) { n     scanf( %d , &x); n     v[1].push_back(x); n   } n   for (int j = 0; j < n3; j++) { n     scanf( %d , &x); n     v[2].push_back(x); n   } n   for (int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end()); n   int cnt = 0; n   for (int i = 0; i < 3; i++) { n     for (int u : v[i]) { n       p[cnt] = make_pair(u, cnt); n       cnt++; n     } n   } n   sort(p, p + n, cmp); n   build(1, 0, n - 1); n   int maxi = 0; n   for (int i = 0; i < n; i++) { n     int tmp = query(1, 0, n - 1, 0, p[i].second - 1); n     maxi = max(maxi, tmp + 1); n     update(1, 0, n - 1, p[i].second, tmp + 1); n   } n   printf( %d n , n - maxi); n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-9, PI = acos(-1.); n const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; n const int N = 1e5 + 5; n int n, x, v; n long long sm; n int main() { n   scanf( %d%d , &n, &x); n   for (int i = 0; i < n; ++i) scanf( %d , &v), sm += v; n   printf( %s n , sm + n - 1 == x ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x[100], n, a, b, i, dem = 0; n   scanf( %d , &n); n   for (i = 0; i < n - 1; i++) scanf( %d , &x[i]); n   scanf( %d , &a); n   scanf( %d , &b); n   for (i = a - 1; i != b - 1; i++) dem = dem + x[i]; n   printf( %d , dem); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int SIZE = 500 + 10; n int data[SIZE]; n map<int, int> all_nums; n int n; n bool used[SIZE * SIZE]; n int gcd(int a, int b) { n   if (a % b == 0) return b; n   return gcd(b, a % b); n } n void make_data() { n   srand(time(0)); n   int n = 5; n   int data[SIZE]; n   for (int i = 0; i < n; i++) data[i] = (rand() % (10)); n   FILE* output = fopen( input.txt ,  w ); n   fprintf(output,  %d n , n); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) fprintf(output,  %d  , gcd(data[i], data[j])); n   fclose(output); n } n int main() { n   cin >> n; n   int val; n   for (int i = 0; i < n * n; i++) { n     cin >> val; n     all_nums[val]++; n   } n   auto iter = all_nums.rbegin(); n   data[n - 1] = iter->first; n   iter->second--; n   int curtop = n - 1; n   for (int i = 0; i < n - 1; i++) { n     while (all_nums.rbegin()->second == 0) { n       all_nums.erase(all_nums.find(all_nums.rbegin()->first)); n     } n     data[curtop - 1] = all_nums.rbegin()->first; n     all_nums.rbegin()->second--; n     for (int k = curtop; k < n; k++) n       all_nums[gcd(data[curtop - 1], data[k])] -= 2; n     curtop--; n   } n   for (int i = 0; i < n; i++) cout << data[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; n const int N = 1e6 + 10; n const int mod = 1e9 + 7; n const double pi = acos(-1); n const double eps = 1e-8; n const long long INF = 2e10; n template <class T> n void _print(T arg) { n   cout << arg <<    ; n } n template <class... Args> n void log(Args... args) { n   int arr[] = {(_print(args), 0)...}; n   cout << endl; n } n long long a[N], b[N]; n int n, m, k; n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> k; n   for (int i = 0; i <= n; ++i) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   for (int i = 0; i < n; ++i) { n     a[i + 1] += a[i] / 2; n     a[i] %= 2; n   } n   int pos; n   for (int i = 0; i <= n; ++i) { n     if (a[i]) { n       pos = i; n       break; n     } n   } n   int res = 0; n   long long tmp = 0; n   for (int i = n; i >= 0; --i) { n     tmp = tmp * 2 + a[i]; n     if (abs(tmp) > INF) break; n     if (i <= pos) { n       long long x = abs(tmp - b[i]); n       if (i == n & x == 0) continue; n       res += (x <= k); n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename X> n ostream& operator<<(ostream& x, const vector<X>& v) { n   for (long long i = 0; i < v.size(); ++i) x << v[i] <<    ; n   return x; n } n template <typename X> n ostream& operator<<(ostream& x, const set<X>& v) { n   for (auto it : v) x << it <<    ; n   return x; n } n template <typename X, typename Y> n ostream& operator<<(ostream& x, const pair<X, Y>& v) { n   x << v.ff <<     << v.ss; n   return x; n } n template <typename T, typename S> n ostream& operator<<(ostream& os, const unordered_map<T, S>& v) { n   for (auto it : v) os << it.first <<  =>  << it.second << endl; n   return os; n } n struct pair_hash { n   inline std::size_t operator()( n       const std::pair<long long, long long>& v) const { n     return v.first * 31 + v.second; n   } n }; n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC targett( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n const int N = 100005; n ; n int dis[N]; n vector<pair<int, int>> dp[N]; n bool vis[N]; n int dpp[N]; n int pth; n int n; n int xx; n int f(int i, int j) { n   if (i == n - 1) { n     return 0; n   } n   if (dis[i] + j != pth) { n     return -1000000007; n   } n   if (dpp[i] != -1) { n     return dpp[i]; n   } n   dpp[i] = 0; n   for (pair<int, int> k : dp[i]) { n     dpp[i] = max(dpp[i], k.second + f(k.first, j + 1)); n   } n   return dpp[i]; n } n set<pair<pair<int, int>, int>> ans; n void recover(int i, int j) { n   if (i == n - 1) { n     return; n   } n   int mx = -1; n   int vr = -1; n   int ff; n   for (pair<int, int> k : dp[i]) { n     if (mx <= f(k.first, j + 1) + k.second) { n       mx = f(k.first, j + 1) + k.second; n       vr = k.first; n       ff = k.second ^ 1; n     } n   } n   if (ff == 1) n     ans.insert({{min(i, vr), max(i, vr)}, ff}); n   else n     ans.erase({{min(i, vr), max(i, vr)}, ff}); n   recover(vr, j + 1); n } n int main() { n   int m; n   cin >> n >> m; n   int on = 0; n   pair<pair<int, int>, int> ed[m]; n   for (long long i = 0; i < m; i++) { n     int x, y, z; n     cin >> x >> y >> z; n     --x; n     --y; n     ed[i] = {{x, y}, z}; n     on += z; n     dp[x].push_back({y, z}); n     dp[y].push_back({x, z}); n   } n   queue<pair<int, int>> q; n   q.push({n - 1, 0}); n   vis[n - 1] = true; n   while (q.size()) { n     int dd = q.front().second; n     int curr = q.front().first; n     q.pop(); n     dis[curr] = dd; n     for (pair<int, int> i : dp[curr]) { n       if (!vis[i.first]) { n         vis[i.first] = true; n         q.push({i.first, dd + 1}); n       } n     } n   } n   pth = dis[0]; n   memset(dpp, -1, sizeof dpp); n   int xxp = f(0, 0); n   cout << on + pth - 2 * dpp[0] << endl; n   for (long long i = 0; i < m; i++) { n     if (ed[i].second == 1) { n       ans.insert({{min(ed[i].first.first, ed[i].first.second), n                    max(ed[i].first.first, ed[i].first.second)}, n                   ed[i].second ^ 1}); n     } n   } n   recover(0, 0); n   for (auto it = ans.begin(); it != ans.end(); ++it) { n     cout << (*it).first.first + 1 <<     << (*it).first.second + 1 <<     n          << (*it).second << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int d[200060], cost[200060]; n long long int m, tank; n vector<pair<int, int>> temp; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int src; n   cin >> src >> tank >> m; n   d[0] = 0; n   cost[0] = 0; n   d[m + 1] = src; n   cost[m + 1] = 0; n   for (int i = 0; i < m; i++) { n     pair<int, int> t; n     cin >> t.first >> t.second; n     temp.push_back(t); n   } n   sort(temp.begin(), temp.end()); n   for (int i = 0; i < m; i++) { n     d[i + 1] = temp[i].first; n     cost[i + 1] = temp[i].second; n   } n   int current = 0; n   long long int fuel = tank; n   int toAdd = 1; n   auto srt = [](int i, int j) { n     pair<int, int> a = make_pair(cost[i], d[i]); n     pair<int, int> b = make_pair(cost[j], d[j]); n     return a < b; n   }; n   multiset<int, function<bool(int, int)>> stations(srt); n   long long int ans = 0; n   while (true) { n     while (!stations.empty() && d[*stations.begin()] < d[current]) { n       stations.erase(stations.begin()); n     } n     while (toAdd <= m + 1 && (d[current] + tank) >= d[toAdd]) { n       stations.insert(toAdd); n       toAdd++; n     } n     auto it = stations.begin(); n     if (it == stations.end()) { n       cout << -1; n       return 0; n     } n     int minPricy = *it; n     if (cost[minPricy] >= cost[current]) { n       long long int fuelNeeded = d[minPricy] - d[current]; n       ans += max(0ll, (tank - fuel) * cost[current]); n       fuel = tank - fuelNeeded; n       current = minPricy; n       stations.erase(it); n     } else { n       int check = current + 1; n       while (cost[current] <= cost[check]) { n         check++; n       } n       int minPricy = check; n       long long int fuelNeeded = d[minPricy] - d[current]; n       ans += max(0ll, (fuelNeeded - fuel) * cost[current]); n       fuel = max(fuel - fuelNeeded, 0ll); n       current = minPricy; n     } n     if (current == m + 1) break; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int solveA(vector<int> a, vector<int> b) { n   int n = (int)((a).size()); n   vector<int> m(n); n   for (int i = (0); i <= ((n)-1); i++) m[b[i]] = i; n   for (int i = (0); i <= ((n)-1); i++) a[i] = m[a[i]]; n   b[0] = a[0]; n   for (int i = (1); i <= ((n - 1)); i++) b[i] = max(b[i - 1], a[i]); n   int res = 0; n   for (int i = (0); i <= ((n)-1); i++) res += (a[i] != b[i]); n   return res; n } n int solveB(vector<int> a, vector<int> b) { n   int res = 0, n = (int)((a).size()); n   vector<int> used(n + 1, false); n   while (a.size() || b.size()) { n     if (a.size() && b.size() && a.back() == b.back()) n       b.pop_back(), a.pop_back(); n     else if (b.size() && used[b.back()]) n       b.pop_back(); n     else if (a.size() && a.back() != b.back()) { n       used[a.back()] = true; n       a.pop_back(); n       res++; n     } n   } n   return res; n } n int solve(vector<int> a, vector<int> b) { n   int n = (int)((a).size()); n   vector<int> m(n); n   for (int i = (0); i <= ((n)-1); i++) m[b[i]] = i; n   for (int i = (0); i <= ((n)-1); i++) a[i] = m[a[i]]; n   for (int i = (0); i <= ((n - 1) - 1); i++) n     if (a[i] > a[i + 1]) { n       return n - 1 - i; n     } n   return 0; n } n int main() { n   int n = 100; n   scanf( %d , &n); n   vector<int> a(n), b(n); n   for (int i = (0); i <= ((n)-1); i++) scanf( %d , &a[i]), a[i]--; n   for (int i = (0); i <= ((n)-1); i++) scanf( %d , &b[i]), b[i]--; n   cout << solve(a, b) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 10, inf = 1e18; n struct SegTree { n   long long l[N << 2], r[N << 2]; n   long long mn[N << 2], tag[N << 2]; n   inline void push_up(long long i) { mn[i] = min(mn[i << 1], mn[i << 1 | 1]); } n   inline void push_down(long long i) { n     mn[i << 1] += tag[i]; n     mn[i << 1 | 1] += tag[i]; n     tag[i << 1] += tag[i]; n     tag[i << 1 | 1] += tag[i]; n     tag[i] = 0; n   } n   void build(long long i, long long x, long long y) { n     l[i] = x; n     r[i] = y; n     if (x == y) return; n     build(i << 1, x, (x + y) >> 1); n     build(i << 1 | 1, ((x + y) >> 1) + 1, y); n   } n   void update(long long i, long long x, long long y, long long k) { n     if (l[i] >= x && r[i] <= y) { n       mn[i] += k; n       tag[i] += k; n       return; n     } n     push_down(i); n     if (r[i << 1] >= x) update(i << 1, x, y, k); n     if (l[i << 1 | 1] <= y) update(i << 1 | 1, x, y, k); n     push_up(i); n   } n   long long query(long long i, long long x, long long y) { n     if (l[i] >= x && r[i] <= y) return mn[i]; n     push_down(i); n     long long ans = inf; n     if (r[i << 1] >= x) ans = min(ans, query(i << 1, x, y)); n     if (l[i << 1 | 1] <= y) ans = min(ans, query(i << 1 | 1, x, y)); n     push_up(i); n     return ans; n   } n }; n SegTree dis1, dis2; n long long n, m, cnt, u[N << 2], v[N << 2], c[N << 2], f[N], dfn[N], siz[N], n     dep[N]; n vector<pair<long long, long long> > edge[N]; n long long dfs(long long u, long long sum, long long depth) { n   cnt++; n   dep[u] = depth; n   dfn[u] = cnt; n   siz[u] = 1; n   dis1.update(1, dfn[u], dfn[u], sum); n   dis2.update(1, dfn[u], dfn[u], sum + f[u]); n   for (long long i = 0; i < edge[u].size(); i++) n     siz[u] += dfs(edge[u][i].first, sum + edge[u][i].second, dep[u] + 1); n   return siz[u]; n } n int main() { n   scanf( %lld%lld , &n, &m); n   dis1.build(1, 1, n); n   dis2.build(1, 1, n); n   for (long long i = 1; i <= n - 1; i++) { n     scanf( %lld%lld%lld , &u[i], &v[i], &c[i]); n     edge[u[i]].push_back(make_pair(v[i], c[i])); n   } n   for (long long i = n; i <= 2 * n - 2; i++) { n     scanf( %lld%lld%lld , &u[i], &v[i], &c[i]); n     f[u[i]] = c[i]; n   } n   dfs(1ll, 0ll, 1ll); n   while (m--) { n     long long op, x, y; n     scanf( %lld%lld%lld , &op, &x, &y); n     if (op == 1) { n       if (x <= n - 1) { n         dis1.update(1ll, dfn[v[x]], dfn[v[x]] + siz[v[x]] - 1, y - c[x]); n         dis2.update(1ll, dfn[v[x]], dfn[v[x]] + siz[v[x]] - 1, y - c[x]); n         c[x] = y; n       } else { n         dis2.update(1ll, dfn[u[x]], dfn[u[x]], y - f[u[x]]); n         f[u[x]] = y; n       } n     } else { n       if (dfn[x] <= dfn[y] && dfn[x] + siz[x] - 1 >= dfn[y]) { n         printf( %lld n , dis1.query(1ll, dfn[y], dfn[y]) - n                              dis1.query(1ll, dfn[x], dfn[x])); n       } else { n         printf( %lld n , dis2.query(1ll, dfn[x], dfn[x] + siz[x] - 1) - n                              dis1.query(1ll, dfn[x], dfn[x]) + n                              dis1.query(1ll, dfn[y], dfn[y])); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ii = pair<int, int>; n const int MOD(1e9 + 7); n const int MAXN(1e5 + 11); n int n, first, z, a, l; n int main() { n   scanf( %d%d%d%d%d , &n, &first, &z, &a, &l); n   int ans = 0; n   for (int ptr = 0; ptr < n;) { n     if (ptr) n       ptr += max(0, first - l); n     else n       ptr += first; n     first += a; n     first = min(first, z); n     ++ans; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-7; n const int MX = 1111 * 1111 * 2; n int n, m; n const double pi = acos(-1.0); n int len, res[MX], mx; n struct Complex { n   double r, i; n   Complex(double r = 0, double i = 0) : r(r), i(i){}; n   Complex operator+(const Complex &rhs) { n     return Complex(r + rhs.r, i + rhs.i); n   } n   Complex operator-(const Complex &rhs) { n     return Complex(r - rhs.r, i - rhs.i); n   } n   Complex operator*(const Complex &rhs) { n     return Complex(r * rhs.r - i * rhs.i, i * rhs.r + r * rhs.i); n   } n } va[MX], vb[MX], ve[MX], vc[MX]; n void rader(Complex F[], int len) { n   int j = len >> 1; n   for (int i = 1; i < len - 1; ++i) { n     if (i < j) swap(F[i], F[j]); n     int k = len >> 1; n     while (j >= k) { n       j -= k; n       k >>= 1; n     } n     if (j < k) j += k; n   } n } n void FFT(Complex F[], int len, int t) { n   rader(F, len); n   for (int h = 2; h <= len; h <<= 1) { n     Complex wn(cos(-t * 2 * pi / h), sin(-t * 2 * pi / h)); n     for (int j = 0; j < len; j += h) { n       Complex E(1, 0); n       for (int k = j; k < j + h / 2; ++k) { n         Complex u = F[k]; n         Complex v = E * F[k + h / 2]; n         F[k] = u + v; n         F[k + h / 2] = u - v; n         E = E * wn; n       } n     } n   } n   if (t == -1) n     for (int i = 0; i < len; ++i) F[i].r /= len; n } n void Conv(Complex a[], Complex b[], int len) { n   FFT(a, len, 1); n   FFT(b, len, 1); n   for (int i = 0; i < len; ++i) a[i] = a[i] * b[i]; n   FFT(a, len, -1); n   for (int i = 0; i < len; ++i) a[i].r = (a[i].r > 0.5); n } n void init(Complex *a, Complex *b) { n   for (int i = 0; i < len; i++) a[i].i = 0, a[i].r = b[i].r; n } n void _init(Complex *a) { n   for (int i = 0; i < len; i++) a[i].i = 0; n } n void Out(int a) { n   if (a > 9) Out(a / 10); n   putchar(a % 10 +  0 ); n } n void print(Complex *a) { n   for (int i = 0; i < len; i++) printf( %d  , (int)(a[i].r + 0.5)); n   cout << endl; n } n void gao() { n   len = 1; n   while (len < mx) len <<= 1; n   ve[0].r = 1; n   while (m) { n     if (m & 1) { n       init(vc, va); n       Conv(ve, va, len); n       _init(ve); n       init(va, vc); n       if (m == 1) break; n     } n     init(vb, va); n     Conv(va, vb, len); n     _init(va); n     m >>= 1; n   } n   for (int i = 0; i < len; ++i) res[i] = ve[i].r + 0.5; n   for (int i = 0; i < len; i++) n     if (res[i]) Out(i), putchar(   ); n   cout << endl; n } n int main() { n   while (cin >> n >> m) { n     int maxn = 0; n     for (int i = 0; i < n; i++) { n       int x; n       scanf( %d , &x); n       maxn = max(maxn, x); n       va[x].r = 1; n       va[x].i = 0; n     } n     mx = maxn * m + 1; n     gao(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10009; n const int D = 5001; n int n; n vector<vector<pair<int, int>>> hs(N, vector<pair<int, int>>()); n vector<vector<pair<int, int>>> vs(N, vector<pair<int, int>>()); n vector<vector<int>> ds(N, vector<int>()); n class FenwickTree { n  public: n   FenwickTree(int n) { arr.assign(n + 1, 0); } n   int rsq(int a) { n     int res = 0; n     for (; a; a -= LSOne(a)) { n       res += arr[a]; n     } n     return res; n   } n   int rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); } n   void update(int a, int c) { n     for (; a < arr.size(); a += LSOne(a)) { n       arr[a] += c; n     } n   } n  n  private: n   vector<int> arr; n   int LSOne(int a) { return ((a) & (-a)); } n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     int x1, y1, x2, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     x1 += D; n     x2 += D; n     y1 += D; n     y2 += D; n     if (x1 == x2) { n       vs[x1].emplace_back(min(y1, y2), max(y1, y2)); n     } else { n       hs[y1].emplace_back(min(x1, x2), max(x1, x2)); n     } n   } n   long long res = 0; n   for (int i = 1; i < N; ++i) n     for (auto h : hs[i]) { n       int l = h.first; n       int r = h.second; n       for (int j = 0; j < N; ++j) ds[j].clear(); n       FenwickTree ft(N); n       for (int x = l; x <= r; ++x) n         for (auto v : vs[x]) { n           if (v.first <= i && v.second > i) { n             ft.update(x, 1); n             ds[v.second].push_back(x); n           } n         } n       for (int y = i + 1; y < N; y++) { n         for (auto h : hs[y]) { n           int s = ft.rsq(h.first, h.second); n           res += (s * (s - 1)) / 2ll; n         } n         for (int v : ds[y]) { n           ft.update(v, -1); n         } n       } n     } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n stack<int> s; n int a[(int)(1e+6) * 5]; n bool b[(int)(1e+6) * 5]; n int main() { n   ios_base::sync_with_stdio(0); n   int n, i, t, x; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   cin >> t; n   while (t > 0) cin >> x, b[x] = 1, t--; n   for (i = n; i > 0; i--) { n     x = -1; n     if (!s.empty()) x = s.top(); n     if (x != -1 && !b[i] && a[i] == a[x]) n       a[x] *= -1, s.pop(); n     else n       s.push(i); n   } n   if (!s.empty()) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES n ; n   for (i = 1; i <= n; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 0x3f3f3f3f; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long test; n   test = 1; n   while (test--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     int misha = max((3 * a) / 10.0, a - (a * c) / 250.0); n     int vasya = max((3 * b) / 10.0, b - (b * d) / 250.0); n     if (misha == vasya) { n       cout <<  Tie  << endl; n     } else if (misha > vasya) { n       cout <<  Misha  << endl; n     } else if (misha < vasya) { n       cout <<  Vasya  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const double pi = acos(-1.0); n const int inf = 2147483647; n int n, w; n int a[1005]; n bool first; n int MIN; n void output(int x) { n   if (first) n     first = false; n   else n     printf(   ); n   if (x == MIN) n     x = 0; n   else if (x == 0) n     x = MIN; n   printf( %d , x + 1); n } n int main() { n   scanf( %d%d , &n, &w); n   int total = 0; n   MIN = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     total += a[i]; n     if (a[MIN] > a[i]) MIN = i; n   } n   first = true; n   if (w >= a[MIN] && w <= total) { n     printf( Yes n ); n     swap(a[0], a[MIN]); n     output(0); n     total = total - w; n     for (int i = 1; i < n && total; i++) { n       while (total && a[i]) { n         total--; n         a[i]--; n         output(i); n         output(i); n       } n     } n     output(0); n     a[0]--; n     for (int i = 0; i < n; i++) { n       while (a[i]) { n         a[i]--; n         output(i); n         output(i); n       } n     } n     printf(  n ); n   } else if (w > total || n == 1) { n     printf( No n ); n   } else if (w <= 1) { n     printf( No n ); n   } else { n     printf( Yes n ); n     swap(a[0], a[MIN]); n     output(0); n     total = total - w; n     for (int i = 1; i < n && total; i++) { n       int limit = (i == 1 ? 1 : 0); n       while (total && a[i] > limit) { n         total--; n         a[i]--; n         output(i); n         output(i); n       } n     } n     output(0); n     a[0]--; n     output(1); n     while (a[0] >= w - 1) { n       output(0); n       output(0); n       a[0]--; n     } n     output(1); n     while (a[0]) { n       output(0); n       output(0); n       a[0]--; n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n], b[n], c = 0, d = 0, e = 0, i; n   for (i = 0; i < n; i++) { n     cin >> a[i] >> b[i]; n     if (a[i] > b[i]) n       c++; n     else if (b[i] > a[i]) n       d++; n     else n       e++; n   } n   if (c > d) n     cout <<  Mishka  << endl; n   else if (d > c) n     cout <<  Chris  << endl; n   else n     cout <<  Friendship is magic!^^  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MM = 600005; n const long long MOD = 1000000007; n double a[MM], sum[MM]; n char s[MM]; n int main() { n   sum[0] = a[0] = 0; n   for (int i = 1; i < MM; i++) { n     a[i] = a[i - 1] + 1.0 / i; n     sum[i] = sum[i - 1] + a[i]; n   } n   scanf( %s , s + 1); n   int L = strlen(s + 1); n   double ans = 0; n   for (int j = 1; j <= L; j++) { n     if (s[j] ==  I  || s[j] ==  E  || s[j] ==  A  || s[j] ==  O  || n         s[j] ==  U  || s[j] ==  Y ) n       ans += (sum[L] - sum[L - j]) - (sum[j - 1]); n   } n   printf( %.9lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p, out[1010]; n struct node { n   int v, c; n }; n vector<node> e[1010]; n int t1[1010], t2[1010], r[1010], k; n void dfs(int i, int fa, int mi) { n   if (e[i].size() == 0) { n     t1[k] = fa; n     t2[k] = i; n     r[k] = mi; n     k++; n     return; n   } n   mi = min(e[i][0].c, mi); n   dfs(e[i][0].v, fa, mi); n } n int main() { n   while (cin >> n >> p) { n     int u; n     node a; n     memset(out, 0, sizeof(out)); n     for (int i = 0; i <= n; i++) e[i].clear(); n     for (int i = 0; i < p; i++) { n       scanf( %d%d%d , &u, &a.v, &a.c); n       e[u].push_back(a); n       out[u]++; n       out[a.v]--; n     } n     k = 0; n     for (int i = 1; i <= n; i++) n       if (out[i] == 1) dfs(i, i, 99999999); n     printf( %d n , k); n     for (int i = 0; i < k; i++) printf( %d %d %d n , t1[i], t2[i], r[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int p = 0, q = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) ch ==  -  ? q = -1 : 0, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) p = p * 10 + ch -  0 , ch = getchar(); n   return p * q; n } n long long readll() { n   long long p = 0, q = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) ch ==  -  ? q = -1 : 0, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) p = p * 10 + ch -  0 , ch = getchar(); n   return p * q; n } n bool cmp(int x, int y) { return x > y; } n int power(long long a, int b) { n   long long c = 1; n   while (b) { n     if (b & 1) c = c * a % 998244353; n     a = a * a % 998244353; n     b >>= 1; n   } n   return c; n } n int n, a[300005], pre[300005]; n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   sort(a + 1, a + 1 + n, cmp); n   for (int i = 1; i <= n; i++) pre[i] = (pre[i - 1] + a[i]) % 998244353; n   for (int k = 1; k <= n; k++) { n     int low = (n - k) / k; n     long long ans = 0; n     for (int j = 1; j <= low; j++) n       ans = (ans + 1ll * (pre[(j + 1) * k] - pre[j * k]) * j) % 998244353; n     ans = (ans + 1ll * (pre[n] - pre[low * k + k]) * (low + 1)) % 998244353; n     printf( %I64d%s , n            (ans * power(n, 998244353 - 2) % 998244353 + 998244353) % 998244353, n            k == n ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5; n int n, m, head[N], cnt, dep[N], fa[N], pid[N]; n long long c[N], val[N]; n bool vis[N], use[N]; n struct edge { n   int to, nxt, id; n } e[N << 1]; n void finish() { n   cout <<  YES n ; n   for (int i = 1; i <= m; ++i) cout << val[i] <<   n ; n   exit(0); n } n void dfs(int u) { n   vis[u] = 1; n   for (int i = head[u]; i; i = e[i].nxt) n     if (!vis[e[i].to]) { n       fa[e[i].to] = u; n       dep[e[i].to] = dep[u] + 1; n       pid[e[i].to] = e[i].id; n       use[e[i].id] = 1; n       dfs(e[i].to); n     } n   if (u != 1) { n     val[pid[u]] = c[u]; n     c[fa[u]] -= c[u]; n     c[u] = 0; n   } n } n void dfs2(int u) { n   for (int i = head[u]; i; i = e[i].nxt) n     if (!use[e[i].id] && (dep[e[i].to] - dep[u]) % 2 == 0) { n       assert(dep[e[i].to] > dep[u]); n       int fh = dep[u] % 2; n       long long dlt = c[1] / 2; n       if (fh == 1) dlt *= -1; n       val[e[i].id] = dlt; n       c[u] -= dlt, c[e[i].to] -= dlt; n       for (int v = e[i].to; v != 1; v = fa[v]) { n         val[pid[v]] += c[v]; n         c[fa[v]] -= c[v]; n         c[v] = 0; n       } n       assert(!c[1]); n       finish(); n     } n   for (int i = head[u]; i; i = e[i].nxt) n     if (use[e[i].id] && dep[e[i].to] > dep[u]) dfs2(e[i].to); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> c[i]; n   for (int i = 1; i <= m; ++i) { n     int u, v; n     cin >> u >> v; n     e[++cnt] = (edge){v, head[u], i}, head[u] = cnt; n     e[++cnt] = (edge){u, head[v], i}, head[v] = cnt; n   } n   dfs(1); n   if (c[1] % 2 == 0) { n     if (c[1]) n       dfs2(1); n     else n       finish(); n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void readi(int &x) { n   int v = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n void readll(long long &x) { n   long long v = 0ll, f = 1ll; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n void readc(char &x) { n   char c; n   while ((c = getchar()) ==    ) n     ; n   x = c; n } n void writes(string s) { puts(s.c_str()); } n void writeln() { writes(  ); } n void writei(int x) { n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n void writell(long long x) { n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n inline long long inc(int &x) { return ++x; } n inline long long inc(long long &x) { return ++x; } n inline long long inc(int &x, long long y) { return x += y; } n inline long long inc(long long &x, long long y) { return x += y; } n inline double inc(double &x, double y) { return x += y; } n inline long long dec(int &x) { return --x; } n inline long long dec(long long &x) { return --x; } n inline long long dec(int &x, long long y) { return x -= y; } n inline long long dec(long long &x, long long y) { return x -= y; } n inline double dec(double &x, double y) { return x -= y; } n inline long long mul(int &x) { return x = ((long long)x) * x; } n inline long long mul(long long &x) { return x = x * x; } n inline long long mul(int &x, long long y) { return x *= y; } n inline long long mul(long long &x, long long y) { return x *= y; } n inline double mul(double &x, double y) { return x *= y; } n inline long long divi(int &x) { return x = sqrt(x); } n inline long long divi(long long &x) { return x = sqrt(x); } n inline long long divi(int &x, long long y) { return x /= y; } n inline long long divi(long long &x, long long y) { return x /= y; } n inline double divi(double &x, double y) { return x /= y; } n inline long long mod(int &x, long long y) { return x %= y; } n inline long long mod(long long &x, long long y) { return x %= y; } n int dx[5] = {0, -1, 1, 0, 0}, dy[5] = {0, 0, 0, -1, 1}; n string dc =  ^v<> ; n int n, m, i, j, k, dg[2222][2222]; n queue<int> qx, qy; n char mp[2222][2222]; n vector<pair<int, int> > add(int x, int y, int z) { n   int i; n   vector<pair<int, int> > ans; n   if ((1) <= ((4))) n     for (((i)) = (1); ((i)) <= ((4)); ((i))++) { n       dg[x + dx[i]][y + dy[i]] += z; n       if (dg[x + dx[i]][y + dy[i]] == 1 && mp[x + dx[i]][y + dy[i]] ==  . ) n         ans.push_back(make_pair(x + dx[i], y + dy[i])); n     } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   ; n   cin >> n >> m; n   if ((1) <= ((n))) n     for (((i)) = (1); ((i)) <= ((n)); ((i))++) n       if ((1) <= ((m))) n         for (((j)) = (1); ((j)) <= ((m)); ((j))++) cin >> mp[i][j]; n   if ((1) <= ((n))) n     for (((i)) = (1); ((i)) <= ((n)); ((i))++) n       if ((1) <= ((m))) n         for (((j)) = (1); ((j)) <= ((m)); ((j))++) n           if (mp[i][j] ==  . ) add(i, j, 1); n   if ((1) <= ((n))) n     for (((i)) = (1); ((i)) <= ((n)); ((i))++) n       if ((1) <= ((m))) n         for (((j)) = (1); ((j)) <= ((m)); ((j))++) n           if (mp[i][j] ==  .  && dg[i][j] == 1) { n             qx.push(i); n             qy.push(j); n           } n   while (!qx.empty()) { n     int x = qx.front(), y = qy.front(); n     qx.pop(); n     qy.pop(); n     if (mp[x][y] !=  . ) continue; n     if ((1) <= ((4))) n       for (((k)) = (1); ((k)) <= ((4)); ((k))++) { n         if (mp[x + dx[k]][y + dy[k]] ==  . ) { n           mp[x][y] = dc[(k - 1) ^ 1]; n           mp[x + dx[k]][y + dy[k]] = dc[(k - 1)]; n           vector<pair<int, int> > nxt = add(x, y, -1); n           for (__typeof((nxt).begin()) it = (nxt).begin(); it != (nxt).end(); n                it++) { n             if (mp[it->first][it->second] ==  . ) { n               qx.push(it->first); n               qy.push(it->second); n             } n           } n           nxt = add(x + dx[k], y + dy[k], -1); n           for (__typeof((nxt).begin()) it = (nxt).begin(); it != (nxt).end(); n                it++) { n             if (mp[it->first][it->second] ==  . ) { n               qx.push(it->first); n               qy.push(it->second); n             } n           } n           break; n         } n       } n   } n   if ((1) <= ((n))) n     for (((i)) = (1); ((i)) <= ((n)); ((i))++) n       if ((1) <= ((m))) n         for (((j)) = (1); ((j)) <= ((m)); ((j))++) n           if (mp[i][j] ==  . ) { n             cout <<  Not unique ; n             return 0; n           }; n   if ((1) <= ((n))) n     for (((i)) = (1); ((i)) <= ((n)); ((i))++) { n       if ((1) <= ((m))) n         for (((j)) = (1); ((j)) <= ((m)); ((j))++) cout << mp[i][j]; n       cout << endl; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> split(const string& s, char c) { n   vector<string> v; n   stringstream ss(s); n   string x; n   while (getline(ss, x, c)) v.push_back(move(x)); n   return move(v); n } n void err(vector<string>::iterator it) {} n template <typename T, typename... Args> n void err(vector<string>::iterator it, T a, Args... args) { n   cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   n ; n   err(++it, args...); n } n int N, M; n int S[300013]; n set<int> flv[300013]; n vector<int> adj[300013]; n int ans = 1; n int color[300013]; n void dfs(int n, int p = 0) { n   set<int> s; n   int cur = 1; n   for (int x : flv[n]) { n     if (color[x]) { n       s.insert(color[x]); n     } n   } n   for (int x : flv[n]) { n     if (!color[x]) { n       while (s.count(cur)) cur++; n       color[x] = cur++; n     } n   } n   for (int v : adj[n]) { n     if (v != p) { n       dfs(v, n); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> N >> M; n   for (int i = 1; i <= N; i++) { n     cin >> S[i]; n     ans = max(ans, S[i]); n     for (int j = 0; j < S[i]; j++) { n       int k; n       cin >> k; n       flv[i].insert(k); n     } n   } n   for (int i = 1; i < N; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(1); n   cout << ans << endl; n   for (int i = 1; i <= M; i++) { n     cout << (color[i] ? color[i] : 1) <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   unsigned long long int n; n   cin >> q; n   for (int i = 0; i < q; i++) { n     cin >> n; n     if (n < 4) { n       cout << 4 - n << endl; n     } else { n       if (n % 2 == 0) { n         cout << 0 << endl; n       } else { n         cout << 1 << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T abs(T t) { n   return t < 0 ? -t : t; n } n const long long modn = 1000000007; n inline long long mod(long long x) { return x % modn; } n const int N = 1000009; n int a[N], t[N]; n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int A, B, n; n long long memo[N][2][2]; n long long solve(int i, bool on, bool first) { n   if (i == n) return (first && on) ? 100000000000000000ll : 0ll; n   if (!on && t[i] == 2) return 100000000000000000ll; n   long long &r = memo[i][on][first]; n   if (r != -1) return r; n   if (on) n     r = min(solve(i, false, first), solve(i + 1, true, first) + A); n   else n     r = solve(i + 1, false, first) + (t[i] == 1 ? B : 0ll); n   return r; n } n void add_ps(set<int> &p, int x) { n   for (int i = 2; i * i <= x; i++) { n     if (!(x % i)) p.insert(i); n     while (!(x % i)) x /= i; n   } n   if (x > 1) p.insert(x); n } n int main() { n   int i; n   scanf( %d %d %d , &n, &A, &B); n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   set<int> p; n   for (i = -1; i <= 1; i++) add_ps(p, a[0] + i), add_ps(p, a[n - 1] + i); n   long long ans = LLONG_MAX; n   for (int x : p) { n     for (i = 0; i < n; i++) n       if ((a[i] % x) == 0) n         t[i] = 0; n       else if (!((a[i] + 1) % x) || !((a[i] - 1) % x)) n         t[i] = 1; n       else n         t[i] = 2; n     memset(memo, -1, sizeof memo); n     long long cur = 0; n     for (i = 0; i < n; i++) { n       ans = min(ans, cur + solve(i, true, !i)); n       if (t[i] == 1) n         cur += B; n       else if (t[i] == 2) n         break; n     } n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n string solve(string s) { n   if (s.size() & 1) { n     return s; n   } n   string a = solve(s.substr(0, s.size() / 2)); n   string b = solve(s.substr(s.size() / 2)); n   if (a < b) { n     return a.append(b); n   } else { n     return b.append(a); n   } n } n int main() { n   string s, t; n   cin >> s >> t; n   cout << (solve(s) == solve(t) ?  YES  :  NO ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c[500]; n int main() { n   string s, t; n   int n, i, j, k; n   cin >> s >> t; n   bool ok = 1; n   vector<pair<char, char> > ans; n   n = s.length(); n   vector<char> v(500,  0 ); n   for (i = 0; i < n; i++) { n     if (s[i] == t[i]) { n       if (c[s[i]] == -2) ok = 0; n       c[s[i]] = -1; n       continue; n     } else if (c[s[i]] == -1 || c[t[i]] == -1) { n       ok = 0; n     } else if (!c[s[i]] && !c[t[i]]) { n       ans.push_back({s[i], t[i]}); n       c[s[i]] = -2; n       v[s[i]] = t[i]; n       c[t[i]] = -2; n       v[t[i]] = s[i]; n     } else if (c[s[i]] == -2 && c[t[i]] == -2) { n       if (v[s[i]] != t[i] || v[t[i]] != s[i]) ok = 0; n     } else n       ok = 0; n   } n   if (!ok) return cout << -1, 0; n   cout << ans.size() << endl; n   for (i = 0; i < ans.size(); i++) { n     cout << ans[i].first <<     << ans[i].second << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   string ans; n   cin >> s; n   int i = 0; n   int j = 0; n   while (i < s.size() & j < 3) { n     if (j == 0) { n       if (s[i] ==  f ) { n         ans =  ftp:// ; n         i = 3; n       } else { n         ans =  http:// ; n         i = 4; n       } n       j = 1; n     } n     if (j == 1) { n       int temp = i; n       while (s[i + 1] !=  r  || s[i + 2] !=  u ) { n         i++; n       } n       ans += s.substr(temp, i + 1 - temp); n       ans +=  .ru ; n       i = i + 3; n       j = 2; n     } n     if (j == 2) { n       if (s.size() - i) { n         ans +=  / ; n         ans += s.substr(i, s.size() - i); n         i = s.size(); n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200100; n const long long OO = 1e18; n const int oo = 2e9; n const int md = 998244353; n set<int> st; n set<int>::iterator ite; n int sto, n, p[N], obr = 1, ans = 0, mul[N], q, psm[N]; n bool mrk[N]; n int mult(int x, int y) { return (1ll * x * y) % md; } n int sum(int x, int y) { n   x += y; n   if (x >= md) x -= md; n   return x; n } n int sub(int x, int y) { n   x -= y; n   if (x < 0) x += md; n   return x; n } n int binpow(int x, int po) { n   int res = 1; n   while (po > 0) { n     if (po & 1) res = mult(res, x); n     x = mult(x, x); n     po >>= 1; n   } n   return res; n } n int calc(int l, int r) { n   int up = sub(psm[r - 1], (l - 2 < 0 ? 0 : psm[l - 2])); n   up = mult(up, binpow(mul[l - 1], md - 2)); n   int down = mult(mul[r], binpow(mul[l - 1], md - 2)); n   return mult(up, binpow(down, md - 2)); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> q; n   sto = binpow(100, md - 2); n   mul[0] = 1; n   mrk[1] = 1; n   psm[0] = 1; n   for (int i = 1; i <= n; i++) { n     cin >> p[i]; n     p[i] = mult(p[i], sto); n     mul[i] = mult(mul[i - 1], p[i]); n     psm[i] = sum(psm[i - 1], mul[i]); n   } n   ans = calc(1, n); n   st.clear(); n   st.insert(1); n   st.insert(n + 1); n   for (; q; q--) { n     int ps; n     cin >> ps; n     if (!mrk[ps]) { n       st.insert(ps); n       ite = st.find(ps); n       int lf = *prev(ite); n       int rt = (*next(ite)) - 1; n       ans = sub(ans, calc(lf, rt)); n       ans = sum(ans, calc(lf, ps - 1)); n       ans = sum(ans, calc(ps, rt)); n     } else { n       ite = st.find(ps); n       int lf = *prev(ite); n       int rt = (*next(ite)) - 1; n       ans = sum(ans, calc(lf, rt)); n       ans = sub(ans, calc(lf, ps - 1)); n       ans = sub(ans, calc(ps, rt)); n       st.erase(ite); n     } n     mrk[ps] ^= 1; n     cout << ans <<   n ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int size = 508; n int num[size]; n int Abs(int x) { return x > 0 ? x : -x; } n int main() { n   int n, sum, m, i, x, L, R, c, t, v, up; n   cin >> n; n   sum = m = 0; n   up = 1000000; n   for (i = 1; i <= 2 * n - 1; i++) { n     cin >> num[i]; n     if (num[i] < 0) m++; n     sum += Abs(num[i]); n     if (up > Abs(num[i])) up = Abs(num[i]); n   } n   if (n & 1) { n     cout << sum << endl; n     return 0; n   } n   if (m & 1) { n     cout << sum - 2 * up << endl; n   } else n     cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, d; n   int n; n   cin >> a >> d >> n; n   scanf( %lf%lf%d , &a, &d, &n); n   for (int i = 0; i < n; i++) { n     double temp = fmod((i + 1) * d, 4 * a); n     if (temp < a) n       printf( %lf %lf n , temp, 0.0); n     else if (temp < a * 2) n       printf( %lf %lf n , a, temp - a); n     else if (temp < a * 3) n       printf( %lf %lf n , 3 * a - temp, a); n     else n       printf( %lf %lf n , 0.0, 4 * a - temp); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int mxn = 105; n const int inf = 505; n int n; n int m; n int ans; n int row[mxn]; n int col[mxn]; n int mat[mxn][mxn]; n inline void calcRow() { n   for (int i = 1; i <= n; ++i) { n     row[i] = inf; n     for (int j = 1; j <= m; ++j) n       if (row[i] > mat[i][j]) row[i] = mat[i][j]; n     for (int j = 1; j <= m; ++j) mat[i][j] -= row[i]; n     ans += row[i]; n   } n } n inline void calcCol() { n   for (int j = 1; j <= m; ++j) { n     col[j] = inf; n     for (int i = 1; i <= n; ++i) n       if (col[j] > mat[i][j]) col[j] = mat[i][j]; n     for (int i = 1; i <= n; ++i) mat[i][j] -= col[j]; n     ans += col[j]; n   } n } n signed main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) scanf( %d , &mat[i][j]); n   if (n <= m) n     calcRow(), calcCol(); n   else n     calcCol(), calcRow(); n   bool flag = true; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (mat[i][j]) flag = false; n   if (flag) { n     printf( %d n , ans); n     for (int i = 1; i <= n; ++i) n       for (int j = 1; j <= row[i]; ++j) printf( row %d n , i); n     for (int j = 1; j <= m; ++j) n       for (int i = 1; i <= col[j]; ++i) printf( col %d n , j); n   } else n     puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1; n const long long MOD = 1; n long long _gcd(long long a, long long b) { n   if (b == 0) return a; n   return _gcd(b, a % b); n } n long long gcd(long long a, long long b) { n   a = abs(a), b = abs(b); n   if (a < b) swap(a, b); n   return _gcd(a, b); n } n long long qpow(long long a, long long n) { n   long long rt = 1; n   while (n) { n     if (n & 1) rt = (rt * a) % MOD; n     a = a * a % MOD; n     n >>= 1; n   } n   return rt; n } n long long factor[MAXN]; n long long inv[MAXN]; n void cal_factor() { n   factor[0] = 1; n   for (int u = 1; u < MAXN; u++) { n     factor[u] = (factor[u - 1] * u) % MOD; n   } n } n void cal_factor_inv() { n   inv[0] = 1; n   inv[MAXN - 1] = qpow(factor[MAXN - 1], MOD - 2); n   for (int u = MAXN - 2; u >= 1; u--) { n     inv[u] = inv[u + 1] * (u + 1) % MOD; n   } n } n void init_factor() { n   cal_factor(); n   cal_factor_inv(); n } n long long C(long long n, long long k) { n   if (n < k) return 0; n   return factor[n] * qpow(factor[n - k], MOD - 2) % MOD * n          qpow(factor[k], MOD - 2) % MOD; n } n void solve() { n   int a[6]; n   for (int u = 0; u < 6; u++) cin >> a[u]; n   int n; n   cin >> n; n   vector<pair<int, int>> b; n   for (int u = 0; u < n; u++) { n     int tb; n     cin >> tb; n     for (int k = 0; k < 6; k++) { n       b.push_back({tb - a[k], u}); n     } n   } n   sort(b.begin(), b.end()); n   int ptr1 = 0, ptr2 = 0; n   vector<int> vis(n, 0); n   int cnt = 0; n   int ans = 2e9; n   for (; ptr2 < n * 6; ptr2++) { n     if (vis[b[ptr2].second] == 0) cnt++; n     vis[b[ptr2].second]++; n     while (cnt == n && ptr1 <= ptr2 && vis[b[ptr1].second]) { n       ans = min(ans, b[ptr2].first - b[ptr1].first); n       vis[b[ptr1].second]--; n       if (vis[b[ptr1].second] == 0) cnt--; n       ptr1++; n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n struct point { n   double x, y; n } p, q, u; n double v, vp, r, R, k; n double po, qo, pa, qa, angp, angq, angpq; n point rorate(point a, double ang) { n   point c; n   c.x = a.x * cos(ang) - a.y * sin(ang); n   c.y = a.x * sin(ang) + a.y * cos(ang); n   return c; n } n double disp2o(point a) { return a.x * a.x + a.y * a.y; } n double cal(double pq) { n   if (pq * pq < po || pq * pq < qo) return pq; n   angpq = acos((po + qo - (pq * pq)) / (2 * sqrt(po * qo))); n   return k + (angpq - angp - angq) * r; n } n int bi(double t) { n   double d, dis, ang; n   ang = t * vp / R; n   q = rorate(u, ang); n   dis = sqrt((p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y)); n   d = fabs(p.x * q.y - p.y * q.x) / dis; n   if (d < r) dis = cal(dis); n   if (dis > v * t + 1e-8) return 1; n   if (dis < v * t - 1e-8) return -1; n   return 0; n } n int main() { n   double lt, rt, mid; n   int t; n   while (~scanf( %lf%lf%lf , &u.x, &u.y, &vp)) { n     scanf( %lf%lf%lf%lf , &p.x, &p.y, &v, &r); n     qo = disp2o(u); n     R = sqrt(qo); n     po = disp2o(p); n     angp = acos(r / sqrt(po)); n     angq = acos(r / R); n     k = sqrt(po - (r * r)) + sqrt(qo - (r * r)); n     lt = 0; n     rt = 1e4; n     while (rt > lt + 1e-8) { n       mid = (rt + lt) / 2; n       t = bi(mid); n       if (t == 1) n         lt = mid; n       else if (t == -1) n         rt = mid; n       else n         break; n     } n     printf( %.10lf n , mid); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n void in() { cin >> n >> m; } n void out() { n   int s = 0; n   if (n > m) { n     cout << n - m; n     return; n   } n   while (n < m) { n     s++; n     n <<= 1; n   } n   int diff = n - m; n   n >>= 1; n   long long x = 2; n   long long c = 0; n   while (x <= diff && c < s) { n     c++; n     x *= 2; n   } n   x /= 2; n   while (diff > 0) { n     diff -= x; n     s++; n     while (diff < x) { n       x /= 2; n     } n   } n   cout << s; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   while (t--) { n     in(); n     out(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e6 + 5; n const int K = 20; n vector<int> P[N]; n int s[K]; n int t[K]; n int L[1 << K]; n int R[1 << K]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, m, k; n   cin >> n >> m >> k; n   char f; n   int c0 = 0, c1 = 0; n   for (int i = 0; i < k; i++) { n     cin >> f; n     s[i] = f -  0 ; n     c0 += s[i]; n   } n   for (int i = 0; i < k; i++) { n     cin >> f; n     t[i] = f -  0 ; n     c1 += t[i]; n   } n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j < k; j++) P[i].push_back(j); n   } n   int l, r; n   for (int i = 1; i <= n; i++) { n     cin >> l >> r; n     l--; n     r--; n     P[i][l] = r; n     P[i][r] = l; n     vector<int> nw; n     for (auto x : P[i]) { n       nw.push_back(P[i - 1][x]); n     } n     P[i] = nw; n   } n   for (int i = 0; i < (1 << k); i++) { n     L[i] = (int)1e9; n     R[i] = -1; n   } n   int mask; n   for (int i = 0; i <= n - 1; i++) { n     mask = 0; n     for (int j = 0; j < k; j++) { n       if (s[j]) mask |= (1 << P[i][j]); n     } n     L[mask] = min(L[mask], i); n   } n   for (int i = 1; i <= n; i++) { n     mask = 0; n     for (int j = 0; j < k; j++) { n       if (t[j]) mask |= (1 << P[i][j]); n     } n     R[mask] = max(R[mask], i); n   } n   int nex; n   for (int i = (1 << k) - 1; i >= 0; i--) { n     for (int j = 0; j < k; j++) { n       if ((i & (1 << j))) continue; n       nex = (i | (1 << j)); n       L[i] = min(L[i], L[nex]); n       R[i] = max(R[i], R[nex]); n     } n   } n   int mx = 0; n   int fl = 0, fr = n; n   for (int i = 0; i < (1 << k); i++) { n     if (L[i] == (int)1e9 || R[i] == -1) continue; n     if (R[i] - L[i] >= m) { n       if (__builtin_popcount(i) > mx) { n         mx = __builtin_popcount(i); n         fl = L[i], fr = R[i]; n       } n     } n   } n   cout << k + 2 * mx - c0 - c1 <<   n ; n   cout << fl + 1 <<     << fr <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 123, INF = 1e9, mod = 1e9 + 7, N = 2e5 + 123; n struct btr { n   map<int, long long> dp; n   set<pair<long long, int> > st; n   long long mn, add; n }; n vector<int> g[maxn]; n int n, m; n btr a[maxn]; n void Merge(btr &a, btr &b) { n   if (a.dp.size() < b.dp.size()) swap(a, b); n   long long x = a.add, y = b.add; n   a.add += b.mn + y; n   b.add += a.mn + x; n   for (auto x : b.dp) { n     int v = x.first; n     long long c = x.second + b.add - a.add; n     if (!a.dp.count(v) || a.dp[v] > c) { n       a.st.erase({a.dp[v], v}); n       a.dp[v] = c; n       a.st.insert({a.dp[v], v}); n     } n   } n   if (!a.st.empty()) a.mn = a.st.begin()->first; n } n void dfs(int v, int p) { n   if (!a[v].st.empty()) a[v].mn = a[v].st.begin()->first; n   btr tmp; n   bool flag = 0; n   for (auto to : g[v]) { n     if (to == p) continue; n     dfs(to, v); n     if (!flag) n       swap(tmp, a[to]); n     else n       Merge(tmp, a[to]); n     flag = 1; n     a[to].dp.clear(); n     a[to].st.clear(); n   } n   if (flag) { n     for (auto x : a[v].dp) { n       int u = x.first; n       long long c = x.second + tmp.mn; n       if (!tmp.dp.count(u) || tmp.dp[u] > c) { n         tmp.st.erase({tmp.dp[u], u}); n         tmp.dp[u] = c; n         tmp.st.insert({tmp.dp[u], u}); n       } n     } n     swap(a[v], tmp); n   } n   if (v != 1 && a[v].dp.count(v)) { n     a[v].st.erase({a[v].dp[v], v}); n     a[v].dp.erase(v); n     if (!a[v].st.empty()) a[v].mn = a[v].st.begin()->first; n   } n   if (a[v].st.empty()) { n     cerr << v << endl; n     printf( -1 ); n     exit(0); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   if (n == 1) { n     printf( 0 ); n     exit(0); n   } n   for (int i = 1; i < n; i++) { n     int v, u; n     scanf( %d%d , &v, &u); n     g[v].push_back(u); n     g[u].push_back(v); n   } n   for (int i = 0; i < m; i++) { n     int u, v, c; n     scanf( %d%d%d , &v, &u, &c); n     if (!a[v].dp.count(u) || a[v].dp[u] > c) { n       a[v].st.erase({a[v].dp[u], u}); n       a[v].dp[u] = c; n       a[v].st.insert({a[v].dp[u], u}); n     } n   } n   dfs(1, 1); n   printf( %lld , 0ll + a[1].mn + a[1].add); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void read(T &x) { n   x = 0; n   char ch = getchar(); n   int f = 1; n   while (!isdigit(ch)) { n     if (ch ==  - ) f *= -1; n     ch = getchar(); n   }; n   while (isdigit(ch)) { n     x = x * 10 + ch - 48; n     ch = getchar(); n   } n   x *= f; n } n int n; n vector<int> tv; n int lst[1310000][26]; n bool vis[1310000]; n int main() { n   read(n); n   int tsu = 0; n   int cu; n   for (int i = 0; i < n * 2; i++) { n     read(cu); n     tsu += cu; n     tv.push_back(cu); n   } n   sort(tv.begin(), tv.end()); n   int ans = 1e9, rans[30][2]; n   int csz = 0; n   for (int j = n * 2 - 1; j >= n + 1; j--) csz += tv[j]; n   for (int j = 0; j <= csz; j++) memset(lst[j], 0, sizeof(lst[j])); n   memset(vis, 0, sizeof(vis)); n   lst[0][0] = 99999; n   vis[0] = 1; n   int used[100] = {0}; n   for (int i = 1; i >= 1; i--) { n     int sua = 0, sub = 0; n     for (int j = 0; j < i; j++) sua += tv[j]; n     sub += tv[i]; n     for (int j = n * 2 - 1; j >= i + 1; j--) { n       if (used[j]) continue; n       used[j] = 1; n       int cv = tv[j]; n       for (int k = csz; k >= cv; k--) { n         if (!vis[k - cv]) continue; n         for (int l = n; l >= 1; l--) { n           if (lst[k - cv][l - 1] != 0 && lst[k][l] == 0) { n             lst[k][l] = j; n             vis[k] = 1; n           } n         } n       } n     } n     int cans = 1e9, cbst = 0; n     ; n     for (int j = 0; j <= csz; j++) { n       if (lst[j][n - i]) { n         if (max(j + sua + sub, tsu - sua - sub - j + sub + tv[0]) < cans) { n           cans = max(j + sua + sub, tsu - sua - sub - j + sub + tv[0]); n           cbst = j; n         } n       } n     } n     if (cans < ans) { n       vector<int> ntv = tv; n       ans = cans; n       for (int j = 0; j < i; j++) { n         rans[j][0] = ntv[j]; n         ntv[j] = -1; n       } n       int cp = cbst, cn = n - i; n       for (int j = i; j < n; j++) { n         rans[j][0] = ntv[lst[cp][cn]]; n         ntv[lst[cp][cn]] = -1; n         cp -= rans[j][0]; n         cn--; n       } n       int p = n - 1; n       for (int j = 0; j < 2 * n; j++) { n         if (ntv[j] != -1) { n           rans[p][1] = ntv[j]; n           p--; n         } n       } n     } n   } n   for (int i = 0; i < n; i++) cout << rans[i][0] <<    ; n   cout << endl; n   for (int i = 0; i < n; i++) cout << rans[i][1] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n int n; n double p; n double C2(double x) { n   if (x < 1) return 0; n   return x * (x - 1) / 2; n } n double C3(double x) { n   if (x < 2) return 0; n   return x * (x - 1) * (x - 2) / 6; n } n int main() { n   std::cin >> n >> p; n   for (int i = 0; i <= n; i++) n     if ([&](int x) { n           double an = (double)C2(n - x) * x / C3(n) * (1.0 / 3 + 1.0 / 6) + n                       (double)(n - x) * C2(x) / C3(n) + (double)C3(x) / C3(n); n           return an >= p; n         }(i)) n       return std::cout << i, 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, st, ed, i, j, ep = 1, h[1005]; n long long d[1005][1005], dis[1005]; n queue<int> q; n struct node { n   int y, ne, v; n } e[1000005]; n void add(int a, int b, int v) { n   e[ep].y = b; n   e[ep].v = v; n   e[ep].ne = h[a]; n   h[a] = ep; n   ep++; n } n int main() { n   scanf( %d%d , &n, &m); n   scanf( %d%d , &st, &ed); n   for (i = 1; i <= m; i++) { n     int a, b, c; n     scanf( %d%d%d , &a, &b, &c); n     add(a, b, c); n     add(b, a, c); n   } n   memset(d, 0x3f, sizeof(d)); n   for (i = 1; i <= n; i++) { n     d[i][i] = 0; n     q.push(i); n     while (!q.empty()) { n       int s = q.front(); n       q.pop(); n       for (j = h[s]; j; j = e[j].ne) { n         if (d[i][s] + e[j].v < d[i][e[j].y]) { n           d[i][e[j].y] = d[i][s] + e[j].v; n           q.push(e[j].y); n         } n       } n     } n   } n   memset(h, 0, sizeof(h)); n   ep = 1; n   for (i = 1; i <= n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     for (j = 1; j <= n; j++) n       if (d[i][j] <= a && i != j) add(i, j, b); n   } n   memset(dis, 0x3f, sizeof(dis)); n   dis[st] = 0; n   q.push(st); n   while (!q.empty()) { n     int s = q.front(); n     q.pop(); n     for (i = h[s]; i; i = e[i].ne) { n       if (dis[s] + e[i].v < dis[e[i].y]) { n         dis[e[i].y] = dis[s] + e[i].v; n         q.push(e[i].y); n       } n     } n   } n   if (dis[ed] < (1LL << 60)) n     printf( %I64d n , dis[ed]); n   else n     puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int flag1 = 0, flag2 = 0, flag3 = 0, ff3, flag4 = 0; n int n, a[200000 + 5], x, y; n map<int, bool> mp; n int main() { n   n = read(); n   read(); n   x = read(); n   y = read(); n   for (int i = 1; i <= n; ++i) mp[a[i] = read()] = 1; n   for (int i = 1; i <= n; ++i) { n     if (mp[a[i] - x]) flag1 = i; n     if (mp[a[i] - y]) flag2 = i; n     if (mp[a[i] - y + x] && (a[i] - y >= 0 || a[i] + x <= a[n])) n       flag3 = i, ff3 = (a[i] - y >= 0) ? a[i] - y : a[i] + x; n     ; n     if (mp[a[i] - y - x]) flag4 = i; n   } n   if (flag1 && flag2) n     puts( 0 ); n   else if (flag1 | flag2) n     printf( 1 n%d , flag1 ? y : x); n   else if (flag3) n     printf( 1 n%d , ff3); n   else if (flag4) n     printf( 1 n%d , a[flag4] - x); n   else n     printf( 2 n%d %d , x, y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int r, d; n   cin >> r >> d; n   int n; n   cin >> n; n   d = r - d; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     int x, y, rx; n     cin >> x >> y >> rx; n     long double distance = sqrt(x * x + y * y); n     long double temp = (rx); n     if (distance - d - temp >= 0) { n       if (r - distance - temp >= 0) ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long int; n lint liters(int l, vector<int> &arr) { n   lint sum = 0; n   for (int k : arr) sum += (lint)(k - l); n   return sum; n } n int main() { n   int n, m = 1000000010; n   lint s; n   vector<int> arr; n   cin >> n >> s; n   arr.resize(n); n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     m = min(m, arr[i]); n   } n   if (s > liters(0, arr)) n     cout << -1 << endl; n   else { n     int start = 0, end = m; n     while (start < end) { n       int mid = (start + end) / 2 + 1; n       if (s <= liters(mid, arr)) n         start = mid; n       else n         end = mid - 1; n     } n     cout << start << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int val, lazy, child; n   node() { n     val = child = 0; n     lazy = 1e9 + 7; n   } n   node(int vval, int llazy, int cchild) { n     val = vval; n     lazy = llazy; n     child = cchild; n   } n }; n int N, K, Q; n int w, x, y, z; n int arr[100100]; n int stree[4 * 100100]; n vector<node> tree; n int counter, c1, c2; n int squery(int n, int l, int r, int ql, int qr) { n   if (l > qr || r < ql) { n     return 1e9 + 7; n   } else if (ql <= l && r <= qr) { n     return stree[n]; n   } else { n     return min(squery(2 * n, l, (l + r) / 2, ql, qr), n                squery(2 * n + 1, (l + r) / 2 + 1, r, ql, qr)); n   } n } n void propogate(int n) { n   tree[tree[n].child].val = tree[n].lazy; n   tree[tree[n].child + 1].val = tree[n].lazy; n   tree[tree[n].child].lazy = tree[n].lazy; n   tree[tree[n].child + 1].lazy = tree[n].lazy; n   tree[n].lazy = 1e9 + 7; n } n void update(int n, int l, int r, int ql, int qr, int q) { n   if (tree[n].child == 0) { n     tree[n].child = counter; n     counter += 2; n     tree.push_back(node()); n     tree.push_back(node()); n   } n   if (tree[n].lazy != 1e9 + 7 && l != r) { n     propogate(n); n   } n   if (l > qr || r < ql) { n     if (tree[n].val == 0) { n       if ((r - l + 1) >= N) { n         tree[n].val = squery(1, 1, N, 1, N); n       } else { n         c1 = l % N; n         c2 = r % N; n         if (c1 == 0) { n           c1 = N; n         } n         if (c2 == 0) { n           c2 = N; n         } n         if (c1 <= c2) { n           tree[n].val = squery(1, 1, N, c1, c2); n         } else { n           tree[n].val = min(squery(1, 1, N, c1, N), squery(1, 1, N, 1, c2)); n         } n       } n     } n     return; n   } else if (ql <= l && r <= qr) { n     tree[n].val = tree[n].lazy = q; n     return; n   } else { n     update(tree[n].child, l, (l + r) / 2, ql, qr, q); n     update(tree[n].child + 1, (l + r) / 2 + 1, r, ql, qr, q); n     tree[n].val = min(tree[tree[n].child].val, tree[tree[n].child + 1].val); n   } n } n int query(int n, int l, int r, int ql, int qr) { n   if (tree[n].child == 0) { n     tree[n].child = counter; n     counter += 2; n     tree.push_back(node()); n     tree.push_back(node()); n   } n   if (tree[n].val == 0) { n     if ((r - l + 1) >= N) { n       tree[n].val = squery(1, 1, N, 1, N); n     } else { n       c1 = l % N; n       c2 = r % N; n       if (c1 == 0) { n         c1 = N; n       } n       if (c2 == 0) { n         c2 = N; n       } n       if (c1 <= c2) { n         tree[n].val = squery(1, 1, N, c1, c2); n       } else { n         tree[n].val = min(squery(1, 1, N, c1, N), squery(1, 1, N, 1, c2)); n       } n     } n   } n   if (tree[n].lazy != 1e9 + 7 && l != r) { n     propogate(n); n   } n   if (l > qr || r < ql) { n     return 1e9 + 7; n   } else if (ql <= l && r <= qr) { n     return tree[n].val; n   } else { n     return min(query(tree[n].child, l, (l + r) / 2, ql, qr), n                query(tree[n].child + 1, (l + r) / 2 + 1, r, ql, qr)); n   } n } n void buildtree(int n, int l, int r) { n   if (l == r) { n     stree[n] = arr[l]; n     return; n   } else { n     buildtree(2 * n, l, (l + r) / 2); n     buildtree(2 * n + 1, (l + r) / 2 + 1, r); n     stree[n] = min(stree[2 * n], stree[2 * n + 1]); n   } n } n int main() { n   cin >> N >> K; n   for (int i = 1; i <= N; i++) { n     cin >> arr[i]; n   } n   buildtree(1, 1, N); n   counter = 1; n   tree.push_back(node()); n   cin >> Q; n   for (int i = 0; i < Q; i++) { n     cin >> w; n     if (w == 1) { n       cin >> x >> y >> z; n       update(0, 1, N * K, x, y, z); n     } else { n       cin >> x >> y; n       cout << query(0, 1, N * K, x, y) << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long bin_pow(long long a, long long b) { n   if (b == 0) return 1; n   if (b % 2 == 0) { n     long long t = bin_pow(a, b / 2); n     return t * t % 1000000007; n   } else n     return a * bin_pow(a, b - 1) % 1000000007; n } n long long t = 1, n, m, k = 0, sum = 0, l = 0, r = 0, x = 0, y = 0, z = 0, n           ans = 0, mn = LLONG_MAX, mx = LLONG_MIN; n struct cat { n   long long a, b, c; n }; n vector<cat> edges; n vector<long long> graph[100000]; n long long z1 = 1, color[100000]; n void dfs(long long v) { n   color[v] = 1; n   for (auto u : graph[v]) { n     if (color[u] == 1) { n       z1 = 0; n       return; n     } n     if (color[u] == 0) dfs(u); n   } n   color[v] = 2; n } n bool tr(long long x) { n   z1 = 1; n   for (int i = 0; i < n; i++) graph[i].clear(), color[i] = 0; n   for (int i = 0; i < m; i++) { n     if (edges[i].c <= x) break; n     long long x1 = edges[i].a, y1 = edges[i].b; n     graph[x1].push_back(y1); n   } n   for (int i = 0; i < n; i++) { n     if (color[i] == 0) dfs(i); n   } n   return z1; n } n bool cmp(cat a, cat b) { return a.c > b.c; } n vector<long long> order; n bool used[100000]; n void dfs1(long long v) { n   used[v] = true; n   for (auto u : graph[v]) { n     if (used[u]) continue; n     dfs1(u); n   } n   order.push_back(v); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   string s, s1; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> x >> y >> z; n     x--, y--; n     cat f; n     f.a = x, f.b = y, f.c = z; n     edges.push_back(f); n   } n   vector<cat> c = edges; n   ans = -1; n   sort(edges.begin(), edges.end(), cmp); n   for (long long b = 1e9; b >= 1; b /= 2) { n     while (!tr(ans + b)) ans += b; n   } n   ans++; n   cout << ans <<    ; n   vector<long long> d; n   for (int i = 0; i < n; i++) { n     graph[i].clear(); n   } n   for (int i = 0; i < m; i++) { n     if (c[i].c <= ans) continue; n     graph[c[i].a].push_back(c[i].b); n   } n   for (int i = 0; i < n; i++) { n     if (used[i]) continue; n     dfs1(i); n   } n   reverse(order.begin(), order.end()); n   vector<long long> pos(n); n   for (int i = 0; i < n; i++) { n     pos[order[i]] = i; n   } n   for (int i = 0; i < m; i++) { n     if (c[i].c <= ans) { n       if (pos[c[i].a] <= pos[c[i].b]) n         ; n       else n         d.push_back(i); n     } n   } n   cout << d.size() <<   n ; n   for (auto u : d) cout << u + 1 <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 1; n int n, x[N]; n char c[N]; n vector<pair<int, int>> segs; n long long ans; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   int last = -1; n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> c[i]; n     if (c[i] ==  G ) { n       segs.emplace_back(last, i); n       last = i; n     } n   } n   segs.emplace_back(last, n); n   for (auto p : segs) { n     int l, r; n     tie(l, r) = p; n     int res = 0; n     vector<int> rs, bs; n     for (int i = l + 1; i < r; i++) { n       if (c[i] ==  R ) n         rs.push_back(i); n       else n         bs.push_back(i); n     } n     if (l != -1 && r != n) { n       res = x[r] - x[l]; n       if (!rs.empty()) { n         int rsub = max(x[rs.front()] - x[l], x[r] - x[rs.back()]); n         for (int i = 1; i < rs.size(); i++) n           rsub = max(x[rs[i]] - x[rs[i - 1]], rsub); n         res += x[r] - x[l] - rsub; n       } n       if (!bs.empty()) { n         int bsub = max(x[bs.front()] - x[l], x[r] - x[bs.back()]); n         for (int i = 1; i < bs.size(); i++) n           bsub = max(x[bs[i]] - x[bs[i - 1]], bsub); n         res += x[r] - x[l] - bsub; n       } n       if (!rs.empty() && !bs.empty()) res = min(2 * (x[r] - x[l]), res); n     } else { n       if (l != -1) { n         if (!rs.empty()) res += x[rs.front()] - x[l]; n         if (!bs.empty()) res += x[bs.front()] - x[l]; n       } n       if (r != n) { n         if (!rs.empty()) res += x[r] - x[rs.back()]; n         if (!bs.empty()) res += x[r] - x[bs.back()]; n       } n       res += (!rs.empty() ? x[rs.back()] - x[rs.front()] : 0) + n              (!bs.empty() ? x[bs.back()] - x[bs.front()] : 0); n     } n     ans += res; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3000000 + 7; n const int M = 1500 + 7; n const int inf = 1e9 + 7; n const long long linf = 1ll * inf * (inf - 1); n const double pi = acos(-1); n const double eps = 1e-6; n const bool multipleTest = false; n const int mod[2] = {inf, 984723593 + 7}; n const int gen[2] = {(rand() % inf) + 1, (rand() % 92473247) + 1}; n long long f[2][N]; n void init() { n   f[0][0] = f[1][0] = 1; n   for (int i = 1; i < N; ++i) { n     for (int t = 0; t < 2; ++t) n       f[t][i] = (long long)f[t][i - 1] * gen[t] % mod[t]; n   } n } n pair<int, int> val[N]; n pair<int, int> getNext(pair<int, int> cur, pair<int, int> nxt, int len) { n   int fir = (cur.first * f[0][len] + nxt.first) % mod[0]; n   int sec = (cur.second * f[1][len] + nxt.second) % mod[1]; n   return make_pair(fir, sec); n } n pair<int, int> getVal(int u, int v) { n   ++u; n   ++v; n   long long fir = (val[v].first - val[u - 1].first * f[0][v - u + 1]) % mod[0]; n   if (fir < 0) fir += mod[0]; n   long long sec = n       (val[v].second - val[u - 1].second * f[1][v - u + 1]) % mod[1]; n   if (sec < 0) sec += mod[1]; n   return make_pair(fir, sec); n } n int n, k; n string s; n map<pair<int, int>, int> all; n int ans[N]; n set<int> has; n void solve() { n   init(); n   cin >> n >> k; n   cin >> s; n   int m; n   cin >> m; n   for (int i = 0; i < m; ++i) { n     string x; n     cin >> x; n     pair<int, int> cur = make_pair(0, 0); n     for (int j = 0, len = (int)(x).size(); j < len; ++j) { n       cur = getNext(cur, make_pair(x[j], x[j] + 2), 1); n     } n     all[cur] = i + 1; n   } n   for (int t = 0; t < k; ++t) s += s[t]; n   val[0] = make_pair(0, 0); n   for (int i = 1, len = (int)(s).size(); i <= len; ++i) { n     val[i] = getNext(val[i - 1], make_pair(s[i - 1], s[i - 1] + 2), 1); n   } n   for (int i = 0; i < k; ++i) { n     bool ok = true; n     int t = 0; n     has.clear(); n     for (int j = i; t < n; j += k) { n       pair<int, int> cur = getVal(j, j + k - 1); n       if (!all.count(cur) || has.count(all[cur])) { n         ok = false; n         break; n       } else { n         ans[t++] = all[cur]; n         has.insert(ans[t - 1]); n       } n     } n     if (ok) { n       puts( YES ); n       for (int j = 0; j < n; ++j) { n         printf( %d  , ans[j]); n       } n       return; n     } n   } n   puts( NO ); n } n int main() { n   int Test = 1; n   if (multipleTest) { n     cin >> Test; n   } n   for (int i = 0; i < Test; ++i) { n     solve(); n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:512000000 ) n using namespace std; n void solve(); n void precalc(); n clock_t start; n int testNumber = 1; n bool todo = true; n int main() { n   start = clock(); n   int t = 1; n   cout.sync_with_stdio(0); n   cin.tie(0); n   precalc(); n   cout.precision(10); n   cout << fixed; n   int testNum = 1; n   while (t--) { n     solve(); n     ++testNumber; n   } n   return 0; n } n template <typename T> n T binpow(T q, T w, T mod) { n   if (!w) return 1 % mod; n   if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod; n   return binpow(q * 1LL * q % mod, w / 2, mod); n } n void precalc() {} n template <typename T> n T gcd(T q, T w) { n   while (w) { n     q %= w; n     swap(q, w); n   } n   return q; n } n template <typename T> n T lcm(T q, T w) { n   return q / gcd(q, w) * w; n } n struct SegTree { n   const int shift = 1 << 18; n   vector<int> tree; n   SegTree() { tree.assign(2 * shift, 0); } n   int rmq(int l, int r) { n     if (l >= r) { n       return 0; n     } n     if (l & 1) { n       return tree[l] + rmq(l + 1, r); n     } n     if (r & 1) { n       return tree[r - 1] + rmq(l, r - 1); n     } n     return rmq(l / 2, r / 2); n   } n   int get_sum(int l, int r) { return rmq(l + shift, r + shift); } n   void update(int v, int val) { n     v += shift; n     tree[v] = val; n     v /= 2; n     while (v) { n       tree[v] = tree[2 * v] + tree[2 * v + 1]; n       v /= 2; n     } n   } n }; n void solve() { n   int n, k, Q; n   vector<int> a(2); n   cin >> n >> k >> a[0] >> a[1] >> Q; n   vector<int> sums(n, 0); n   vector<SegTree> tree(2); n   for (int w = 0; w < Q; ++w) { n     int type; n     cin >> type; n     if (type == 1) { n       int day, num; n       cin >> day >> num; n       --day; n       sums[day] += num; n       for (int i = 0; i < 2; ++i) { n         tree[i].update(day, min(sums[day], a[i])); n       } n     } else { n       int l; n       cin >> l; n       --l; n       long long res = (long long)tree[1].get_sum(0, l) + n                       (long long)tree[0].get_sum(l + k, n); n       cout << res <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-10; n const int maxn = 1000 * 1000 * 1000 + 2; n int n; n int a[3][5 * 100 * 1000 + 2]; n long double s, e = maxn; n bool check(long double x) { n   long double maxr = -1000000001; n   for (int i = 0; i < n; i++) { n     if (a[2][i] > 0 && n         (long double)(a[1][i] + (long double)(((long double)x) * n                                               ((long double)a[2][i]))) > maxr) n       maxr = (long double)(a[1][i] + (long double)(((long double)x) * n                                                    ((long double)a[2][i]))); n     if (a[2][i] < 0 && maxr != -1000000001 && n         maxr >= (long double)(a[1][i] + (long double)(((long double)x) * n                                                       ((long double)a[2][i])))) n       return 1; n   } n   return 0; n } n long double bs(long double x, long double y) { n   if (y - x < eps) return x; n   long double min = (long double)((x + y) / (long double)2.0); n   if (check(min)) n     return bs(x, min); n   else n     return bs(min, y); n } n int main() { n   cout << fixed << setprecision(12); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[1][i] >> a[2][i]; n   if (!check(1000 * 1000 * 1000 + 1.0)) { n     cout << -1 <<  .00000000000000000000  << endl; n     return 0; n   } n   cout << bs(s, e) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1000001; n int n, m, k, a[M], ver[M], nex[M], head[M], cnt, fa[M], dp[M], tmp[M], sz[M]; n vector<int> v[M]; n long long d[M]; n void add(int x, int y) { n   ver[++cnt] = y, nex[cnt] = head[x], head[x] = cnt; n   ver[++cnt] = x, nex[cnt] = head[y], head[y] = cnt; n } n void dfs(int x, int f) { n   fa[x] = f; n   dp[x] = dp[f] + 1; n   for (int i = head[x]; i; i = nex[i]) { n     if (ver[i] == f) continue; n     dfs(ver[i], x); n   } n } n bool cmp(int a, int b) { return dp[a] > dp[b]; } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     scanf( %d , &a[i]), v[a[i]].push_back(i), m = max(m, a[i]); n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     add(x, y); n   } n   dfs(1, 0); n   for (int i = 1; i <= m; i++) { n     int cnt = 0; n     for (int j = i; j <= m; j += i) { n       for (int l = 0; l < v[j].size(); l++) tmp[++cnt] = v[j][l]; n     } n     sort(tmp + 1, tmp + 1 + cnt, cmp); n     d[i] = cnt; n     for (int j = 1; j <= cnt; j++) sz[tmp[j]] = 1; n     for (int j = 1; j <= cnt; j++) { n       int x = tmp[j], f = fa[x]; n       if (!sz[f]) continue; n       d[i] = (d[i] + (long long)sz[x] * sz[f]); n       sz[f] += sz[x]; n     } n     for (int j = 1; j <= cnt; j++) sz[tmp[j]] = 0; n   } n   for (int i = m; i >= 1; i--) n     for (int j = i + i; j <= m; j += i) d[i] -= d[j]; n   for (int i = 1; i <= m; i++) n     if (d[i]) printf( %d %lld n , i, d[i]); n } n


#include <bits/stdc++.h> n using namespace std; n void fre() { n   freopen( c://test//input.in ,  r , stdin); n   freopen( c://test//output.out ,  w , stdout); n } n template <class T> n inline void gmax(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n inline void gmin(T &a, T b) { n   if (b < a) a = b; n } n const int N = 1010, M = 0, Z = 1e9 + 7, ms63 = 1061109567; n const int dy[4] = {-1, 0, 0, 1}, dx[4] = {0, -1, 1, 0}; n int n, m; n char s[N][N]; n struct BFS { n   queue<pair<int, int> > q; n   int f[N][N]; n   int ans[3]; n   void init() { n     memset(f, 63, sizeof(f)); n     memset(ans, 63, sizeof(ans)); n   } n   void inq(int y, int x, int step) { n     if (y < 0 || y == n || x < 0 || x == m) return; n     if (s[y][x] ==  # ) return; n     if (step >= f[y][x]) return; n     f[y][x] = step; n     if (isdigit(s[y][x])) { n       gmin(ans[s[y][x] -  1 ], f[y][x]); n     } n     q.push(make_pair(y, x)); n   } n   void bfs() { n     while (!q.empty()) { n       int y = q.front().first; n       int x = q.front().second; n       q.pop(); n       for (int i = 0; i < 4; i++) { n         inq(y + dy[i], x + dx[i], f[y][x] + 1); n       } n     } n   } n } a[3]; n int main() { n   while (~scanf( %d%d , &n, &m)) { n     for (int i = 0; i < 3; i++) a[i].init(); n     for (int i = 0; i < n; i++) { n       scanf( %s , s[i]); n       for (int j = 0; s[i][j]; j++) n         if (isdigit(s[i][j])) { n           a[s[i][j] -  1 ].inq(i, j, 0); n         } n     } n     for (int i = 0; i < 3; i++) a[i].bfs(); n     int ans = ms63; n     for (int i = 0; i < 3; i++) { n       gmin(ans, a[i].ans[0] + a[i].ans[1] + a[i].ans[2] - 2); n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         long long tmp = -2; n         for (int k = 0; k < 3; k++) tmp += a[k].f[i][j]; n         if (tmp < ans) ans = tmp; n       } n     } n     if (ans > 1e8) ans = -1; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n const int MAXN = 100500; n bool is_occupied[MAXN]; n string names[MAXN]; n int types[MAXN]; n vector<string> nonex_bad; n vector<string> ex_bad; n vector<string> ex_neutral, nonex_neutral; n bool is_bogus_name(string const& fname) { n   if (fname[0] ==  0 ) return true; n   if (not all_of(fname.begin(), fname.end(), [](char x) { return isdigit(x); })) n     return true; n   return false; n } n bool is_ex_filename(int ex_num, string const& fname) { n   if (is_bogus_name(fname)) return false; n   int ret = stoi(fname); n   return 1 <= ret and ret <= ex_num; n } n bool is_nonex_filename(int ex_num, int all_num, string const& fname) { n   if (is_bogus_name(fname)) return false; n   int ret = stoi(fname); n   return ex_num + 1 <= ret and ret <= all_num; n } n int main() { n   cin.sync_with_stdio(false); n   cin.tie(0); n   int n; n   int ex_num = 0; n   set<string> all_names; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string name; n     int is_ex; n     cin >> name >> is_ex; n     all_names.insert(name); n     ex_num += is_ex; n     names[i] = name; n     types[i] = is_ex; n   } n   int cnt_ok = 0; n   for (int i = 0; i < n; i++) { n     bool is_ex = is_ex_filename(ex_num, names[i]); n     bool is_nonex = is_nonex_filename(ex_num, n, names[i]); n     if (is_ex or is_nonex) { n       is_occupied[stoi(names[i])] = true; n     } n     if (is_ex && types[i]) { n       cnt_ok++; n       continue; n     } n     if (is_nonex && !types[i]) { n       cnt_ok++; n       continue; n     } n     if (not is_ex and not is_nonex) { n       if (types[i]) n         ex_neutral.push_back(names[i]); n       else n         nonex_neutral.push_back(names[i]); n       continue; n     } n     if (types[i]) n       ex_bad.push_back(names[i]); n     else n       nonex_bad.push_back(names[i]); n   } n   if (cnt_ok == n) { n     cout <<  0  << endl; n     return 0; n   } n   int free_slot = -1; n   vector<pair<string, string>> moves; n   for (int i = 1; i <= n; i++) { n     if (not is_occupied[i]) { n       free_slot = i; n       break; n     } n   } n   if (free_slot == -1) { n     string move_to; n     for (int i = 0; i < MAXN; i++) { n       string cur = to_string(i); n       while (cur.size() < 6) cur =  0  + cur; n       if (all_names.count(cur) == 0) { n         move_to = cur; n         break; n       } n     } n     if (not ex_bad.empty()) { n       free_slot = stoi(ex_bad.back()); n       is_occupied[free_slot] = false; n       moves.push_back({ex_bad.back(), move_to}); n       ex_neutral.push_back(move_to); n       ex_bad.pop_back(); n     } else if (not nonex_bad.empty()) { n       free_slot = stoi(nonex_bad.back()); n       is_occupied[free_slot] = false; n       moves.push_back({nonex_bad.back(), move_to}); n       nonex_neutral.push_back(move_to); n       nonex_bad.pop_back(); n     } else n       exit(1); n   } n   while (not ex_bad.empty() and not nonex_bad.empty()) { n     if (1 <= free_slot and free_slot <= ex_num) { n       int idx = stoi(ex_bad.back()); n       moves.push_back({ex_bad.back(), to_string(free_slot)}); n       is_occupied[free_slot] = true; n       is_occupied[idx] = false; n       free_slot = idx; n       ex_bad.pop_back(); n     } else { n       int idx = stoi(nonex_bad.back()); n       moves.push_back({nonex_bad.back(), to_string(free_slot)}); n       is_occupied[free_slot] = true; n       is_occupied[idx] = false; n       free_slot = idx; n       nonex_bad.pop_back(); n     } n   } n   for (int i = 1; not ex_bad.empty() and i <= ex_num; i++) { n     if (not is_occupied[i]) { n       is_occupied[i] = true; n       moves.push_back({ex_bad.back(), to_string(i)}); n       is_occupied[stoi(ex_bad.back())] = false; n       ex_bad.pop_back(); n     } n   } n   for (int i = ex_num + 1; not nonex_bad.empty() and i <= n; i++) { n     if (not is_occupied[i]) { n       is_occupied[i] = true; n       moves.push_back({nonex_bad.back(), to_string(i)}); n       is_occupied[stoi(nonex_bad.back())] = false; n       nonex_bad.pop_back(); n     } n   } n   for (int i = 1; not ex_neutral.empty() and i <= ex_num; i++) { n     if (not is_occupied[i]) { n       is_occupied[i] = true; n       moves.push_back({ex_neutral.back(), to_string(i)}); n       ex_neutral.pop_back(); n     } n   } n   for (int i = ex_num + 1; not nonex_neutral.empty() and i <= n; i++) { n     if (not is_occupied[i]) { n       is_occupied[i] = true; n       moves.push_back({nonex_neutral.back(), to_string(i)}); n       nonex_neutral.pop_back(); n     } n   } n   cout << moves.size() <<   n ; n   for (auto const& p : moves) { n     cout <<  move   << p.first <<     << p.second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace my_useful_tools { n const int INF = 0x3f3f3f3f; n inline void pc(char c) { putchar(c); } n template <class T> n inline T gcd(T a, T b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <class T> n inline void W(T p) { n   if (p < 0) pc( - ), p = -p; n   if (p / 10 != 0) W(p / 10); n   pc( 0  + p % 10); n } n template <class T> n inline void Wn(T p) { n   W(p), puts(  ); n } n template <class T> n inline void W(T a, T b) { n   W(a), pc(   ), W(b); n } n template <class T> n inline void Wn(T a, T b) { n   W(a), pc(   ), Wn(b); n } n template <class T> n inline void W(T a, T b, T c) { n   W(a), pc(   ), W(b), pc(   ), W(c); n } n inline char gchar() { n   char ret = getchar(); n   for (; ret ==   n  || ret ==   r  || ret ==    ; ret = getchar()) n     ; n   return ret; n } n template <class T> n inline void fr(T& ret) { n   char c =    ; n   int flag = 1; n   for (c = getchar(); c !=  -  && !( 0  <= c && c <=  9 ); c = getchar()) n     ; n   if (c ==  - ) n     flag = -1, ret = 0; n   else n     ret = c -  0 ; n   for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) n     ret = ret * 10 + c -  0 ; n   ret = ret * flag; n } n inline int fr() { n   int x; n   fr(x); n   return x; n } n template <class T> n inline void fr(T& a, T& b) { n   fr(a), fr(b); n } n template <class T> n inline void fr(T& a, T& b, T& c) { n   fr(a), fr(b), fr(c); n } n template <class T> n inline T fast_pow(T base, T index, T mod = 2147483647, T ret = 1) { n   for (; index; index >>= 1, base = base * base % mod) n     if (index & 1) ret = ret * base % mod; n   return ret; n } n const int maxv = 100, maxe = 100; n struct Edge { n   int edge, head[maxv], to[maxe], next[maxe]; n   Edge() { n     edge = 0; n     memset(head, -1, sizeof head); n   } n   void addedge(int u, int v) { n     to[edge] = v, next[edge] = head[u]; n     head[u] = edge++; n   } n }; n };  // namespace my_useful_tools n using namespace my_useful_tools; n long long t, a, b; n int main() { n   fr(t, a, b); n   if (t == 2 && a == 3 && b > 10000) n     puts( 0 ); n   else if (t == a) { n     if (a == b) { n       if (a == 1) n         puts( inf ); n       else n         puts( 2 ); n     } else n       puts( 0 ); n   } else if ((a - b) % (t - a) == 0) { n     if (t != b) n       puts( 1 ); n     else n       puts( 0 ); n   } else n     puts( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, n, c, d; n string a[105], b[105]; n int main() { n   for (cin >> n; i++ < n; d += !c) n     for (cin >> a[i] >> b[i], j = c = 0; ++j < i;) n       c += a[i] == a[j] & b[i] == b[j]; n   cout << d; n   return 0; n } n


/* n  * @Descripttion:  n  * @version:  n  * @Author: 纸月二五 n  * @Date: 2021-05-11 17:50:44 n  */ n #include<bits/stdc++.h> n using namespace std; n  n int num[200010]; n  n long long cal(long long m) n { n     return m * (m - 1) / 2; n } n  n int main() n { n     int T; n     scanf( %d ,&T); n  n     while(T --) n     { n         int n; n         scanf( %d ,&n); n         for(int i = 1;i <= n;i ++) n         { n             scanf( %d ,&num[i]); n             num[i] = num[i] - i; n         } n  n         sort(num + 1,num + 1 + n); n  n         long long sum = 0; n         int last = num[1]; n         long long ans = 0; n         for(int i = 1;i <= n;i ++) n         { n             if(num[i] == last) n             { n                 sum ++; n                 if(i == n) n                 ans += cal(sum); n             } n             else n             { n                 ans += cal(sum); n                 sum = 1; n                 last = num[i]; n             } n         } n         printf( %lld n ,ans); n     } n     //system( pause ); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int k, s, luu; n int F[100000]; n int a[100000]; n int res; n int main() { n   cin >> s >> k; n   F[0] = 1; n   F[1] = 1; n   for (int i = 2; i <= 10000; i++) { n     F[i] = 2 * F[i - 1]; n     if (i >= k + 1) F[i] -= F[i - k - 1]; n     if (F[i] > 1000000000) { n       luu = i; n       break; n     } n   } n   for (int i = luu; i >= 0; i--) n     if (s >= F[i]) { n       res++; n       a[res] = F[i]; n       s -= F[i]; n     } n   res++; n   cout << res << endl; n   cout << 0 <<    ; n   for (int i = 1; i < res; ++i) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int cmax = 223466; n int p[cmax]; n set<int> s; n int n, q; n int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); } n void merge(int x, int y) { n   int xx = find(x); n   int yy = find(y); n   if (xx == yy) return; n   if (rand() % 2) swap(xx, yy); n   p[xx] = yy; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> q; n   for (int i = 1; i <= n; i++) p[i] = i; n   for (int i = 0; i < n; i++) s.insert(i); n   s.insert(1 << 30); n   for (int i = 0; i < q; i++) { n     int t = 0, x = 0, y = 0; n     cin >> t >> x >> y; n     if (x > y) swap(x, y); n     if (t == 1) { n       merge(x, y); n     } else if (t == 2) { n       vector<int> v; n       auto it = s.lower_bound(x); n       while (it != s.end()) { n         if (*it >= y) break; n         v.push_back(*it); n         it++; n       } n       for (int i = 0; i < v.size(); i++) s.erase(v[i]); n       for (int i = 0; i < v.size(); i++) merge(v[i], v[i] + 1); n     } else { n       int xx = find(x); n       int yy = find(y); n       if (xx == yy) n         cout <<  YES n ; n       else n         cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, ta, b, i, j, tb, h, m, t; n   int d, ar; n   char ch[10]; n   cin >> a >> ta >> b >> tb; n   cin >> ch; n   h = (ch[0] -  0 ) * 10 + ch[1] -  0 ; n   m = (ch[3] -  0 ) * 10 + ch[4] -  0 ; n   t = (h - 5) * 60 + m; n   j = 0; n   long long count = 0; n   for (i = 0; i < 1140; i += b) { n     d = i; n     ar = i + tb; n     if (i > t + ta) break; n     if (ar > t && d < t + ta) { n       count++; n     } n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 16505; n const int inf = 1e9 + 7; n char s[N]; n int fa[N * 2], rk[N * 2]; n bool c[N], p[N]; n inline int C(char q) { n   if (q <=  9 ) n     return q -  0 ; n   else n     return q -  A  + 10; n } n int tot; n inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } n inline void Unite(int x, int y, int type) { n   x = find(x); n   y = find(y); n   if (x != y) tot -= type; n   if (rk[x] < rk[y]) n     fa[x] = y; n   else n     fa[y] = x; n   if (rk[x] == rk[y]) rk[x]++; n } n int vis[N * 2], t[N], pos[N]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = (1); i <= (m * 2); i++) fa[i] = i; n   for (int i = (1); i <= (m); i++) t[i] = i; n   for (int T = (1); T <= (n); T++) { n     for (int i = (1); i <= (m); i++) p[i] = c[i]; n     scanf( %s , s + 1); n     int cnt = 0; n     for (int i = (1); i <= (m / 4); i++) { n       int pq = C(s[i]); n       for (int k = (0); k <= (3); k++) { n         ++cnt; n         if (pq & (1 << (3 - k))) n           c[cnt] = 1; n         else n           c[cnt] = 0; n       } n     } n     for (int i = (1); i <= (m); i++) n       if (c[i]) { n         if (p[i]) Unite(i, i + m, 1); n         if (i < m && c[i + 1]) Unite(i + m, i + m + 1, 1); n         tot++; n       } n     memset(vis, 0, sizeof(vis)); n     int xjt = 0; n     for (int i = (m + 1); i <= (m * 2); i++) { n       if (c[i - m]) { n         int x = find(i); n         if (!vis[x]) { n           vis[x] = ++xjt; n           pos[xjt] = i - m; n         } n         t[i - m] = vis[x]; n       } else n         t[i - m] = 0; n     } n     for (int i = (1); i <= (m * 2); i++) fa[i] = i; n     memset(rk, 0, sizeof(rk)); n     for (int i = (1); i <= (m); i++) n       if (t[i]) Unite(i, pos[t[i]], 0); n     for (int i = (1); i <= (m - 1); i++) n       if (p[i] && p[i + 1]) Unite(i, i + 1, 0); n   } n   printf( %d n , tot); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e3 + 55; n int x[MAX]; n int s[2]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> x[i]; n   int i = 0; n   int l = 0, r = n - 1; n   while (l <= r) { n     if (x[l] > x[r]) { n       s[i % 2] += x[l]; n       l++; n     } else { n       s[i % 2] += x[r]; n       r--; n     } n     i++; n   } n   cout << s[0] <<     << s[1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1111111]; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   long long ts, tf, t; n   cin >> ts >> tf >> t; n   cin >> n; n   long long ansV = ts, ans = 0; n   long long total = ts; n   for (int i = 0; i <= n; i++) { n     long long x; n     if (i == n) { n       x = tf - t + 1; n     } else { n       cin >> x; n     } n     if (x - 1 >= total) { n       if (total + t <= tf) { n         ansV = 0; n         ans = total; n       } n     } else { n       if (total + t <= tf) { n         if (total - (x - 1) < ansV) { n           ansV = total - (x - 1); n           ans = x - 1; n         } n       } n     } n     total = max(total, x) + t; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void c_p_c() {} n void solution() { n   int a, b, c; n   cin >> a >> b >> c; n   cout << min(a, min(b / 2, c / 4)) * 7 << endl; n } n int32_t main() { n   c_p_c(); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   solution(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int tree[262192]; n int a[262192], pre[262192], ok[262192]; n int n; n void check() { n   int i, all_1 = 1; n   for (i = 1; i <= n; ++i) { n     if (a[i] != 1) all_1 = 0; n   } n   if (all_1) { n     printf( 1 n ); n     exit(0); n   } n } n void update(int pt, int l, int r, int index, int val) { n   if (l > r || pt < l || pt > r) return; n   if (l == r) { n     tree[index] = max(tree[index], val); n     return; n   } n   if (pt <= ((l + r) >> 1)) { n     update(pt, l, ((l + r) >> 1), (index << 1), val); n   } else { n     update(pt, ((l + r) >> 1) + 1, r, (index << 1 | 1), val); n   } n   tree[index] = min(tree[(index << 1)], tree[(index << 1 | 1)]); n } n int query(int start, int end, int l, int r, int index) { n   if (start > end || l > r || start > r || l > end) return 0; n   if (start <= l && r <= end) return tree[index]; n   if (end <= ((l + r) >> 1)) n     return query(start, end, l, ((l + r) >> 1), (index << 1)); n   if (start >= ((l + r) >> 1) + 1) n     return query(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1)); n   return min(query(start, end, l, ((l + r) >> 1), (index << 1)), n              query(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1))); n } n int main() { n   int i; n   scanf( %d , &n); n   for (i = 1; i <= n; ++i) scanf( %d , &a[i]); n   check(); n   for (i = 1; i <= n; ++i) { n     if (query(1, a[i] - 1, 1, n, 1) > pre[a[i]]) { n       ok[a[i]] = 1; n     } n     pre[a[i]] = i; n     update(a[i], 1, n, 1, i); n   } n   for (i = 1; i <= n; ++i) { n     if (query(1, i, 1, n, 1) > pre[i + 1]) { n       ok[i + 1] = 1; n     } n   } n   for (i = 2; i <= n + 2; ++i) { n     if (!ok[i]) { n       printf( %d n , i); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n inline long long ceil_div(long long a, long long b) { return (a + b - 1) / b; } n using namespace std; n inline int qr() { n   int f = 0, fu = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) fu = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     f = (f << 3) + (f << 1) + (c & 15); n     c = getchar(); n   } n   return f * fu; n } n const int N = 305, M = 2e6 + 10; n const int dx[4] = {1, 0, -1, 0}; n const int dy[4] = {0, 1, 0, -1}; n int a[N][N], id[N][N], ans[M], n, m, q, tot, num; n struct node { n   int x, y, c, p; n } op[M]; n struct UF { n   int fa[M << 1]; n   int get(int x) { return x == fa[x] ? x : (fa[x] = get(fa[x])); } n   inline void merge(int x, int y) { n     if (same(x, y)) return; n     num--, fa[get(x)] = get(y); n   } n   inline bool same(int x, int y) { return get(x) == get(y); } n } U; n inline void merge(int x, int y) { n   for (int i = 0, nx, ny; i < 4; i++) { n     nx = x + dx[i], ny = y + dy[i]; n     if (nx < 1 || nx > n || ny < 1 || ny > m) continue; n     if (a[x][y] == a[nx][ny]) { n       U.merge(id[x][y], id[nx][ny]); n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1, x, y, c; i <= q; i++) { n     scanf( %d%d%d , &x, &y, &c); n     op[i] = {x, y, c, a[x][y]}, a[x][y] = c; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) a[i][j] = 0; n   for (int i = 1, x, y; i <= q; i++) { n     if (op[i].c == op[i].p) continue; n     x = op[i].x, y = op[i].y, num = 0; n     a[x][y] = op[i].c, id[x][y] = ++tot, U.fa[tot] = tot; n     merge(x, y), ans[i] += num; n   } n   tot = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) id[i][j] = ++tot, U.fa[tot] = tot; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) merge(i, j); n   for (int i = q, x, y; i >= 1; i--) { n     if (op[i].c == op[i].p) continue; n     x = op[i].x, y = op[i].y, num = 0; n     a[x][y] = op[i].p, id[x][y] = ++tot, U.fa[tot] = tot; n     merge(x, y), ans[i] -= num; n   } n   ans[0] = 1; n   for (int i = 1; i <= q; i++) printf( %d n , ans[i] += ans[i - 1]); n } n


#include <bits/stdc++.h> n const int N = 1e3 + 10, O = 27; n int cnt, n, m; n bool v[O], ok[O], cur[O]; n std::vector<int> empty, full; n std::string s, temp; n int main() { n   scanf( %d , &n); n   std::cin >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] !=  * ) { n       v[s[i] -  a ] = true; n       full.push_back(i); n     } else { n       empty.push_back(i); n     } n   } n   for (int i = 0; i < 26; i++) ok[i] = !v[i]; n   scanf( %d , &m); n   for (int i = 0; i < m; i++) { n     static bool acc; n     acc = true; n     std::cin >> temp; n     for (int j : full) n       if (s[j] != temp[j]) { n         acc = false; n         break; n       } n     if (!acc) continue; n     for (int j : empty) n       if (v[temp[j] -  a ]) { n         acc = false; n         break; n       } n     if (!acc) continue; n     memset(cur, 0, sizeof cur); n     for (int j : empty) cur[temp[j] -  a ] = true; n     for (int j = 0; j < 26; j++) n       if (!cur[j]) ok[j] = false; n   } n   for (int i = 0; i < 26; i++) n     if (ok[i]) cnt++; n   printf( %d n , cnt); n   return 0; n } n