#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct Node {     int cnt, l, r, z_0, z_1;     Node() {       cnt = 0;       l = r = -1;       z_0 = z_1 = 0;     }   };   vector<Node> Trie;   void update(int x) {     int cur = 0;     for (int i = 30; i >= 0; i--) {       int c = (((1 << i) & x) > 0);       if (Trie[cur].l == -1) {         Trie.push_back(Node());         Trie[cur].l = Trie.size() - 1;       }       if (Trie[cur].r == -1) {         Trie.push_back(Node());         Trie[cur].r = Trie.size() - 1;       }       if (!c)         cur = Trie[cur].l;       else         cur = Trie[cur].r;       Trie[cur].cnt++;     }   }   int query(int x, int k) {     int ans = 0, cur = 0;     for (int i = 30; i >= 0; i--) {       int c_x = (((1 << i) & x) > 0);       int c_k = (((1 << i) & k) > 0);       if (Trie[cur].l == -1) {         Trie.push_back(Node());         Trie[cur].l = Trie.size() - 1;       }       if (Trie[cur].r == -1) {         Trie.push_back(Node());         Trie[cur].r = Trie.size() - 1;       }       if (!c_x) {         if (!c_k) {           ans += Trie[Trie[cur].r].cnt;           cur = Trie[cur].l;         } else           cur = Trie[cur].r;       } else {         if (!c_k) {           ans += Trie[Trie[cur].l].cnt;           cur = Trie[cur].r;         } else           cur = Trie[cur].l;       }     }     ans += Trie[cur].cnt;     return ans;   }   void update2(int x, int col) {     int cur = 0;     for (int i = 30; i >= 0; i--) {       int c = (((1 << i) & x) > 0);       if (Trie[cur].l == -1) {         Trie.push_back(Node());         Trie[cur].l = Trie.size() - 1;       }       if (Trie[cur].r == -1) {         Trie.push_back(Node());         Trie[cur].r = Trie.size() - 1;       }       if (!c)         cur = Trie[cur].l;       else         cur = Trie[cur].r;       if (col == 1)         Trie[cur].z_1++;       else         Trie[cur].z_0++;     }   }   long long query2(int x, int k, int col) {     long long ans = 0;     int cur = 0;     for (int i = 30; i >= 0; i--) {       int c_x = (((1 << i) & x) > 0);       int c_k = (((1 << i) & k) > 0);       if (Trie[cur].l == -1) {         Trie.push_back(Node());         Trie[cur].l = Trie.size() - 1;       }       if (Trie[cur].r == -1) {         Trie.push_back(Node());         Trie[cur].r = Trie.size() - 1;       }       if (!c_x) {         if (!c_k) {           if (col == 1)             ans += Trie[Trie[cur].r].z_1;           else             ans += Trie[Trie[cur].r].z_0;           cur = Trie[cur].l;         } else           cur = Trie[cur].r;       } else {         if (!c_k) {           if (col == 1)             ans += Trie[Trie[cur].l].z_1;           else             ans += Trie[Trie[cur].l].z_0;           cur = Trie[cur].r;         } else           cur = Trie[cur].l;       }     }     if (col == 1)       ans += Trie[cur].z_1;     else       ans += Trie[cur].z_0;     return ans;   }   int n, m;   int a[50001];   int check(int x) {     Trie.clear();     Trie.push_back(Node());     int cnt = 0;     for (int i = 1; i <= n; i++) {       cnt += query(a[i], x);       update(a[i]);     }     return cnt;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     if (m == 0) {       cout << 0;       return 0;     }     for (int i = 1; i <= n; i++) cin >> a[i];     long long l = 0, r = 2e9;     int ans = -1;     while (l <= r) {       long long mi = (l + r) / 2;       if (check(mi) >= m) {         ans = mi;         l = mi + 1;       } else         r = mi - 1;     }     int lft = check(ans) - m;     long long res = 0;     for (int j = 0; j <= 30; j++) {       Trie.clear();       Trie.push_back(Node());       for (int i = 1; i <= n; i++) {         int c = (((1 << j) & a[i]) > 0);         res = (res + (query2(a[i], ans, 1 - c) * (1LL << j)) % mod) % mod;         update2(a[i], c);       }     }     cout << ((res - lft * ans) % mod + mod) % mod;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int i, k, j, l, a, b, len;     scanf( %ld%ld , &len, &k);     if (k > len) {       printf( -1 n );       return 0;     }     if ((len > 1) && (k == 1)) {       printf( -1 n );       return 0;     }     if ((len == 1) && (k == 1)) {       printf( a n );       return 0;     }     if ((len == 2) && (k == 2)) {       printf( ab n );       return 0;     } else if (k == 2) {       for (i = 1; i <= len; i++) {         if (i % 2 == 1)           printf( a );         else if (i % 2 == 0)           printf( b );       }       printf(  n );     } else {       for (i = 1; i <= (len + 2 - k); i++) {         if (i % 2 == 1)           printf( a );         else if (i % 2 == 0)           printf( b );       }       b = k - 1;       for (i = 1; i <= (k - 2); i++) {         a = i % b;         printf( %c , (98 + a));       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100005];   int main(void) {     int n, a, b;     scanf( %d%d%d%s , &n, &a, &b, s);     --a;     --b;     puts(s[a] != s[b] ?  1  :  0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     ;     int precision = numeric_limits<double>::digits10;     ;     int n;     cin >> n;     int j = sqrt(n), k = sqrt(n);     for (int i = j; i > 0; i--) {       for (int p = k; p < n + 1; p++) {         if (i * p == n) {           cout << i <<     << p << endl;           return 0;         }       }     }   }


#include <bits/stdc++.h>   const long long MOD = 1e9 + 7;   using pii = std::pair<long long, long long>;   using namespace std;   long long n;   string s;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> s;     long long good = 1;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < i; j++)         for (long long k = 0; k < j; k++)           if (s[k] > s[j] && s[j] > s[i]) {             good = 0;             break;           }     long long ans[205] = {0};     for (long long i = 0; i < n; i++)       for (long long j = i + 1; j < n; j++)         if (s[j] < s[i]) ans[j] = !ans[i];     if (!good)       cout <<  NO n ;     else {       cout <<  YES n ;       for (long long i = 0; i < n; i++) cout << ans[i];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50005;   int n;   int id[N];   vector<pair<int, int> > val;   vector<int> sol;   int main() {     ios ::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> id[i];     }     id[n] = id[0];     for (int i = 0; i < n; i++) {       val.push_back(make_pair((n - id[i]) - id[i + 1], i));     }     sort(val.begin(), val.end());     sol.resize(n);     for (int i = 0; i < n; i++) {       sol[val[i].second] = n - i - 1;     }     for (int i = 0; i < n; i++) {       cout << sol[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ch[3000005][2];   int v[3000005];   map<int, int> mp;   int sz;   void inser(int x) {     int u = 0;     for (int i = 20; i >= 0; i--) {       int c = x >> i & 1;       if (!ch[u][c]) {         memset(ch[sz], 0, sizeof(ch[sz]));         v[sz] = 0;         ch[u][c] = sz++;       }       u = ch[u][c];     }     v[u] = x;   }   int query(int y) {     int u = 0;     for (int i = 20; i >= 0; i--) {       int c = y >> i & 1;       if (ch[u][c])         u = ch[u][c];       else         u = ch[u][c ^ 1];     }     return v[u] ^ y;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     sz = 1;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       mp[x] = 1;     }     for (int i = 0; i <= 600005; i++) {       if (mp[i] == 0) inser(i);     }     int yi = 0;     for (int i = 1; i <= m; i++) {       int y;       scanf( %d , &y);       yi ^= y;       printf( %d n , query(yi));     }     return 0;   }


#include <bits/stdc++.h>   const int N = 205;   int n, m, A[N][N], a[N][N], h[N], l[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &A[i][j]);     for (int i = 0; i <= m; i++) {       int f = 1;       memcpy(a, A, sizeof(A));       memset(h, 0, sizeof(h));       memset(l, 0, sizeof(l));       for (int j = 1; j <= m; j++)         if ((j <= i && a[1][j]) || (j > i && a[1][j] == 0)) {           for (int k = 1; k <= n; k++) a[k][j] ^= 1;           l[j] ^= 1;         }       for (int j = 2; j <= n; j++) {         int f0 = 1, f1 = 1;         for (int k = 1; k <= m; k++)           if (a[j][k])             f0 = 0;           else             f1 = 0;         if (f0)           h[j] ^= 1;         else if (!f1) {           f = 0;           break;         }       }       if (f) {         puts( YES );         for (int j = 1; j <= n; j++) printf( %d , h[j]);         puts(  );         for (int j = 1; j <= m; j++) printf( %d , l[j]);         puts(  );         return 0;       }     }     memcpy(a, A, sizeof(A));     memset(h, 0, sizeof(h));     memset(l, 0, sizeof(l));     for (int i = 1; i <= m; i++)       if (a[1][i]) {         for (int k = 1; k <= n; k++) a[k][i] ^= 1;         l[i] ^= 1;       }     int f = 2;     for (int j = 2; j <= n; j++) {       int cnt = 0, c = a[j][1];       for (int k = 2; k <= m; k++)         if (a[j][k] != a[j][k - 1]) cnt++;       if (cnt > 1) {         puts( NO );         return 0;       }       if (cnt == 0 && f == 2) {         if (c == 1) h[j] ^= 1;         continue;       }       if (cnt == 0 && f == 1) {         if (c == 0) h[j] ^= 1;         continue;       }       if (cnt == 1 && f == 2) {         f--;         if (c) h[j] ^= 1;         continue;       }       puts( NO );     }     puts( YES );     for (int j = 1; j <= n; j++) printf( %d , h[j]);     puts(  );     for (int j = 1; j <= m; j++) printf( %d , l[j]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long maxn = 60;   const char spec1[5] = { T ,  J ,  Q ,  K ,  A };   const char spec2[4] = { S ,  D ,  H ,  C };   long start[maxn];   bool pos[maxn][maxn][maxn][maxn];   long n;   bool ispair[maxn][maxn];   int main() {     scanf( %ld , &n);     long q;     long maxx = -1;     for (q = 1; q <= n; q++) {       long tmp1 = -1;       long tmp2 = -1;       string s;       cin >> s;       if ((s[0] >=  2 ) && (s[0] <=  9 ))         tmp1 = s[0] -  2 ;       else {         for (long j = 0; j <= 4; j++)           if (spec1[j] == s[0]) {             tmp1 = j + 8;             break;           }       }       for (long j = 0; j <= 3; j++)         if (spec2[j] == s[1]) {           tmp2 = j;           break;         }       assert(tmp1 != -1);       assert(tmp2 != -1);       start[q] = tmp2 * 13 + tmp1 + 1;       maxx = max(maxx, start[q]);     }     for (long first = 1; first <= 52; first++)       for (long second = 1; second <= 52; second++) {         long t1 = (first - 1) % 13;         long t2 = (first - 1) / 13;         long t3 = (second - 1) % 13;         long t4 = (second - 1) / 13;         ispair[first][second] = ((t1 == t3) || (t2 == t4));       }     long t1, t2, t3;     if (n >= 3)       t1 = start[n - 2];     else       t1 = 0;     if (n >= 2)       t2 = start[n - 1];     else       t2 = 0;     t3 = start[n];     pos[n][t1][t2][t3] = true;     for (long it = n; it > 1; it--)       for (long first = 0; first <= maxx; first++)         for (long second = 0; second <= maxx; second++)           for (long third = 0; third <= maxx; third++)             if (pos[it][first][second][third]) {               if (ispair[second][third]) {                 long tmp;                 if (it - 3 > 0)                   tmp = start[it - 3];                 else                   tmp = 0;                 pos[it - 1][tmp][first][third] = true;               }               if ((it - 3 > 0) && (ispair[start[it - 3]][third]))                 pos[it - 1][third][first][second] = true;             }     for (long j = 0; j <= maxx; j++)       if (pos[1][0][0][j]) {         printf( YES n );         exit(0);       }     printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   template <class I>   inline void ckMax(I& p, I q) {     p = (p > q ? p : q);   }   template <class I>   inline void ckMin(I& p, I q) {     p = (p < q ? p : q);   }   template <class I>   inline I Max(I& p, I q) {     return p > q ? p : q;   }   template <class I>   inline I Min(I& p, I q) {     return p < q ? p : q;   }   template <class I>   inline void sp(I& p, I& q) {     I x = p;     p = q, q = x;   }   int n, m, k, a[N];   long long f[N][N], ans;   deque<int> q[N];   int main() {     scanf( %d%d%d , &n, &k, &m);     register int i, j;     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     q[0].push_back(0);     for (i = 1; i <= n; ++i)       for (j = m; j; --j) {         while ((!q[j - 1].empty()) && q[j - 1].front() < i - k)           q[j - 1].pop_front();         if (q[j - 1].empty()) continue;         f[i][j] = f[q[j - 1].front()][j - 1] + a[i];         while ((!q[j].empty()) && f[q[j].back()][j] <= f[i][j]) q[j].pop_back();         q[j].push_back(i);       }     for (i = n - k + 1; i <= n; ++i) ckMax(ans, f[i][m]);     printf( %lld , ans > 0 ? ans : -1ll);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int matrix[505][505];   int m, n;   int col[505];   int row[505];   int prime[110000];   int pc;   bool visit[110000];   void init() {     for (int i = 2; i < 110000; i++) {       if (visit[i]) continue;       for (int j = i * 2; j < 110000; j += i) visit[j] = true;     }     for (int i = 2; i < 110000; i++)       if (!visit[i]) prime[pc++] = i;   }   int next(int num) {     int l, r, mid;     l = 0;     r = pc - 1;     while (l < r) {       mid = (l + r) / 2;       if (prime[mid] < num)         l = mid + 1;       else         r = mid;     }     return prime[r] - num;   }   int main() {     int i, j, v, tmp, min;     cin >> n >> m;     init();     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) cin >> matrix[i][j];     for (i = 0; i < n; i++) {       v = 0;       for (j = 0; j < m; j++) {         tmp = next(matrix[i][j]);         col[j] += tmp;         v += tmp;       }       row[i] = v;     }     min = INT_MAX;     for (i = 0; i < n; i++)       if (min > row[i]) min = row[i];     for (j = 0; j < m; j++)       if (min > col[j]) min = col[j];     cout << min << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   const double eps = 1e-9;   const double pi = acos(-1.0);   int Sng(double x) {     if (x < -eps) return -1;     if (x > eps) return 1;     return 0;   }   class Point {    public:     double x, y;     Point(double x = 0, double y = 0) : x(x), y(y) {}     void Read() { scanf( %lf%lf , &x, &y); }     double Angle() { return atan2(y, x); }     friend double Dis(const Point &A, const Point &B);   };   Point operator-(const Point &A, const Point &B) {     return Point(A.x - B.x, A.y - B.y);   }   double Dis(const Point &A, const Point &B) {     return sqrt(((A.x - B.x) * (A.x - B.x)) + ((A.y - B.y) * (A.y - B.y)));   }   struct Data {     double x;     int io;     Data(double x = 0, int io = 0) : x(x), io(io) {}     bool operator<(const Data &O) const {       if (Sng(x - O.x)) return x < O.x;       return io > O.io;     }   };   void Good(double &x) {     while (x < -pi) x += 2.0 * pi;     while (x > pi) x -= 2.0 * pi;   }   Point p[N];   Data sk[N * 20];   double ang[N][N], dis[N][N];   int w, h, n, top;   int Add(double l, double r) {     Good(l);     Good(r);     sk[top++] = (Data(l, 1));     sk[top++] = (Data(r, -1));     return l > r;   }   bool Check(int id, double m) {     if (Sng(m) == 0) return true;     int cnt = 0;     top = 0;     if (p[id].x < m) {       double agl = acos(p[id].x / m);       cnt += Add(pi - agl, pi + agl);       cnt += Add(pi - agl, pi + agl);     }     if (p[id].x + m > w) {       double agl = acos((w - p[id].x) / m);       cnt += Add(-agl, agl);       cnt += Add(-agl, agl);     }     if (p[id].y < m) {       double agl = acos(p[id].y / m);       cnt += Add(1.5 * pi - agl, 1.5 * pi + agl);       cnt += Add(1.5 * pi - agl, 1.5 * pi + agl);     }     if (p[id].y + m > h) {       double agl = acos((h - p[id].y) / m);       cnt += Add(0.5 * pi - agl, 0.5 * pi + agl);       cnt += Add(0.5 * pi - agl, 0.5 * pi + agl);     }     for (int i = 0; i < n; i++) {       if (i == id || Sng(dis[id][i]) == 0 || dis[id][i] >= 2 * m) continue;       double agl = acos((dis[id][i] / 2 / m));       cnt += Add(ang[i][id] - agl, ang[i][id] + agl);     }     if (cnt <= 1) return true;     sort(sk, sk + top);     for (int i = 0; i < top; i++) {       cnt += sk[i].io;       if (cnt <= 1) return true;     }     return false;   }   int main() {     scanf( %d%d%d , &w, &h, &n);     for (int i = 0; i < n; i++) {       p[i].Read();     }     random_shuffle(p, p + n);     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         ang[i][j] = (p[i] - p[j]).Angle();         ang[j][i] = (p[j] - p[i]).Angle();         dis[j][i] = dis[i][j] = Dis(p[i], p[j]);       }     double ans = 0.0;     for (int i = 0; i < n; i++) {       if (Check(i, ans + eps) == false) continue;       double l = ans, r = sqrt(1.0 * w * w + 1.0 * h * h);       for (int t = 0; r - l > 1e-10; t++) {         double mid = (l + r) / 2.0;         if (Check(i, mid))           l = mid + eps, ans = mid;         else           r = mid - eps;       }     }     printf( %.15lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class _T>   inline _T sqr(const _T &first) {     return first * first;   }   template <class _T>   inline string tostr(const _T &a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   const long double EPS = 1e-12;   char TEMPORARY_CHAR;   const int INF = 1e9;   inline void fft(vector<complex<long double> > &a, bool invert) {     int n = (int)a.size();     for (int i = 1, j = 0; i < n; ++i) {       int bit = n >> 1;       for (; j >= bit; bit >>= 1) j -= bit;       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (int len = 2; len <= n; len <<= 1) {       long double ang = 2 * PI / len * (invert ? -1 : 1);       complex<long double> wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         complex<long double> w(1);         for (int j = 0; j < len / 2; ++j) {           complex<long double> u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert)       for (int i = 0; i < n; ++i) a[i] /= n;   }   inline void input(int &a) {     a = 0;     while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) &&            (TEMPORARY_CHAR !=  - )) {     }     char neg = 0;     if (TEMPORARY_CHAR ==  - ) {       neg = 1;       TEMPORARY_CHAR = getchar();     }     while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) {       a = (a << 3) + (a << 1) + TEMPORARY_CHAR -  0 ;       TEMPORARY_CHAR = getchar();     }     if (neg) a = -a;   }   inline void out(long long a) {     if (!a) putchar( 0 );     if (a < 0) {       putchar( - );       a = -a;     }     char s[20];     int i;     for (i = 0; a; ++i) {       s[i] =  0  + a % 10;       a /= 10;     }     for (int j = (i)-1; j >= 0; j--) putchar(s[j]);   }   inline int nxt() {     int(ret);     input((ret));     ;     return ret;   }   struct lnum {     vector<int> a;     int base;     lnum(int num = 0, int base = 1000000000) : base(base) {       if (!num) a.resize(1);       while (num) {         a.push_back(num % base);         num /= base;       }     }     inline int len() const { return a.size(); }     lnum &operator=(const lnum &l) {       if (this != &l) {         a = l.a;         base = l.base;       }       return *this;     }     inline friend lnum operator+(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       int ln = l.len(), rn = r.len();       int n = max(ln, rn);       ret.a.resize(n);       int o = 0;       for (int i = 0; i < n; ++i) {         int s = o;         if (i < ln) s += l.a[i];         if (i < rn) s += r.a[i];         o = s >= base;         if (o) s -= base;         ret.a[i] = s;       }       if (o) ret.a.push_back(1);       return ret;     }     inline friend lnum operator-(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       int n = l.len();       int rn = r.len();       ret.a.resize(n);       int o = 0;       for (int i = 0; i < n; ++i) {         int s = l.a[i] - o;         if (i < rn) s -= r.a[i];         o = s < 0;         if (o) s += base;         ret.a[i] = s;       }       if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back();       return ret;     }     inline friend lnum operator*(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       if (l.len() * r.len() > 1000000) {         vector<complex<long double> > fa(l.a.begin(), l.a.end()),             fb(r.a.begin(), r.a.end());         int n = 1;         while (n < max(l.len(), r.len())) n <<= 1;         n <<= 1;         fa.resize(n), fb.resize(n);         fft(fa, false), fft(fb, false);         for (int i = 0; i < n; ++i) fa[i] *= fb[i];         fft(fa, true);         ret.a.resize(n);         for (int i = 0; i < n; ++i) ret.a[i] = int(fa[i].real() + 0.5);         int carry = 0;         for (int i = 0; i < n; ++i) {           ret.a[i] += carry;           carry = ret.a[i] / base;           ret.a[i] %= base;         }       } else {         ret.a.resize(l.len() + r.len());         for (int i = 0; i < l.len(); ++i)           for (int j = 0, carry = 0; j < r.len() || carry; ++j) {             long long cur = ret.a[i + j] +                             (long long)l.a[i] * (j < r.len() ? r.a[j] : 0) +                             carry;             ret.a[i + j] = cur % base;             carry = cur / base;           }       }       while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back();       return ret;     }     inline friend lnum operator/(const lnum &l, const int &r) {       lnum ret(0, l.base);       ret.a.resize(l.len());       int carry = 0;       for (int i = l.len() - 1; i >= 0; --i) {         long long cur = l.a[i] + (long long)carry * l.base;         ret.a[i] = cur / r;         carry = cur % r;       }       while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back();       return ret;     }     inline friend bool operator<(const lnum &l, const lnum &r) {       if (l.len() < r.len()) return true;       if (l.len() > r.len()) return false;       int n = l.len();       for (int i = n - 1; i >= 0; --i) {         if (l.a[i] < r.a[i]) return true;         if (l.a[i] > r.a[i]) return false;       }       return false;     }     inline friend bool operator>(const lnum &l, const lnum &r) { return r < l; }     inline friend bool operator==(const lnum &l, const lnum &r) {       if (l.len() != r.len()) return false;       int n = l.len();       for (int i = n - 1; i; --i) {         if (l.a[i] != r.a[i]) return false;       }       return true;     }     inline friend bool operator!=(const lnum &l, const lnum &r) {       return !(l == r);     }     inline void print() {       if (base == 1000000000) {         printf( %d , a.back());         for (int i = a.size() - 2; i >= 0; --i) printf( %09d , a[i]);       } else {         for (int i = a.size() - 1; i >= 0; --i) printf( %d , a[i]);       }     }   };   vector<int> get(int n, int len) {     vector<int> ret;     ret.push_back(n);     ret.push_back(-n);     for (int i = 1, p = 10; i < len; ++i, p *= 10) {       vector<int> a = get(n % p, i);       vector<int> b = get(n / p, len - i);       for (int i = 0; i < (int)(a.size()); i++) {         for (int j = 0; j < (int)(b.size()); j++) {           ret.push_back(a[i] * b[j]);           ret.push_back(a[i] + b[j]);           ret.push_back(a[i] - b[j]);         }       }     }     sort((ret).begin(), (ret).end());     ret.resize(unique((ret).begin(), (ret).end()) - ret.begin());     return ret;   }   int main() {     int(k);     input((k));     ;     int(m);     input((m));     ;     set<string> s;     char buf[10];     for (int i = 0; i < (int)(10000); i++) {       vector<int> cur = get(i, 4);       for (int j = 0; j < (int)(cur.size()); j++) {         if (abs(k - cur[j]) < 10000) {           sprintf(buf,  %04d%04d , abs(k - cur[j]), i);           sprintf(buf,  %04d%04d , i, abs(k - cur[j]));           s.insert(string(buf));           if ((int)s.size() >= m) break;         }       }       if ((int)s.size() >= m) break;     }     for (__typeof((s).begin()) i = (s).begin(); i != (s).end(); i++) {       cout << *i << endl;     }     return 0;   }


#include <bits/stdc++.h>   struct el {     int x, y, z;   };   using namespace std;   int cmp(el a, el b) { return a.x < b.x; }   int cmp1(el a, el b) { return a.y < b.y; }   int main(int argc, const char* argv[]) {     int n, w;     cin >> n >> w;     vector<el> a;     el b;     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> b.x;       ans += b.x / 2 + b.x % 2;       b.z = b.x / 2 + b.x % 2;       b.y = i;       a.push_back(b);     }     if (ans > w) {       cout << -1;       return 0;     }     int diff = w - ans;     sort(a.begin(), a.end(), cmp);     for (int i = (int)a.size() - 1; (i > -1) && (diff > 0); i--) {       int tmp = min(diff, a[i].x - (a[i].x / 2 + a[i].x % 2));       a[i].z += tmp;       diff -= tmp;     }     sort(a.begin(), a.end(), cmp1);     for (auto i = a.begin(); i != a.end(); i++) {       cout << (*i).z <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     int n;     cin >> n;     vector<pair<int, int> > arr[1001];     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       arr[x / 1000].push_back(make_pair(y, i));     }     for (int i = 0; i < 1001; i++)       if (arr[i].size() > 1) sort(arr[i].begin(), arr[i].end());     bool flag = 0;     for (int i = 0; i < 1001; i++) {       if (arr[i].size()) {         flag = (!flag);         if (flag)           for (int j = 0; j < arr[i].size(); j++) cout << arr[i][j].second <<    ;         else           for (int j = arr[i].size() - 1; j >= 0; j--)             cout << arr[i][j].second <<    ;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 200010, LOG = 20;   struct DSU {     int par[MAXN];     int rank[MAXN];     stack<pair<int*, int>> stk;     DSU() {       for (int i = 1; i < MAXN; i++) par[i] = i;     }     int get(int x) {       if (par[x] == x) return x;       return get(par[x]);     }     int join(int x, int y) {       x = get(x);       y = get(y);       if (x == y) return 0;       if (rank[x] > rank[y]) swap(x, y);       stk.push({&par[x], par[x]});       stk.push({&rank[y], rank[y]});       par[x] = y;       rank[y] += (rank[x] == rank[y]);       return 1;     }     void undo(int cnt = 1) {       cnt <<= 1;       while (cnt--) {         auto it = stk.top();         stk.pop();         *it.first = it.second;       }     }   } dsu;   int n, m, k, u, v, x, y, a, b, last;   int T[MAXN], X[MAXN], Y[MAXN];   map<pair<int, int>, vector<int>> mp;   vector<pair<int, int>> seg[MAXN << 2];   set<pair<int, int>> edge;   string out;   int f(int x) {     if (x == n) return 1;     return x + 1;   }   pair<int, int> ff(int x, int y) {     if (x > y) swap(x, y);     return {x, y};   }   void Add(int id, int tl, int tr, int l, int r, pair<int, int> p) {     if (r <= tl || tr <= l) return;     if (l <= tl && tr <= r) {       seg[id].push_back(p);       return;     }     int mid = (tl + tr) >> 1;     Add(id << 1, tl, mid, l, r, p);     Add(id << 1 | 1, mid, tr, l, r, p);   }   void handle(int i) {     if (T[i] == 2) return;     if (last) X[i] = f(X[i]), Y[i] = f(Y[i]);     pair<int, int> p = ff(X[i], Y[i]);     if (edge.count(p))       edge.erase(p);     else       edge.insert(p);   }   void dfs(int id, int tl, int tr) {     int cnt = 0;     for (pair<int, int> p : seg[id])       if (edge.count(p)) cnt += dsu.join(p.first, p.second);     if (tr - tl == 1) {       if (T[tl] == 1)         ;       else {         int i = tl;         if (last) X[i] = f(X[i]), Y[i] = f(Y[i]);         out +=  0  + (last = (dsu.get(X[i]) == dsu.get(Y[i])));       }     } else {       int mid = (tl + tr) >> 1;       dfs(id << 1, tl, mid);       handle(mid);       dfs(id << 1 | 1, mid, tr);     }     dsu.undo(cnt);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> T[i] >> X[i] >> Y[i];       mp[ff(X[i], Y[i])].push_back(i);       mp[ff(f(X[i]), f(Y[i]))].push_back(i);     }     for (auto it : mp) {       it.second.push_back(m + 1);       for (int i = 0; i < it.second.size() - 1; i++)         Add(1, 1, m + 1, it.second[i], it.second[i + 1], it.first);     }     handle(1);     dfs(1, 1, m + 1);     cout << out <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dat[1500][1500], vst[1500][1500], lx[1500][1500], ly[1500][1500],       step[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   char str[1600];   int n, m, sx, sy;   bool dfs(int x, int y) {     int nx = ((x % n) + n) % n;     int ny = ((y % m) + m) % m;     if (!dat[nx][ny]) return false;     if (!vst[nx][ny]) {       vst[nx][ny] = 1;       lx[nx][ny] = x;       ly[nx][ny] = y;     } else if ((lx[nx][ny] != x) || (ly[nx][ny] != y))       return true;     else       return false;     for (int i = 0; i < 4; ++i)       if (dfs(x + step[i][0], y + step[i][1])) return true;     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , str);       for (int j = 0; j < m; ++j) {         dat[i][j] = (str[j] !=  # );         if (str[j] ==  S ) {           sx = i;           sy = j;         }       }     }     memset(lx, 0, sizeof(lx));     memset(ly, 0, sizeof(ly));     if (dfs(sx, sy))       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long int mod = 1e9 + 7;   long double dp[111][11111], ans;   long long int a[111], n, k, x;   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int i, j, k;     cin >> n >> x;     dp[0][0] = 1;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++)       for (j = i - 1; j >= 0; j--)         for (k = 0; k <= 10000; k++)           dp[j + 1][k + a[i]] += dp[j][k] * (j + 1) / (n - j);     for (i = 1; i <= n; i++)       for (j = 1; j <= 10000; j++)         ans += min((1.0 * n / i + 1) * x / 2, 1.0 * j / i) * dp[i][j];     cout << fixed << setprecision(15) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 3e1 + 17, N = 5e1 + 17, inf = 1e9 + 7, MOD = 1e9 + 7,                   Mod = 1e9 + 6;   long long n, m, y, t, d[maxN][maxN][N], help, mini, x;   int main() {     for (long long i = 0; i <= 30; i++) {       for (long long j = 0; j <= 30; j++) {         for (long long k = 0; k <= 50; k++) d[i][j][k] = inf;         if (i && j) d[i][j][0] = 0;       }     }     for (long long i = 1; i <= 30; i++) {       for (long long j = 1; j <= 30; j++) {         mini = min((i * j), (long long)50);         for (long long k = 1; k <= mini; k++) {           if (i < 2 || j < 2) d[i][j][k] = 1;           if (k == i * j) d[i][j][k] = 0;           for (long long z = 0; z <= i; z++) {             for (long long e = 0; e <= k; e++)               d[i][j][k] =                   min(d[i][j][k], d[i - z][j][e] + d[z][j][k - e] + (j * j));           }           for (long long z = 0; z <= j; z++) {             for (long long e = 0; e <= k; e++)               d[i][j][k] =                   min(d[i][j][k], d[i][j - z][e] + d[i][z][k - e] + (i * i));           }         }       }     }     cin >> t;     for (long long i = 1; i <= t; i++) {       cin >> n >> m >> y;       cout << d[n][m][y] <<   n ;     }     return cout <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename t>   void read(t &x) {     char ch = getchar();     x = 0;     t f = 1;     while (ch <  0  || ch >  9 ) f = (ch ==  -  ? -1 : f), ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   long long dp[1000][100];   int main() {     int n, m;     read(n), read(m);     m *= 2;     ;     for (int i = 1; i <= n; i++) dp[1][i] = 1;     for (int i = 2; i <= m; i++)       for (int j = n; j > 0; j--)         dp[i][j] = (dp[i][j + 1] + dp[i - 1][j]) % 1000000007;     long long ans = 0;     for (int i = 1; i <= n; i++) ans = (ans + dp[m][i]) % 1000000007;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int w[N];   vector<pair<int, int> > v[N], g[N];   int a[N];   int rnk(int x) {     while (a[x] != x) a[x] = a[a[x]], x = a[x];     return x;   }   struct eg {     int x, y, id;   } e[N];   bool cmp(eg a, eg b) { return w[a.id] < w[b.id]; }   bool vis[N], taken[N];   int ans = 0;   int dp[N][20], mx[N][20], l[N];   int lca(int x, int y) {     int res = 0;     if (l[x] > l[y]) swap(x, y);     for (int i = 19; i >= 0; i--)       if ((l[y] - l[x]) & (1 << i)) res = max(res, mx[y][i]), y = dp[y][i];     if (y == x) return res;     for (int i = 19; i >= 0; i--)       if (dp[x][i] != dp[y][i])         res = max(res, max(mx[x][i], mx[y][i])), x = dp[x][i], y = dp[y][i];     return max(res, max(mx[x][0], mx[y][0]));   }   void dfs(int x, int val = 0, int p = 0) {     if (vis[x]) return;     vis[x] = 1;     l[x] = l[p] + 1;     dp[x][0] = p;     mx[x][0] = val;     for (int i = 1; i < 20; i++)       dp[x][i] = dp[dp[x][i - 1]][i - 1],       mx[x][i] = max(mx[x][i - 1], mx[dp[x][i - 1]][i - 1]);     for (auto it : v[x]) {       int y = it.first, z = it.second;       if (!taken[z] && vis[y] && y != p) {         int lc = lca(x, y);         assert(lc <= w[z]);         if (lc == w[z]) ans++;       }     }     for (auto it : g[x]) {       if (!vis[it.first]) dfs(it.first, w[it.second], x);     }   }   int main() {     int n, m, x, y, z;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &x, &y, &z);       v[x].push_back({y, i});       v[y].push_back({x, i});       w[i] = z;       e[i] = {x, y, i};     }     sort(e + 1, e + m + 1, cmp);     for (int i = 1; i <= n; i++) a[i] = i;     for (int i = 1; i <= m; i++) {       if (rnk(e[i].x) != rnk(e[i].y)) {         a[rnk(e[i].x)] = rnk(e[i].y);         g[e[i].x].push_back({e[i].y, e[i].id});         g[e[i].y].push_back({e[i].x, e[i].id});         taken[e[i].id] = 1;       }     }     dfs(1, 0);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 6;   int n, t[MX];   int ID(int x, int jump) {     int st = 1, en = x, ret = 1e6;     while (st <= en) {       int mid = (st + en) / 2;       if (t[x] - jump <= t[mid]) {         ret = min(ret, mid);         en = mid - 1;       } else         st = mid + 1;     }     return ret;   }   int dp[MX];   int solve(int x) {     if (x < 1) return 0;     if (dp[x] != -1) return dp[x];     int ans = 1e8;     int id = ID(x, 1439);     if (id < x) ans = min(ans, 120 + solve(id - 1));     id = ID(x, 89);     if (id < x) ans = min(ans, 50 + solve(id - 1));     ans = min(ans, 20 + solve(x - 1));     return dp[x] = ans;   }   int main() {     cin >> n;     memset(dp, -1, sizeof dp);     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , t + i);       cout << solve(i) - ans << endl;       ans = solve(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, x1, y1, x2, y2, count = 0;     cin >> n >> m;     vector<char> v[n];     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         char x;         cin >> x;         v[i].push_back(x);         if (count == 0 && x ==  B ) {           x1 = i + 1, y1 = j + 1;           count++;         }         if (count > 0 && x ==  B ) {           x2 = i + 1, y2 = j + 1;         }       }     }     cout << (x1 + x2) / 2 <<     << (y1 + y2) / 2;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long n = s.size();     for (long long i = 0; i < n; i++) {       if (s[i] ==  r ) {         cout << i + 1 <<   n ;       }     }     for (long long i = n - 1; i >= 0; i--) {       if (s[i] ==  l ) {         cout << i + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   const long long int MOD = 998244353;   class Combination {     long long int ppow(long long int i, long long int j) {       long long int res = 1LL;       while (j) {         if ((j & 1LL)) {           res *= i;           if (res >= MOD) {             res %= MOD;           }         }         j >>= 1;         i *= i;         if (i >= MOD) {           i %= MOD;         }       }       return res;     }       public:     vector<long long int> k;     vector<long long int> r;     void resize(int N) {       k.resize(N + 2);       r.resize(N + 2);       k[0] = 1;       for (int i = 1; i < N + 2; i++) {         k[i] = k[i - 1];         k[i] *= i;         if (k[i] >= MOD) k[i] %= MOD;       }       long long int al = k[k.size() - 1];       long long int iv = ppow(k[k.size() - 1], MOD - 2);       r[k.size() - 1] = iv;       for (int i = (int)(r.size()) - 2; i >= 0; i--) {         r[i] = r[i + 1] * (i + 1);         if (r[i] >= MOD) {           r[i] %= MOD;         }       }     }     long long int C(int a, int b) {       if (a < b) return 0;       long long int up = k[a];       long long int dw = r[b] * r[a - b];       dw %= MOD;       up *= dw;       up %= MOD;       return up;     }     long long int H(int a, int b) { return C(a + b - 1, b); }     long long int catalan_number(int n) {       return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD;     }   } c;   int main() {     cin >> n;     c.resize(2000000);     long long int subt = 0;     for (int i = 1; i < n; i++) {       long long int way = c.C(n, i);       way *= c.k[n - i];       way %= MOD;       subt += way;       if (subt >= MOD) subt %= MOD;     }     long long int whole = c.k[n];     whole *= n;     whole %= MOD;     whole += MOD;     whole %= MOD;     whole += MOD - subt;     whole %= MOD;     printf( %lld n , whole);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char now[1 << 16], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline long long read() {     register long long x = 0, f = 1;     char ch = gc();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = gc();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = gc();     }     return (f == 1) ? x : -x;   }   struct node {     long long l, r, sz, rd, w;   } g[1200001];   inline void pushup(long long rt) {     g[rt].sz = g[g[rt].l].sz + g[g[rt].r].sz + 1;   }   long long tot;   inline long long news(long long w) {     g[++tot].sz = 1;     g[tot].w = w;     g[tot].rd = rand();     g[tot].l = g[tot].r = 0;     return tot;   }   void split(long long rt, long long &a, long long &b, long long w) {     if (!rt) return (void)(a = b = 0);     if (g[rt].w <= w) {       a = rt;       split(g[a].r, g[a].r, b, w);       pushup(a);     } else {       b = rt;       split(g[b].l, a, g[b].l, w);       pushup(b);     }   }   long long merge(long long a, long long b) {     if (a * b == 0) return a + b;     if (g[a].rd <= g[b].rd) {       g[a].r = merge(g[a].r, b);       pushup(a);       return a;     } else {       g[b].l = merge(a, g[b].l);       pushup(b);       return b;     }   }   long long root;   inline void insert(long long w) {     long long a = 0, b = 0, c = 0;     split(root, a, b, w);     root = merge(merge(a, news(w)), b);   }   inline long long rank_x(long long rt, long long ra) {     while (rt) {       if (g[g[rt].l].sz + 1 == ra)         return g[rt].w;       else if (g[g[rt].l].sz + 1 > ra)         rt = g[rt].l;       else         ra -= g[g[rt].l].sz + 1, rt = g[rt].r;     }     return -1;   }   struct QUE {     long long id, pos, opt, wht;   } q[2000001];   long long ans[1000001], n, m, Q, qcnt;   inline bool cmp(QUE a, QUE b) {     if (a.pos == b.pos) return a.opt < b.opt;     return a.pos < b.pos;   }   long long sum[1000001];   signed main() {     n = read(), m = read(), Q = read();     for (long long i = 1; i <= n; i++) {       sum[read()]++;     }     for (long long i = 1; i <= m; i++) {       q[++qcnt].opt = 2;       q[qcnt].pos = sum[i];       q[qcnt].id = i;     }     sort(q + 1, q + 1 + qcnt, cmp);     long long SUM = 0;     for (long long i = 1; i <= m; i++) {       SUM += sum[q[i].id];       q[i].pos = sum[q[i].id] * i - SUM;     }     sort(q + 1, q + 1 + qcnt, cmp);     for (long long i = 1; i <= Q; i++) {       long long sb = read() - n;       q[++qcnt].id = i;       q[qcnt].pos = sb;       q[qcnt].opt = 1;       q[qcnt].wht = sb;     }     sort(q + m + 1, q + qcnt + 1, cmp);     long long tmp = 0;     for (long long i = m + 1; i <= qcnt; i++) {       long long sb = q[i].wht;       while (tmp < m && q[tmp + 1].pos < sb) tmp++;       q[i].wht = ((sb - q[tmp].pos) % tmp ? (sb - q[tmp].pos) % tmp : tmp);     }     sort(q + 1, q + 1 + qcnt, cmp);     for (long long i = 1; i <= qcnt; i++) {       if (q[i].opt == 1) {         ans[q[i].id] = rank_x(root, q[i].wht);       } else {         insert(q[i].id);       }     }     for (long long i = 1; i <= Q; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int v[100000], c[100000], l[100000], r[100000];   vector<int> g[300001];   int d[200001] = {};   vector<int> p[200001], pp[200001], px[200001];   vector<int> t;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < (int)(n); ++i) cin >> v[i] >> c[i] >> l[i] >> r[i];     for (int i = 0; i < (int)(n); ++i) g[c[i] + l[i] + r[i]].push_back(i);     int ans = 0;     for (int i = 0; i < (int)(200001); ++i)       if (!g[i].empty()) {         for (int x : g[i])           if ((!l[x] || d[l[x]]) && d[l[x] + c[x]] < d[l[x]] + v[x]) {             d[l[x] + c[x]] = d[l[x]] + v[x];             p[l[x] + c[x]].push_back(l[x]);             pp[l[x] + c[x]].push_back((int)p[l[x]].size() - 1);             px[l[x] + c[x]].push_back(x);           }         int ind = i;         if (d[ind] > ans) {           int pind = (int)p[ind].size() - 1;           ans = d[ind];           t.clear();           while (ind) {             t.push_back(px[ind][pind]);             int nind = p[ind][pind];             pind = pp[ind][pind];             ind = nind;           }         }         for (int x : g[i]) {           int pos = l[x] + c[x];           d[pos] = 0;           p[pos].clear();           pp[pos].clear();           px[pos].clear();         }       }     cout << (int)t.size() <<   n ;     for (int i = (int)t.size() - 1; i >= 0; --i) cout << t[i] + 1 <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double n, t, x = 1.000000011;     scanf( %lf%lf , &n, &t);     double res = n * pow(x, t);     printf( %.12lf , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<long long> mod;   int main() {     long long n, k;     scanf( %I64d%I64d , &n, &k);     bool result = true;     for (long long i = 1LL; i <= k; i++) {       long long x = n % i;       if (mod.find(x) != mod.end()) {         result = false;         break;       }       mod.insert(x);     }     printf( %s n , result ?  Yes  :  No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 100;   char ch[maxn];   namespace Suffix_Array {   int cntA[maxn], cntB[maxn], tsa[maxn], A[maxn], B[maxn];   int sa[maxn], rkrk[maxn], height[maxn];   void GetSa(char *ch, int n) {     for (int i = 0; i < maxn; i++) cntA[i] = 0;     for (int i = 1; i <= n; i++) cntA[ch[i]]++;     for (int i = 1; i <= maxn; i++) cntA[i] += cntA[i - 1];     for (int i = n; i; i--) sa[cntA[ch[i]]--] = i;     rkrk[sa[1]] = 1;     for (int i = 2; i <= n; i++) {       rkrk[sa[i]] = rkrk[sa[i - 1]];       if (ch[sa[i]] != ch[sa[i - 1]]) rkrk[sa[i]]++;     }     for (int l = 1; rkrk[sa[n]] < n; l <<= 1) {       for (int i = 0; i < maxn; i++) cntA[i] = 0;       for (int i = 0; i < maxn; i++) cntB[i] = 0;       for (int i = 1; i <= n; i++) {         cntA[A[i] = rkrk[i]]++;         cntB[B[i] = (i + l <= n) ? rkrk[i + l] : 0]++;       }       for (int i = 1; i < maxn; i++) cntB[i] += cntB[i - 1];       for (int i = n; i; i--) tsa[cntB[B[i]]--] = i;       for (int i = 1; i < maxn; i++) cntA[i] += cntA[i - 1];       for (int i = n; i; i--) sa[cntA[A[tsa[i]]]--] = tsa[i];       rkrk[sa[1]] = 1;       for (int i = 2; i <= n; i++) {         rkrk[sa[i]] = rkrk[sa[i - 1]];         if (A[sa[i]] != A[sa[i - 1]] || B[sa[i]] != B[sa[i - 1]]) rkrk[sa[i]]++;       }     }   }   };  // namespace Suffix_Array   int sum[maxn];   struct Segment_Tree {     int Min[maxn * 8];     void up(int x) { Min[x] = min(Min[x << 1], Min[x << 1 | 1]); }     void build(int x, int l, int r) {       if (l == r) {         Min[x] = sum[l];         return;       }       int mid = l + r >> 1;       build(x << 1, l, mid);       build(x << 1 | 1, mid + 1, r);       up(x);     }     int query(int x, int l, int r, int L, int R) {       if (l > R || L > r) return 0x3f3f3f3f;       if (L <= l && r <= R) return Min[x];       int mid = l + r >> 1;       return min(query(x << 1, l, mid, L, R),                  query(x << 1 | 1, mid + 1, r, L, R));     }   } seg;   int SUM;   int n, N;   bool check(int x) {     int Min = seg.query(1, 1, N, x, x + n - 1);     int begin = sum[x - 1];     if (SUM < 0) {       begin += SUM;     }     if (Min >= begin)       return 1;     else       return 0;   }   int main() {     scanf( %s , ch + 1);     n = strlen(ch + 1);     for (int i = n + 1; i <= 2 * n; i++) {       if (ch[i - n] ==  ( )         ch[i - n] =  0 ;       else         ch[i - n] =  1 ;       ch[i] = ch[i - n];     }     N = n << 1;     Suffix_Array::GetSa(ch, N);     for (int i = 1; i <= N; i++) {       sum[i] = sum[i - 1];       if (ch[i] ==  0 )         sum[i]++;       else         sum[i]--;     }     SUM = sum[n];     seg.build(1, 1, N);     for (int i = 1; i <= N; i++) {       int x = Suffix_Array::sa[i];       if (x > n) continue;       if (check(x)) {         if (SUM < 0) {           for (int j = 0; j > SUM; j--) {             printf( ( );           }         }         for (int j = x; j < x + n; j++) {           if (ch[j] ==  0 )             printf( ( );           else             printf( ) );         }         if (SUM > 0) {           for (int j = 0; j < SUM; j++) {             printf( ) );           }         }         puts(  );         return 0;       }     }     assert(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long lim;   long long n, mod;   int m;   inline long long F(long long a, long long d, long long want, long long n) {     if (want == 0 or lim < a) {       return 0;     }     if (n == want) {       n = min(n, (lim - a) / d + 1);       long long z = 2 * a + (n - 1) * d;       ((z & 1) ? n : z) >>= 1;       return (n % mod) * (z % mod) % mod;     }     long long mid = (n + 1) >> 1;     if (want <= mid) {       return F(a, d << 1, want, mid);     }     return (F(a, d << 1, mid, mid) + F(a + d, d << 1, want - mid, n - mid)) % mod;   }   inline long long cal(long long r, long long v) {     lim = min(v, n);     return F(1, 1, r, n);   }   int main() {     scanf( %I64d %d %I64d , &n, &m, &mod);     for (; m-- > 0;) {       long long l, r, u, v;       scanf( %I64d %I64d %I64d %I64d , &l, &r, &u, &v);       l--, u--;       printf( %I64d n ,              (((cal(r, v) - cal(l, v)) - (cal(r, u) - cal(l, u))) % mod + mod) %                  mod);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300000 + 100;   int p[maxn << 2];   void pushdown(int L, int R, int u) {     if (L != R) {       if (p[u] != -1) {         p[u << 1] = p[u];         p[u << 1 | 1] = p[u];         p[u] = -1;       }     }   }   void update(int cL, int cR, int val, int L, int R, int u) {     pushdown(L, R, u);     if (cL <= L && R <= cR) {       p[u] = val;     } else {       int m = (L + R) / 2;       if (cR <= m)         update(cL, cR, val, L, m, u << 1);       else if (cL > m)         update(cL, cR, val, m + 1, R, u << 1 | 1);       else {         update(cL, cR, val, L, m, u << 1);         update(cL, cR, val, m + 1, R, u << 1 | 1);         update(cL, cR, val, m + 1, R, u << 1 | 1);       }     }   }   int query(int x, int L, int R, int u) {     pushdown(L, R, u);     if (L == R)       return p[u];     else {       int m = (L + R) / 2;       if (x <= m)         return query(x, L, m, u << 1);       else         return query(x, m + 1, R, u << 1 | 1);     }   }   vector<int> G[maxn];   int res[maxn];   int sum[maxn];   int n;   void dfs(int u) {     sum[u]++;     int Max = 0;     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i];       dfs(v);       sum[u] += sum[v];       Max = max(Max, sum[v]);     }     update(Max, sum[u], u, 0, n, 1);     res[u] = query(sum[u] / 2, 0, n, 1);   }   int main() {     int q;     scanf( %d %d , &n, &q);     for (int i = 2; i <= n; ++i) {       int t;       scanf( %d , &t);       G[t].push_back(i);     }     memset(p, -1, sizeof(p));     memset(sum, 0, sizeof(sum));     dfs(1);     while (q--) {       int t;       scanf( %d , &t);       printf( %d n , res[t]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;      int main()   {       ios_base::sync_with_stdio(0); cin.tie(0);       long long cases, no_points, xcoord, ycoord;       cin >> cases;       for (int i = 0; i < cases; i++)       {           vector <long long> xpoints;           vector <long long> ypoints;                      long long choicesx,choicesy = 1;                     cin >> no_points;           for (int x = 0; x < no_points; x++)           {               cin >> xcoord >> ycoord;               xpoints.push_back(xcoord);               ypoints.push_back(ycoord);           }           if(no_points % 2 == 1){               cout << 1 <<   n ;           }              else{               sort(xpoints.begin(), xpoints.end());               sort(ypoints.begin(), ypoints.end());               choicesx = xpoints[(no_points/2)] - xpoints[(no_points/2) - 1] + 1;               choicesy = ypoints[(no_points/2)] - ypoints[(no_points/2) - 1] + 1;               cout << choicesx * choicesy <<   n ;           }                                        }              return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[4];   int check(int a, int b, int c, int d) {     int avg = a + b + c + d;     int med = b + c;     if (avg % 4 != 0 || med % 2 != 0) return 0;     if (avg / 4 == d - a && med / 2 == d - a) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i <= n - 1; i++) cin >> a[i];     sort(a, a + n);     if (n == 0) {       cout <<  YES  << endl;       cout << 1 << endl << 1 << endl << 3 << endl << 3;       return 0;     }     if (n == 1) {       cout <<  YES  << endl;       cout << 3 * a[0] << endl;       cout << 2 * a[0] << endl;       cout << 2 * a[0];       return 0;     }     if (n <= 2) {       if (a[1] <= 3 * a[0]) {         cout <<  YES  << endl;         cout << 4 * a[0] - a[1] << endl;         cout << 3 * a[0];         return 0;       }       cout <<  NO ;       return 0;     }     if (n == 3) {       for (int i = 1; i <= 1000000; i++) {         int b[4] = {a[0], a[1], a[2], i};         sort(b, b + 4);         if (check(b[0], b[1], b[2], b[3]) == 1) {           cout <<  YES  << endl;           cout << i;           return 0;         }       }       cout <<  NO ;       return 0;     }     if (check(a[0], a[1], a[2], a[3]) == 0)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   inline long long Input() {     long long ret = 0;     bool isN = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) isN = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ret = ret * 10 + c -  0 ;       c = getchar();     }     return isN ? -ret : ret;   }   inline void Output(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     int len = 0, data[20];     while (x) {       data[len++] = x % 10;       x /= 10;     }     if (!len) data[len++] = 0;     while (len--) putchar(data[len] + 48);     putchar(  n );   }   #pragma comment(linker,  /STACK:124000000,124000000 )   const long double PI = acos(-1.0);   using namespace std;   int num[100005];   int shit[100005];   int a[100005], n;   long long work1(int id) {     memset(shit, 0, sizeof(shit));     if (num[a[(n + 1) / 2]] & 1) {       int i;       for (i = n / 2; i; i--) {         if (a[i] != a[n + 1 - i]) break;       }       for (int j = id; j <= i; j++) {         shit[a[j]]++;         shit[a[n - j + 1]]--;       }       int j, cnt = 0;       bool flag = 1;       for (j = 0; j <= n; j++) {         if (shit[j] != 0) {           flag = 0;           if (shit[j] < 0) cnt++;         }       }       if (cnt == 0) return 1LL * id * (n - id + 1 - i);       for (j = i + 1; j < n - i + 1; j++) {         shit[a[j]] += 1;         if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;         if (cnt == 0) {           return 1LL * id * (n - id + 1 - j);         }       }       for (j = n - i + 1; j <= n; j++) {         shit[a[j]] += 2;         if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;         if (cnt == 0) {           return 1LL * id * (n - id + 1 - j);         }       }     } else {       for (int j = id; j <= (n + 1) / 2; j++) {         shit[a[j]]++;         shit[a[n - j + 1]]--;       }       shit[a[(n + 1) / 2]]++;       int j, cnt = 0;       bool flag = 1;       for (j = 0; j <= n; j++) {         if (shit[j] != 0) {           if (shit[j] < 0) cnt++;         }       }       if (cnt == 0) return 1LL * id * (n - id + 1 - (n + 1) / 2);       for (j = n + 2 - (n + 1) / 2; j <= n; j++) {         shit[a[j]] += 2;         if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;         if (cnt == 0) {           return 1LL * id * (n - id + 1 - j);         }       }     }   }   long long work2(int id) {     memset(shit, 0, sizeof(shit));     int i;     for (i = n / 2; i; i--) {       if (a[i] != a[n + 1 - i]) break;     }     for (int j = id; j <= i; j++) {       shit[a[j]]++;       shit[a[n - j + 1]]--;     }     int j, cnt = 0;     bool flag = 1;     for (j = 0; j <= n; j++) {       if (shit[j] != 0) {         flag = 0;         if (shit[j] < 0) cnt++;       }     }     if (cnt == 0) return 1LL * id * (n - id + 1 - i);     for (j = i + 1; j < n - i + 1; j++) {       shit[a[j]] += 1;       if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;       if (cnt == 0) {         return 1LL * id * (n - id + 1 - j);       }     }     for (j = n - i + 1; j <= n; j++) {       shit[a[j]] += 2;       if (shit[a[j]] >= 0 && shit[a[j]] - 2 < 0) cnt--;       if (cnt == 0) {         return 1LL * id * (n - id + 1 - j);       }     }   }   long long solve() {     long long ans = 0;     int i, id;     for (i = 1; i <= n; i++) {       if (a[i] != a[n + 1 - i]) {         ans = ans + 1LL * i * i;         id = i;         break;       }     }     if (i == n + 1) return 1LL * n * (n + 1) / 2;     if (n & 1) {       ans = ans + work1(id);       for (int i = 1; i <= n / 2; i++) swap(a[i], a[n + 1 - i]);       ans = ans + work1(id);     } else {       ans = ans + work2(id);       for (int i = 1; i <= n / 2; i++) swap(a[i], a[n + 1 - i]);       ans = ans + work2(id);     }     return ans;   }   int main() {     while (scanf( %d , &n) != EOF) {       memset(num, 0, sizeof(num));       for (int i = 1; i <= n; i++) {         scanf( %d , a + i);         num[a[i]]++;       }       int cnt = 0;       for (int i = 1; i <= n; i++) {         if (num[i] & 1) cnt++;       }       if (cnt >= 2) {         printf( 0 n );         continue;       }       printf( %I64d n , solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3fffffff;   const int maxn = 110;   char a[20];   int k;   int main() {     scanf( %s , a);     cin >> k;     int len = strlen(a);     for (int i = 0; i < len; ++i) {       int p = i;       for (int j = 1; j <= k && j + i < len; ++j)         if (a[i + j] > a[p]) p = i + j;       if (a[p] == a[i]) continue;       for (int j = p; j > i; --j) swap(a[j], a[j - 1]);       k -= p - i;       if (k <= 0) break;     }     printf( %s n , a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, tt[40], qq[10];   long long int m[10][41];   vector<int> ss[10];   int check(int c, long long int s) {     if (c == k) return (s == 0) || ((s + (s & (-s))) == (1LL << n));     int i, z = ss[c].size() - qq[c] - __builtin_popcountll(s & m[c][0]);     s &= ~m[c][0], s |= m[c][z];     for (i = 0; i <= qq[c]; i++) {       if (!check(c + 1, s)) return 0;       if (i < qq[c]) s ^= (1LL << ss[c][z + i]);     }     return 1;   }   int main() {     int i, j;     int q;     cin >> n >> k;     for (i = 0; i < n; i++) tt[i] = -1;     for (i = 0; i < k; i++) {       cin >> q;       ss[i].resize(q);       for (j = 0; j < q; j++) {         cin >> ss[i][j], ss[i][j]--;         if (tt[ss[i][j]] == -1) tt[ss[i][j]] = i;       }     }     if (n == 1) {       cout <<  ACCEPTED  << endl;       return 0;     }     for (i = 0; i < n; i++) {       if (tt[i] == -1) {         cout <<  REJECTED  << endl;         return 0;       } else         qq[tt[i]]++;     }     for (i = 0; i < k; i++) {       long long int a = 0;       for (j = 0; j < ss[i].size(); j++) a |= (1LL << ss[i][j]);       for (j = 0; j <= ss[i].size(); j++) {         m[i][j] = a;         if (j < ss[i].size()) a ^= (1LL << ss[i][j]);       }     }     if (check(0, 0))       cout <<  ACCEPTED  << endl;     else       cout <<  REJECTED  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, num[100001], mxn, contador;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> num[i];     }     if (n == 1) {       cout << 1;       return 0;     }     for (int i = 2; i < n; i++) {       if (num[i] == num[i - 1] + num[i - 2])         contador++;       else {         mxn = max(mxn, contador);         contador = 0;       }     }     if (contador < mxn)       cout << mxn + 2;     else       cout << contador + 2;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e2 + 5;   string grid[N];   bool found, vis[N][N];   ;   int n, m, k, cnt, ans;   vector<pair<int, pair<int, int> > > p;   int dr[] = {-1, 1, 0, 0};   int dc[] = {0, 0, -1, 1};   bool check(int r, int c) {     return r == 0 || r == n - 1 || c == 0 || c == m - 1;   }   bool valid(int r, int c) { return r >= 0 && r < n && c >= 0 && c < m; }   void dfs(int r, int c) {     vis[r][c] = 1;     if (check(r, c)) found = 1;     cnt++;     for (int i = 0; i < 4; i++) {       int rr = r + dr[i], cc = c + dc[i];       if (valid(rr, cc) && !vis[rr][cc] && grid[rr][cc] ==  . ) dfs(rr, cc);     }   }   void build(int r, int c) {     grid[r][c] =  * ;     for (int i = 0; i < 4; i++) {       int rr = r + dr[i], cc = c + dc[i];       if (valid(rr, cc)) {         if (grid[rr][cc] ==  . ) {           build(rr, cc);         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> grid[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!vis[i][j] && grid[i][j] ==  . ) {           found = 0;           cnt = 0;           dfs(i, j);           if (found) continue;           p.push_back({cnt, {i, j}});         }       }     }     sort(p.begin(), p.end());     for (int i = 0; i < (int)p.size() - k; i++) {       ans += p[i].first;       build(p[i].second.first, p[i].second.second);     }     cout << ans <<   n ;     for (int i = 0; i < n; i++) {       cout << grid[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string elimina(string s) {     for (int i = 0; i < int(s.size()); i++) {       if (s[i] ==  )  or s[i] ==  (  or s[i] ==  ,  or s[i] ==  . ) s[i] =    ;     }     return s;   }   int main() {     string ss;     int n;     cin >> n;     getline(cin, ss);     map<string, vector<string> > g;     map<string, vector<string> > pare;     map<string, string> tipus;     map<string, long long int> border;     map<string, long long int> spacing;     map<string, long long int> width;     map<string, long long int> height;     map<string, long long int> aritat;     for (int pas = 0; pas < n; pas++) {       getline(cin, ss);       ss = elimina(ss);       istringstream ci(ss);       string name;       ci >> name;       if (name ==  VBox ) {         ci >> name;         tipus[name] =  VBox ;       } else if (name ==  HBox ) {         ci >> name;         tipus[name] =  HBox ;       } else if (name ==  Widget ) {         ci >> name;         tipus[name] =  Widget ;         long long int w, h;         ci >> w >> h;         width[name] = w;         height[name] = h;       } else {         string inst;         ci >> inst;         if (inst ==  pack ) {           string name2;           ci >> name2;           g[name].push_back(name2);           aritat[name]++;           pare[name2].push_back(name);         } else if (inst ==  set_border ) {           long long int b;           ci >> b;           border[name] = b;         } else if (inst ==  set_spacing ) {           long long int spa;           ci >> spa;           spacing[name] = spa;         }       }     }     stack<string> s;     for (map<string, string>::iterator it = tipus.begin(); it != tipus.end();          it++) {       string name = it->first;       if (aritat[name] == 0) s.push(name);     }     while (not s.empty()) {       string name = s.top();       s.pop();       if (tipus[name] ==  HBox ) {         long long int ample = 0;         long long int alt = 0;         vector<string> &fill = g[name];         for (int i = 0; i < int(fill.size()); i++) {           string f = fill[i];           alt = max(alt, height[f]);           ample += width[f];         }         if (int(fill.size()) == 0) {           ample = 0;           alt = 0;         } else if (int(fill.size()) == 1) {           alt += 2 * border[name];           ample += 2 * border[name];         } else {           alt += 2 * border[name];           ample += 2 * border[name] + (int(fill.size()) - 1) * spacing[name];         }         height[name] = alt;         width[name] = ample;       } else if (tipus[name] ==  VBox ) {         long long int ample = 0;         long long int alt = 0;         vector<string> &fill = g[name];         for (int i = 0; i < int(fill.size()); i++) {           string f = fill[i];           alt += height[f];           ample = max(ample, width[f]);         }         if (int(fill.size()) == 0) {           ample = 0;           alt = 0;         } else if (int(fill.size()) == 1) {           alt += 2 * border[name];           ample += 2 * border[name];         } else {           alt += 2 * border[name] + (int(fill.size()) - 1) * spacing[name];           ample += 2 * border[name];         }         height[name] = alt;         width[name] = ample;       }       vector<string> &p = pare[name];       for (int i = 0; i < int(p.size()); i++) {         string nam = p[i];         aritat[nam]--;         if (aritat[nam] == 0) {           s.push(nam);         }       }     }     for (map<string, string>::iterator it = tipus.begin(); it != tipus.end();          it++) {       string name = it->first;       cout << name <<     << width[name] <<     << height[name] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, t;     cin >> t;     while (t--) {       cin >> a >> b;       c = ceil(abs(a - b) / 10.0);       cout << c << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int64_t P0 = 2000003;   constexpr int64_t P1 = 2000017;   constexpr int64_t M0 = 3000000000013;   constexpr int64_t M1 = 2000000000003;   class TaskC {    public:     struct Class {       int id;       int cnt;     };     struct Hash {       int64_t a, b;       Hash() : a(0), b(0) {}       void update(int addition) {         a = (a * P0 + addition) % M0;         b = (b * P1 + addition) % M1;       }       bool operator<(const Hash& other) const {         return std::tie(a, b) < std::tie(other.a, other.b);       }     };     void solve(std::istream& in, std::ostream& out) {       int n, m;       in >> n >> m;       vector<vector<int>> schools(n);       vector<Class> classes;       int timer = 0;       vector<Hash> hashes(m);       for (int i = 0; i < n; i++) {         int k;         in >> k;         auto& school = schools[i];         for (int j = 0; j < k; j++) {           int id;           in >> id;           --id;           school.push_back(id);         }         sort(school.begin(), school.end());         classes.clear();         int l = 0;         while (l < k) {           int id = school[l], cnt = 0;           while (l < k && school[l] == id) {             ++l;             ++cnt;           }           classes.push_back(Class{id, cnt});         }         sort(classes.begin(), classes.end(),              [](Class lhs, Class rhs) { return lhs.cnt < rhs.cnt; });         l = 0;         while (l < classes.size()) {           ++timer;           int cnt = classes[l].cnt;           while (l < classes.size() && classes[l].cnt == cnt) {             int id = classes[l].id;             ++l;             hashes[id].update(timer);           }         }       }       map<Hash, int> was;       int64_t result = 1;       int64_t MOD = (1000000000 + 7);       for (auto hash : hashes) {         ++was[hash];         result = (result * was[hash]) % MOD;       }       out << result <<   n ;     }   };   int main() {     std::ios_base::sync_with_stdio(false);     TaskC solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     in.tie(0);     out << std::fixed;     out.precision(20);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   struct Node {     string str;     int pos;     friend bool operator<(Node const& n1, Node const& n2) {       return n2.str < n1.str;     }   };   priority_queue<Node> que;   int main() {     int k;     string str;     cin >> str;     cin >> k;     que.push({string{ z  + 1}, INF});     for (int i = 0; i < str.size(); ++i) {       que.push({string{str[i]}, i});     }     Node i;     while (k-- && !que.empty()) {       i = que.top();       que.pop();       if (i.pos == str.size() - 1 || i.pos == INF) continue;       que.push({i.str + str[i.pos + 1], i.pos + 1});     }     if (k && que.empty())       cout <<  No such line.  << endl;     else       cout << i.str << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[1000010], b[1000010];     while (scanf( %s%s , &a, &b) != EOF) {       int len1 = strlen(a);       int len2 = strlen(b);       int ans = 0;       if (len1 != len2) {         ans = 1;       } else {         if (len1 == 1) {           if (a[0] != b[0])             ans = 1;           else             ans = 0;         } else {           if (strcmp(a, b) == 0)             ans = 0;           else {             int j1 = 0, j2 = 0;             for (int i = 0; i < len1; i++)               if (a[i] ==  1 ) j1 = 1;             for (int i = 0; i < len1; i++)               if (b[i] ==  1 ) j2 = 1;             if (j1 && j2)               ans = 0;             else               ans = 1;           }         }       }       if (!ans)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr <<     << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void inp_out() {}   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     inp_out();     long long int n, m;     cin >> n >> m;     vector<pair<long long int, long long int>> a(n);     long long int cnt = 0;     multiset<pair<long long int, long long int>> st;     vector<multiset<long long int>> adj(m + 1);     for (long long int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;       adj[a[i].first].insert(a[i].second);       if (a[i].first == 1)         ++cnt;       else         st.insert({a[i].second, a[i].first});     }     vector<long long int> ans(n + 1, 3e18);     for (long long int i = max(1ll, cnt); i <= n; ++i) {       vector<multiset<long long int>> temp_adj = adj;       multiset<pair<long long int, long long int>> temp_st = st;       long long int val = cnt, cost = 0;       for (long long int j = 2; j <= m; ++j) {         while (temp_adj[j].size() >= i) {           cost += *temp_adj[j].begin();           temp_st.erase(temp_st.find({*temp_adj[j].begin(), j}));           temp_adj[j].erase(temp_adj[j].begin());           ++val;         }       }       if (val > i) continue;       while (val < i) {         cost += (*temp_st.begin()).first;         temp_st.erase(temp_st.begin());         ++val;       }       ans[i] = cost;     }     long long int fa = *min_element(ans.begin(), ans.end());     cout << fa;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   void fastIO() {     std::ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     fastIO();     int n, a;     cin >> n;     int tot = 0;     int mx = 0;     for (int i = 0; i < n; i++) {       cin >> a;       tot += a;       mx = max(mx, a);     }     double cond = (2.0 * tot) / n;     if (cond < mx) {       cout << mx << endl;     } else {       cout << ceil(cond + .00001) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int arr[n];     bool fl = false;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (arr[i] == 1) {         fl = true;       }     }     if (fl == false)       printf( EASY );     else       printf( HARD );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[105];   int main() {     int n;     int k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> arr[i];     int count = 105;     int ans;     for (int i = 0; i < n; i++) {       if (k % arr[i] == 0) {         ans = k / arr[i];       }       count = min(count, ans);     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char tr[100005];   map<char, int> p;   char num[12] = { AHIMOTUVWXY };   char num1[27] = { ABCDEFGHIJKLMNOPQRSTUVWXYZ };   void init() {     int i;     for (i = 0; i < 26; i++) {       p[num1[i]] = 0;     }     for (i = 0; i < 11; i++) {       p[num[i]] = 1;     }   }   int main() {     init();     int n, i, j;     while (scanf( %s , tr) != EOF) {       n = strlen(tr);       for (i = 0, j = n - 1; i < n / 2; i++, j--) {         if (tr[i] != tr[j]) break;       }       if (i < n / 2) {         printf( NO n );         continue;       }       for (i = 0; i < n; i++) {         if (!p[tr[i]]) break;       }       if (i < n)         printf( NO n );       else         printf( YES n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int time = 10;     int solvedCount = 0;     int penalty = 0;     for (int i = 0; i < n; i++) {       time = time + a[i];       if (time <= 720) {         solvedCount++;         if (time > 360) penalty = penalty + (time - 360);       }     }     cout << solvedCount <<     << penalty << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       cout << n << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;      void solve() {       int n; cin >> n;       map<int,int> m;       for(int i=0,x; i < n; ++i) {           cin >> x;           m[x]++;       }       map<int,int> m2;       for(auto p : m) {           m2[p.second]++;       }       int cnt,mn=n;       for(auto p1 : m2) {           cnt = 0;           for(auto p2 : m2) {               if(p1.first > p2.first) {                   cnt += p2.first * p2.second;               } else {                   cnt += (p2.first -p1.first) * p2.second;               }           }           mn = min(mn, cnt);       }       cout << mn << endl;   }   // 1,3,2,1,4,2   // 1 1 2 2   // 1:2   // 2:2      // 1 2 3 3 3 3 2 6 6   // 1 2 2 4   // 1:1   // 2:2   // 4:1   int main() {       int t; cin >> t; while(t--)       solve();   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167772160 )   using namespace std;   const int inf = 1000000000;   long long k[1001], p[1001], f[1001], c[1001];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> k[i] >> c[i];     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (c[i] > c[j]) {           swap(c[i], c[j]);           swap(k[i], k[j]);         }     int t;     cin >> t;     for (int i = 1; i <= t; i++) cin >> p[i];     p[0] = 0;     for (int i = 1; i <= t; i++) f[i] = p[i] - p[i - 1];     f[t + 1] = 1000000000000LL;     int j = 1;     long long num = 0;     long long ans = 0;     for (int i = 1; i <= t + 1; i++) {       while (j <= n) {         long long mn = min(k[j] - num, f[i]);         ans += (long long)c[j] * mn * (long long)i;         if (mn == k[j] - num && mn == f[i]) {           ++j;           num = 0;           break;         } else if (mn == k[j] - num) {           ++j;           f[i] -= mn;           num = 0;         } else {           num += mn;           break;         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long b[150005], up[150005], a[150005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     bool fl = false;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> b[i];       up[i] = max(1ll, b[i]);       if (b[i] != 0) fl = true;     }     if (!fl) {       cout <<  YES n ;       for (int i = 1; i <= n; i++) cout << 1 <<    ;       exit(0);     }     for (int i = 1; i <= n; i++) {       if (i == 1)         up[i] = max(up[i], b[n] + 1);       else         up[i] = max(up[i], b[i - 1] + 1);     }     for (int i = 1; i <= n; i++) {       if (b[i] < up[i]) continue;       cout <<  YES n ;       a[i] = b[i];       int uk;       if (i == 1)         uk = n;       else         uk = i - 1;       while (uk != i) {         long long t = up[uk] / a[uk % n + 1];         if (t * a[uk % n + 1] + b[uk] >= up[uk])           a[uk] = t * a[uk % n + 1] + b[uk];         else           a[uk] = (t + 1) * a[uk % n + 1] + b[uk];         if (uk == 1)           uk = n;         else           uk--;       }       for (int j = 1; j <= n; j++) cout << a[j] <<    ;       exit(0);     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   template <typename T>   inline void cmax(T &x, T y) {     if (x < y) x = y;   }   char s[N];   int len, n, m[N], mx, A[N], B[N][N], cost[10];   int cnt[10], rnk[N], rk2[N], dp[N][N];   void init() {     scanf( %s , s + 1);     len = strlen(s + 1);     mx = len;     for (int i = 1; i <= len; ++i) {       A[i] = s[len - i + 1] -  0 ;     }     read(n);     for (int i = 1; i <= n; ++i) {       scanf( %s , s + 1);       m[i] = strlen(s + 1);       cmax(mx, m[i]);       for (int j = 1; j <= m[i]; ++j) {         B[i][j] = s[m[i] - j + 1] -  0 ;       }     }     ++mx;     for (int i = 0; i <= 9; ++i) {       read(cost[i]);     }   }   void solve() {     for (int i = 1; i <= n; ++i) {       rnk[i] = i;     }     memset(dp, 0x80, sizeof(dp));     dp[0][0] = 0;     for (int d = 1, l, r; d <= mx; ++d) {       if (A[d] <= 9) {         l = r = A[d];       } else {         l = (d == len ? 1 : 0);         r = 9;       }       for (int k = l; k <= r; ++k) {         int sum = 0, jin = 0;         for (int i = 1; i <= n; ++i) {           int cur = k + B[i][d];           if (!cur) {             if (d <= m[i] || d <= len) {               sum += cost[0];             }           } else if (cur > 9) {             sum += cost[cur - 10];             ++jin;           } else {             sum += cost[cur];           }         }         for (int i = 0; i <= n; ++i) {           if (i) {             int cur = k + B[rnk[n - i + 1]][d];             if (cur == 9) {               sum += cost[0] - cost[9];               ++jin;             } else {               if (cur == 0 && d > m[rnk[n - i + 1]] && d > len) {                 sum += cost[1];               } else {                 sum += cost[cur % 10 + 1] - cost[cur % 10];               }             }           }           cmax(dp[d][jin], dp[d - 1][i] + sum);         }       }       for (int i = 0; i <= 9; ++i) {         cnt[i] = 0;       }       for (int i = 1; i <= n; ++i) {         ++cnt[B[i][d]];       }       for (int i = 1; i <= 9; ++i) {         cnt[i] += cnt[i - 1];       }       for (int i = n; i >= 1; --i) {         rk2[cnt[B[rnk[i]][d]]--] = rnk[i];       }       memcpy(rnk, rk2, sizeof(rnk));     }     printf( %d n , dp[mx][0]);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   const long long maxn = 1e4 + 10;   inline long long Max(long long a, long long b) { return a > b ? a : b; }   inline long long Min(long long a, long long b) { return a > b ? b : a; }   namespace FastIO {   inline long long read() {     long long f = 1, r = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) {         f = -1;       }       c = getchar();     }     while (isdigit(c)) {       r = 10 * r + c -  0 ;       c = getchar();     }     return f * r;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writesp(long long x) { write(x), putchar(   ); }   inline void writeln(long long x) { write(x), puts(  ); }   };  // namespace FastIO   using namespace FastIO;   long long N;   inline bool ask(long long x1, long long y1, long long x2, long long y2) {     putchar( ? ), putchar(   );     writesp(x1), writesp(y1), writesp(x2), writeln(y2);     fflush(stdout);     std::string s;     std::cin >> s;     return s ==  YES ;   }   signed main() {     std::cin >> N;     long long nowx = 1, nowy = 1;     std::string s1 =   ;     while (true) {       if (nowx + nowy == N + 1) {         break;       }       if (nowx == N) {         nowy++, s1.push_back( R );       } else if (nowy == N) {         nowx++, s1.push_back( D );       } else {         if (ask(nowx + 1, nowy, N, N)) {           nowx++, s1.push_back( D );         } else {           nowy++, s1.push_back( R );         }       }     }     nowx = N, nowy = N;     std::string s2 =   ;     while (true) {       if (nowx + nowy == N + 1) {         break;       }       if (nowx == 1) {         nowy--, s2.push_back( R );       } else if (nowy == 1) {         nowx--, s2.push_back( D );       } else {         if (ask(1, 1, nowx, nowy - 1)) {           nowy--, s2.push_back( R );         } else {           nowx--, s2.push_back( D );         }       }     }     std::reverse(s2.begin(), s2.end());     putchar( ! ), putchar(   );     std::string res = s1 + s2;     std::cout << res << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long u, long long v) {     while (v != 0) {       long long r = u % v;       u = v;       v = r;     }     return u;   }   typedef struct State {     char cnt[21];     char top[3];   } State;   inline bool operator<(const State &a, const State &b) {     return memcmp(&a, &b, sizeof(State)) < 0;   }   int nways[3];   int need[3][16], gain[3][16];   char color[3] = { B ,  G ,  R };   char name[21][4] = { B ,    G ,    R ,    BBB ,  BBG ,  BBR ,  BGB ,                        BGG ,  BGR ,  BRB ,  BRG ,  BRR ,  GBG ,  GBR ,                        GGG ,  GGR ,  GRG ,  GRR ,  RBR ,  RGR ,  RRR };   void init() {     memset(nways, 0, sizeof(nways));     for (int i = (0); i < (3); ++i) {       int x = name[i][0] ==  B  ? 0 : name[i][0] ==  G  ? 1 : 2;       need[x][nways[x]] = i;       gain[x][nways[x]] = -1;       ++nways[x];     }     for (int i = (3); i < (21); ++i)       for (int j = (0); j < (3); ++j) {         if (j == 2 && name[i][0] == name[i][2]) continue;         int x = name[i][j] ==  B  ? 0 : name[i][j] ==  G  ? 1 : 2;         int y = name[i][2 - j] ==  B  ? 0 : name[i][2 - j] ==  G  ? 1 : 2;         need[x][nways[x]] = i;         gain[x][nways[x]] = j == 1 ? -1 : y;         ++nways[x];       }     for (int i = (0); i < (3); ++i) assert(nways[i] == 16);   }   int encode(char s[3]) {     for (int i = (3); i < (21); ++i)       if (s[0] == name[i][0] && s[1] == name[i][1] && s[2] == name[i][2])         return i;     assert(false);     return -1;   }   map<State, double> mem;   double go(State &s) {     map<State, double>::iterator retit = mem.find(s);     if (retit != mem.end()) return retit->second;     char oldtop[3];     int gaintop = -1;     bool fulltop = true;     for (int k = (0); k < (3); ++k)       if (s.top[k] ==  ? ) fulltop = false;     if (fulltop) {       for (int k = (0); k < (3); ++k) oldtop[k] = s.top[k];       gaintop = encode(s.top);       for (int k = (0); k < (3); ++k) s.top[k] =  ? ;     }     int nwait = 1;     double sum = 0;     for (int i = (0); i < (3); ++i) {       int times = i == 2 ? 1 : 2;       bool any = false;       double best = -1;       for (int j = (0); j < (nways[i]); ++j)         if (s.cnt[need[i][j]] > 0)           for (int k = (0); k < (3); ++k) {             if (s.top[k] !=  ?  || k == 2 && s.top[0] ==  ? ) continue;             s.top[k] = color[i];             bool swaptop = false;             if (k == 2 && s.top[0] > s.top[2]) {               swaptop = true;               swap(s.top[0], s.top[2]);             }             --s.cnt[need[i][j]];             if (gain[i][j] != -1) ++s.cnt[gain[i][j]];             if (gaintop != -1) ++s.cnt[gaintop];             double cur = go(s);             if (!any || cur < best) any = true, best = cur;             if (gaintop != -1) --s.cnt[gaintop];             if (gain[i][j] != -1) --s.cnt[gain[i][j]];             ++s.cnt[need[i][j]];             if (swaptop) swap(s.top[0], s.top[2]);             s.top[k] =  ? ;           }       if (!any)         nwait += times;       else         sum += times * best;     }     if (fulltop) {       for (int k = (0); k < (3); ++k) s.top[k] = oldtop[k];     }     double ret = nwait == 6 ? 0.0 : (6 + sum) / (6 - nwait);     return mem[s] = ret;   }   char sinit[6][3];   void run() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (3); ++j) scanf(  %c , &sinit[i][j]);     for (int i = (0); i < (n); ++i)       if (sinit[i][0] > sinit[i][2]) swap(sinit[i][0], sinit[i][2]);     State init;     for (int j = (0); j < (21); ++j) init.cnt[j] = 0;     for (int i = (0); i < (n - 1); ++i) init.cnt[encode(sinit[i])]++;     for (int k = (0); k < (3); ++k) init.top[k] = sinit[n - 1][k];     double ret = go(init);     printf( %.9lf n , ret);   }   int main() {     init();     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long gcd(long long x, long long y) {     if (!y) return x;     return gcd(y, x % y);   }   int main() {     scanf( %I64d%I64d%I64d , &n, &m, &k);     if (n * m * 2 % k) {       printf( NO );       return 0;     }     long long x = gcd(n * m * 2 / k, n), y = n * m * 2 / k / x;     if (y > m) x *= 2, y /= 2;     printf( YES n );     printf( %I64d 0 n0 %I64d n0 0 , x, y);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long MAX = 1000004;   const long long INF = 1e18L + 5;   template <class T, class U>   void chmin(T &t, const U &u) {     if (t > u) t = u;   }   template <class T, class U>   void chmax(T &t, const U &u) {     if (t < u) t = u;   }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   template <typename Arg1>   void pn(Arg1 &&arg1) {     cout << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void pn(Arg1 &&arg1, Args &&...args) {     cout << arg1 <<   n ;     pn(args...);   }   template <typename Arg1>   void ps(Arg1 &&arg1) {     cout << arg1 <<    ;   }   template <typename Arg1, typename... Args>   void ps(Arg1 &&arg1, Args &&...args) {     cout << arg1 <<    ;     ps(args...);   }   template <typename Arg1>   void read(Arg1 &&arg1) {     cin >> arg1;   }   template <typename Arg1, typename... Args>   void read(Arg1 &&arg1, Args &&...args) {     cin >> arg1;     read(args...);   }   long long n, m;   char mat[51][51];   long long dx[] = {1, 0, -1, 0};   long long dy[] = {0, 1, 0, -1};   bool valid(long long x, long long y) {     if (x >= 0 && y >= 0 && x < n && y < m) return true;     return false;   }   vector<vector<long long>> vis(51, vector<long long>(51, 0));   void dfs(long long x, long long y) {     if (mat[x][y] ==  # ) return;     if (mat[x][y] ==  G ) {       mat[x][y] =  . ;     }     if (mat[x][y] ==  B ) {       return;     }     vis[x][y] = 1;     for (long long i = 0; i < 4; ++i) {       long long tx = x + dx[i];       long long ty = y + dy[i];       if (valid(tx, ty)) {         if (!vis[tx][ty]) dfs(tx, ty);       }     }   }   void solve() {     read(n, m);     bool pos = true;     for (long long i = 0; i < n; ++i)       for (long long j = 0; j < m; ++j) read(mat[i][j]);     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < m; ++j) {         if (mat[i][j] ==  B ) {           for (long long k = 0; k < 4; ++k) {             long long tx = i + dx[k];             long long ty = j + dy[k];             if (valid(tx, ty)) {               if (mat[tx][ty] ==  G ) {                 pos = false;               } else {                 if (mat[tx][ty] !=  B ) mat[tx][ty] =  # ;               }             }           }         }       }     }     if (pos) {       for (long long i = 0; i < n; ++i) {         for (long long j = 0; j < m; ++j) {           if (mat[i][j] ==  G ) {             for (long long k = 0; k < n; ++k)               for (long long l = 0; l < m; ++l) vis[k][l] = 0;             dfs(i, j);             if (vis[n - 1][m - 1] == 0) {               pos = false;             }           }         }       }       pn(pos ?  Yes  :  No );     } else       pn( No );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long tc = 1;     cin >> tc;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 5;   int n, m, fa[N], b[N], ans;   struct edge {     int u, v, w;   } e[N];   bool cmp(edge x, edge y) { return x.w > y.w; }   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int main() {     scanf( %d%d , &n, &m);     for (register int i = 1; i <= n + m; ++i) fa[i] = i;     for (register int i = 1, x, y, w; i <= m; ++i) {       scanf( %d%d%d , &x, &y, &w);       e[i] = (edge){x, y, w};     }     sort(e + 1, e + m + 1, cmp);     for (register int i = 1, x, y; i <= m; ++i) {       x = find(e[i].u), y = find(e[i].v);       if (x == y && !b[x]) {         b[x] = 1;         ans += e[i].w;       } else if (x != y && !(b[x] && b[y])) {         if (b[x] || b[y]) b[y] = 1;         fa[x] = y;         ans += e[i].w;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     int type;     void get(int t) {       cin >> x >> y;       type = t;     }   };   int N, M;   Point R[500], B[500], P[1000], pivot;   bool used[500];   Point operator-(Point p1, Point p2) { return Point{p1.x - p2.x, p1.y - p2.y}; }   int quadrant(Point p) {     if (p.x >= 0 && p.y >= 0) return 1;     if (p.x <= 0 && p.y >= 0) return 2;     if (p.x <= 0 && p.y <= 0) return 3;     return 4;   }   long long cross(Point p1, Point p2) { return p1.x * p2.y - p1.y * p2.x; }   bool operator<(Point p1, Point p2) {     if (quadrant(p1 - pivot) != quadrant(p2 - pivot))       return quadrant(p1 - pivot) < quadrant(p2 - pivot);     return cross(p1 - pivot, p2 - pivot) > 0;   }   int main() {     while (cin >> N >> M) {       for (int i = 0; i < N; i++) R[i].get(0);       for (int i = 0; i < M; i++) B[i].get(1);       memset(used, 0, sizeof(used));       int x = 0;       for (int i = 0; i < N; i++) {         used[i] = 1;         pivot = R[i];         int cnt = 0;         for (int j = 0; j < N; j++)           if (!used[j]) P[cnt++] = R[j];         for (int j = 0; j < M; j++) P[cnt++] = B[j];         sort(P, P + cnt);         for (int j = 0; j < cnt; j++) {           if (P[j].type == 0) {             int last = -1;             for (int k = (j + 1) % cnt; k != j; k = (k + 1) % cnt) {               bool ok = (last == -1 || cross(P[last] - P[j], P[k] - P[j]) > 0);               if (P[k].type == 0) {                 if (cross(P[j] - R[i], P[k] - R[i]) < 0) break;                 if (ok) x++;               } else if (ok)                 last = k;             }           }         }       }       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (n > m) swap(n, m);     switch (n) {       case 1:         cout << m / 6 * 6 + 2 * max(m % 6 - 3, 0);         break;       case 2:         switch (m) {           case 2:             cout << 0;             break;           case 3:             cout << 4;             break;           case 7:             cout << 12;             break;           default:             cout << 2 * m;             break;         }         break;       default:         cout << 1ll * n * m / 2 * 2;         break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[500000 + 5], ans[500000 + 5];   int main() {     int n, k, d;     cin >> n >> k >> d;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     ans[n + 1] = 0;     ans[n] = 1;     int lptr = n - 1, dptr = n - 1;     for (int i = n - 1; i >= 0; i--) {       while (lptr > 0 && lptr - i > k - 1) lptr--;       while (dptr > 0 && a[dptr] - a[i] > d) dptr--;       if (ans[lptr + 1] - ans[dptr + 2] > 0 && lptr - i == k - 1) ans[i]++;       ans[i] += ans[i + 1];     }     if (ans[0] - ans[1] == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     int n, p, k;     cin >> n >> p >> k;     map<int, int> mp;     long long sol = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       int y = x * 1ll * x % p;       y = y * 1ll * y % p;       y = ((y - k * 1ll * x) % p + p) % p;       sol += mp[y]++;     }     cout << sol <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   const int K = 5;   const int INF = 1e9;   struct node {     int t[K][K];     node() {       for (int i = int(0); i < int(K); ++i)         for (int j = int(0); j < int(K); ++j) t[i][j] = INF;       for (int i = int(0); i < int(K); ++i) t[i][i] = 0;     }   };   const int N = 200100;   node t[4 * N];   int sz;   node botva(node a, node b) {     node c;     for (int i = int(0); i < int(K); ++i)       for (int j = int(i); j < int(K); ++j) {         c.t[i][j] = INF;         for (int k = int(i); k < int(j + 1); ++k)           umn(c.t[i][j], a.t[i][k] + b.t[k][j]);       }     return c;   }   node fnd(int i, int x, int y, int l, int r) {     if (x > r || y < l) return node();     if (x >= l && y <= r) {       return t[i];     }     return botva(fnd(2 * i, x, (x + y) >> 1, l, r),                  fnd(2 * i + 1, ((x + y) >> 1) + 1, y, l, r));   }   node fnd(int l, int r) {     l += sz, r += sz;     if (l == r) {       return t[l];     }     node left = t[l], right = t[r];     while (l / 2 != r / 2) {       if (!(l & 1)) {         left = botva(left, t[l + 1]);       }       if (r & 1) {         right = botva(t[r - 1], right);       }       l >>= 1, r >>= 1;     }     return botva(left, right);   }   char c[N];   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     int n, q;     cin >> n >> q;     string s;     getline(cin, s);     gets(c);     s = c;     string g =  2017 ;     sz = 1;     while (sz < n) sz <<= 1;     for (int i = int(0); i < int(n); ++i) {       node& v = t[i + sz];       for (int j = int(0); j < int(((int)(g).size())); ++j) {         if (g[j] == s[i]) {           v.t[j][j] = 1;           v.t[j][j + 1] = 0;         }       }       if (s[i] ==  6 ) {         v.t[3][3] = v.t[4][4] = 1;       }     }     for (int i = int(sz) - 1; i >= int(1); --i) {       t[i] = botva(t[2 * i], t[2 * i + 1]);     }     for (int i = int(0); i < int(q); ++i) {       int l, r;       scanf( %d%d , &l, &r);       l--, r--;       node res = fnd(1, 0, sz - 1, l, r);       if (res.t[0][4] >= INF) {         printf( -1 n );       } else {         printf( %d n , res.t[0][4]);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -fhoist-adjacent-loads )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   const int N = 2e5 + 9;   int x[N], t, n, k;   char buf[1 << 21], *p1 = buf, *p2 = buf;   inline int getc() {     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int ret = 0, f = 0;     char ch = getc();     while (!isdigit(ch)) {       if (ch ==  - ) f = 1;       ch = getc();     }     while (isdigit(ch)) {       ret = ret * 10 + ch - 48;       ch = getc();     }     return f ? -ret : ret;   }   char Buf[1 << 21], out[20];   int P, Size = -1;   inline void flush() {     fwrite(Buf, 1, Size + 1, stdout);     Size = -1;   }   inline void write(int x, char ch) {     if (Size > 1 << 20) flush();     if (x < 0) Buf[++Size] = 45, x = -x;     do {       out[++P] = x % 10 + 48;     } while (x /= 10);     do {       Buf[++Size] = out[P];     } while (--P);     Buf[++Size] = ch;   }   inline int max(int a, int b) { return a > b ? a : b; }   int main() {     t = read();     while (t--) {       n = read(), k = read();       for (register int i = 0; i < n; i++) *(x + i) = read();       for (register int i = 0; i < n; i++) read();       sort(x, x + n);       int maxi = 0, opt = 0, fans = 0;       for (register int i = 0; i < n; i++) {         int curr = upper_bound(x + i, x + n, *(x + i) + k) - x - i;         if (i) opt = x + i - lower_bound(x, x + i - 1, *(x + i - 1) - k);         maxi = max(maxi, opt);         curr += maxi;         fans = max(fans, curr);       }       write(fans,   n );     }     flush();     return 0;   }