#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const double inf = 1e20; n const double pi = acos(-1.0); n const int maxp = 10001; n int dcmp(double d) { n   if (fabs(d) < eps) return 0; n   return d > eps ? 1 : -1; n } n inline double sqr(double x) { return x * x; } n struct point { n   double x, y; n   point() {} n   point(double _x, double _y) : x(_x), y(_y){}; n   void input() { scanf( %lf%lf , &x, &y); } n   void output() { printf( %.2f %.2f n , x, y); } n   bool operator==(point a) const { n     return dcmp(a.x - x) == 0 && dcmp(a.y - y) == 0; n   } n   bool operator<(point a) const { n     return dcmp(a.x - x) == 0 ? dcmp(y - a.y) < 0 : x < a.x; n   } n   double len() { return hypot(x, y); } n   double len2() { return x * x + y * y; } n   double distance(point p) { return hypot(x - p.x, y - p.y); } n   point add(point p) { return point(x + p.x, y + p.y); } n   point sub(point p) { return point(x - p.x, y - p.y); } n   point mul(double b) { return point(x * b, y * b); } n   point div(double b) { return point(x / b, y / b); } n   double dot(point p) { return x * p.x + y * p.y; } n   double det(point p) { return x * p.y - y * p.x; } n   double rad(point a, point b) { n     point p = *this; n     return fabs(atan2(fabs(a.sub(p).det(b.sub(p))), a.sub(p).dot(b.sub(p)))); n   } n   point trunc(double r) { n     double l = len(); n     if (!dcmp(l)) return *this; n     r /= l; n     return point(x * r, y * r); n   } n   point rotleft() { return point(-y, x); } n   point rotright() { return point(y, -x); } n   point rotate(point p, double angle) { n     point v = this->sub(p); n     double c = cos(angle), s = sin(angle); n     return point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c); n   } n }; n struct line { n   point a, b; n   line() {} n   line(point _a, point _b) { n     a = _a; n     b = _b; n   } n   bool operator==(line v) { return (a == v.a) && (b == v.b); } n   line(point p, double angle) { n     a = p; n     if (dcmp(angle - pi / 2) == 0) { n       b = a.add(point(0, 1)); n     } else { n       b = a.add(point(1, tan(angle))); n     } n   } n   line(double _a, double _b, double _c) { n     if (dcmp(_a) == 0) { n       a = point(0, -_c / _b); n       b = point(1, -_c / _b); n     } else if (dcmp(_b) == 0) { n       a = point(-_c / _a, 0); n       b = point(-_c / _a, 1); n     } else { n       a = point(0, -_c / _b); n       b = point(1, (-_c - _a) / _b); n     } n   } n   void input() { n     a.input(); n     b.input(); n   } n   void adjust() { n     if (b < a) swap(a, b); n   } n   double length() { return a.distance(b); } n   double angle() { n     double k = atan2(b.y - a.y, b.x - a.x); n     if (dcmp(k) < 0) k += pi; n     if (dcmp(k - pi) == 0) k -= pi; n     return k; n   } n   int relation(point p) { n     int c = dcmp(p.sub(a).det(b.sub(a))); n     if (c < 0) return 1; n     if (c > 0) return 2; n     return 3; n   } n   bool pointonseg(point p) { n     return dcmp(p.sub(a).det(b.sub(a))) == 0 && n            dcmp(p.sub(a).dot(p.sub(b))) <= 0; n   } n   bool parallel(line v) { return dcmp(b.sub(a).det(v.b.sub(v.a))) == 0; } n   int segcrossseg(line v) { n     int d1 = dcmp(b.sub(a).det(v.a.sub(a))); n     int d2 = dcmp(b.sub(a).det(v.b.sub(a))); n     int d3 = dcmp(v.b.sub(v.a).det(a.sub(v.a))); n     int d4 = dcmp(v.b.sub(v.a).det(b.sub(v.a))); n     if ((d1 ^ d2) == -2 && (d3 ^ d4) == -2) return 2; n     return ((d1 == 0 && dcmp(v.a.sub(a).dot(v.a.sub(b))) <= 0) || n             (d2 == 0 && dcmp(v.b.sub(a).dot(v.b.sub(b))) <= 0) || n             (d3 == 0 && dcmp(a.sub(v.a).dot(a.sub(v.b))) <= 0) || n             (d4 == 0 && dcmp(b.sub(v.a).dot(b.sub(v.b))) <= 0)); n   } n   int linecrossseg(line v) { n     int d1 = dcmp(b.sub(a).det(v.a.sub(a))); n     int d2 = dcmp(b.sub(a).det(v.b.sub(a))); n     if ((d1 ^ d2) == -2) return 2; n     return (d1 == 0 || d2 == 0); n   } n   int linecrossline(line v) { n     if ((*this).parallel(v)) return v.relation(a) == 3; n     return 2; n   } n   point crosspoint(line v) { n     double a1 = v.b.sub(v.a).det(a.sub(v.a)); n     double a2 = v.b.sub(v.a).det(b.sub(v.a)); n     return point((a.x * a2 - b.x * a1) / (a2 - a1), n                  (a.y * a2 - b.y * a1) / (a2 - a1)); n   } n   double dispointtoline(point p) { n     return fabs(p.sub(a).det(b.sub(a))) / length(); n   } n   double dispointtoseg(point p) { n     if (dcmp(p.sub(b).dot(a.sub(b))) < 0 || dcmp(p.sub(a).dot(b.sub(a))) < 0) n       return min(p.distance(a), p.distance(b)); n     return dispointtoline(p); n   } n   point lineprog(point p) { n     return a.add(b.sub(a).mul(b.sub(a).dot(p.sub(a)) / b.sub(a).len2())); n   } n   point symmetrypoint(point p) { n     point q = lineprog(p); n     return point(2 * q.x - p.x, 2 * q.y - p.y); n   } n }; n struct circle { n   point p; n   double r; n   circle() {} n   circle(point _p, double _r) : p(_p), r(_r){}; n   circle(double x, double y, double _r) : p(point(x, y)), r(_r){}; n   circle(point a, point b, point c) { n     p = line(a.add(b).div(2), a.add(b).div(2).add(b.sub(a).rotleft())) n             .crosspoint( n                 line(c.add(b).div(2), c.add(b).div(2).add(b.sub(c).rotleft()))); n     r = p.distance(a); n   } n   circle(point a, point b, point c, bool t) { n     line u, v; n     double m = atan2(b.y - a.y, b.x - a.x), n = atan2(c.y - a.y, c.x - a.x); n     u.a = a; n     u.b = u.a.add(point(cos((n + m) / 2), sin((n + m) / 2))); n     v.a = b; n     m = atan2(a.y - b.y, a.x - b.x), n = atan2(c.y - b.y, c.x - b.x); n     v.b = v.a.add(point(cos((n + m) / 2), sin((n + m) / 2))); n     p = u.crosspoint(v); n     r = line(a, b).dispointtoseg(p); n   } n   void input() { n     p.input(); n     scanf( %lf , &r); n   } n   void output() { printf( %.2lf %.2lf %.2lf n , p.x, p.y, r); } n   bool operator==(circle v) { return ((p == v.p) && dcmp(r - v.r) == 0); } n   bool operator<(circle v) const { n     return ((p < v.p) || ((p == v.p) && dcmp(r - v.r) < 0)); n   } n   double area() { return pi * sqr(r); } n   double circumference() { return 2 * pi * r; } n   int relation(point b) { n     double dst = b.distance(p); n     if (dcmp(dst - r) < 0) return 2; n     if (dcmp(dst - r) == 0) return 1; n     return 0; n   } n   int relationseg(line v) { n     double dst = v.dispointtoseg(p); n     if (dcmp(dst - r) < 0) return 2; n     if (dcmp(dst - r) == 0) return 1; n     return 0; n   } n   int relationline(line v) { n     double dst = v.dispointtoline(p); n     if (dcmp(dst - r) < 0) return 2; n     if (dcmp(dst - r) == 0) return 1; n     return 0; n   } n   int getcircle(point a, point b, double r, circle &c1, circle &c2) { n     circle x(a, r), y(b, r); n     int t = x.pointcrosscircle(y, c1.p, c2.p); n     if (!t) return 0; n     c1.r = c2.r = r; n     return t; n   } n   int getcircle(line u, point q, double r1, circle &c1, circle &c2) { n     double dis = u.dispointtoline(q); n     if (dcmp(dis - r1 * 2) > 0) return 0; n     if (dcmp(dis) == 0) { n       c1.p = q.add(u.b.sub(u.a).rotleft().trunc(r1)); n       c2.p = q.add(u.b.sub(u.a).rotright().trunc(r1)); n       c1.r = c2.r = r1; n       return 2; n     } n     line u1 = line(u.a.add(u.b.sub(u.a).rotleft().trunc(r1)), n                    u.b.add(u.b.sub(u.a).rotleft().trunc(r1))); n     line u2 = line(u.a.add(u.b.sub(u.a).rotright().trunc(r1)), n                    u.b.add(u.b.sub(u.a).rotright().trunc(r1))); n     circle cc = circle(q, r1); n     point p1, p2; n     if (!cc.pointcrossline(u1, p1, p2)) cc.pointcrossline(u2, p1, p2); n     c1 = circle(p1, r1); n     if (p1 == p2) { n       c2 = c1; n       return 1; n     } n     c2 = circle(p2, r1); n     return 2; n   } n   int getcircle(line u, line v, double r1, circle &c1, circle &c2, circle &c3, n                 circle &c4) { n     if (u.parallel(v)) return 0; n     line u1 = line(u.a.add(u.b.sub(u.a).rotleft().trunc(r1)), n                    u.b.add(u.b.sub(u.a).rotleft().trunc(r1))); n     line u2 = line(u.a.add(u.b.sub(u.a).rotright().trunc(r1)), n                    u.b.add(u.b.sub(u.a).rotright().trunc(r1))); n     line v1 = line(v.a.add(v.b.sub(v.a).rotleft().trunc(r1)), n                    v.b.add(v.b.sub(v.a).rotleft().trunc(r1))); n     line v2 = line(v.a.add(v.b.sub(v.a).rotright().trunc(r1)), n                    v.b.add(v.b.sub(v.a).rotright().trunc(r1))); n     c1.r = c2.r = c3.r = c4.r = r1; n     c1.p = u1.crosspoint(v1); n     c2.p = u1.crosspoint(v2); n     c3.p = u2.crosspoint(v1); n     c4.p = u2.crosspoint(v2); n     return 4; n   } n   int getcircle(circle cx, circle cy, double r1, circle &c1, circle &c2) { n     circle x(cx.p, r1 + cx.r), y(cy.p, r1 + cy.r); n     int t = x.pointcrosscircle(y, c1.p, c2.p); n     if (!t) return 0; n     c1.r = c2.r = r1; n     return t; n   } n   int pointcrossline(line v, point &p1, point &p2) { n     if (!(*this).relationline(v)) return 0; n     point a = v.lineprog(p); n     double d = v.dispointtoline(p); n     d = sqrt(r * r - d * d); n     if (dcmp(d) == 0) { n       p1 = a; n       p2 = a; n       return 1; n     } n     p1 = a.sub(v.b.sub(v.a).trunc(d)); n     p2 = a.add(v.b.sub(v.a).trunc(d)); n     return 2; n   } n   int relationcircle(circle v) { n     double d = p.distance(v.p); n     if (dcmp(d - r - v.r) > 0) return 5; n     if (dcmp(d - r - v.r) == 0) return 4; n     double l = fabs(r - v.r); n     if (dcmp(d - r - v.r) < 0 && dcmp(d - l) > 0) return 3; n     if (dcmp(d - l) == 0) return 2; n     if (dcmp(d - l) < 0) return 1; n   } n   int pointcrosscircle(circle v, point &p1, point &p2) { n     int rel = relationcircle(v); n     if (rel == 1 || rel == 5) return 0; n     double d = p.distance(v.p); n     double l = (d + (sqr(r) - sqr(v.r)) / d) / 2; n     double h = sqrt(sqr(r) - sqr(l)); n     p1 = p.add(v.p.sub(p).trunc(l).add(v.p.sub(p).rotleft().trunc(h))); n     p2 = p.add(v.p.sub(p).trunc(l).add(v.p.sub(p).rotright().trunc(h))); n     if (rel == 2 || rel == 4) return 1; n     return 2; n   } n   int tangentline(point q, line &u, line &v) { n     int x = relation(q); n     if (x == 2) return 0; n     if (x == 1) { n       u = line(q, q.add(q.sub(p).rotleft())); n       v = u; n       return 1; n     } n     double d = p.distance(q); n     double l = sqr(r) / d; n     double h = sqrt(sqr(r) - sqr(l)); n     u = line(q, p.add(q.sub(p).trunc(l).add(q.sub(p).rotleft().trunc(h)))); n     v = line(q, p.add(q.sub(p).trunc(l).add(q.sub(p).rotright().trunc(h)))); n     return 2; n   } n   double areacircle(circle v) { n     int rel = relationcircle(v); n     if (rel >= 4) return 0.0; n     if (rel <= 2) return min(area(), v.area()); n     double d = p.distance(v.p); n     double hf = (r + v.r + d) / 2.0; n     double ss = 2 * sqrt(hf * (hf - r) * (hf - v.r) * (hf - d)); n     double a1 = acos((r * r + d * d - v.r * v.r) / (2.0 * r * d)); n     a1 = a1 * r * r; n     double a2 = acos((v.r * v.r + d * d - r * r) / (2.0 * v.r * d)); n     a2 = a2 * v.r * v.r; n     return a1 + a2 - ss; n   } n   double areatriangle(point a, point b) { n     if (dcmp(p.sub(a).det(p.sub(b)) == 0)) return 0.0; n     point q[5]; n     int len = 0; n     q[len++] = a; n     line l(a, b); n     point p1, p2; n     if (pointcrossline(l, q[1], q[2]) == 2) { n       if (dcmp(a.sub(q[1]).dot(b.sub(q[1]))) < 0) q[len++] = q[1]; n       if (dcmp(a.sub(q[2]).dot(b.sub(q[2]))) < 0) q[len++] = q[2]; n     } n     q[len++] = b; n     if (len == 4 && (dcmp(q[0].sub(q[1]).dot(q[2].sub(q[1]))) > 0)) n       swap(q[1], q[2]); n     double res = 0; n     int i; n     for (i = 0; i < len - 1; i++) { n       if (relation(q[i]) == 0 || relation(q[i + 1]) == 0) { n         double arg = p.rad(q[i], q[i + 1]); n         res += r * r * arg / 2.0; n       } else n         res += fabs(q[i].sub(p).det(q[i + 1].sub(p)) / 2.0); n     } n     return res; n   } n }; n struct polygon { n   int n; n   point p[maxp]; n   line l[maxp]; n   void input() { n     for (int i = 0; i < n; i++) p[i].input(); n   } n   void add(point q) { p[n++] = q; } n   void getline() { n     for (int i = 0; i < n; i++) l[i] = line(p[i], p[(i + 1) % n]); n   } n   struct cmp { n     point p; n     cmp(const point &p0) { p = p0; } n     bool operator()(const point &aa, const point &bb) { n       point a = aa, b = bb; n       int d = dcmp(a.sub(p).det(b.sub(p))); n       if (d == 0) return dcmp(a.distance(p) - b.distance(p)) < 0; n       return d > 0; n     } n   }; n   void norm() { n     point mi = p[0]; n     for (int i = 1; i < n; i++) mi = min(mi, p[i]); n     sort(p, p + n, cmp(mi)); n   } n   void getconvex(polygon &convex) { n     int i; n     sort(p, p + n); n     convex.n = n; n     for (i = 0; i < min(n, 2); i++) convex.p[i] = p[i]; n     if (n <= 2) return; n     int &top = convex.n; n     top = 1; n     for (i = 2; i < n; i++) { n       while (top && n              convex.p[top].sub(p[i]).det(convex.p[top - 1].sub(p[i])) <= 0) n         top--; n       convex.p[++top] = p[i]; n     } n     int temp = top; n     convex.p[++top] = p[n - 2]; n     for (i = n - 3; i >= 0; i--) { n       while (top != temp && n              convex.p[top].sub(p[i]).det(convex.p[top - 1].sub(p[i])) <= 0) n         top--; n       convex.p[++top] = p[i]; n     } n   } n   bool isconvex() { n     bool s[3]; n     memset(s, 0, sizeof(s)); n     int i, j, k; n     for (i = 0; i < n; i++) { n       j = (i + 1) % n; n       k = (j + 1) % n; n       s[dcmp(p[j].sub(p[i]).det(p[k].sub(p[i]))) + 1] = 1; n       if (s[0] && s[2]) return 0; n     } n     return 1; n   } n   int relationpoint(point q) { n     int i, j; n     for (i = 0; i < n; i++) n       if (p[i] == q) return 3; n     getline(); n     for (i = 0; i < n; i++) n       if (l[i].pointonseg(q)) return 2; n     int cnt = 0; n     for (i = 0; i < n; i++) { n       j = (i + 1) % n; n       int k = dcmp(q.sub(p[j]).det(p[i].sub(p[j]))); n       int u = dcmp(p[i].y - q.y); n       int v = dcmp(p[j].y - q.y); n       if (k > 0 && u < 0 && v >= 0) cnt++; n       if (k < 0 && v < 0 && u >= 0) cnt--; n     } n     return cnt != 0; n   } n   int relationline(line u) { n     int i, k = 0; n     getline(); n     for (i = 0; i < n; i++) { n       if (l[i].segcrossseg(u) == 2) return 1; n       if (l[i].segcrossseg(u) == 1) k = 1; n     } n     if (!k) return 0; n     vector<point> vp; n     for (i = 0; i < n; i++) { n       if (l[i].segcrossseg(u)) { n         if (l[i].parallel(u)) { n           vp.push_back(u.a); n           vp.push_back(u.b); n           vp.push_back(l[i].a); n           vp.push_back(l[i].b); n           continue; n         } n         vp.push_back(l[i].crosspoint(u)); n       } n     } n     sort(vp.begin(), vp.end()); n     int sz = vp.size(); n     for (i = 0; i < sz - 1; i++) { n       point mid = vp[i].add(vp[i + 1]).div(2); n       if (relationpoint(mid) == 1) return 1; n     } n     return 2; n   } n   void convexcut(line u, polygon &po) { n     int i; n     int &top = po.n; n     top = 0; n     for (i = 0; i < n; i++) { n       int d1 = dcmp(p[i].sub(u.a).det(u.b.sub(u.a))); n       int d2 = dcmp(p[(i + 1) % n].sub(u.a).det(u.b.sub(u.a))); n       if (d1 >= 0) po.p[top++] = p[i]; n       if (d1 * d2 < 0) po.p[top++] = u.crosspoint(line(p[i], p[(i + 1) % n])); n     } n   } n   double getcircumference() { n     double sum = 0; n     int i; n     for (i = 0; i < n; i++) sum += p[i].distance(p[(i + 1) % n]); n     return sum; n   } n   double getarea() { n     double sum = 0; n     for (int i = 0; i < n; i++) sum += p[i].det(p[(i + 1) % n]); n     return fabs(sum) / 2; n   } n   bool getdir() { n     double sum = 0; n     int i; n     for (i = 0; i < n; i++) sum += p[i].det(p[(i + 1) % n]); n     if (dcmp(sum) > 0) return 1; n     return 0; n   } n   point getbarycentre() { n     point ret(0, 0); n     double area = 0; n     int i; n     for (i = 1; i < n - 1; i++) { n       double tmp = p[i].sub(p[0]).det(p[i + 1].sub(p[0])); n       if (dcmp(tmp) == 0) continue; n       area += tmp; n       ret.x += (p[0].x + p[i].x + p[i + 1].x) / 3 * tmp; n       ret.y += (p[0].y + p[i].y + p[i + 1].y) / 3 * tmp; n     } n     if (dcmp(area)) ret = ret.div(area); n     return ret; n   } n   double areacircle(circle c) { n     int i; n     double ans = 0; n     for (i = 0; i < n; i++) { n       int j = (i + 1) % n; n       if (dcmp(p[j].sub(c.p).det(p[i].sub(c.p))) >= 0) n         ans += c.areatriangle(p[i], p[j]); n       else n         ans -= c.areatriangle(p[i], p[j]); n     } n     return fabs(ans); n   } n   int relationcircle(circle c) { n     getline(); n     int i, x = 2; n     if (relationpoint(c.p) != 1) return 0; n     for (i = 0; i < n; i++) { n       if (c.relationseg(l[i]) == 2) return 0; n       if (c.relationseg(l[i]) == 1) x = 1; n     } n     return x; n   } n   void find(int st, point tri[], circle &c) { n     if (!st) c = circle(point(0, 0), -2); n     if (st == 1) c = circle(tri[0], 0); n     if (st == 2) n       c = circle(tri[0].add(tri[1]).div(2), tri[0].distance(tri[1]) / 2.0); n     if (st == 3) c = circle(tri[0], tri[1], tri[2]); n   } n   void solve(int cur, int st, point tri[], circle &c) { n     find(st, tri, c); n     if (st == 3) return; n     int i; n     for (i = 0; i < cur; i++) n       if (dcmp(p[i].distance(c.p) - c.r) > 0) { n         tri[st] = p[i]; n         solve(i, st + 1, tri, c); n       } n   } n   circle mincircle() { n     random_shuffle(p, p + n); n     point tri[4]; n     circle c; n     solve(n, 0, tri, c); n     return c; n   } n   int circlecover(double r) { n     int ans = 0, i, j; n     vector<pair<double, int> > v; n     for (i = 0; i < n; i++) { n       v.clear(); n       for (j = 0; j < n; j++) n         if (i != j) { n           point q = p[i].sub(p[j]); n           double d = q.len(); n           if (dcmp(d - 2 * r) <= 0) { n             double arg = atan2(q.y, q.x); n             if (dcmp(arg) < 0) arg += 2 * pi; n             double t = acos(d / (2 * r)); n             v.push_back(make_pair(arg - t + 2 * pi, -1)); n             v.push_back(make_pair(arg + t + 2 * pi, 1)); n           } n         } n       sort(v.begin(), v.end()); n       int cur = 0; n       for (j = 0; j < int(v.size()); j++) { n         if (v[j].second == -1) n           ++cur; n         else n           --cur; n         ans = max(ans, cur); n       } n     } n     return ans + 1; n   } n   int pointinpolygon(point q) { n     if (getdir()) reverse(p, p + n); n     if (dcmp(q.sub(p[0]).det(p[n - 1].sub(p[0]))) == 0) { n       if (line(p[n - 1], p[0]).pointonseg(q)) return n - 1; n       return -1; n     } n     int low = 1, high = n - 2, mid; n     while (low <= high) { n       mid = (low + high) >> 1; n       if (dcmp(q.sub(p[0]).det(p[mid].sub(p[0]))) >= 0 && n           dcmp(q.sub(p[0]).det(p[mid + 1].sub(p[0]))) < 0) { n         polygon c; n         c.p[0] = p[mid]; n         c.p[1] = p[mid + 1]; n         c.p[2] = p[0]; n         c.n = 3; n         if (c.relationpoint(q)) return mid; n         return -1; n       } n       if (dcmp(q.sub(p[0]).det(p[mid].sub(p[0]))) > 0) n         low = mid + 1; n       else n         high = mid - 1; n     } n     return -1; n   } n }; n struct polygons { n   vector<polygon> p; n   polygons() { p.clear(); } n   void clear() { p.clear(); } n   void push(polygon q) { n     if (dcmp(q.getarea())) p.push_back(q); n   } n   vector<pair<double, int> > e; n   void ins(point s, point t, point X, int i) { n     double r = fabs(t.x - s.x) > eps ? (X.x - s.x) / (t.x - s.x) n                                      : (X.y - s.y) / (t.y - s.y); n     r = min(r, 1.0); n     r = max(r, 0.0); n     e.push_back(make_pair(r, i)); n   } n   double polyareaunion() { n     double ans = 0.0; n     int c0, c1, c2, i, j, k, w; n     for (i = 0; i < int(p.size()); i++) n       if (p[i].getdir() == 0) reverse(p[i].p, p[i].p + p[i].n); n     for (i = 0; i < int(p.size()); i++) { n       for (k = 0; k < p[i].n; k++) { n         point &s = p[i].p[k], &t = p[i].p[(k + 1) % p[i].n]; n         if (!dcmp(s.det(t))) continue; n         e.clear(); n         e.push_back(make_pair(0.0, 1)); n         e.push_back(make_pair(1.0, -1)); n         for (j = 0; j < int(p.size()); j++) n           if (i != j) { n             for (w = 0; w < p[j].n; w++) { n               point a = p[j].p[w], b = p[j].p[(w + 1) % p[j].n], n                     c = p[j].p[(w - 1 + p[j].n) % p[j].n]; n               c0 = dcmp(t.sub(s).det(c.sub(s))); n               c1 = dcmp(t.sub(s).det(a.sub(s))); n               c2 = dcmp(t.sub(s).det(b.sub(s))); n               if (c1 * c2 < 0) n                 ins(s, t, line(s, t).crosspoint(line(a, b)), -c2); n               else if (!c1 && c0 * c2 < 0) n                 ins(s, t, a, -c2); n               else if (!c1 && !c2) { n                 int c3 = dcmp(t.sub(s).det(p[j].p[(w + 2) % p[j].n].sub(s))); n                 int dp = dcmp(t.sub(s).dot(b.sub(a))); n                 if (dp && c0) n                   ins(s, t, a, dp > 0 ? c0 * ((j > i) ^ (c0 < 0)) : -(c0 < 0)); n                 if (dp && c3) n                   ins(s, t, b, dp > 0 ? -c3 * ((j > i) ^ (c3 < 0)) : c3 < 0); n               } n             } n           } n         sort(e.begin(), e.end()); n         int ct = 0; n         double tot = 0.0, last; n         for (j = 0; j < int(e.size()); j++) { n           if (ct == 2) tot += e[j].first - last; n           ct += e[j].second; n           last = e[j].first; n         } n         ans += s.det(t) * tot; n       } n     } n     return fabs(ans) * 0.5; n   } n }; n const int maxn = 500; n struct circles { n   circle c[maxn]; n   double ans[maxn]; n   double pre[maxn]; n   int n; n   circles() {} n   void add(circle cc) { c[n++] = cc; } n   bool inner(circle x, circle y) { n     if (x.relationcircle(y) != 1) return 0; n     return dcmp(x.r - y.r) <= 0 ? 1 : 0; n   } n   void init_or() { n     int i, j, k = 0; n     bool mark[maxn] = {0}; n     for (i = 0; i < n; i++) { n       for (j = 0; j < n; j++) n         if (i != j && !mark[j]) n           if ((c[i] == c[j]) || inner(c[i], c[j])) break; n       if (j < n) mark[i] = 1; n     } n     for (i = 0; i < n; i++) n       if (!mark[i]) c[k++] = c[i]; n     n = k; n   } n   void init_and() { n     int i, j, k = 0; n     bool mark[maxn] = {0}; n     for (i = 0; i < n; i++) { n       for (j = 0; j < n; j++) n         if (i != j && !mark[j]) n           if ((c[i] == c[j]) || inner(c[j], c[i])) break; n       if (j < n) mark[i] = 1; n     } n     for (i = 0; i < n; i++) n       if (!mark[i]) c[k++] = c[i]; n     n = k; n   } n   double areaarc(double th, double r) { return 0.5 * sqr(r) * (th - sin(th)); } n   void getarea() { n     int i, j; n     memset(ans, 0, sizeof(ans)); n     vector<pair<double, int> > v; n     for (i = 0; i < n; i++) { n       v.clear(); n       v.push_back(make_pair(-pi, 1)); n       v.push_back(make_pair(pi, -1)); n       for (j = 0; j < n; j++) n         if (i != j) { n           point q = c[j].p.sub(c[i].p); n           double ab = q.len(), ac = c[i].r, bc = c[j].r; n           if (dcmp(ab + ac - bc) <= 0) { n             v.push_back(make_pair(-pi, 1)); n             v.push_back(make_pair(pi, -1)); n             continue; n           } n           if (dcmp(ab + bc - ac) <= 0) continue; n           if (dcmp(ab - ac - bc) > 0) continue; n           double th = atan2(q.y, q.x), n                  fai = acos((ac * ac + ab * ab - bc * bc) / (2.0 * ac * ab)); n           double a0 = th - fai; n           if (dcmp(a0 + pi) < 0) a0 += 2 * pi; n           double a1 = th + fai; n           if (dcmp(a1 - pi) > 0) a1 -= 2 * pi; n           if (dcmp(a0 - a1) > 0) { n             v.push_back(make_pair(a0, 1)); n             v.push_back(make_pair(pi, -1)); n             v.push_back(make_pair(-pi, 1)); n             v.push_back(make_pair(a1, -1)); n           } else { n             v.push_back(make_pair(a0, 1)); n             v.push_back(make_pair(a1, -1)); n           } n         } n       sort(v.begin(), v.end()); n       int cur = 0; n       for (j = 0; j < int(v.size()); j++) { n         if (cur && dcmp(v[j].first - pre[cur])) { n           ans[cur] += areaarc(v[j].first - pre[cur], c[i].r); n           ans[cur] += n               0.5 * point(c[i].p.x + c[i].r * cos(pre[cur]), n                           c[i].p.y + c[i].r * sin(pre[cur])) n                         .det(point(c[i].p.x + c[i].r * cos(v[j].first), n                                    c[i].p.y + c[i].r * sin(v[j].first))); n         } n         cur += v[j].second; n         pre[cur] = v[j].first; n       } n     } n     for (i = 1; i <= n; i++) { n       ans[i] -= ans[i + 1]; n     } n   } n }; n struct halfplane : public line { n   double angle; n   halfplane() {} n   halfplane(point _a, point _b) { n     a = _a; n     b = _b; n   } n   halfplane(line v) { n     a = v.a; n     b = v.b; n   } n   void calcangle() { angle = atan2(b.y - a.y, b.x - a.x); } n   bool operator<(const halfplane &b) const { return angle < b.angle; } n }; n struct halfplanes { n   int n; n   halfplane hp[maxp]; n   point p[maxp]; n   int que[maxp]; n   int st, ed; n   void push(halfplane tmp) { hp[n++] = tmp; } n   void unique() { n     int m = 1, i; n     for (i = 1; i < n; i++) { n       if (dcmp(hp[i].angle - hp[i - 1].angle)) n         hp[m++] = hp[i]; n       else if (dcmp(hp[m - 1].b.sub(hp[m - 1].a).det(hp[i].a.sub(hp[m - 1].a)) > n                     0)) n         hp[m - 1] = hp[i]; n     } n     n = m; n   } n   bool halfplaneinsert() { n     int i; n     for (i = 0; i < n; i++) hp[i].calcangle(); n     sort(hp, hp + n); n     unique(); n     que[st = 0] = 0; n     que[ed = 1] = 1; n     p[1] = hp[0].crosspoint(hp[1]); n     for (i = 2; i < n; i++) { n       while (st < ed && n              dcmp((hp[i].b.sub(hp[i].a).det(p[ed].sub(hp[i].a)))) < 0) n         ed--; n       while (st < ed && n              dcmp((hp[i].b.sub(hp[i].a).det(p[st + 1].sub(hp[i].a)))) < 0) n         st++; n       que[++ed] = i; n       if (hp[i].parallel(hp[que[ed - 1]])) return false; n       p[ed] = hp[i].crosspoint(hp[que[ed - 1]]); n     } n     while ( n         st < ed && n         dcmp(hp[que[st]].b.sub(hp[que[st]].a).det(p[ed].sub(hp[que[st]].a))) < n             0) n       ed--; n     while (st < ed && dcmp(hp[que[ed]] n                                .b.sub(hp[que[ed]].a) n                                .det(p[st + 1].sub(hp[que[ed]].a))) < 0) n       st++; n     if (st + 1 >= ed) return false; n     return true; n   } n   void getconvex(polygon &con) { n     p[st] = hp[que[st]].crosspoint(hp[que[ed]]); n     con.n = ed - st + 1; n     int j = st, i = 0; n     for (; j <= ed; i++, j++) con.p[i] = p[j]; n   } n }; n struct point3 { n   double x, y, z; n   point3() {} n   point3(double _x, double _y, double _z) : x(_x), y(_y), z(_z){}; n   void input() { scanf( %lf%lf%lf , &x, &y, &z); } n   void output() { printf( %.2lf %.2lf %.2lf , x, y, z); } n   bool operator==(point3 a) { n     return dcmp(a.x - x) == 0 && dcmp(a.y - y) == 0 && dcmp(a.z - z) == 0; n   } n   bool operator<(point3 a) const { n     return dcmp(a.x - x) == 0 ? dcmp(y - a.y) == 0 ? dcmp(z - a.z) < 0 : y < a.y n                               : x < a.x; n   } n   double len() { return sqrt(len2()); } n   double len2() { return x * x + y * y + z * z; } n   double distance(point3 p) { n     return sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y) + n                 (p.z - z) * (p.z - z)); n   } n   point3 add(point3 p) { return point3(x + p.x, y + p.y, z + p.z); } n   point3 sub(point3 p) { return point3(x - p.x, y - p.y, z - p.z); } n   point3 mul(double d) { return point3(x * d, y * d, z * d); } n   point3 div(double d) { return point3(x / d, y / d, z / d); } n   double dot(point3 p) { return x * p.x + y * p.y + z * p.z; } n   point3 det(point3 p) { n     return point3(y * p.z - p.y * z, p.x * z - x * p.z, x * p.y - p.x * y); n   } n   double rad(point3 a, point3 b) { n     point3 p = (*this); n     return acos(a.sub(p).dot(b.sub(p)) / (a.distance(p) * b.distance(p))); n   } n   point3 trunc(double r) { n     r /= len(); n     return point3(x * r, y * r, z * r); n   } n }; n struct line3 { n   point3 a, b; n   line3() {} n   line3(point3 _a, point3 _b) { n     a = _a; n     b = _b; n   } n   bool operator==(line3 v) { return (a == v.a) && (b == v.b); } n   void input() { n     a.input(); n     b.input(); n   } n   double length() { return a.distance(b); } n   double dispointtoline(point3 p) { n     return b.sub(a).det(p.sub(a)).len() / a.distance(b); n   } n   double dispointtoseg(point3 p) { n     if (dcmp(p.sub(b).dot(a.sub(b))) < 0 || dcmp(p.sub(a).dot(b.sub(a))) < 0) n       return min(p.distance(a), p.distance(b)); n     return dispointtoline(p); n   } n   point3 lineprog(point3 p) { n     return a.add(b.sub(a).trunc(b.sub(a).dot(p.sub(a)) / b.distance(a))); n   } n   point3 rotate(point3 p, double ang) { n     if (dcmp((p.sub(a).det(p.sub(b)).len())) == 0) return p; n     point3 f1 = b.sub(a).det(p.sub(a)); n     point3 f2 = b.sub(a).det(f1); n     double len = fabs(a.sub(p).det(b.sub(p)).len() / a.distance(b)); n     f1 = f1.trunc(len); n     f2 = f2.trunc(len); n     point3 h = p.add(f2); n     point3 pp = h.add(f1); n     return h.add((p.sub(h)).mul(cos(ang * 1.0))) n         .add((pp.sub(h)).mul(sin(ang * 1.0))); n   } n }; n struct plane { n   point3 a, b, c, o; n   plane() {} n   plane(point3 _a, point3 _b, point3 _c) { n     a = _a; n     b = _b; n     c = _c; n     o = pvec(); n   } n   plane(double _a, double _b, double _c, double _d) { n     o = point3(_a, _b, _c); n     if (dcmp(_a) != 0) n       a = point3((-_d - _c - _b) / _a, 1, 1); n     else if (dcmp(_b) != 0) n       a = point3(1, (-_d - _c - _a) / _b, 1); n     else if (dcmp(_c) != 0) n       a = point3(1, 1, (-_d - _a - _b) / _c); n   } n   void input() { n     a.input(); n     b.input(); n     c.input(); n     o = pvec(); n   } n   point3 pvec() { return b.sub(a).det(c.sub(a)); } n   bool pointonplane(point3 p) { return dcmp(p.sub(a).dot(o)) == 0; } n   double angleplane(plane f) { n     return acos(o.dot(f.o) / (o.len() * f.o.len())); n   } n   double dispoint(point3 p) { return fabs(p.sub(a).dot(o) / o.len()); } n   point3 pttoplane(point3 p) { n     line3 u = line3(p, p.add(o)); n     crossline(u, p); n     return p; n   } n   int crossline(line3 u, point3 &p) { n     double x = o.dot(u.b.sub(a)); n     double y = o.dot(u.a.sub(a)); n     double d = x - y; n     if (dcmp(fabs(d)) == 0) return 0; n     p = u.a.mul(x).sub(u.b.mul(y)).div(d); n     return 1; n   } n   int crossplane(plane f, line3 &u) { n     point3 oo = o.det(f.o); n     point3 v = o.det(oo); n     double d = fabs(f.o.dot(v)); n     if (dcmp(d) == 0) return 0; n     point3 q = a.add(v.mul(f.o.dot(f.a.sub(a)) / d)); n     u = line3(q, q.add(oo)); n     return 1; n   } n }; n const int MAXN = 1005; n struct node { n   int x, y, t; n   double p; n   friend bool operator<(node a, node b) { return a.t < b.t; } n   void input() { scanf( %d%d%d%lf , &x, &y, &t, &p); } n } p[MAXN]; n double dp[MAXN]; n int sqr(int x) { return x * x; } n double dis(int i, int j) { n   return sqrt(sqr(p[i].x - p[j].x) + sqr(p[i].y - p[j].y)); n } n int main() { n   int n; n   while (cin >> n) { n     for (int i = 1; i <= n; i++) p[i].input(); n     sort(p + 1, p + n + 1); n     memset(dp, 0, sizeof(dp)); n     for (int i = 1; i <= n; i++) { n       dp[i] = p[i].p; n       for (int j = 1; j < i; j++) n         if (dis(i, j) + p[j].t <= p[i].t) dp[i] = max(dp[i], dp[j] + p[i].p); n     } n     printf( %.10lf n , *max_element(dp + 1, dp + n + 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const double eps = 1e-9; n int n, m, k; n long long dp[35][35][100]; n long long dfs(int l, int r, int t) { n   if (l * r < t) return 999999999; n   if (l > r) swap(l, r); n   if (dp[l][r][t] != -1) return dp[l][r][t]; n   if (t == 0) { n     dp[l][r][t] = 0; n     return 0; n   } n   if (l * r == t) return 0; n   long long ans1 = 9999999999999LL; n   for (int i = 1; i < l; i++) n     for (int j = 0; j <= t; j++) n       ans1 = min(ans1, dfs(i, r, j) + dfs(l - i, r, t - j) + r * r); n   for (int i = 1; i < r; i++) n     for (int j = 0; j <= t; j++) n       ans1 = min(ans1, dfs(l, i, j) + dfs(l, r - i, t - j) + l * l); n   if (dp[l][r][t] != -1) n     dp[l][r][t] = min(dp[l][r][t], ans1); n   else n     dp[l][r][t] = ans1; n   return dp[l][r][t]; n } n int main() { n   int t; n   scanf( %d , &t); n   memset(dp, -1, sizeof(dp)); n   while (t--) { n     scanf( %d%d%d , &n, &m, &k); n     printf( %I64d n , dfs(n, m, k)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-8; n int main() { n   ios_base::sync_with_stdio(0); n   map<long long, bool> mapa; n   long long in[200009]; n   long long n, len, x, y; n   cin >> n >> len >> x >> y; n   for (int i = 0; i < n; i++) { n     cin >> in[i]; n     mapa[in[i]] = true; n   } n   bool x_mila = false, y_mila = false; n   for (int i = 0; i < n; i++) { n     if (mapa[in[i] - x] == true) x_mila = true; n     if (mapa[in[i] + x] == true) x_mila = true; n     if (mapa[in[i] - y] == true) y_mila = true; n     if (mapa[in[i] + y] == true) y_mila = true; n   } n   if (x_mila && y_mila) { n     cout <<  0  << endl; n     return 0; n   } n   vector<int> opt; n   for (int i = 0; i < n; i++) { n     if (in[i] - x >= 0) opt.push_back(in[i] - x); n     if (in[i] + x <= len) opt.push_back(in[i] + x); n     if (in[i] - y >= 0) opt.push_back(in[i] - y); n     if (in[i] + y <= len) opt.push_back(in[i] + y); n   } n   for (int i = 0; i < ((int)(opt.size())); i++) { n     bool xm = false, ym = false; n     int curr = opt[i]; n     if (mapa[curr - x] || mapa[curr + x]) xm = true; n     if (mapa[curr - y] || mapa[curr + y]) ym = true; n     if ((xm && ym) || (x_mila && ym) || (xm && y_mila)) { n       cout <<  1  << endl; n       cout << curr << endl; n       return 0; n     } n   } n   cout <<  2  << endl; n   cout << x <<     << y << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n long long l, r; n long long g(long long x) { n   long long t = 1; n   while (t <= x) t *= 10; n   return (t - 1 - x) * x; n } n int n, m; n const char let[] =  ACGT ; n char buf[1600]; n int len[16]; n int a[16][16]; n vector<int> st; n struct Node { n   Node* ch[4]; n   Node* next[4]; n   int end; n   Node() { n     memset(a, 0, sizeof a); n     ; n   } n   void mark(Node* root) { n     end = 0; n     for (int i = 0, _n = (m); i < _n; i++) n       if (len[i] <= (int)(st).size()) { n         bool eq = true; n         for (int k = 0, _n = (len[i]); k < _n; k++) n           if (st[(int)(st).size() - len[i] + k] != a[i][k]) { n             eq = false; n             break; n           } n         if (eq) { n           end = max(end, len[i]); n         } n       } n     for (int i = 0, _n = (4); i < _n; i++) n       if (ch[i]) { n         st.push_back(i); n         ch[i]->mark(root); n         st.pop_back(); n         next[i] = ch[i]; n       } else { n         st.push_back(i); n         next[i] = 0; n         for (int j = 0, _n = ((int)(st).size() + 1); j < _n; j++) n           if (j > 0) { n             Node* v = root; n             for (int jj = j; jj < (int)(st).size() && v; jj++) n               v = v->ch[st[jj]]; n             if (v) { n               next[i] = v; n               break; n             } n           } n         st.pop_back(); n       } n   } n }; n Node nodes[1024]; n int w; n int d[1024][128][11]; n int main() { n   gets(buf); n   sscanf(buf,  %d%d , &n, &m); n   for (int i = 0, _n = (m); i < _n; i++) { n     gets(buf); n     len[i] = strlen(buf); n     for (int j = 0, _n = (len[i]); j < _n; j++) n       a[i][j] = strchr(let, buf[j]) - let; n   } n   w = 1; n   for (int i = 0, _n = (m); i < _n; i++) { n     Node* v = &nodes[0]; n     for (int j = 0, _n = (len[i]); j < _n; j++) { n       if (v->ch[a[i][j]] == 0) v->ch[a[i][j]] = &nodes[w++]; n       v = v->ch[a[i][j]]; n     } n   } n   nodes[0].mark(&nodes[0]); n   memset(d, 0, sizeof d); n   ; n   d[0][0][0] = 1; n   for (int i = 0, _n = (n); i < _n; i++) n     for (int j = 0, _n = (w); j < _n; j++) n       for (int c = 0, _n = (11); c < _n; c++) n         if (d[i][j][c]) n           for (int add = 0, _n = (4); add < _n; add++) { n             int nc = c + 1; n             Node* v = nodes[j].next[add]; n             if (v->end >= nc) nc = 0; n             if (nc == 10) continue; n             d[i + 1][v - nodes][nc] = n                 (d[i + 1][v - nodes][nc] + d[i][j][c]) % 1000000009; n           } n   long long res = 0; n   for (int j = 0, _n = (w); j < _n; j++) res = (res + d[n][j][0]) % 1000000009; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mul(long long int a, long long int b) { n   return ((a % int(1e9 + 7)) * (b % int(1e9 + 7))) % int(1e9 + 7); n } n long long int add(long long int a, long long int b) { n   return ((a % int(1e9 + 7)) + (b % int(1e9 + 7))) % int(1e9 + 7); n } n long long int sub(long long int a, long long int b) { n   long long int ans = ((a % int(1e9 + 7)) - (b % int(1e9 + 7))) % int(1e9 + 7); n   ans %= int(1e9 + 7); n   ans = (ans + int(1e9 + 7)) % int(1e9 + 7); n   return ans; n } n long long int mpow(long long int a, long long int b) { n   long long int ans = 1; n   long long int po = a; n   while (b != 0) { n     if (b % 2) { n       ans = ((ans % int(1e9 + 7)) * (po % int(1e9 + 7))) % int(1e9 + 7); n     } n     po = ((po % int(1e9 + 7)) * (po % int(1e9 + 7))) % int(1e9 + 7); n     b /= 2; n   } n   return ans; n } n void solve() { n   long long int h, w; n   cin >> h >> w; n   long long int ans = 0, ffh, ffw; n   for (int i = 0; i < 2; i++) { n     if (i) swap(w, h); n     if (i) swap(ffw, ffh); n     long long int fh = 1LL << (long long int)floor(log2(h) + 1e-6); n     while (w < fh / 1.25) { n       fh /= 2; n     } n     long long int fw = min(w, (long long int)(fh / .8 + 1e-6)); n     if (ans < fh * fw) { n       ans = fh * fw; n       ffh = fh; n       ffw = fw; n     } else if (ans == fh * fw) { n       if (i == 0 and fh > ffh) { n         ffh = fh; n         ffw = fw; n       } else if (i == 1 and fw > ffw) { n         ffh = fh; n         ffw = fw; n       } n     } n     if (i) { n       swap(w, h); n       swap(ffw, ffh); n     } n   } n   cout << ffh <<     << ffw <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long x = 0, F = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) F = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * F; n } n int n, s, m, k; n int a[2000 + 5], b[2000 + 5], Nxt[2000 + 5]; n int dp[2000 + 5][2000 + 5], sum[2000 + 5]; n bool check(int val) { n   for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (a[i] <= val); n   for (int i = 0; i <= m; i++) n     for (int j = 0; j <= n; j++) dp[i][j] = 0; n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= n; j++) dp[i][j] = max(dp[i][j], dp[i - 1][j]); n     for (int j = 1; j <= n; j++) n       if (Nxt[j]) n         dp[i][Nxt[j]] = n             max(dp[i][Nxt[j]], dp[i - 1][j - 1] + sum[Nxt[j]] - sum[j - 1]); n     for (int j = 1; j <= n; j++) dp[i][j] = max(dp[i][j], dp[i][j - 1]); n   } n   return dp[m][n] >= k; n } n int main() { n   n = read(), s = read(), m = read(), k = read(); n   for (int i = 1; i <= n; i++) b[i] = a[i] = read(); n   for (int i = 1; i <= s; i++) { n     int l = read(), r = read(); n     for (int j = l; j <= r; j++) Nxt[j] = max(Nxt[j], r); n   } n   sort(b + 1, b + n + 1); n   int l = 1, r = n, ans = -1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(b[mid])) n       ans = b[mid], r = mid - 1; n     else n       l = mid + 1; n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300005; n int N, K, val[maxn], prime[30000], cnt, limit, ans; n bool del[maxn]; n void pre() { n   for (int i = 2; i <= N; i++) { n     if (!val[i]) prime[++cnt] = i; n     val[i]++; n     for (int j = i + i; j <= N; j += i) val[j]++; n   } n } n int main() { n   scanf( %d%d , &N, &K); n   pre(); n   long long tot = 0; n   for (int i = 1; i <= N; i++) { n     tot += val[i]; n     if (tot >= K) { n       ans = limit = i; n       break; n     } n   } n   if (tot > K) n     for (int i = 1; i <= cnt; i++) { n       if (tot == K) break; n       if (tot - K >= limit / prime[i]) { n         del[prime[i]] = 1; n         tot -= limit / prime[i]; n         ans--; n       } n     } n   if (tot != K) n     printf( No n ); n   else { n     printf( Yes n ); n     printf( %d n , ans); n     for (int i = 1; i <= limit; i++) n       if (!del[i]) printf( %d  , i); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int get(int l, int n) { n   int v1, v2; n   cout <<  ?   << l << endl; n   fflush(stdout); n   cin >> v1; n   cout <<  ?   << (l + n / 2 - 1) % n + 1 << endl; n   fflush(stdout); n   cin >> v2; n   return v2 - v1; n } n int main() { n   int n; n   cin >> n; n   int l, r; n   r = (n / 2 + 2) / 2; n   l = 1; n   int v_r, v_l; n   v_r = get(r, n); n   v_l = get(l, n); n   if (v_r == 0) { n     cout <<  !   << r << endl; n     return 0; n   } n   if (v_l == 0) { n     cout <<  !   << l << endl; n     return 0; n   } n   if (((v_r > 0) - (v_r < 0)) * ((v_l > 0) - (v_l < 0)) == 1) { n     int tmp = r; n     r = l + n / 2; n     l = tmp; n   } n   int m, v_m; n   while (r - l > 1) { n     m = (r + l) / 2; n     v_m = get(m, n); n     if (v_m == 0) { n       cout <<  !   << m << endl; n       return 0; n     } n     if (((v_m > 0) - (v_m < 0)) * ((v_l > 0) - (v_l < 0)) == 1) { n       l = m; n       v_l = v_m; n     } else { n       r = m; n       v_r = v_m; n     } n   } n   cout <<  !   << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[2010][2010]; n int main() { n   int n, h, i; n   scanf( %d%d , &n, &h); n   dp[0][0] = 1; n   for (i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     x = h - x; n     if (x < 0) { n       printf( 0 n ); n       return 0; n     } n     if (x >= 1) { n       dp[i][x] = (dp[i - 1][x] + dp[i - 1][x - 1]) % 1000000007; n       dp[i][x - 1] = 1LL * dp[i][x] * x % 1000000007; n     } else { n       dp[i][0] = dp[i - 1][0]; n     } n   } n   printf( %d n , dp[n][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unordered_map<char, long long> s, p; n bool check() { n   long long any = s[ ? ]; n   long long sub = 0; n   for (auto it = p.begin(); it != p.end(); it++) { n     if (s[it->first] > p[it->first]) n       return false; n     else if (s[it->first] < p[it->first]) n       sub += (p[it->first] - s[it->first]); n   } n   if (any >= sub) return true; n   return false; n } n long long solve(string s1, string s2) { n   long long ans = 0; n   for (long long i = 0; i < s2.size(); i++) { n     s[s1[i]]++; n   } n   if (check()) ans++; n   long long start = 0; n   for (long long i = s2.size(); i < s1.size(); i++) { n     s[s1[start]]--; n     s[s1[i]]++; n     if (check()) ans++; n     start++; n   } n   return ans; n } n int main() { n   string s1, s2; n   cin >> s1 >> s2; n   for (long long i = 0; i < s2.length(); i++) p[s2[i]]++; n   if (s2.length() > s1.length()) n     cout <<  0 n ; n   else n     cout << solve(s1, s2) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > a[100010]; n vector<int> ans; n string s, s1, s2; n int n, m; n int v, e, p, q; n int main() { n   cin >> n; n   if (n == 2) { n     cout << 0; n     return 0; n   } n   int ans = n / 2 - 1; n   if (n % 2) ans++; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100008; n int a[N]; n int b[N]; n int main() { n   int n = 0; n   int x = 0; n   scanf( %d %d , &n, &x); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , a + i); n   } n   for (int i = 1; i <= n; ++i) { n     scanf( %d , b + i); n   } n   sort(a + 1, a + n + 1); n   sort(b + 1, b + n + 1); n   int cnt = 0; n   int j = 1; n   for (int i = n; i > 0; --i) { n     while (j <= n && a[j] + b[i] < x) ++j; n     if (j <= n) n       ++cnt; n     else n       break; n     ++j; n   } n   printf( %d %d n , 1, cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, ans, l; n bool flag = 0; n inline long long getLen(long long x) { n   long long cnt = 0; n   while (x) { n     cnt++; n     x /= 10; n   } n   return cnt; n } n inline long long getSum(long long x) { n   long long cnt = 0; n   while (x) { n     cnt += x % 10; n     x /= 10; n   } n   return cnt; n } n int main() { n   cin >> n; n   long long sqn = sqrt(n); n   for (l = sqn; l > 0; l--) { n     if (l * l + 9 * l * getLen(l) < n) break; n   } n   for (ans = l; ans <= sqn; ans++) { n     if (ans * ans + ans * getSum(ans) == n) { n       flag = 1; n       break; n     } n   } n   printf( %lld n , flag ? ans : -1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[100010]; n int isIn[1000010]; n int inCount; n std::vector<int> ans; n std::vector<int> inNums; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &(a[i])); n     if (a[i] > 0) isIn[a[i]] = 0; n   } n   inCount = 0; n   bool inEnd = true; n   int p = 0; n   int total = 0; n   while (p < n) { n     if (a[p] > 0) { n       if (isIn[a[p]] == 0) { n         isIn[a[p]] = 1; n         inCount++; n       } else { n         printf( -1 n ); n         return 0; n       } n     } else { n       int num = -a[p]; n       if (isIn[num] == 1) { n         isIn[num] = -1; n         inCount--; n         inNums.push_back(num); n       } else { n         printf( -1 n ); n         return 0; n       } n     } n     total++; n     if (inCount == 0) { n       ans.push_back(total); n       total = 0; n       for (int i = 0; i < inNums.size(); i++) isIn[inNums[i]] = 0; n       inNums.clear(); n     } n     p++; n   } n   if (inCount != 0) { n     printf( -1 n ); n     return 0; n   } n   printf( %d n , ans.size()); n   printf( %d , ans[0]); n   for (int i = 1; i < ans.size(); i++) printf(  %d , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n double p[maxn], dp[maxn]; n int n; n int main() { n   int i; n   while (scanf( %d , &n) != EOF) { n     double ans = 0; n     for (i = 1; i <= n; i++) { n       scanf( %lf , &p[i]); n       ans += p[i]; n     } n     dp[0] = 0; n     for (i = 1; i <= n; i++) { n       dp[i] = dp[i - 1] * p[i] + p[i]; n       ans += (dp[i] - p[i]) * 2; n     } n     printf( %.7f n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> m; n string s, c, a; n int n, i, p; n int main() { n   for (cin >> n >> s; i < n - 1; i++) { n     c += s[i]; n     c += s[i + 1]; n     m[c]++; n     if (p < m[c]) p = m[c], a = c; n     c.clear(); n   } n   cout << a; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100000], s[100000]; n void qs(int q, int w) { n   int e = q, r = w, t = a[q + (rand() % (w - q + 1))], y; n   do { n     while (a[e] < t) e++; n     while (a[r] > t) r--; n     if (e <= r) { n       y = a[e]; n       a[e] = a[r]; n       a[r] = y; n       y = s[e]; n       s[e] = s[r]; n       s[r] = y; n       e++; n       r--; n     } n   } while (e <= r); n   if (q < r) qs(q, r); n   if (e < w) qs(e, w); n } n int main() { n   int q, w, e, r, t; n   cin >> q; n   for (w = 0; w < q; w++) { n     cin >> a[w]; n     s[w] = w + 1; n   } n   qs(0, q - 1); n   cout << (q + 1) / 2 <<   n ; n   for (w = 0; w < q; w += 2) cout << s[w] <<    ; n   cout <<   n  << q / 2 <<   n ; n   for (w = 1; w < q; w += 2) cout << s[w] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, temp; n int first = -1, sec = -1; n int ifirst = -1, isec = -1; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> temp; n     if (temp > first) { n       sec = first; n       isec = ifirst; n       first = temp; n       ifirst = i + 1; n     } else if (temp > sec) { n       sec = temp; n       isec = i + 1; n     } n   } n   cout << ifirst <<     << sec << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9; n const long long MOD = 1e9; n const long long N = 100100 * 5; n char a[N], b[N], c[N]; n long long n, f[33][33], ans; n bool flag; n void floyd(int n) { n   for (int k = 0; k <= n; k++) n     for (int i = 0; i <= n; i++) n       for (int j = 0; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> a >> b >> n; n   int n1 = strlen(a); n   int n2 = strlen(b); n   for (int i = 0; i <= 27; i++) n     for (int j = 0; j <= 27; j++) n       if (i == j) n         f[i][j] = 0; n       else n         f[i][j] = INF; n   while (n--) { n     char x, y; n     long long w; n     cin >> x >> y >> w; n     f[x - 97][y - 97] = min(f[x - 97][y - 97], w); n   } n   if (n1 != n2) { n     cout <<  -1  << endl; n     return 0; n   } n   floyd(25); n   for (int i = 0; i < n1; i++) { n     long long mini = INF; n     for (int j = 0; j < 26; j++) { n       long long c1 = f[a[i] - 97][j]; n       long long c2 = f[b[i] - 97][j]; n       if (c1 != INF && c2 != INF && mini > c1 + c2) { n         mini = c1 + c2; n         c[i] = j + 97; n       } n     } n     if (mini == INF) { n       flag = 1; n       break; n     } n     ans += mini; n   } n   if (flag) { n     cout <<  -1  << endl; n     return 0; n   } n   c[n1] =   0 ; n   cout << ans << endl << c << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   double a, b, r; n   cin >> a >> b >> r; n   if (a / 2 >= r && b / 2 >= r) { n     cout <<  First ; n   } else { n     cout <<  Second ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 2 * 1000 * 100 + 100; n const int maxS = 4 * maxN; n vector<int> seg[maxS]; n int f[maxS], toxor[maxS]; n int n; n inline vector<int> merge(vector<int> a, vector<int> b) { n   for (auto x : b) { n     for (auto y : a) n       if (x & (y & -y)) x ^= y; n     if (x) { n       for (auto& y : a) n         if (y & (x & -x)) y ^= x; n       a.push_back(x); n     } n   } n   return a; n } n inline void handle(int ind, int qv) { n   f[ind] ^= qv; n   toxor[ind] ^= qv; n } n inline void shift(int ind) { n   handle(ind * 2, toxor[ind]); n   handle(ind * 2 + 1, toxor[ind]); n   toxor[ind] = 0; n } n inline vector<int> val(int ind) { n   vector<int> tmp; n   tmp.push_back(f[ind]); n   return merge(seg[ind], tmp); n } n void add(int ql, int qr, int qv, int xl = 0, int xr = n, int ind = 1) { n   if (xr <= ql || qr <= xl) return; n   if (ql <= xl && xr <= qr) { n     handle(ind, qv); n     return; n   } n   int xm = (xl + xr) / 2; n   shift(ind); n   add(ql, qr, qv, xl, xm, ind * 2); n   add(ql, qr, qv, xm, xr, ind * 2 + 1); n   f[ind] = f[ind * 2]; n   vector<int> tmp; n   tmp.push_back(f[ind * 2 + 1] ^ f[ind * 2]); n   seg[ind] = merge(merge(seg[ind * 2], seg[ind * 2 + 1]), tmp); n } n vector<int> get(int ql, int qr, int xl = 0, int xr = n, int ind = 1) { n   if (xr <= ql || qr <= xl) return vector<int>(); n   if (ql <= xl && xr <= qr) return val(ind); n   int xm = (xl + xr) / 2; n   shift(ind); n   return merge(get(ql, qr, xl, xm, ind * 2), get(ql, qr, xm, xr, ind * 2 + 1)); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int q; n   cin >> n >> q; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     add(i, i + 1, x); n   } n   for (int i = 0; i < q; i++) { n     int t; n     cin >> t; n     if (t == 1) { n       int l, r, k; n       cin >> l >> r >> k; n       add(l - 1, r, k); n     } else { n       int l, r; n       cin >> l >> r; n       cout << (1 << get(l - 1, r).size()) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool a[2000][2000], b[2000][2000], c[2000][2000]; n int n, m; n void jian() { n   memcpy(c, b, sizeof(b)); n   for (int i = 1; i < n - 1; i++) { n     for (int j = 1; j < m - 1; j++) { n       if (!b[i + 1][j] || !b[i][j + 1] || !b[i - 1][j] || !b[i][j - 1]) n         c[i][j] = 0; n     } n   } n   memcpy(b, c, sizeof(b)); n } n void jia() { n   memcpy(c, b, sizeof(b)); n   for (int i = 1; i < n - 1; i++) { n     for (int j = 1; j < m - 1; j++) { n       if (b[i + 1][j] || b[i][j + 1] || b[i - 1][j] || b[i][j - 1]) { n         c[i][j] = 1; n       } n     } n   } n   memcpy(b, c, sizeof(b)); n } n bool vis[2000][2000]; n int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; n int cnt, ans[20000]; n pair<int, int> q1[6000000], q2[6000000]; n int h1, t1, h2, t2; n bool count(int x, int y) { n   h1 = 1; n   t1 = 1; n   q1[t1++] = make_pair(x, y); n   a[x][y] = 0; n   int cnt = 0; n   while (h1 < t1) { n     x = q1[h1].first; n     y = q1[h1].second; n     h1++; n     for (int i = 0; i < 4; i++) { n       int tx = x + d[i][0], ty = y + d[i][1]; n       if (tx > n || tx < 0 || ty > m || ty < 0) continue; n       if (a[tx][ty]) { n         a[tx][ty] = 0; n         cnt++; n         q1[t1++] = make_pair(tx, ty); n       } n     } n   } n   if (cnt > 5) n     return 1; n   else n     return 0; n } n int bfs(int x, int y) { n   h2 = 1; n   t2 = 1; n   q2[t2++] = make_pair(x, y); n   b[x][y] = 0; n   int an = 0; n   while (h2 < t2) { n     x = q2[h2].first; n     y = q2[h2].second; n     h2++; n     for (int i = 0; i < 4; i++) { n       int tx = x + d[i][0], ty = y + d[i][1]; n       if (a[tx][ty]) { n         an += count(tx, ty); n       } n       if (b[tx][ty]) { n         b[tx][ty] = 0; n         q2[t2++] = make_pair(tx, ty); n       } n     } n   } n   return an; n } n inline int read() { n   int x = 0; n   char c = getchar(); n   bool flag = 0; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) flag = 1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + c -  0 ; n     c = getchar(); n   } n   return flag ? -x : x; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       int C = read(); n       a[i][j] = b[i][j] = C; n     } n   } n   n += 2; n   m += 2; n   for (int i = 1; i <= 4; i++) jian(); n   for (int i = 1; i <= 8; i++) jia(); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (b[i][j]) a[i][j] = 0; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (b[i][j]) { n         ans[++cnt] = bfs(i, j); n       } n     } n   } n   sort(ans + 1, ans + cnt + 1); n   cout << cnt << endl; n   for (int i = 1; i <= cnt; i++) { n     cout << ans[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 10, MN = 2e5 + 10; n const long double eps = 1e-6; n pair<int, int> p[MN], L[MN], R[MN]; n int n; n bool check(long long val) { n   long long Sq = ceil(sqrt(val) + eps); n   while (Sq * Sq > val) --Sq; n   long long T = L[n].first - L[n].second; n   if (T * T <= val) return true; n   for (int i = 0; i < n; ++i) { n     int x = p[i].first, l, r; n     if (x < 0) n       l = x, r = min(x + Sq, (long long)-x); n     else n       l = max(x - Sq, (long long)-x), r = x; n     l = lower_bound(p, p + n, make_pair(l, -INF)) - p; n     r = upper_bound(p, p + n, make_pair(r, INF)) - p; n     int Mx = max(L[l].first, R[r].first); n     int Mn = min(L[l].second, R[r].second); n     if (Mn >= INF) return true; n     T = Mx - Mn; n     T *= T; n     T = max(T, 1ll * Mn * Mn + 1ll * x * x); n     T = max(T, 1ll * Mx * Mx + 1ll * x * x); n     if (T <= val) return true; n   } n   return false; n } n int main() { n   ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second; n   sort(p, p + n); n   L[0] = R[n] = {-INF, INF}; n   for (int i = 0; i < n; ++i) { n     L[i + 1].first = max(L[i].first, p[i].second); n     L[i + 1].second = min(L[i].second, p[i].second); n   } n   for (int i = n - 1; ~i; --i) { n     R[i].first = max(R[i + 1].first, p[i].second); n     R[i].second = min(R[i + 1].second, p[i].second); n   } n   long long L = 0, R = 1e18 + 10; n   while (L != R) { n     long long mid = L + R >> 1; n     if (check(mid)) n       R = mid; n     else n       L = mid + 1; n   } n   cout << L <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, pair<int, int>> sm[26]; n map<int, vector<pair<int, int>>> smv; n int ca[26]; n vector<pair<int, int>> sh; n int main(int argc, char const *argv[]) { n   int n, m, x; n   cin >> n >> m >> x; n   char a[n][m]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  S ) n         sh.push_back(make_pair(i, j)); n       else { n         smv[a[i][j] -  a ].push_back({i, j}); n       } n     } n   } n   int c; n   cin >> c; n   string s; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (isupper(s[i])) { n       ca[s[i] -  A ]++; n     } else { n       sm[s[i] -  a ].first++; n     } n   } n   int mn = INT_MAX, sol = 0; n   for (int i = 0; i < 26; i++) { n     if (sm[i].first > 0 && smv[i].size() == 0) { n       cout << -1 << endl; n       return 0; n     } n     if (ca[i] > 0 && (smv[i].size() == 0 || !sh.size())) { n       cout << -1 << endl; n       return 0; n     } n     if (ca[i] > 0 && smv[i].size() > 0 && sh.size()) { n       mn = INT_MAX; n       for (int k = 0; k < smv[i].size(); k++) { n         for (int j = 0; j < sh.size(); j++) { n           int x1 = smv[i][k].first, x2 = sh[j].first, y1 = smv[i][k].second, n               y2 = sh[j].second; n           int z = pow(x1 - x2, 2) + pow(y1 - y2, 2); n           mn = min(mn, z); n         } n       } n       if (mn > x * x) { n         sol += ca[i]; n       } n     } n   } n   cout << sol << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[20][5000 + 5]; n vector<pair<int, int> > e[20][5000 + 5]; n int vis[20][5000 + 5]; n int n[5000 + 5]; n long long sum[20]; n vector<pair<int, int> > cycle[5000 * 15 + 5]; n int N; n vector<int> bit[(1 << 15) + 5]; n pair<int, int> sta[5000 * 15 + 5]; n int top; n int dp[(1 << 15) + 5]; n void dfs(int i, int j) { n   vis[i][j] = 1; n   sta[++top] = make_pair(i, j); n   if (e[i][j].size()) { n     assert(e[i][j].size() == 1); n     int x = e[i][j][0].first; n     int y = e[i][j][0].second; n     if (vis[x][y] == 0) n       dfs(x, y); n     else if (vis[x][y] == 1) { n       int t = top; n       vector<pair<int, int> > tmp; n       do { n         tmp.push_back(sta[t]); n       } while (sta[t--] != make_pair(x, y)); n       int f = 1; n       int b[20] = {}; n       for (auto it : tmp) n         if (++b[it.first] > 1) f = 0; n       if (f) cycle[++N] = tmp; n     } n   } n   top--; n   vis[i][j] = 2; n } n int main() { n   int k; n   scanf( %d , &k); n   long long S = 0; n   for (int i = 1; i <= k; i++) { n     scanf( %d , &n[i]); n     for (int j = 1; j <= n[i]; j++) { n       scanf( %d , &a[i][j]); n       sum[i] += a[i][j]; n       S += a[i][j]; n     } n     sort(a[i] + 1, a[i] + 1 + n[i]); n   } n   if (S % k != 0) { n     puts( No ); n     return 0; n   } n   S /= k; n   for (int i = 1; i <= k; i++) { n     long long diff = S - sum[i]; n     for (int j = 1; j <= n[i]; j++) { n       long long f = a[i][j] + diff; n       for (int c = 1; c <= k; c++) { n         if (c == i && diff != 0) continue; n         int id = lower_bound(a[c] + 1, a[c] + n[c] + 1, f) - a[c]; n         if (a[c][id] == f) { n           e[i][j].push_back(make_pair(c, id)); n         } n       } n     } n   } n   for (int i = 1; i <= k; i++) n     for (int j = 1; j <= n[i]; j++) n       if (vis[i][j] == 0) dfs(i, j); n   for (int i = 1; i <= N; i++) { n     int b = 0; n     for (auto it : cycle[i]) b |= 1 << it.first - 1; n     bit[b].push_back(i); n   } n   memset(dp, -1, sizeof dp); n   dp[0] = 0; n   for (int s = 0; s <= (1 << k) - 1; s++) { n     for (int t = s; t; t = (t - 1) & s) n       if (bit[t].size() && dp[s ^ t] != -1) { n         dp[s] = t; n         break; n       } n   } n   if (dp[(1 << k) - 1] != -1) { n     vector<int> ans; n     int s = (1 << k) - 1; n     while (s) { n       ans.push_back(bit[dp[s]][0]); n       s = s ^ dp[s]; n     } n     int id1[20] = {}, id2[20] = {}; n     for (auto id : ans) { n       int L = cycle[id].size(); n       for (int i = 0; i <= L - 1; i++) { n         id1[cycle[id][i].first] = cycle[id][i].second; n         id2[cycle[id][i].first] = cycle[id][(i + 1) % L].first; n       } n     } n     puts( Yes ); n     for (int i = 1; i <= k; i++) printf( %d %d n , a[i][id1[i]], id2[i]); n   } else n     puts( No ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c[100004], i, n, t, q, w, nr, r, d, s; n char a[100004], b[100004]; n int main() { n   scanf( %d %d n , &n, &t); n   for (i = 1; i <= n; i++) scanf( %c , &a[i]); n   scanf(  n ); n   for (i = 1; i <= n; i++) scanf( %c , &b[i]); n   for (i = 1; i <= n; i++) { n     if (a[i] == b[i]) c[++nr] = i; n   } n   if ((n - nr) <= t) { n     for (i = 1; i <= n; i++) { n       if (a[i] != b[i]) { n         if (a[i] !=  a  && b[i] !=  a ) n           printf( a ); n         else if (a[i] !=  b  && b[i] !=  b ) n           printf( b ); n         else n           printf( c ); n       } else if (r < (n - t)) { n         printf( %c , a[i]); n         r++; n       } else { n         if (a[i] !=  a ) n           printf( a ); n         else n           printf( b ); n       } n     } n   } else { n     q = n - nr; n     if (q > (2 * t)) n       printf( %d , -1); n     else { n       s = (n - nr - t) * 2; n       if (s > q) n         printf( %d , s); n       else { n         for (i = 1; i <= n; i++) { n           if (a[i] != b[i]) { n             if (d < s) { n               if (d % 2 == 0) n                 printf( %c , a[i]); n               else n                 printf( %c , b[i]); n               d++; n             } else { n               if (a[i] !=  a  && b[i] !=  a ) n                 printf( a ); n               else if (a[i] !=  b  && b[i] !=  b ) n                 printf( b ); n               else n                 printf( c ); n             } n           } else n             printf( %c , a[i]); n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Imx = 2147483647; n const long long Lbig = 2e18; n const int mod = 1e9 + 7; n struct fastio { n   char s[100000]; n   int it, len; n   fastio() { it = len = 0; } n   inline char get() { n     if (it < len) return s[it++]; n     it = 0; n     len = fread(s, 1, 100000, stdin); n     if (len == 0) n       return EOF; n     else n       return s[it++]; n   } n   bool notend() { n     char c = get(); n     while (c ==     || c ==   n ) c = get(); n     if (it > 0) it--; n     return c != EOF; n   } n } _buff; n inline long long getnum() { n   long long r = 0; n   bool ng = 0; n   char c; n   c = _buff.get(); n   while (c !=  -  && (c <  0  || c >  9 )) c = _buff.get(); n   if (c ==  - ) ng = 1, c = _buff.get(); n   while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = _buff.get(); n   return ng ? -r : r; n } n template <class T> n inline void putnum(T x) { n   if (x < 0) putchar( - ), x = -x; n   register short a[20] = {}, sz = 0; n   while (x) a[sz++] = x % 10, x /= 10; n   if (sz == 0) putchar( 0 ); n   for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]); n } n inline char getreal() { n   char c = _buff.get(); n   while (c <= 32) c = _buff.get(); n   return c; n } n long long qpow(long long x, long long k) { n   return k == 0 ? 1 n                 : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod; n } n const int maxn = 200111; n int n, q; n long long pos[maxn]; n struct SGT { n   long long a[maxn << 4], b[maxn << 4]; n   void modify(int x, long long v, int l, int r, int p) { n     if (l == r) { n       a[p] = v; n       b[p] = pos[l] * v % mod; n       return; n     } n     int m = l + r >> 1; n     if (x <= m) n       modify(x, v, l, m, p << 1); n     else n       modify(x, v, m + 1, r, p << 1 | 1); n     a[p] = a[p << 1] + a[p << 1 | 1]; n     b[p] = (b[p << 1] + b[p << 1 | 1]) % mod; n   } n   long long query(int x, int y, int l, int r, int p) { n     if (x > y) return 0; n     if (x <= l && r <= y) return a[p]; n     int m = l + r >> 1; n     long long ret = 0; n     if (x <= m) ret += query(x, y, l, m, p << 1); n     if (m < y) ret += query(x, y, m + 1, r, p << 1 | 1); n     return ret; n   } n   long long queryb(int x, int y, int l, int r, int p) { n     if (x > y) return 0; n     if (x <= l && r <= y) return b[p]; n     int m = l + r >> 1; n     long long ret = 0; n     if (x <= m) ret += queryb(x, y, l, m, p << 1); n     if (m < y) ret += queryb(x, y, m + 1, r, p << 1 | 1); n     return ret % mod; n   } n   int querylft(int x, int y, long long &v, int l, int r, int p) { n     if (x <= l && r <= y) { n       if (v > a[p]) { n         v -= a[p]; n         return r + 1; n       } else { n         if (l == r) return l; n         int m = l + r >> 1; n         if (v <= a[p << 1]) n           return querylft(x, y, v, l, m, p << 1); n         else { n           v -= a[p << 1]; n           return querylft(x, y, v, m + 1, r, p << 1 | 1); n         } n       } n     } n     int m = l + r >> 1; n     if (x <= m && m < y) { n       int t = querylft(x, y, v, l, m, p << 1); n       if (t == m + 1) n         return querylft(x, y, v, m + 1, r, p << 1 | 1); n       else n         return t; n     } else if (x <= m) n       return querylft(x, y, v, l, m, p << 1); n     else n       return querylft(x, y, v, m + 1, r, p << 1 | 1); n   } n } sgt; n long long w[maxn], w2[maxn]; n long long solve(int l, int r) { n   long long sum = sgt.query(l, r, 1, n, 1); n   long long cur = (sum + 1) / 2; n   int p = sgt.querylft(l, r, cur, 1, n, 1); n   assert(p >= l && p <= r); n   long long ANS = sgt.queryb(p + 1, r, 1, n, 1) - sgt.queryb(l, p, 1, n, 1); n   long long cnt = n       (-sgt.query(p + 1, r, 1, n, 1) + sgt.query(l, p, 1, n, 1)) % mod; n   return ((ANS + cnt * pos[p] % mod) % mod + mod) % mod; n } n int main() { n   n = getnum(), q = getnum(); n   for (int i = 1; i <= n; i++) { n     pos[i] = getnum(); n     pos[i] -= i; n   } n   for (int i = 1; i <= n; i++) { n     w[i] = getnum(); n     sgt.modify(i, w[i], 1, n, 1); n   } n   for (int i = 1; i <= q; i++) { n     long long x, y; n     x = getnum(), y = getnum(); n     if (x > 0) { n       putnum(solve(x, y)), putchar(  n ); n     } else { n       x = -x; n       w[x] = y; n       sgt.modify(x, y, 1, n, 1); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 205; n const int mod = 1e9 + 7; n long long f[2][N][N]; n int n, tot; n struct point { n   long long x, y; n   point(long long _x = 0, long long _y = 0) { n     x = _x; n     y = _y; n   } n   point operator-(const point &rhs) const { n     return point(x - rhs.x, y - rhs.y); n   } n } p[N], p2[N]; n long long cross(point a, point b) { return a.x * b.y - a.y * b.x; } n long long dp(int i, int j, int op, point p[]) { n   if (f[op][i][j] != -1) return f[op][i][j]; n   if (j - i < 2) return 1; n   f[op][i][j] = 0; n   for (int k = i + 1; k <= j - 1; k++) { n     if (cross(p[k] - p[i], p[j] - p[i]) > 0) { n       f[op][i][j] += (dp(i, k, op, p) * dp(k, j, op, p)) % mod; n       f[op][i][j] %= mod; n     } n   } n   return f[op][i][j]; n } n int main() { n   memset(f, -1, sizeof(f)); n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %lld%lld , &p[i].x, &p[i].y); n     p2[n - i - 1].x = p[i].x; n     p2[n - i - 1].y = p[i].y; n   } n   long long ans1, ans2; n   ans1 = dp(0, n - 1, 0, p); n   ans2 = dp(0, n - 1, 1, p2); n   printf( %lld n , max(ans1, ans2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct T { n   T *l, *r; n   int v; n   int c; n   T(int v) : v(v), c(1) { l = r = NULL; } n   T(T *a) { n     l = a->l; n     r = a->r; n     v = a->v; n     c = a->c; n   } n   T() {} n }; n T pool[(5000000) + 10000]; n int stack_size; n T *my_new(int v) { return &(pool[stack_size++] = T(v)); } n T *my_new(T *a) { return &(pool[stack_size++] = T(a)); } n int count(T *c) { n   if (!c) n     return 0; n   else n     return c->c; n } n T *update(T *c) { n   if (!c) return c; n   c->c = count(c->l) + count(c->r) + 1; n   return c; n } n T *merge(T *a, T *b, int flag = 1) { n   if (!a) return b; n   if (!b) return a; n   if (rand() % (count(a) + count(b)) < count(a)) { n     T *R = flag ? my_new(a) : a; n     R->r = merge(a->r, b, flag); n     return update(R); n   } else { n     T *R = flag ? my_new(b) : b; n     R->l = merge(a, b->l, flag); n     return update(R); n   } n } n pair<T *, T *> split(T *c, int k, int flag = 1) { n   if (!c) return make_pair(c, c); n   T *R = flag ? my_new(c) : c; n   if (k <= count(c->l)) { n     pair<T *, T *> s = split(c->l, k, flag); n     R->l = s.second; n     return make_pair(s.first, update(R)); n   } else { n     pair<T *, T *> s = split(c->r, k - count(c->l) - 1, flag); n     R->r = s.first; n     return make_pair(update(R), s.second); n   } n } n T *insert(T *c, int k, int value) { n   pair<T *, T *> div = split(c, k, 0); n   T *mono_tree = my_new(value); n   return merge(merge(div.first, mono_tree, 0), div.second, 0); n } n int tmp[100010]; n int tmp2[100010]; n int N, M, m; n pair<T *, T *> generate_tree() { n   stack_size = 0; n   T *root1 = NULL; n   T *root2 = NULL; n   for (int i = 0; i < N; i++) root1 = insert(root1, i, tmp[i]); n   for (int i = 0; i < N; i++) root2 = insert(root2, i, tmp2[i]); n   return make_pair(root1, root2); n } n void write(int *arr, T *c) { n   if (m >= N) return; n   if (!c) return; n   write(arr, c->l); n   if (m < N) arr[m++] = c->v; n   write(arr, c->r); n } n int main() { n   scanf( %d%d , &N, &M); n   for (int i = 0; i < N; i++) { n     scanf( %d , &tmp[i]); n   } n   for (int i = 0; i < N; i++) { n     scanf( %d , &tmp2[i]); n   } n   T *A, *B; n   pair<T *, T *> hoge = generate_tree(); n   A = hoge.first; n   B = hoge.second; n   for (int i = 0; i < M; i++) { n     int a; n     int x, y, k; n     scanf( %d , &a); n     if (a == 1) { n       scanf( %d%d%d , &x, &y, &k); n       x--, y--; n       pair<T *, T *> sub = split(A, x); n       pair<T *, T *> sub2 = split(sub.second, k); n       pair<T *, T *> sub3 = split(B, y); n       pair<T *, T *> sub4 = split(sub3.second, k); n       T *f1 = merge(sub3.first, sub2.first); n       T *f2 = merge(f1, sub4.second); n       B = f2; n       if (stack_size > (5000000)) { n         m = 0; n         write(tmp, A); n         m = 0; n         write(tmp2, B); n         pair<T *, T *> hoge = generate_tree(); n         A = hoge.first; n         B = hoge.second; n       } n     } else { n       scanf( %d , &x); n       x--; n       pair<T *, T *> sub = split(B, x); n       pair<T *, T *> sub2 = split(sub.second, 1); n       printf( %d n , sub2.first->v); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int a, b; n   cin >> a >> b; n   for (int i = 1; i <= a; ++i) cout << i <<    ; n   cout << a + b + 1; n   for (int i = a + b; i > a; --i) cout <<     << i; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000LL * 1000LL * 1000LL + 7; n long long n, k, len; n vector<long long> a, b; n vector<vector<long long> > dp; n void init() { n   cin >> n >> len >> k; n   a.resize(n + 1); n   b.resize(n); n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     b[i - 1] = a[i]; n   } n   sort(a.begin(), a.end()); n   dp.resize(k + 1, vector<long long>(n + 1, 0)); n   for (int i = 1; i <= n; ++i) { n     dp[1][i] = 1; n   } n } n void solve() { n   if (len <= n) { n     cout << len; n     return; n   } n   long long sum = 0; n   int l = 1, r = 1; n   for (int i = 2; i <= k; ++i) { n     sum = 0; n     l = 1; n     r = 1; n     while (l <= n) { n       r = l; n       while (r <= n && a[r] == a[l]) { n         sum = (sum + dp[i - 1][r]) % mod; n         ++r; n       } n       for (int j = l; j < r; ++j) { n         dp[i][j] = (dp[i][j] + sum) % mod; n       } n       l = r; n     } n   } n   long long res = 0, pos = min(len / n, k); n   for (int i = 1; i <= pos; ++i) { n     for (int j = 1; j <= n; ++j) { n       res = (res + (((len / n - i + 1) % mod) * dp[i][j]) % mod) % mod; n     } n   } n   if (len % n > 0) { n     if (len / n < k) { n       pos = len / n + 1; n       for (int i = 1; i <= len % n; ++i) { n         int d = n             std::distance(a.begin(), lower_bound(a.begin(), a.end(), b[i - 1])); n         res = (res + dp[pos][d]) % mod; n       } n     } n     pos = min(len / n, k); n     for (int i = 1; i <= pos; ++i) { n       for (int j = 1; j <= len % n; ++j) { n         int d = n             std::distance(a.begin(), lower_bound(a.begin(), a.end(), b[j - 1])); n         res = (res + dp[i][d]) % mod; n       } n     } n   } n   cout << res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200050; n int n, num[MAXN], pre[MAXN], g[MAXN], ans; n int st[MAXN]; n map<int, int> f; n int main() { n   int u; n   ans = -1; n   st[0] = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &num[i]); n     if (!f.count(num[i] - 1)) { n       g[i] = 1; n       pre[i] = -1; n     } else { n       g[i] = g[pre[i] = f[num[i] - 1]] + 1; n     } n     if (!f.count(num[i])) n       f[num[i]] = i; n     else { n       u = f[num[i]]; n       f[num[i]] = g[u] < g[i] ? i : u; n     } n     if (ans == -1 || g[ans] < g[i]) ans = i; n   } n   for (int i = ans; i != -1; i = pre[i]) st[++st[0]] = i; n   printf( %d n , st[0]); n   while (st[0]) printf( %d  , st[st[0]--]); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400 * 1000 + 10; n vector<int> graph[N]; n int n, num[N], par[N], ans[N], c1[N], c2[N]; n void dfs(int v) { n   num[v]++; n   for (int i = 0; i < (int)graph[v].size(); i++) { n     int u = graph[v][i]; n     if (u != par[v]) { n       par[u] = v; n       dfs(u); n       num[v] += num[u]; n       if (num[u] - c1[u] > n / 2) ans[v] = 1; n       c1[v] = max(c1[v], c1[u]); n     } n   } n   if (num[v] <= n / 2) c1[v] = num[v]; n } n void dfs2(int v) { n   if (n - num[v] - c2[v] > n / 2) ans[v] = 1; n   if (n - num[v] <= n / 2) c2[v] = n - num[v]; n   int mx = c2[v]; n   for (int i = 0; i < (int)graph[v].size(); i++) { n     int u = graph[v][i]; n     if (u != par[v]) { n       c2[u] = max(c2[u], mx); n       mx = max(mx, c1[u]); n     } n   } n   mx = 0; n   for (int i = (int)graph[v].size() - 1; i >= 0; i--) { n     int u = graph[v][i]; n     if (u != par[v]) { n       c2[u] = max(c2[u], mx); n       mx = max(mx, c1[u]); n       dfs2(u); n     } n   } n } n int main() { n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     graph[a].push_back(b); n     graph[b].push_back(a); n   } n   par[0] = -1; n   dfs(0); n   dfs2(0); n   for (int i = 0; i < n; i++) cout << 1 - ans[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 300050; n const long long LINF = 0x3f3f3f3f3f3f3f3f; n map<int, int> odd, even; n int buf[MAXN], pre[MAXN]; n int main() { n   ios::sync_with_stdio(false); n   long long n; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> buf[i]; n     pre[i] = pre[i - 1] ^ buf[i]; n   } n   long long res = 0; n   even[0]++; n   for (int i = 1; i <= n; i++) { n     if (i % 2 == 1) { n       res += odd[pre[i]]; n       odd[pre[i]]++; n     } else { n       res += even[pre[i]]; n       even[pre[i]]++; n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void out(T x) { n   cout << x << endl; n   exit(0); n } n void relax(int &x, int y) { x = max(x, y); } n const int inf = 1e9; n int n, k; n int dp[20][1 << 18][2][2]; n int like[1 << 18]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   for (int i = 0; i <= n + 1; i++) { n     for (int j = 0; j < 1 << n; j++) { n       for (int a = 0; a < 2; a++) { n         for (int b = 0; b < 2; b++) { n           dp[i][j][a][b] = -inf; n         } n       } n     } n   } n   while (k--) { n     int i; n     cin >> i; n     --i; n     like[i] = 1; n   } n   for (int i = 0; i < 1 << n; i += 2) { n     for (int a = 0; a < 2; a++) { n       for (int b = 0; b < 2; b++) { n         if (like[i] + like[i + 1] == a + b) { n           relax(dp[1][i][a][b], a || b); n         } n       } n     } n   } n   for (int d = 2; d <= n; d++) { n     for (int i = 0; i < 1 << n; i += (1 << d)) { n       int j = i + (1 << (d - 1)); n       for (int a = 0; a < 2; a++) { n         for (int b = 0; b < 2; b++) { n           if (dp[d - 1][i][a][b] >= 0) { n             for (int x = 0; x < 2; x++) { n               for (int y = 0; y < 2; y++) { n                 if (dp[d - 1][j][x][y] >= 0) { n                   bool ub = (a || x); n                   bool lb = (b || y); n                   bool lb2 = (a && x) || lb; n                   relax(dp[d][i][ub][lb], ub + lb + lb2 + dp[d - 1][i][a][b] + n                                               dp[d - 1][j][x][y]); n                 } n               } n             } n           } n         } n       } n     } n   } n   int res = 0; n   for (int a = 0; a < 2; a++) { n     for (int b = 0; b < 2; b++) { n       relax(res, dp[n][0][a][b] + (a || b)); n     } n   } n   out(res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = 3.14159265359; n const long long MOD = (long long)998244353ll; n const long long MAXN = (long long)2e5 + 10; n const long long INF = (long long)2242545357980376863; n const long double EPS = (long double)1e-8; n long long su = 0; n long long a[MAXN], dp1[MAXN], dp2[MAXN], dp3[MAXN]; n vector<long long> G[MAXN]; n void DFS(long long u, long long p) { n   dp1[u] = 0; n   dp2[u] = 0; n   for (auto adj : G[u]) { n     if (adj == p) continue; n     DFS(adj, u); n     dp1[u] += dp1[adj]; n     dp2[u] += dp2[adj]; n   } n   dp2[u] += dp1[u]; n   dp1[u] += a[u]; n } n void DFS2(long long u, long long p, long long v) { n   dp3[u] = v; n   long long tot = 0; n   for (auto adj : G[u]) { n     if (adj == p) continue; n     DFS2(adj, u, (v + dp2[u] - (dp2[adj] + dp1[adj])) + (su - dp1[adj])); n   } n   return; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) su += a[i]; n   long long u, v; n   for (int i = 1; i < n; i++) { n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   DFS(1, -1); n   DFS2(1, -1, 0); n   long long ans = 0; n   for (int i = 1; i <= n; i++) ans = max(ans, dp2[i] + dp3[i]); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n ostream& operator<<(ostream& os, const pair<A, B>& x) { n   return os <<  (  << x.first <<  ,  << x.second <<  ) ; n } n vector<int> E[505][505]; n long long dp[505][505], W[505][505]; n vector<pair<int, int>> verts[505][505], hors[505][505]; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   vector<int> C(k); n   for (int i = 0; i < k; ++i) { n     int r, c, d, t; n     scanf( %d%d%d%d%d , &r, &c, &d, &t, &C[i]); n     vector<bool> has(4); n     if (r + c >= t && (r + c - t) % 4 == 0) has[0] = true; n     if (r + c >= t && (r + c - t) % 4 == 1) has[1] = true; n     if (r + c + d >= t && (r + c + d - t) % 4 == 2) has[2] = true; n     if (r + c + d >= t && (r + c + d - t) % 4 == 3) has[3] = true; n     int tot = has[0] + has[1] + has[2] + has[3]; n     assert(tot <= 2); n     if (!tot) continue; n     if (has[0] && has[2]) n       verts[r][c].emplace_back(r + d, C[i]); n     else if (has[0] && has[3]) n       hors[r][c].emplace_back(c + d, C[i]); n     else if (has[1] && has[2]) n       hors[r + d][c - d].emplace_back(c, C[i]); n     if (has[0]) W[r][c] += C[i]; n     if (has[1]) W[r + d][c - d] += C[i]; n     if (has[2]) W[r + d][c] += C[i]; n     if (has[3]) W[r][c + d] += C[i]; n   } n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) { n       if (!i && !j) continue; n       long long val = LLONG_MAX; n       long long cost = 0; n       for (int k = j; k >= 0; --k) { n         cost += W[i][k]; n         for (auto& x : hors[i][k]) { n           if (x.first <= j) cost -= x.second; n         } n         if (k < j) val = min(val, dp[i][k] + cost - W[i][k]); n       } n       cost = 0; n       for (int k = i; k >= 0; --k) { n         cost += W[k][j]; n         for (auto& x : verts[k][j]) { n           if (x.first <= i) cost -= x.second; n         } n         if (k < i) val = min(val, dp[k][j] + cost - W[k][j]); n       } n       dp[i][j] = val; n     } n   printf( %lld n , dp[n - 1][m - 1]); n } n


#include <bits/stdc++.h> n using namespace std; n void st() {} n string str; n int n; n int main() { n   st(); n   cin >> n >> str; n   if (str.find( L ) == string::npos) { n     int x = str.find( R ); n     int y = str.find( . , x); n     printf( %d %d n , x + 1, y + 1); n     return 0; n   } n   if (str.find( R ) == string::npos) { n     int x = str.find( L ); n     int y = str.find( . , x); n     printf( %d %d n , y, x); n     return 0; n   } n   int x = str.find( L ); n   int y = str.find( R ); n   printf( %d %d n , y + 1, x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 9, LOG = 20; n int n, a, b; n int h[maxn], par[LOG][maxn], siz[maxn]; n vector<int> adj[maxn]; n void DFS(int v, int p = -1) { n   par[0][v] = p; n   for (int i = 1; i < LOG; i++) par[i][v] = par[i - 1][par[i - 1][v]]; n   siz[v] = 1; n   for (auto u : adj[v]) { n     if (u != p) { n       h[u] = h[v] + 1; n       DFS(u, v); n       siz[v] += siz[u]; n     } n   } n } n int i_par(int v, int d) { n   for (int i = 0; i < LOG; i++) { n     if (d & (1 << i)) v = par[i][v]; n   } n   return v; n } n int lca(int a, int b) { n   if (h[b] > h[a]) swap(a, b); n   a = i_par(a, h[a] - h[b]); n   if (a == b) return a; n   for (int i = LOG - 1; i >= 0; i--) { n     if (par[i][a] != par[i][b]) { n       a = par[i][a], b = par[i][b]; n     } n   } n   return par[0][a]; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     adj[x].push_back(y), adj[y].push_back(x); n   } n   DFS(1); n   int q; n   cin >> q; n   while (q--) { n     int a, b; n     cin >> a >> b; n     int p = lca(a, b); n     int x = h[a] - h[p] + h[b] - h[p]; n     if (a == b) { n       cout << n <<   n ; n       continue; n     } n     if (x % 2 == 1) n       cout << 0 <<   n ; n     else { n       if (h[a] < h[b]) swap(a, b); n       int c = i_par(a, x / 2); n       if (c != p) { n         int d = i_par(a, x / 2 - 1); n         cout << siz[c] - siz[d] <<   n ; n       } else { n         int d = i_par(a, x / 2 - 1), t = i_par(b, x / 2 - 1); n         cout << siz[c] - siz[d] - siz[t] + n - siz[c] <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n multiset<int, greater<int>> m1, m2; n int n, m; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     int a; n     cin >> a; n     m1.insert(a); n   } n   for (int i = 0; i < n; ++i) { n     int a; n     cin >> a; n     m2.insert(a); n   } n   vector<int> ans; n   for (; m1.size();) { n     auto a = m1.begin(); n     auto b = m2.begin(); n     auto bestfora = m2.lower_bound(m - 1 - *a); n     auto bestforb = m1.lower_bound(m - 1 - *b); n     if (bestfora == m2.end()) --bestfora; n     if (bestforb == m1.end()) --bestforb; n     if ((*a + *b) % m > (*a + *bestfora) % m && n         (*a + *b) % m > (*b + *bestforb) % m) { n       ans.push_back((*a + *b) % m); n       m1.erase(a); n       m2.erase(b); n     } else if ((*a + *bestfora) % m >= (*a + *b) % m && n                (*a + *bestfora) % m >= (*b + *bestforb) % m) { n       ans.push_back((*a + *bestfora) % m); n       m1.erase(a); n       m2.erase(bestfora); n     } else { n       ans.push_back((*b + *bestforb) % m); n       m1.erase(bestforb); n       m2.erase(b); n     } n   } n   sort(ans.begin(), ans.end(), greater<int>()); n   for (size_t i = 0; i < ans.size(); ++i) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, spr; n   vector<string> valer; n   cin >> s; n   char h; n   int k = (int)s.size(); n   valer.push_back(s); n   for (int i = 1; i < k; i++) { n     h = s[k - 1]; n     for (int j = k - 1; j > 0; j--) { n       s[j] = s[j - 1]; n     } n     s[0] = h; n     spr = s; n     bool t = true; n     for (int r = 0; r < (int)valer.size(); r++) { n       if (spr == valer[r]) t = false; n     } n     if (t == true) { n       valer.push_back(spr); n     } n   } n   cout << (int)valer.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, n, m, j, y, pos, fed = 0; n int mice[100001], cheese[100001], taken[100001]; n int main() { n   scanf( %d %d %d %d , &n, &m, &y, &y); n   for (i = 0; i < n; i++) scanf( %d , &mice[i]); n   for (i = 0; i < m; i++) scanf( %d , &cheese[i]); n   for (i = 0; i < m; i++) taken[i] = -1; n   for (i = 0; i < n; i++) { n     pos = lower_bound(cheese, cheese + m, mice[i]) - cheese; n     if (pos == 0) { n       if (taken[pos] == -1) { n         taken[pos] = cheese[pos] - mice[i]; n         fed++; n       } else { n         taken[pos] = cheese[pos] - mice[i]; n       } n       continue; n     } n     if (pos == m) { n       if (taken[pos - 1] == -1 || taken[pos - 1] == mice[i] - cheese[pos - 1]) { n         taken[pos - 1] = mice[i] - cheese[pos - 1]; n         fed++; n       } else if (taken[pos - 1] > mice[i] - cheese[pos - 1]) { n         taken[pos - 1] = mice[i] - cheese[pos - 1]; n       } n       continue; n     } n     { n       if ((mice[i] - cheese[pos - 1]) < (cheese[pos] - mice[i])) { n         if (taken[pos - 1] == -1 || n             taken[pos - 1] == mice[i] - cheese[pos - 1]) { n           taken[pos - 1] = mice[i] - cheese[pos - 1]; n           fed++; n         } else if (taken[pos - 1] > mice[i] - cheese[pos - 1]) { n           taken[pos - 1] = mice[i] - cheese[pos - 1]; n         } n       } else if ((mice[i] - cheese[pos - 1]) == (cheese[pos] - mice[i])) { n         if (taken[pos - 1] == -1 || n             taken[pos - 1] == mice[i] - cheese[pos - 1]) { n           taken[pos - 1] = mice[i] - cheese[pos - 1]; n           fed++; n         } else { n           taken[pos] = cheese[pos] - mice[i]; n           fed++; n         } n       } else { n         if (taken[pos] == -1) { n           taken[pos] = cheese[pos] - mice[i]; n           fed++; n         } else { n           taken[pos] = cheese[pos] - mice[i]; n         } n       } n     } n   } n   printf( %d n , n - fed); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 998244353; n int n; n vector<int> v; n vector<set<int> > g; n int all[300011] = {}; n set<pair<int, int> > ed; n pair<int, int> DFS(int u, int p) { n   pair<int, int> ret(v[u], 1); n   if (v[u] == 0) ret = {-1, 0}; n   for (auto v : g[u]) n     if (v != p) { n       auto cur = DFS(v, u); n       if (cur.first == -1) { n         ed.insert({min(u, v), max(u, v)}); n         continue; n       } n       if (ret.first == -1 || cur.first == ret.first) { n         ret.first = cur.first; n         ret.second += cur.second; n       } else { n         puts( 0 ); n         exit(0); n       } n     } n   if (ret.first == -1) return ret; n   if (all[ret.first] == ret.second) ret = {-1, 0}; n   return ret; n } n vector<vector<int> > gr; n int w[300003]; n int p[300003]; n int find(int u) { n   if (p[u] == u) return u; n   return p[u] = find(p[u]); n } n int dp[300003][2]; n int calc(int u, int p, int st) { n   int &ret = dp[u][st]; n   if (ret != -1) return ret; n   if (st == 0 && w[u] > 0) return ret = calc(u, p, 1); n   ret = 0; n   if (st == 1) { n     ret = 1; n     for (auto &v : gr[u]) n       if (v != p) n         ret = n             ret * (long long)(calc(v, u, 0) + calc(v, u, 1) * (w[v] == 0)) % M; n   } else { n     vector<int> pre(gr[u].size()); n     long long mul = 1; n     for (int i = 0; i < gr[u].size(); ++i) { n       int v = gr[u][i]; n       pre[i] = mul; n       if (v == p) continue; n       mul = mul * (calc(v, u, 0) + calc(v, u, 1) * (w[v] == 0)) % M; n     } n     mul = 1; n     for (int i = (int)gr[u].size() - 1; i >= 0; --i) { n       int v = gr[u][i]; n       if (v == p) continue; n       ret = (ret + calc(v, u, 0) * mul % M * pre[i]) % M; n       mul = mul * (calc(v, u, 0) + calc(v, u, 1) * (w[v] == 0)) % M; n     } n   } n   return ret; n } n int main() { n   int k; n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; ++i) p[i] = i; n   v.resize(n); n   g.resize(n); n   for (auto &x : v) { n     scanf( %d , &x); n     ++all[x]; n   } n   for (int i = 0; i < n; ++i) w[i] = v[i]; n   for (int i = 1, a, b; i < n; ++i) { n     scanf( %d%d , &a, &b); n     --a; n     --b; n     g[a].insert(b); n     g[b].insert(a); n   } n   { n     queue<int> q; n     for (int i = 0; i < n; ++i) n       if (v[i] == 0 && g[i].size() == 1) q.push(i); n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       int v = *g[u].begin(); n       g[u].erase(v); n       g[v].erase(u); n       if (g[v].size() == 1 && w[v] == 0) q.push(v); n     } n   } n   int root; n   for (int i = 0; i < n; ++i) n     if (g[i].size()) { n       root = i; n       break; n     } n   DFS(root, -1); n   gr.resize(n); n   for (int i = 0; i < g.size(); ++i) n     for (auto x : g[i]) { n       int u = i; n       int v = x; n       if (u > v) swap(u, v); n       if (ed.find({u, v}) == ed.end()) { n         u = find(u); n         v = find(v); n         p[u] = v; n         w[v] = max(w[v], w[u]); n       } n     } n   for (int i = 0; i < g.size(); ++i) n     for (auto x : g[i]) { n       int u = i; n       int v = x; n       if (u > v) continue; n       if (ed.find({u, v}) != ed.end()) { n         u = find(u); n         v = find(v); n         gr[u].push_back(v); n         gr[v].push_back(u); n       } n     } n   for (int i = 0; i < gr.size(); ++i) n     if (gr[i].size() && w[i]) { n       root = i; n       break; n     } n   memset(dp, -1, sizeof(dp)); n   printf( %d n , calc(root, -1, 1)); n   return 0; n } n


#include <bits/stdc++.h> n const long long int inf = LLONG_MAX; n using namespace std; n int main() { n   int n, a[4], dp[4005] = {0}, i, j; n   dp[0] = 0; n   cin >> n >> a[0] >> a[1] >> a[2]; n   for (i = 1; i <= n; i++) { n     for (j = 0; j < 3; j++) { n       if (i < a[j]) continue; n       if (dp[i - a[j]] != 0) n         dp[i] = max((1 + dp[i - a[j]]), dp[i]); n       else if (i == a[j]) n         dp[i] = max(1, dp[i]); n     } n   } n   cout << dp[n]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int arr[n]; n     for (int i = 0; i < n; i++) cin >> arr[i]; n     int cnt[n + 1]; n     memset(cnt, 0, sizeof cnt); n     cnt[0] = 1; n     int lvl = 0; n     int ind = 1; n     while (ind < n) { n       lvl++; n       for (int i = 0; i < cnt[lvl - 1] && i < n; i++) { n         int last = -1; n         while (ind < n && arr[ind] > last) { n           cnt[lvl]++; n           last = arr[ind]; n           ind++; n         } n       } n     } n     cout << lvl << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long int dp[1001], sum[1001]; n unsigned long long int nCrModp(unsigned long long int n, n                                unsigned long long int r) { n   unsigned long long int p = 1000000007; n   n = n + r - 1; n   r = r - 1; n   unsigned long long int C[r + 1]; n   memset(C, 0, sizeof(C)); n   C[0] = 1; n   for (unsigned long long int i = 1; i <= n; i++) { n     for (unsigned long long int j = min(i, r); j > 0; j--) n       C[j] = (C[j] + C[j - 1]) % p; n   } n   return C[r]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   unsigned long long int n, t, i, j, k, ans = 0; n   cin >> n; n   unsigned long long int ar[n]; n   for (i = 0; i < n; i++) { n     cin >> ar[i]; n     if (i != 0) n       sum[i] = sum[i - 1] + ar[i]; n     else n       sum[i] = ar[i]; n   } n   unsigned long long int prod = 1; n   dp[0] = 1; n   for (i = 1; i < n; i++) { n     dp[i] = nCrModp(sum[i - 1], ar[i]) % 1000000007; n     prod *= dp[i]; n     prod %= 1000000007; n   } n   cout << prod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int nax = 1e2 + 5; n string s; n int n, k; n int bonus[26][26]; n const int inf = 1e9; n long long int cnt = 0; n int dp[nax][26][nax]; n int solve(int i, int prev, int changes) { n   if (i >= s.length()) return 0; n   if (dp[i][prev][changes] != -inf) return dp[i][prev][changes]; n   int ans = -inf; n   if (changes < k) { n     for (int c = 0; c < 26; c++) { n       ans = max(ans, n                 bonus[prev][c] + n                     solve(i + 1, c, changes + ((c == (s[i] -  a )) ? 0 : 1))); n     } n   } else n     ans = n         max(ans, bonus[prev][s[i] -  a ] + solve(i + 1, (s[i] -  a ), changes)); n   return dp[i][prev][changes] = ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> s >> k >> n; n   for (int i = 0; i < nax; i++) { n     for (int c = 0; c < 26; c++) { n       for (int j = 0; j < nax; j++) { n         dp[i][c][j] = -inf; n       } n     } n   } n   memset(bonus, 0, sizeof(bonus)); n   for (int i = 0; i < n; i++) { n     char x, y; n     int b; n     cin >> x >> y >> b; n     bonus[x -  a ][y -  a ] = b; n   } n   int ans = -inf; n   if (k > 0) { n     for (int c = 0; c < 26; c++) { n       ans = max(ans, solve(1, c, ((c == (s[0] -  a )) ? 0 : 1))); n     } n   } else n     ans = max(ans, solve(1, s[0] -  a , 0)); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n const int MaxN = 5000; n using namespace std; n int a[MaxN + 5]; n long long res; n long long dp[MaxN + 5][MaxN + 5]; n int n; n long long Solve(int l, int r) { n   if (l > r) return 0; n   if (l == r) { n     return a[l] != 0; n   } n   int MinPos = l; n   for (int i = l; i <= r; i++) n     if (a[i] < a[MinPos]) MinPos = i; n   long long Min = a[MinPos]; n   for (int i = l; i <= r; i++) a[i] -= Min; n   return min((long long)r - l + 1, n              Solve(l, MinPos - 1) + Solve(MinPos + 1, r) + Min); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) dp[i][j] = -1; n   res = Solve(1, n); n   printf( %lld n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cnk[50][50] = {1}; n long long calc(long long mask, long long mx, int cnt, int n) { n   if (mask > mx) return 0; n   if (cnt == 0) return 1; n   if (cnt > n + 1) return 0; n   if (mask + (1LL << (n + 1)) - 1 <= mx) return cnk[n + 1][cnt]; n   return calc(mask + (1LL << n), mx, cnt - 1, n - 1) + n          calc(mask, mx, cnt, n - 1); n } n bool solve() { n   long long n, t; n   if (!(cin >> n >> t)) return false; n   if ((t - 1) & t) { n     printf( 0 n ); n     return true; n   } n   int cnt = 0; n   for (; t; t /= 2, cnt++) n     ; n   for (int i = 1; i < 50; ++i) n     for (int j = 0; j <= i; ++j) { n       cnk[i][j] = 0; n       if (j > 0) cnk[i][j] += cnk[i - 1][j - 1]; n       if (j < i) cnk[i][j] += cnk[i - 1][j]; n     } n   long long ans = calc(0, n + 1, cnt, 60); n   if (cnt == 1) ans--; n   cout << ans << endl; n   return true; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = 0; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n string direc =  RDLU ; n long long ln, lk, lm; n void etp(bool f = 0) { n   puts(f ?  YES  :  NO ); n   exit(0); n } n void addmod(int& x, int y, int mod = 1000000007) { n   x += y; n   if (x >= mod) x -= mod; n   assert(x >= 0 && x < mod); n } n void et() { n   puts( -1 ); n   exit(0); n } n struct Point { n   long double x, y; n   Point() {} n   Point(long double x, long double y) : x(x), y(y) {} n   Point operator*(double o) const { return Point(x * o, y * o); } n   Point operator+(const Point& o) const { return Point(x + o.x, y + o.y); } n   Point operator-(const Point& o) const { return Point(x - o.x, y - o.y); } n   bool operator<(const Point& o) const { n     return x < o.x || (x == o.x && y < o.y); n   } n   friend bool operator==(const Point& r1, const Point& r2) { n     return r1.x == r2.x && r1.y == r2.y; n   } n   long double cross(Point b) const { return x * b.y - b.x * y; } n   long double dot(Point b) const { return x * b.x + y * b.y; } n }; n set<Point> ss; n void add(long double x, long double y) { n   Point p = Point(x, y); n   auto it = ss.lower_bound({x, 0}); n   auto pre = it; n   pre--; n   if (it != ss.end() && (p - *pre).cross(*it - *pre) <= 0) return; n   ss.insert(p); n   pre = ss.lower_bound(p); n   pre--; n   if (pre == ss.begin()) return; n   auto pp = pre; n   pp--; n   while (pre != ss.begin() && (*pre - *pp).cross(p - *pre) <= 0) { n     ss.erase(pre); n     pre = pp; n     if (pp == ss.begin()) return; n     pp--; n   } n } n inline int dcmp(long double x) { n   return fabsl(x) < 1e-9 ? 0 : (x > 0 ? 1 : -1); n } n bool ck(long double dam, long double mana) { n   auto cur = ss.lower_bound(Point(dam, 0)); n   if (cur == ss.end()) return 0; n   auto pre = cur; n   pre--; n   long double x = dam - (*pre).x, y = mana - (*pre).y; n   Point z = *cur - *pre; n   if (dcmp(x * z.y - y * z.x) <= 0) return 1; n   return 0; n } n void fmain(int tid) { n   scanf( %d%lld , &n, &lm); n   int ans = 0, M = 1e6; n   ss.insert(Point(0, 0)); n   for (int(i) = 1; (i) <= (int)(n); (i)++) { n     int t, x, y; n     scanf( %d%d%d , &t, &x, &y); n     x = (x + ans) % M + 1; n     y = (y + ans) % M + 1; n     if (t == 1) n       add(x, y); n     else { n       bool ok = ck((long double)y / x, (long double)lm / x); n       puts(ok ?  YES  :  NO ); n       if (ok) ans = i; n     } n   } n } n int main() { n   int t = 1; n   for (int(i) = 1; (i) <= (int)(t); (i)++) { n     fmain(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int fir = 0; n char s[1100000]; n int check() { n   for (int i = 0; s[i]; i++) { n     if (s[i] ==    ) continue; n     if (s[i] ==  # ) n       return 1; n     else n       return 0; n   } n   return 0; n } n int main() { n   while (gets(s)) { n     if (check()) { n       if (fir) putchar(  n ); n       puts(s); n       fir = 0; n     } else { n       for (int i = 0; s[i]; i++) { n         if (s[i] ==    ) continue; n         putchar(s[i]); n       } n       fir = 1; n     } n   } n   if (fir) putchar(  n ); n   return 0; n } n