#include <bits/stdc++.h>   using std::vector;   const long double EPS = 1e-10;   int n;   int x[5], y[5], r[5];   inline int sqr(int x) { return x * x; }   namespace solver2 {   bool get(int a, int b) {     int dist2 = sqr(x[a] - x[b]) + sqr(y[a] - y[b]);     return dist2 < sqr(r[a] + r[b]) && dist2 > sqr(r[a] - r[b]);   }   bool in(int x0, int y0, int a) {     return (sqr(x0 - x[a]) + sqr(y0 - y[a])) < sqr(r[a]);   }   bool sta[10];   void main() {     int p = 240;     for (int i = 1; i <= n; i++) x[i] *= p, y[i] *= p, r[i] *= p;     for (int i = 1, x = -20 * p; i <= p * 40; i++, x++) {       for (int j = 1, y = -20 * p; j <= p * 40; j++, y++) {         int tmp = 0;         for (int k = 1; k <= n; k++) {           tmp += in(x, y, k) << (k - 1);         }         sta[tmp] = 1;       }     }     int ans = 1;     for (int i = 1; i < (1 << n); i++) ans += sta[i];     printf( %d n , ans);   }   }  // namespace solver2   namespace geometry {   inline long double sqr(long double x) { return x * x; }   inline int sgn(long double x) { return x < -EPS ? -1 : x > EPS; }   struct Vector {     long double x, y;     Vector(long double x = 0, long double y = 0) : x(x), y(y) {}     long double len() { return sqrt(sqr(x) + sqr(y)); }     long double norm() { return sqr(x) + sqr(y); }     Vector unit() { return *this / len(); }     long double angle() { return atan2(y, x); }     bool operator==(const Vector &rhs) const {       return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0;     }     bool operator<(const Vector &rhs) const {       return sgn(x - rhs.x) < 0 || (sgn(x - rhs.x) == 0 && sgn(y - rhs.y) < 0);     }     Vector operator+(const Vector &__rhs) const {       return Vector(x + __rhs.x, y + __rhs.y);     }     Vector operator-(const Vector &__rhs) const {       return Vector(x - __rhs.x, y - __rhs.y);     }     Vector operator*(const long double __rhs) const {       return Vector(x * __rhs, y * __rhs);     }     Vector operator/(const long double __rhs) const {       return Vector(x / __rhs, y / __rhs);     }   };   long double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }   long double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }   Vector rotate(Vector a, Vector b) {     b = b.unit();     return Vector(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);   }   struct Line {     Vector u;     Vector v;     Line() {}     Line(Vector a, Vector b) : u(a), v((b - a).unit()) {}   };   struct Circle {     Vector o;     long double r;     Circle() {}     Circle(Vector o, long double r) : o(o), r(r) {}   };   Vector mid_point(Vector a, Vector b) {     return Vector((a.x + b.x) / 2, (a.y + b.y) / 2);   }   Line divide_angle(Vector u, Vector v1, Vector v2) {     return Line(u, v1.unit() + v2.unit());   }   long double distance_to_line(Vector u, Line l) {     return fabs(cross(u - l.u, l.v)) / l.v.len();   }   Vector perpendicular_foot(Vector u, Line l) {     return l.u + l.v * dot(l.v, u - l.u);   }   Line move(Line l, long double d) {     return Line(l.u + rotate(l.v, Vector(0, 1)).unit() * d, l.v);   }   Vector intersection(Line l1, Line l2) {     return l1.u + l1.v * (cross(l2.v, l1.u - l2.u) / cross(l1.v, l2.v));   }   vector<Vector> intersection(Circle c1, Circle c2) {     if (sgn(c1.r - c2.r) < 0) std::swap(c1, c2);     long double d = (c1.o - c2.o).len();     if (sgn(c1.r + c2.r - d) < 0 || sgn(fabs(c1.r - c2.r) - d) > 0) {       return {};     } else if (sgn(c1.r + c2.r - d) == 0 || sgn(fabs(c1.r - c2.r) - d) == 0) {       return {c1.o + (c2.o - c1.o).unit() * c1.r};     } else {       long double cos_alpha = (sqr(d) + sqr(c1.r) - sqr(c2.r)) / (2 * d * c1.r);       long double sin_alpha = sqrt(1 - sqr(cos_alpha));       Vector delta1 = rotate(c2.o - c1.o, Vector(cos_alpha, sin_alpha)),              delta2 = rotate(c2.o - c1.o, Vector(cos_alpha, -sin_alpha));       return {c1.o + delta1.unit() * c1.r, c1.o + delta2.unit() * c1.r};     }   }   vector<Vector> intersection(Line l, Circle c) {     long double d = distance_to_line(c.o, l);     if (sgn(d - c.r) > 0) {       return {};     } else if (sgn(d - c.r) == 0) {       return {perpendicular_foot(c.o, l)};     } else {       Vector p = perpendicular_foot(c.o, l);       long double delta = sqrt(sqr(c.r) - sqr(d));       return {p + l.v * delta, p - l.v * delta};     }   }   }  // namespace geometry   using namespace geometry;   namespace solver1 {   bool get(int a, int b) {     int dist2 = sqr(x[a] - x[b]) + sqr(y[a] - y[b]);     return dist2 < sqr(r[a] + r[b]) && dist2 > sqr(r[a] - r[b]);   }   bool in(int x0, int y0, int a) {     return (sqr(x0 - x[a]) + sqr(y0 - y[a])) < sqr(r[a]);   }   bool sta[10];   void main() {     if (n == 1) {       puts( 2 );       return;     } else if (n == 2) {       if (get(1, 2)) {         puts( 4 );       } else         puts( 3 );       return;     } else {       Circle c[5];       for (int i = 1; i <= n; i++) c[i] = Circle(Vector(x[i], y[i]), r[i]);       vector<Vector> i12 = intersection(c[1], c[2]),                      i13 = intersection(c[1], c[3]),                      i23 = intersection(c[2], c[3]);       vector<Vector> p;       for (auto i : i12) p.push_back(i);       for (auto i : i13) p.push_back(i);       for (auto i : i23) p.push_back(i);       std::sort(p.begin(), p.end());       p.erase(std::unique(p.begin(), p.end()), p.end());       int cnt[5];       memset(cnt, 0, sizeof cnt);       for (auto i : p) {         for (int j = 1; j <= 3; j++) {           if (sgn((i - c[j].o).len() - r[j]) == 0) cnt[j]++;         }       }       int tot = 0;       for (int i = 1; i <= 3; i++) tot += cnt[i] ? cnt[i] : 1;       printf( %d , tot + 2 - std::max((int)p.size(), 1));     }   }   }  // namespace solver1   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d%d , &x[i], &y[i], &r[i]);     solver1::main();   }


#include <bits/stdc++.h>   using namespace std;   void fun() {}   long long mod = 1000000000 + 7;   long long powe(long long x, long long y) {     x = x % mod, y = y % (mod - 1);     long long ans = 1;     while (y > 0) {       if (y & 1) {         ans = (1ll * x * ans) % mod;       }       y >>= 1;       x = (1ll * x * x) % mod;     }     return ans;   }   map<pair<long long, long long>, long long> m;   long long ncr(long long n, long long r) { return n * (n - 1) * (n - 2) / 6; }   int32_t main() {     fun();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t, temp;     long long n, s, k;     cin >> t;     while (t--) {       cin >> n >> s >> k;       long long a[k];       long long i;       long long num;       for (i = 0; i < k; i++) {         cin >> num;         a[i] = num;       }       sort(a, a + k);       long long num1 = INT_MAX, num2 = INT_MAX;       for (i = s; i >= 1; i--) {         if (!binary_search(a, a + k, i)) {           num1 = i;           break;         }       }       for (i = s; i <= n; i++) {         if (!binary_search(a, a + k, i)) {           num2 = i;           break;         }       }       if (num1 == INT_MAX)         cout << num2 - s <<   n ;       else if (num2 == INT_MAX)         cout << s - num1 <<   n ;       else         cout << min(s - num1, num2 - s) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   double x[100010], y[100010], X, Y, mem[100010];   int id[100010], len;   int cmp(int i, int j) {     if (fabs(x[i] - x[j]) > 1e-8) return x[i] < x[j];     return y[i] > y[j];   }   int main() {     int n, i, j, k, A, B, C, D;     scanf( %d %d/%d %d/%d , &n, &A, &B, &C, &D);     for (i = 0; i < n; i++) {       scanf( %lf %lf , &X, &Y);       x[i] = X;       y[i] = Y;       if (C && D) x[i] -= Y / C * D;       if (A && B) y[i] -= X / B * A;       id[i] = i;     }     sort(id, id + n, cmp);     len = 0;     for (i = 0; i < n; i++)       if (x[id[i]] > 0 && y[id[i]] > 0) {         k = lower_bound(mem, mem + len, y[id[i]] - 1e-8) - mem;         if (k == len) len++;         mem[k] = y[id[i]];       }     printf( %d n , len);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   const long long L = 1e5 + 5;   long long arr[L];   long long bo[L];   long long gi[L];   long long bg[L];   priority_queue<long long> val;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, b, g;     cin >> b >> g;     long long ans = 0;     long long x = -1e18, y = 1e18;     for (i = 0; i < b; i++) {       bg[i] = 1;       cin >> bo[i];       arr[i] = g - 1;       ans += bo[i];       x = max(bo[i], x);     }     for (i = 0; i < g; i++) {       cin >> gi[i];       ans += gi[i];       val.push(gi[i]);       y = min(gi[i], y);     }     if (y < x) {       cout << -1 << endl;       return 0;     }     sort(bo, bo + b);     i = b - 1;     while (!val.empty() && i >= 0) {       if (val.top() >= bo[i]) {         if (arr[i] == 0) {           if (bo[i] == val.top()) {             ans -= bo[i];             val.pop();           }           i--;           continue;         }         arr[i]--;         val.pop();       } else         i--;     }     for (i = 0; i < b; i++) ans += arr[i] * bo[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 111;   int a[maxn];   int getid[maxn];   int b[maxn];   int lpos[maxn];   vector<int> savepos[maxn];   vector<int> G[maxn];   vector<int> v;   int n, m, q;   int vis[maxn];   void dfs(int pos, int fa) {     v.push_back(pos);     vis[pos] = 1;     if (v.size() >= n) {       int id = v.size() - n;       lpos[pos] = v[id];     }     for (int d : G[pos]) {       if (d == fa) continue;       dfs(d, pos);     }     v.pop_back();   }   int main() {     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       getid[a[i]] = i;     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]);       savepos[b[i]].push_back(i);     }     for (int i = 1; i <= m; i++) {       int nowval = b[i];       int preid = getid[nowval] - 1;       if (!preid) preid = n;       int preval = a[preid];       int id = lower_bound(savepos[preval].begin(), savepos[preval].end(), i) -                savepos[preval].begin() - 1;       if (id >= 0) {         G[savepos[preval][id]].push_back(i);       }       savepos[nowval].push_back(i);     }     for (int i = 1; i <= m; i++) {       if (!vis[i]) {         v.clear();         dfs(i, -1);       }     }     int p = 0;     for (int i = 1; i <= m; i++) {       lpos[i] = max(lpos[i - 1], lpos[i]);     }     while (q--) {       int l, r;       scanf( %d %d , &l, &r);       if (l <= lpos[r]) {         cout << 1;       } else {         cout << 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int flag[100005];   int ok, a[100005], b[100005], vis[100005];   vector<int> G[100005];   void Sech(int u, int p) {     int i, v;     vis[u] = 1;     if (flag[u] == 1) ok = -1;     flag[u] = -1;     for (i = 0; i < G[u].size(); i++) {       v = G[u][i];       if (v == p || vis[v]) continue;       Sech(v, u);     }   }   int main(void) {     ok = 1;     int n, m, i, j, len2, len1, ans;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       if (i == 1) {         scanf( %d , &len2);         for (j = 1; j <= len2; j++) scanf( %d , &b[j]);         continue;       }       for (j = 1; j <= len2; j++) a[j] = b[j];       len1 = len2;       scanf( %d , &len2);       for (j = 1; j <= len2; j++) scanf( %d , &b[j]);       for (j = 1; j <= min(len1, len2); j++) {         if (a[j] < b[j]) {           G[b[j]].push_back(a[j]);           break;         } else if (a[j] > b[j]) {           if (flag[a[j]] == 1 || flag[b[j]] == -1) ok = -1;           flag[a[j]] = -1, flag[b[j]] = 1;           break;         }       }       if (len1 > len2 && j == len2 + 1) {         printf( No n );         return 0;       }     }     if (ok == -1) {       printf( No n );       return 0;     }     for (i = 1; i <= m; i++) {       if (vis[i] == 0 && flag[i] == -1) Sech(i, -1);       if (ok == -1) break;     }     if (ok == -1) {       printf( No n );       return 0;     }     printf( Yes n );     ans = 0;     for (i = 1; i <= m; i++) {       if (flag[i] == -1) ans++;     }     printf( %d n , ans);     for (i = 1; i <= m; i++) {       if (flag[i] == -1) printf( %d  , i);     }     if (ans != 0) printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int toint(char a) { return (a -  0 ); }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tst;     cin >> tst;     while (tst--) {       string a, s;       cin >> a >> s;       long long int num = stoll(a);       long long int sum = stoll(s);       if (s.length() < a.length()) {         cout <<  -1 n ;       } else if (a.length() == s.length()) {         bool no = false;         for (int i = s.length() - 1; i >= 0; i--) {           if ((toint(s[i]) - toint(a[i])) < 0) {             cout <<  -1 n ;             no = true;             break;           }         }         if (!no) {           cout << stoll(s) - stoll(a) <<   n ;         }       } else if (a.length() < s.length()) {         int lastdigit;         int lastsub;         string ans;         bool no = 0;         int strlen = s.length();         while (strlen > 0) {           lastsub = num % 10;           if (sum % 10 - num % 10 < 0) {             lastdigit = (sum % 10) + ((sum % 100) - (sum % 10));             sum /= 100;             num /= 10;             strlen -= 2;           } else {             lastdigit = sum % 10;             sum /= 10;             num /= 10;             strlen--;           }           if (lastdigit - lastsub >= 0 && lastdigit - lastsub <= 9) {             if (strlen != 0) {               ans = to_string(lastdigit - lastsub) + ans;             } else {               if (lastdigit - lastsub != 0) {                 ans = to_string(lastdigit - lastsub) + ans;               }             }           } else {             cout <<  -1 n ;             no = true;             break;           }         }         if (!no) {           cout << ans <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100001], i, l, r, n, j, c44, c1, c4, c, x, ans, h, y, m, step[101],       v, b[100500], d[100500];   string s;   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (i = 1; i <= n; i++) {       if (l <= b[i]) {         c++;         l += b[i];       }     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000030;   int num[MAXN];   int a[MAXN], b[MAXN];   int dex[MAXN];   int res[MAXN];   int bsch(int le, int ri, int key) {     int l = le, r = ri;     while (l <= r) {       int m = (l + r) / 2;       if (res[m] == key)         return m;       else if (res[m] > key)         r = m - 1;       else         l = m + 1;     }     return l;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       dex[b[i]] = i;     }     for (int i = 1; i <= n; i++) {       num[i] = dex[a[i]];     }     for (int i = 1; i <= n / 2; i++) {       swap(num[i], num[n - i + 1]);     }     for (int i = 1; i <= n; i++) {       res[i] = 1 << 30;     }     int maxv = 1;     res[1] = num[1];     for (int i = 2; i <= n; i++) {       int s = bsch(1, n, num[i]);       res[s] = num[i];       if (maxv < s) maxv = s;     }     printf( %d n , maxv);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n, m, num[40][40], len = 0, stat[20], sv[20], ans = 0;   bool vis[10][10], vis2[10][10], usedr[10], have = false;   string s[40];   vector<pair<int, int> > coo[400];   vector<int> pr[20];   bool stane = false;   bool check(int pos) {     map<pair<int, int>, int> mp;     mp.clear();     for (int i = 0; i < pr[pos].size(); ++i) {       int x = stat[pos], y = stat[pr[pos][i]];       if (vis[x][y] || mp[make_pair(x, y)]) return false;       mp[make_pair(x, y)] = mp[make_pair(y, x)] = true;     }     return true;   }   void add(int pos, bool val) {     for (int i = 0; i < pr[pos].size(); ++i) {       int x = stat[pos], y = stat[pr[pos][i]];       vis[x][y] = vis[y][x] = val;     }   }   void dfs(int pos, int curc) {     if (pos == 14) {       ++ans;       if (!have) {         have = true;         for (int i = 0; i < 14; ++i) sv[i] = stat[i];       }       return;     }     if (curc < 7) {       stat[pos] = curc;       if (check(pos)) {         add(pos, true);         dfs(pos + 1, curc + 1);         add(pos, false);       }     }     for (int i = 0; i < curc; ++i) {       if (usedr[i]) continue;       stat[pos] = i;       if (check(pos)) {         usedr[i] = true;         add(pos, true);         dfs(pos + 1, curc);         usedr[i] = false;         add(pos, false);       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> s[i];       for (int j = 0; j < m; ++j)         if (s[i][j] ==  A )           s[i][j] =  z  + 1;         else if (s[i][j] ==  B )           s[i][j] =  z  + 2;     }     for (int i = 0; i < n + 5; ++i)       for (int j = 0; j < m + 5; ++j) num[i][j] = -1;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if ( a  <= s[i][j] && s[i][j] <=  z  + 2) {           coo[s[i][j]].push_back(make_pair(i, j));           if (num[i][j] == -1) {             for (int k = i; k < i + 2; ++k)               for (int p = j; p < j + 2; ++p) num[k][p] = len;             ++len;           }         }     for (int i =  a ; i <=  z  + 2; ++i) {       int x = coo[i][0].first, y = coo[i][0].second, xx = coo[i][1].first,           yy = coo[i][1].second;       pr[max(num[x][y], num[xx][yy])].push_back(min(num[x][y], num[xx][yy]));     }     dfs(0, 0);     cout << ans * 5040 << endl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (!( a  <= s[i][j] && s[i][j] <=  z  + 2))           cout <<  . ;         else           cout << sv[num[i][j]];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int m, k;     cin >> m >> k;     if (m % 2 == 0) {       printf( %d n , m + k * 2);     } else {       int t;       for (int i = 3; i <= m; i += 2) {         if (m % i == 0) {           t = i;           break;         }       }       k--;       m += t;       printf( %d n , m + k * 2);     }   }   int main() {     int n;     cin >> n;     while (n--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m = 1e9 + 7;   double eps = 1e-6;   bool good[256];   long long n, spos = -1;   int main(int argc, char *argv[]) {     ios::sync_with_stdio(0);     string g, pat;     cin >> g;     cin >> pat;     cin >> n;     for (int i = 0; (i) < (256); ++i) good[i] = false;     for (int i = 0; (i) < (((int)(pat).size())); ++i)       if (pat[i] ==  * ) spos = i;     for (int i = 0; (i) < (((int)(g).size())); ++i) {       good[int(g[i])] = true;     }     for (int i = 0; (i) < (n); ++i) {       string s;       bool pass = true;       cin >> s;       if (spos == -1) {         if (((int)(pat).size()) != ((int)(s).size()))           cout <<  NO  << endl;         else {           for (int j = 0; (j) < (((int)(pat).size())); ++j) {             if (pat[j] !=  ?  && pat[j] != s[j])               pass = false;             else if (pat[j] ==  ?  && !good[int(s[j])])               pass = false;           }           if (pass)             cout <<  YES  << endl;           else             cout <<  NO  << endl;         }       } else {         if (((int)(s).size()) - ((int)(pat).size()) < -1)           cout <<  NO  << endl;         else {           long long offset = ((int)(s).size()) - ((int)(pat).size());           for (int j = 0; (j) < (spos); ++j) {             if (pat[j] !=  ?  && pat[j] != s[j])               pass = false;             else if (pat[j] ==  ?  && !good[int(s[j])])               pass = false;           }           for (long long j = spos + 1 + offset; j < ((int)(s).size()); j++) {             if (pat[j - offset] !=  ?  && pat[j - offset] != s[j])               pass = false;             else if (pat[j - offset] ==  ?  && !good[int(s[j])])               pass = false;           }           for (long long j = spos; j <= spos + offset; j++)             if (good[int(s[j])]) pass = false;           if (pass)             cout <<  YES  << endl;           else             cout <<  NO  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> s(n, 0);     s[n - 1] = a[n - 1];     for (int i = n - 2; i >= 0; i--) s[i] = max(a[i], s[i + 1]);     for (int i = 0; i < n - 1; i++) cout << max(0, s[i + 1] - a[i] + 1) <<    ;     cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pr {     int a, b, n, x;     pr(int a, int b, int n) : a(a), b(b), n(n) {}     pr() : a(0), b(0), n(-1) {}   };   int n, m;   vector<pr> a, b;   void connect(int x1, int& x2, int& y2) {     if ((x2 != -1 && x2 != x1) || (y2 != -1 && y2 != x1)) {       cout << -1;       exit(0);     }     x2 = y2 = x1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       a.push_back(pr(x, y, -1));     }     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       b.push_back(pr(x, y, -1));     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i].a == b[j].a && a[i].b != b[j].b)           connect(a[i].a, a[i].n, b[j].n);         else if (a[i].b == b[j].b && a[i].a != b[j].a)           connect(a[i].b, a[i].n, b[j].n);         else if (a[i].a == b[j].b && a[i].b != b[j].a)           connect(a[i].a, a[i].n, b[j].n);         else if (a[i].b == b[j].a && a[i].a != b[j].b)           connect(a[i].b, a[i].n, b[j].n);       }     }     int ans = -1;     for (int i = 0; i < n; i++) {       if (a[i].n != -1) {         if (ans == -1 || ans == a[i].n)           ans = a[i].n;         else {           cout << 0;           return 0;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 70, MAXM = 100, MOD = 1e9 + 7, INF = 1e9;   char c[] = { c ,  o ,  d ,  e ,  f ,  o ,  r ,  c ,  e ,  s };   void solve() {     long long n;     cin >> n;     long long x = 0, x1 = 0;     while (pow(x + 1, 10) <= n) x++;     while (pow(x, 10 - x1) * pow(x + 1, x1) < n) x1++;     for (int i = 0; i < 10; i++) {       if (i < x1)         for (int j = 0; j <= x; j++) cout << c[i];       else         for (int j = 0; j < x; j++) cout << c[i];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const double SUCK = 999999999999999999.99;   const int MX = 51 * 101;   int n;   int r;   int f[55];   int s[55];   int p[55];   double cp[55];   double dp[55][MX];   bool isOk(double det) {     for (int i = 0; i <= r; i++) {       dp[n][i] = 0;     }     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j <= r; j++) {         dp[i][j] = det;         double togo = 0;         if (j + f[i] > r) {           togo = det;         } else {           togo += cp[i] * (f[i] + dp[i + 1][j + f[i]]);           if (j + s[i] > r)             togo += (1 - cp[i]) * (s[i] + det);           else             togo += (1 - cp[i]) * (s[i] + dp[i + 1][j + s[i]]);         }         dp[i][j] = min(det, togo);       }     }     if (dp[0][0] >= det) return false;     return true;   }   const double eps = 0.000000001;   time_t bg;   double getTime() {     time_t en = clock();     double ret = (double)(en - bg) / CLOCKS_PER_SEC;     return ret;   }   double bsearch(double l, double r) {     double m = (l + r) / 2;     if (r - l < eps) return m;     if (getTime() >= 1.95) return m;     if (isOk(m))       return bsearch(l, m);     else       return bsearch(m, r);   }   int main() {     bg = clock();     scanf( %d%d , &n, &r);     for (int i = 0; i < n; i++) scanf( %d%d%d , &f[i], &s[i], &p[i]);     for (int i = 0; i < n; i++) cp[i] = 0.010000 * p[i];     double ans = bsearch(n, 50000000);     printf( %.12f , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 400010, inf = 1 << 30;   int N, M, father[maxn], nxt[maxn], toit[maxn], len[maxn], side[maxn], id[maxn],       seq[maxn], D[maxn], cnt;   int DFN, dfn[maxn], top[maxn], size[maxn], con[maxn], ans[maxn],       tree[maxn << 2], cover[maxn << 2];   bool exist[maxn];   inline int find(int a) {     if (father[a] != a) father[a] = find(father[a]);     return father[a];   }   inline void add(int a, int b, int c, int d) {     nxt[++cnt] = side[a];     side[a] = cnt;     toit[cnt] = b;     len[cnt] = c;     id[cnt] = d;   }   inline void ins(int a, int b, int c, int d) {     add(a, b, c, d);     add(b, a, c, d);   }   inline int gi() {     char ch;     int ret = 0, f = 1;     do ch = getchar();     while (!(ch >=  0  && ch <=  9 ) && ch !=  - );     if (ch ==  - ) f = -1, ch = getchar();     do ret = ret * 10 + ch -  0 , ch = getchar();     while (ch >=  0  && ch <=  9 );     return ret * f;   }   struct Edge {     int u, v, c, id;     inline void read(int i) {       id = i;       u = gi(), v = gi(), c = gi();     }     inline void bind() {       int a = find(u), b = find(v);       if (a != b) {         father[a] = b;         exist[id] = true;         ins(u, v, c, id);       }     }     friend inline bool operator<(const Edge &a, const Edge &b) {       return a.c < b.c;     }   } edge[maxn];   inline void Div(int now, int Top) {     dfn[now] = ++DFN;     seq[DFN] = now;     top[now] = Top;     int heavy = 0;     for (int i = side[now]; i; i = nxt[i])       if (toit[i] != father[now] && size[toit[i]] > size[heavy]) heavy = toit[i];     if (!heavy) return;     Div(heavy, Top);     for (int i = side[now]; i; i = nxt[i])       if (toit[i] != father[now] && toit[i] != heavy) Div(toit[i], toit[i]);   }   inline void dfs(int now) {     size[now] = 1;     for (int i = side[now]; i; i = nxt[i])       if (toit[i] != father[now]) {         father[toit[i]] = now, con[toit[i]] = i;         D[toit[i]] = D[now] + 1, dfs(toit[i]);         size[now] += size[toit[i]];       }   }   inline void mst() {     sort(edge + 1, edge + M + 1);     cnt = 1;     for (int i = 1; i <= N; ++i) father[i] = i;     for (int i = 1; i <= M; ++i) edge[i].bind();     father[1] = 0;     dfs(1);     Div(1, 1);   }   inline int ask(int now, int l, int r, int ql, int qr) {     if (l == ql && r == qr) return tree[now];     int mid = (l + r) >> 1;     if (qr <= mid)       return ask(now << 1, l, mid, ql, qr);     else if (ql > mid)       return ask(now << 1 | 1, mid + 1, r, ql, qr);     else       return max(ask(now << 1, l, mid, ql, mid),                  ask(now << 1 | 1, mid + 1, r, mid + 1, qr));   }   inline void modify(int now, int l, int r, int ql, int qr, int c) {     if (l == ql && r == qr) {       cover[now] = min(cover[now], c);       return;     }     int mid = (l + r) >> 1;     if (qr <= mid)       modify(now << 1, l, mid, ql, qr, c);     else if (ql > mid)       modify(now << 1 | 1, mid + 1, r, ql, qr, c);     else {       modify(now << 1, l, mid, ql, mid, c);       modify(now << 1 | 1, mid + 1, r, mid + 1, qr, c);     }   }   inline int Query(int a, int b, int c) {     int ret = -inf;     while (top[a] != top[b]) {       if (D[top[a]] < D[top[b]]) swap(a, b);       ret = max(ret, ask(1, 1, N, dfn[top[a]], dfn[a]));       modify(1, 1, N, dfn[top[a]], dfn[a], c);       a = father[top[a]];     }     if (D[a] < D[b]) swap(a, b);     if (a != b) {       ret = max(ret, ask(1, 1, N, dfn[b] + 1, dfn[a]));       modify(1, 1, N, dfn[b] + 1, dfn[a], c);     }     return ret;   }   inline void build(int now, int l, int r) {     cover[now] = inf;     if (l == r) {       tree[now] = len[con[seq[l]]];       return;     }     int mid = (l + r) >> 1;     build(now << 1, l, mid);     build(now << 1 | 1, mid + 1, r);     tree[now] = max(tree[now << 1], tree[now << 1 | 1]);   }   inline int query(int now, int l, int r, int pos) {     if (l == r) return cover[now];     int mid = (l + r) >> 1;     if (pos <= mid)       return min(cover[now], query(now << 1, l, mid, pos));     else       return min(cover[now], query(now << 1 | 1, mid + 1, r, pos));   }   inline void work() {     build(1, 1, N);     for (int i = 1; i <= M; ++i)       if (!exist[edge[i].id])         ans[edge[i].id] = Query(edge[i].u, edge[i].v, edge[i].c);     for (int i = 2; i <= N; ++i) ans[id[con[i]]] = query(1, 1, N, dfn[i]);     for (int i = 1; i <= M; ++i) {       if (ans[i] == inf)         ans[i] = -1;       else         --ans[i];       printf( %d  , ans[i]);     }   }   int main() {     N = gi();     M = gi();     for (int i = 1; i <= M; ++i) edge[i].read(i), ans[i] = inf;     mst();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char a = getchar();     for (; !isdigit(a); a = getchar())       if (a ==  - ) f = -1;     for (; isdigit(a); a = getchar()) x = x * 10 + a -  0 ;     return x * f;   }   const unsigned long long INF = 1ULL << 63;   const int N = 200 + 5;   const int M = 50 + 5;   int IG, IN, IM, n, ipt[N];   int issuf[N];   int vis[N][M][M];   unsigned long long f[N][M][M];   vector<pair<int, int> > ed[N];   int ch[M][2], fail[M * 2], ok[M * 2], tot = 1;   void ins(int *A, int len) {     int x = 1;     for (int i = 1; i <= len; i++) {       if (!ch[x][A[i]]) ch[x][A[i]] = ++tot;       x = ch[x][A[i]];     }     ok[x] = 1;   }   void buildfail() {     queue<int> q;     for (int i = 0; i <= 1; i++)       if (ch[1][i])         fail[ch[1][i]] = 1, q.push(ch[1][i]);       else         ch[1][i] = 1;     while (q.size()) {       int x = q.front();       q.pop();       for (int i = 0; i <= 1; i++)         if (ch[x][i]) {           fail[ch[x][i]] = ch[fail[x]][i];           ok[ch[x][i]] |= ok[fail[ch[x][i]]];           q.push(ch[x][i]);         } else           ch[x][i] = ch[fail[x]][i];     }   }   int id[M * 2], loc[M * 2];   struct Node {     int x, fr, to;     unsigned long long val;     Node(int X = 0, int F = 0, int T = 0, unsigned long long V = 0)         : x(X), fr(F), to(T), val(V) {}     inline friend bool operator<(const Node &a, const Node &b) {       return a.val > b.val;     }   };   priority_queue<Node> hp;   int main() {     IG = read() - 1;     IN = read();     IM = read();     n = IG;     for (int i = 1; i <= IN; i++) {       int a = read(), k = read();       for (int j = 1; j <= k; j++) ipt[j] = read(), issuf[j + n] = 1;       for (int j = 2; j <= k; j++) {         ed[n + j].push_back({n + j - 1, ipt[j - 1]});         ed[ipt[j - 1]].push_back({n + j - 1, n + j});       }       ed[ipt[k]].push_back({n + k, -1});       ed[n + 1].push_back({a, -1});       n += k;     }     for (int i = 1; i <= IM; i++) {       int len = read();       for (int j = 1; j <= len; j++) ipt[j] = read();       ins(ipt, len);     }     buildfail();     int cnt = 0;     for (int i = 1; i <= tot; i++)       if (ok[i] == 0) id[i] = ++cnt, loc[cnt] = i;     for (int i = 0; i <= n; i++)       for (int j = 1; j <= cnt; j++)         for (int k = 1; k <= cnt; k++) f[i][j][k] = INF;     for (int i = 1; i <= cnt; i++) {       int x = loc[i];       if (id[ch[x][0]]) {         f[0][i][id[ch[x][0]]] = 1;         hp.push(Node(0, i, id[ch[x][0]], 1));       }       if (id[ch[x][1]]) {         f[1][i][id[ch[x][1]]] = 1;         hp.push(Node(1, i, id[ch[x][1]], 1));       }     }     while (hp.size()) {       Node tmp = hp.top();       hp.pop();       int x = tmp.x, fr = tmp.fr, to = tmp.to;       unsigned long long val = tmp.val;       if (vis[x][fr][to]) continue;       vis[x][fr][to] = 1;       for (auto e : ed[x]) {         int y = e.first, w = e.second;         if (w == -1) {           if (f[y][fr][to] > val) {             f[y][fr][to] = val;             hp.push(Node(y, fr, to, f[y][fr][to]));           }         } else {           if (issuf[x] == 0) {             for (int j = 1; j <= cnt; j++)               if (f[y][fr][j] > val + f[w][to][j]) {                 f[y][fr][j] = val + f[w][to][j];                 hp.push(Node(y, fr, j, f[y][fr][j]));               }           } else {             for (int j = 1; j <= cnt; j++)               if (f[y][j][to] > f[w][j][fr] + val) {                 f[y][j][to] = f[w][j][fr] + val;                 hp.push(Node(y, j, to, f[y][j][to]));               }           }         }       }     }     for (int i = 2; i <= IG; i++) {       unsigned long long ans = INF;       for (int j = 1; j <= cnt; j++) ans = min(ans, f[i][1][j]);       if (ans == INF)         printf( YES n );       else         printf( NO %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const std::string str =  ATGC ;   int main() {     int n, m;     std::vector<std::string> s;     std::vector<std::string> tmp;     std::vector<std::string> ans;     int min_ans = INF, pos;     std::cin >> n >> m;     for (int i = 0; i < n; ++i) {       std::string st;       std::cin >> st;       s.push_back(st);     }     for (int c1 = 0; c1 < 4; ++c1)       for (int c2 = c1 + 1; c2 < 4; ++c2) {         std::string stri;         std::set<int> st;         for (int i = 0; i < 4; ++i) st.insert(i);         st.erase(c1);         st.erase(c2);         auto it = st.begin();         stri.push_back(str[c1]);         stri.push_back(str[c2]);         stri.push_back(str[*(it++)]);         stri.push_back(str[*it]);         pos = 0;         tmp.clear();         for (int i = 0; i < n; ++i) {           tmp.push_back(  );           int bit = (i & 1) << 1;           int cnt1 = 0, cnt2 = 0;           for (int j = 0; j < m; ++j) {             if (s[i][j] != stri[bit + (j & 1)]) ++cnt1;             if (s[i][j] != stri[bit + ((j & 1) ^ 1)]) ++cnt2;           }           if (cnt1 < cnt2)             for (int j = 0; j < m; ++j) tmp[i].push_back(stri[bit + (j & 1)]);           else             for (int j = 0; j < m; ++j)               tmp[i].push_back(stri[bit + ((j & 1) ^ 1)]);           pos += std::min(cnt1, cnt2);         }         if (pos < min_ans) {           ans = tmp;           min_ans = pos;         }         pos = 0;         tmp.clear();         for (int i = 0; i < n; ++i) tmp.push_back(  );         for (int j = 0; j < m; ++j) {           int bit = (j & 1) << 1;           int cnt1 = 0, cnt2 = 0;           for (int i = 0; i < n; ++i) {             if (s[i][j] != stri[bit + (i & 1)]) ++cnt1;             if (s[i][j] != stri[bit + ((i & 1) ^ 1)]) ++cnt2;           }           if (cnt1 < cnt2)             for (int i = 0; i < n; ++i) tmp[i].push_back(stri[bit + (i & 1)]);           else             for (int i = 0; i < n; ++i)               tmp[i].push_back(stri[bit + ((i & 1) ^ 1)]);           pos += std::min(cnt1, cnt2);         }         if (pos < min_ans) {           ans = tmp;           min_ans = pos;         }       }     for (int i = 0; i < n; ++i) std::cout << ans[i] << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long base = 233;   const long long ff = 4e5 + 1;   const long long mod = 1e9 + 7;   const long long inf = 1e17 + 1;   long long read() {     long long x;     scanf( %lld , &x);     return x;   }   inline long long Read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long a, b, c, d;   long long my_max(long long x, long long y) { return (x > y) ? x : y; }   void init() {     long long ans = 0;     a = Read(), b = Read(), c = Read(), d = Read();     for (long long i = a; i <= b; ++i) {       long long st = my_max(min(i + b - c, d), 0LL);       long long ed = my_max(min(i + c - 1, d) - c + 1, 0LL);       long long q = max(ed - st + 1, 0LL);       ans += (st + ed) * q / 2;       if (i + c - 1 > d)         ans += my_max(min((i + c - 1) - d, c - b + 1), 0LL) * (d - c + 1);     }     cout << ans;   }   signed main() { init(); }


#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (n % 2 != 0) {       printf( %d , n);     } else {       int a[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           scanf( %d , &a[i][j]);         }       }       bool isSymmetric = true;       while (isSymmetric == true && n % 2 == 0) {         for (int i = 0; i < n / 2; i++) {           for (int j = 0; j < m; j++) {             if (a[i][j] != a[n - 1 - i][j]) {               isSymmetric = false;               break;             }           }         }         if (isSymmetric) {           n = n / 2;         }       }       printf( %d , n);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> questions(k);     vector<int> previsited(n + 1, 0);     vector<int> posvisited(n + 1, 0);     vector<int> vis;     int tot_non = n;     for (int i = 0; i < k; i++) {       cin >> questions[i];       if (!previsited[questions[i]]) {         tot_non--;         vis.push_back(questions[i]);         previsited[questions[i]] = i + 1;       }       posvisited[questions[i]] = i + 1;     }     int ans = tot_non * 3;     if (previsited[1] == 0) ans--;     if (previsited[n] == 0) ans--;     for (int i = 0; i < vis.size(); i++) {       if (vis[i] <= n - 1 && previsited[vis[i]] > posvisited[vis[i] + 1]) {         ans++;       }       if (vis[i] >= 2 && previsited[vis[i]] > posvisited[vis[i] - 1]) {         ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = (pow(10, 9) + 7);   void vec_p(vector<long long int> &a) {     for (long long int i = 0; i < a.size(); i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   long long int vec_sum(vector<long long int> a) {     long long int s = 0;     for (long long int i = 0; i < a.size(); i++) {       s += a[i];     }     return s;   }   void pfx(vector<long long int> &a, vector<long long int> &prefix_sum) {     prefix_sum[0] = a[0];     for (long long int i = 1; i < a.size(); i++) {       prefix_sum[i] += (prefix_sum[i - 1] + a[i]);     }   }   void sorting_p(vector<pair<long long int, long long int> > &a) {     sort(a.begin(), a.end());   }   void sorting(vector<long long int> &a) {     sort(a.begin(), a.end(), greater<long long int>());   }   void vec_in(vector<long long int> &a, long long int n) {     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       a.push_back(x);     }   }   void Graph_in(vector<vector<long long int> > &G, long long int n) {     long long int x, y;     for (long long int i = 0; i < n; i++) {       cin >> x >> y;       G[x].push_back(y);       G[y].push_back(x);     }   }   void lps_table(string &s, vector<long long int> &lps) {     long long int n = s.size();     long long int len = 0;     for (long long int i = 1; i < n; i++) {       while (s[i] != s[len] && len > 0) {         len = lps[len - 1];         if (len == 0 && s[len] != s[i]) {           lps[i] = 0;           len = 0;           break;         }       }       if (s[len] == s[i]) {         lps[i] = len + 1;         len++;       }       if (len == 0 && s[len] != s[i]) {         lps[i] = 0;         len = 0;       }     }   }   void traversal(long long int &x, long long int &y,                  vector<vector<long long int> > &a, long long int r,                  long long int c) {     if (x + 2 < r) {       if (y + 1 < c) {         if (a[x + 2][y + 1] == -1) {           long long int i = x + 2;           long long int j = y + 1;           a[i][j] = a[x][y] ^ 1;           traversal(i, j, a, r, c);         }       }       if (y - 1 < c && y - 1 >= 0) {         if (a[x + 2][y - 1] == -1) {           long long int i = x + 2;           long long int j = y - 1;           a[i][j] = a[x][y] ^ 1;           traversal(i, j, a, r, c);         }       }     }     if (x + 1 < r) {       if (y + 2 < c) {         if (a[x + 1][y + 2] == -1) {           long long int i = x + 1;           long long int j = y + 2;           a[i][j] = a[x][y] ^ 1;           traversal(i, j, a, r, c);         }       }       if (y - 2 < c && y - 2 >= 0) {         if (a[x + 1][y - 2] == -1) {           long long int i = x + 1;           long long int j = y - 2;           a[i][j] = a[x][y] ^ 1;           traversal(i, j, a, r, c);         }       }     }     if (x - 2 < r && x - 2 >= 0) {       if (y + 1 < c) {         if (a[x - 2][y + 1] == -1) {           long long int i = x - 2;           long long int j = y + 1;           a[i][j] = a[x][y] ^ 1;           traversal(i, j, a, r, c);         }       }       if (y - 1 < c && y - 1 >= 0) {         if (a[x - 2][y - 1] == -1) {           long long int i = x - 2;           long long int j = y - 1;           a[i][j] = a[x][y] ^ 1;           traversal(i, j, a, r, c);         }       }     }     if (x - 1 < r && x - 1 >= 0) {       if (y + 2 < c) {         if (a[x - 1][y + 2] == -1) {           long long int i = x - 1;           long long int j = y + 2;           a[i][j] = a[x][y] ^ 1;           traversal(i, j, a, r, c);         }       }       if (y - 2 < c && y - 2 >= 0) {         if (a[x - 1][y - 2] == -1) {           long long int i = x - 1;           long long int j = y - 2;           a[i][j] = a[x][y] ^ 1;           traversal(i, j, a, r, c);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int r, c;     cin >> r >> c;     if (r < c) {       swap(r, c);     }     vector<vector<long long int> > a(r, vector<long long int>(c, -1));     for (long long int i = 0; i < r; i++) {       for (long long int j = 0; j < c; j++) {         if (a[i][j] == -1) {           a[i][j] = 1;           traversal(i, j, a, r, c);         }       }     }     long long int one = 0;     for (long long int i = 0; i < r; i++) {       for (long long int j = 0; j < c; j++) {         if (a[i][j] == 1) {           one++;         }       }     }     cout << one <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     int a[n + 1];     for (int i = 1; i <= n; ++i) cin >> a[i];     int ans = 0;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       ans += min(a[u], a[v]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const double INF = 1e12, EPS = 1e-9;   int n;   pair<int, int> p[5000];   int main() {     cin >> n;     for (int i = 0; i < (int)n; i++) {       int a, b;       cin >> a >> b;       p[i] = pair<int, int>(a, b);     }     sort(p, p + n);     int mn = 0;     for (int i = 0; i < (int)n; i++) {       if (p[i].second >= mn)         mn = p[i].second;       else         mn = p[i].first;     }     cout << mn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     stack<char> s;     map<char, char> type = {{ ( ,  ) }, { { ,  } }, { < ,  > }, { [ ,  ] }};     int ans = 0;     for (auto it : str) {       if (it ==  {  || it ==  (  || it ==  <  || it ==  [ ) {         s.push(it);       } else {         if (s.empty()) {           cout <<  Impossible n ;           return 0;         } else {           if (type[s.top()] != it) {             ans += 1;           }           s.pop();         }       }     }     if (s.empty()) {       cout << ans <<   n ;       return 0;     }     cout <<  Impossible n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 10;   bool isp[maxn];   int _prime[maxn], lp = 0;   int _minCost[maxn];   void InitPrime() {     isp[0] = isp[1] = true;     for (int i = 4; i < maxn; i += 2) isp[i] = true;     for (int i = 3; i * i < maxn; i += 2)       if (!isp[i])         for (int j = i * i; j < maxn; j += i) isp[j] = true;     _prime[lp++] = 2;     for (int i = 3; i < maxn; i += 2)       if (!isp[i]) _prime[lp++] = i;   }   bool IsPrime(long long n) {     if (n < maxn) return !isp[n];     for (int i = 0; i < lp && (long long)_prime[i] * _prime[i] <= n; ++i) {       if (n % _prime[i] == 0) return false;     }     return true;   }   int minCost(long long n) {     if (IsPrime(n)) return 1;     for (int i = 0; i < lp && _prime[i] + 2 <= n; ++i) {       if (n - _prime[i] >= 2 && IsPrime(n - _prime[i])) return 2;     }     return 3;   }   int main() {     InitPrime();     long long n;     cin >> n;     cout << minCost(n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   const long double pi = acos(-1);   int N;   int A[300100];   long long S[300100];   int shouldCut[300100];   map<int, vector<int> > mymap;   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cout << fixed;     cout.tie(0);     cin.tie(0);     cin >> N;     for (int(i) = 1, j123 = N; (i) <= j123; (i)++) {       cin >> A[i];       S[i] = max(0, A[i]);       S[i] += S[i - 1];       mymap[A[i]].push_back(i);       v.push_back(A[i]);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     int mx = -2e9;     long long bestTot = -2e10;     int bestFirst = -1;     int bestLast = -1;     for (int(i) = 0, j123 = int(v.size()); (i) < j123; (i)++) {       if (int(mymap[v[i]].size()) > 1) {         sort(mymap[v[i]].begin(), mymap[v[i]].end());         int curfirst = mymap[v[i]].front();         int curlast = mymap[v[i]].back();         long long score = S[curlast - 1] - S[curfirst];         score += A[curfirst];         score += A[curlast];         if (score > bestTot) {           bestTot = score;           bestFirst = curfirst;           bestLast = curlast;         }       }     }     for (int i = 1; i < bestFirst; i++) shouldCut[i] = 1;     for (int i = N; i > bestLast; i--) shouldCut[i] = 1;     for (int i = bestFirst + 1; i <= bestLast - 1; i++)       if (A[i] < 0) shouldCut[i] = 1;     long long toteth = 0;     vector<int> vec;     for (int(i) = 1, j123 = N; (i) <= j123; (i)++) {       if (shouldCut[i])         vec.push_back(i);       else         toteth += A[i];     }     cout << toteth <<     << int(vec.size()) <<   n ;     for (int(i) = 0, j123 = int(vec.size()); (i) < j123; (i)++)       cout << vec[i] << (i + 1 < int(vec.size()) ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1999999999;   const double pi = acos(-1.0);   const double eps = 1e-9;   char gc() {     char c;     while (isspace(c = getchar()))       ;     return c;   }   int gs(char* s) {     if (!fgets(s, 9999999, stdin)) return -1;     int l = strlen(s);     while (l && isspace(s[l - 1])) s[--l] = 0;     return l;   }   int main() {     ios::sync_with_stdio(false);     cout << fixed << setprecision(15);     int n;     cin >> n;     vector<int> v;     for (int i = 0, _i = (n); i < (_i); i++) {       int t;       cin >> t;       v.push_back(t);     }     sort((v).begin(), (v).end());     v.erase(unique((v).begin(), (v).end()), v.end());     for (int i = 0, _i = (((int)(v).size()) - 1); i < (_i); i++) {       if (v[i] * 2 > v[i + 1]) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 24;   int n, m, a[N][N], f[1 << 20];   char str[N][N];   void work() {     int i, j, k, x;     scanf( %d%d , &n, &m);     for (i = 0; i < n; ++i) scanf( %s , str[i]);     for (i = 0; i < n; ++i)       for (j = 0; j < m; ++j) scanf( %d , &a[i][j]);     for (i = 1; i < 1 << n; ++i) {       x = __builtin_ctz(i & -i);       f[i] = 1 << 30;       for (j = 0; j < m; ++j) {         f[i] = min(f[i], f[i ^ (1 << x)] + a[x][j]);         int sum = 0, mx = 0, mask = 0;         for (k = 0; k < n; ++k) {           if (str[k][j] == str[x][j]) {             sum += a[k][j];             mx = max(mx, a[k][j]);             mask |= 1 << k;           }         }         f[i] = min(f[i], f[i & (i ^ mask)] + sum - mx);       }     }     cout << f[(1 << n) - 1] << endl;   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int pw(long long int a, long long int b, long long int mod) {     if (!b) return 1;     if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;     return pw(a * a % mod, b / 2, mod) % mod;   }   const long long int MAXN = 1e5 + 10;   const long long int MAXK = 1e4 + 10;   const long long int INF = 8e18;   const long long int MOD = 1e9 + 7;   long long int h, n, m, k, dist[MAXK], mark[MAXK], seen[MAXN];   pair<long long int, long long int> A[MAXN];   vector<pair<long long int, long long int>> adj[MAXK];   set<pair<long long int, long long int>> st;   priority_queue<pair<long long int, long long int>,                  vector<pair<long long int, long long int>>,                  greater<pair<long long int, long long int>>>       pq;   void Dijk() {     fill(dist, dist + MAXK, INF);     fill(mark, mark + MAXK, 0);     dist[0] = 0;     pq.push({0, 0});     while (!pq.empty()) {       long long int u = pq.top().second;       pq.pop();       if (mark[u]) continue;       mark[u] = 1;       for (pair<long long int, long long int>& e : adj[u]) {         if (dist[e.first] <= dist[u] + e.second) continue;         dist[e.first] = dist[u] + e.second;         pq.push({dist[e.first], e.first});       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> h >> n >> m >> k;     for (long long int i = 1; i <= n; i++) {       cin >> A[i].first >> A[i].second;       A[i].first--;       if (A[i].first % k == 0) {         st.insert({A[i].second, -i});         seen[i] = 1;       }     }     Dijk();     while (m--) {       long long int type;       cin >> type;       if (type == 1) {         long long int x;         cin >> x;         for (long long int i = 0; i < k; i++) {           adj[i].push_back({(i + x) % k, x});         }         Dijk();         for (long long int i = 1; i <= n; i++) {           if (!seen[i] && dist[A[i].first % k] <= A[i].first) {             seen[i] = 1;             st.insert({A[i].second, -i});           }         }       }       if (type == 2) {         long long int x, val;         cin >> x >> val;         if (seen[x]) st.erase({A[x].second, -x});         A[x].second -= val;         if (seen[x]) st.insert({A[x].second, -x});       }       if (type == 3) {         if (st.empty()) {           cout << 0 <<   n ;           continue;         }         auto it = st.end();         it--;         cout << (*it).first <<   n ;         st.erase(it);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     cin >> x;   }   template <typename T, typename T0>   void read(T &x, T0 &y) {     cin >> x >> y;   }   template <typename T, typename T0, typename T1>   void read(T &x, T0 &y, T1 &z) {     cin >> x >> y >> z;   }   bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }   int digits(int n) {     int x = floor(log10(n)) + 1;     return x;   }   long long int fact(long long int n) {     if (n == 0) return 1;     return n * fact(n - 1);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   vector<bool> sieve(1000000, true);   void sieve_er() {     sieve[0] = false;     sieve[1] = false;     for (long long int i = 2; i * i <= 1000000; i++) {       if (sieve[i] == true) {         for (long long int j = i * i; j < 1000000; j += i) sieve[j] = false;       }     }   }   vector<long long int> vec;   void divisors(long long int n) {     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           vec.push_back(i);         else {           vec.push_back(i);           vec.push_back(n / i);         }       }     }   }   long long int total_divisors(long long int n) {     long long int c = 0;     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           c = c + 1;         else           c = c + 2;       }     }     return c;   }   long long int nCr(long long int n, long long int r) {     long long int ans = 1;     for (long long int i = 0; i < r; i++) {       ans *= n - i;       ans /= i + 1;     }     return ans;   }   long long int power_m(long long int a, long long int b,                         long long int m = 1000000007) {     a %= m;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long int power(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int strTo(string s) {     stringstream tmp(s);     long long int x = 0;     tmp >> x;     return x;   }   string NoTo(long long int n) {     ostringstream str1;     str1 << n;     string ans = str1.str();     return ans;   }   void start() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       int ans = 0;       if (x1 == x2)         ans = abs(y1 - y2);       else if (y1 == y2)         ans = abs(x1 - x2);       else {         ans += abs(x1 - x2);         ans += 2;         ans += abs(y1 - y2);       }       cout << ans << endl;     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, k;     long long a, ans = 0;     map<long long, long long> mp;     scanf( %d %d %d , &n, &p, &k);     for (int i = 0; i < n; i++) {       scanf( %lld , &a);       ans += mp[((((a * a) % p) * ((a * a) % p)) % p - (k * a) % p + p) % p]++;     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   int abss(int a);   int main() {     int size;     scanf( %d , &size);     int colunm[size + 10][2];     int i;     int left = 0, right = 0;     for (i = 1; i <= size; i++) {       scanf( %d %d , &colunm[i][0], &colunm[i][1]);       left += colunm[i][0];       right += colunm[i][1];     }     int abs = abss(left - right);     int max = 0, temp, flag = 0;     for (i = 1; i <= size; i++) {       int tLeft = left;       int tRight = right;       tLeft = tLeft - colunm[i][0] + colunm[i][1];       tRight = tRight - colunm[i][1] + colunm[i][0];       int tAbs = abss(tLeft - tRight);       temp = tAbs - abs;       if (temp > max) {         max = temp;         flag = i;       }     }     printf( %d , flag);     return 0;   }   int abss(int a) {     if (a > 0)       return a;     else       return -a;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int num[500005];   long long dp[500005];   int cnt[500005];   bool ok(int cost) {     dp[0] = dp[1] = cnt[0] = cnt[1] = 0;     for (int i = (2); i <= (n); i += (1)) {       dp[i] = dp[i - 1];       cnt[i] = cnt[i - 1];       long long v = dp[i - 2] + num[i] - num[i - 1] - cost;       int c = cnt[i - 2] + 1;       if (v < dp[i] || v == dp[i] && c > cnt[i]) dp[i] = v, cnt[i] = c;     }     return (cnt[n] >= k);   }   int main() {     scanf( %d %d , &k, &n);     for (int i = (1); i <= (n); i += (1)) scanf( %d , &num[i]);     sort(num + 1, num + n + 1);     int l = 0, r = 1000000000;     while (l <= r) {       int m = (l + r) >> 1;       if (ok(m))         r = m - 1;       else         l = m + 1;     }     ok(l);     printf( %lld n , dp[n] + 1LL * l * k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = 0;     long long p = 1, q = 2, r, n;     cin >> n;     while (q <= n) {       ans++;       r = q;       q = p + q;       p = r;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 8;   const int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};   const int dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};   string a[N];   int v[105][N][N], f[105][N][N];   int main() {     for (int i = 0; i < N; ++i) cin >> a[i];     memset(v, 0, sizeof(v));     for (int i = 0; i < N; ++i)       for (int j = 0; j < N; ++j)         if (a[i][j] ==  S )           for (int k = i + 1; k <= N; ++k)             v[k - i][k][j] = v[k - i][k - 1][j] = 1;     memset(f, 0, sizeof(f));     f[0][7][0] = 1;     for (int t = 1; t <= 100; ++t)       for (int x = 0; x < N; ++x)         for (int y = 0; y < N; ++y)           if (f[t - 1][x][y])             for (int dire = 0; dire < 9; ++dire) {               int xx = x + dx[dire];               int yy = y + dy[dire];               if (xx < 0 || xx >= N) continue;               if (yy < 0 || yy >= N) continue;               if (v[t][xx][yy]) continue;               f[t][xx][yy] = 1;             }     bool flag = 0;     for (int t = 1; t <= 100; ++t) flag |= f[t][0][7];     if (flag)       cout <<  WIN ;     else       cout <<  LOSE ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> p(n);     for (int i = 0; i < n; ++i) {       cin >> p[i];     }     vector<int> f(n + 1, 0);     for (int& x : p) {       f[x] = f[x - 1] + 1;     }     cout << n - *max_element(f.begin(), f.end());   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, h, l = 0, c = 0, a = 0, b = 0, d;     cin >> n >> h;     while (n--) {       cin >> d;       c += d;       if (c > a)         a = c;       else if (c < b)         b = c;     }     l -= b;     h -= a;     d = h - l + 1;     if (d < 0) d = 0;     cout << d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double PI = acos(-1.0);   const long long int mod = 1e9 + 9;   const int MAXN = 1e6 + 5;   long long int fpow(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res % mod * x % mod) % mod;       x = (x % mod * x % mod) % mod;       y = y / 2;     }     return res;   }   void cp() {     int n, m;     cin >> n >> m;     long long int total = (fpow(2, m) - 1 + mod) % mod;     long long int ans = 1;     for (int i = 0; i < n; i++) {       long long int me = me = (total - i + mod) % mod;       ans = (ans % mod * me % mod) % mod;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       cp();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, m, x = 0, n, a[1000], j;   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) {       m = 1;       for (j = i - 1; j >= 0; j--)         if (a[j] <= a[j + 1])           ++m;         else           break;       for (j = i + 1; j < n; j++)         if (a[j] <= a[j - 1])           ++m;         else           break;       x = max(x, m);     }     cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double ans = 0;   void calc(vector<int> arr, int d, double p) {     if (d == 0) {       int tmp = 0;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < i; ++j) {           if (arr[j] > arr[i]) {             tmp++;           }         }       }       ans += double(tmp) * p;       return;     }     for (int i = 0; i < n; ++i) {       for (int j = i; j < n; ++j) {         vector<int> xxx = arr;         reverse(xxx.begin() + min(i, j), xxx.begin() + max(i, j) + 1);         calc(xxx, d - 1, p / (n * (n + 1) / 2));       }     }   }   int main() {     int dep;     cin >> n >> dep;     vector<int> vec(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &vec[i]);     }     calc(vec, dep, 1);     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, p, i, j, val, sum = 0, ans = 0;     scanf( %lld %lld , &n, &p);     long long int a[n];     for (i = 0; i < n; i++) {       scanf( %lld , &a[i]);       sum += a[i];     }     sum %= p;     val = 0;     for (i = 0; i < n - 1; i++) {       val += a[i];       val %= p;       if (sum - val >= 0) {         if (sum > ans) ans = sum;       } else {         ans = sum + p;         break;       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize ( O3 )   #pragma GCC optimize ( Ofast )   using namespace std;      #define int int64_t   #define SQ(a) (a)*(a)      const int INF = 1e15;      int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);        int n, m;     cin >> n >> m;        vector<vector<pair<int, int>>> g(n);     for (int i = 0, a, b, c; i < m; i++) {       cin >> a >> b >> c;       a--, b--;       g[a].push_back({b, c});       g[b].push_back({a, c});     }        vector<int> deven(n, INF);     vector<vector<int>> dodd(51, vector<int> (n, INF));        deven[0] = 0;     priority_queue<array<int, 3>> Q; // {dist, v, (-1 OR w_last)}     Q.push({0, 0, -1});        vector<vector<bool>> vis(52, vector<bool> (n));     while (!Q.empty()) {       int d = -Q.top()[0];       int v =  Q.top()[1];       int lw=  Q.top()[2];       Q.pop();          if (vis[lw + 1][v])         continue;       vis[lw + 1][v] = true;          if (lw == -1) { // even steps         for (auto [u, w] : g[v]) {           if (dodd[w][u] > d) {             dodd[w][u] = d;             Q.push({-d, u, w});           }         }       } else {         for (auto [u, w] : g[v]) {           if (deven[u] > d + SQ(lw + w)) {             deven[u] = d + SQ(lw + w);             Q.push({-deven[u], u, -1});           }         }       }     }        for (int i = 0; i < n; i++)       cout << (deven[i] == INF ? -1 : deven[i]) <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     int n;     cin >> n;     int a[n];     int b[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     long long mx = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         long long an = 0;         long long bn = 0;         for (int t = i; t <= j; t++) {           an = an | a[t];           bn = bn | b[t];         }         if (an + bn > mx) {           mx = an + bn;         }       }     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int N = 1e5 + 5;   long long a[N], b[N];   long long n, h;   bool cmp(int a, int b) { return a > b; }   long long judge(int index) {     for (int i = 0; i <= index; i++) {       b[i] = a[i];     }     sort(b, b + index + 1, cmp);     long long sum;     if (index % 2 == 0)       sum = b[index], index--;     else       sum = 0;     for (int i = 0; i <= index; i += 2) {       sum += b[i];     }     if (sum <= h)       return 1;     else       return 0;   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n >> h;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int l = 0, r = n - 1;     long long res;     while (l <= r) {       int mid = (l + r) / 2;       if (judge(mid)) {         l = mid + 1;         res = mid;       } else {         r = mid - 1;       }     }     cout << res + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed long long int a[100000 + 5], b[100000 + 5];   int n, m;   signed long long int func(signed long long int x) {     signed long long int ans = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] < x) ans += x - a[i];     }     for (int i = 1; i <= m; ++i) {       if (x < b[i]) ans += b[i] - x;     }     return ans;   }   signed long long int ter(signed long long int i, signed long long int j) {     if (i == j) return i;     if (j - i == 2) {       signed long long int mi = j - 1;       if (func(mi) < func(i) && func(mi) < func(j)) return mi;       if (func(i) < func(j) && func(i) < func(mi)) return i;       return j;     }     signed long long int l, r;     l = i + (j - i) / 3;     r = j - (j - i) / 3;     if (func(l) > func(r))       return ter(l, j);     else       return ter(i, r);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= m; ++i) cin >> b[i];     cout << func(ter(0, 2 * 1000000007 + 1));   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[120000];   void query(int L, int R) {     int M = (L + R) / 2;     printf( ? %d n , M);     fflush(stdout);     printf( ? %d n , n / 2 + M);     fflush(stdout);     scanf( %d %d , a + M, a + M + n / 2);     if (a[M] == a[n / 2 + M]) {       printf( ! %d n , M);       fflush(stdout);       return;     }     if (((a[M + n / 2] - a[M]) < 0) ^ ((a[L + n / 2] - a[L]) < 0))       query(L, M);     else       query(M, R);   }   int main() {     scanf( %d , &n);     if (n % 4) {       printf( ! -1 n );       fflush(stdout);       return 0;     }     printf( ? 1 n );     fflush(stdout);     printf( ? %d n , n / 2 + 1);     fflush(stdout);     scanf( %d %d , a + 1, a + n / 2 + 1);     if (a[1] == a[n / 2 + 1]) {       printf( ! %d n , 1);       fflush(stdout);       return 0;     }     printf( ? %d n , n / 2);     fflush(stdout);     printf( ? %d n , n);     fflush(stdout);     scanf( %d %d , a + n / 2, a + n);     if (a[n / 2] == a[n]) {       printf( ! %d n , n / 2);       fflush(stdout);       return 0;     }     query(1, n / 2);   }


#include <bits/stdc++.h>   using namespace std;   long long readi() {     long long input = 0;     char c =    ;     while (c <  - ) {       c = getchar();     }     bool negative = false;     if (c ==  - ) {       negative = true;       c = getchar();     }     while (c >=  0 ) {       input = 10 * input + (c -  0 );       c = getchar();     }     if (negative) {       input = -input;     }     return input;   }   void printi(long long output) {     if (output == 0) {       putchar( 0 );       return;     }     if (output < 0) {       putchar( - );       output = -output;     }     int aout[20];     int ilen = 0;     while (output) {       aout[ilen] = ((output % 10));       output /= 10;       ilen++;     }     for (int i = ilen - 1; i >= 0; i--) {       putchar(aout[i] +  0 );     }     return;   }   string reads() {     string input =   ;     char c =    ;     while (c <=    ) {       c = getchar();     }     while (c >    ) {       input += c;       c = getchar();     }     return input;   }   void prints(string output) {     for (int i = 0; i < output.length(); i++) {       putchar(output[i]);     }     return;   }   long long getrand() {     long long rand1 = (rand() % 536870912);     long long rand2 = (rand() % 536870912);     return (rand1 * 536870912ll + rand2);   }   int N;   long long arr[5][1010];   bool bad[1010];   int ans;   long long scalar(long long a, long long b, long long c) {     long long res = 0ll;     for (long long i = 0; i < 5; i++) {       res += ((arr[i][b] - arr[i][a]) * (arr[i][c] - arr[i][a]));     }     return res;   }   int32_t main() {     srand(time(NULL));     cout << fixed << setprecision(10);     cerr << fixed << setprecision(10);     ios_base::sync_with_stdio(false);     if (fopen( cf850a.in ,  r )) {       freopen( cf850a.in ,  r , stdin);     }     cin >> N;     for (int i = 0; i < N; i++) {       for (int j = 0; j < 5; j++) {         cin >> arr[j][i];       }     }     if (N >= 100) {       cout <<  0 n ;       return 0;     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         if (j == i) {           continue;         }         for (int k = j + 1; k < N; k++) {           if (k == i) {             continue;           }           if (scalar(i, j, k) > 0) {             bad[i] = true;           }         }       }     }     for (int i = 0; i < N; i++) {       if (!bad[i]) {         ans++;       }     }     cout << ans <<   n ;     for (int i = 0; i < N; i++) {       if (!bad[i]) {         cout << i + 1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   void mergesort(char z[], int left, int right) {     char temp[1000];     if (left >= right) {       return;     }     int mid = (left + right) / 2;     mergesort(z, left, mid);     mergesort(z, mid + 1, right);     int lenl = mid;     int lenr = right;     int i = left, j = mid + 1, k = left;     while (i <= lenl && j <= lenr) {       if (z[i] >= z[j]) {         temp[k] = z[i];         k++;         i++;       } else {         temp[k] = z[j];         k++;         j++;       }     }     while (i <= lenl) {       temp[k] = z[i];       k++;       i++;     }     while (j <= lenr) {       temp[k] = z[j];       k++;       j++;     }     for (int i = left; i <= right; i++) {       z[i] = temp[i];     }   }   int main() {     int a, b, c, d, e, f, g, h;     char z[1000];     scanf( %d , &a);     getchar();     for (int i = 0; i < a; i++) {       scanf( %s , z);       getchar();       b = strlen(z);       mergesort(z, 0, b - 1);       if (b == 1) {         printf( YES n );       } else {         for (int j = 0; j < b - 1; j++) {           if ((z[j] - z[j + 1]) == 1) {           } else {             printf( NO n );             break;           }           if (j == b - 2) {             printf( YES n );           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string s;   vector<int> q;   int mo[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int h, w;   int data(int x, int y) {     int tmp = 0;     for (int i = 0; i < x - 1; i++) tmp += mo[i];     return tmp + y;   }   int cal(int x, int y, int z) { return x * 60 * 60 + y * 60 + z; }   int getpos(string s) {     int p = data((s[5] -  0 ) * 10 + s[6] -  0 , (s[8] -  0 ) * 10 + s[9] -  0 );     int res = (p - 1) * 24 * 60 * 60;     res += cal((s[11] -  0 ) * 10 + s[12] -  0 , (s[14] -  0 ) * 10 + s[15] -  0 ,                (s[17] -  0 ) * 10 + s[18] -  0 );     return res;   }   int main() {     cin >> n >> m;     h = 0;     getline(cin, s);     while (getline(cin, s)) {       int t = getpos(s);       q.push_back(t);       while (h < q.size() && t - q[h] >= n) h++;       if (q.size() - h >= m) {         for (int i = 0; i <= 18; i++) cout << s[i];         cout << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   template <typename _Tp>   void read(_Tp &x) {     char ch(getchar());     bool f(false);     while (!isdigit(ch)) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();     if (f) x = -x;   }   template <typename _Tp, typename... Args>   void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   const int N = 100005, mod = 1000000007;   template <typename _Tp1, typename _Tp2>   inline void add(_Tp1 &a, _Tp2 b) {     (a += b) >= mod && (a -= mod);   }   template <typename _Tp1, typename _Tp2>   inline void sub(_Tp1 &a, _Tp2 b) {     (a -= b) < 0 && (a += mod);   }   long long ksm(long long a, long long b = mod - 2) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod, b >>= 1;     }     return res;   }   long long fac[N], inv[N], ifac[N];   void init() {     fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;     for (int i = 2; i < N; ++i)       fac[i] = fac[i - 1] * i % mod,       inv[i] = inv[mod % i] * (mod - mod / i) % mod,       ifac[i] = ifac[i - 1] * inv[i] % mod;   }   inline long long C(int n, int m) {     return n < m || m < 0 ? 0 : fac[n] * ifac[m] % mod * ifac[n - m] % mod;   }   int f[N];   std::map<int, int> mp;   int cnt[N], pw[N];   int main() {     init();     int n, k;     read(n, k);     for (int i = 0; i <= n; ++i) pw[i] = ksm(k - 1, i);     f[0] = 0;     for (int i = 0; i < n; ++i)       f[i + 1] = (1LL * (k - 1) * i % mod * f[i] % mod + 1) * inv[n - i] % mod;     for (int i = 1; i <= n; ++i) add(f[i], f[i - 1]);     int a = 0, s = 0;     for (int i = 1, x; i <= n; ++i) {       read(x);       if (x != -1)         ++mp[x];       else         ++a;     }     for (auto it : mp) ++cnt[it.second];     cnt[0] += k - mp.size();     for (int i = 0; i <= n; ++i)       if (cnt[i]) {         int tmp = 0;         for (int j = 0; j <= a; ++j)           add(tmp, 1LL * f[i + j] * C(a, j) % mod * pw[a - j] % mod);         add(s, 1LL * tmp * cnt[i] % mod);       }     s = ksm(k, mod - 1 - a) * s % mod;     printf( %lld n , 1LL * (f[n] - s + mod) * n % mod);     return 0;   }


/*   Author: QAQAutoMaton   Lang: C++   Code: C.cpp   Mail: lk@qaq-am.com   Blog: https://www.qaq-am.com/   */   #include<bits/stdc++.h>   #define debug(...) fprintf(stderr,__VA_ARGS__)   #define DEBUG printf( Passing [%s] in LINE %d n ,__FUNCTION__,__LINE__)   #define Debug debug( Passing [%s] in LINE %d n ,__FUNCTION__,__LINE__)   #define all(x) x.begin(),x.end()   #define x first   #define y second   using namespace std;   typedef unsigned uint;   typedef long long ll;   typedef unsigned long long ull;   typedef complex<double> cp;   typedef pair<int,int> pii;   int inf;   const double eps=1e-8;   const double pi=acos(-1.0);   template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;}   template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;}   template<class T>T sqr(T a){return a*a;}   template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;}   template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;}   template<class T>T aabs(T a){return a<0?-a:a;}   template<class T>int dcmp(T a,T b){return a>b;}   template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}   template<class T>bool sort2(T &a,T &b){return a>b?swap(a,b),1:0;}   #define min mmin   #define max mmax   #define abs aabs   struct __INIT__{    __INIT__(){     fill((unsigned char*)&inf,(unsigned char*)&inf+sizeof(inf),0x3f);    }   }__INIT___;   namespace io {    const int SIZE = (1 << 21) + 1;    char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;    // getchar    #define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)    // print the remaining part    inline void flush () {     fwrite (obuf, 1, oS - obuf, stdout);     oS = obuf;    }    // putchar    inline void putc (char x) {     *oS ++ = x;     if (oS == oT) flush ();    }    template<typename A>    inline bool read (A &x) {     for (f = 1, c = gc(); c <  0  || c >  9 ; c = gc()) if (c ==  - ) f = -1;else if(c==EOF)return 0;     for (x = 0; c <=  9  && c >=  0 ; c = gc()) x = x * 10 + (c & 15); x *= f;     return 1;    }    inline bool read (char &x) {     while((x=gc())==   ||x==  n  || x==  r );     return x!=EOF;    }    inline bool read(char *x){     while((*x=gc())==  n  || *x==   ||*x==  r );     if(*x==EOF)return 0;     while(!(*x==  n ||*x==   ||*x==  r ||*x==EOF))*(++x)=gc();     *x=0;     return 1;    }    template<typename A,typename ...B>    inline bool read(A &x,B &...y){     return read(x)&&read(y...);    }    template<typename A>    inline bool write (A x) {     if (!x) putc ( 0 ); if (x < 0) putc ( - ), x = -x;     while (x) qu[++ qr] = x % 10 +  0 ,  x /= 10;     while (qr) putc (qu[qr --]);     return 0;    }    inline bool write (char x) {     putc(x);     return 0;    }    inline bool write(const char *x){     while(*x){putc(*x);++x;}     return 0;    }    inline bool write(char *x){     while(*x){putc(*x);++x;}     return 0;    }    template<typename A,typename ...B>    inline bool write(A x,B ...y){     return write(x)||write(y...);    }    //no need to call flush at the end manually!    struct Flusher_ {~Flusher_(){flush();}}io_flusher_;   }   using io :: read;   using io :: putc;   using io :: write;   char s[100005];   int p[1005],q[1005],rp[1005];   int t1,t2,t3,t4,t5,t6;   int a[1005][1005],b[1005][1005];   int v[4];   signed main(){   #ifdef QAQAutoMaton     freopen( C.in , r ,stdin);    freopen( C.out , w ,stdout);   #endif    int t;    read(t);    for(;t;--t){     int n,m;     read(n,m);     for(int i=0;i<n;++i)for(int j=0;j<n;++j){      read(a[i][j]);      --a[i][j];     }     read(s+1);     pii x={1,0},y={2,0},z={3,0};     for(int i=1;i<=m;++i){      switch(s[i]){       case  R :++y.y;break;       case  L :--y.y;break;       case  D :++x.y;break;       case  U :--x.y;break;       case  I :swap(y,z);break;       case  C :swap(x,z);break;      }     }     ((x.y%=n)+=n)%=n;     ((y.y%=n)+=n)%=n;     ((z.y%=n)+=n)%=n;     for(int i=0;i<n;++i){      for(int j=0;j<n;++j){       v[1]=i;v[2]=j;v[3]=a[i][j];       b[(v[x.x]+x.y)%n][(v[y.x]+y.y)%n]=(v[z.x]+z.y)%n;      }     }     for(int i=0;i<n;++i)for(int j=0;j<n;++j)write(b[i][j]+1,j==n-1?  n :   );     putc(  n );    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, bx, x;     long long X = 0;     cin >> n >> bx;     for (int i = 1; i <= n; i++) {       cin >> x;       X += x * pow(bx, n - i);     }     int m, by, y;     long long Y = 0;     cin >> m >> by;     for (int i = 1; i <= m; i++) {       cin >> y;       Y += y * pow(by, m - i);     }     if (X == Y) {       cout <<  = ;       return 0;     }     if (X > Y) {       cout <<  > ;       return 0;     }     cout <<  < ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x;     cin >> x;     while (x--) {       string str;       cin >> str;       long long n, b, m, v, finl, finl2;       finl2 = 0;       v = 0;       b = 0;       m = 0;       v = 0;       for (n = 0; n < str.size(); n++) {         finl = (int)str[n] - 48;         if (finl == 0)           b++;         else if (finl % 2 == 0)           m++;         finl2 = finl + finl2;       }       if (finl2 % 3 == 0) v = 1;       if (b >= 2 && v == 1 || b >= 1 && m >= 1 && v == 1)         cout <<  red ;       else         cout <<  cyan ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, si, mi, t;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t;       if (t == 1) {         si = i;       }       if (t == n) {         mi = i;       }     }     if (si < mi) {       cout << max(mi, n - 1 - si);     } else {       cout << max(si, n - 1 - mi);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50005;   long long num[maxn];   int main() {     long long sum = 0, ans = 0;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) cin >> num[i], sum += num[i];     if (n == 0) {       cout <<  0  << endl;       return 0;     }     sum = sum / n;     for (int i = 0; i < n - 1; i++) {       if (num[i] < sum) {         ans += sum - num[i];         num[i + 1] -= (sum - num[i]);       } else if (num[i] > sum) {         ans += num[i] - sum;         num[i + 1] += num[i] - sum;       }       num[i] = sum;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void mohammed() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   int main() {     mohammed();     int n, x, y;     map<int, int> mp;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       mp[x]++;       mp[y + 1]--;     }     x = 0;     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       it->second += x;       if (it->second > 2) return cout <<  NO n , 0;       x = it->second;     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = (int)2e5 + 7;   long long dp[MAX_N];   long long num[MAX_N][2];   long long dist[MAX_N][2];   vector<int> a[MAX_N];   long long ans = 0;   void go(int v, int pr = -1) {     ++num[v][0];     for (int to : a[v]) {       if (to == pr) continue;       go(to, v);       for (int i = 0; i < 2; ++i)         for (int j = 0; j < 2; ++j) {           ans += dist[v][i] * num[to][j] + dist[to][j] * num[v][i];           if (!i && !j) {             ans += num[to][j] * num[v][i];           }         }       num[v][0] += num[to][1];       dist[v][0] += dist[to][1];       num[v][1] += num[to][0];       dist[v][1] += dist[to][0] + num[to][0];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       a[x].push_back(y);       a[y].push_back(x);     }     go(0);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxlongint = 2147483647;   const int inf = 1000000000;   int main() {     int a, b, c, d, e, f, ans = 0, k = -1, n1, n2;     cin >> a >> b >> c >> d >> e >> f;     ans = a * b + c * d + e * f;     for (n1 = 1; n1 <= 1000; n1++)       if (n1 * n1 == ans) {         k = n1;         break;       }     if (k == -1) {       cout << -1 << endl;       return 0;     }     if (b == k) swap(a, b);     if (d == k) swap(c, d);     if (f == k) swap(e, f);     if (a == k && c == k && e == k) {       cout << k << endl;       for (n1 = 1; n1 <= b; n1++) {         for (n2 = 1; n2 <= k; n2++) putchar( A );         printf(  n );       }       for (n1 = 1; n1 <= d; n1++) {         for (n2 = 1; n2 <= k; n2++) putchar( B );         printf(  n );       }       for (n1 = 1; n1 <= f; n1++) {         for (n2 = 1; n2 <= k; n2++) putchar( C );         printf(  n );       }       return 0;     }     int sd = 0;     if (c == k) {       sd = 1;       swap(a, c);       swap(b, d);     } else if (e == k) {       sd = 2;       swap(a, e);       swap(b, f);     }     if (a != k) {       cout << -1 << endl;       return 0;     }     if (d == k - b) swap(c, d);     if (f == k - b) swap(e, f);     if (c != k - b || e != k - b) {       cout << -1 << endl;       return 0;     }     {       cout << k << endl;       for (n1 = 1; n1 <= b; n1++) {         for (n2 = 1; n2 <= k; n2++) putchar( A  + sd);         printf(  n );       }       for (n1 = 1; n1 <= k - b; n1++) {         if (sd != 1)           for (n2 = 1; n2 <= d; n2++) putchar( B );         else           for (n2 = 1; n2 <= d; n2++) putchar( A );         if (sd != 2)           for (n2 = 1; n2 <= f; n2++) putchar( C );         else           for (n2 = 1; n2 <= f; n2++) putchar( A );         printf(  n );       }       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     multiset<int> list;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < n; i++) {       int x;       cin >> x;       list.insert(x);     }     for (int i = 0; i < n; ++i) {       auto current = list.lower_bound(n - v[i]);       if (current == list.end()) {         current = list.begin();       }       cout << (v[i] + *current) % n <<    ;       list.erase(current);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   struct edge {     int u, v;     int adj(int x) { return u + v - x; }   };   int n, c[N];   vector<int> adj[N];   vector<edge> e;   int lvl[N], pre[N], root;   vector<int> cycle;   void dfs1(int u) {     for (auto ind : adj[u])       if (ind != pre[u]) {         auto ei = e[ind];         int v = ei.adj(u);         if (lvl[v]) {           if ((lvl[u] + lvl[v]) % 2 == 0 && cycle.empty()) {             for (int w = u; w != v; w = e[pre[w]].adj(w)) cycle.push_back(pre[w]);             reverse((cycle).begin(), (cycle).end());             cycle.push_back(ind);             root = v;           }         } else {           lvl[v] = lvl[u] + 1;           pre[v] = ind;           dfs1(v);         }       }   }   long long int ans[N];   bool vis[N];   long long int dfs2(int u, int pre) {     if (vis[u]) return 0;     vis[u] = 1;     long long int sum = 0;     for (auto ind : adj[u])       if (ind != pre) {         int v = e[ind].adj(u);         sum += dfs2(v, ind);       }     if (pre != -1) ans[pre] = c[u] - sum;     return c[u] - sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int m;     cin >> n >> m;     for (int i = 0; i < (int)(n); i++) cin >> c[i];     e.resize(m);     for (int i = 0; i < (int)(m); i++) {       cin >> e[i].u >> e[i].v;       e[i].u--;       e[i].v--;       adj[e[i].u].push_back(i);       adj[e[i].v].push_back(i);     }     bool ok = 1;     for (int u = 0; u < (int)(n); u++)       if (!lvl[u]) {         cycle.clear();         lvl[u] = 1;         pre[u] = -1;         dfs1(u);         if (cycle.empty()) {           ok &= dfs2(u, -1) == 0;         } else {           auto delta = dfs2(root, -1) / 2;           for (auto ind : cycle) {             ans[ind] += delta;             delta = -delta;           }         }       }     if (ok) {       cout <<  YES n ;       for (int i = 0; i < (int)(m); i++) cout << ans[i] <<   n ;     } else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cout << setprecision(10);     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 1) {         cout <<  HARD n ;         return 0;       }     }     cout <<  EASY n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 41, K = 11;   bitset<40> a[N];   vector<int> steps[K];   int n, k;   bool ok = true;   void go(int pos, bitset<40> is_one, bitset<40> is_question) {     if (pos == k) {       if (is_question != 0) {         ok = false;         return;       }       int ones = is_one.count();       if (is_one != a[ones]) {         ok = false;         return;       }       return;     }     int ones = 0, zeros = 0, questions = 0;     for (int i : steps[pos]) {       if (is_question[i]) {         questions++;       } else if (is_one[i]) {         ones++;       } else {         zeros++;       }       is_question[i] = 0;       is_one[i] = 1;     }     for (int i = 0; i < zeros; i++) {       is_one[steps[pos][i]] = 0;     }     go(pos + 1, is_one, is_question);     for (int i = zeros; i < questions + zeros; i++) {       is_one[steps[pos][i]] = 0;       go(pos + 1, is_one, is_question);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int _ = 1;     while (_--) {       cin >> n >> k;       for (int i = 0; i <= n; i++) {         a[i] = 0;         for (int j = 0; j < i; j++) {           a[i][n - j - 1] = 1;         }       }       for (int i = 0; i < k; i++) {         int q;         cin >> q;         while (q--) {           int x;           cin >> x;           steps[i].push_back(--x);         }       }       bitset<40> is_one = 0;       bitset<40> is_question = (1ll << n) - 1;       go(0, is_one, is_question);       cout << (n == 1 || ok ?  ACCEPTED  :  REJECTED ) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long xmax, ymax, sx, sy, i, j;     cin >> xmax >> ymax >> sx >> sy;     cout << sx <<     << sy << endl;     for (i = sx - 1; i >= 1; i--) cout << i <<     << sy << endl;     i++;     for (j = sy + 1; j <= ymax; j++) cout << i <<     << j << endl;     j--;     for (j = sy - 1; j >= 1; j--) cout << i <<     << j << endl;     j++;     for (i = 2; i <= xmax; i++) {       if (i % 2 == 0) {         for (j = 1; j <= ymax; j++) {           if (i <= sx && j == sy)             continue;           else             cout << i <<     << j << endl;         }         j--;       } else {         for (j = ymax; j >= 1; j--) {           if (i <= sx && j == sy)             continue;           else             cout << i <<     << j << endl;         }         j++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, m, n, x, y;   set<long long> a, b;   int main() {     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> x >> y;       a.insert(x);       b.insert(y);       cout << (n - a.size()) * (n - b.size()) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int MAX = 1000007;   int n;   long long a, b;   vector<int> primes(int x) {     vector<int> p;     for (int i = 2; i * i <= x; ++i)       if (x % i == 0) {         p.push_back(i);         while (x % i == 0) {           x /= i;         }       }     if (x != 1) p.push_back(x);     return p;   }   long long dp[MAX][3];   long long solve(vector<int> c) {     vector<int> p = primes(c[0]);     vector<int> p1 = primes(c[0] - 1);     for (int i = (0); i < (p1.size()); i++) p.push_back(p1[i]);     p1 = primes(c[0] + 1);     for (int i = (0); i < (p1.size()); i++) p.push_back(p1[i]);     p1 = primes(c.back());     for (int i = (0); i < (p1.size()); i++) p.push_back(p1[i]);     p1 = primes(c.back() + 1);     for (int i = (0); i < (p1.size()); i++) p.push_back(p1[i]);     p1 = primes(c.back() - 1);     for (int i = (0); i < (p1.size()); i++) p.push_back(p1[i]);     sort(p.begin(), p.end());     p.resize(unique(p.begin(), p.end()) - p.begin());     long long res = 1LL * INF * INF;     for (int t = (0); t < (p.size()); t++) {       int pr = p[t];       dp[0][0] = dp[0][1] = dp[0][2] = 0;       for (int i = (0); i < (n); i++) {         int val = min(c[i] % pr, pr - c[i] % pr);         dp[i + 1][0] = dp[i + 1][1] = dp[i + 1][2] = 1LL * INF * INF;         if (val <= 1) {           dp[i + 1][2] = min(dp[i][2] + a * val,                              min(dp[i][1] + a * val, dp[i][0] + a * val));         }         dp[i + 1][1] = min(dp[i][0], dp[i][1]) + b;         if (val <= 1) {           dp[i + 1][0] = dp[i][0] + a * val;         }       }       long long r = min(dp[n][2], min(dp[n][1], dp[n][0]));       res = min(res, r);     }     return res;   }   int main() {     cin >> n >> a >> b;     swap(a, b);     vector<int> c(n);     for (int i = (0); i < (n); i++) {       scanf( %d , &c[i]);     }     long long res = solve(c);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[100][40];   char b[100][40];   int at[1445], use[100], ok[100], idx[100], pos[100], sum[100], cnt;   int dp[43205], ans_dd, ans_hh, ans_mm;   int pt[43205][100];   void run_to(int t) {     while (1) {       int next_dd = ans_dd;       int next_hh = ans_hh;       int next_mm = ans_mm;       if (++next_mm == 60) {         next_mm = 0;         if (++next_hh == 24) {           next_hh = 0;           next_dd++;         }       }       if ((next_dd - 1) * cnt + at[next_hh * 60 + next_mm] >= t) break;       ans_dd = next_dd;       ans_hh = next_hh;       ans_mm = next_mm;     }   }   void output(int t, int i, int cnt) {     if (~i) {       int x = pt[t][i];       if (~x) {         output(t - use[idx[x]], i - 1, cnt + 1);         run_to(t - use[idx[x]] + 1);         printf( %d %d %02d:%02d , x + 1, ans_dd, ans_hh, ans_mm);         run_to(t);         printf(  %d %02d:%02d n , ans_dd, ans_hh, ans_mm);       } else {         output(t, i - 1, cnt);       }     } else {       printf( %d n , cnt);     }   }   int main() {     int m, n, all, hh, mm;     scanf( %d%d%d , &m, &n, &all);     for (int i = 0; i < m; i++) scanf( %s , a[i]);     for (int i = 0; i < m; i++) scanf( %d , use + i);     for (int i = 0; i < 4; i++) {       scanf( %d:%d- , &hh, &mm);       int st = hh * 60 + mm;       scanf( %d:%d , &hh, &mm);       int ed = hh * 60 + mm;       for (int x = st; x <= ed; x++) at[x] = -1;     }     for (int x = 0; x < 1440; x++)       if (~at[x]) at[x] = cnt++;     all *= at[1440] = cnt;     for (int x = 1439; ~x; x--)       if (at[x] < 0) at[x] = at[x + 1];     for (int i = 0; i < n; i++) {       scanf( %s , b[i]);       for (idx[i] = 0; idx[i] < m; idx[i]++)         if (!strcmp(b[i], a[idx[i]])) break;       if (idx[i] != m) ok[i] = 1;       scanf( %d%d:%d%d , pos + i, &hh, &mm, sum + i);       pos[i] = (pos[i] - 1) * cnt + at[hh * 60 + mm];     }     for (int i = 0; i < n; i++) {       int k = -1;       for (int j = 0; j < n; j++)         if (ok[j] && (k < 0 || pos[j] < pos[k])) k = j;       for (int x = all; ~x; x--) pt[x][i] = -1;       for (int x = all; ~x; x--) {         int t = x + use[idx[k]];         if (t <= pos[k] && sum[k] + dp[x] > dp[t]) {           dp[t] = sum[k] + dp[x];           pt[t][i] = k;         }       }       ok[k] = 0;     }     int x = max_element(dp, dp + all + 1) - dp;     printf( %d n , dp[x]);     output(x, n - 1, 0);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long INF = 2e18;   const int N = 11234;   int n, m;   set<string> st;   char s[N];   int dp[N][4];   void dfs(int pos, string pre, int len) {     if (pos - 1 < 5) return;     if (dp[pos][len]) return;     dp[pos][len] = 1;     string str =   ;     for (int i = 1; i >= 0; --i) str += s[pos - i];     if (str != pre) {       st.insert(str);       dfs(pos - 2, str, 2);     }     if (pos - 2 >= 5) {       str =   ;       for (int i = 2; i >= 0; --i) str += s[pos - i];       if (str != pre) {         st.insert(str);         dfs(pos - 3, str, 3);       }     }   }   int main() {     while (scanf( %s , s) != EOF) {       int i, j;       memset(dp, 0, sizeof(dp));       st.clear();       n = strlen(s);       if (n < 5)         puts( 0 );       else {         dfs(n - 1,   , 0);         printf( %d n , st.size());         set<string>::iterator it = st.begin();         for (; it != st.end(); ++it) {           cout << *it << endl;         }       }     }   }


#include <bits/stdc++.h>   template <class C, class E>   inline bool contains(const C &container, const E &element) {     return container.find(element) != container.end();   }   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   using namespace std;   class UnionFind {    public:     UnionFind(int elements) : _subsets(elements), _setCount(elements) {       for (int i = 0; i < elements; ++i) {         _subsets[i].parent = i;         _subsets[i].rank = 0;       }     }     int Find(int i) {       if (_subsets[i].parent != i) _subsets[i].parent = Find(_subsets[i].parent);       return _subsets[i].parent;     }     void Union(int x, int y) {       int xroot = Find(x);       int yroot = Find(y);       if (xroot == yroot) return;       --_setCount;       if (_subsets[xroot].rank < _subsets[yroot].rank)         _subsets[xroot].parent = yroot;       else if (_subsets[xroot].rank > _subsets[yroot].rank)         _subsets[yroot].parent = xroot;       else {         _subsets[yroot].parent = xroot;         _subsets[xroot].rank++;       }     }     struct subset {       int parent;       int rank;     };     void Trace() {       for (int i = (0), _b = ((_subsets.size()) - 1); i <= _b; i++)         cout << i <<  :  << Find(i) <<   | ;       cout << endl;     }     vector<subset> _subsets;     int _setCount;   };   vector<int> res;   struct Node {     Node(int v) {       l = r = NULL;       val = v;     }     Node(Node *_l, Node *_r) {       l = _l;       r = _r;     }     Node *l, *r;     int val;     void Solve() {       if (l == NULL) {         cout << val <<    ;       } else {         l->Solve();         r->Solve();       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << std::setprecision(15);     cout << std::fixed;     int n;     cin >> n;     res.reserve(n);     UnionFind uf(n + 1);     vector<Node *> d(n + 1);     for (int i = (1), _b = (n); i <= _b; i++) {       d[i] = new Node(i);     }     for (int i = (0), _b = ((n - 1) - 1); i <= _b; i++) {       int a, b;       cin >> a >> b;       int ra = uf.Find(a);       int rb = uf.Find(b);       Node *na = d[ra];       Node *nb = d[rb];       assert(na != NULL);       assert(nb != NULL);       d[ra] = NULL;       d[rb] = NULL;       uf.Union(ra, rb);       int nr = uf.Find(ra);       Node *nn = new Node(na, nb);       d[nr] = nn;     }     int rootR = uf.Find(1);     d[rootR]->Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long tc, n, m, a, b, k;   string str;   char c;   set<long long> s;   map<long long, long long> mp;   int main() {     int k2, k3, k5, k6, ans = 0;     cin >> k2 >> k3 >> k5 >> k6;     int x = min(k2, k5);     x = min(x, k6);     ans += 256 * x;     k2 -= x;     x = min(k2, k3);     ans += 32 * x;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   string inp[100005];   int num[100005];   int tl;   int ch[1200005][27];   int fail[1200005], len[1200005], elen[1200005];   long long cost[1200005];   int rt = 1, tot = 1, last = 1;   void add(int x, int c, int _elen) {     int p = last;     int np = ++tot;     len[np] = len[p] + 1;     cost[np] = c;     elen[np] = _elen;     last = np;     while (p && !ch[p][x]) {       ch[p][x] = np;       p = fail[p];     }     if (!p) {       fail[np] = rt;     } else {       int q = ch[p][x];       if (len[q] == len[p] + 1) {         fail[np] = q;       } else {         int nq = ++tot;         memcpy(ch[nq], ch[q], sizeof(ch[q]));         len[nq] = len[p] + 1;         fail[nq] = fail[q];         fail[np] = fail[q] = nq;         while (p && ch[p][x] == q) {           ch[p][x] = nq;           p = fail[p];         }       }     }   }   int freq[600005], tpsort[1200005];   void TopoSort() {     for (int i = (1); i <= (tot); i += (1)) freq[len[i]]++;     for (int i = (1); i <= (tl); i += (1)) freq[i] += freq[i - 1];     for (int i = (tot); i >= (1); i -= (1)) tpsort[--freq[len[i]]] = i;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = (1); i <= (n); i += (1)) cin >> inp[i];     for (int i = (1); i <= (n); i += (1)) cin >> num[i];     for (int i = (0); i <= (1200005 - 1); i += (1)) elen[i] = 1000000000;     tl = 0;     for (int i = (1); i <= (n); i += (1)) {       int t = inp[i].length();       for (int j = (0); j <= (t - 1); j += (1)) {         add(inp[i][j] -  a , num[i], j + 1);       }       add(26, 0, 0);       tl += t + 1;     }     TopoSort();     long long mx = 0;     for (int i = (tot); i >= (1); i -= (1)) {       int u = tpsort[i];       cost[fail[u]] += cost[u];       elen[fail[u]] = min(elen[fail[u]], elen[u]);       if (elen[u] > len[fail[u]]) {         mx = max(mx, cost[u] * min(elen[u], len[u]));       }     }     printf( %lld n , mx);     return 0;   }