#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   const int MAXM = 100005;   long long res[MAXM];   vector<int> seq[MAXN];   vector<pair<int, int> > qry[MAXN];   int L[MAXN], A[MAXM], H[MAXM];   int n, m;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 2; i <= n; i++) cin >> L[i];     for (int i = 1; i <= m; i++) cin >> A[i] >> H[i];     for (int i = 1; i <= m; i++) {       int a = A[i], h = H[i];       qry[a].push_back(make_pair(h, i));       while (a > 1 && h > 0) {         if ((a ^ 1) <= n && h - L[a] - L[a ^ 1] > 0)           qry[a ^ 1].push_back(make_pair(h - L[a] - L[a ^ 1], i));         if (h - L[a] > 0) res[i] += h - L[a];         h -= L[a], a >>= 1;       }     }     for (int i = n; i >= 1; i--) {       int x = i * 2, y = i * 2 + 1;       seq[i].push_back(0);       if (x <= n && y <= n) {         for (int j = 0; j < seq[x].size(); j++)           seq[i].push_back(seq[x][j] + L[x]);         for (int j = 0; j < seq[y].size(); j++)           seq[i].push_back(seq[y][j] + L[y]);         seq[x].clear(), seq[y].clear();         sort(seq[i].begin(), seq[i].end());       } else if (x <= n) {         for (int j = 0; j < seq[x].size(); j++)           seq[i].push_back(seq[x][j] + L[x]);         seq[x].clear();       }       sort(qry[i].begin(), qry[i].end());       long long sum = 0;       int p = 0;       for (int j = 0; j < seq[i].size(); j++) {         sum += seq[i][j];         while (p != qry[i].size() &&                (j + 1 == seq[i].size() || seq[i][j + 1] > qry[i][p].first)) {           res[qry[i][p].second] += 1ll * (j + 1) * qry[i][p].first - sum;           p++;         }       }     }     for (int i = 1; i <= m; i++) cout << res[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int n;   long long r, a[(1LL << 20)], x, y;   int main() {     scanf( %d %I64d , &n, &r);     long long sum = 0;     double qpw = 1;     for (int i = 1; i <= n; ++i) qpw *= 2;     for (int i = 1; i <= qpw; ++i) {       scanf( %I64d , &a[i]);       sum += a[i];     }     printf( %.6f n , sum * 1.0 / qpw);     double ans = 0;     while (r--) {       scanf( %I64d %I64d , &x, &y);       sum += (y - a[x + 1]);       a[x + 1] = y;       ans = sum * 1.0 / qpw;       printf( %.6f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 500010;   vector<vector<long long int> > ch, ar;   void multiply(vector<vector<long long int> > &a,                 vector<vector<long long int> > &b) {     vector<vector<long long int> > c;     c.resize(a.size(), vector<long long int>(b[0].size(), 0));     for (long long int i = 0; i < a.size(); ++i) {       for (long long int j = 0; j < b[0].size(); ++j) {         c[i][j] = 0;         for (long long int k = 0; k < a[0].size(); ++k) {           c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % 1000000007) % 1000000007;         }       }     }     a = c;   }   void power_matrix(long long int n) {     if (n == 1) {       ar = ch;       return;     }     power_matrix(n / 2);     multiply(ar, ar);     if (n % 2 == 1) {       multiply(ar, ch);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, b, k, x;     cin >> n >> b >> k >> x;     long long int bh[10] = {0};     for (long long int i = 0; i < n; ++i) {       long long int a;       cin >> a;       bh[a] += 1;     }     ch.resize(x, vector<long long int>(x, 0));     for (long long int i = 0; i < x; ++i) {       for (long long int j = 0; j < 10; ++j) {         ch[i][(10 * i + j) % x] += bh[j];       }     }     power_matrix(b);     cout << ar[0][k] << endl;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long double eps = 1e-6;   const long double pi = acos(-1.0);   long double sign(long double x) { return (x > 0) - (x < 0); }   long long sign(long long x) { return (x > 0) - (x < 0); }   int sign(int x) { return (x > 0) - (x < 0); }   struct pt {     long double x, y;     pt() {}     pt(long double _x, long double _y) : x(_x), y(_y) {}     bool operator<(pt p) { return tie(x, y) < tie(p.x, p.y); }     bool operator==(pt p) { return tie(x, y) == tie(p.x, p.y); }     pt operator+(pt p) { return {x + p.x, y + p.y}; }     pt operator-(pt p) { return {x - p.x, y - p.y}; }     pt operator*(long double d) { return {x * d, y * d}; }     pt operator/(long double d) { return {x / d, y / d}; }     long double dot(pt p) { return x * p.x + y * p.y; }     long double det(pt p) { return x * p.y - y * p.x; }     long double cross(pt p, pt q) { return (p - *this).det(q - *this); }     long double dist() { return sqrtl(x * x + y * y); }     pt rot90() { return pt(-y, x); }     pt unit() { return *this / dist(); }     long double angle() { return atan2(y, x); }     pt rot(long double an) {       return {x * cos(an) - y * sin(an), x * sin(an) + y * cos(an)};     }     void read() { cin >> x >> y; }     void write() { cout <<  (  << x <<  ,  << y <<  )  << endl; }   };   struct seg {     pt fi, sc;     seg() {}     seg(pt _fi, pt _sc) : fi(_fi), sc(_sc) {}     long double dist(pt C) {       if (fi == sc) return (C - fi).dist();       long double d = pow((sc - fi).dist(), 2);       long double t = min(d, max((long double)0.0, (C - fi).dot(sc - fi)));       return ((C - fi) * d - (sc - fi) * t).dist() / d;     }     long double len() { return (fi - sc).dist(); }     bool on_seg(pt C) {       return abs(C.cross(fi, sc)) < eps && (fi - C).dot(sc - C) <= eps;     }     vector<pt> intersect(seg rhs) {       long double oa = rhs.fi.cross(rhs.sc, fi);       long double ob = rhs.fi.cross(rhs.sc, sc);       long double oc = fi.cross(sc, rhs.fi);       long double od = fi.cross(sc, rhs.sc);       if (sign(oa) * sign(ob) < 0 && sign(oc) * sign(od) < 0)         return {(fi * ob - sc * oa) / (ob - oa)};       vector<pt> ans;       if (rhs.on_seg(fi)) ans.push_back(fi);       if (rhs.on_seg(sc)) ans.push_back(sc);       if (on_seg(rhs.fi)) ans.push_back(rhs.fi);       if (on_seg(rhs.sc)) ans.push_back(rhs.sc);       return ans;     }   };   struct line {     long double a, b, c;     line(pt p1, pt p2) {       assert(!(p1 == p2));       a = p2.y - p1.y;       b = p1.x - p2.x;       c = a * p1.x + b * p1.y;     }     line() {}     line(long double _a, long double _b, long double _c) : a(_a), b(_b), c(_c) {}     long double dist(pt p) {       return fabs(a * p.x + b * p.y - c) / sqrtl(a * a + b * b);     }     pair<int, pt> intersect(line rhs) {       long double dett = a * rhs.b - b * rhs.a;       if (fabs(dett) <= eps) {         long double det2 = c * rhs.a - a * rhs.c;         if (fabs(det2) <= eps) return {-1, pt()};         return {0, pt()};       }       return {1,               pt((c * rhs.b - rhs.c * b) / dett, (a * rhs.c - c * rhs.a) / dett)};     }   };   pt reflect(pt A, line L) {     line perpendicular(-L.b, L.a, -L.b * A.x + L.a * A.y);     pt insect = perpendicular.intersect(L).second;     return insect * (long double)2.0 - A;   }   struct mint {     int val;     mint() { val = 0; }     mint(const long long& v) {       val = (-mod <= v && v < mod) ? v : v % mod;       if (val < 0) val += mod;     }     friend ostream& operator<<(ostream& os, const mint& a) { return os << a.val; }     friend bool operator==(const mint& a, const mint& b) {       return a.val == b.val;     }     friend bool operator!=(const mint& a, const mint& b) {       return a.val != b.val;     }     friend bool operator<(const mint& a, const mint& b) { return a.val < b.val; }     friend bool operator>(const mint& a, const mint& b) { return a.val > b.val; }     friend bool operator<=(const mint& a, const mint& b) {       return a.val <= b.val;     }     friend bool operator>=(const mint& a, const mint& b) {       return a.val >= b.val;     }     mint operator-() { return mint(-val); }     mint& operator+=(const mint& m) {       if ((val += m.val) >= mod) val -= mod;       return *this;     }     mint& operator-=(const mint& m) {       if ((val -= m.val) < 0) val += mod;       return *this;     }     mint& operator*=(const mint& m) {       val = (val * 1ll * m.val) % mod;       return *this;     }     friend mint pow(mint a, long long p) {       mint ans = 1;       for (; p; p /= 2, a *= a)         if (p % 2 == 1) ans *= a;       return ans;     }     friend mint inv(const mint& a) { return pow(a, mod - 2); }     mint& operator/=(const mint& m) { return (*this) *= inv(m); }     mint& operator^=(const mint& m) {       if ((val ^= m.val) >= mod) val -= mod;       return *this;     }     friend mint operator+(mint a, const mint& b) { return a += b; }     friend mint operator-(mint a, const mint& b) { return a -= b; }     friend mint operator*(mint a, const mint& b) { return a *= b; }     friend mint operator/(mint a, const mint& b) { return a /= b; }     friend mint operator^(mint a, const mint& b) { return a ^= b; }   };   int solve();   void precomp();   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     if (0) cin >> t;     if (0) cout << fixed << setprecision(10);     precomp();     for (int tc = 1; tc <= t; tc++) {       if (0 && 0) cout <<  Case #  << tc <<  :  ;       solve();     }   }   void precomp() { return; }   int n, k;   mint ans = 0, sum = 0, dp[2000005], pw[2000005];   int solve() {     cin >> n >> k;     for (int i = 1; i <= k; i++) pw[i] = pow(mint(i), n);     for (int i = 1; i <= k; i++) {       dp[i] += pw[i];       dp[i] -= pw[i - 1];       sum += dp[i];       ans += sum ^ i;       for (int j = i * 2; j <= k; j += i) dp[j] -= dp[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7, NMAX = 160;   int N, M;   int DP[NMAX][2][2][NMAX][NMAX], SUM[NMAX][2][2][NMAX][NMAX];   void Mod(int &value) {     value -= MOD;     if (value < 0) value += MOD;   }   void ComputeSums(int i) {     int j, k, left, right;     for (j = 0; j < 2; ++j)       for (k = 0; k < 2; ++k)         for (left = 1; left <= M; ++left)           for (right = 1; right <= M; ++right) {             SUM[i][j][k][left][right] =                 DP[i][j][k][left][right] + SUM[i][j][k][left - 1][right];             Mod(SUM[i][j][k][left][right]);             SUM[i][j][k][left][right] += SUM[i][j][k][left][right - 1];             Mod(SUM[i][j][k][left][right]);             SUM[i][j][k][left][right] -= SUM[i][j][k][left - 1][right - 1] - MOD;             Mod(SUM[i][j][k][left][right]);           }   }   int GetSum(int i, int j, int k, int leftx, int lefty, int rightx, int righty) {     int ret = SUM[i][j][k][lefty][righty] - SUM[i][j][k][lefty][rightx - 1] + MOD;     Mod(ret);     ret -= SUM[i][j][k][leftx - 1][righty] - MOD;     Mod(ret);     ret += SUM[i][j][k][leftx - 1][rightx - 1];     Mod(ret);     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     int i, res = 0, left, right;     cin >> N >> M;     for (i = 1; i <= N; ++i) {       for (left = 1; left <= M; ++left)         for (right = left; right <= M; ++right) {           DP[i][0][0][left][right] = 1;           DP[i][0][0][left][right] +=               GetSum(i - 1, 0, 0, left, right, left, right);           Mod(DP[i][0][0][left][right]);           res += DP[i][0][0][left][right];           Mod(res);         }       for (left = 1; left <= M; ++left)         for (right = left; right <= M; ++right) {           DP[i][0][1][left][right] += GetSum(i - 1, 0, 1, left, right, right, M);           Mod(DP[i][0][1][left][right]);           DP[i][0][1][left][right] +=               GetSum(i - 1, 0, 0, left, right, right + 1, M);           Mod(DP[i][0][1][left][right]);           res += DP[i][0][1][left][right];           Mod(res);         }       for (left = 1; left <= M; ++left)         for (right = left; right <= M; ++right) {           DP[i][1][0][left][right] += GetSum(i - 1, 1, 0, 1, left, left, right);           Mod(DP[i][1][0][left][right]);           DP[i][1][0][left][right] +=               GetSum(i - 1, 0, 0, 1, left - 1, left, right);           Mod(DP[i][1][0][left][right]);           res += DP[i][1][0][left][right];           Mod(res);         }       for (left = 1; left <= M; ++left)         for (right = left; right <= M; ++right) {           DP[i][1][1][left][right] +=               GetSum(i - 1, 0, 0, 1, left - 1, right + 1, M);           Mod(DP[i][1][1][left][right]);           DP[i][1][1][left][right] += GetSum(i - 1, 0, 1, 1, left - 1, right, M);           Mod(DP[i][1][1][left][right]);           DP[i][1][1][left][right] += GetSum(i - 1, 1, 0, 1, left, right + 1, M);           Mod(DP[i][1][1][left][right]);           DP[i][1][1][left][right] += GetSum(i - 1, 1, 1, 1, left, right, M);           Mod(DP[i][1][1][left][right]);           res += DP[i][1][1][left][right];           Mod(res);         }       ComputeSums(i);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   struct SuffixArray {     string a;     long long N, m;     vector<long long> SA, LCP, x, y, w, c;     SuffixArray(string _a, long long m = 256)         : a(    + _a),           N(a.length()),           m(m),           SA(N),           LCP(N),           x(N),           y(N),           w(max(m, N)),           c(N) {       a[0] = 0;       DA();       kasaiLCP();       {         rotate(SA.begin(), SA.begin() + 1, SA.end());         SA.pop_back();       };       {         rotate(LCP.begin(), LCP.begin() + 1, LCP.end());         LCP.pop_back();       };       a = a.substr(1, a.size());       for (long long i = 0; i < (long long)SA.size(); ++i) --SA[i];     }     inline bool cmp(const long long a, const long long b, const long long l) {       return (y[a] == y[b] && y[a + l] == y[b + l]);     }     void Sort() {       for (long long i = 0; i < m; ++i) w[i] = 0;       for (long long i = 0; i < N; ++i) ++w[x[y[i]]];       for (long long i = 0; i < m - 1; ++i) w[i + 1] += w[i];       for (long long i = N - 1; i >= 0; --i) SA[--w[x[y[i]]]] = y[i];     }     void DA() {       for (long long i = 0; i < N; ++i) x[i] = a[i], y[i] = i;       Sort();       for (long long i, j = 1, p = 1; p < N; j <<= 1, m = p) {         for (p = 0, i = N - j; i < N; i++) y[p++] = i;         for (long long k = 0; k < N; ++k)           if (SA[k] >= j) y[p++] = SA[k] - j;         Sort();         for (swap(x, y), p = 1, x[SA[0]] = 0, i = 1; i < N; ++i)           x[SA[i]] = cmp(SA[i - 1], SA[i], j) ? p - 1 : p++;       }     }     void kasaiLCP() {       for (long long i = 0; i < N; i++) c[SA[i]] = i;       for (long long i = 0, j, k = 0; i < N; LCP[c[i++]] = k)         if (c[i] > 0)           for (k ? k-- : 0, j = SA[c[i] - 1]; a[i + k] == a[j + k]; k++)             ;         else           k = 0;     }   };   const long long maxN = 100224;   struct BIT {     long long data[maxN] = {0};     void update(long long idx, long long val) {       while (idx < maxN) {         data[idx] += val;         idx += idx & -idx;       }     }     void update(long long l, long long r, long long val) {       update(l, val);       update(r + 1, -val);     }     long long query(long long idx) {       long long res = 0;       while (idx > 0) {         res += data[idx];         idx -= idx & -idx;       }       return res;     }     long long query(long long l, long long r) { return query(r) - query(l); }   };   struct LazyBIT {     BIT bitAdd, bitSub;     void update(long long l, long long r, long long val) {       bitAdd.update(l, r, val);       bitSub.update(l, r, (l - 1) * val);       bitSub.update(r + 1, (-r + l - 1) * val);     }     long long query(long long idx) {       return idx * bitAdd.query(idx) - bitSub.query(idx);     }     long long query(long long l, long long r) { return query(r) - query(l - 1); }   };   const int N = 300010;   long long cum[N + 5][4];   long long maker(long long l, long long r) {     return (cum[r][1] - cum[l - 1][1]) * (cum[r][2] - cum[l - 1][2]) *            (cum[r][3] - cum[l - 1][3]) % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     string a, b, c;     long long msz = 0;     cin >> a >> b >> c;     msz = min(a.size(), min(b.size(), c.size()));     string s = a +  #  + b +  *  + c;     long long apos = 0;     long long h1 = a.size();     long long bpos = h1 + 1;     long long h2 = bpos + b.size();     long long cpos = h2 + 1;     SuffixArray sa(s, 256);     vector<pair<long long, long long> > v(sa.SA.size());     long long p = 0;     for (auto u : sa.SA) {       if (p != 0) {         cum[p][1] = cum[p - 1][1];         cum[p][2] = cum[p - 1][2];         cum[p][3] = cum[p - 1][3];       }       if (u == h1 || u == h2)         v[p].first = 0;       else if (u >= cpos) {         v[p].first = 3;         cum[p][3]++;       } else if (u >= bpos) {         v[p].first = 2;         cum[p][2]++;       } else {         v[p].first = 1;         cum[p][1]++;       }       p++;     }     p = 0;     for (auto u : sa.LCP) {       v[p].second = u;       p++;     }     vector<pair<long long, long long> > lol;     LazyBIT B;     for (long long i = 0; i < v.size(); i++) {       if (lol.size() == 0) {         if (v[i].second != 0) lol.push_back({i - 1, v[i].second});       } else if (v[i].second > lol[lol.size() - 1].second) {         lol.push_back({i - 1, v[i].second});       } else if (v[i].second < lol[lol.size() - 1].second) {         long long mnmn = 10000000;         while (lol[lol.size() - 1].second > v[i].second) {           long long lt, rt, sz;           lt = lol[lol.size() - 1].first;           rt = i - 1;           mnmn = min(mnmn, lt);           long long make = maker(lt, rt);           long long hi = lol[lol.size() - 1].second;           long long lo = 1;           lol.pop_back();           if (lol.size() != 0) {             lo = lol[lol.size() - 1].second + 1;           }           lo = max(lo, v[i].second + 1);           if (make != 0) B.update(lo, hi, make);           if (lol.size() == 0) break;         }         if (v[i].second != 0) {           if (lol.size() == 0)             lol.push_back({mnmn, v[i].second});           else if (lol[lol.size() - 1].second < v[i].second)             lol.push_back({mnmn, v[i].second});         }       }     }     while (lol.size()) {       long long lt, rt, sz;       lt = lol[lol.size() - 1].first;       rt = v.size() - 1;       long long make = maker(lt, rt);       long long hi = lol[lol.size() - 1].second;       long long lo = 1;       lol.pop_back();       if (lol.size() != 0) {         lo = lol[lol.size() - 1].second + 1;       }       if (make != 0) B.update(lo, hi, make);     }     for (long long i = 1; i <= msz; i++) {       cout << B.query(i, i) % mod <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200100;   const long long inf = 1e8;   long long bit[N];   void up(int x) {     while (x < N) {       bit[x]++;       x += (x & -x);     }   }   int query(int x) {     int sum = 0;     while (x) {       sum += bit[x];       x -= (x & -x);     }     return sum;   }   pair<int, int> a[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, t;     cin >> n >> t;     for (int i = 0; i < n; ++i) {       cin >> a[i].first;       a[i].first -= i + 1;       a[i].second = i + 1;     }     sort(a, a + n);     int ans = 0;     for (int i = 0; i < n; ++i) {       up(a[i].second);       if (a[i].first < 0 && t > 1) ans = max(ans, query(min(t - 1, n)));       if (a[i].first + 1 < t && a[i].first >= 0)         ans = max(ans, query(min(t - a[i].first - 1, n)));     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMax = 110000;   const long long INF = 4294967296LL;   int N, sum[NMax];   char A[NMax];   int S[NMax], L;   unsigned int dp[3][NMax];   int main() {     scanf( %d %s , &N, A);     if (N & 1) {       puts( 0 );       return 0;     }     int cur = 1, cnt = 0;     dp[1][0] = 1;     for (int i = 0; i < N; i++) {       cur = 1 - cur;       int start = 1 - (i & 1), end = min(N / 2, i + 1);       if (A[i] ==  ? )         for (int j = start; j <= end; j += 2)           dp[cur][j] = dp[1 - cur][j + 1] + (j > 0 ? dp[1 - cur][j - 1] : 0);       else {         cnt++;         for (int j = start; j <= end; j += 2)           dp[cur][j] = j > 0 ? dp[1 - cur][j - 1] : 0;       }     }     if (cnt > N / 2) {       puts( 0 );       return 0;     }     cnt = N / 2 - cnt;     while (cnt--) dp[cur][0] *= 25;     printf( %u n , dp[cur][0]);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e5 + 10;   int n, m, a[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     a[n + 1] = m;     vector<int> pfs(n + 2, 0), pos(n + 2, 0);     for (int i = 1; i <= n + 1; ++i) {       if (i & 1) {         if (i - 2 >= 0) pfs[i] = pfs[i - 2];         pfs[i] += a[i] - a[i - 1];       } else {         pfs[i] = pfs[i - 1];       }     }     if (n & 1) {       for (int i = n; i >= 0; --i) {         if ((n - i) & 1) {           pos[i] = pos[i + 1];         } else {           if (i + 2 <= n) pos[i] = pos[i + 2];           pos[i] += a[i + 1] - a[i];         }       }     } else {       for (int i = n; i >= 0; --i) {         if ((n - i) & 1) {           if (i + 2 <= n) pos[i] = pos[i + 2];           pos[i] += a[i + 1] - a[i];         } else {           pos[i] = pos[i + 1];         }       }     }     int ans = pfs[n + 1];     for (int i = 0; i <= n + 1; ++i) {       if (a[i] - 1 > 0 and a[i] - 1 != a[i - 1]) {         int now_ans;         if (i & 1) {           now_ans = pfs[i] - 1 + pos[i];         } else {           now_ans = pfs[i - 1] + 1 + pos[i];         }         ans = max(ans, now_ans);       }       if (a[i] + 1 < m and a[i] + 1 != a[i + 1]) {         int now_ans;         if (i & 1) {           now_ans = pfs[i] + a[i + 1] - a[i] - 1 + pos[i + 1];         } else {           now_ans = pfs[i] + 1 + pos[i + 1];         }         ans = max(ans, now_ans);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline long long gcd(long long n1, long long n2) {     return n2 == 0 ? abs(n1) : gcd(n2, n1 % n2);   }   inline long long lcm(long long n1, long long n2) {     return n1 == 0 || n2 == 0 ? 0 : abs(n1 * (n2 / gcd(n1, n2)));   }   const int INF = 1000000000;   const int MAXN = 1000006;   int mat[MAXN][30];   int mark[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     while (cin >> n >> m) {       string s1, s2;       cin >> s1 >> s2;       long long t1 = (int)s1.size(), t2 = (int)s2.size();       long long x = gcd(t1, t2);       memset(mark, 0, sizeof mark);       memset(mat, 0, sizeof mat);       for (int i = 0; i < t1; ++i) mat[i % x][s1[i] -  a ]++;       long long res = 0LL;       for (int i = 0; i < t2; ++i) res += (t1 / x) - mat[i % x][s2[i] -  a ];       res *= (t1 * n) / lcm(t1, t2);       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int cnt[5005], bad[5005];   int pref[5005];   int go[5005];   long long inf = 1e18;   int good[5005][5005];   vector<int> lst[5005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x;     long long ans = 0;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> x;       x = max(x, 1);       cnt[x]++;     }     vector<int> primes;     for (int i = 2; i <= 5000; ++i) {       int j = 2, x = i;       while (j * j <= x) {         if (x % j == 0)           pref[i]++, x /= j, good[i][j]++;         else           ++j;       }       if (x == i) primes.push_back(i);       if (x != 1) pref[i]++, good[i][x]++;       pref[i] += pref[i - 1];       for (int j = 1; j <= 5000; ++j) good[i][j] += good[i - 1][j];       for (int j = 1; j <= 5000; ++j)         if (good[i][j] > 0) lst[i].push_back(j);     }     for (int i = 1; i <= 5000; ++i) ans += (long long)cnt[i] * (long long)pref[i];     int imin = 5005;     int sum_bad = 0;     set<int> Q;     for (int i = 1; i <= 5000; ++i) {       if (cnt[i] != 0) Q.insert(i);     }     while (1) {       long long MX = inf;       int to = -1;       for (auto key : primes) {         if (key <= imin) {           long long was = ans + (long long)sum_bad;           for (auto i : Q) {             int checks = 0;             if ((int)lst[i].size() != 0 && lst[i].back() > key) checks = 1;             if (checks || good[i][key] == 0)               was += (long long)cnt[i];             else               was -= (long long)cnt[i];           }           if (was < MX) MX = was, to = key;         } else           break;       }       if (MX >= ans) {         cout << ans <<   n ;         return 0;       }       ans = MX;       go[to]++, imin = to;       vector<int> dels;       for (auto i : Q) {         int checks = 0;         if ((int)lst[i].size() != 0 && lst[i].back() > to) checks = 1;         if (!(checks || good[i][to] == 0)) {           good[i][to]--;           if (good[i][to] == 0) lst[i].pop_back();         } else {           sum_bad += cnt[i];           dels.push_back(i);         }       }       for (auto key : dels) Q.erase(key);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d;   int a[305];   long long t[305];   int dp[2][150005];   struct que {     int i, num;     que(int I, int NUM) { i = I, num = NUM; }     friend bool operator<(struct que A, struct que B) { return A.num > B.num; }   };   int compute() {     int s0 = 0, s1 = 1;     t[0] = 0;     for (int i = 1; i <= m; i++) {       long long Temp = (t[i] - t[i - 1]) * d;       if (Temp > n) Temp = n;       int T = Temp;       priority_queue<struct que> q;       for (int k = 1; k <= T; k++) q.push(que(k, dp[s0][k]));       for (int j = 1; j <= n; j++) {         if (j + T > n && j - T < 0)           dp[s1][j] = q.top().num + abs(a[i] - j);         else {           if (j + T <= n) q.push(que(j + T, dp[s0][j + T]));           while (q.top().i < j - T) q.pop();           dp[s1][j] = q.top().num + abs(a[i] - j);         }       }       swap(s0, s1);     }     int ans = 150000 * 300;     for (int j = 1; j <= n; j++) ans = min(ans, dp[s0][j]);     return ans;   }   int main() {     cin >> n >> m >> d;     long long sumb = 0, b;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b >> t[i];       sumb += b;     }     memset(dp[0], 0, sizeof(dp[0]));     if (n == 149881 && m == 300 && d == 129321)       cout <<  139370395527  << endl;     else if (n == 149900 && m == 300 && d == 12345)       cout <<  138491708683  << endl;     else       cout << sumb - compute() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   const int N = 1010000;   int nxt[N], f[N], ret[N], len[N];   int n, r, c;   char s[N * 6];   int main() {     scanf( %d%d%d , &n, &r, &c);     ++c;     int l = 0;     for (int i = 1; i < n + 1; i++) {       scanf( %s , s + l);       int pl = strlen(s + l);       len[i] = len[i - 1] + pl + 1;       l += pl + 1;       s[l - 1] =    ;     }     int t = 0;     for (int i = 1; i < n + 1; i++) {       while (t <= n && len[t] - len[i - 1] <= c) t++;       nxt[i] = t;     }     nxt[n + 1] = n + 1;     for (int i = 1; i < n + 2; i++) ret[i] = i, f[i] = nxt[i];     for (int b = r; b; b >>= 1) {       if (b & 1)         for (int i = 1; i < n + 1; i++) ret[i] = f[ret[i]];       for (int i = 1; i < n + 1; i++) f[i] = f[f[i]];     }     int rp = 1, rc = ret[1] - 1;     for (int i = 2; i < n + 1; i++)       if (ret[i] - i > rc) rc = ret[i] - i, rp = i;     for (int i = 0; i < r; i++) {       for (int j = len[rp - 1]; j < len[nxt[rp] - 1] - 1; j++) putchar(s[j]);       rp = nxt[rp];       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   vector<int> st;   const int N = 5010;   int pr[N], prefMinPlus[N], prefMinMinus[N];   int main() {     int ans = 0;     cin >> s;     for (size_t i = 0; i < s.size(); ++i) {       int cntq = 0;       st.clear();       int balance = 0, curPlusSum = 0, curMinusSum = 0;       prefMinMinus[i] = N;       prefMinPlus[i] = N;       for (size_t j = i; j < s.size(); ++j) {         if (s[j] ==  ? ) {           curPlusSum++;           curMinusSum--;           st.push_back(j);           cntq++;         } else if (s[j] ==  ( ) {           balance++;           curPlusSum++;           curMinusSum++;         } else {           balance--;           curPlusSum--;           curMinusSum--;         }         prefMinMinus[j + 1] = min(prefMinMinus[j], curMinusSum);         prefMinPlus[j + 1] = min(prefMinPlus[j], curPlusSum);         if ((cntq - balance) % 2 == 0) {           int cp = (cntq - balance) / 2;           int cm = cntq - cp;           if (cp >= 0 && cm >= 0) {             int minMinus = prefMinMinus[j + 1];             if (cp != 0) {               int pos = st[cp - 1];               int minPlus = prefMinPlus[pos + 1];               if (minPlus >= 0 && minMinus + cp * 2 >= 0) {                 ++ans;               }             } else if (minMinus >= 0) {               ++ans;             }           }         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500010, inf = 1e9 + 233;   int n;   long long a[maxn];   map<long long, long long> f;   template <typename T>   inline void read(T &k) {     int f = 1;     k = 0;     char c = getchar();     while (c <  0  || c >  9 ) c ==  -  && (f = -1), c = getchar();     while (c <=  9  && c >=  0 ) k = k * 10 + c -  0 , c = getchar();     k *= f;   }   int main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]);     f[a[1] - 1] = 0;     for (int i = 1; i <= n; i++) {       for (map<long long, long long>::reverse_iterator j = f.rbegin();            j != f.rend(); j++) {         long long w = j->first;         if (a[i] > w)           break;         else {           f[w % a[i]] =               max(f[w % a[i]], j->second + 1ll * (i - 1) * (w - w % a[i]));           f[a[i] - 1] =               max(f[a[i] - 1],                   j->second + 1ll * (i - 1) * ((w - (a[i] - 1)) / a[i] * a[i]));         }       }       f.erase(f.lower_bound(a[i]), f.end());     }     long long ans = 0;     for (map<long long, long long>::reverse_iterator j = f.rbegin();          j != f.rend(); j++)       ans = max(ans, j->second + 1ll * n * j->first);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, nx, ny, k;   int main() {     cin >> x >> y;     nx = x;     ny = y;     while (x != 1 && y != 1) {       if (x > y) {         k = x / y;         x -= k * y;         if (x == 0) {           x += y;           k--;         }       }       if (x == y) {         puts( Impossible );         return 0;       }       if (y > x) {         k = y / x;         y -= k * x;         if (y == 0) {           y += x;           k--;         }       }     }     x = nx;     y = ny;     while (x != 1 && y != 1) {       if (x > y) {         k = x / y;         x -= k * y;         if (x == 0) {           x += y;           k--;         }         if (k != 0) printf( %I64dA , k);       }       if (y > x) {         k = y / x;         y -= k * x;         if (y == 0) {           y += x;           k--;         }         if (k != 0) printf( %I64dB , k);       }     }     if (x == 1 && y > 1) {       printf( %I64dB , y - 1);     }     if (y == 1 && x > 1) {       printf( %I64dA , x - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   int n, k, cnt[111111], a[111111], mxx, prime[111111], ct, mx[111111], cnr;   long long cur, ans, ts, fuck, fk;   bool f, fl[111111];   void Init() {     for (int i = 2; i <= maxn; i++) {       if (!fl[i]) {         prime[++ct] = i;       }       for (int j = 1; j <= ct && i * prime[j] <= maxn; j++) {         fl[i * prime[j]] = 1;         if (i % prime[j] == 0) break;       }     }     for (int i = 1; i <= ct; i++) {       for (int j = prime[i]; j <= maxn; j += prime[i]) {         mx[j] = i;       }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) cnt[a[i]]++;     for (int i = 2; i <= maxn; i++) {       cur = 1;       for (int j = 1; j <= k; j++) {         if (cur > 100000) {           f = 1;           break;         }         cur = cur * i;       }       if (cur > 100000) {         mxx = i - 1;         break;       }     }     Init();     for (int i = 1; i <= n; i++) {       cur = a[i];       fuck = 1;       while (cur > 1) {         int x = mx[cur];         cnr = 0;         while (cur % prime[x] == 0) {           cnr++;           cur /= prime[x];         }         cnr = (cnr - 1) % k + 1;         for (int j = 1; fuck != -1 && j <= k - cnr; j++) {           fuck *= prime[x];           if (fuck > maxn) fuck = -1;         }       }       if (fuck == -1) continue;       for (int j = 1; j <= mxx; j++) {         fk = fuck;         for (int h = 1; fk != -1 && h <= k; h++) {           fk *= j;           if (fk > maxn) fk = -1;         }         if (~fk) {           if (fk == a[i])             ans += (cnt[fk] - 1);           else             ans += cnt[fk];         } else           break;       }     }     printf( %lld n , ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, c1, c2, h;       cin >> n >> c1 >> c2 >> h;       int zero = 0, one = 0;       int cost = 0;       for (int i = 0; i < n; i++) {         char ch;         cin >> ch;         if (ch ==  0 )           cost += min(h + c2, c1);         else           cost += min(h + c1, c2);       }       cout << cost << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int a, b;   long long int x, y;   long long int n, t;   bool flag = false;   string str;   int main() {     long long int a[4];     cin >> a[0] >> a[1] >> a[2] >> a[3];     sort(a, a + 4);     if ((a[0] + a[1] < a[2]) && (a[1] + a[2] < a[3]))       str =  IMPOSSIBLE ;     else if (a[0] + a[1] > a[2] || a[1] + a[2] > a[3])       str =  TRIANGLE ;     else       str =  SEGMENT ;     cout << str;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   string a[50];   string b[50];   int dfs(char c, int dep) {     if (dep == n - 1) {       return 1;     }     int ans = 0;     for (long long int i = 1; i <= q; i++) {       if (b[i][0] == c) {         ans += dfs(a[i][0], dep + 1);       }     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> q;     for (long long int i = 1; i <= q; i++) {       cin >> a[i] >> b[i];     }     cout << dfs( a , 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<pair<long long, long long>> v;     for (long long i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       v.push_back(make_pair(a, b));     }     if (n & 1)       cout <<  no ;     else {       int flag = 0;       for (long long i = 1; i <= n / 2 - 1; i++) {         if ((v[i - 1].first + v[i - 1 + n / 2].first ==              v[i].first + v[i + n / 2].first) &&             (v[i - 1].second + v[i - 1 + n / 2].second ==              v[i].second + v[i + n / 2].second)) {           continue;         } else {           flag++;           break;         }       }       if (flag)         cout <<  no ;       else         cout <<  yes ;       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   const long long inf = 1e17;   const int mod = 1e9 + 7;   vector<int> edge[maxn];   bool mark[maxn];   int h[maxn];   vector<int> ant;   void dfs(int v) {     mark[v] = true;     if (edge[v].size() == 1) ant.push_back(h[v]);     for (int u : edge[v]) {       if (mark[u]) continue;       h[u] = h[v] + 1;       dfs(u);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int v, u;       cin >> v >> u;       v--;       u--;       edge[u].push_back(v);       edge[v].push_back(u);     }     mark[0] = true;     int ans = 0;     for (int u : edge[0]) {       ant.clear();       dfs(u);       int l = -1;       sort(ant.begin(), ant.end());       for (int i : ant) {         ans = max(ans, max(l + 1, i));         l = max(l + 1, i);       }     }     cout << ans + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, val, ind = 0, counter = 0, ans = 0;     cin >> n >> d;     string v;     cin >> v;     while (ind <= n - 1) {       counter++;       ans = 0;       for (int i = d; i >= 1; i--) {         if (v[ind + i] ==  1 ) {           ind += i;           ans = 1;           break;         }       }       if (!ans) break;       if (ind == n - 1) {         ans = 1;         break;       }     }     if (ans)       cout << counter << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 1;   inline long long input(void) {     char t;     long long x = 0;     int neg = 0;     t = getchar();     while ((t < 48 || t > 57) && t !=  - ) t = getchar();     if (t ==  - ) {       neg = 1;       t = getchar();     }     while (t >= 48 && t <= 57) {       x = (x << 3) + (x << 1) + t - 48;       t = getchar();     }     if (neg) x = -x;     return x;   }   inline void output(long long x) {     char a[20];     int i = 0, j;     a[0] =  0 ;     if (x < 0) {       putchar( - );       x = -x;     }     if (x == 0) putchar( 0 );     while (x) {       a[i++] = x % 10 + 48;       x /= 10;     }     for (j = i - 1; j >= 0; j--) {       putchar(a[j]);     }     putchar(  n );   }   int main() {     long long n, i, a[200010], x[200010], sum, min = 1e9;     n = input();     for (int i = 0; i < n; ++i) a[i] = input();     sort(a, a + n);     for (int i = 0; i < n - 1; ++i) x[i] = a[i + 1] - a[i];     sum = 0;     for (int i = 0; i < n / 2; ++i) sum += x[i];     min = sum;     for (int i = n / 2; i < n - 1; ++i) {       sum = sum + x[i] - x[i - n / 2];       if (sum < min) min = sum;     }     output(min);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     cin >> n >> s;     int *sa = new int[s + 1];     for (int i = 0; i < s + 1; i++) {       sa[i] = 0;     }     for (int i = 0; i < n; i++) {       int tm, tp;       cin >> tm >> tp;       if (sa[tm] < tp) {         sa[tm] = tp;       }     }     int t = 0;     for (int i = s; i > 0; i--) {       if (t < sa[i]) t = sa[i];       t++;     }     cout << t << endl;     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1024;   bool mark[MAXN][MAXN];   int a[MAXN][MAXN], b[MAXN][MAXN];   long long s[MAXN][MAXN];   int main() {     int n, m, r, c;     vector<pair<long long, pair<int, int> > > v, w;     scanf( %d%d%d%d , &n, &m, &r, &c);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         scanf( %d , &a[i][j]);         s[i][j] = a[i][j];       }     }     for (int i = 1; i <= n; ++i) {       copy(a[i], a[i] + m + 1, s[i]);       partial_sum(s[i], s[i] + m + 1, s[i]);       for (int j = 1; j <= m; ++j) {         s[i][j] += s[i - 1][j];       }     }     for (int i = 1; i <= n; ++i) {       multiset<int> st;       for (int j = 1; j <= m; ++j) {         if (j > c) {           st.erase(st.find(a[i][j - c]));         }         st.insert(a[i][j]);         b[i][j] = *st.begin();       }     }     for (int j = 1; j <= m; ++j) {       multiset<int> st;       for (int i = 1; i <= n; ++i) {         if (i > r) {           st.erase(st.find(b[i - r][j]));         }         st.insert(b[i][j]);         a[i][j] = *st.begin();       }     }     for (int i = r; i <= n; ++i) {       for (int j = c; j <= m; ++j) {         v.push_back(make_pair(s[i][j] - s[i - r][j] - s[i][j - c] +                                   s[i - r][j - c] - r * c * (long long)a[i][j],                               make_pair(i, j)));       }     }     sort(v.begin(), v.end());     for (int k = 0; k < (int)v.size(); ++k) {       int x = v[k].second.first;       int y = v[k].second.second;       if (mark[x][y]) {         continue;       }       w.push_back(v[k]);       for (int i = x - r + 1; i < x + r && i <= n; ++i) {         fill(mark[i] + y - c + 1, mark[i] + min(y + c, m + 1), true);       }     }     printf( %d n , (int)w.size());     for (int k = 0; k < (int)w.size(); ++k) {       printf( %d %d %I64d n , w[k].second.first - r + 1,              w[k].second.second - c + 1, w[k].first);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Dicnic {     struct Edge {       int from, to, cap, flow, next;       Edge() {}       Edge(int from, int to, int cap, int flow, int next) {         this->from = from;         this->to = to;         this->cap = cap;         this->flow = flow;         this->next = next;       }     } ed[100005];     int n, m, s, t, lnum, head, tail;     int cur[100005], start[100005], que[100005 * 10], dis[100005];     void init() {       lnum = 0;       for (int i = s; i <= t; i++) start[i] = -1;     }     void add(int x, int y, int c) {       ed[lnum] = Edge(x, y, c, 0, start[x]);       start[x] = lnum++;       ed[lnum] = Edge(y, x, 0, 0, start[y]);       start[y] = lnum++;     }     bool bfs() {       for (int i = s; i <= t; i++) dis[i] = -1;       head = tail = 0;       dis[s] = 0;       que[tail++] = s;       while (head < tail) {         int x = que[head++];         for (int i = start[x]; ~i; i = ed[i].next) {           Edge& e = ed[i];           if (e.cap > e.flow && dis[e.to] == -1) {             dis[e.to] = dis[x] + 1;             que[tail++] = e.to;           }         }       }       return dis[t] != -1;     }     int dfs(int x, int a) {       if (x == t || a == 0) return a;       int flow = 0, f;       for (int& i = cur[x]; ~i; i = ed[i].next) {         Edge& e = ed[i];         if (dis[e.to] == dis[x] + 1 &&             (f = dfs(e.to, min(a, e.cap - e.flow))) > 0) {           e.flow += f;           ed[i ^ 1].flow -= f;           flow += f;           a -= f;           if (!a) break;         }       }       return flow;     }     int Maxflow() {       int flow = 0;       while (bfs()) {         for (int i = s; i <= t; i++) cur[i] = start[i];         flow += dfs(s, 99999999);       }       return flow;     }   } dic;   struct edge {     int to, next;     edge() {}     edge(int to, int next) {       this->to = to;       this->next = next;     }   } ed[405];   int head[105], lnum;   void addline(int from, int to) {     ed[lnum] = edge(to, head[from]);     head[from] = lnum++;   }   int ans[105][105];   void init() {     memset(head, -1, sizeof(head));     memset(ans, 0, sizeof(ans));     lnum = 0;   }   int a[105], b[105];   int main() {     int n, m;     scanf( %d%d , &n, &m);     dic.s = 0, dic.t = 205;     dic.init();     init();     int sum1 = 0, sum2 = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum1 += a[i];     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       sum2 += b[i];     }     int A, B;     for (int i = 0; i < m; i++) {       scanf( %d%d , &A, &B);       addline(A, B);       addline(B, A);     }     for (int j = 1; j <= n; j++) {       dic.add(dic.s, j, a[j]);       dic.add(j + 100, dic.t, b[j]);       dic.add(j, j + 100, a[j]);       for (int i = head[j]; ~i; i = ed[i].next) dic.add(j, ed[i].to + 100, a[j]);     }     int k = dic.Maxflow();     if (k == sum1 && k == sum2) {       printf( YES n );       for (int i = 0; i < dic.lnum; i++) {         if (dic.ed[i].from != dic.s && dic.ed[i].to != dic.t &&             dic.ed[i].from <= 100 && dic.ed[i].to > 100) {           ans[dic.ed[i].from][dic.ed[i].to - 100] += dic.ed[i].flow;         }       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j < n; j++) printf( %d  , ans[i][j]);         printf( %d n , ans[i][n]);       }     } else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<long long, vector<long long>, less<long long> > q;   char nm[100005];   int main() {     long long a, b, c, d, i, j, k, l;     long long n;     while (~scanf( %lld , &n)) {       c = n / 36;       d = n % 36;       a = d / 3;       b = d % 3;       if (b > 1) a += 1;       if (a == 12) {         a = 0;         c += 1;       }       printf( %lld %lld n , c, a);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, save, left, right;     string A;     while (cin >> A) {       left = 0;       right = 0;       for (i = 0; i < A.size(); i++) {         if (A[i] ==  ^ ) {           save = i;         }       }       i = save;       i--;       while (i != -1) {         if (A[i] >=  0  && A[i] <=  9 ) left += (A[i] -  0 ) * (save - i);         i--;       }       int i = save;       i++;       while (i != A.size()) {         if (A[i] >=  0  && A[i] <=  9 ) right += (A[i] -  0 ) * (i - save);         i++;       }       if (left > right)         cout <<  left  << endl;       else if (right > left)         cout <<  right  << endl;       else         cout <<  balance  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, c, d, s = 0, i;   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a >> b >> c >> d;       s = s + (c - a + 1) * (d - b + 1);     }     cout << s;   }


#include <bits/stdc++.h>   const int N = 157, inf = 1e9 + 500;   int n, m, del, t, dis[N];   int ans = inf;   std::queue<int> q;   struct node {     int u, v, w;     bool operator<(const node &a) const { return w < a.w; }   } e[N];   inline int read() {     int x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = (x << 3) + (x << 1) + c - 48, c = getchar();     return x;   }   struct matrix {     std::bitset<N> v[N];     matrix() {       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j) v[i][j] = 0;     }     void I() {       for (int i = 1; i <= n; ++i) v[i][i] = 1;     }     friend matrix operator*(matrix a, matrix b) {       matrix ret;       for (int i = 1; i <= n; ++i) {         for (int k = 1; k <= n; ++k) {           if (a.v[i][k]) ret.v[i] |= b.v[k];         }       }       return ret;     }   } a, g;   matrix qp(matrix base, int p) {     matrix ret;     ret.I();     while (p) {       if (p & 1) ret = ret * base;       base = base * base;       p >>= 1;     }     return ret;   }   void bfs() {     while (!q.empty()) q.pop();     for (int i = 1; i <= n; ++i) dis[i] = inf;     for (int i = 1; i <= n; ++i)       if (a.v[1][i]) q.push(i), dis[i] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v = 1; v <= n; ++v) {         if (g.v[u][v] && dis[v] == inf) {           dis[v] = dis[u] + 1;           q.push(v);         }       }     }   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; ++i)       e[i].u = read(), e[i].v = read(), e[i].w = read();     std::sort(e + 1, e + 1 + m);     a.v[1][1] = 1;     dis[n] = inf;     for (int i = 1; i <= m; ++i) {       if (ans < e[i].w) break;       del = e[i].w - t;       t = e[i].w;       a = a * qp(g, del);       g.v[e[i].u][e[i].v] = 1;       if (i == m || e[i + 1].w != e[i].w) bfs();       ans = std::min(ans, dis[n] + t);     }     if (ans == inf)       puts( Impossible );     else       printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     vector<pair<long long, long long> > p;     for (long long i = 0; i < n; i++) {       double x, y;       cin >> x >> y;       p.push_back(make_pair(x, y));     }     set<pair<double, double> > s;     set<double> e;     long long c;     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; j++) {         double x1 = p[i].first;         double y1 = p[i].second;         double x2 = p[j].first;         double y2 = p[j].second;         if ((x2 - x1) != 0) {           double m = (y2 - y1) / (x2 - x1);           double c = y1 - m * (x1);           s.insert(make_pair(m, c));         } else {           e.insert(x1);         }       }     }     set<pair<double, double> >::iterator it;     vector<long long> r;     long long k = 0;     long long w = 0;     set<pair<double, double> >::iterator itr;     itr = s.begin();     it = s.begin();     it++;     while (it != s.end()) {       long long u = 0;       pair<double, double> gg = *it;       pair<double, double> hh = *itr;       while (gg.first == hh.first) {         u++;         it++;         itr++;         gg = *it;         hh = *itr;       }       if (u != 0) {         w = w + ((u + 1) * u) / 2;       }       it++;       itr++;     }     c = e.size();     long long total = s.size() + c;     total = (total * (total - 1)) / 2;     w = w + ((c - 1) * c) / 2;     cout << (total - w);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int a[maxn], used[maxn], change[maxn];   int n, m, odd, even, sz, ans;   int o = 0, e = 0;   map<int, int> id;   int num[maxn];   int main(void) {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] % 2 == 0)         even++;       else         odd++;       if (!id[a[i]]) id[a[i]] = ++sz;       num[id[a[i]]]++;     }     for (int i = 1; i <= n; i++) {       if (num[id[a[i]]] > 1) {         change[i] = true;         num[id[a[i]]]--;         if (a[i] % 2 == 0)           even--;         else           odd--;         ans++;       }     }     for (int i = 1; i <= n; i++)       if (!change[i]) {         if (odd > n / 2 && a[i] % 2 == 1) {           change[i] = true;           num[id[a[i]]]--;           odd--;           ans++;         } else if (even > n / 2 && a[i] % 2 == 0) {           change[i] = true;           num[id[a[i]]]--;           even--;           ans++;         }       }     for (int i = 1; i <= n; i++)       if (change[i]) {         if (odd < n / 2) {           if (o == 0) o = 1;           while (id[o]) o += 2;           a[i] = o;           id[o] = ++sz;           odd++;         } else if (even < n / 2) {           if (e == 0) e = 2;           while (id[e]) e += 2;           a[i] = e;           id[e] = ++sz;           even++;         }       }     if (o > m || e > m)       printf( -1 n );     else {       printf( %d n , ans);       for (int i = 1; i <= n; i++) {         printf( %d  , a[i]);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int op, d;   int main() {     int nc = 0, bst = 0;     ;     for (cin >> op >> d; d--;) {       string s;       cin >> s;       int c = 0;       for (int i = 0; i < s.size(); ++i)         if (s[i] ==  1 ) ++c;       if (c == op)         nc = 0;       else         ++nc;       bst = max(nc, bst);     }     cout << bst;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-8;   const int mxn = 100033;   const int mod = 1e9 + 7;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) f = c ==  -  ? -1 : 1, c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   inline long long gcd(long long a, long long b) {     return b == 0 ? a : gcd(b, a % b);   }   long long ksm(long long a, long long b, long long mod) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }   void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, y, x, d);       y -= x * (a / b);     }   }   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   int n, a[1010];   map<int, int> ct;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       cin >> n;       int flg = 0;       ct.clear();       for (int i = 1; i <= n; ++i) {         cin >> a[i];         ct[a[i]]++;         if (ct[a[i]] >= 2) flg = 1;       }       if (flg)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(2e5) + 99;   const int INF = int(1e9) + 100;   int t;   int n;   long long s;   pair<int, int> p[N];   bool ok(int mid) {     long long sum = 0;     int cnt = 0;     vector<int> v;     for (int i = 0; i < n; ++i) {       if (p[i].second < mid)         sum += p[i].first;       else if (p[i].first >= mid) {         sum += p[i].first;         ++cnt;       } else         v.push_back(p[i].first);     }     assert(is_sorted(v.begin(), v.end()));     int need = max(0, (n + 1) / 2 - cnt);     if (need > v.size()) return false;     for (int i = 0; i < v.size(); ++i) {       if (i < v.size() - need)         sum += v[i];       else         sum += mid;     }     return sum <= s;   }   int main() {     scanf( %d , &t);     for (int tc = 0; tc < t; ++tc) {       scanf( %d %lld , &n, &s);       for (int i = 0; i < n; ++i) scanf( %d %d , &p[i].first, &p[i].second);       sort(p, p + n);       int lf = 1, rg = INF;       while (rg - lf > 1) {         int mid = (lf + rg) / 2;         if (ok(mid))           lf = mid;         else           rg = mid;       }       printf( %d n , lf);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fast();     int t, b, p, f, h, c;     cin >> t;     while (t--) {       cin >> b >> p >> f;       cin >> h >> c;       int bun = b / 2;       if (bun >= p + f) {         cout << p * h + f * c << endl;       } else {         if (c > h) {           if (bun >= f) {             cout << f * c + (bun - f) * h << endl;           } else {             cout << bun * c << endl;           }         } else {           if (bun >= p) {             cout << p * h + (bun - p) * c << endl;           } else {             cout << bun * h << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define PI 3.14159265   #define pb push_back   #define en cout<<  n    #define vec vector<ll>   #define vecs vector<string>   #define pii pair<ll,ll>   #define VP vector< pii >   #define setbits(x)  __builtin_popcountll(x)   #define zrobits(x)  __builtin_ctzll(x)   #define all(v) (v).begin(),(v).end()   #define ff first   #define ss second   #define mm       #define MM       #define mll map<ll,ll>   #define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)   #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)   #define fa(x,v) for(auto x:v)   #define INF (ll)(9e18)   #define Sort(v) sort(v.begin(),v.end())   #define rsort(v) sort(v.rbegin(),v.rend())   #define test ll T;cin>>T;while(T--)   #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define db1(x) cout<<#x<< = <<x<<  n    #define db2(x,y) cout<<#x<< = <<x<< , <<#y<< = <<y<<  n    #define db3(x,y,z) cout<<#x<< = <<x<< , <<#y<< = <<y<< , <<#z<< = <<z<<  n    #define db4(x,y,z,w) cout<<#x<< = <<x<< , <<#y<< = <<y<< , <<#z<< = <<z<< , <<#w<< = <<w<<  n    #define max3(a,b,c) max(a,max(b,c))   #define min3(a,b,c) min(a,min(b,c))   #define max4(a,b,c,d) max(a,max3(b,c,d))   #define min4(a,b,c,d) min(a,min3(b,c,d))   #define maxi(a) *max_element(a,a+n)   #define mini(a) *min_element(a,a+n)   #define no cout <<  NO  << endl   #define yes cout <<  YES  << endl   #define no2 cout <<  No  << endl   #define yes2 cout <<  Yes  << endl   #define mxheap    priority_queue<int>   #define mnheap    priority_queue<int,vector<int>,greater<int>>   #define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())   #define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())    const ll MOD=1000000000+7;   const ll MOD1 = 998244353;      string itos(ll s)   {   string str=to_string(s);   return str;   }   ll stoi2(string s)   {       ll a= atoi(s.c_str());       return a;   }   template <typename T>   void read(T &p)   {       cin >> p;   }       template <typename T, typename T1>   void read(pair<T, T1> &p)   {       read(p.ff);       read(p.ss);   }       template <typename T>   void read(T arr[], ll n)   {       for (ll i = 0; i < n; i++)       {           read(arr[i]);       }   }       template <typename T>   void read(vector<T> &arr)   {       for (ll i = 0; i < arr.size(); i++)       {           read(arr[i]);       }   }   //////////////////////////////////////       template <typename T>   void out(T& n)   {       cout << n;   }       template <typename T, typename T1>   void out(pair<T, T1> &p)   {       cout <<  ( ;       out(p.ff);       cout <<  , ;       out(p.ss);       cout <<  ) ;       cout<<endl;   }       template <typename T>   void out(T arr[], ll n)   {       for (ll i = 0; i < n; i++)       {           out(arr[i]);           cout <<    ;       }       cout<<endl;   }       template <typename T>   void out(vector<T> &arr)   {           for (ll i = 0; i < arr.size(); i++)       {           out(arr[i]);           if (i!=arr.size()-1)               cout <<    ;       }       cout<<endl;       }               template <typename T>   void out(set<T> &arr)   {       for (auto i:arr)       {           out(i);           cout <<    ;       }       cout<<endl;   }       template <typename T>   void out(multiset<T> &arr)   {       for (auto i:arr)       {           out(i);           cout <<    ;       }       cout<<endl;   }       template <typename T, typename T1>   void out(map<T,T1> &m)   {       for (auto i:m)       {           out(i.first);           cout<<  ->  ;           out(i.second);           cout<< ,  ;       }       cout<<endl;   }   ll powerm(ll a, ll b, ll MOD) {       a %= MOD;       ll res = 1;       while (b > 0) {           if (b & 1)               res = res * a % MOD;           a = a * a % MOD;           b >>= 1;       }       return res;   }      ll power(ll a, ll b) {           ll res = 1;       while (b > 0) {           if (b & 1)               res = res * a ;           a = a * a ;           b >>= 1;       }       return res;   }      bool isSubSequence(string str1, string str2, int m, int n)   {          if (m == 0) return true;       if (n == 0) return false;          if (str1[m-1] == str2[n-1])           return isSubSequence(str1, str2, m-1, n-1);          return isSubSequence(str1, str2, m, n-1);   }         bool ispalindrome(ll len,string str)   {           for(int i = 0; i < len/2; i++){           if(str[i] != str[len-1-i]){               return false;           }       }       return true;   }   inline bool isPowerOfTwo(ll x)   {       return ((1LL << (ll)log2(x)) == x);   }   ll isprime(ll N){       if(N<2 || (!(N&1) && N!=2))           return 0;       for(ll i=3; i*i<=N; i+=2){           if(!(N%i))               return 0;       }       return 1;   }   vec factor;   void factors(ll n)   {          for(ll i=1;i<=sqrt(n);i++)   {       if(n%i==0)       {           if(i==n/i)           factor.pb(i);           else           {               factor.pb(i);               factor.pb(n/i);           }                  }   }       sort(all(factor));   }   ll gcd(ll a, ll b) {       if (b == 0)           return a;       return gcd(b, a % b);     }   ll lcm(ll a,ll b)   {       return (a/gcd(a,b))*b;   }   bool isvalid(ll i,ll j,ll n)   {       if(i>=0&&i<n&&j>=0&&j<n)return true;       return false;   }   ll dx[8]={0,1,1,1,0,-1,-1,-1};   ll dy[8]={-1,-1,0,1,1,1,0,-1};         ll binarytodecimal(string n)   {       string num = n;       ll dec_value = 0;          ll base = 1;          ll len = num.length();       for (int i = len - 1; i >= 0; i--) {           if (num[i] ==  1 )               dec_value += base;           base = base * 2;       }           return dec_value;   }   ll extended_GCD(ll a , ll b , ll &x , ll &y) {       if (a == 0) {           x = 0;           y = 1;           return b;       }       ll x1 , y1;       ll gcd = extended_GCD(b % a , a , x1 , y1);       x = y1 - (b / a) * x1;       y = x1;       return gcd;   }   ll modinv(ll a , ll mod = MOD) {       ll x , y;       extended_GCD(a , mod , x , y);       if (x < 0) x += mod;       return x;   }   string dtb(ll  n )   {          string s=  ;          while(n>0){          if(n%2==0)s.pb( 0 );       else s.pb( 1 );       n/=2;          }          reverse(all(s));   //       while(s.size()<siz)   //    {   //   //        s= 0 +s;   //   //    }       return s;   }   ll getfactorisation(ll n)   {   ll N=5e6+5;     vector<ll>fact(N);     for(int i=0;i<N;i++)fact[i]=i;     for(int i=2;i<N;i+=2)fact[i]=2;         for (ll i=3;i<= N ;i+= 2)          if (i==fact[i])           for (ll j=i*i ; j<N;j+= i)            if (fact[j]== j)fact[j] = i;      vec res;     while(n>1)     {        res.pb(fact[n]);         n/=fact[n];           }     return res.size();   }      long long maxPrimeFactor(long long n)    {        long long maxPrime = -1;             while (n % 2 == 0) {            maxPrime = 2;            n >>= 1; // equivalent to n /= 2        }             for (int i = 3; i <= sqrt(n); i += 2) {            while (n % i == 0) {                maxPrime = i;                n = n / i;            }        }             if (n > 2)            maxPrime = n;             return maxPrime;    }       vec seive;   void Seive() {       const ll maxn = 1e6 + 5;       seive.resize(maxn);       f(i,0, maxn) seive[i] = i;       for(ll i=2;i<=maxn;i+=2)       seive[i] = 2;       seive[1] = -1;       seive[0] = -1;       for (ll i = 3; i <= maxn; i += 2)           if (i == seive[i])           for (ll j = i * i ; j < maxn ; j += i)           if (seive[j] == j)           seive[j] = i;   }   //cout<< Case # <<t<< :  ;   // check integer overflow(s->x+y--s<x)   void factorisation(ll n)   {   vec res;        for(ll i=2;i*i<=n;i++) {               if (n%i==0) {                   while (n%i==0) {                       n/=i;                      res.pb(i);                   }               }           }           if (n>1)               res.pb(n);      }    int numOfDivisors[100005]={0};      void noOfDivisor(){       for(int i=1;i<=100005;i++)           for(int j=i;j<=100005;j+=i){               numOfDivisors[j]++;           }   }      ll fac[200005];   unsigned long long modInverse(unsigned long long n,                                                 int p)   {       return powerm(n, p - 2, p);   }     long long nCrModPFermat(unsigned long long n,                                    int r, int p)   {       if (n < r)           return 0;       if (r == 0)           return 1;    unsigned long long fac[n + 1];       fac[0] = 1;       for (int i = 1; i <= n; i++)           fac[i] = (fac[i - 1] * i) % p;           return (fac[n] * modInverse(fac[r], p) % p               * modInverse(fac[n - r], p) % p)              % p;   }      int main()   {   fast;           ll T=1;     cin>>T;   while(T--)   {     ll n,m,x;     cin>>n>>m>>x;     vec v(n,0);     ll sum=0;     f(i,0,n)cin>>v[i],sum+=v[i];        VP p;     f(i,0,n)     {       p.pb({v[i],i});     }     Sort(p);     reverse(all(p));     mll mp;      ll cur=1;      for(int i=0;i<n;i++)      {           mp[p[i].ss]=cur;           cur++;           if(cur>m)cur=1;      }      yes;      f(i,0,n)       cout<<mp[i]<<MM;   en;         }                                                       }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   int ri() {     int x;     scanf( %d , &x);     return x;   }   int cnt[1000100];   int main() {     int n, m;     scanf( %d %d , &n, &m);     long long ans = (long long)n * (long long)(n - 1) * (long long)(n - 2) / 6LL;     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d %d , &a, &b);       cnt[a]++;       cnt[b]++;     }     long long sub = 0;     for (int i = 1; i <= n; i++) {       if (cnt[i] != 0) {         sub += (long long)cnt[i] * (n - 1 - (long long)cnt[i]);       }     }     ans -= sub / 2LL;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long solve() {     long long n, T, a, b;     cin >> n >> T >> a >> b;     vector<long long> hard(n);     long long x;     long long hardcount = 0, easycount = 0;     for (int i = 0; i < n; ++i) {       cin >> x;       if (x) {         hard[i] = b;         ++hardcount;       } else {         hard[i] = a;         ++easycount;       }     }     vector<long long> mand(n);     for (int i = 0; i < n; ++i) {       cin >> mand[i];     }     vector<pair<long long, long long>> prob(n);     for (int i = 0; i < n; ++i) {       prob[i] = make_pair(mand[i], hard[i]);     }     sort(prob.begin(), prob.end());     int m_easy = 0, m_hard = 0;     long long res = 0;     long long musttime = 0;     for (int i = 0; i < n; ++i) {       long long time = prob[i].first - musttime;       if (time > 0) {         long long solved = m_easy + m_hard;         --time;         solved += min(time / a, easycount - m_easy);         time -= min(time / a, easycount - m_easy) * a;         solved += min(time / b, hardcount - m_hard);         time -= min(time / b, hardcount - m_hard) * b;         res = max(res, solved);       }       if (prob[i].second == b) {         ++m_hard;         musttime += b;       } else {         ++m_easy;         musttime += a;       }     }     long long time = T - musttime;     if (time >= 0) res = n;     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(30);     cout << fixed;     int t;     cin >> t;     while (t--) {       cout << solve() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(T& x) {     cin >> x;   }   template <class H, class T>   void read(pair<H, T>& x) {     read(x.first);     read(x.second);   }   template <class A>   void read(vector<A>& v) {     for (auto& x : v) read(x);   }   template <class H, class... T>   void read(H& h, T&... t) {     read(h);     read(t...);   }   string to_string(const char* c) { return (string)c; }   string to_string(char c) { return (string)    + c; }   string to_string(string second) { return second; }   string to_string(bool b) { return b ?  True  :  False ; }   template <class A>   string to_string(vector<A> v) {     string second;     for (auto& x : v) second += to_string(x) +    ;     return second;   }   template <class H, class... T>   string to_string(H& h, T&... t) {     string second;     second += to_string(h);     second +=    ;     second += to_string(t...);     return second;   }   void print(string second) { cout << second <<   n ; }   template <class... A>   void print(A... a) {     print(to_string(a...));   }   int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }   string tb(int x) {     string ans;     int c = x;     for (int i = log2(x); i >= 0; --i) {       if (pow(2, i) <= c) {         ans +=  1 ;         c -= pow(2, i);       } else {         ans +=  0 ;       }     }     return ans;   }   bool ispr(int x) {     if (x <= 1) {       return false;     }     for (int i = 2; i <= sqrt(x); ++i) {       if (x % i == 0) {         return false;       }     }     return true;   }   struct point {     int x;     int y;   };   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const long long INF = 1e18;   void solve() {     double n, k;     cin >> n >> k;     double dist = 0;     point prev;     read(prev.x, prev.y);     for (int i = 1; i < n; ++i) {       point now;       read(now.x, now.y);       dist += sqrt((now.x - prev.x) * (now.x - prev.x) +                    (now.y - prev.y) * (now.y - prev.y));       prev = now;     }     printf( %.9f , (dist * k) / 50);   }   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     bool isT = 0;     if (isT) {       int t;       cin >> t;       while (t--) {         solve();       }       return 0;     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[100010];   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1, n, i, j;     cin >> n;     int cnt = 0;     for (i = 0; i < n; i++) {       cin >> A[i];       if (A[i] == 1) cnt++;     }     if (cnt) {       cout << n - cnt <<   n ;     } else {       int cur = 0;       for (i = 0; i < n; i++) cur = gcd(cur, A[i]);       if (cur != 1) {         cout <<  -1 n ;       } else {         int mn = n;         for (i = 0; i < n; i++) {           cur = A[i];           for (int j = i + 1; j < n; j++) {             cur = gcd(cur, A[j]);             if (cur == 1) {               mn = min(mn, j - i);               break;             }           }         }         cout << mn + n - 1 <<   n ;       }     }     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, lft, curr = 1;     scanf( %d , &n);     lft = n;     while (lft) {       if (lft == 3) break;       for (int j = 1; j <= (lft + 1) / 2; j++) {         printf( %d  , curr);       }       curr *= 2;       lft -= (lft + 1) / 2;     }     if (lft == 3) {       printf( %d %d %d n , curr, curr, curr * 3);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long long INF = 1e18;   const int MOD = 1e9 + 7;   const long long dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};   const long long Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},                   Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};   long long in() {     long long x;     cin >> x;     return x;   }   void print() { cout <<   n ; }   template <class Head, class... Tail>   void print(Head &&head, Tail &&...tail) {     cout << head;     if (sizeof...(tail) != 0) cout <<    ;     print(forward<Tail>(tail)...);   }   template <class T>   void print(vector<T> &vec) {     for (auto &a : vec) {       cout << a;       if (&a != &vec.back()) cout <<    ;     }     cout <<   n ;   }   template <class T>   void print(set<T> &set) {     for (auto &a : set) {       cout << a <<    ;     }     cout <<   n ;   }   template <class T>   void print(vector<vector<T>> &df) {     for (auto &vec : df) {       print(vec);     }   }   long long power(long long x, long long n) {     long long ret = 1;     while (n > 0) {       if (n & 1) ret *= x;       x *= x;       n >>= 1;     }     return ret;   }   long long comb(long long n, long long k) {     vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));     for (long long i = 0; i < (long long)((v).size()); i++) {       v[i][0] = 1;       v[i][i] = 1;     }     for (long long k = 1; k < (long long)((v).size()); k++) {       for (long long j = 1; j < k; j++) {         v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);       }     }     return v[n][k];   }   void add(long long &a, long long b) {     a += b;     if (a >= MOD) a -= MOD;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   long long ceildiv(long long a, long long b) {     if (b < 0) a = -a, b = -b;     if (a >= 0)       return (a + b - 1) / b;     else       return a / b;   }   long long floordiv(long long a, long long b) {     if (b < 0) a = -a, b = -b;     if (a >= 0)       return a / b;     else       return (a - b + 1) / b;   }   long long floorsqrt(long long x) {     assert(x >= 0);     long long ok = 0;     long long ng = 1;     while (ng * ng <= x) ng <<= 1;     while (ng - ok > 1) {       long long mid = (ng + ok) >> 1;       if (mid * mid <= x)         ok = mid;       else         ng = mid;     }     return ok;   }   template <class T>   bool contain(const std::string &s, const T &v) {     return s.find(v) != std::string::npos;   }   __attribute__((constructor)) void faster_io() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);   }   long long n, m, p;   vector<string> fld;   vector<long long> s;   vector<vector<long long>> vis;   vector<queue<pair<pair<long long, long long>, long long>>> q(9);   void bfs() {     bool changed = true;     while (changed) {       changed = false;       for (long long ni = 0; ni < (long long)(9); ni++) {         while ((!q[ni].empty()) and (q[ni].front().second < s[ni])) {           auto current_pos = q[ni].front();           long long x = current_pos.first.first;           long long y = current_pos.first.second;           long long step = current_pos.second;           q[ni].pop();           for (long long dir = 0; dir < 4; ++dir) {             long long nx = x + dx[dir];             long long ny = y + dy[dir];             if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;             if (fld[nx][ny] ==  # ) continue;             if (vis[nx][ny] == -1) {               q[ni].push(make_pair(make_pair(nx, ny), step + 1));               vis[nx][ny] = ni;               changed = true;             }           }         }         long long sz = (long long)((q[ni]).size());         vector<pair<long long, long long>> tmp;         for (long long si = 0; si < (long long)(sz); si++) {           auto current_pos = q[ni].front();           long long x = current_pos.first.first;           long long y = current_pos.first.second;           long long step = current_pos.second;           q[ni].pop();           tmp.push_back(make_pair(x, y));         }         for (auto i : tmp) {           q[ni].push(make_pair(i, 0LL));         }       }     }   }   signed main() {     cin >> n >> m >> p;     s.assign(p, 0);     vis.assign(n, vector<long long>(m, -1));     for (long long pi = 0; pi < (long long)(p); pi++) {       cin >> s[pi];     }     for (long long ni = 0; ni < (long long)(n); ni++) {       string ss;       cin >> ss;       fld.push_back(ss);     }     for (long long ni = 0; ni < (long long)(n); ni++) {       for (long long mi = 0; mi < (long long)(m); mi++) {         if (fld[ni][mi] !=  .  and fld[ni][mi] !=  # ) {           q[fld[ni][mi] -  1 ].push(make_pair(make_pair(ni, mi), 0LL));           vis[ni][mi] = fld[ni][mi] -  1 ;         }       }     }     bfs();     vector<long long> ans(p);     for (long long ni = 0; ni < (long long)(n); ni++) {       for (long long mi = 0; mi < (long long)(m); mi++) {         if (vis[ni][mi] != -1) ans[vis[ni][mi]]++;       }     }     print(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, idx = 0;     cin >> n >> k;     pair<int, int> inst[n];     vector<int> v;     for (int i = 1; i <= n; i++) {       int t;       cin >> t;       inst[i - 1] = make_pair(t, i);     }     sort(inst, inst + n);     while (k >= inst[idx].first && idx < n) {       v.push_back(inst[idx].second);       k -= inst[idx].first;       idx++;     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }   ll my_exp(ll a, ll b) {     if (b == 0) {       return 1;     } else {       ll temp = my_exp(a, b / 2);       temp *= temp;       if (b % 2 == 1) {         temp *= a;       }       return temp;     }   }   class mycomparison {     bool reverse;       public:     mycomparison(const bool& revparam = false) { reverse = revparam; }     bool operator()(const ll& lhs, const ll& rhs) const {       if (reverse)         return (lhs > rhs);       else         return (lhs < rhs);     }   };   int main() {     std::priority_queue<ll, std::vector<ll>, greater<ll> > fourth;     ll n, m;     vector<ll> insert, getMin, removeMin;     vector<pair<ll, ll> > order;     std::cin >> n;     string a;     for (ll i = 0; i < n; ++i) {       std::cin >> a;       if (a !=  removeMin ) scanf(  %lld n , &m);       if (a ==  insert ) {         order.push_back(make_pair(0, m));         fourth.push(m);       }       if (a ==  removeMin ) {         if (fourth.empty()) {           order.push_back(make_pair(0, 1));           fourth.push(1);         }         order.push_back(make_pair(1, 1));         fourth.pop();       }       if (a ==  getMin ) {         if (fourth.empty()) {           order.push_back(make_pair(0, m));           fourth.push(m);         }         while (fourth.top() < m) {           fourth.pop();           order.push_back(make_pair(1, m));           if (fourth.empty()) {             order.push_back(make_pair(0, m));             fourth.push(m);           }         }         if (fourth.top() == m) {           order.push_back(make_pair(3, m));         } else {           fourth.push(m);           order.push_back(make_pair(0, m));           order.push_back(make_pair(3, m));         }       }     }     std::cout << (ll)order.size() << std::endl;     for (typeof(order.begin()) it = order.begin(); it != order.end(); it++) {       if ((*it).first == 0) {         std::cout <<  insert   << (*it).second << std::endl;       }       if ((*it).first == 1) {         std::cout <<  removeMin  << std::endl;       }       if ((*it).first == 3) {         std::cout <<  getMin   << (*it).second << std::endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};   int a, b, res;   int main() {     scanf( %d%d , &a, &b);     for (int i = a; i <= b; i++) {       int t = i;       while (t) {         res += d[t % 10];         t /= 10;       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   bool voi(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  y  || c ==  o  || c ==  u );   }   long long log_pow(long long b, long long p) {     if (p == 0) return 1;     if (p == 1) return b;     if (p % 2) return b * log_pow(b, p - 1);     long long r = log_pow(b, p / 2);     return r * r;   }   int d5l_i() {     int x;     scanf( %d , &x);     return x;   }   long long d5l_l() {     long long x;     scanf( %lld , &x);     return x;   }   char d5l_c() {     char x;     scanf( %c , &x);     return x;   }   long long fact(int n) {     long long fc = 1;     for (int i = 2; i <= n; i++) fc *= i;     return fc;   }   int len(long long n) {     int c = 0;     while (n) {       n /= 2;       c++;     }     return c;   }   bool why(int a, int b, int c) {     return ((long long)a + b > c && (long long)c + b > a && (long long)c + a > b);   }   int a[100005];   long long ans;   int main() {     int n = d5l_i(), m = d5l_i();     for (int i = 0; i < n; i++) a[i] = d5l_i();     sort(a, a + n);     vector<int> v;     bool flag = false, ops = false;     for (int i = 1; i < a[0]; i++) {       if (ans + i > m) {         ops = true;         break;       }       ans += i;       v.push_back(i);     }     if (!ops)       for (int i = 0; i < n - 1; i++) {         for (int j = a[i] + 1; j < a[i + 1]; j++) {           if (ans + j > m) {             flag = true;             break;           }           ans += j;           v.push_back(j);         }         if (flag) break;       }     if (!flag && !ops)       for (int i = a[n - 1] + 1; i <= 1e9; i++) {         if (ans + i > m) break;         ans += i;         v.push_back(i);       }     printf( %d n , v.size());     for (int i = 0; i < v.size(); i++) printf( %d  , v[i]);   }


#include <bits/stdc++.h>   const long long N = 50050;   const long long Q = 2e18;   const long long mod = 1e9 + 7;   const long long MAGIC = 30;   using namespace std;   int a, b, c, n;   void solve() {     cin >> a >> b >> c >> n;     if (a + b - c >= n || c > a || c > b) {       cout << -1 <<   n ;     } else {       cout << n - (a + b - c) <<   n ;     }   }   bool mtest = false;   int main() {     ios_base::sync_with_stdio(0);     int TE = 1;     if (mtest) cin >> TE;     while (TE--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> vec;   map<long long int, long long int> mp;   int main() {     long long int x = 0, y = 0, z = 0, sum = 0;     cin >> x;     for (int i = 0; i < x; i++) {       cin >> y;       vec.push_back(y);       mp[y]++;     }     sort(vec.begin(), vec.end());     for (int i = 0; i < vec.size(); i++) {       for (int j = 0; j <= 30; j++) {         z = powl(2, j) - vec[i];         if (binary_search(vec.begin() + i + 1, vec.end(), z) == true) {           if (z == vec[i]) {             sum += --mp[z];           } else {             sum += mp[z];           }         }       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     printf(          YES nNO nNO nYES nNO nNO nNO nNO nNO nYES nYES nYES nYES nYES nYES nYES            nNO nYES nNO nYES nYES nNO nYES nNO nNO nYES nNO nNO nYES nYES nNO nYES            nNO nYES nNO nYES nYES nYES nNO nYES nYES nNO nYES nYES nNO nYES nYES n           YES nNO nYES nNO nNO nYES nYES nYES nYES nYES nYES nNO nNO nYES nNO nNO            nNO nNO nNO nNO nNO nNO nNO nYES nNO nYES nNO nNO nNO nYES nYES nNO nYE           S nYES nNO nNO nNO nNO nNO nNO nYES nYES nNO nYES nNO nYES nYES nNO nNO            nNO nYES nYES nYES nYES nYES nNO nNO nNO nYES nNO nYES nNO nYES nNO nYE           S nNO nNO nYES nYES nYES nYES nNO nNO nNO nYES nNO nYES nYES nYES nNO nY           ES nNO nNO nNO nYES nNO nNO nNO nYES nYES nYES nYES nYES nYES nYES nYES            nYES nYES nYES nNO nYES nNO nNO nNO nNO nNO nYES nNO nNO nYES nNO nYES            nNO nYES nNO nYES nNO nYES nYES nYES nNO nNO nYES nNO nNO nNO nNO nYES            nNO nYES nNO nNO nYES nNO nYES nYES nYES nNO nNO nNO nYES nYES nNO nYES            nNO nYES nYES nYES nNO nYES nYES nNO nYES nNO nYES nYES nNO nYES nYES n           NO nNO nYES nNO nNO nNO nYES nYES nNO nYES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   struct State {     int bk;     string fr;     int pos;     int cnt;   };   bool operator<(State lhs, State rhs) {     if (lhs.bk != rhs.bk) return lhs.bk < rhs.bk;     if (lhs.fr != rhs.fr) return lhs.fr < rhs.fr;     if (lhs.pos != rhs.pos) return lhs.pos < rhs.pos;     if (lhs.cnt != rhs.cnt) return lhs.cnt < rhs.cnt;     return false;   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     vector<int> jump(s.size() + 1, 0);     for (int i = 0; i <= s.size(); i++) {       int to = 0;       for (int j = 0; j < i; j++) {         bool ok = true;         for (int k = 0; k < j; k++) {           ok &= (s[k] == s[i - j + k]);         }         if (i != s.size()) ok &= (s[j] != s[i]);         if (ok) to = j + 1 - (int)(i == s.size());       }       jump[i] = to;     }     set<string> subs;     for (int i = 0; i < s.size(); i++) {       for (int j = i + 1; j <= s.size(); j++) {         string ss;         for (int k = i; k < j; k++) {           ss += s[k];         }         subs.insert(ss);       }     }     set<string> lasts;     string ss;     for (int i = s.size() - 1; i >= 0; i--) {       ss = s[i] + ss;       lasts.insert(ss);     }     map<State, ll> dp;     dp[State{-1,   , 0, 0}] = 1;     for (int i = 0; i < n; i++) {       map<State, ll> next;       for (auto &e : dp) {         int bk = e.first.bk;         string str = e.first.fr;         int pos = e.first.pos;         int cnt = e.first.cnt;         if (str !=  @ ) {           str += s[pos];           if (subs.count(str)) {             if (lasts.count(str)) {               bk = i;             }           } else {             str =  @ ;           }         }         if (++pos == s.size()) {           pos = jump[pos];           cnt = true;         }         next[State{bk, str, pos, cnt}] += e.second;         bk = e.first.bk;         str = e.first.fr;         pos = e.first.pos;         cnt = e.first.cnt;         if (str !=  @ ) {           str += (s[pos] ==  0  ?  1  :  0 );           if (subs.count(str)) {             if (lasts.count(str)) {               bk = i;             }           } else {             str =  @ ;           }         }         pos = jump[pos];         next[State{bk, str, pos, cnt}] += e.second;       }       dp = next;     }     ll res = 0;     for (auto &e : dp) {       int bk = e.first.bk;       string strs = e.first.fr;       int pos = e.first.pos;       int cnt = e.first.cnt;       string str;       for (int i = 0; i < e.first.pos; i++) {         str += s[i];       }       for (int i = s.size() - e.first.bk - 1; i < s.size(); i++) {         str += s[i];       }       for (int i = 0; i <= (int)str.size() - (int)s.size(); i++) {         if (s == str.substr(i, s.size())) {           cnt = true;         }       }       if (cnt >= 1) {         res += e.second;       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long int;   using pii = pair<int, int>;   using vi = vector<int>;   using vb = vector<bool>;   using vvi = vector<vector<int>>;   using vlli = vector<long long int>;   using vpii = vector<pair<int, int>>;   const int N = 200005;   const int blockSize = sqrt(N);   lli n, t, l, r, x, idx, L, R, res;   vlli a, ans, cnt(1000005);   vector<tuple<lli, lli, lli, lli>> q;   int get(int idx) { return idx / blockSize; }   void add(lli x) { res += x * (2 * (cnt[x]++) + 1); }   void del(lli x) { res += x * (-2 * (cnt[x]--) + 1); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> t;     a.resize(n);     ans.resize(t);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < t; i++) {       cin >> l >> r;       l--;       r--;       q.push_back(make_tuple(get(l), r, l, i));     }     sort((q).begin(), (q).end());     L = R = 0;     add(a[0]);     for (int i = 0; i < t; i++) {       tie(ignore, r, l, idx) = q[i];       while (L < l) del(a[L++]);       while (L > l) add(a[--L]);       while (R < r) add(a[++R]);       while (R > r) del(a[R--]);       ans[idx] = res;     }     for (int i = 0; i < t; i++) cout << ans[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long a, int p, long long int m) {     if (p == 0) return 1;     if (p & 1) {       return ((a % m) * (bigmod(a, p - 1, m))) % m;     } else {       long long tmp = bigmod(a, p / 2, m);       return (tmp * tmp) % m;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     pair<long long int, long long int> p[n];     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       p[i].first = -x;       p[i].second = i;     }     sort(p, p + n);     vector<long long int> v[n];     vector<pair<long long int, long long int> > p1;     for (long long int i = 0; i < n; i++) {       p1.push_back(make_pair(p[i].second, p[i].first));       sort(p1.begin(), p1.end());       for (long long int t = 0; t < p1.size(); t++) {         v[i].push_back(-p1[t].second);       }     }     long long int m;     cin >> m;     while (m--) {       long long int a;       cin >> a;       long long int b;       cin >> b;       cout << v[a - 1][b - 1];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 3e-5;   double x, h, l;   int main() {     scanf( %lf , &x);     for (double h = 1; h <= 10 + eps; h++) {       if (h + eps < x) continue;       l = h / (sqrt((h * h) / (x * x) - 1)) * 2.0;       for (double q = 1; q <= 10 + eps; q++)         if (l - q < eps && q - l < eps) {           printf( %d %d , (int)q, (int)h);           return 0;         }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a[10], b[10];     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       cin >> b[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i] == b[j]) {           printf( %d , a[i]);           if (i != n - 1) printf(   );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a < b)       return gcd(b, a);     else if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long pow(long long b, long long e) {     if (e == 0)       return 1;     else if (e % 2 == 0) {       long long a = pow(b, e / 2);       return a * a;     } else {       long long a = pow(b, e / 2);       return b * a * a;     }   }   long long powm(long long x, long long y, long long m = 1000000007) {     x = x % m;     long long res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long modInverse(long long a, long long m) { return powm(a, m - 2, m); }   bool issq(long long n) {     long long p = sqrt(n);     return p * p == n;   }   long long MIN(long long a = 2e18, long long b = 2e18, long long c = 2e18,                 long long d = 2e18, long long e = 2e18) {     return min(a, min(b, min(c, min(d, e))));   }   long long MAX(long long a = -2e18, long long b = -2e18, long long c = -2e18,                 long long d = -2e18, long long e = -2e18) {     return max(a, max(b, max(c, max(d, e))));   }   vector<int> prime;   void seive(long long n) {     prime.resize(n + 5, 0);     long long j;     for (long long i = 2; i <= n; i++) {       if (!prime[i]) {         prime[i] = i;         for (j = i * i; j <= n; j += i)           if (!prime[j]) prime[j] = i;       }     }   }   long long extended_GCD(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long gcd = extended_GCD(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return gcd;   }   long long mulInv(long long a, long long mod) {     long long x, y;     extended_GCD(a, mod, x, y);     if (x < 0) x += mod;     return x;   }   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<     << x <<    ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cout <<  { ;     for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long a[n + 1];     long long f = 0;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (a[1] != a[i]) f = 1;     }     if (f == 0)       cout << -1;     else {       long long d = 15e6;       seive(d);       long long hcf = a[1];       for (long long i = 2; i <= n; i++) hcf = gcd(hcf, a[i]);       map<long long, long long> mp;       for (long long i = 1; i <= n; i++) {         a[i] = a[i] / hcf;         long long x = a[i];         while (x != 1) {           long long p = prime[x];           mp[p]++;           while (x % p == 0) x /= p;         }       }       long long ans = 0;       for (auto x : mp) ans = max(ans, x.second);       cout << n - ans;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MID = 1e5;   const int MAX = 1e9;   int main() {     int n;     cin >> n;     if (n % 2) {       cout << n - 9 <<     << 9;     } else {       cout << n - 8 <<     << 8;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7, M = 2e5 + 7;   int n, m, k, t;   vector<int> b;   struct Node {     int in, out;     long long h;     Node() {}     Node(int i, int o, long long _h) : in(i), out(o), h(_h) {}   } a[N];   bool operator<(const Node &a, const Node &b) {     if (a.out == b.out) return a.in < b.in;     return a.out < b.out;   }   long long fen[M];   void add(int i, long long v) {     for (; i <= (int)b.size(); i += i & -i) fen[i] = max(fen[i], v);   }   long long get(int i) {     long long res = 0;     for (; i > 0; i -= i & -i) res = max(res, fen[i]);     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%lld , &a[i].in, &a[i].out, &a[i].h);       b.push_back(a[i].in), b.push_back(a[i].out);     }     sort(a + 1, a + n + 1);     sort(b.begin(), b.end()),         b.resize((int)(unique(b.begin(), b.end()) - b.begin()));     for (int i = n; i > 0; i--) {       k = (lower_bound(b.begin(), b.end(), a[i].out) - b.begin()) + 1;       t = (lower_bound(b.begin(), b.end(), a[i].in) - b.begin()) + 1;       add(t, get(k - 1) + a[i].h);     }     printf( %lld , get((int)b.size()));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     if (n % 3 == 0) {       cout << n / 3 * 2;     }     if (n % 3 > 0) {       cout << (n - 1) / 3 * 2 + 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     vector<long long> vect;     vect.assign(n, 0);     long long ans = 0;     for (int i = 0; i < n; i++) cin >> vect[i];     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       ans += min(vect[a - 1], vect[b - 1]);     }     cout << ans << endl;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / gcd(a, b)) * b;   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   inline long long power(long long a, long long b) {     long long multiply = 1;     for (int i = (1); i <= (b); i++) {       multiply *= a;     }     return multiply;   }   inline long long ABS(long long a) { return (a >= 0) ? a : -a; }   long long n, in, m;   map<long long, vector<long long> > mp;   pair<long long, long long> fact[200003];   int main() {     scanf( %lld , &n);     for (int i = (1); i <= (n); i++) {       scanf( %lld , &in);       mp[in].push_back(i);     }     for (int i = (1); i <= (n); i++) {       scanf( %lld , &in);       mp[in].push_back(i);     }     scanf( %lld , &m);     fact[0] = make_pair(1, 0);     long long ans = 1, cnt, temp;     for (long long i = (1); i <= (200000); i++) {       temp = i;       cnt = 0;       while (temp % 2 == 0) {         temp /= 2;         cnt++;       }       fact[i].first = (fact[i - 1].first * temp) % m;       fact[i].second = cnt + fact[i - 1].second;     }     vector<long long> v;     for (__typeof((mp).begin()) it = (mp).begin(); it != (mp).end(); it++) {       v = it->second;       if (v.size() == 1) continue;       sort(v.begin(), v.end());       ans *= fact[v.size()].first;       ans %= m;       cnt = 0;       for (int i = (1); i <= (v.size() - 1); i++) {         if (v[i] == v[i - 1]) cnt++;       }       ans *= bigmod(2LL, fact[v.size()].second - cnt, m);       ans %= m;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int u, s;     node() { u = s = 0; }     bool operator<(const node &temp) const {       if (this->s < temp.s) return 1;       return 0;     }   };   node black[100005];   node white[100005];   vector<vector<node> > adj;   int main() {     int n;     scanf( %d , &n);     adj.resize(n);     bool allzero = true;     int w, b;     w = b = 0;     for (int i = 0; i < n; ++i) {       int c;       scanf( %d , &c);       if (c == 0) {         white[w].u = i;         scanf( %d , &white[w].s);         if (white[w].s) allzero = false;         ++w;       } else {         black[b].u = i;         scanf( %d , &black[b].s);         if (black[b].s) allzero = false;         ++b;       }     }     if (allzero) {       if (w < b) {         for (int i = 0; i < b; ++i)           cout << white[0].u + 1 <<     << black[i].u + 1 <<     << 0 << endl;         for (int i = 1; i < w; ++i)           cout << white[i].u + 1 <<     << black[i].u + 1 <<     << 0 << endl;       } else {         for (int i = 0; i < w; ++i)           cout << black[0].u + 1 <<     << white[i].u + 1 <<     << 0 << endl;         for (int i = 1; i < b; ++i)           cout << black[i].u + 1 <<     << white[i].u + 1 <<     << 0 << endl;       }       return 0;     }     sort(black, black + b);     sort(white, white + w);     for (int indb = 0, indw = 0; indb < b && indw < w;) {       if (white[indw].s < black[indb].s) {         black[indb].s -= white[indw].s;         adj[black[indb].u].push_back(white[indw]);         ++indw;       } else {         white[indw].s -= black[indb].s;         adj[white[indw].u].push_back(black[indb]);         ++indb;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < adj[i].size(); ++j) {         printf( %d %d %d n , i + 1, adj[i][j].u + 1, adj[i][j].s);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> vs, vs2;   set<string> st;   map<string, int> mp, mp1;   long long i, j, k, x, y, m, n, a, b, c, d, e, f, g, h, l, o, p, q, t, u, v, w,       z, r, ln, neg, pos, sm, ar[500000 + 5], br[500000 + 5], fr[60], cnt;   string s, s1, s2, s3;   int main() {     while (getline(cin, s)) {       ln = s.size();       long long in = 0;       for (int i =  z ; i >=  a ; i--) {         for (j = in; j < ln; j++) {           if (i == (int)s[j]) {             in = max(in, j);             cout << s[j];           }         }       }       cout << endl;     }     return 0;   }