#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T checkmin(T &a, T b) { n   return (a < b) ? a : a = b; n } n template <class T> n inline T checkmax(T &a, T b) { n   return (a > b) ? a : a = b; n } n template <class T> n T GCD(T a, T b) { n   if (a < 0) return GCD(-a, b); n   if (b < 0) return GCD(a, -b); n   return (a == 0) ? b : GCD(b % a, a); n } n template <class T> n T LCM(T a, T b) { n   if (a < 0) return LCM(-a, b); n   if (b < 0) return LCM(a, -b); n   return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b; n } n template <class T> n inline T sqr(T X) { n   return X * X; n } n namespace Poor { n const int MaxiN = 105; n const long long Infinity = 2000000000000000000LL; n int N, M; n long long K; n int C[MaxiN][MaxiN]; n int Weight[MaxiN + MaxiN]; n pair<int, int> List[MaxiN + MaxiN]; n char St[MaxiN + MaxiN]; n inline void Inc(long long &a, long long b) { n   a += b; n   if (a > Infinity) a = Infinity; n } n long long DP() { n   map<int, long long> Now, Suc; n   Now.clear(); n   Now[0] = 1; n   for (int i = 0; i < N + M - 1; ++i) { n     for (typeof(Now.begin()) it = Now.begin(); it != Now.end(); ++it) { n       if (St[i] !=  ) ) Inc(Suc[it->first + 1], it->second); n       if (St[i] !=  (  && it->first > 0) Inc(Suc[it->first - 1], it->second); n     } n     Now = Suc; n     Suc.clear(); n   } n   return Now[0]; n } n void Run() { n   cin >> N >> M >> K; n   for (int i = 0; i < N; ++i) n     for (int j = 0; j < M; ++j) cin >> C[i][j]; n   fill(Weight, Weight + N + M - 1, INT_MAX); n   for (int i = 0; i < N; ++i) n     for (int j = 0; j < M; ++j) checkmin(Weight[i + j], C[i][j]); n   for (int i = 0; i < N + M - 1; ++i) List[i] = make_pair(Weight[i], i); n   sort(List, List + N + M - 1); n   fill(St, St + N + M - 1,  ? ); n   for (int i = 0; i < N + M - 1; ++i) { n     int p = List[i].second; n     St[p] =  ( ; n     long long dp = DP(); n     if (dp < K) { n       K -= dp; n       St[p] =  ) ; n     } n   } n   for (int i = 0; i < N; ++i) { n     for (int j = 0; j < M; ++j) putchar(St[i + j]); n     puts(  ); n   } n } n }  // namespace Poor n int main() { n   Poor::Run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[7][7][101]; n int d[101], t[7]; n char cd[101]; n bool dfs(int now, int saw, int n) { n   if (saw == n) return true; n   for (int i = 0; i < 7; i++) n     if (a[now][i][0] > 0) { n       d[saw] = a[now][i][a[now][i][0]]; n       cd[saw] =  + ; n       a[now][i][0]--; n       if (dfs(i, saw + 1, n)) return true; n       a[now][i][0]++; n     } n   for (int i = 0; i < 7; i++) n     if (a[i][now][0] > 0) { n       d[saw] = a[i][now][a[i][now][0]]; n       cd[saw] =  - ; n       a[i][now][0]--; n       if (dfs(i, saw + 1, n)) return true; n       a[i][now][0]++; n     } n   return false; n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int v1, v2; n     cin >> v1 >> v2; n     a[v1][v2][0]++; n     a[v1][v2][a[v1][v2][0]] = i + 1; n     t[v1]++; n     t[v2]++; n   } n   int odd1 = -1, odd2 = -1; n   for (int i = 0; i < 7; i++) n     if (t[i] % 2 == 1) { n       if (odd2 != -1) { n         cout <<  No solution n ; n         return 0; n       } else if (odd1 == -1) n         odd1 = i; n       else n         odd2 = i; n     } n   if (odd1 != -1 && odd2 == -1) { n     cout <<  No solution n ; n     return 0; n   } n   if (odd1 != -1) { n     if (dfs(odd1, 0, n)) { n       for (int i = 0; i < n; i++) cout << d[i] <<     << cd[i] << endl; n       return 0; n     } else { n       cout <<  No solution n ; n       return 0; n     } n   } else { n     for (int i = 0; i < 7; i++) n       if (t[i] > 0) { n         if (dfs(i, 0, n)) { n           for (int j = 0; j < n; j++) cout << d[j] <<     << cd[j] << endl; n           return 0; n         } else { n           cout <<  No solution n ; n           return 0; n         } n       } n     cout <<  No solution n ; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000009; n int n, m, k; n class Mat { n  public: n   long long e[2][2]; n   Mat mul(Mat u) { n     Mat s; n     for (int i = 0; i < 2; i++) { n       for (int j = 0; j < 2; j++) { n         s.e[i][j] = 0; n         for (int k = 0; k < 2; k++) { n           s.e[i][j] += e[i][k] * u.e[k][j]; n           s.e[i][j] %= mod; n         } n       } n     } n     return s; n   } n   Mat powMat(Mat u, int k) { n     Mat mat; n     memset(mat.e, 0, sizeof(mat.e)); n     mat.e[0][0] = 1; n     mat.e[1][1] = 1; n     while (k) { n       if (k & 1) { n         mat = mat.mul(u); n       } n       u = u.mul(u); n       k = (k >> 1); n     } n     return mat; n   } n }; n bool good(int mid) { n   int n1 = n - mid * k; n   int m1 = m - mid * k; n   int ans = n1 / k * (k - 1) + n1 % k; n   if (ans >= m1) return true; n   return false; n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   int l = 0, r = m / k; n   int mid; n   while (l < r) { n     mid = (l + r) / 2; n     if (good(mid)) n       r = mid; n     else n       l = mid + 1; n   } n   Mat u; n   u.e[0][0] = (long long)k; n   u.e[0][1] = 1L; n   u.e[1][0] = 0; n   u.e[1][1] = 0; n   Mat v; n   v.e[0][0] = 2L; n   v.e[0][1] = 0; n   v.e[1][0] = (long long)k; n   v.e[1][1] = 1L; n   u = u.mul(v.powMat(v, l)); n   long long ans = (u.e[0][0] - k + (m - l * k) + mod) % mod; n   cout << ans; n   return 0; n } n


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n long a[1000000], m, n, i, j, k, l, ma, mi; n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   if (n <= 2) { n     cout << -1 << endl; n     return 0; n   } n   for (i = 1; i <= n - 2; i++) n     if (a[i] != a[i + 2]) { n       if (a[i] == a[i + 1]) { n         cout << i + 1 <<     << i + 2 << endl; n         return 0; n       } else if (a[i + 1] == a[i + 2]) { n         cout << i <<     << i + 1 << endl; n         return 0; n       } else { n         if (a[i] > a[i + 1] && a[i] > a[i + 2]) n           ma = i; n         else if (a[i + 1] > a[i] && a[i + 1] > a[i + 2]) n           ma = i + 1; n         else n           ma = i + 2; n         if (a[i] < a[i + 1] && a[i] < a[i + 2]) n           mi = i; n         else if (a[i + 1] < a[i] && a[i + 1] < a[i + 2]) n           mi = i + 1; n         else n           mi = i + 2; n         if (ma != i + 1) { n           if (ma != i + 2) n             cout << i <<     << i + 1 << endl; n           else n             cout << i + 2 <<     << i + 1 << endl; n           return 0; n         } n         if (mi != i + 1) { n           if (mi != i + 2) n             cout << i <<     << i + 1 << endl; n           else n             cout << i + 2 <<     << i + 1 << endl; n           return 0; n         } n       } n     } n   if (n == 3 && a[1] == a[3]) { n     cout << -1 << endl; n     return 0; n   } else if (a[1] != a[2]) n     cout << 1 <<     << 2 << endl; n   else n     cout << -1 << endl; n } n


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n int n, m, h, t, r, x, y, dis[210][210], h1[210], t1[210], h2[210], t2[210], n     bfs[210 * 210][2], L, R; n void renew(int x, int y, int v) { n   if (x + y > r) return; n   if (dis[x][y] == -1) { n     dis[x][y] = v; n     bfs[++R][0] = x; n     bfs[R][1] = y; n   } n } n int dfs(int x, int y) { n   if (x + y > r) return 0; n   int i, p = 1; n   if (dis[x][y] == -1) { n     printf( Draw n ); n     exit(0); n   } n   if (dis[x][y]) return dis[x][y]; n   dis[x][y] = -1; n   for (i = 1; i <= n && i <= x; ++i) n     p = max(p, dfs(x - i + h1[i], y + t1[i]) + 1); n   for (i = 1; i <= m && i <= y; ++i) n     p = max(p, dfs(x + h2[i], y - i + t2[i]) + 1); n   dis[x][y] = p; n   return p; n } n int main() { n   int i; n   scanf( %d%d%d , &h, &t, &r); n   scanf( %d , &n); n   for (i = 1; i <= n; ++i) scanf( %d%d , &h1[i], &t1[i]); n   scanf( %d , &m); n   for (i = 1; i <= m; ++i) scanf( %d%d , &h2[i], &t2[i]); n   memset(dis, -1, sizeof(dis)); n   dis[h][t] = 0; n   bfs[L = R = 1][0] = h; n   bfs[1][1] = t; n   while (L <= R) { n     x = bfs[L][0]; n     y = bfs[L++][1]; n     for (i = 1; i <= n && i <= x; ++i) n       renew(x - i + h1[i], y + t1[i], dis[x][y] + 1); n     for (i = 1; i <= m && i <= y; ++i) n       renew(x + h2[i], y - i + t2[i], dis[x][y] + 1); n   } n   if (dis[0][0] != -1) return printf( Ivan n%d n , dis[0][0]), 0; n   memset(dis, 0, sizeof(dis)); n   printf( Zmey n%d n , dfs(h, t)); n } n


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n inline char gc() { n   static char now[1 << 16], *S, *T; n   if (T == S) { n     T = (S = now) + fread(now, 1, 1 << 16, stdin); n     if (T == S) return EOF; n   } n   return *S++; n } n inline long long read() { n   register long long x = 0, f = 1; n   char ch = gc(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = gc(); n   } n   while (isdigit(ch)) { n     x = (x << 3) + (x << 1) + ch -  0 ; n     ch = gc(); n   } n   return (f == 1) ? x : -x; n } n long long a[1010101], b[1010101], m, n, ida[1010101], idb[1010101]; n long long A[1010101], B[1010101], ans[1010101]; n inline bool cmpa(long long i, long long j) { return a[i] < a[j]; } n inline bool cmpb(long long i, long long j) { return b[i] < b[j]; } n signed main() { n   m = read(), n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(), ida[i] = i; n   for (int i = 1; i <= n; i++) b[i] = read(), idb[i] = i; n   sort(ida + 1, ida + 1 + n, cmpa); n   sort(idb + 1, idb + 1 + n, cmpb); n   sort(a + 1, a + 1 + n); n   sort(b + 1, b + 1 + n); n   for (int i = 1; i <= n; i++) { n     b[i + n] = b[i]; n     b[i + 2 * n] = b[i] + m; n     b[i] -= m; n   } n   for (int i = 1, j = 0; i <= n; i++) { n     for (; b[j + 1] <= a[i] && j + 1 <= 3 * n; j++) n       ; n     if (j - i + 1 >= 1) A[1] += a[i], A[j - i + 2] -= a[i]; n     if (j - i + 2 <= 2 * n + 1) n       A[max(1, j - i + 2)] -= a[i], A[2 * n + 2] += a[i]; n   } n   for (int j = 1, i = 0; j <= 3 * n; j++) { n     for (; b[j] > a[i + 1] && i + 1 <= n; i++) n       ; n     if (j - i + 1 <= j) B[max(1, j - i + 1)] += b[j], B[j + 1] -= b[j]; n     if (max(1ll, j - n + 1) <= j - i + 1 && j - i + 1 > 0) n       B[max(1ll, j - n + 1)] -= b[j], B[j - i + 1] += b[j]; n   } n   for (int i = 1; i <= 2 * n + 1; i++) { n     A[i] += A[i - 1]; n     B[i] += B[i - 1]; n   } n   long long ansid = 0; n   A[ansid] = B[ansid] = 99999999999999; n   for (int i = 1; i <= 2 * n + 1; i++) { n     if (A[ansid] + B[ansid] > A[i] + B[i]) ansid = i; n   } n   cout << A[ansid] + B[ansid] <<   n ; n   for (int i = 1; i <= n; i++) { n     ans[ida[i]] = idb[(ansid + i - 2) % n + 1]; n   } n   for (int i = 1; i <= n; i++) { n     printf( %lld  , ans[i]); n   } n   return 0; n } n


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n int mx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}, my[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; n int main() { n   ios::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   char a[n + 2][m + 2]; n   memset(a, 0, sizeof a); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j]; n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       if (a[i][j] !=  * ) { n         int cnt = 0; n         for (int k = 0; k <= 7; k++) { n           if (a[i + mx[k]][j + my[k]] ==  * ) cnt++; n         } n         if (!(cnt == 0 && a[i][j] ==  .  || cnt > 0 && a[i][j] -  0  == cnt)) { n           cout <<  NO  << endl; n           return 0; n         } n       } n     } n   cout <<  YES  << endl; n   return 0; n } n


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


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


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


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


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


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


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


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


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


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


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


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


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