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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h>   using namespace std;   const int N = 10000000;   bool f[N] = {1, 1};   long long p, q, rub, primepi, res;   long long rev(long long x) {     long long res;     for (res = 0; x; x /= 10) {       res = res * 10 + x % 10;     }     return res;   }   int main() {     cin >> p >> q;     for (long long i = 1; i < N; ++i) {       if (!f[i]) {         primepi++;         for (long long j = i * i; j < N; j += i) f[j] = 1;       }       if (rev(i) == i) rub++;       if (q * primepi <= p * rub) res = i;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   struct Point {     int x, y;   };   struct Line {     int A, B, C;     Line(int a = 0, int b = 1, int c = 0) : A(a), B(b), C(c) {       int g = gcd(gcd(abs(A), abs(B)), abs(C));       A /= g;       B /= g;       C /= g;       if (A < 0 || (A == 0 || B < 0)) {         A = -A;         B = -B;         C = -C;       }     }   };   Line getLine(const Point &a, const Point &b) {     int dx = b.x - a.x;     int dy = -(b.y - a.y);     return Line(dy, dx, dy * a.x + dx * a.y);   }   Line perpLine(const Line &li, const Point &p) {     int a = -li.B, b = li.A;     return Line(a, b, p.x * a + p.y * b);   }   bool operator<(const Line &g, const Line &h) {     if (g.A != h.A) return g.A < h.A;     if (g.B != h.B) return g.B < h.B;     return g.C < h.C;   }   const int maxN = 1024;   int N, K;   map<int, vector<Point>> circ;   map<Line, map<int, int>> segs;   int main() {     cin >> N >> K;     for (int i = (0); i < (N); i++) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       Point a{x1 * 2, y1 * 2};       Point b{x2 * 2, y2 * 2};       Line li = getLine(a, b);       {         if (0) fprintf(stderr,  li: a %d, b %d, c %d n , li.A, li.B, li.C);       };       int pa = a.x * li.B - a.y * li.A;       int push_back = b.x * li.B - b.y * li.A;       if (pa > push_back) swap(pa, push_back);       segs[li][pa + 0]++;       segs[li][push_back + 1]--;     }     for (int i = (0); i < (K); i++) {       int x, y, r;       cin >> x >> y >> r;       circ[r * 2].push_back(Point{x * 2, y * 2});     }     for (auto &s : segs) {       s.second[INT_MIN / 2] = 0;       s.second[INT_MAX / 2] = 0;       {         if (0) fprintf(stderr,  seg n );       };       int prev = 0;       for (auto &e : s.second) {         {           if (0) fprintf(stderr,  %d: %d n , e.first, e.second);         };         e.second = (prev += e.second);         {           if (0) fprintf(stderr,      %d n , prev);         };       }     }     int res = 0;     for (const auto &ci : circ) {       for (int ia = (0); ia < (int((ci.second).size())); ia++) {         for (int ib = (ia + 1); ib < (int((ci.second).size())); ib++) {           Point a = ci.second[ia];           Point b = ci.second[ib];           Point d{b.x - a.x, b.y - a.y};           if (d.x * d.x + d.y * d.y <= ci.first * ci.first * 4) continue;           Point m{a.x + d.x / 2, a.y + d.y / 2};           {             if (0) fprintf(stderr,  M: %d %d n , m.x, m.y);           };           Line li = perpLine(getLine(a, b), m);           {             if (0) fprintf(stderr,  li: a %d, b %d, c %d n , li.A, li.B, li.C);           };           if (!((segs).find(li) != (segs).end())) continue;           int pp = m.x * li.B - m.y * li.A;           {             if (0) cerr <<  DBGDO:   << ( pp ) <<   =   << (pp) << endl;           };           auto it = segs[li].upper_bound(pp);           assert(it != segs[li].begin());           it--;           res += it->second;         }       }     }     cout << res << endl;   }