#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &out, const vector<T> &data) {     out <<  [ ;     for (int i = 0; i < data.size(); ++i)       out << data[i] << (i == data.size() - 1 ?    :  , );     out <<  ] ;     return out;   }   template <class T>   ostream &operator<<(ostream &out, const set<T> &s) {     out <<  { ;     for (typename set<T>::iterator itr = s.begin(); itr != s.end(); ++itr)       out << *itr <<    ;     out <<  } ;     return out;   }   template <class T>   ostream &operator<<(ostream &out, const multiset<T> &s) {     out <<  { ;     for (typename multiset<T>::iterator itr = s.begin(); itr != s.end(); ++itr)       out << *itr <<    ;     out <<  } ;     return out;   }   template <class T1, class T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &p) {     out <<  (  << p.first <<  ,  << p.second <<  ) ;     return out;   }   template <class T1, class T2>   ostream &operator<<(ostream &out, const map<T1, T2> &m) {     for (typename map<T1, T2>::const_iterator itr = m.begin(); itr != m.end();          ++itr)       out << itr->first <<  ->  << itr->second <<    ;     return out;   }   const double eps = 1e-6;   const double pi = acos(-1.0);   const double INF = 1e20;   inline int sign(double d) { return d < -eps ? -1 : d > eps; }   inline double sqr(double x) { return x * x; }   struct Point {     int id;     double x, y;     Point() {       x = 0.0;       y = 0.0;     }     Point(double nx, double ny) : x(nx), y(ny) {}     Point turnLeft() const { return Point(-y, x); }     Point turnRight() const { return Point(y, -x); }     Point rotate(double ang) const {       return Point(x * cos(ang) - y * sin(ang), x * sin(ang) + y * cos(ang));     }     inline double length() { return sqrt(x * x + y * y); }     void normalize() {       double r = length();       if (sign(r) != 0) x /= r, y /= r;     }     inline bool equal(const Point &other) const {       return sign(x - other.x) == 0 && sign(y - other.y) == 0;     }     friend ostream &operator<<(ostream &out, const Point &point) {       out <<  (  << point.x <<  ,  << point.y <<  ) ;       return out;     }     friend istream &operator>>(istream &in, Point &point) {       in >> point.x >> point.y;       return in;     }   };   bool comPointByX(const Point &a, const Point &b) { return a.x < b.x; }   bool comPointEqual(const Point &a, const Point &b) { return a.equal(b); }   inline Point operator+(const Point &a, const Point &b) {     return Point(a.x + b.x, a.y + b.y);   }   inline Point operator-(const Point &a, const Point &b) {     return Point(a.x - b.x, a.y - b.y);   }   inline Point operator*(const Point &a, double d) {     return Point(a.x * d, a.y * d);   }   inline Point operator/(const Point &a, double d) {     if (sign(d) == 0) return Point();     return Point(a.x / d, a.y / d);   }   inline bool operator==(const Point &a, const Point &b) {     return a.x == b.x && a.y == b.y;   }   inline bool operator!=(const Point &a, const Point &b) {     return a.x != b.x || a.y != b.y;   }   inline double dist(const Point &a, const Point &b) {     return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));   }   inline double sqrdist(const Point &a, const Point &b) {     return sqr(a.x - b.x) + sqr(a.y - b.y);   }   inline double operator^(const Point &a, const Point &b) {     return a.x * b.y - a.y * b.x;   }   inline double cross(const Point &p, const Point &a, const Point &b) {     return (a - p) ^ (b - p);   }   inline double operator*(const Point &a, const Point &b) {     return a.x * b.x + a.y * b.y;   }   inline double dot(const Point &p, const Point &a, const Point &b) {     return (a - p) * (b - p);   }   inline double segDegree(const Point &p, const Point &a, const Point &b) {     double d = dot(p, a, b);     double cosd = d / dist(a, p) / dist(b, p);     if (cosd > 1.0) cosd = 1.0;     if (cosd < -1.0) cosd = -1.0;     return acos(cosd);   }   inline double segDegree(double a, double b, double c) {     double ret = a * a + b * b - c * c;     ret = ret / a / b / 2;     if (ret > 1.0) ret = 1.0;     if (ret < -1.0) ret = -1.0;     return acos(ret);   }   inline double triangleArea(double a, double b, double c) {     double p = (a + b + c) / 2;     return sqrt(p * (p - a) * (p - b) * (p - c));   }   inline bool onSeg(const Point &p, const Point &a, const Point &b) {     return (sign(cross(p, a, b)) == 0 && sign(dot(p, a, b)) <= 0);   }   inline bool onRay(const Point &p, const Point &a, const Point &b) {     return (sign(cross(p, a, b)) == 0 && sign(dot(a, p, b)) >= 0);   }   inline bool onLine(const Point &p, const Point &a, const Point &b) {     return sign(cross(p, a, b)) == 0;   }   pair<Point, Point> onLine(double A, double B, double C) {     if (sign(A) == 0) return make_pair(Point(0, -C / B), Point(1, -C / B));     if (sign(B) == 0) return make_pair(Point(-C / A, 0), Point(-C / A, 1));     if (fabs(A + B + C) < eps)       return make_pair(Point(-(C + B) / A, 1), Point(2, -(C + A * 2) / B));     return make_pair(Point(-(C + B) / A, 1), Point(1, -(C + A) / B));   }   vector<Point> interLine(const Point &a, const Point &b, const Point &c,                           const Point &d) {     vector<Point> inters;     double u = cross(a, c, b), v = cross(a, b, d);     if (sign(u + v) == 0) return inters;     Point p = (c * v + d * u) / (u + v);     inters.push_back(p);     return inters;   }   vector<Point> interSeg(const Point &a, const Point &b, const Point &c,                          const Point &d) {     vector<Point> inters = interLine(a, b, c, d);     if (inters.size() == 0) return inters;     const Point &p = inters[0];     if (onSeg(p, a, b) && onSeg(p, c, d))       return inters;     else {       inters.clear();       return inters;     }   }   pair<Point, Point> getVerticalEquallySegment(const Point &a, const Point &b) {     Point mid = (a + b) / 2;     Point dir = mid - a;     dir = dir.turnLeft();     Point begin = mid - dir;     Point end = mid + dir;     return make_pair(begin, end);   }   Point getMinimumDistPointOnLine(const Point &a, const Point &b,                                   const Point &p) {     if (onLine(p, a, b)) return p;     pair<Point, Point> vertical = getVerticalEquallySegment(a, b);     const Point &q = p + (vertical.second - vertical.first);     vector<Point> inter = interLine(a, b, p, q);     return inter[0];   }   Point getMinimumDistPointOnSeg(const Point &a, const Point &b, const Point &p) {     Point q = getMinimumDistPointOnLine(a, b, p);     if (onSeg(q, a, b)) return q;     if (dist(a, p) < dist(b, p))       return a;     else       return b;   }   Point getMinimumDistPointOnRay(const Point &a, const Point &b, const Point &p) {     Point q = getMinimumDistPointOnLine(a, b, p);     if (onRay(q, a, b)) return q;     if (dist(a, p) < dist(b, p))       return a;     else       return b;   }   Point getReflectionPointByLine(const Point &a, const Point &b, const Point &p) {     Point q = getMinimumDistPointOnLine(a, b, p);     return q * 2 - p;   }   vector<Point> interCir(const Point &a, const Point &b, double r1, double r2) {     vector<Point> ret;     double d = dist(a, b), d1 = ((sqr(r1) - sqr(r2)) / d + d) / 2;     if (sign(r1 + r2 - d) < 0 || sign(abs(r1 - r2) - d) > 0) return ret;     Point mid = a + ((b - a) / d) * d1;     if (sign(r1 + r2 - d) == 0) {       ret.push_back(mid);       return ret;     }     Point incr = (b - a).turnLeft() / d * sqrt(sqr(r1) - sqr(d1));     ret.push_back(mid - incr);     ret.push_back(mid + incr);     return ret;   }   double interCirArea(Point a, Point b, double ra, double rb) {     double d, dA, dB;     d = dist(a, b);     if ((d < eps) || (d + ra <= rb) || (d + rb <= ra))       return sqr((rb < ra) ? rb : ra) * pi;     if (d >= ra + rb) return 0;     dA = (sqr(d) + sqr(ra) - sqr(rb)) / d / 2;     dB = d - dA;     return sqr(ra) * acos(dA / ra) - dA * sqrt(sqr(ra) - sqr(dA)) +            sqr(rb) * acos(dB / rb) - dB * sqrt(sqr(rb) - sqr(dB));   }   vector<Point> interLineCir(const Point &o, double r, const Point &a,                              const Point &b) {     vector<Point> ret;     double d = dist(a, b), h = fabs(cross(a, b, o)) / d;     if (sign(r - h) < 0) return ret;     double d1 = ((sqr(dist(o, a)) - sqr(dist(o, b))) / d + d) / 2;     Point mid = a + (b - a) / d * d1;     if (sign(r - h) == 0) {       ret.push_back(mid);       return ret;     }     Point incr = (b - a) / d * sqrt(sqr(r) - sqr(h));     ret.push_back(mid - incr);     ret.push_back(mid + incr);     return ret;   }   vector<Point> interSegCir(const Point &o, double r, const Point &a,                             const Point &b) {     vector<Point> temp = interLineCir(o, r, a, b);     vector<Point> ret;     for (int i = 0; i < temp.size(); ++i)       if (onSeg(temp[i], a, b)) ret.push_back(temp[i]);     return ret;   }   vector<Point> tangentCirPoint(const Point &o, double r, const Point &a) {     vector<Point> ret;     double d = dist(a, o);     if (sign(d - r) < 0) return ret;     if (sign(r - d) == 0) {       ret.push_back(a);       return ret;     }     return interCir(o, a, r, sqrt(sqr(d) - sqr(r)));   }   inline bool inCircle(const Point &p, const pair<Point, double> &circle) {     double dis = dist(p, circle.first);     return sign(dis - circle.second) <= 0;   }   double distOnCircle(const Point &a, const Point &b, const Point &o, double r) {     double costheta = (a - o) * (b - o) / r / r;     double theta = acos(costheta);     return r * theta;   }   pair<Point, double> minCoverCircle(const Point &a, const Point &b,                                      const Point &c) {     if (a.equal(b)) return make_pair((b + c) / 2, dist(b, c) / 2);     if (b.equal(c)) return make_pair((c + a) / 2, dist(c, a) / 2);     if (c.equal(a)) return make_pair((a + b) / 2, dist(a, b) / 2);     if (onLine(a, b, c)) {       if (onSeg(a, b, c)) return make_pair((b + c) / 2, dist(b, c) / 2);       if (onSeg(b, a, c)) return make_pair((a + c) / 2, dist(a, c) / 2);       return make_pair((a + b) / 2, dist(a, b) / 2);     }     pair<Point, double> minCircle;     minCircle.second = INF;     pair<Point, double> cir1 = make_pair((a + b) / 2, dist(a, b) / 2);     pair<Point, double> cir2 = make_pair((b + c) / 2, dist(b, c) / 2);     pair<Point, double> cir3 = make_pair((a + c) / 2, dist(a, c) / 2);     if (inCircle(c, cir1) && cir1.second < minCircle.second) minCircle = cir1;     if (inCircle(a, cir2) && cir2.second < minCircle.second) minCircle = cir2;     if (inCircle(b, cir3) && cir3.second < minCircle.second) minCircle = cir3;     Point mid1 = (a + b) / 2;     Point mid2 = (b + c) / 2;     Point turn1 = (b - a).turnLeft();     Point turn2 = (c - b).turnLeft();     turn1 = mid1 + turn1;     turn2 = mid2 + turn2;     vector<Point> inters = interLine(mid1, turn1, mid2, turn2);     pair<Point, double> cir4 = make_pair(inters[0], dist(inters[0], a));     if (cir4.second < minCircle.second) minCircle = cir4;     return minCircle;   }   double getCircleTriangleInterArea(const Point &o, double r, const Point &a,                                     const Point &b) {     vector<Point> abcir = interSegCir(o, r, a, b);     if (abcir.size() == 2 && dist(a, abcir[0]) > dist(a, abcir[1]))       swap(abcir[0], abcir[1]);     abcir.insert(abcir.begin(), a);     abcir.push_back(b);     double ret = 0;     for (int i = 0; i < abcir.size() - 1; ++i) {       Point &t1 = abcir[i];       Point &t2 = abcir[i + 1];       if (inCircle((t1 + t2) / 2, make_pair(o, r)))         ret += fabs(cross(o, t1, t2) / 2);       else         ret += segDegree(o, t1, t2) * r * r * 0.5;     }     return ret;   }   class Polygon {    public:     vector<Point> pt;     inline void clear() { pt.clear(); }     inline int size() const { return (int)pt.size(); }     inline void addPoint(Point a) { pt.push_back(a); }     inline void removePoint() { pt.pop_back(); }     inline Point &operator[](int offset) { return pt[offset]; }     inline void getSeg(int offset, Point &a, Point &b) {       a = pt[offset];       b = pt[(offset + 1) % pt.size()];     }     int inside(const Point &p) {       int N = (int)pt.size();       bool positiveSign = false;       bool negativeSign = false;       for (int i = 0; i < N; ++i) {         Point &now = pt[i];         Point &next = pt[(i + 1) % N];         Point t1 = next - now;         Point t2 = p - next;         int s = sign(t1 ^ t2);         if (s == 0) {           if (onSeg(p, now, next))             return 0;           else             return -1;         }         if (s > 0) positiveSign = true;         if (s < 0) negativeSign = true;       }       if (positiveSign && negativeSign)         return -1;       else         return 1;     }     double interCirArea(const Point &o, double r) {       int N = (int)pt.size();       double ret = 0;       for (int i = 0; i < N; ++i) {         Point &now = pt[i];         Point &next = pt[(i + 1) % N];         double area = getCircleTriangleInterArea(o, r, now, next);         if (cross(now, next, o) >= 0)           ret += area;         else           ret -= area;       }       return ret;     }     int interCircle(const Point &o, double r, vector<Point> &inters) {       inters.clear();       bool ok = true;       for (int i = 0; i < pt.size(); ++i)         if (!inCircle(pt[i], make_pair(o, r))) ok = false;       if (ok) return 1;       if (inside(o) == 1) {         double mindis = 1e20;         for (int i = 0; i < pt.size(); ++i) {           Point a = pt[i];           Point b = pt[(i + 1) % pt.size()];           Point p = getMinimumDistPointOnSeg(a, b, o);           mindis = min(mindis, dist(p, o));         }         if (mindis >= r) return 2;       }       for (int i = 0; i < pt.size(); ++i) {         Point a = pt[i];         Point b = pt[(i + 1) % pt.size()];         vector<Point> ps = interSegCir(o, r, a, b);         inters.insert(inters.end(), ps.begin(), ps.end());       }       return inters.size() > 0 ? 3 : 4;     }     Point getMinDistPointInPolygon(const Point &p) {       if (inside(p) >= 0) return p;       int N = (int)pt.size();       double minDis = INF;       Point ret;       for (int i = 0; i < N; ++i) {         Point &a = pt[i];         Point &b = pt[(i + 1) % N];         Point nowMin = getMinimumDistPointOnSeg(a, b, p);         double nowDis = dist(nowMin, p);         if (nowDis < minDis) minDis = nowDis, ret = nowMin;       }       return ret;     }     Polygon cut(const Point &a, const Point &b) {       Polygon newPoly;       Point temp;       for (unsigned int i = 0; i < pt.size(); i++) {         Point &nowP = pt[i];         Point &nextP = pt[(i + 1) % pt.size()];         if (sign(cross(a, b, nowP)) <= 0) newPoly.addPoint(nowP);         if (sign(cross(a, b, nowP)) * sign(cross(a, b, nextP)) < 0) {           vector<Point> inters = interLine(nowP, nextP, a, b);           if (inters.size() > 0) newPoly.addPoint(inters[0]);         }       }       return newPoly;     }     vector<Point> polyInterLine(const Point &a, const Point &b) {       int N = (int)pt.size();       vector<Point> ret;       Point temp;       for (int i = 0; i < N; ++i) {         Point &now = pt[i];         Point &next = pt[(i + 1) % N];         if (sign(cross(a, b, now)) * sign(cross(a, b, next)) <= 0) {           vector<Point> inters = interLine(a, b, now, next);           if (inters.size() > 0) ret.push_back(inters[0]);         }       }       return ret;     }     double area() {       int size = this->size();       if (size <= 2) return 0.0;       addPoint(this->pt[0]);       double ans = 0;       for (int i = 0; i < size; ++i) ans += (pt[i] ^ pt[i + 1]);       removePoint();       return fabs(ans / 2);     }     double length() {       int size = this->size();       addPoint(pt[0]);       double ans = 0;       for (int i = 0; i < size; ++i) ans += dist(pt[i], pt[i + 1]);       removePoint();       return ans;     }     pair<Point, Point> getDiameter() {       if (this->size() == 0) return make_pair(Point(0, 0), Point(0, 0));       if (this->size() == 1) return make_pair(pt[0], pt[0]);       if (this->size() == 2) return make_pair(pt[0], pt[1]);       pair<Point, Point> answer;       double diameter = 0.0;       for (unsigned int i = 0; i < pt.size(); ++i)         for (unsigned int j = i + 1; j < pt.size(); ++j) {           double now = sqrdist(pt[i], pt[j]);           if (now > diameter) {             diameter = now;             answer = make_pair(pt[i], pt[j]);           }         }       return answer;     }     pair<Point, double> getMinCoverCircle() {       vector<Point> &points = pt;       if (points.size() == 0) return make_pair(Point(0, 0), 0);       if (points.size() == 1) return make_pair(points[0], 0);       if (points.size() == 2)         return make_pair((points[0] + points[1]) / 2,                          dist(points[0], points[1]) / 2);       Point a = points[0];       Point b = points[1];       Point c = points[2];       pair<Point, double> nowCircle = minCoverCircle(a, b, c);       while (true) {         bool found = false;         double maxDis = nowCircle.second;         Point maxDisPoint;         for (unsigned int i = 0; i < points.size(); ++i) {           double dis = dist(points[i], nowCircle.first);           if (sign(dis - maxDis) > 0) {             maxDis = dis;             maxDisPoint = points[i];             found = true;           }         }         if (!found) break;         Point d = maxDisPoint;         Point newa, newb, newc;         pair<Point, double> cir1 = minCoverCircle(a, b, d);         pair<Point, double> cir2 = minCoverCircle(a, c, d);         pair<Point, double> cir3 = minCoverCircle(b, c, d);         pair<Point, double> minCircle;         minCircle.second = INF;         if (inCircle(c, cir1) && cir1.second < minCircle.second) {           minCircle = cir1;           c = d;         } else {           if (inCircle(b, cir2) && cir2.second < minCircle.second) {             minCircle = cir2;             b = d;           } else {             if (inCircle(a, cir3) && cir3.second < minCircle.second) {               minCircle = cir3;               a = d;             }           }         }         nowCircle = minCircle;       }       return nowCircle;     }     friend ostream &operator<<(ostream &out, const Polygon &poly) {       int size = poly.size();       for (int i = 0; i < size; ++i) out << poly.pt[i] <<   t ;       return out;     }   };   bool comPs(const pair<Point, int> &a, const pair<Point, int> &b) {     int s = sign(a.first.x - b.first.x);     if (s < 0) return true;     if (s > 0) return false;     return a.second < b.second;   }   double unionArea(vector<Polygon> &polys) {     double ans = 0;     int N = (int)polys.size();     if (N == 0) return ans;     vector<pair<double, double> > lines;     for (int i = 0; i < N; ++i)       for (int j = 0; j < polys[i].size(); ++j) {         Point a, b;         polys[i].getSeg(j, a, b);         if (fabs(a.x - b.x) < eps) continue;         double deg = atan2(b.y - a.y, b.x - a.x);         double bb = a.y - (b.y - a.y) * a.x / (b.x - a.x);         bool close = false;         for (int k = 0; k < lines.size(); ++k)           if (fabs(lines[k].first - deg) < eps &&               fabs(lines[k].second - bb) < eps)             close = true;         if (close) continue;         lines.push_back(make_pair(deg, bb));         vector<pair<Point, int> > ps;         for (int k = 0; k < N; ++k) {           bool isPar = false;           for (int l = 0; l < polys[k].size(); ++l) {             Point c, d;             polys[k].getSeg(l, c, d);             if (fabs(c.x - d.x) < eps) continue;             if (onLine(c, a, b) && onLine(d, a, b)) {               int dir = (c.x < d.x) ? 2 : 1;               if (c.x > d.x) swap(c, d);               ps.push_back(make_pair(c, dir * 2));               ps.push_back(make_pair(d, dir * 2 + 1));               isPar = true;               break;             }           }           if (isPar) continue;           vector<Point> inters;           for (int l = 0; l < polys[k].size(); ++l) {             Point c, d;             polys[k].getSeg(l, c, d);             vector<Point> t = interLine(a, b, c, d);             for (int z = 0; z < t.size(); ++z)               if (onSeg(t[z], c, d)) inters.push_back(t[z]);           }           sort(inters.begin(), inters.end(), comPointByX);           inters.resize(unique(inters.begin(), inters.end(), comPointEqual) -                         inters.begin());           if (inters.size() >= 2) {             ps.push_back(make_pair(inters.front(), 0));             ps.push_back(make_pair(inters.back(), 1));           }         }         sort(ps.begin(), ps.end(), comPs);         int cntPosi = 0, cntNega = 0;         int cntIn = 0;         for (int k = 0; k < ps.size(); ++k) {           double x2 = ps[k].first.x;           double y2 = ps[k].first.y;           double x1 = 0, y1 = 0;           if (k > 0) {             x1 = ps[k - 1].first.x;             y1 = ps[k - 1].first.y;           }           double area = (x2 - x1) * (y2 + y1) / 2;           if (cntPosi > 0 && cntNega == 0 && x2 - x1 > eps && cntIn == 0)             ans += area;           if (cntPosi == 0 && cntNega > 0 && x2 - x1 > eps && cntIn == 0)             ans -= area;           int id = ps[k].second;           if (id == 2) cntPosi++;           if (id == 4) cntNega++;           if (id == 0) cntIn++;           if (id == 3) cntPosi--;           if (id == 5) cntNega--;           if (id == 1) cntIn--;         }       }     return ans;   }   struct ConvexHull {     static inline bool cmp(const Point &a, const Point &b) {       return a.y < b.y || (a.y == b.y && a.x < b.x);     }     static Polygon convexHull(const vector<Point> &points,                               bool needInnerEdgePoint = false) {       vector<Point> p(points.begin(), points.end());       vector<int> stack(p.size() + 1);       Polygon poly;       poly.clear();       if (p.size() == 0) return poly;       if (p.size() == 1) {         poly.addPoint(points[0]);         return poly;       }       sort(p.begin(), p.end(), ConvexHull::cmp);       int threshold = 0;       if (needInnerEdgePoint) threshold = 1;       int N = (int)p.size();       int top = -1;       stack[++top] = 0;       stack[++top] = 1;       for (int i = 2; i < N; i++) {         while (top >= 1 &&                sign(cross(p[stack[top - 1]], p[i], p[stack[top]])) >= threshold)           top--;         stack[++top] = i;       }       int temp_top = top;       stack[++top] = N - 2;       for (int i = N - 3; i >= 0; i--) {         while (top >= temp_top + 1 &&                sign(cross(p[stack[top - 1]], p[i], p[stack[top]])) >= threshold)           top--;         stack[++top] = i;       }       for (int i = 0; i < top; ++i) poly.addPoint(p[stack[i]]);       return poly;     }   };   class HalfPlanes {    public:     Polygon poly;     HalfPlanes(double maxRange) {       poly.addPoint(Point(-maxRange, -maxRange));       poly.addPoint(Point(maxRange, -maxRange));       poly.addPoint(Point(maxRange, maxRange));       poly.addPoint(Point(-maxRange, maxRange));     }     void intersect(const Point &a, const Point &b) { poly = poly.cut(a, b); }     void intersect(double A, double B, double C) {       pair<Point, Point> ab = onLine(A, B, C);       pair<Point, Point> cd = getVerticalEquallySegment(ab.first, ab.second);       Point a = ab.first, b = ab.second, c = cd.first, d = cd.second;       double vc = A * c.x + B * c.y + C;       if (vc > 0) {         if (sign(cross(a, b, c)) > 0) swap(a, b);       } else {         if (sign(cross(a, b, d)) > 0) swap(a, b);       }       poly = poly.cut(a, b);     }     void intersect(const Point &a, const Point &b, const Point &c) {       if (sign(cross(a, b, c)) <= 0)         poly = poly.cut(a, b);       else         poly = poly.cut(b, a);     }   };   class Voronoy {    public:     vector<Point> ps;     vector<HalfPlanes> planes;     Voronoy(vector<Point> &points, double maxRange) {       int N = (int)points.size();       ps = points;       planes.resize(N, HalfPlanes(maxRange));       for (int i = 0; i < N; ++i)         for (int j = i + 1; j < N; ++j) {           pair<Point, Point> v = getVerticalEquallySegment(ps[i], ps[j]);           planes[i].intersect(v.first, v.second, ps[i]);           planes[j].intersect(v.first, v.second, ps[j]);         }     }   };   struct Point3D {     double x, y, z;     Point3D() {}     Point3D(double xx, double yy, double zz) {       x = xx;       y = yy;       z = zz;     }     double len() { return sqrt(x * x + y * y + z * z); }   };   Point3D operator+(const Point3D &a, const Point3D &b) {     return Point3D(a.x + b.x, a.y + b.y, a.z + b.z);   }   Point3D operator-(const Point3D &a, const Point3D &b) {     return Point3D(a.x - b.x, a.y - b.y, a.z - b.z);   }   double dist(const Point3D &a, const Point3D &b) {     return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z));   }   double dot(const Point3D &a, const Point3D &b) {     return a.x * b.x + a.y * b.y + a.z * b.z;   }   Point3D cross(const Point3D &u, const Point3D &v) {     Point3D ret;     ret.x = u.y * v.z - v.y * u.z;     ret.y = u.z * v.x - u.x * v.z;     ret.z = u.x * v.y - u.y * v.x;     return ret;   }   Point3D planeVector(const Point3D &a, const Point3D &b, const Point3D &c) {     return cross(a - b, b - c);   }   double distToPlane(const Point3D &p, const Point3D &s1, const Point3D &s2,                      const Point3D &s3) {     Point3D plane = planeVector(s1, s2, s3);     return dot(plane, p - s1) / plane.len();   }   Point ps[4];   Point a, b, c, d;   class State {    public:     double x, y, z;     State operator+(const State &other) {       State ret;       ret.x = x + other.x;       ret.y = y + other.y;       ret.z = z + other.z;       return ret;     }     State operator-(const State &other) {       State ret;       ret.x = x - other.x;       ret.y = y - other.y;       ret.z = z - other.z;       return ret;     }     State operator*(double k) {       State ret;       ret.x = x * k;       ret.y = y * k;       ret.z = z * k;       return ret;     }     friend ostream &operator<<(ostream &out, const State &state) {       out << state.x <<     << state.y <<     << state.z;       return out;     }   };   double func(const State &s) {     Point p(s.x, s.y);     double ret = dist(Point(0, 0), p);     ret += dist(getMinimumDistPointOnLine(c, d, p), p);     return ret;   }   class GoldSplitSearch {    public:     static State findMinimum(State &begin, State &end,                              double (*func)(const State &s)) {       const double tou = (sqrt(5.0) - 1) / 2;       State a = begin;       State b = end;       for (int k = 0; k < 200; ++k) {         State x1 = a + (b - a) * (1 - tou);         State x2 = a + (b - a) * tou;         double f1 = func(x1);         double f2 = func(x2);         if (f1 > f2)           a = x1;         else           b = x2;       }       return a;     }   };   double getAns(Point aa, Point bb, Point cc, Point dd) {     c = cc;     d = dd;     double scale = 100000 / (bb - aa).length();     Point na = (aa - bb) * scale + bb;     Point nb = (bb - aa) * scale + aa;     State begin;     begin.x = na.x;     begin.y = na.y;     State end;     end.x = nb.x;     end.y = nb.y;     State s = GoldSplitSearch::findMinimum(begin, end, func);     return func(s);   }   int N;   vector<Polygon> polys;   void init() {     double ans = 0;     cin >> N;     polys.clear();     for (int i = 0; i < N; ++i) {       vector<Point> ps(4);       for (int j = 0; j < 4; ++j) cin >> ps[j];       Polygon poly = ConvexHull::convexHull(ps);       polys.push_back(poly);       ans += poly.area();     }     ans = ans / (unionArea(polys));     printf( %.10f n , ans);   }   void york() {}   int main() {     init();     york();     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-10;   int n, a, b, cnta[100010], cntb[100010];   double p[100010], q[100010], f[100010];   void check2(double costa, double costb) {     for (int i = 1; i <= n; i++) {       f[i] = 0;       cnta[i] = 0;       cntb[i] = 0;       f[i] = f[i - 1];       cnta[i] = cnta[i - 1];       cntb[i] = cntb[i - 1];       if (f[i] < f[i - 1] + p[i] - costa - eps) {         f[i] = f[i - 1] + p[i] - costa;         cnta[i] = cnta[i - 1] + 1;         cntb[i] = cntb[i - 1];       }       if (f[i] < f[i - 1] + q[i] - costb - eps) {         f[i] = f[i - 1] + q[i] - costb;         cnta[i] = cnta[i - 1];         cntb[i] = cntb[i - 1] + 1;       }       if (f[i] < f[i - 1] + p[i] - costa + q[i] - costb - p[i] * q[i] - eps) {         f[i] = f[i - 1] + p[i] - costa + q[i] - costb - p[i] * q[i];         cnta[i] = cnta[i - 1] + 1;         cntb[i] = cntb[i - 1] + 1;       }     }   }   double check1(double cost) {     double l = 0, r = 1, mid;     for (int i = 1; i <= 50; i++) {       mid = (l + r) / 2;       check2(cost, mid);       if (cntb[n] > b)         l = mid;       else         r = mid;     }     return l;   }   double l, r, mid, v, ans;   int main() {     scanf( %d %d %d , &n, &a, &b);     for (int i = 1; i <= n; i++) scanf( %lf , p + i);     for (int i = 1; i <= n; i++) scanf( %lf , q + i);     l = 0;     r = 1;     while (r - l > eps) {       mid = (l + r) / 2.0;       v = check1(mid);       if (cnta[n] > a)         l = mid;       else         r = mid;     }     check2(l, v);     printf( %.10lf n , f[n] + l * a + v * b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using s64 = long long;   const int M = 1000000007;   int add(int a, const int &b) {     a += b;     return a >= M ? a - M : a;   }   int sub(int a, const int &b) {     a -= b;     return a < 0 ? a + M : a;   }   int mul(const int &a, const int &b) { return (s64)a * b % M; }   int main() {     int n, k;     cin >> n >> k;     vector<int> fac(n), ifac(n);     fac[0] = fac[1] = ifac[0] = ifac[1] = 1;     for (int i = 2; i < n; ++i) {       fac[i] = mul(fac[i - 1], i);       ifac[i] = mul(M - M / i, ifac[M % i]);     }     for (int i = 2; i < n; ++i) {       ifac[i] = mul(ifac[i], ifac[i - 1]);     }     vector<int> f(n + 1), sum(n + 1);     for (int i = k + 1; i <= n; ++i) {       f[i] = mul(add(i - k - 1, sub(sum[i - 1], sum[i - k - 1])), fac[i - 2]);       sum[i] = mul(f[i], ifac[i - 1]);       sum[i] = add(sum[i], sum[i - 1]);     }     int answer = 0;     for (int i = 1; i <= n; ++i) {       answer = add(answer, mul(f[i], mul(fac[n - 1], ifac[i - 1])));     }     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e9 + 7;   map<long long, long long> factorize(long long n) {     map<long long, long long> ans;     for (long long i = 2; i * i <= n; i++) {       while (n % i == 0) {         ans[i]++;         n /= i;       }     }     if (n > 1) {       ans[n]++;       n = 1;     }     return ans;   }   void FAST() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   int main() {     FAST();     long long t;     cin >> t;     while (t--) {       long long x;       cin >> x;       long long y;       cin >> y;       long long k;       cin >> k;       long long reqy = y * k;       if ((k * (y + 1) - 1) % (x - 1)) {         cout << (k * (y + 1) - 1) / (x - 1) + k + 1 <<   n ;       } else         cout << (k * (y + 1) - 1) / (x - 1) + k <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int infi = 1e9 + 7;   const long long infl = (long long)1e18 + (long long)7;   const long long mod = 998244353;   long long sum[300500];   long long get_sum(int l, int r) {     if (l > r) {       return 0;     }     if (l) {       return sum[r] - sum[l - 1];     }     return sum[r];   }   long long ar[300500];   long long pow(long long a, long long p) {     long long ans = 1;     while (p) {       if (p & 1LL) {         ans *= a;         ans %= mod;       }       a *= a;       a %= mod;       p >>= 1;     }     return ans;   }   long long norm(long long a, long long n) { return (a * pow(n, mod - 2)) % mod; }   int32_t main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < (n); ++i) {       cin >> ar[i];     }     sort(ar, ar + n);     reverse(ar, ar + n);     for (int i = 0; i < (n); ++i) {       if (i) sum[i] = sum[i - 1];       sum[i] += ar[i];       sum[i] %= mod;     }     for (int len = 1; len < n; ++len) {       long long ans = 0;       for (long long w = 1, l = len; l < n; l += len, ++w) {         long long r = min(l + len - 1, n - 1LL);         ans += get_sum(l, r) * w;         ans %= mod;       }       if (ans < 0) ans += mod;       cout << norm(ans, n) <<    ;     }     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     bitset<30> a;     bitset<30> b;     a.reset();     b.reset();     bool bigger = 0;     cout <<  ? 0 0  << endl;     fflush(stdout);     int aa;     cin >> aa;     if (aa == -1) {       bigger = 1;     }     bitset<30> adda;     bitset<30> addb;     for (int i = 29; i >= 0; i--) {       adda[i] = 1;       addb[i] = 1;       cout <<  ?   << adda.to_ulong() <<     << addb.to_ulong() << endl;       fflush(stdout);       int aa;       cin >> aa;       if (aa == -1 && bigger == 0) {         a[i] = 1;         b[i] = 0;         adda[i] = 0;         addb[i] = 1;         cout <<  ?   << adda.to_ulong() <<     << addb.to_ulong() << endl;         fflush(stdout);         int aa;         cin >> aa;         if (aa == -1) {           bigger = 1;         }       } else if (aa == 1 && bigger == 1) {         a[i] = 0;         b[i] = 1;         adda[i] = 1;         addb[i] = 0;         cout <<  ?   << adda.to_ulong() <<     << addb.to_ulong() << endl;         fflush(stdout);         int aa;         cin >> aa;         if (aa == 1) {           bigger = 0;         }       } else if (aa == 1 && bigger == 0) {         adda[i] = 1;         addb[i] = 0;         cout <<  ?   << adda.to_ulong() <<     << addb.to_ulong() << endl;         fflush(stdout);         int aa;         cin >> aa;         if (aa == 1) {           a[i] = 0;           b[i] = 0;           adda[i] = 0;           addb[i] = 0;         } else if (aa == -1) {           a[i] = 1;           b[i] = 1;           adda[i] = 1;           addb[i] = 1;         }       } else if (aa == -1 && bigger == 1) {         adda[i] = 0;         addb[i] = 1;         cout <<  ?   << adda.to_ulong() <<     << addb.to_ulong() << endl;         fflush(stdout);         int aa;         cin >> aa;         if (aa == -1) {           a[i] = 0;           b[i] = 0;           adda[i] = 0;           addb[i] = 0;         } else if (aa == 1) {           a[i] = 1;           b[i] = 1;           adda[i] = 1;           addb[i] = 1;         }       } else if (aa == 0) {         adda[i] = 0;         addb[i] = 1;         cout <<  ?   << adda.to_ulong() <<     << addb.to_ulong() << endl;         fflush(stdout);         int aa;         cin >> aa;         if (aa == -1) {           a[i] = 0;           b[i] = 0;           adda[i] = 0;           addb[i] = 0;         } else if (aa == 1) {           a[i] = 1;           b[i] = 1;           adda[i] = 1;           addb[i] = 1;         }       }     }     cout <<  !   << a.to_ulong() <<     << b.to_ulong() << endl;     fflush(stdout);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int arr[26];   string s;   long long dp[1001][1001];   int mn = 1 << 20, mx = 0;   long long solve(int idx, int sz, int mn) {     if (sz > mn) return 0;     mx = max(mx, sz);     if (idx == n) return 1;     if (dp[idx][sz] != -1) return dp[idx][sz] % 1000000007;     if (sz < mn) {       long long a = solve(idx + 1, 1, arr[s[idx] -  a ]);       return dp[idx][sz] =                  (a + solve(idx + 1, sz + 1, min(mn, arr[s[idx] -  a ]))) %                  1000000007;     } else       return dp[idx][sz] = solve(idx + 1, 1, arr[s[idx] -  a ]) % 1000000007;   }   long long solve2(int idx, int sz, int mn) {     if (sz > mn) return 1 << 20;     if (idx == n) {       return 0;     }     if (dp[idx][sz] != -1) return dp[idx][sz];     if (sz < mn) {       long long a = solve2(idx + 1, 1, arr[s[idx] -  a ]) + 1;       return dp[idx][sz] =                  min(a, solve2(idx + 1, sz + 1, min(mn, arr[s[idx] -  a ])));     } else       return dp[idx][sz] = solve2(idx + 1, 1, arr[s[idx] -  a ]) + 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     memset(dp, -1, sizeof dp);     cin >> n;     cin >> s;     for (int i = 0; i < 26; i++) {       cin >> arr[i];     }     cout << solve(1, 1, arr[s[0] -  a ]) % 1000000007 << endl;     ;     cout << mx << endl;     memset(dp, -1, sizeof dp);     cout << solve2(1, 1, arr[s[0] -  a ]) + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   string a[12];   int b[12], vis[40];   vector<string> v;   void solve(int i, int rem) {     if (i == k + 1) {       if (rem == 0) {         string s =   ;         for (int j = 1; j <= k; j++) {           if (vis[j])             s += a[0][j];           else             s += (a[0][j] ==  0  ?  1  :  0 );         }         v.push_back(s);       }       return;     }     if (rem > 0) {       vis[i] = 1;       solve(i + 1, rem - 1);       vis[i] = 0;     }     if (k - i + 1 > rem) solve(i + 1, rem);   }   bool ok(string s) {     for (int i = 0; i < m; i++) {       int k = 0;       for (int j = 0; j < n; j++) {         if (s[j] == a[i][j]) k++;       }       if (k != b[i]) {         return 0;       }     }     return 1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> a[i] >> b[i];     k = b[0];     string g = a[0];     a[0] =  x  + a[0];     swap(k, n);     solve(1, n);     swap(k, n);     int ans = 0;     a[0] = g;     for (auto s : v) {       if (ok(s)) ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   void MAIN();   int main() {     MAIN();     return 0;   }   const int N = (int)1e5 + 32;   char s[N];   int n;   void MAIN() {     scanf( %d , &n);     scanf( %s , s);     vector<int> cnt(26, 0);     for (int i = 0; i < int(n); i++) cnt[s[i] -  A ]++;     int ma = 0, nma = 0;     for (int i = 0; i < int(26); i++) {       if (cnt[i] > ma) {         ma = cnt[i];         nma = 1;       } else if (cnt[i] == ma)         nma++;     }     int res = 1;     for (int i = 0; i < int(n); i++) res = 1LL * res * nma % MOD;     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, x, i, j;     cin >> n >> x;     long long int mm = 0;     long long int mx = 0;     for (i = 0; i < n; i++) {       long long int a, b;       cin >> a >> b;       mm = max(mm, a - b);       mx = max(mx, a);     }     if (x <= mx) {       cout <<  1 n ;       return;     }     if (mm <= 0) {       cout <<  -1 n ;       return;     }     long long int p = x - mx;     long long int q = p / mm;     if (p % mm != 0) {       q++;     }     x -= (q * mm);     if (x > 0) {       q++;     }     cout << q <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     int t;     cin >> t;     while (t > 0) {       t--;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010 + 10;   const int mod = 1e9 + 7;   char s[N];   char t[N];   int d[N][N];   int main() {     int n, m;     cin >> n >> m;     scanf( %s%s , s + 1, t + 1);     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         d[i][j] = max(d[i - 1][j], d[i][j - 1]) - 1;         if (s[i] == t[j]) {           d[i][j] = d[i - 1][j - 1] + 2;           d[i][j] = max(d[i][j], 2);         }         ans = max(ans, d[i][j]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     long long ans[6][3] = {0, 1, 2, 1, 0, 2, 1, 2, 0, 2, 1, 0, 2, 0, 1, 0, 2, 1};     cout << ans[n % 6][k] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T BigMod(T b, T p, T m) {     if (p == 0) return 1;     if (p % 2 == 0) {       T s = BigMod(b, p / 2, m);       return ((s % m) * (s % m)) % m;     }     return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;   }   template <typename T>   T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   T POW(T B, T printf) {     if (printf == 0) return 1;     if (printf & 1)       return B * POW(B, printf - 1);     else       return (POW(B, printf / 2) * POW(B, printf / 2));   }   template <typename T>   T Bigmod(T b, T p, T m) {     if (p == 0)       return 1;     else if (!(p & 1))       return (Bigmod(b, p / 2, m) * Bigmod(b, p / 2, m)) % m;     else       return ((b % m) * Bigmod(b, p - 1, m)) % m;   }   template <typename T>   T Dis(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));   }   template <typename T>   T Angle(T x1, T y1, T x2, T y2) {     return atan(double(y1 - y2) / double(x1 - x2));   }   template <typename T>   T DIFF(T a, T b) {     T d = a - b;     if (d < 0)       return -d;     else       return d;   }   template <typename T>   T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <typename T>   T euclide(T a, T b, T &x, T &y) {     if (a < 0) {       T d = euclide(-a, b, x, y);       x = -x;       return d;     }     if (b < 0) {       T d = euclide(a, -b, x, y);       y = -y;       return d;     }     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       T d = euclide(b, a % b, x, y);       T t = x;       x = y;       y = t - (a / b) * y;       return d;     }   }   template <typename T>   void ia(T a[], int n) {     for (int i = 0; i < n; i++) cin >> a[i];   }   template <typename T>   void pa(T a[], int n) {     for (int i = 0; i < n - 1; i++) cout << a[i] <<    ;     cout << a[n - 1] << endl;   }   template <typename T>   long long int isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int Reset(int N, int pos) { return N = N & ~(1 << pos); }   bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }   template <class T, class first>   inline T togglebit(T a, first i) {     T t = 1;     return (a ^ (t << i));   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int cdigittoint(char ch) { return ch -  0 ; }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   double DEG(double x) { return (180.0 * x) / (2.0 * acos(0.0)); }   double RAD(double x) { return (x * (double)2.0 * acos(0.0)) / (180.0); }   int vis[5000007];   long long int sum[5000007];   void Sieve() {     vis[2] = 2;     for (int i = 3; i < 5000007; i += 2) {       if (!vis[i]) {         vis[i] = i;         for (int j = 3 * i; j < 5000007; j += i + i) vis[j] = i;       }       vis[i + 1] = 2;     }   }   void Factor(int n) {     int x = n;     while (n != 1) {       int p = vis[n];       while (n % p == 0) {         sum[x]++;         n /= p;       }     }   }   int main() {     Sieve();     for (int i = 2; i < 5000007; i++) Factor(i), sum[i] += sum[i - 1];     int(t);     scanf( %d , &t);     while (t--) {       int x, y;       scanf( %d%d , &x, &y);       printf( %lld n , sum[x] - sum[y]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[10000 + 1];   int M;   char tmp[10000 + 1];   int main() {     scanf( %s , str);     scanf( %d , &M);     for (int t = 0; t < M; t++) {       int l, r, k;       scanf( %d %d %d , &l, &r, &k);       int s_len = (r - l + 1);       k = k % s_len;       --l, --r;       for (int i = s_len - 1; i >= 0; i--) {         int d = (i - k);         if (d < 0) {           tmp[i] = str[l + d + s_len];         } else {           tmp[i] = str[l + d];         }       }       for (int i = l; i <= r; i++) {         str[i] = tmp[i - l];       }     }     printf( %s n , str);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 200011;   long long n, i, j, cntx, cnty, x, y, z;   long long vx[maxN];   map<long long, long long> Mx, My;   map<pair<long long, long long>, long long> M;   pair<long long, pair<long long, long long> > low;   vector<vector<long long> > data;   vector<long long> le, ri;   vector<long long> vals;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     while (b > 0) {       a %= b;       swap(a, b);     }     return a;   }   bool check_rat() {     int i, j;     for (i = 1; i + 1 <= cntx; i++) {       for (j = 1; j + 1 <= cnty; j++) {         if (data[i][j] * data[i + 1][j + 1] != data[i + 1][j] * data[i][j + 1])           return false;       }     }     return true;   }   void check(long long d) {     long long i, j;     le[low.second.first] = d;     for (i = 1; i <= cnty; i++) {       if (data[low.second.first][i] % d) return;       ri[i] = data[low.second.first][i] / d;     }     for (i = 1; i <= cntx; i++) {       if (data[i][1] % ri[1]) return;       le[i] = data[i][1] / ri[1];     }     long long aux = 0;     for (i = 1; i <= cntx; i++) aux += le[i] * vx[i];     vals.push_back(aux);   }   int main() {     low = make_pair(1LL << 60, make_pair(0, 0));     scanf( %lld , &n);     for (i = 1; i <= n; i++) {       scanf( %lld%lld%lld , &x, &y, &z);       if (Mx[x] == 0) Mx[x] = ++cntx, vx[cntx] = x;       if (My[y] == 0) My[y] = ++cnty;       M[make_pair(Mx[x], My[y])] = z;       low = min(low, make_pair(z, make_pair(Mx[x], My[y])));     }     if (cntx * cnty != n) {       printf( 0 );       return 0;     }     le.resize(cntx + 1);     ri.resize(cnty + 1);     data = vector<vector<long long> >(cntx + 1, vector<long long>(cnty + 1, 0));     for (i = 1; i <= cntx; i++)       for (j = 1; j <= cnty; j++) data[i][j] = M[make_pair(i, j)];     if (!check_rat()) {       printf( 0 );       return 0;     }     for (i = 1; i <= cnty; i++)       low.first = gcd(low.first, data[low.second.first][i]);     for (long long d = 1; d * d <= low.first; d++) {       if (low.first % d) continue;       check(d);       if (d * d != low.first) check(low.first / d);     }     sort(vals.begin(), vals.end());     vals.resize(unique(vals.begin(), vals.end()) - vals.begin());     printf( %d , vals.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, mod = 1000000007;   bool ok[1005];   char a[1005], b[1005];   int cnt[2][1005], tp, tn;   int solve() {     scanf( %s , a);     scanf( %s , b);     n = strlen(a);     scanf( %d , &k);     int cg = 0;     for (int i = 0; i < n; i++) {       ok[i] = true;       for (int j = 0; j < n && ok[i]; j++)         if (a[j] != b[(i + j) % n]) ok[i] = false;       cg += ok[i];     }     if (!cg) return 0;     cnt[1][0] = 1;     tp = 1;     for (int s = 0; s < k; s++) {       tn = 0;       int p = (s + 1) % 2, c = s % 2;       for (int i = 0; i < n; i++) {         cnt[c][i] = (tp + mod - cnt[p][i]) % mod;         tn = (tn + cnt[c][i]) % mod;       }       tp = tn;     }     int re = 0;     for (int i = 0; i < n; i++)       if (ok[i]) {         re = (re + cnt[(k + 1) % 2][i]) % mod;       }     return re;   }   int main() { printf( %d n , solve()); }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1e5;   int v[NMAX + 5], ans[NMAX + 5];   inline void GenerateAnswer(int n) {     int i, state = 1, st = 1, dr = n, dim = 0;     sort(v + 1, v + n + 1);     while (st <= dr) {       if (st != dr) {         if (state == 1)           ans[++dim] = v[st], ans[++dim] = v[dr];         else           ans[++dim] = v[dr], ans[++dim] = v[st];       } else         ans[++dim] = v[st];       ++st;       --dr;     }   }   int main() {     int t, n, i, j;     scanf( %d , &t);     for (j = 1; j <= t; ++j) {       scanf( %d , &n);       for (i = 1; i <= n; ++i) scanf( %d , &v[i]);       GenerateAnswer(n);       for (i = n; i >= 1; --i) printf( %d  , ans[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     string s;     cin >> s;     if (s[0] ==  @  || s.back() ==  @  || (s.find( @ ) == -1)) {       cout <<  No solution ;       return 0;     }     vector<int> v;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  @ ) v.push_back(i);     }     for (int i = 1; i < v.size(); i++) {       if (v[i] - v[i - 1] < 3) {         cout <<  No solution ;         return 0;       }     }     int pre = 0;     for (int i = 0; i < v.size(); i++) {       for (int j = pre; j <= v[i] + 1; j++) {         cout << s[j];       }       if (i + 1 != v.size()) cout <<  , ;       pre = v[i] + 2;     }     for (int i = pre; i < s.size(); i++) cout << s[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4010;   int N;   long long V[MAXN], D[MAXN], P[MAXN];   set<int> st;   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios::sync_with_stdio(false);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> V[i] >> D[i] >> P[i];       st.insert(i);     }     vector<int> ans;     while (!st.empty()) {       int b = *st.begin();       ans.push_back(b);       st.erase(st.begin());       long long val = V[b];       for (int i : st) {         P[i] -= val;         val--;         if (val == 0) {           break;         }       }       for (auto it = st.begin(); it != st.end();) {         int i = *it;         if (P[i] >= 0) {           it++;           continue;         }         st.erase(it++);         for (auto jt = it; jt != st.end(); jt++) {           P[*jt] -= D[i];         }       }     }     cout << ans.size() << endl;     for (int i : ans) {       cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e7 + 10;   const int INF = 0x3f3f3f3f;   const double EPS = 1e-10;   inline int read() {     int ret = 0, f = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) f ^= ch ==  - , ch = getchar();     while (ch <=  9  && ch >=  0 ) ret = ret * 10 + ch -  0 , ch = getchar();     return f ? -ret : ret;   }   int n, m;   char s[1005];   int main() {     scanf( %d%d , &n, &m);     int x = 0, y = 0;     int cnt = 0;     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++)         if (s[j] ==  B ) cnt++, x += i, y += j;     }     x /= cnt;     y /= cnt;     printf( %d %d n , x, y);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   constexpr long long mod = 998244353;   const long long INF = mod * mod;   const long double eps = 1e-12;   const long double pi = acosl(-1.0);   long long mod_pow(long long x, long long n, long long m = mod) {     if (n < 0) {       long long res = mod_pow(x, -n, m);       return mod_pow(res, m - 2, m);     }     if (abs(x) >= m) x %= m;     if (x < 0) x += m;     long long res = 1;     while (n) {       if (n & 1) res = res * x % m;       x = x * x % m;       n >>= 1;     }     return res;   }   struct modint {     long long n;     modint() : n(0) { ; }     modint(long long m) : n(m) {       if (n >= mod)         n %= mod;       else if (n < 0)         n = (n % mod + mod) % mod;     }     operator int() { return n; }   };   bool operator==(modint a, modint b) { return a.n == b.n; }   modint operator+=(modint& a, modint b) {     a.n += b.n;     if (a.n >= mod) a.n -= mod;     return a;   }   modint operator-=(modint& a, modint b) {     a.n -= b.n;     if (a.n < 0) a.n += mod;     return a;   }   modint operator*=(modint& a, modint b) {     a.n = ((long long)a.n * b.n) % mod;     return a;   }   modint operator+(modint a, modint b) { return a += b; }   modint operator-(modint a, modint b) { return a -= b; }   modint operator*(modint a, modint b) { return a *= b; }   modint operator^(modint a, long long n) {     if (n == 0) return modint(1);     modint res = (a * a) ^ (n / 2);     if (n % 2) res = res * a;     return res;   }   long long inv(long long a, long long p) {     return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);   }   modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }   modint operator/=(modint& a, modint b) {     a = a / b;     return a;   }   const int max_n = 1 << 10;   modint fact[max_n], factinv[max_n];   void init_f() {     fact[0] = modint(1);     for (int i = 0; i < max_n - 1; i++) {       fact[i + 1] = fact[i] * modint(i + 1);     }     factinv[max_n - 1] = modint(1) / fact[max_n - 1];     for (int i = max_n - 2; i >= 0; i--) {       factinv[i] = factinv[i + 1] * modint(i + 1);     }   }   modint comb(int a, int b) {     if (a < 0 || b < 0 || a < b) return 0;     return fact[a] * factinv[b] * factinv[a - b];   }   modint combP(int a, int b) {     if (a < 0 || b < 0 || a < b) return 0;     return fact[a] * factinv[a - b];   }   void solve() {     int n, m;     cin >> n >> m;     vector<vector<int>> v(m);     for (int i = 0; i < m; i++) {       int len;       cin >> len;       v[i].resize(len);       for (int j = 0; j < len; j++) {         cin >> v[i][j];         v[i][j]--;       }     }     vector<vector<int>> ids(n);     for (int i = 0; i < m; i++)       for (int j = 0; j < v[i].size(); j++) ids[v[i][j]].push_back(i);     vector<bool> used(m);     modint pro = 1;     int cnt = 0;     vector<pair<int, int>> vv;     for (int i = 0; i < m; i++) {       vv.push_back({v[i].size(), i});     }     sort((vv).begin(), (vv).end(), greater<pair<int, int>>());     function<int(vector<int>)> dfs = [&](vector<int> vid) {       int cnt = 0;       for (int _ = 0; _ < vid.size(); _++) {         int i = vid[_];         if (used[i]) continue;         used[i] = true;         vector<vector<int>> vals;         vals.push_back(v[i]);         priority_queue<pair<int, int>> q;         for (int id : v[i])           for (int iid : ids[id]) {             if (!used[iid]) {               q.push({v[iid].size(), iid});               used[iid] = true;             }           }         cnt++;         if (q.empty()) {           pro *= fact[v[i].size()];           continue;         }         bool exiz = false;         auto merge = [&](int x) -> bool {           int l = mod, r = -mod;           bool exi = false;           vector<int> cnt(vals.size());           vector<int> trans(n, -1);           for (int i = 0; i < vals.size(); i++)             for (int j = 0; j < vals[i].size(); j++) trans[vals[i][j]] = i;           vector<bool> isin(n);           for (int id : v[x]) isin[id] = true;           for (int id : v[x]) {             if (trans[id] < 0) {               exi = true;               continue;             }             cnt[trans[id]]++;             l = min(l, trans[id]);             r = max(r, trans[id]);           }           if (r - l > 1) {             for (int j = l + 1; j < r; j++) {               if (cnt[j] != vals[j].size()) {                 cout << 0 <<   n ;                 exit(0);               }             }           }           if (exi) {             bool isleft = false;             bool isright = false;             if (l == 0) {               isleft = true;               if (r > 0 && vals[0].size() != cnt[0]) isleft = false;             }             if (r == vals.size() - 1) {               isright = true;               if (l < r && vals[r].size() != cnt[r]) isright = false;             }             if (!isleft && !isright) {               cout << 0 <<   n ;               exit(0);             }             if (isleft) {               if (vals[r].size() != cnt[r]) {                 vector<int> cl, cr;                 for (int id : vals[r]) {                   if (isin[id])                     cl.push_back(id);                   else                     cr.push_back(id);                 }                 vals.erase(vals.begin() + r);                 vals.insert(vals.begin() + r, cr);                 vals.insert(vals.begin() + r, cl);               }               vector<int> cl;               for (int id : v[x])                 if (trans[id] < 0) cl.push_back(id);               vals.insert(vals.begin(), cl);             } else {               if (vals[l].size() != cnt[l]) {                 vector<int> cl, cr;                 for (int id : vals[l]) {                   if (isin[id])                     cr.push_back(id);                   else                     cl.push_back(id);                 }                 vals.erase(vals.begin() + l);                 vals.insert(vals.begin() + l, cr);                 vals.insert(vals.begin() + l, cl);               }               vector<int> cr;               for (int id : v[x])                 if (trans[id] < 0) cr.push_back(id);               vals.push_back(cr);             }           } else {             if (l < r) {               if (vals[r].size() != cnt[r]) {                 vector<int> cl, cr;                 for (int id : vals[r]) {                   if (isin[id])                     cl.push_back(id);                   else                     cr.push_back(id);                 }                 vals.erase(vals.begin() + r);                 vals.insert(vals.begin() + r, cr);                 vals.insert(vals.begin() + r, cl);               }               if (vals[l].size() != cnt[l]) {                 vector<int> cl, cr;                 for (int id : vals[l]) {                   if (isin[id])                     cr.push_back(id);                   else                     cl.push_back(id);                 }                 vals.erase(vals.begin() + l);                 vals.insert(vals.begin() + l, cr);                 vals.insert(vals.begin() + l, cl);               }             } else {               return false;             }           }           exiz = true;           return true;         };         vector<int> zr;         while (!q.empty()) {           int x = q.top().second;           q.pop();           for (int id : v[x])             for (int iid : ids[id]) {               if (!used[iid]) {                 q.push({v[iid].size(), iid});                 used[iid] = true;               }             }           if (!merge(x)) {             zr.push_back(x);           }         }         while (zr.size()) {           bool fin = false;           for (int j = 0; j < zr.size(); j++) {             if (merge(zr[j])) {               zr.erase(zr.begin() + j);               fin = true;               break;             }           }           if (!fin) break;         }         for (int id : zr) {           used[id] = false;         }         vector<vector<int>> zid(vals.size());         vector<int> trans(n);         for (int i = 0; i < vals.size(); i++)           for (int j = 0; j < vals[i].size(); j++) trans[vals[i][j]] = i;         for (int id : zr) {           zid[trans[v[id][0]]].push_back(id);         }         vector<bool> aft(n);         for (int id : zr)           for (int iid : v[id]) aft[iid] = true;         for (int i = 0; i < vals.size(); i++) {           vector<pair<int, int>> nv;           for (int id : zid[i]) nv.push_back({v[id].size(), id});           sort((nv).begin(), (nv).end(), greater<pair<int, int>>());           for (int j = 0; j < nv.size(); j++) {             zid[i][j] = nv[j].second;           }           int c = dfs(zid[i]);           for (int id : vals[i])             if (!aft[id]) {               pro *= c + 1;               c++;             }         }         if (exiz) pro *= 2;       }       pro *= fact[cnt];       return cnt;     };     vector<int> ori(m);     for (int i = 0; i < m; i++) {       ori[i] = vv[i].second;     }     int c = dfs(ori);     vector<int> exi(n);     for (int i = 0; i < m; i++)       for (int j = 0; j < v[i].size(); j++) exi[v[i][j]] = true;     for (int i = 0; i < n; i++)       if (!exi[i]) {         pro *= c + 1;         c++;       }     cout << pro <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     init_f();     solve();     return 0;   }


#include <bits/stdc++.h>   const int N = 1000001;   using namespace std;   vector<int> a[N];   bool st[N], vis1[N];   void f(int u) {     st[u] = true;     vis1[u] = true;     for (int v : a[u]) {       if (st[v]) {         cout <<  Draw ;         exit(0);       }       if (!vis1[v]) {         f(v);       }     }     st[u] = false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 1; i < n + 1; i++) {       int x, v;       cin >> x;       while (x--) {         cin >> v;         a[i].push_back(v);       }     }     int x;     cin >> x;     queue<pair<int, int>> q;     bool vis[n + 1][2];     int par[n + 1][2];     memset(vis, false, sizeof vis);     q.push(make_pair(x, 0));     vis[x][0] = true;     while (!q.empty()) {       auto f = q.front();       q.pop();       if (a[f.first].empty() && f.second) {         cout <<  Win n ;         vector<int> ans;         int v = f.first, typ = f.second;         while (v != x || typ) {           ans.push_back(v);           v = par[v][typ];           typ = 1 - typ;         }         cout << x <<    ;         for (int i = (int)ans.size() - 1; i >= 0; i--) cout << ans[i] <<    ;         return 0;       }       for (int v : a[f.first]) {         if (!vis[v][1 - f.second]) {           vis[v][1 - f.second] = true;           q.push(make_pair(v, 1 - f.second));           par[v][1 - f.second] = f.first;         }       }     }     memset(st, false, sizeof st);     memset(vis1, false, sizeof vis1);     f(x);     cout <<  Lose ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   bool a[2501][2501];   int sum[2501][2501];   long long ans = 0;   int get(int x1, int x2, int y1, int y2) {     return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];   }   void solve(int x1, int y1, int x2, int y2) {     if (x1 == x2 && y1 == y2) {       ans += a[x1][y1] == k;       return;     }     if (y2 - y1 > x2 - x1) {       int yy = (y2 + y1) >> 1;       for (int c = 0; c <= k; c++) {         int c1 = c, c2 = k - c;         for (int i = x1; i <= x2; i++) {           int l1 = y1, r1 = y1;           int l2 = y2, r2 = y2;           for (int j = i; j <= x2; j++) {             while (l1 <= yy && get(i, j, l1, yy) >= c1) l1++;             while (r1 <= yy && get(i, j, r1, yy) > c1) r1++;             if (r1 > yy) break;             while (l2 > yy && get(i, j, yy + 1, l2) >= c2) l2--;             while (r2 > yy && get(i, j, yy + 1, r2) > c2) r2--;             if (r2 <= yy) break;             long long w1 = 0, w2 = 0;             if (get(i, j, r1, yy) == c1) w1 = l1 - r1;             if (get(i, j, yy + 1, r2) == c2) w2 = r2 - l2;             ans += w1 * w2;           }         }       }       solve(x1, y1, x2, yy);       solve(x1, yy + 1, x2, y2);     } else {       int xx = (x1 + x2) >> 1;       for (int c = 0; c <= k; c++) {         int c1 = c, c2 = k - c;         for (int i = y1; i <= y2; i++) {           int l1 = x1, r1 = x1;           int l2 = x2, r2 = x2;           for (int j = i; j <= y2; j++) {             while (l1 <= xx && get(l1, xx, i, j) >= c1) l1++;             while (r1 <= xx && get(r1, xx, i, j) > c1) r1++;             if (r1 > xx) break;             while (l2 > xx && get(xx + 1, l2, i, j) >= c2) l2--;             while (r2 > xx && get(xx + 1, r2, i, j) > c2) r2--;             if (r2 <= xx) break;             long long w1 = 0, w2 = 0;             if (get(r1, xx, i, j) == c1) w1 = l1 - r1;             if (get(xx + 1, r2, i, j) == c2) w2 = r2 - l2;             ans += w1 * w2;           }         }       }       solve(x1, y1, xx, y2);       solve(xx + 1, y1, x2, y2);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         char c;         cin >> c;         a[i][j] = c -  0 ;         sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];       }     }     solve(1, 1, n, m);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int nf, ne, ns, rf, re, rs, df, de;   double disf, dise, diss;   int num[22];   double f[22][22][22];   double ans;   double valf[22], vale[22];   inline double cover(double l1, double r1, double l2, double r2) {     return max(0.0, min(r1, r2) - max(l1, l2));   }   void calc(int n) {     double ss = sqrt(1.0 * rs * rs - 1.0);     double ff = sqrt(1.0 * rf * rf - 1.0);     double ee = sqrt(1.0 * re * re - 1.0);     memset(valf, 0, sizeof(valf));     memset(vale, 0, sizeof(vale));     for (int i = (0); i < (int)(n); ++i) {       if (num[i] == 2) continue;       valf[i] = (ff + ff) * 1.0 * df;       if (ff && ss) {         for (int j = i; j >= 0; j--) {           if (ss + ff < i - j) break;           if (!num[j]) continue;           valf[i] +=               cover(1.0 * i - ff, 1.0 * i + ff, 1.0 * j - ss, 1.0 * j + ss) *               1.0 * df * num[j];         }         for (int j = i + 1; j < n; j++) {           if (ss + ff < j - i) break;           if (!num[j]) continue;           valf[i] +=               cover(1.0 * i - ff, 1.0 * i + ff, 1.0 * j - ss, 1.0 * j + ss) *               1.0 * df * num[j];         }       }       vale[i] = (ee + ee) * 1.0 * de;       if (ee && ss) {         for (int j = i; j >= 0; j--) {           if (ss + ee < i - j) break;           if (!num[j]) continue;           vale[i] +=               cover(1.0 * i - ee, 1.0 * i + ee, 1.0 * j - ss, 1.0 * j + ss) *               1.0 * de * num[j];         }         for (int j = i + 1; j < n; j++) {           if (ss + ee < j - i) break;           if (!num[j]) continue;           vale[i] +=               cover(1.0 * i - ee, 1.0 * i + ee, 1.0 * j - ss, 1.0 * j + ss) *               1.0 * de * num[j];         }       }     }   }   void dp(int n) {     memset(f, 0.0, sizeof(f));     int presum = 0;     for (int i = (0); i < (int)(n); ++i) {       presum += num[i];       if (!i) {         f[i][nf][ne] = 0;         if (num[i] <= 1) {           if (nf) f[i][nf - 1][ne] = valf[i];           if (ne) f[i][nf][ne - 1] = vale[i];         }         if (num[i] == 0) {           if (nf > 1) f[i][nf - 2][ne] = valf[i] * 2;           if (ne > 1) f[i][nf][ne - 2] = vale[i] * 2;           if (nf && ne) f[i][nf - 1][ne - 1] = valf[i] + vale[i];         }         continue;       }       for (int j = nf; nf - j <= (i * 2 - presum + num[i]) && j >= 0; j--) {         for (int k = ne; ne - k + nf - j <= (i * 2 - presum + num[i]) && k >= 0;              k--) {           f[i][j][k] = max(f[i][j][k], f[i - 1][j][k]);           if (num[i] <= 1) {             if (j) f[i][j - 1][k] = max(f[i][j - 1][k], f[i - 1][j][k] + valf[i]);             if (k) f[i][j][k - 1] = max(f[i][j][k - 1], f[i - 1][j][k] + vale[i]);           }           if (num[i] == 0) {             if (j > 1)               f[i][j - 2][k] = max(f[i][j - 2][k], f[i - 1][j][k] + valf[i] * 2);             if (k > 1)               f[i][j][k - 2] = max(f[i][j][k - 2], f[i - 1][j][k] + vale[i] * 2);             if (j && k)               f[i][j - 1][k - 1] =                   max(f[i][j - 1][k - 1], f[i - 1][j][k] + valf[i] + vale[i]);           }         }       }     }     ans = max(ans, f[n - 1][0][0]);   }   void dfs(int pos, int lft) {     if (lft < 0) return;     if (pos * 2 >= (nf + ne + ns)) {       if (lft == 0) {         calc(pos);         dp(pos);       }       return;     }     num[pos] = 0;     dfs(pos + 1, lft);     num[pos] = 1;     dfs(pos + 1, lft - 1);     num[pos] = 2;     dfs(pos + 1, lft - 2);     num[pos] = 0;   }   int main() {     scanf( %d%d%d%d%d%d%d%d , &nf, &ne, &ns, &rf, &re, &rs, &df, &de);     dfs(0, ns);     printf( %.8lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int mod(int x, int m) {     if (x < 0) x += m;     return x % m;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       int mx = -1;       for (int i = 0; i < n; ++i) {         cin >> v[i];         mx = max(v[i], mx);       }       int ans = -1;       for (int i = 0; i < n; ++i) {         if (v[i] == mx) {           if (i != 0 && v[i - 1] < v[i]) {             ans = i;             break;           } else if (i != (n - 1) && v[i] > v[i + 1]) {             ans = i;             break;           }         }       }       cout << ans + (ans != -1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a[n];     for (int i = 0, ggdem = n; i < ggdem; ++i) cin >> a[i];     long long yo = -1;     for (int i = 0, ggdem = n; i < ggdem; ++i) {       if (a[i] == -1) {         yo = i;       }     }     for (int i = 0, ggdem = yo + 1; i < ggdem; ++i) {       a[i] = 0;     }     long long res = 0;     for (long long i = 20; i >= 0; i--) {       if ((1 << i) > n) continue;       long long mini = 1e18, minid = -1;       for (int j = (1 << i) - 1, ggdem = n; j < ggdem; ++j) {         if (a[j] <= mini) {           mini = a[j];           minid = j;         }       }       res += mini;       a[minid] = 1e18;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     int maxEle = -1;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > maxEle) maxEle = a[i];     }     int gcdTillNow = maxEle;     for (int i = 0; i < n; i++) {       int currMaxGcd = -1, maxGcdPos = -1;       for (int j = i; j < n; j++) {         if (gcd(a[j], gcdTillNow) > currMaxGcd) {           currMaxGcd = gcd(a[j], gcdTillNow);           maxGcdPos = j;         }       }       swap(a[i], a[maxGcdPos]);       cout << a[i] <<    ;       gcdTillNow = currMaxGcd;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int sum = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       sum = (sum << 1) + (sum << 3) + (c ^ 48);       c = getchar();     }     return sum;   }   int n, k, a, m;   set<int> s;   set<int>::iterator it;   int main() {     n = read(), k = read(), a = read();     s.insert(0), s.insert(n + 1);     m = read();     int rest = (n + 1) / (a + 1);     if (rest < k) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= m; i++) {       int x = read();       it = s.lower_bound(x);       int a1 = *it;       it--;       int a2 = *it;       int dist = a1 - a2 - 1, dist1 = x - a2 - 1, dist2 = a1 - x - 1;       int b = (dist + 1) / (a + 1), b1 = (dist1 + 1) / (a + 1),           b2 = (dist2 + 1) / (a + 1);       rest -= (b - (b1 + b2));       if (rest < k) {         printf( %d n , i);         return 0;       }       s.insert(x);     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int n;     cin >> n;     int flag = 0;     while (flag == 0 && n != 0) {       if ((n % 10) == 1)         n = n / 10;       else if ((n % 10) == 4) {         if (((n / 10) % 10) == 1)           n = n / 100;         else if (((n / 10) % 10) == 4) {           if (((n / 100) % 10) == 1)             n = n / 1000;           else             flag = 1;         } else           flag = 1;       } else         flag = 1;     }     if (flag == 1)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   const long long maxn = 1e5 + 10, LG = 30, mod = 1e9 + 7, inf = 1e18;   long long n, m, f[maxn];   vector<long long> in[maxn], out[maxn];   bool mk[maxn], km[maxn];   void dfs(long long v) {     mk[v] = 1;     for (auto u : out[v])       if (!mk[u] && f[u] != 1) dfs(u);   }   void sfd(long long v) {     km[v] = 1;     if (f[v] == 1) return;     for (auto u : in[v])       if (!km[u] && f[u] != 2) sfd(u);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> f[i];     while (m--) {       long long v, u;       cin >> v >> u;       out[v].push_back(u);       in[u].push_back(v);     }     for (int i = 1; i <= n; i++)       if (f[i] == 1) dfs(i);     for (int i = 1; i <= n; i++)       if (f[i] == 2) sfd(i);     for (int i = 1; i <= n; i++) cout << (mk[i] && km[i]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, x;     scanf( %d%d , &n, &x);     if (n < 2) n = 2;     int ans = ((n - 2) + x - 1) / x + 1;     printf( %d n , ans);   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int main() {     cin >> a >> b;     int l1 = a.size();     int l2 = b.size();     int maxx = 0;     for (int i = 0; i < l1; ++i) {       for (int j = i; j < l1; ++j) {         int p = 0;         for (int k = 0; k < i; ++k) {           if (p < l2) {             if (a[k] == b[p]) {               p++;             }           }         }         for (int k = j + 1; k < l1; ++k) {           if (p < l2) {             if (a[k] == b[p]) {               p++;             }           }         }         if (p == l2) {           maxx = max(maxx, j - i + 1);         }       }     }     cout << maxx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n;     cin >> n;     array<long, 2> a[n], b[n];     long i;     for (i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];     }     for (i = 0; i < n; i++) {       if (a[i][0] != a[i][1]) {         cout <<  rated ;         return 0;       }     }     for (i = 0; i < n - 1; i++) {       if (a[i][0] < a[i + 1][0]) {         cout <<  unrated ;         return 0;       }     }     cout <<  maybe ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, k, t;     cin >> n >> m >> k >> t;     pair<long long, long long> p[k];     string s[3] = { Carrots ,  Kiwis ,  Grapes };     for (int i = 0; i < k; i++) {       cin >> p[i].first >> p[i].second;     }     sort(p, p + k);     for (int i = 0; i < t; i++) {       long long a, b;       cin >> a >> b;       bool f = 1;       long long x = (a - 1) * m + b - 1;       long long y = 0;       for (int j = 0; j < k; j++) {         if (p[j].first == a && p[j].second == b) {           cout <<  Waste  << endl;           f = 0;           break;         }         if (p[j].first < a) {           y++;         } else if (p[j].first == a) {           if (p[j].second < b) {             y++;           }         }       }       if (f) {         cout << s[(x - y) % 3] << endl;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.precision(8);     long long t(1);     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<pair<int, int>, int> > v;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       v.push_back(pair<pair<int, int>, int>(pair<int, int>(x / 2012, y), i));     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) cout << v[i].second <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int m[200001], k, cd;   int val[2000001];   void inp() {     cin >> cd >> k;     for (int i = 1; i <= cd; i++) {       cin >> m[i];       val[m[i]]++;     }     sort(m + 1, m + 1 + cd);   }   bool check(int i) {     if (m[i] <= m[i - 1] + k && m[i] > m[i - 1]) return true;     return false;   }   void calc() {     int kq = cd;     for (int i = 2; i <= cd; i++) {       if (check(i)) kq -= val[m[i - 1]];     }     cout << kq << endl;   }   int main() {     inp();     calc();   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long ksm(long long a, long long b) {     long long r = 1;     while (b) {       if (b & 1) r = (r * a) % mod;       a = a * a % mod;       b >>= 1;     }     return r;   }   void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, d, y, x);       y -= x * (a / b);     }   }   long long inv(long long a, long long p) {     long long d, x, y;     exgcd(a, p, d, x, y);     return d == 1 ? (x + p) % p : -1;   }   inline int read() {     char c = getchar();     int x = 0, f = 1;     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;   }   const int maxn = 1e5 + 100;   int n, m, k, t, a[1005][1005];   int r[1005], c[1005];   int main() {     int x, y;     cin >> x >> y;     for (int i = 1; i <= x; i++) cin >> r[i];     for (int i = 1; i <= y; i++) cin >> c[i];     memset(a, 0, sizeof(a));     for (int i = 1; i <= x; i++) {       if (r[i] == 0)         a[i][1] = -1;       else {         for (int j = 1; j <= r[i]; j++) a[i][j] = 1;         a[i][r[i] + 1] = -1;       }     }     int flag = 1;     for (int i = 1; i <= y; i++) {       if (c[i] == 0) {         if (a[1][i] == 1) flag = 0;         a[1][i] = -1;       } else {         for (int j = 1; j <= c[i]; j++) {           if (a[j][i] == -1) flag = 0;           a[j][i] = 1;         }         if (a[c[i] + 1][i] == 1) flag = 0;         a[c[i] + 1][i] = -1;       }     }     if (!flag) {       cout <<  0 n ;       return 0;     }     long long ans = 1;     for (int i = 1; i <= x; i++)       for (int j = 1; j <= y; j++) {         if (a[i][j] == 0) ans = ans * 2ll % mod;       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)(1e9 + 7);   const long long INF = (long long)(1e9 + 10);   const int MAXN = (int)(2e5 + 5);   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string caso;     cin >> caso;     while (caso ==  start ) {       int a = 0, b = 1;       cout <<  ?   << a <<     << b << endl;       char aux;       cin >> aux;       while (aux ==  y ) {         a = b;         b = a * 2;         cout <<  ?   << a <<     << b << endl;         cin >> aux;       }       int x = a, y = b;       while (y - x > 1) {         int med = (x + y) / 2;         cout <<  ?   << med <<     << b << endl;         cin >> aux;         if (aux ==  y )           y = med;         else           x = med;       }       cout <<  !   << y << endl;       cin >> caso;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, freq[201][212345];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       vector<int> pos[201];       for (int i = 0; i < 201; ++i)         for (int j = 0; j <= n; ++j) freq[i][j] = 0;       for (int x, i = 1; i <= n; ++i)         scanf( %d , &x), freq[x][i] = 1, pos[x].push_back(i);       map<pair<int, int>, int> mp;       for (int i = 1; i < 201; ++i) {         int ctr = 0;         for (int j = n; j > 0; --j)           if (freq[i][j]) mp[{i, ++ctr}] = j;         for (int j = 1; j <= n; ++j) freq[i][j] += freq[i][j - 1];       }       int ans = 1;       for (int i = 1; i < 201; ++i)         for (int j = 1; j < 201; ++j)           if (i == j)             ans = max(ans, freq[i][n]);           else if (freq[i][n] > 1) {             for (int idx1, idx2, p = 0; p < pos[i].size(); ++p) {               idx1 = pos[i][p];               idx2 = mp[{i, freq[i][idx1]}];               if (idx1 >= idx2) break;               ans =                   max(ans, 2 * freq[i][idx1] + freq[j][idx2 - 1] - freq[j][idx1]);             }           }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double INF = 1e100;   int N, T, P[200000], L[200000], S[200000];   struct AddChange {     int id;     double dif;     AddChange(const int i) : id(i) {       if (S[i] == L[i])         dif = -INF;       else         dif = P[i] * ((double)(S[i] + 1) / (S[i] + 1 + L[i]) -                       (double)S[i] / (S[i] + L[i]));     }     bool operator<(const AddChange &c) const {       return dif != c.dif ? dif > c.dif : id < c.id;     }   };   struct RevChange {     int id;     double dif;     RevChange(const int i) : id(i) {       if (S[i] == 0)         dif = -INF;       else         dif = P[i] * ((double)(S[i] - 1) / (S[i] - 1 + L[i]) -                       (double)S[i] / (S[i] + L[i]));     }     bool operator<(const RevChange &c) const {       return dif != c.dif ? dif > c.dif : id < c.id;     }   };   set<AddChange> AC;   set<RevChange> RC;   double ANS;   double ExpEarn(const int id) { return P[id] * (double)S[id] / (S[id] + L[id]); }   void ModifyS(const int id, const int val) {     AC.erase(AddChange(id)), RC.erase(RevChange(id)), ANS -= ExpEarn(id);     S[id] += val, T -= val;     AC.insert(AddChange(id)), RC.insert(RevChange(id)), ANS += ExpEarn(id);   }   void ModifyL(const int id, const int val) {     AC.erase(AddChange(id)), RC.erase(RevChange(id)), ANS -= ExpEarn(id);     L[id] += val;     AC.insert(AddChange(id)), RC.insert(RevChange(id)), ANS += ExpEarn(id);   }   int main() {     for (int querycount; scanf( %d%d%d , &N, &T, &querycount) == 3;) {       for (int i = 0; i < N; i++) scanf( %d , &P[i]);       for (int i = 0; i < N; i++) scanf( %d , &L[i]);       for (int i = 0; i < N; i++) S[i] = 0;       AC.clear(), RC.clear();       for (int i = 0; i < N; i++)         AC.insert(AddChange(i)), RC.insert(RevChange(i));       ANS = 0.0;       while (T > 0 && AC.begin()->dif > 0.0) ModifyS(AC.begin()->id, 1);       for (int t, r; querycount--;) {         scanf( %d%d , &t, &r), r--;         if (t == 1)           ModifyL(r, 1);         else if (t == 2) {           if (S[r] > L[r] - 1) ModifyS(r, -1);           ModifyL(r, -1);         } else           assert(0);         for (bool changed = true; changed;) {           changed = false;           if (T > 0 && AC.begin()->dif > 0.0)             ModifyS(AC.begin()->id, 1), changed = true;           if (AC.begin()->dif + RC.begin()->dif > 0.0) {             const int a = RC.begin()->id, b = AC.begin()->id;             ModifyS(a, -1), ModifyS(b, 1);             changed = true;           }         }         printf( %.9f n , ANS);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int n, m, q;     cin >> n >> m >> q;     int grid[n][m];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) grid[i][j] = 0;     vector<vector<int>> instr(q);     for (int i = 0; i < q; i++) {       int t;       cin >> t;       instr[q - 1 - i].push_back(t);       int u = 1;       if (t == 3) u = 3;       for (int j = 0; j < u; j++) {         int x;         cin >> x;         instr[q - 1 - i].push_back(x);       }     }     for (int i = 0; i < q; i++) {       auto cur = instr[i];       if (cur[0] == 1) {         int r = cur[1] - 1;         vector<int> v(m);         for (int j = 0; j < m; j++) v[j] = grid[r][(j + m - 1) % m];         for (int j = 0; j < m; j++) grid[r][j] = v[j];       } else if (cur[0] == 2) {         int c = cur[1] - 1;         vector<int> v(n);         for (int j = 0; j < n; j++) v[j] = grid[(j + n - 1) % n][c];         for (int j = 0; j < n; j++) grid[j][c] = v[j];       } else         grid[cur[1] - 1][cur[2] - 1] = cur[3];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (j) cout <<    ;         cout << grid[i][j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300001;   int n, a, b, c, d, start, len;   vector<int> T;   long long dp[2][N + 2], seg[4 * N];   void build(int p, int s, int e) {     if (s == e) {       seg[p] = dp[1][s];       return;     }     build(2 * p, s, (s + e) / 2);     build(2 * p + 1, (s + e) / 2 + 1, e);     seg[p] = min(seg[2 * p], seg[2 * p + 1]);   }   long long get(int p, int s, int e, int a, int b) {     if (s >= a && e <= b) return seg[p];     if (s > b || e < a) return 1e15;     return min(get(2 * p, s, (s + e) / 2, a, b),                get(2 * p + 1, (s + e) / 2 + 1, e, a, b));   }   int main() {     scanf( %d%d%d%d%d%d%d , &n, &a, &b, &c, &d, &start, &len);     dp[0][0] = start;     dp[1][0] = start;     T.push_back(0);     for (int i = 1, t, q; i <= n; i++) {       scanf( %d%d , &t, &q);       dp[0][i] = dp[0][i - 1], dp[1][i] = dp[1][i - 1];       if (q)         dp[0][i] += a, dp[1][i] += c;       else         dp[0][i] -= b, dp[1][i] -= d;       T.push_back(t);     }     build(1, 0, n);     int j = n, c = 0;     auto it = lower_bound(T.begin(), T.end(), c + len);     if (it != T.end()) j = *it - 1;     if (get(1, 0, n, 0, j) >= 0) {       printf( %d n , c);       return 0;     }     for (int i = 0; i < T.size(); i++) {       if (dp[0][i] < 0) break;       c = T[i] + 1;       j = lower_bound(T.begin(), T.end(), c + len) - T.begin() - 1;       if (i == n || j < i + 1 ||           get(1, 0, n, i + 1, j) - dp[1][i] + dp[0][i] >= 0) {         printf( %d n , c);         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   struct Node {     int pos, id;     Node(int p = 0, int i = 0) : pos(p), id(i) {}     bool operator<(const Node& rhs) const { return pos < rhs.pos; }   } a[MAXN], b[MAXN];   int m, n;   long long c[3 * MAXN];   int ans[MAXN];   void add(int x, int y, int k) { c[x + n] += k, c[y + n] -= k; }   int main() {     scanf( %d%d , &m, &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i].pos);       a[i].pos--, a[i].id = i + 1;     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i].pos);       b[i].pos--, b[i].id = i + 1;     }     sort(a, a + n);     sort(b, b + n);     for (int i = 0; i < n; i++) {       int j = lower_bound(b, b + n, a[i]) - b - i;       int p = a[i].pos + (m + 1) / 2;       if (p < m) {         int k = lower_bound(b, b + n, Node(p)) - b - i;         add(j, k, -a[i].pos);         add(k, n - i, a[i].pos + m);         add(n - i, j + n, a[i].pos);       } else {         int k = lower_bound(b, b + n, Node(p - m)) - b - i;         add(j, n - i, -a[i].pos);         add(n - i, k + n, m - a[i].pos);         add(k + n, j + n, a[i].pos);       }     }     for (int i = 0; i < n; i++) {       int j = i - (upper_bound(a, a + n, b[i]) - a - 1);       int p = b[i].pos - (m + 1) / 2;       if (p >= 0) {         int k = i - (upper_bound(a, a + n, Node(p)) - a - 1);         add(j, k, b[i].pos);         add(k, j + n, -b[i].pos);       } else {         int k = i - (upper_bound(a, a + n, Node(p + m)) - a - 1);         add(j, k + n, b[i].pos);         add(k + n, j + n, -b[i].pos);       }     }     for (int i = 1; i < 3 * n; i++) c[i] += c[i - 1];     for (int i = 0; i < n; i++) c[i] += c[i + n] + c[i + 2 * n];     int p = min_element(c, c + n) - c;     printf( %lld n , c[p]);     for (int i = 0; i < n; i++) ans[a[i].id] = b[(i + p) % n].id;     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1e5 + 1, Mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, k;     cin >> n >> k;     std::vector<int> v(n);     for (auto &x : v) cin >> x;     multiset<int> s;     int pos = -1;     long long count = 0;     for (int i = 0; i < n; i++) {       if (v[i] < 0) {         count++;         if (pos != -1) {           s.insert(i - pos - 1);         }         pos = i;       }     }     int fx;     if (pos != -1) fx = n - 1 - pos;     if (count > k) {       cout <<  -1 n ;       return 0;     }     long long ans = 0;     int flag = 0;     for (int i = 0; i < n; i++) {       if (!flag) {         if (v[i] >= 0)           continue;         else {           ans++;           flag = flag ^ 1;         }       } else {         if (v[i] < 0)           continue;         else {           ans++;           flag = flag ^ 1;         }       }     }     k -= count;     int fl = 0;     for (auto x : s) {       if (x == 0) continue;       if (k < x) {         fl = 1;         if (fx != 0 && x > fx && fx <= k) {           k -= fx;           ans -= 1;         }         break;       }       ans -= 2;       k -= x;     }     if (!fl && fx != 0 && fx <= k) ans -= 1;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   const unsigned int Mod1 = 1000000009, Mod2 = 1000000007;   const unsigned int Bas1 = 12232, Bas2 = 14124;   struct mybit {     unsigned long long b[16];     mybit() { memset(b, 0, sizeof b); }     void clear() { memset(b, 0, sizeof b); }     void flip(int z) { b[z >> 6] ^= 1llu << (z & 63); }     unsigned int cnt() {       unsigned int ret = 0;       for (unsigned int j = 0u; j < 16u; ++j) ret += __builtin_popcount(b[j]);       return ret;     }     unsigned long long calc() {       unsigned int z1 = 0, z2 = 0;       for (unsigned int j = 0u; j < 16u; ++j)         z1 = (z1 + b[j] % Mod1 * Bas1) % Mod1,         z2 = (z2 + b[j] % Mod2 * Bas2) % Mod2;       return (unsigned long long)z1 << 32 | z2;     }     void operator^=(const mybit &p2) {       for (unsigned int j = 0u; j < 16u; ++j) b[j] ^= p2.b[j];     }   };   int N, S, Z, Q;   mybit bits[31], now;   std::unordered_map<unsigned long long, int> mp;   void DFS1(int st, int k) {     if (st > S) {       unsigned long long z = now.calc();       if (mp.find(z) != mp.end())         mp[z] = std::min(mp[z], k);       else         mp[z] = k;       return;     }     DFS1(st + 1, k);     now ^= bits[st];     DFS1(st + 1, k + 1);     now ^= bits[st];   }   int Ans;   void DFS2(int st, int k) {     if (st > Z) {       unsigned long long z = now.calc();       if (mp.find(z) != mp.end()) Ans = std::min(Ans, k + mp[z]);       return;     }     DFS2(st + 1, k);     now ^= bits[st];     DFS2(st + 1, k + 1);     now ^= bits[st];   }   int main() {     scanf( %d%d%d , &N, &S, &Q), Z = S / 3;     for (int i = 1; i <= S; ++i) {       unsigned int c, x;       scanf( %u , &c);       while (c--) {         scanf( %u , &x);         bits[i].flip(x - 1);       }     }     now.clear();     DFS1(Z + 1, 0);     while (Q--) {       now.clear();       unsigned int c, x;       scanf( %u , &c);       while (c--) {         scanf( %u , &x);         now.flip(x - 1);       }       Ans = S + 1;       DFS2(1, 0);       printf( %d n , Ans == S + 1 ? -1 : Ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   const long long mod2 = 998244353LL;   int n;   int a[100005], b[100005];   int main() {     cin >> n;     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);     long long det = 0;     int i = n, j = n;     bool cur = false;     while (i >= 1 || j >= 1) {       if (!cur) {         if (i < 1) {           j--;         } else {           if (j < 1) {             det += a[i];             i--;           } else {             if (a[i] >= b[j]) {               det += a[i];               i--;             } else {               j--;             }           }         }       } else {         if (j < 1) {           i--;         } else {           if (i < 1) {             det -= b[j];             j--;           } else {             if (b[j] >= a[i]) {               det -= b[j];               j--;             } else {               i--;             }           }         }       }       cur = !cur;     }     cout << det << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, m, k, dist, min_count, num;     vector<int> len_jumps, mosqs, mosq_count, result;     cin >> n >> m >> k;     len_jumps.resize(m);     mosqs.resize(k);     mosq_count.resize(m);     for (i = 0; i < m; i++) {       cin >> len_jumps[i];       mosq_count[i] = 0;     }     for (i = 0; i < k; i++) {       cin >> mosqs[i];     }     for (i = 0; i < m; i++) {       for (j = 0; j < k; j++) {         if (mosqs[j] % len_jumps[i] == 0) {           mosq_count[i]++;         }       }     }     min_count = n;     for (i = 0; i < m; i++) {       if (mosq_count[i] < min_count) {         min_count = mosq_count[i];       }     }     num = 0;     for (i = 0; i < m; i++) {       if (mosq_count[i] == min_count) {         num++;         result.push_back(i + 1);       }     }     cout << num << endl;     for (i = 0; i < result.size() - 1; i++) {       cout << result[i] <<    ;     }     cout << result[result.size() - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   const int mod = 1051131, inv2 = (mod + 1) / 2, phi = 700752;   using namespace std;   int n, T, s;   long long w;   int a[33554440];   void qmo(int &x) { x += (x >> 31) & mod; }   int ksm(int a, int k) {     int res = 1;     for (; k; k >>= 1, a = 1ll * a * a % mod)       if (k & 1) res = 1ll * res * a % mod;     return res;   }   void calc(int m, int p, int q) {     if (!m) return a[0] = 1ll * a[0] * ksm(p + q, T) % mod, void();     for (int i = 0; i < m; i++) {       int x = a[i], y = a[i + m];       qmo(a[i] = x + y - mod), qmo(a[i + m] = x - y);     }     calc(m >> 1, (p << 1) % mod, (q + 1ll * (m - 1) * p) % mod);     int w = ksm(q - 1ll * (m - 1) * p % mod + mod, T);     for (int i = 0; i < m; i++) {       int x = a[i], y = 1ll * a[i + m] * w % mod;       a[i] = 1ll * (x + y) * inv2 % mod,       a[i + m] = 1ll * (x - y + mod) * inv2 % mod;     }   }   int main() {     scanf( %d%lld%d , &n, &w, &s);     if (w > phi)       T = w % phi + phi;     else       T = w;     for (int i = 0; i < s; i++) scanf( %d , &a[i]);     for (int i = s; i < (1 << n); i++) a[i] = (a[i - s] * 101 + 10007) % mod;     calc((1 << n) / 2, 1, 0);     int res = 0;     for (int i = 0; i < (1 << n); i++) res ^= a[i];     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6) {       if (n % i == 0 || n % (i + 2) == 0) return false;     }     return true;   }   bool sec(const pair<long long, long long> &a,            const pair<long long, long long> &b) {     return a.second > b.second;   }   long long po(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     long long n;     cin >> n;     long long a[n], b[n], i, an = 0, m = 998244353;     for (i = 0; i < n; i++) {       cin >> a[i];       a[i] = a[i] * (i + 1) * (n - i);     }     for (i = 0; i < n; i++) cin >> b[i];     sort(b, b + n);     sort(a, a + n);     for (i = 0; i < n; i++) {       an += ((a[n - 1 - i] % m) * b[i]) % m;       an = an % m;     }     cout << an;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 5;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   mt19937 rnd(time(0));   signed main() {     long long q;     cin >> q;     while (q--) {       long long d, mod;       cin >> d >> mod;       long long c = 1;       long long lg = 0;       while ((1ll << lg) <= d) {         c = (c * (min(d, (1ll << (lg + 1)) - 1) - (1ll << lg) + 2ll)) % mod;         lg++;       }       c--;       if (c < 0) {         c += mod;       }       cout << c <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int h = 0, t = 1;     while ((ch >  9  || ch <  0 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) h = h * 10 + ch -  0 , ch = getchar();     return h * t;   }   const int N = 2001000;   struct edge {     int next, to;   } a[N];   int n, m, Ans, du[N], head[N], cnt = 1;   int dep[N], vis[N], fa[N], ed[N], ve[N];   void link(int x, int y) {     a[++cnt] = (edge){head[x], y};     head[x] = cnt;   }   void dfs(int x) {     for (int i = head[x]; i; i = a[i].next) {       int R = a[i].to;       if (R == fa[x]) continue;       if (!dep[R])         dep[R] = dep[x] + 1, fa[R] = x, ed[R] = i, dfs(R);       else if (dep[R] < dep[x]) {         vis[R] = ve[i] = ve[i ^ 1] = 1;         for (int p = x; p != R; p = fa[p])           vis[p] = 1, ve[ed[p]] = ve[ed[p] ^ 1] = 1;       }     }   }   void calctree(int x, int rt) {     if (!vis[x]) vis[x] = 2;     int s = 0;     for (int i = head[x]; i; i = a[i].next)       if (!ve[i]) ve[i] = ve[i ^ 1] = 1, calctree(a[i].to, rt), s++;     Ans += (s >> 1) + (x == rt && s & 1);   }   void calccircle(int x) {     vis[x] = 3;     for (int i = head[x]; i; i = a[i].next) {       int R = a[i].to;       if (R == fa[x]) continue;       if (vis[R] == 1)         dep[R] = dep[x] + 1, fa[R] = x, calccircle(R);       else if (vis[R] == 3 && dep[R] < dep[x]) {         int s = (du[R] > 2);         for (int p = x; p != R; p = fa[p]) s += (du[p] > 2);         Ans += (s < 2);       }     }   }   int main() {     n = read();     m = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       link(x, y);       link(y, x);       du[x]++;       du[y]++;     }     for (int i = 1; i <= n; i++)       if (!dep[i]) dep[i] = 1, dfs(i);     for (int i = 1; i <= n; i++)       if (vis[i]) calctree(i, i);     for (int i = 1; i <= n; i++)       if (!vis[i]) calctree(i, i);     for (int i = 1; i <= n; i++)       if (vis[i] == 1) dep[i] = 1, fa[i] = 0, calccircle(i);     printf( %d %d n , Ans, m);   }