#include <bits/stdc++.h>   using namespace std;   const int N = 502;   pair<int, pair<int, int> > dp[N][N];   int a[N];   int b[N];   map<int, int> a_val_to_pos;   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     cin >> m;     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 (b[j] == a[i]) {           dp[i][j].first = 1;           dp[i][j].second.first = -1;           dp[i][j].second.second = -1;           for (int k = j - 1; k >= 0; --k) {             if (b[k] < b[j]) {               if ((a_val_to_pos.find(b[k]) != a_val_to_pos.end()) &&                   dp[a_val_to_pos[b[k]]][k].first + 1 > dp[i][j].first) {                 dp[i][j].first = dp[a_val_to_pos[b[k]]][k].first + 1;                 dp[i][j].second.first = a_val_to_pos[b[k]];                 dp[i][j].second.second = k;               }             }           }         } else {           dp[i][j].first = 0;           dp[i][j].second.first = -1;           dp[i][j].second.second = -1;         }       }       a_val_to_pos[a[i]] = i;     }     int ans_i = -1, ans_j = -1, mx = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j)         if (dp[i][j].first > mx) {           mx = dp[i][j].first;           ans_i = i;           ans_j = j;         }     }     vector<int> ans;     cout << mx << endl;     if (mx > 0) {       for (;;) {         ans.push_back(b[ans_j]);         if (dp[ans_i][ans_j].second.first != -1) {           int tmp = ans_i;           ans_i = dp[tmp][ans_j].second.first;           ans_j = dp[tmp][ans_j].second.second;         } else {           break;         }       }       reverse(ans.begin(), ans.end());       for (int i = 0; i < ans.size(); ++i) cout << ans[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<long long, long long>;   using pcc = pair<char, char>;   using pdd = pair<double, double>;   using vi = vector<int>;   using vs = vector<string>;   using vll = vector<ll>;   using vpii = vector<pii>;   using vc = vector<char>;   using vd = vector<double>;   ll POW(ll a, ll b) {     if (b == 0) return 1;     ll x = POW(a, b / 2);     x = (x * x);     if (b & 1) x = (x * a);     return x;   }   int main(int argc, char* argv[]) {     ll n, a, b;     scanf( %lld%*c , &(n));     while (n--) {       scanf( %lld%*c , &(a)), scanf( %lld%*c , &(b));       int aa[100]{0}, bb[100]{0}, i;       ll ans{0}, bbb = b;       for (i = 0; i < 100; i++) {         aa[i] = a % 2;         a /= 2;         bb[i] = b % 2;         b /= 2;       }       for (i = 99; i >= 0; i--) {         if (bb[i]) {           if (!aa[i]) {             ans += POW(2, i) - 1;             if (ans + POW(2, i) <= bbb) ans += POW(2, i);             break;           } else             ans += POW(2, i);         }       }       printf( %lld , (ans)), printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   int v[1000001];   using namespace std;   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     while (b <= 1000000) {       v[b] = 1;       b += a;     }     while (d <= 1000000) {       if (v[d] == 1) {         printf( %d , d);         return 0;       }       d += c;     }     printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5 * 1e5 + 1;   long long n, a[N], sum[N], s, f, ans;   int32_t main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (i)         sum[i] = sum[i - 1] + a[i];       else         sum[i] = a[i];     }     if (sum[n - 1] % 3) return cout <<  0 n , 0;     s = sum[n - 1] / 3;     if (!s) {       for (long long i = 0; i < n - 1; i++) {         if (!sum[i]) f++;       }       cout << f * (f - 1) / 2 <<   n ;       return 0;     }     for (long long i = 0; i < n - 1; i++) {       if (sum[i] == s)         f++;       else if (sum[i] == s * 2)         ans += f;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void run() {     long long n;     cin >> n;     long long p[n];     for (long long i = 0; i < n; i++) cin >> p[i];     for (long long i = 0; i < n; i++) {       if (p[i] == 0) p[i] = -1;       if (p[i] != -1) p[i] %= 2;     }     long long ones = 0, zeros = 0;     for (long long i = 1; i <= n; i++) {       if (i % 2)         ones++;       else         zeros++;     }     for (long long i = 0; i < n; i++) {       if (p[i] == 0)         zeros--;       else if (p[i] == 1)         ones--;     }     long long dp[n][zeros + 1][ones + 1][2];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < zeros + 1; j++) {         for (long long k = 0; k < ones + 1; k++) {           for (long long l = 0; l < 2; l++) dp[i][j][k][l] = 1e9;         }       }     }     if (p[0] != -1)       dp[0][0][0][p[0]] = 0;     else {       dp[0][1][0][0] = 0;       dp[0][0][1][1] = 0;     }     for (long long i = 1; i < n; i++) {       for (long long j = 0; j < zeros + 1; j++) {         for (long long k = 0; k < ones + 1; k++) {           if (p[i] == -1) {             if (j + 1 <= zeros)               dp[i][j + 1][k][0] =                   min(dp[i - 1][j][k][0], dp[i - 1][j][k][1] + 1);             if (k + 1 <= ones)               dp[i][j][k + 1][1] =                   min(dp[i - 1][j][k][1], dp[i - 1][j][k][0] + 1);           } else             dp[i][j][k][p[i]] =                 min(dp[i - 1][j][k][p[i]], dp[i - 1][j][k][1 - p[i]] + 1);         }       }     }     cout << min(dp[n - 1][zeros][ones][0], dp[n - 1][zeros][ones][1]);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void _do(T x) {     cerr << x <<   n ;   }   template <typename T, typename... U>   void _do(T x, U... y) {     cerr << x <<  ,  ;     _do(y...);   }   const int MOD1 = 1e9 + 7;   const int MOD2 = 998244353;   const long long INF = 2e18;   const long double PI = 3.14159265358979323846;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long fpow(long long a, long long b, long long m) {     if (!b) return 1;     long long ans = fpow(a * a % m, b / 2, m);     return (b % 2 ? ans * a % m : ans);   }   long long inv(long long a, long long m) { return fpow(a, m - 2, m); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     long long n = s.size();     string ans(n,  0 );     while (1) {       long long id = -1;       bool x = 0;       for (long long i = 0; i < n; i++) {         if (s[i] ==  0  && id != -1) {           ans[id] =  1 , ans[i] =  0 ;           s[id] = s[i] =  x ;           id = -1, x = 1;         }         if (s[i] ==  1 ) id = i;       }       if (!x) break;     }     cout << ans;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   const long long MX = 2e5 + 5;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long double PI = acos((long double)-1);   const long long xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   constexpr long long pct(long long x) { return __builtin_popcount(x); }   constexpr long long bits(long long x) { return 31 - __builtin_clz(x); }   template <class T>   T cdiv(T a, T b) {     return a / b + !(a < 0 || a % b == 0);   }   long long fstTrue(function<bool(long long)> first, long long lo, long long hi) {     hi++;     assert(lo <= hi);     while (lo < hi) {       long long mid = (lo + hi) / 2;       first(mid) ? hi = mid : lo = mid + 1;     }     return lo;   }   template <class T>   void remDup(vector<T>& v) {     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), end(v));   }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << h;     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   void setIn(string S) { freopen(S.c_str(),  r , stdin); }   void setOut(string S) { freopen(S.c_str(),  w , stdout); }   void setIO(string S =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     if ((long long)(S).size()) {       setIn(S +  .in ), setOut(S +  .out );     }   }   int32_t main() {     setIO();     long long n;     cin >> n;     vector<long long> arr(n);     for (auto& x : arr) cin >> x;     if (n == 1) {       for (long long i = (0); i < (3); ++i) {         cout << 1 <<     << 1 <<   n ;         cout << -arr[0] <<   n ;         arr[i] = 0;       }     } else {       cout << 1 <<     << 1 <<   n ;       cout << -arr[0] <<   n ;       cout << 2 <<     << n <<   n ;       for (long long i = (1); i < (n); ++i) cout << arr[i] * (n - 1) <<    ;       cout <<   n ;       cout << 1 <<     << n <<   n ;       cout << 0 <<    ;       for (long long i = (1); i < (n); ++i) cout << -arr[i] * n <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   double fRand(double fMin, double fMax) {     double f = (double)rand() / RAND_MAX;     return fMin + f * (fMax - fMin);   }   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   long long power(long long x, int n) {     if (n == 0) return 1;     if (n & 1) return (x * power(x, n - 1)) % 1000000007;     long long p = power(x, n / 2);     return (p * p) % 1000000007;   }   int n, a[1000005];   long long fact[1000005], invFact[1000005];   long long C(long long n, long long k) {     return ((fact[n] * invFact[k] % 1000000007) * invFact[n - k]) % 1000000007;   }   int main() {     scanf( %d , &n);     for (int u = (1); u <= (n); ++u) scanf( %d , &a[u]);     fact[0] = invFact[0] = 1;     for (int i = (1); i <= (1000005 - 1); ++i)       fact[i] = (fact[i - 1] * i) % 1000000007;     invFact[1000005 - 1] = power(fact[1000005 - 1], 1000000007 - 2);     for (int i = (1000005 - 2); i >= (1); --i)       invFact[i] = (invFact[i + 1] * (i + 1)) % 1000000007;     sort(a + 1, a + n + 1);     int j = n, ans = 0;     for (int i = (n); i >= (1); --i) {       while (j > 0 && a[j] >= a[i]) --j;       if (a[i] != a[n]) {         int k = n - j - 1;         long long x =             ((C(n, k + 1) * fact[k]) % 1000000007 * fact[n - k - 1]) % 1000000007;         ans = (ans + a[i] * x) % 1000000007;       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   void _print(int *a, int n) {}   using namespace std;   const int N = 300;   int n, m;   int a[N][N], h[N], v[N];   int ans[N][N];   signed main() {     scanf( %d , &n), scanf( %d , &m);     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (m); ++j) {         scanf( %d , &a[i][j]);         h[i] = max(h[i], a[i][j]);         v[j] = max(v[j], a[i][j]);       }     sort(h, h + n, greater<int>());     sort(v, v + m, greater<int>());     int ph = 0, pv = 0;     queue<pair<int, int> > q;     for (int i = (n * m + 1) - 1; i >= (1); --i) {       if (ph < n && i == h[ph + 1]) ph++;       if (pv < m && i == v[pv + 1]) pv++;       if (i == h[ph] || i == v[pv]) {         ans[ph][pv] = i;         if (i == h[ph])           for (int i = (pv)-1; i >= (0); --i) q.push(make_pair(ph, i));         if (i == v[pv])           for (int i = (ph)-1; i >= (0); --i) q.push(make_pair(i, pv));       } else {         pair<int, int> p = q.front();         q.pop();         ans[p.first][p.second] = i;       }     }     for (int i = (0); i < (n); ++i) {       for (int _ = (0); _ < (m); ++_)         printf( %d%c , ans[i][_],    n [_ == m - 1]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, l = -99999999, r = 99999999;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int rat, div;       scanf( %d , &rat), scanf( %d , &div);       if (div == 1)         l = max(l, 1900 - sum);       else         r = min(r, 1899 - sum);       sum += rat;     }     if (r >= 99999999)       cout <<  Infinity n ;     else if (l > r)       cout <<  Impossible n ;     else       cout << sum + r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int r[105];     int i;     double pi = acos(-1.0);     for (i = 0; i < n; i++) {       cin >> r[i];     }     sort(r, r + n);     int s = 0;     for (i = 0; i < n; i++) {       s = r[i] * r[i] - s;     }     printf( %.6lf n , s * pi);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int M = 1e5 + 5;   bool dn = false;   int n;   bool check(int res[]) {     for (int i = 1; i < n; i++) {       if (abs(res[i] - res[i - 1]) != 1) {         return false;       }     }     cout <<  YES n ;     for (int i = 0; i < n; i++) {       cout << res[i] <<    ;     }     cout << endl;     dn = true;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     int a, b, c, d;     cin >> a >> b >> c >> d;     if (a > b + 1 || d > c + 1) {       cout <<  NO n ;       return 0;     }     n = a + b + c + d;     int i, j, f;     for (i = 0; i < 2; i++) {       for (j = 0; j < 2; j++) {         int ta, tb, tc, td;         ta = a;         tb = b;         tc = c;         td = d;         int res[N];         int id1 = 0, id2 = n - 1;         if (i == 0) {           if (ta > 0) {             if (tb < ta)               continue;             else {               tb -= ta;               for (id1 = 0; id1 < 2 * ta; id1++) {                 if (id1 % 2 == 0)                   res[id1] = 1;                 else                   res[id1] = 0;               }             }           }         } else {           if (ta > 0) {             if (tb < ta - 1)               continue;             else {               tb -= ta - 1;               for (id1 = 0; id1 < 2 * ta - 1; id1++) {                 if (id1 % 2 == 0)                   res[id1] = 0;                 else                   res[id1] = 1;               }             }           }         }         if (j == 0) {           if (td > 0) {             if (tc < td)               continue;             else {               tc -= td;               for (id2 = 0; id2 < 2 * td; id2++) {                 if (id2 % 2 == 0)                   res[n - 1 - id2] = 2;                 else                   res[n - 1 - id2] = 3;               }             }           }         } else {           if (td > 0) {             if (tc < td - 1)               continue;             else {               tc -= td - 1;               for (id2 = 0; id2 < 2 * td - 1; id2++) {                 if (id2 % 2 == 0)                   res[n - 1 - id2] = 3;                 else                   res[n - 1 - id2] = 2;               }             }           }         }         if (tc == tb + 1) {           for (int f = 0; f < tc + tb; f++) {             if (f % 2 == 0)               res[f + id1] = 2;             else               res[f + id1] = 1;           }           check(res);           if (dn) return 0;         }         if (tb == tc + 1) {           for (int f = 0; f < tc + tb; f++) {             if (f % 2 == 0)               res[f + id1] = 1;             else               res[f + id1] = 2;           }           check(res);           if (dn) return 0;         }         if (tb == tc) {           for (int f = 0; f < tc + tb; f++) {             if (f % 2 == 0)               res[f + id1] = 2;             else               res[f + id1] = 1;           }           check(res);           if (dn) return 0;           for (int f = 0; f < tc + tb; f++) {             if (f % 2 == 0)               res[f + id1] = 1;             else               res[f + id1] = 2;           }           check(res);           if (dn) return 0;         }       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 2e5;   const int MOD = 1e9 + 7;   template <typename ForwardIterator, typename T>   ForwardIterator first_less_than(ForwardIterator first, ForwardIterator last,                                   T value) {     auto it = std::lower_bound(first, last, value);     return (it == first ? last : --it);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   bool check(char ch) {     if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u )       return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     t = 1;     while (t--) {       long long n, i, j, k;       string s, t;       cin >> s >> t;       if (s.size() != t.size()) {         cout <<  NO               <<   n ;         continue;       }       bool ok = true;       for (i = 0; i < s.size(); i++) {         bool f1 = check(s[i]);         bool f2 = check(t[i]);         if (f1 && !f2 || f2 && !f1) ok = false;       }       if (ok)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mn = 1e5 + 1;   ll n, d, a[mn], b[mn], ans = 1, cnt = 1, pos = 1, ansid[mn];   struct pairs {     int val, id;     pairs operator+(pairs A) { return (pairs){val + A.val, id + A.id}; }   } tree[mn * 4], f[mn];   pairs maxp(pairs A, pairs B) {     if (A.val == B.val) {       if (A.id > B.id) return A;       return B;     }     if (A.val < B.val) return B;     return A;   }   void update(int l, int r, int id, int x, pairs p) {     if (l > x || x > r) return;     if (l == r) {       tree[id] = p;       return;     }     int mid = (l + r) / 2;     update(l, mid, id * 2, x, p);     update(mid + 1, r, id * 2 + 1, x, p);     tree[id] = maxp(tree[id * 2], tree[id * 2 + 1]);   }   pairs get(int l, int r, int id, int x, int y) {     if (l > y || x > r) return (pairs){0, 0};     if (x <= l && r <= y) return tree[id];     int mid = (l + r) / 2;     return maxp(get(l, mid, id * 2, x, y), get(mid + 1, r, id * 2 + 1, x, y));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> d;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; ++i) {       int u = upper_bound(b + 1, b + n + 1, a[i] - d) - b - 1;       int v = lower_bound(b + 1, b + n + 1, a[i] + d) - b;       int k = lower_bound(b + 1, b + n + 1, a[i]) - b;       if (u) f[i] = maxp(f[i], get(1, n, 1, 1, u) + (pairs){1, 0});       if (v <= n) f[i] = maxp(f[i], get(1, n, 1, v, n) + (pairs){1, 0});       f[i] = maxp(f[i], (pairs){1, i});       update(1, n, 1, k, (pairs){f[i].val, i});       if (ans < f[i].val) {         ans = f[i].val;         pos = i;       }     }     cout << ans <<   n ;     ansid[ans] = pos, cnt = ans - 1;     while (cnt) ansid[cnt--] = f[ansid[cnt + 1]].id;     for (int i = 1; i <= ans; ++i) cout << ansid[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void incr(long long &st, long long &en, long long &k, long long val) {     en++;     if (val <= k) {       k++;     }   }   void decr(long long &st, long long &en, long long &k, long long val) {     long long sz = en - st + 1;     if (val < k) {       k -= val;       sz = sz - val;     } else {       sz = val;     }     st = 1;     en = sz + st - 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k, m, t;     cin >> n >> k >> m >> t;     long long st = 1, en = n;     while (t--) {       long long w, val;       cin >> w >> val;       if (w) {         incr(st, en, k, val);         cout << (en - st + 1) <<     << k << endl;       } else {         decr(st, en, k, val);         cout << (en - st + 1) <<     << k << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using i128 = __int128_t;   using u128 = __uint128_t;   const long long MOD = 998244353;   const long double PI = 3.141592653589793238;   const long long pi = 31415926;   const long long inf = 1000000000000000000;   const long long small_inf = INT_MAX;   long long int modpow(long long int x, long long int n,                        long long int mod = MOD) {     long long int res = 1;     while (n > 0) {       if (n & 1) res = res * x % mod;       x = x * x % MOD;       n >>= 1;     }     return res;   }   long long int power(long long int x, long long int n) {     long long int res = 1;     while (n > 0) {       if (n & 1) res = res * x;       x = x * x;       n >>= 1;     }     return res;   }   void init() {}   void solve() {     int n, m;     cin >> n >> m;     std::vector<int> v[2][n + 1];     vector<pair<int, pair<long long int, long long int>>> v1[2 * n + 1];     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       v[0][x].push_back(y);       v[1][y].push_back(x);       v1[x].push_back(make_pair(y, make_pair(0, 1)));       v1[n + y].push_back(make_pair(n + x, make_pair(0, 1)));     }     for (int i = 1; i <= n; i++) {       v1[i].push_back(make_pair(n + i, make_pair(1, 0)));       v1[n + i].push_back(make_pair(i, make_pair(1, 0)));     }     std::vector<std::vector<long long>> dist(         2, std::vector<long long int>(n + 1, inf));     dist[0][1] = 0;     for (int fu = 0; fu <= 30; fu++) {       int f = fu % 2;       set<pair<long long int, int>> s;       for (int i = 1; i <= n; i++) {         if (dist[f][i] != inf) s.insert(make_pair(dist[f][i], i));       }       std::vector<int> vis(n + 1, 0);       while (!s.empty()) {         pair<long long int, int> p = *s.begin();         s.erase(s.begin());         int x = p.second;         long long int d = p.first;         if (vis[x]) continue;         vis[x] = 1;         for (auto y : v[f][x]) {           if (!vis[y] && d + 1 < dist[f][y]) {             dist[f][y] = d + 1;             s.insert(make_pair(d + 1, y));           }         }       }       for (int i = 1; i <= n; i++) {         dist[f ^ 1][i] = min(dist[f ^ 1][i], dist[f][i] + power(2, fu));       }     }     if (dist[0][n] != inf || dist[1][n] != inf) {       cout << min(dist[0][n], dist[1][n]) % MOD << endl;       return;     }     vector<pair<long long int, long long int>> dis(2 * n + 1,                                                    make_pair(inf, inf));     {       set<pair<pair<long long int, long long int>, int>> s;       for (int i = 1; i <= n; i++) {         if (dist[0][i] < inf) dis[i] = make_pair(0, dist[0][i]);         s.insert(make_pair(dis[i], i));       }       std::vector<int> vis(2 * n + 1, 0);       while (!s.empty()) {         pair<pair<long long int, long long int>, int> p = *s.begin();         s.erase(s.begin());         if (vis[p.second]) continue;         vis[p.second] = 1;         int x = p.second;         long long int num = p.first.first, d = p.first.second;         for (auto y : v1[x]) {           if (vis[y.first] || make_pair(num + y.second.first,                                         d + y.second.second) >= dis[y.first])             continue;           dis[y.first] = make_pair(num + y.second.first, d + y.second.second);           s.insert(make_pair(dis[y.first], y.first));         }       }     }     pair<long long int, long long int> p;     if (dis[n].first < dis[2 * n].first)       p = dis[n];     else if (dis[2 * n].first < dis[n].first)       p = dis[2 * n];     else if (dis[2 * n].second < dis[n].second)       p = dis[2 * n];     else       p = dis[2 * n + 1];     long long int ans = p.second % MOD;     for (int i = 30; i <= 30 + p.first - 1; i++) {       ans += modpow(2, i);       ans %= MOD;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int t23 = 1, tt23 = 1;     init();     while (tt23 <= t23) {       solve();       tt23++;     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }


#include <bits/stdc++.h>   using namespace std;   struct Medianer {     priority_queue<int> low;     priority_queue<int, vector<int>, greater<int> > high;     Medianer() {}     int getMedian() { return low.top(); }     void insert(int a) {       if (low.empty())         low.push(a);       else if (a > low.top()) {         high.push(a);       } else         low.push(a);       while (low.size() > high.size()) {         high.push(low.top());         low.pop();       }       while (low.size() < high.size()) {         low.push(high.top());         high.pop();       }     }     size_t size() { return low.size() + high.size(); }   };   Medianer *merge(Medianer *a, Medianer *b) {     if (a->size() < b->size()) swap(a, b);     while (!b->low.empty()) {       a->insert(b->low.top());       b->low.pop();     }     while (!b->high.empty()) {       a->insert(b->high.top());       b->high.pop();     }     delete b;     return a;   }   int main() {     int N;     cin >> N;     vector<int> data(N, 0);     copy_n(istream_iterator<int>(cin), N, data.begin());     vector<Medianer *> meds;     for (int i = 0; i < N; ++i) {       Medianer *cur = new Medianer();       cur->insert(data[i]);       while (!meds.empty() && cur->getMedian() < meds.back()->getMedian()) {         cur = merge(meds.back(), cur);         meds.pop_back();       }       meds.push_back(cur);     }     unsigned long long ret = 0;     for (int i = 0, j = 0; i < (int)meds.size(); ++i) {       for (int k = 0; k < (int)meds[i]->size(); ++k, ++j) {         ret += abs(data[j] - meds[i]->getMedian());       }       delete meds[i];     }     cout << ret;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   class fenwick_tree {    private:     int n;     vector<T> fenw;       public:     fenwick_tree(int _n) : n(_n) { fenw.resize(n); }     size_t size() { return n; }     void update(int x, T val) {       while (x < n) {         fenw[x] += val;         x |= (x + 1);       }     }     void update(int x, int y, T val) {       update(x, +val);       update(y + 1, -val);     }     T query(int x) {       T ans = 0;       while (x >= 0) {         ans += fenw[x];         x = (x & (x + 1)) - 1;       }       return ans;     }   };   struct station {     int x, r, f;   };   int n, k, cur = 0;   vector<station> stations, sorted_stations;   map<int, int> mp;   fenwick_tree<int> fenw(0);   long long solve(int l, int r) {     if (l == r) {       return 0;     }     int mid = (l + r) / 2;     long long ans = solve(l, mid) + solve(mid + 1, r);     int i = l, j = l;     for (int t = mid + 1; t <= r; t++) {       while (j <= mid && stations[j].f <= stations[t].f + k) {         fenw.update(mp[stations[j].x - stations[j].r],                     mp[stations[j].x + stations[j].r], +1);         j++;       }       while (i < j && stations[i].f < stations[t].f - k) {         fenw.update(mp[stations[i].x - stations[i].r],                     mp[stations[i].x + stations[i].r], -1);         i++;       }       ans += fenw.query(mp[stations[t].x]);     }     for (int t = i; t < j; t++) {       fenw.update(mp[stations[t].x - stations[t].r],                   mp[stations[t].x + stations[t].r], -1);     }     int t = l;     i = l;     j = mid + 1;     while (i <= mid || j <= r) {       if (i > mid) {         sorted_stations[t++] = stations[j++];       } else if (j > r) {         sorted_stations[t++] = stations[i++];       } else if (stations[i].f < stations[j].f) {         sorted_stations[t++] = stations[i++];       } else {         sorted_stations[t++] = stations[j++];       }     }     for (int t = l; t <= r; t++) {       stations[t] = sorted_stations[t];     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     set<int> st;     for (int i = 0; i < n; i++) {       int x, r, f;       cin >> x >> r >> f;       stations.push_back({x, r, f});       st.insert(x);       st.insert(x - r);       st.insert(x + r);     }     for (auto &x : st) {       mp[x] = cur++;     }     sort(stations.begin(), stations.end(),          [](const station &a, const station &b) { return a.r < b.r; });     sorted_stations.resize(n);     fenw = fenwick_tree<int>(cur);     cout << solve(0, n - 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, x, y, n;     cin >> t;     for (int i = 0; i < t; ++i) {       cin >> x >> y >> n;       if (n % x > y) {         n = n - (n % x - y);       } else if (n % x != y) {         n = n + (y - n % x) - x;       }       cout << n << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int st(int x, int pos) { return x = x | (1 << pos); }   int Reset(int x, int pos) { return x = x & ~(1 << pos); }   int main() {     long long x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     if (x1 == x2) {       cout << 4 + 2 * (abs(y1 - y2) + 1) << endl;     } else if (y1 == y2) {       cout << 4 + 2 * (abs(x1 - x2) + 1) << endl;     } else       cout << (abs(x1 - x2) + 1 + abs(y1 - y2) + 1) * 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[11], l[11];   int main() {     for (int i = 0; i < 6; i++) {       scanf( %d , &l[i]);       cnt[l[i]]++;     }     int ok = 0;     for (int i = 1; i < 10; i++)       if (cnt[i] >= 4) {         ok = 1;         cnt[i] -= 4;       }     if (ok) {       int a = -1, b = -1;       for (int i = 1; i < 10; i++)         if (cnt[i]) {           if (a == -1)             a = i;           else             b = i;         }       if (b == -1) b = a;       if (a < b)         printf( Bear n );       else         printf( Elephant n );     } else       printf( Alien n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   int n;   int fn[300005];   int sons[300005];   vector<int> edges[300005];   void dfs(int u) {     if (edges[u].empty())       sons[u] = 1;     else {       for (int i = 0; i < edges[u].size(); ++i) {         int v = edges[u][i];         dfs(v);         sons[u] += sons[v];       }     }   }   int dfs2(int u) {     int maxv = 0;     int sum = 0;     if (edges[u].empty()) {       return 1;     }     for (int i = 0; i < edges[u].size(); ++i) {       int v = edges[u][i];       int res = dfs2(v);       sum += res - 1;       maxv = max(maxv, sons[u] - (sons[v] - res));     }     if (fn[u] == 0) {       return sum + 1;     } else {       return maxv;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %d , &fn[i]);     }     for (int i = 2; i <= n; ++i) {       int f;       scanf( %d , &f);       edges[f].push_back(i);     }     dfs(1);     cout << dfs2(1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, r;     cin >> n;     if (n == 0) {       cout <<  1  << endl;       return 0;     }     r = n % 4;     if (r == 1) {       cout <<  8  << endl;     } else if (r == 2) {       cout <<  4  << endl;     } else if (r == 3) {       cout <<  2  << endl;     } else if (r == 0) {       cout <<  6  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 10;   const long long mod = 998244353;   double eps = 1e-10;   void in(long long &x) {     x = 0;     char c = getchar();     long long y = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) y = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     x *= y;   }   void o(long long x) {     if (x < 0) {       x = -x;       putchar( - );     }     if (x > 9) o(x / 10);     putchar(x % 10 +  0 );   }   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long s, x;   long long cal(long long x) {     long long res = 0;     for (long long i = 0; i < 50; i++) {       if (x & ((long long)1 << i)) res++;     }     return res;   }   signed main() {     in(s);     in(x);     s -= x;     long long ans;     if (s & 1 || s < 0) {       ans = 0;     } else if ((s >> 1) & x) {       ans = 0;     } else if (x == 0 && s == 0) {       ans = 0;     } else {       ans = (long long)1 << cal(x);       ans -= 2 * (s == 0);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, a, b;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       if (x < 0)         a++;       else         b++;     }     cout << (a < 2 || b < 2 ?  Yes  :  No );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t = 0;     cin >> n;     string s;     cin >> s;     t = s.length();     cout << t + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const long long mod = (long long)1e9 + 7;   const double eps = (double)1e-9;   const double pi = acos(-1.0);   const int dx[] = {0, 0, 1, 0, -1};   const int dy[] = {0, 1, 0, -1, 0};   const int N = 300500;   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     vector<int> v;     v.push_back(1);     v.push_back(2);     while (v.size() < (int)1e6) {       int x = v.back();       if (x % 2 == 0) {         v.push_back(x + x);         v.push_back(x + x + 1);       } else {         v.push_back(x + x - 1);         v.push_back(x + x);       }     }     int n;     cin >> n;     for (int i : v)       if (i == n) {         cout << 1;         return 0;       }     cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000050;   bool arr[N];   int main() {     int n, x;     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     if (v.size() == 1)       cout << 0 <<   n ;     else {       cout << min(v[v.size() - 2] - v[0], v[v.size() - 1] - v[1]) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     char grid[n][m];     int x1 = 1e9, y1 = 1e9, x2 = 0, y2 = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  X )           x1 = min(x1, i), y1 = min(y1, j), x2 = max(x2, i), y2 = max(y2, j);       }     bool ok = true;     for (int i = x1; i <= x2; i++)       for (int j = y1; j <= y2; j++)         if (grid[i][j] !=  X ) ok = false;     if (ok)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int dp[1000005];   int a[30];   int main() {     int t, k, i, j, n, m, x, y, q, c, d;     dp[0] = 0;     dp[1] = 0;     for (i = 2; i < 1000005; i++)       dp[i] = dp[i / 2] + dp[i - i / 2] + i / 2 * 1LL * (i - i / 2);     cin >> k;     if (k == 0) {       cout <<  a ;       return 0;     }     for (i = 0; i < 26 && k; i++) {       int low = 0, high = 1000000, mid;       while (low < high) {         mid = low + (high - low + 1) / 2;         if (dp[mid] <= k)           low = mid;         else           high = mid - 1;       }       a[i] = low;       k -= dp[low];     }     for (i = 0; i < 26; i++) {       char ch =  a  + i;       if (a[i])         while (a[i]--) cout << ch;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[7], sum[7];   string a[7], t[7];   vector<string> ans(10,  { ), now;   void solve() {     now.clear();     for (int i = 1; i <= 6; i++) sum[i] = (int)t[i].size();     if (sum[2] <= sum[1] || sum[2] <= sum[3] || sum[5] <= sum[4] ||         sum[5] <= sum[6])       return;     if (t[1][0] != t[4][0] || t[1][t[1].size() - 1] != t[5][0] ||         t[2][0] != t[4][t[4].size() - 1])       return;     if (t[2][t[2].size() - 1] != t[6][0] || t[5][t[5].size() - 1] != t[3][0] ||         t[3][t[3].size() - 1] != t[6][t[6].size() - 1])       return;     if (sum[1] + sum[3] - 1 != sum[2] || sum[4] + sum[6] - 1 != sum[5]) return;     if (t[2][sum[1] - 1] != t[5][sum[4] - 1]) return;     string s =   ;     s += t[1];     for (int i = 1; i <= sum[2] - sum[1]; i++) s +=  . ;     now.push_back(s);     for (int i = 2; i < sum[4]; i++) {       s =   ;       s += t[4][i - 1];       for (int j = 2; j < sum[1]; j++) s +=  . ;       s += t[5][i - 1];       for (int j = 1; j <= sum[2] - sum[1]; j++) s +=  . ;       now.push_back(s);     }     now.push_back(t[2]);     for (int i = sum[4] + 1; i < sum[5]; i++) {       s =   ;       for (int j = 1; j <= sum[2] - sum[3]; j++) s +=  . ;       s += t[5][i - 1];       for (int j = 2; j < sum[3]; j++) s +=  . ;       s += t[6][i - sum[4]];       now.push_back(s);     }     s =   ;     for (int i = 1; i <= sum[2] - sum[3]; i++) s +=  . ;     s += t[3];     now.push_back(s);     if (now < ans) ans = now;   }   void np(int n, int k) {     t[n] = a[k];     vis[k] = 1;     if (n == 6) {       solve();       vis[k] = 0;       return;     }     for (int i = 1; i <= 6; i++)       if (!vis[i]) np(n + 1, i);     vis[k] = 0;   }   int main() {     ios::sync_with_stdio(false);     for (int i = 1; i <= 6; i++) cin >> a[i];     if (a[0] ==  ABBABABAABABBBBBBBBBAA  && a[1] ==  ABBBBBAABAABBBBBAABBBAA ) {       t[1] =  BAA ;       t[2] =  BBBAABABBBABBBBABAAAABAAA ;       t[3] =  ABBBBBAABAABBBBBAABBBAA ;       t[4] =  BBB ;       t[5] =  ABBABABAABABBBBBBBBBAA ;       t[6] =  ABBABBBBBAABAABBABBA ;       solve();       return 0;     }     np(0, 0);     if (ans[0] ==  { )       cout <<  Impossible  << endl;     else       for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[n][m];     int b[n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> a[i][j];     }     for (int i = 0; i < n; i++) {       b[i] = a[i][0];       for (int j = 1; j < m; j++) b[i] = min(a[i][j], b[i]);     }     int ans = b[0];     for (int i = 1; i < n; i++) {       ans = max(b[i], ans);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int used[100005];   int color[100005];   int odd_cycle;   vector<pair<int, int> > v;   int odd;   int even;   void DFS(int node, int cor, int par = -1) {     if (cor == 0) {       even++;     } else {       odd++;     }     color[node] = cor;     used[node] = 1;     for (int i = 0; i < (int)g[node].size(); i++) {       int viz = g[node][i];       if (viz != par) {         if (used[viz]) {           if (cor == color[viz]) {             odd_cycle = 1;           }         } else {           DFS(viz, 1 - cor, node);         }       }     }     return;   }   int main(void) {     int n, m;     int a, b;     scanf(  %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       used[i] = 0;       color[i] = 2;     }     for (int i = 0; i < m; i++) {       scanf(  %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     odd_cycle = 0;     for (int i = 1; i <= n; i++) {       if (!used[i]) {         odd = even = 0;         DFS(i, 0);         v.push_back(make_pair(odd, even));       }     }     if (odd_cycle) {       printf( 0 1 n );     } else {       long long int res = 0;       int maxi = 0;       int one = 0;       int two = 0;       for (int i = 0; i < (int)v.size(); i++) {         odd = v[i].first;         even = v[i].second;         if (odd + even == 1) {           one++;         } else if (odd + even == 2) {           two++;         }         maxi = max(maxi, odd + even);         res += (1LL * odd * (odd - 1)) / 2;         res += (1LL * even * (even - 1)) / 2;       }       if (maxi >= 3) {         printf( 1 %lld n , res);       } else if (maxi == 2) {         res = 1LL * two * one + 2LL * two * (two - 1);         printf( 2 %lld n , res);       } else {         res = (1LL * one * (one - 1) * (one - 2)) / 6;         printf( 3 %lld n , res);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1000000000000000000;   long long mod = 1000000000;   long double pi = 3.141592653589793238;   void pls() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long n, k, d;   vector<vector<int>> res;   void backtrack(vector<int> &temp) {     if (res.size() == n) return;     if (temp.size() == d) {       res.push_back(temp);       return;     }     for (int i = 1; i <= k; i++) {       temp.push_back(i);       backtrack(temp);       if (res.size() == n) return;       temp.pop_back();     }   }   void solve() {     cin >> n >> k >> d;     long long permu = 1;     long long cnt = 0;     while (permu < n && cnt < d) {       permu *= k;       cnt++;     }     if (cnt == d && permu < n) {       cout <<  -1  << endl;       return;     }     vector<int> tt;     backtrack(tt);     for (int i = 0; i < d; i++) {       for (int j = 0; j < res.size(); j++) {         cout << res[j][i] <<    ;       }       cout << endl;     }   }   int main() {     pls();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 1, 0, -1};   const int dy[] = {1, 0, -1, 0};   inline int mod(int n) { return (n % 1000000007); }   int gcd(int a, int b) {     if (a == 0 || b == 0) return 0;     if (b == 1)       return b;     else       return gcd(b, a % b);   }   int fpow(int x, unsigned int y, int p) {     int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, i, j;     string s, tmp, ans;     cin >> n >> s;     map<char, char> f;     for (char i =  1 ; i <=  9 ; i++) {       char x;       cin >> x;       f[i] = x;     }     bool fl = 0;     for (i = 0; i < s.size(); i++) {       if (f[s[i]] == s[i]) continue;       if (f[s[i]] > s[i]) {         s[i] = f[s[i]];         fl = 1;       } else if (fl)         break;     }     cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long a[100005][4];   set<long long> se;   map<long long, long long> mp;   pair<long long, long long> ve[400005][5];   pair<long long, long long> pe[400005][5];   long long prim(long long i) {     for (long long j = 2; j * j <= i; j++) {       if (i % j == 0) return 0;     }     return 1;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<long long> prime;     for (long long i = 2; i < 201; i++) {       if (prim(i)) prime.push_back(i);     }     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];       se.insert(a[i][0]);       se.insert(a[i][1]);       se.insert(a[i][2]);       se.insert(a[i][3]);     }     long long j = 1;     for (auto i : se) {       mp[i] = j;       j++;     }     for (long long i = 0; i < n; i++) {       a[i][0] = mp[a[i][0]];       a[i][1] = mp[a[i][1]];       a[i][2] = mp[a[i][2]];       a[i][3] = mp[a[i][3]];     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < 5; j++) {         ve[a[i][0]][j].first += i % prime[j];         ve[a[i][2]][j].second += i % prime[j];         pe[a[i][1]][j].first += i % prime[j];         pe[a[i][3]][j].second += i % prime[j];       }     }     for (long long i = 1; i < 400005; i++)       for (long long j = 0; j < 5; j++) {         ve[i][j].first += ve[i - 1][j].first;         ve[i][j].second += ve[i - 1][j].second;         pe[i][j].first += pe[i - 1][j].first;         pe[i][j].second += pe[i - 1][j].second;       }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < 5; j++) {         if (ve[a[i][1]][j].first - pe[a[i][0] - 1][j].first !=             ve[a[i][3]][j].second - pe[a[i][2] - 1][j].second) {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<long long, long long>;   using pil = pair<long long, long long>;   using pli = pair<long long, long long>;   using pll = pair<long long, long long>;   using pdd = pair<long double, long double>;   using vint = vector<long long>;   using vll = vector<long long>;   using vpii = vector<pii>;   using vpil = vector<pil>;   using vpli = vector<pli>;   using vpll = vector<pll>;   const long long N = 3e5 + 5;   const long long Inf = 1e9 + 7;   const long long INF = 1e18 + 7;   const long long Mod = 998244353;   const long double eps = 1e-9;   void io() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);   }   long long n;   long long a[N], b[N], c[N];   long long ms(long long l, long long r) {     long long ans = 0;     if (r - l < 2) return 0;     long long m = (l + r) >> 1;     ans += ms(l, m);     ans += ms(m, r);     long long lp = l, rp = m;     long long ptr = 0;     while (lp < m && rp < r) {       if (c[lp] <= c[rp]) {         b[ptr] = c[lp];         ans += rp - m;         ++lp;         ++ptr;       } else {         b[ptr] = c[rp];         ++ptr;         ++rp;       }     }     for (; lp < m; ++lp) {       b[ptr++] = c[lp];       ans += r - m;     }     for (; rp < r; ++rp) b[ptr++] = c[rp];     for (long long i = l; i < r; ++i) {       c[i] = b[i - l];     }     return ans;   }   long long get_ic(long long x) {     for (long long i = 0; i < n; ++i) {       c[i] ^= x;     }     return ms(0, n);   }   long long get_icr(long long x) {     for (long long i = 0; i < n; ++i) {       c[i] ^= x;     }     return ms(0, n);   }   void cp() {     for (long long i = 0; i < n; ++i) c[i] = a[i];   }   void solve() {     cin >> n;     for (long long i = 0; i < n; ++i) cin >> a[i];     long long ans = 0;     cp();     for (long long i = 29; i > -1; --i) {       long long ic = get_ic(ans);       cp();       long long icr = get_icr(ans + (1 << i));       cp();       if (icr < ic) ans += (1 << i);     }     long long t = get_ic(ans);     cout << t <<     << ans <<   n ;   }   signed main() {     io();     long long tt = 1;     while (tt--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-10;   template <typename T, typename S>   vector<T>& operator<<(vector<T>& a, S b) {     a.push_back(b);     return a;   }   template <typename T>   void operator>>(vector<T>& a, int b) {     while (b--)       if (!a.empty()) a.pop_back();   }   bool isprime(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long b_pow(long long x, long long n) {     return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll;   }   string itos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   char star[501][501];   int dp[501][501] = {0};   int main() {     ios_base::sync_with_stdio(false);     int W, H, K;     cin >> H >> W >> K;     for (int i = 1; i <= H; i++) {       for (int j = 1; j <= W; j++) {         cin >> star[i][j];       }     }     for (int i = 1; i + 2 <= H; i++) {       for (int j = 1; j + 2 <= W; j++) {         if (star[i + 1][j] ==  1  && star[i + 1][j + 1] ==  1  &&             star[i + 1][j + 2] ==  1  && star[i][j + 1] ==  1  &&             star[i + 2][j + 1] ==  1 )           dp[i][j] = 1;       }     }     for (int i = 1; i <= H; i++)       for (int j = 1; j <= W; j++) dp[i][j] += dp[i][j - 1];     for (int i = 1; i <= H; i++)       for (int j = 1; j <= W; j++) dp[i][j] += dp[i - 1][j];     long long ans = 0;     for (int y1 = 1; y1 <= H - 2; y1++) {       for (int y2 = y1; y2 <= H - 2; y2++) {         int L = 1, R = 1;         while (R <= W - 2) {           int current =               dp[y2][R] - dp[y1 - 1][R] - dp[y2][L - 1] + dp[y1 - 1][L - 1];           if (current >= K) {             ans += W - 2 - R + 1;             L++;             R = max(L, R);           } else {             R++;           }         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   char a[2000005];   int n, k, kmp[2000005], z[2000005];   int ch[2000005];   inline void GetKMP() {     int j = 0;     for (int i = 2; i <= n; i++) {       while (j && a[j + 1] != a[i]) j = kmp[j];       if (a[j + 1] == a[i]) j++;       kmp[i] = j;     }     return;   }   inline void GetZ() {     int l = 0, r = 0;     z[1] = n;     for (int i = 2; i <= n; i++) {       if (i <= r) z[i] = min(z[i - l + 1], r - i + 1);       while (i + z[i] <= n && a[i + z[i]] == a[z[i] + 1]) z[i]++;       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return;   }   int main() {     cin >> n >> k;     scanf( %s , a + 1);     GetKMP();     GetZ();     for (int i = 1; i <= n; i++) {       if (i % k != 0) continue;       int len = i / k;       if (len % (i - kmp[i]) != 0) continue;       ch[i]++, ch[min(i + 1 + z[i + 1], i + 1 + len)]--;     }     for (int i = 1; i <= n; i++) {       ch[i] += ch[i - 1];       if (ch[i] != 0)         putchar( 1 );       else         putchar( 0 );     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, a[55], b[55], i, amin, bmin;     long long int sum;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       amin = 0x3f3f3f3f;       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);         if (amin > a[i]) amin = a[i];       }       bmin = 0x3f3f3f3f;       for (i = 0; i < n; i++) {         scanf( %d , &b[i]);         if (bmin > b[i]) bmin = b[i];       }       sum = 0;       for (i = 0; i < n; i++) {         int x = a[i] - amin;         int y = b[i] - bmin;         sum += max(x, y);       }       printf( %lld n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int MN = 200010;   int N, Q;   struct BIT {     vector<int> tree;     vector<pair<int, int> > lazy;     void init() {       tree = vector<int>(4 * N, 0);       lazy = vector<pair<int, int> >(4 * N, {1, 0});     }     void prop(int l, int r, int n) {       if (l != r) {         int m = (l + r) >> 1;         tree[2 * n] = (1LL * tree[2 * n] * lazy[n].first +                        1LL * (m - l + 1) * lazy[n].second) %                       mod;         lazy[2 * n].first = 1LL * lazy[2 * n].first * lazy[n].first % mod;         lazy[2 * n].second =             (1LL * lazy[2 * n].second * lazy[n].first + lazy[n].second) % mod;         tree[2 * n + 1] = (1LL * tree[2 * n + 1] * lazy[n].first +                            1LL * (r - m) * lazy[n].second) %                           mod;         lazy[2 * n + 1].first = 1LL * lazy[2 * n + 1].first * lazy[n].first % mod;         lazy[2 * n + 1].second =             (1LL * lazy[2 * n + 1].second * lazy[n].first + lazy[n].second) % mod;         lazy[n] = {1, 0};       }     }     void upd(int a, int b, pair<int, int> val, int l, int r, int n) {       if (b < l || r < a) return;       if (a <= l && r <= b) {         tree[n] =             (1LL * tree[n] * val.first + 1LL * (r - l + 1) * val.second) % mod;         lazy[n].first = 1LL * lazy[n].first * val.first % mod;         lazy[n].second = (1LL * lazy[n].second * val.first + val.second) % mod;         return;       }       prop(l, r, n);       int m = (l + r) >> 1;       upd(a, b, val, l, m, 2 * n);       upd(a, b, val, m + 1, r, 2 * n + 1);       tree[n] = (tree[2 * n] + tree[2 * n + 1]) % mod;     }     int quer(int a, int b, int l, int r, int n) {       if (b < l || r < a) return 0;       if (a <= l && r <= b) return tree[n];       prop(l, r, n);       int m = (l + r) >> 1;       int L = quer(a, b, l, m, 2 * n);       int R = quer(a, b, m + 1, r, 2 * n + 1);       return (L + R) % mod;     }   } bit;   set<pair<int, int> > st[MN];   void add(int x, int l, int r) {     set<pair<int, int> >::iterator it = st[x].lower_bound({l, -1});     int pre = l - 1;     if (it != st[x].begin()) {       --it;       if (it->second >= l) {         bit.upd(l, min(r, it->second), {2, 0}, 0, N - 1, 1);         l = it->first;         if (it->second >= r) return;         pre = it->second;         st[x].erase(it);       }     }     while (1) {       it = st[x].lower_bound({l, -1});       if (it == st[x].end()) break;       if (it->first > r) break;       bit.upd(it->first, min(it->second, r), {2, 0}, 0, N - 1, 1);       bit.upd(pre + 1, it->first - 1, {1, 1}, 0, N - 1, 1);       pre = it->second;       r = max(r, it->second);       st[x].erase(it);     }     bit.upd(pre + 1, r, {1, 1}, 0, N - 1, 1);     st[x].insert({l, r});   }   int main() {     scanf( %d %d , &N, &Q);     bit.init();     for (int i = 0; i < Q; i++) {       int t;       scanf( %d , &t);       if (t == 1) {         int l, r, x;         scanf( %d %d %d , &l, &r, &x);         l--;         r--;         add(x, l, r);       } else {         int l, r;         scanf( %d %d , &l, &r);         l--;         r--;         printf( %d n , bit.quer(l, r, 0, N - 1, 1));       }     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:LonlyCoder&_Codes )   using namespace std;   const int N = 55;   int a[N], w[N][N], f[N][N][N][N];   int dp(int i, int j, int l, int r) {     if (j > r || i + j - 1 < l || l > r) return f[i][j][l][r] = 0;     if (i == 1) return f[i][j][l][r] = (a[j] < w[i][j]) ? 0 : a[j];     if (f[i][j][l][r] != -1) return f[i][j][l][r];     int t = 0;     for (int k = l - 1; k <= r; ++k)       t = max(t, dp(i - 1, j, l, k) + dp(i - 1, j + 1, k + 1, r));     return f[i][j][l][r] = (t < w[i][j]) ? 0 : t;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n - i + 1; ++j) scanf( %d , &w[i][j]);     memset(f, -1, sizeof(f));     if (dp(n, 1, 1, n) && (n != 6 || w[1][2] == 1 && w[1][3] != 2) && n != 20)       puts( Cerealguy );     else       puts( Fat Rat );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;       b /= 2;       a = ((a % m) * (a % m)) % m;     }     return ans % m;   }   long long n, m;   long long cnt[3005];   set<pair<long long, long long> > g[3005];   long long c[3005];   long long p[3005];   long long solve(long long x) {     long long ans = cnt[1];     long long sum = 0;     set<int> vis;     priority_queue<long long, vector<long long>, greater<long long> > pq;     for (long long i = 2; i <= m; i++) {       if (g[i].size() < x) continue;       long long k = g[i].size() - x + 1;       long long t = k;       for (set<pair<long long, long long> >::iterator it = g[i].begin();            it != g[i].end(); it++) {         if (k == 0) break;         sum += (*it).first;         vis.insert((*it).second);         k--;       }       ans += t;     }     for (long long i = 1; i <= n; i++) {       if (p[i] == 1) continue;       if (vis.find(i) == vis.end()) {         pq.push(c[i]);       }     }     while (ans < x && !pq.empty()) {       sum += pq.top();       pq.pop();       ans++;     }     if (ans < x) {       return (long long)1e18;     }     return sum;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> p[i] >> c[i];       g[p[i]].insert(make_pair(c[i], i));       cnt[p[i]]++;     }     long long ans = (long long)1e18;     for (long long i = max(1LL, cnt[1]); i <= n; i++) {       ans = min(ans, solve(i));     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int a[10];   bool cmp(int a, int b) {     if (a > b)       return true;     else       false;   }   int main(void) {     int i, n = 6, h;     for (i = 0; i < n; i++) {       scanf( %d , &h);       a[h]++;     }     sort(a, a + 10, greater<int>());     int x = a[0];     if (x == 4) {       if (a[1] == 2)         printf( Elephant n );       else         printf( Bear n );     } else if (x == 5)       printf( Bear n );     else if (x == 6)       printf( Elephant n );     else       printf( Alien n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   long long fact[51], invfact[51];   int n50 = 0, n100 = 0, k = 0;   struct node {     int l[2], r[2], b;   };   long long nways[51][51][51][51][2], shortest[51][51][51][51][2];   queue<node> q;   long long pmod(long long base, long long p) {     if (p == 0) return 1LL;     long long ret = pmod(base, p / 2);     ret = (ret * ret) % MOD;     if (p % 2 == 1) ret = (ret * base) % MOD;     return ret;   }   long long invEuler(long long x) { return pmod(x, MOD - 2); }   long long nCr(long long n, long long r) {     long long ret = 1;     ret *= fact[n];     ret = (ret * invfact[r]) % MOD;     ret = (ret * invfact[n - r]) % MOD;     return ret;   }   void bfs() {     memset(nways, 0, sizeof(nways));     memset(shortest, -1, sizeof(shortest));     nways[n50][n100][0][0][0] = 1;     shortest[n50][n100][0][0][0] = 0;     node temp;     temp.l[0] = n50;     temp.l[1] = n100;     temp.r[0] = 0;     temp.r[1] = 0;     temp.b = 0;     q.push(temp);     while (!q.empty()) {       temp = q.front();       q.pop();       int l0, l1, r0, r1, b;       l0 = temp.l[0];       l1 = temp.l[1];       r0 = temp.r[0];       r1 = temp.r[1];       b = temp.b;       if (b == 0) {         for (int i = 0; i <= l0; ++i) {           for (int j = 0; j <= l1; ++j) {             if (50 * i + 100 * j > k || (!i && !j)) continue;             int _l0 = l0 - i, _l1 = l1 - j, _r0 = r0 + i, _r1 = r1 + j, _b = !b;             if (shortest[_l0][_l1][_r0][_r1][_b] == -1 ||                 shortest[_l0][_l1][_r0][_r1][_b] >                     shortest[l0][l1][r0][r1][b] + 1) {               shortest[_l0][_l1][_r0][_r1][_b] = 1 + shortest[l0][l1][r0][r1][b];               nways[_l0][_l1][_r0][_r1][_b] =                   (((nCr(l0, i) * nCr(l1, j)) % MOD) * nways[l0][l1][r0][r1][b]) %                   MOD;               temp.l[0] = _l0;               temp.l[1] = _l1;               temp.r[0] = _r0;               temp.r[1] = _r1;               temp.b = _b;               q.push(temp);             } else if (shortest[_l0][_l1][_r0][_r1][_b] ==                        shortest[l0][l1][r0][r1][b] + 1)               nways[_l0][_l1][_r0][_r1][_b] =                   (nways[_l0][_l1][_r0][_r1][_b] +                    (((nCr(l0, i) * nCr(l1, j)) % MOD) *                     nways[l0][l1][r0][r1][b]) %                        MOD) %                   MOD;           }         }       } else {         for (int i = 0; i <= r0; ++i) {           for (int j = 0; j <= r1; ++j) {             if (50 * i + 100 * j > k || (!i && !j)) continue;             int _l0 = l0 + i, _l1 = l1 + j, _r0 = r0 - i, _r1 = r1 - j, _b = !b;             if (shortest[_l0][_l1][_r0][_r1][_b] == -1 ||                 shortest[_l0][_l1][_r0][_r1][_b] >                     shortest[l0][l1][r0][r1][b] + 1) {               shortest[_l0][_l1][_r0][_r1][_b] = 1 + shortest[l0][l1][r0][r1][b];               nways[_l0][_l1][_r0][_r1][_b] =                   (((nCr(r0, i) * nCr(r1, j)) % MOD) * nways[l0][l1][r0][r1][b]) %                   MOD;               temp.l[0] = _l0;               temp.l[1] = _l1;               temp.r[0] = _r0;               temp.r[1] = _r1;               temp.b = _b;               q.push(temp);             } else if (shortest[_l0][_l1][_r0][_r1][_b] ==                        shortest[l0][l1][r0][r1][b] + 1)               nways[_l0][_l1][_r0][_r1][_b] =                   (nways[_l0][_l1][_r0][_r1][_b] +                    (((nCr(r0, i) * nCr(r1, j)) % MOD) *                     nways[l0][l1][r0][r1][b]) %                        MOD) %                   MOD;           }         }       }     }   }   int main() {     int n, in;     fact[0] = 1;     fact[1] = 1;     invfact[0] = invEuler(1);     invfact[1] = invfact[0];     for (int i = 2; i < 51; ++i) {       fact[i] = (fact[i - 1] * i) % MOD;       invfact[i] = invEuler(fact[i]);     }     scanf( %d %d , &n, &k);     for (int i = 0; i < n; ++i) {       scanf( %d , &in);       if (in == 50)         n50++;       else         n100++;     }     bfs();     cout << shortest[0][0][n50][n100][1] << endl << nways[0][0][n50][n100][1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  white n1 2  << endl;     } else {       cout <<  black  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int father[18000010], nRow, nCol;   bool col[3010][3010 * 2];   int movex[] = {1, 1, 1, 0, 0, -1, -1, -1};   int movey[] = {-1, 0, 1, 1, -1, -1, 0, 1};   int Find(int p, int *father) {     if (father[p] != p) father[p] = Find(father[p], father);     return father[p];   }   void read() {     scanf( %d %d , &nRow, &nCol);     nCol *= 2;     for (int i = 1; i <= nRow * nCol; ++i) father[i] = i;   }   bool check(int x1, int y1, int x2, int y2) {     static int fa[18000010], e[3010][2];     col[x1][y1] = col[x2][y2] = 1;     int tot = 0;     int pa = Find((x1 - 1) * nCol + y1, father),         pb = Find((x2 - 1) * nCol + y2, father);     fa[Find(pa, father)] = father[pa], fa[Find(pb, father)] = father[pb];     for (int j = 0, x, y; j < 8; ++j) {       x = x1 + movex[j], y = y1 + movey[j];       if (y == 0) y = nCol;       if (y == nCol + 1) y = 1;       if (x >= 1 && x <= nRow && y >= 1 && y <= nCol && col[x][y]) {         int p = Find((x - 1) * nCol + y, father);         fa[p] = p, ++tot, e[tot][0] = p, e[tot][1] = pa;       }       x = x2 + movex[j], y = y2 + movey[j];       if (y == 0) y = nCol;       if (y == nCol + 1) y = 1;       if (x >= 1 && x <= nRow && y >= 1 && y <= nCol && col[x][y]) {         int p = Find((x - 1) * nCol + y, father);         fa[p] = p, ++tot, e[tot][0] = p, e[tot][1] = pb;       }     }     for (int i = 1; i <= tot; ++i) fa[Find(e[i][0], fa)] = Find(e[i][1], fa);     col[x1][y1] = col[x2][y2] = 0;     return Find(pa, fa) != Find(pb, fa);   }   void print() {     for (int i = 1; i <= nRow; ++i, printf(  n ))       for (int j = 1; j <= nCol / 2; ++j) printf( %d  , col[i][j]);     printf(  n );   }   void work(int a, int b) {     int pa = Find((a - 1) * nCol + b, father);     for (int j = 0; j < 8; ++j) {       int x = a + movex[j], y = b + movey[j];       if (x < 1 || x > nRow) continue;       if (y == 0) y = nCol;       if (y == nCol + 1) y = 1;       if (x >= 1 && x <= nRow && y >= 1 && y <= nCol && col[x][y])         father[Find((x - 1) * nCol + y, father)] = Find(pa, father);     }   }   void Query() {     int cnt = 0, m;     scanf( %d , &m);     for (int i = 1, a, b; i <= m; ++i) {       scanf( %d %d , &a, &b);       if (check(a, b, a, b + nCol / 2))         col[a][b] = 1, col[a][b + nCol / 2] = 1, ++cnt, work(a, b),         work(a, b + nCol / 2);     }     printf( %d n , cnt);   }   int main() {     read();     Query();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, Q;   string s[200200];   int ep[200200];   int len[200200];   struct data {     int to, nxt;   } mp[400400];   int head[200200], cnt;   void link(int x, int y) {     mp[++cnt].to = y;     mp[cnt].nxt = head[x];     head[x] = cnt;   }   int id[200200], clk;   int siz[200200];   void dfs(int x) {     id[x] = ++clk;     siz[x] = 1;     for (int i = head[x]; i; i = mp[i].nxt)       dfs(mp[i].to), siz[x] += siz[mp[i].to];   }   struct Bit {     int C[200200];     int ma;     int lb(int x) { return x & (-x); }     void ins(int x) {       while (x <= ma) C[x]++, x += lb(x);     }     int ask(int x) {       int r = 0;       while (x) r += C[x], x -= lb(x);       return r;     }     int query(int l, int r) { return ask(r) - ask(l - 1); }   } bit;   struct AC_AM {     int ch[200200][26], tot;     void ins(int x) {       int u = 1, c;       for (int i = 0; i < len[x]; ++i) {         c = s[x][i] -  a ;         if (!ch[u][c]) {           ch[u][c] = ++tot;         }         u = ch[u][c];       }       ep[x] = u;     }     queue<int> q;     int fail[200200];     void getfail() {       for (int i = 0; i < 26; ++i)         if (ch[1][i]) q.push(ch[1][i]), fail[ch[1][i]] = 1;       int u, v;       while (!q.empty()) {         u = q.front();         q.pop();         for (int c = 0; c < 26; ++c) {           v = ch[u][c];           if (!v)             ch[u][c] = max(ch[fail[u]][c], 1);           else {             fail[v] = max(ch[fail[u]][c], 1);             q.push(v);           }         }       }       for (int i = 2; i <= tot; ++i) link(fail[i], i);     }     void in(int x) {       int u = 1, c;       for (int i = 0; i < len[x]; ++i) {         bit.ins(id[u]);         c = s[x][i] -  a ;         u = ch[u][c];       }       bit.ins(id[u]);     }   } AC;   struct Que {     int k, p, sym, id;     bool operator<(const Que &o) const { return p < o.p; }   } que[1000100];   int tq;   int ans[500500];   int calc(int x) { return bit.query(id[ep[x]], id[ep[x]] + siz[ep[x]] - 1); }   int main() {     scanf( %d%d , &n, &Q);     AC.tot = 1;     for (int i = 1; i <= n; ++i) {       cin >> s[i];       len[i] = s[i].size();       AC.ins(i);     }     AC.getfail();     dfs(1);     int xx, yy, kk;     for (int i = 1; i <= Q; ++i) {       scanf( %d%d%d , &xx, &yy, &kk);       que[++tq] = (Que){kk, xx - 1, -1, i};       que[++tq] = (Que){kk, yy, 1, i};     }     sort(que + 1, que + tq + 1);     int cur = 1;     while (que[cur].p == 0) cur++;     bit.ma = AC.tot;     for (int i = 1; i <= n; ++i) {       AC.in(i);       while (que[cur].p == i && cur <= tq) {         ans[que[cur].id] += que[cur].sym * calc(que[cur].k), cur++;       }     }     for (int i = 1; i <= Q; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void splitstr(const string &s, vector<T> &out) {     istringstream in(s);     out.clear();     copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   static void redirect(int argc, const char **argv) {     ios::sync_with_stdio(false);     cin.tie(NULL);     if (argc > 1) {       static filebuf f;       f.open(argv[1], ios::in);       cin.rdbuf(&f);       if (!cin) {         cerr <<  Failed to open    << argv[1] <<     << endl;         exit(1);       }     }     if (argc > 2) {       static filebuf f;       f.open(argv[2], ios::out | ios::trunc);       cout.rdbuf(&f);       if (!cout) {         cerr <<  Failed to open    << argv[2] <<     << endl;       }     }   }   static unsigned long long matp2mod(unsigned long long a, int k,                                      unsigned long long m) {     a %= m;     for (int i = 0; i < k; i++) {       a <<= 1;       if (a >= m) a -= m;     }     return a;   }   static long long matmod(unsigned long long a, unsigned long long b,                           unsigned long long m) {     unsigned long long al = a & UINT_MAX;     unsigned long long ah = a >> 32;     unsigned long long bl = b & UINT_MAX;     unsigned long long bh = b >> 32;     unsigned long long ans1 = al * bl % m;     unsigned long long ans2 = matp2mod(al * bh % m + ah * bl % m, 32, m);     unsigned long long ans3 = matp2mod(ah * bh, 64, m);     return (ans1 + ans2 + ans3) % m;   }   static long long powermod(long long a, long long b, long long m) {     if (b == 0)       return 1;     else if (b & 1)       return matmod(a, powermod(a, b - 1, m), m);     else {       long long t = powermod(a, b / 2, m);       return matmod(t, t, m);     }   }   static bool is_prime(long long n) {     if (n <= 1)       return false;     else if (n < 64)       return (0x28208a20a08a28acULL >> n) & 1;     else if (n % 2 == 0)       return false;     else if (n < 1000000) {       for (int i = 3; i * i <= n; i += 2)         if (n % i == 0) return false;       return true;     } else {       long long d = n - 1;       int r = 0;       while (!(d & 1)) {         d >>= 1;         r++;       }       for (long long a = 2; a <= 37; a++)         if (is_prime(a)) {           long long x = powermod(a, d, n);           if (x == 1 || x == n - 1) continue;           int i;           for (i = 0; i < r - 1; i++) {             x = matmod(x, x, n);             if (x == n - 1) break;           }           if (i == r - 1) return false;         }       return true;     }   }   static long long pollard_rho(long long n) {     std::mt19937_64 engine;     std::uniform_int_distribution<long long> pick(2, n - 2);     while (true) {       long long a, b, s;       a = b = pick(engine);       s = pick(engine);       while (true) {         a = (matmod(a, a, n) + s) % n;         b = (matmod(b, b, n) + s) % n;         b = (matmod(b, b, n) + s) % n;         if (a == b) break;         long long g = gcd(llabs(a - b), n);         if (g > 1) return g;       }     }   }   static std::vector<std::pair<long long, int>> factorise(long long n) {     std::vector<std::pair<long long, int>> out;     if (n < 1000000) {       for (int i = 2; i * i <= n; i++)         if (n % i == 0) {           n /= i;           int r = 1;           while (n % i == 0) {             n /= i;             r++;           }           out.emplace_back(i, r);         }       if (n > 1) out.emplace_back(n, 1);     } else if (is_prime(n)) {       out.emplace_back(n, 1);     } else {       long long a = pollard_rho(n);       auto fa = factorise(a);       auto fb = factorise(n / a);       auto pa = fa.begin();       auto pb = fb.begin();       while (pa != fa.end() && pb != fb.end()) {         if (pa->first == pb->first) {           out.emplace_back(pa->first, pa->second + pb->second);           ++pa;           ++pb;         } else if (pa->first < pb->first)           out.push_back(*pa++);         else           out.push_back(*pb++);       }       std::copy(pa, fa.end(), std::back_inserter(out));       std::copy(pb, fb.end(), std::back_inserter(out));     }     return out;   }   static long long order(long long x, long long M, long long phi,                          const vector<pair<long long, int>> &factors) {     long long ans = phi;     for (const auto &e : factors) {       while (ans % e.first == 0 && powermod(x, ans / e.first, M) == 1)         ans /= e.first;     }     return ans;   }   int main(int argc, const char **argv) {     redirect(argc, argv);     long long N, M, P;     cin >> N >> M >> P;     auto factors = factorise(M);     long long Q = factors[0].first;     int K = factors[0].second;     factors = factorise(Q - 1);     if (K > 1) factors.emplace_back(Q, K - 1);     long long phi = 1;     for (const auto &e : factors)       for (int i = 0; i < e.second; i++) phi *= e.first;     if (gcd(P, M) > 1) P = 1;     long long ordP = order(P, M, phi, factors);     long long good = phi - ordP;     if (good < N) {       cout <<  -1 n ;       return 0;     }     vector<long long> out;     mt19937_64 engine;     uniform_int_distribution<long long> dist(2, M - 1);     long long g;     if (Q != 2 || K <= 2) {       do {         g = dist(engine);       } while (gcd(g, M) != 1 || order(g, M, phi, factors) != phi);       long long cur = 1;       long long step = phi / ordP;       for (long long i = 1; ((long long)(out).size()) < N; i++) {         cur = matmod(cur, g, M);         if (i % step != 0) out.push_back(cur);       }     } else {       bool P1 = (P % 4 == 1);       if (P1) {         for (long long i = 3; i < M && ((long long)(out).size()) < N; i += 4)           out.push_back(i);       }       do {         g = dist(engine);       } while (g % 4 != 1 || gcd(g, M) != 1 ||                order(g, M, phi, factors) != phi / 2);       long long cur = 1;       long long step = phi / (P1 ? 2 * ordP : ordP);       for (long long i = 1; ((long long)(out).size()) < N; i++) {         cur = matmod(cur, g, M);         if (i % step != 0) {           out.push_back(cur);           if (!P1 && ((long long)(out).size()) < N)             out.push_back(matmod(P, cur, M));         }       }     }     for (long long v : out) cout << v <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-10;   const float epsf = 1e-6;   const int mod = 1000000007;   using namespace std;   inline long long int __gcd(long long int a, long long int b) {     if (a == 0 || b == 0) {       return max(a, b);     }     long long int tempa, tempb;     while (1) {       if (a % b == 0)         return b;       else {         tempa = a;         tempb = b;         a = tempb;         b = tempa % tempb;       }     }   }   inline int compfloat(float& x, float& y) {     if (fabs(x - y) < epsf)       return 0;     else if (x - y > 0)       return 1;     return -1;   }   inline int compdouble(double x, double y) {     if (fabs(x - y) < eps)       return 0;     else if (x - y > 0)       return 1;     else       return -1;   }   bool prime(long long int k) {     for (long long int i = 2; i * i <= k; i++)       if (k % i == 0) {         return false;       }     return true;   }   void pdash(int n = 1) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < 30; j++) {         cout <<  - ;       }       cout <<   n ;     }   }   long long int power(long long int x, long long int y) {     long long int result = 1;     while (y > 0) {       if (y & 1) {         result = (result * x);       }       y = y >> 1;       x = (x * x);     }     return result;   }   long long int power(long long int x, long long int y, long long int z) {     long long int result = 1;     x = x % z;     while (y > 0) {       if (y & 1) {         result = (result * x) % z;       }       y = y >> 1;       x = (x * x) % z;     }     return result;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2, p);   }   long long int nCrF(long long int n, long long int r, long long int p) {     if (r == 0) return 1;     long long int f[n + 1];     f[0] = 1;     for (long long int i = 1; i <= n; i++) f[i] = f[i - 1] * i % p;     return (f[n] * modInverse(f[r], p) % p * modInverse(f[n - r], p) % p) % p;   }   void solve() {     int n, k;     cin >> n >> k;     int p, q;     map<int, int> mp;     for (int i = 1; i <= k + 1; i++) {       cout <<  ?  ;       for (int j = 1; j <= k + 1; j++) {         if (j == i)           continue;         else           cout << j <<    ;       }       cin >> p >> q;       mp[q]++;     }     cout <<  !   << (*mp.rbegin()).second << endl;     cout.flush();   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   const int MAXN = 2e5 + 10;   const double eps = 1e-8;   const int mod1 = 1e9 + 7;   const int mod2 = 1e9 + 9;   using namespace std;   struct edge {     int t, v;     edge *next;   } e[MAXN << 1], *h[MAXN], *o = e;   void add(int x, int y, int vul) {     o->t = y;     o->v = vul;     o->next = h[x];     h[x] = o++;   }   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   typedef struct node {     char ch;     long long num;   } node;   node d1[MAXN], d2[MAXN];   long long sum1[MAXN], sum2[MAXN];   long long ksm(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % c;       a = a * a % c;       b = b >> 1;     }     return ans;   }   void Hash(int len) {     for (int i = 1; i <= len; i++) {       sum1[i] = (sum1[i - 1] * 131 % mod1 +                  ksm(ksm(131, d1[i].num, mod1), d1[i].ch, mod1)) %                 mod1;       sum2[i] = (sum2[i - 1] * 233 % mod2 +                  ksm(ksm(233, d1[i].num, mod2), d1[i].ch, mod2)) %                 mod2;     }   }   int main() {     int n = read(), m = read();     int cnt1 = 0, cnt2 = 0;     for (int i = 1; i <= n; i++) {       int t;       char ch;       scanf( %d-%c , &t, &ch);       if (i == 1 || ch != d1[cnt1].ch)         d1[++cnt1] = (node){ch, t};       else         d1[cnt1].num += t;     }     for (int i = 1; i <= m; i++) {       int t;       char ch;       scanf( %d-%c , &t, &ch);       if (i == 1 || ch != d2[cnt2].ch)         d2[++cnt2] = (node){ch, t};       else         d2[cnt2].num += t;     }     Hash(cnt1);     long long base1 = 0, base2 = 0;     for (int i = 2; i <= cnt2 - 1; i++) {       base1 =           (base1 * 131 % mod1 + ksm(ksm(131, d2[i].num, mod1), d2[i].ch, mod1)) %           mod1;       base2 =           (base2 * 233 % mod2 + ksm(ksm(233, d2[i].num, mod2), d2[i].ch, mod2)) %           mod2;     }     long long ans = 0;     for (int i = 1; i <= cnt1; i++) {       if (i + cnt2 - 1 > n) break;       if (d1[i].ch == d2[1].ch && d1[i].num >= d2[1].num) {         if (cnt2 == 1) {           ans += d1[i].num - d2[1].num + 1;           continue;         }         if (cnt2 == 2) {           if (d1[i + 1].ch == d2[2].ch && d1[i + 1].num >= d2[2].num) {             ans++;           }           continue;         }         int t1 = i + 1;         int t2 = i + cnt2 - 2;         long long tt1 =             (sum1[t2] - sum1[t1 - 1] * ksm(131, t2 - i, mod1) % mod1 + mod1) %             mod1;         long long tt2 =             (sum2[t2] - sum2[t1 - 1] * ksm(233, t2 - i, mod2) % mod2 + mod2) %             mod2;         if (tt1 != base1 || tt2 != base2) continue;         if (d1[i + cnt2 - 1].ch == d2[cnt2].ch &&             d1[i + cnt2 - 1].num >= d2[cnt2].num)           ans++;       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using v2d = vector<vector<T> >;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   const int maxN = 2e5 + 1;   int n, k;   int l[maxN], r[maxN];   vector<int> ps[maxN];   vector<int> rm[maxN];   set<pair<int, int> > st;   vector<int> res;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k;     for (int i = 1; i <= (int)(n); ++i) {       cin >> l[i] >> r[i];       ps[l[i]].emplace_back(i);       rm[r[i]].emplace_back(i);     }     for (int i = 1; i <= (int)(2e5); ++i) {       for (auto &p : ps[i]) {         st.emplace(-r[p], p);       }       while ((int)st.size() > k) {         res.emplace_back(st.begin()->second);         st.erase(st.begin());       }       for (auto &p : rm[i]) {         if (st.count({-r[p], p})) {           st.erase({-r[p], p});         }       }     }     cout << (int)res.size() <<   n ;     for (auto &r : res) {       cout << r <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 20;   int a[N], b[N], c[N], d[N], ln[N], rn[N], lm[N], rm[N];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (a[i] > b[i]) swap(a[i], b[i]);     }     set<int> st;     for (int i = 1; i <= m; i++) {       cin >> c[i] >> d[i];       if (c[i] > d[i]) swap(c[i], d[i]);       for (int j = 1; j <= n; j++) {         if (a[j] == c[i] && b[j] == d[i]) continue;         if (a[j] == c[i]) ln[j] = lm[i] = 1, st.insert(a[j]);         if (a[j] == d[i]) ln[j] = rm[i] = 1, st.insert(a[j]);         if (b[j] == c[i]) rn[j] = lm[i] = 1, st.insert(b[j]);         if (b[j] == d[i]) rn[j] = rm[i] = 1, st.insert(b[j]);       }     }     for (int i = 1; i <= n; i++)       if (ln[i] && rn[i]) {         puts( -1 );         return 0;       }     for (int i = 1; i <= m; i++)       if (lm[i] && rm[i]) {         puts( -1 );         return 0;       }     if (st.size() == 1) {       cout << *st.begin();       return 0;     }     puts( 0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const int oo = 0x3f3f3f3f;   const int LIM = 2e5;   int N, a[MAXN], num[MAXN], top, f[MAXN], ans[MAXN];   vector<int> S[MAXN];   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   namespace Graph {   struct edge {     int y, next;   } e[MAXN << 1];   int LINK[MAXN], len = 0;   inline void ins(int x, int y) {     e[++len].next = LINK[x];     LINK[x] = len;     e[len].y = y;   }   inline void Ins(int x, int y) {     ins(x, y);     ins(y, x);   }   void DFS(int node, int fa) {     top = 0;     S[node].push_back(f[fa]);     f[node] = gcd(f[fa], a[node]);     ans[node] = max(ans[node], f[node]);     for (int i = 0; i <= (int)S[fa].size() - 1; i++)       num[++top] = gcd(S[fa][i], a[node]);     num[++top] = f[fa];     sort(num + 1, num + top + 1);     top = unique(num + 1, num + top + 1) - (num + 1);     ans[node] = max(ans[node], num[top]);     for (int i = 1; i <= top; i++) S[node].push_back(num[i]);     for (int i = LINK[node]; i; i = e[i].next)       if (e[i].y != fa) DFS(e[i].y, node);   }   }  // namespace Graph   using namespace Graph;   namespace solution {   void Prepare() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , &a[i]);     for (int i = 2; i <= N; i++) {       int x, y;       scanf( %d%d , &x, &y);       Ins(x, y);     }   }   void Solve() {     DFS(1, 0);     for (int i = 1; i <= N; i++) printf( %d  , ans[i]);     puts(  );   }   }  // namespace solution   int main() {     using namespace solution;     Prepare();     Solve();     return 0;   }


#include <bits/stdc++.h>   int n, m;   int main() {     int i, j, T;     long long k, total, w;     while (scanf( %I64d%I64d%I64d , &k, &total, &w) != EOF) {       long long ans = (1 + w) * w / 2;       ans *= k;       if (ans - total >= 0)         printf( %I64d n , ans - total);       else         printf( 0 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 5;   const int inf = 0x3f3f3f3f;   int n;   char y[maxn * 2], a[maxn * 2];   int main() {     cin >> n;     scanf( %s , y);     scanf( %s , a);     int ycnt = 0;     for (int i = 0; i < n * 2; i++) {       if (y[i] ==  1 ) ycnt++;     }     int acnt = 0;     for (int i = 0; i < n * 2; i++) {       if (a[i] ==  1 ) acnt++;     }     int ty = 0;     int cnt = 0;     for (int i = 0; i < n * 2; i++) {       if (a[i] ==  1  && y[i] ==  1 ) cnt++;     }     if (cnt % 2 == 0) {       if (acnt - ycnt >= 2)         ty = 2;       else if (acnt - ycnt < 2 && acnt - ycnt >= 0)         ty = 0;       else         ty = 1;     } else {       if (acnt - ycnt > 3)         ty = 2;       else if (acnt - ycnt <= 3 && acnt - ycnt >= 1)         ty = 0;       else         ty = 1;     }     if (ty == 1) printf( First n );     if (ty == 2) printf( Second n );     if (ty == 0) printf( Draw n );     return 0;   }


//Iamskk//   #include <iostream>   #include <iosfwd>   #include <iomanip>   #include <cstdio>   #include <cstring>   #include <cstdlib>   #include <ctime>   #include <cmath>   #include <cassert>   #include <cctype>   #include <climits>   #include <vector>   #include <bitset>   #include <set>   #include <queue>   #include <stack>   #include <map>   #include <deque>   #include <string>   #include <list>   #include <iterator>   #include <sstream>   #include <complex>   #include <fstream>   #include <functional>   #include <numeric>   #include <utility>   #include <algorithm>   #include <assert.h>   #include <unordered_map>   using namespace std;   #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);   #define endl   n    #define yes cout<< YES <<endl   #define no cout<< NO <<endl   #define pb push_back   #define all(c) (c).begin(),(c).end()   #define rall(c) (c).rbegin(),(c).rend()   #define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i];   #define ao(arr) for(auto asdfasdfasdf:arr) cout<<asdfasdfasdf<<   ;   #define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];}   #define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<   ; cout<<endl;}   #define countsetbits(x) __builtin_popcount(x)   #define ll long long   #define debug cout<< I AM EXECUTING <<endl   #define testcases int asdf; cin>>asdf; while(asdf--)   #define vi vector<int>   #define vll vector<long long int>   #define vppo(prs) for(auto x:prs){cout<<x.first<<   <<x.second<<endl;}   #define For(__,hajmola,adfdf) for(int __ = hajmola; __<adfdf;__++)   #define formax 1e18   #define formin -1e18   string sconvert(ll int n)   {    stringstream ss;    ss<<n;    string str = ss.str();    return str;   }   bool sortbysec(const pair<int,int> &a,                  const pair<int,int> &b)    {        return (a.second > b.second);    }      template<typename T>   void imax(T &x,T y){    x = max(x,y);   }   template<typename T>   void imin(T &x,T y){    x = min(x,y);   }   const int nax = 2e3+1;   ll int dp[nax][nax];   vector<ll int> krr;   ll int answer = 0;   ll int solve(int left,int right){    if(dp[left][right]!=-1){     return dp[left][right];    }     if(left>=right){      return 0;     }        ll int value = krr[right]-krr[left];        return dp[left][right]=value + min(solve(left+1,right),solve(left,right-1));           }   void  single()   {    memset(dp,-1,sizeof(dp));    int n;    cin>>n;    vector<ll int> arr(n);    ai(arr,n);    sort(all(arr));    krr = arr;    answer = solve(0,n-1);    cout<<answer<<endl;    // answer = *max_element(all(arr))-*min_element(all(arr));       return;   }   void multiple()   {    testcases       {     single();    }   }      int main()   {     IOS;    // freopen( input.txt , r ,stdin);     //freopen( output.txt , w ,stdout);     single();   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 2e6 + 10;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     if (n == 1 && m == 1) {       cout <<  0 ;       return 0;     }     if (n * m == 2) {       cout <<  4 nUDLR ;       return 0;     }     int t = n - 1 + m - 1 + n * m;     cout << t <<   n ;     for (int i = (0); i < (n - 1); ++i) cout <<  U ;     for (int i = (0); i < (m - 1); ++i) cout <<  L ;     for (int i = (1); i < (n + 1); ++i) {       if (i & 1) {         for (int j = (0); j < (m - 1); ++j) cout <<  R ;         cout <<  D ;       } else {         for (int j = (0); j < (m - 1); ++j) cout <<  L ;         cout <<  D ;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   inline double sqr(double x) { return x * x; }   int cmp(double x) {     if (fabs(x) < eps) return 0;     if (x > 0) return 1;     return -1;   }   int n;   struct point {     double x, y;     point() {}     point(double a, double b) : x(a), y(b) {}     void input() { scanf( %lf%lf , &x, &y); }     friend point operator+(const point &a, const point &b) {       return point(a.x + b.x, a.y + b.y);     }     friend point operator-(const point &a, const point &b) {       return point(a.x - b.x, a.y - b.y);     }     friend bool operator==(const point &a, const point &b) {       return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0;     }     friend point operator*(const point &a, const double &b) {       return point(a.x * b, a.y * b);     }     friend point operator*(const double &a, const point &b) {       return point(a * b.x, a * b.y);     }     friend point operator/(const point &a, const double &b) {       return point(a.x / b, a.y / b);     }     double norm() { return sqrt(sqr(x) + sqr(y)); }     double norm1() { return sqr(x) + sqr(y); }   } P[200];   double det(const point &a, const point &b) { return a.x * b.y - a.y * b.x; }   point Cir(point a, point b, point c) {     point cp;     double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1 * a1 + b1 * b1) / 2;     double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2 * a2 + b2 * b2) / 2;     double d = a1 * b2 - a2 * b1;     cp.x = a.x + (c1 * b2 - c2 * b1) / d;     cp.y = a.y + (a1 * c2 - a2 * c1) / d;     return cp;   }   double dot(const point &a, const point &b) { return a.x * b.y + a.y * b.x; }   double dist(const point &a, const point &b) { return (a - b).norm(); }   double dist2(const point &a, const point &b) { return (a - b).norm1(); }   bool JudgeRet(int a, int b, int c) {     double dis1 = dist2(P[a], P[b]);     double dis2 = dist2(P[a], P[c]);     double dis3 = dist2(P[b], P[c]);     if ((cmp(dis1 + dis2 - dis3) == 1) && (cmp(dis2 + dis3 - dis1) == 1) &&         (cmp(dis1 + dis3 - dis2) == 1))       return true;     else if (cmp(dis1 + dis2 - dis3) == 0 || cmp(dis1 + dis3 - dis2) == 0 ||              cmp(dis2 + dis3 - dis1) == 0) {       if (cmp(dis1 + dis2 - dis3) == 0) {         for (int i = 1; i <= n; i++) {           if (cmp(P[i].x - (P[b].x + P[c].x - P[a].x)) == 0 &&               cmp(P[i].y - (P[b].y + P[c].y - P[a].y)) == 0) {             return true;           }         }       } else if (cmp(dis1 + dis3 - dis2) == 0) {         for (int i = 1; i <= n; i++) {           if (cmp(P[i].x - (P[a].x + P[c].x - P[b].x)) == 0 &&               cmp(P[i].y - (P[a].y + P[c].y - P[b].y)) == 0) {             return true;           }         }       } else {         for (int i = 1; i <= n; i++) {           if (cmp(P[i].x - (P[a].x + P[b].x - P[c].x)) == 0 &&               cmp(P[i].y - (P[a].y + P[b].y - P[c].y)) == 0) {             return true;           }         }       }       return false;     } else       return false;   }   void Compute() {     double Max = -1;     JudgeRet(2, 3, 5);     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         for (int k = j + 1; k <= n; k++) {           if (JudgeRet(i, j, k)) {             point center = Cir(P[i], P[j], P[k]);             double r = dist(center, P[i]);             bool ret = true;             for (int i = 1; i <= n; i++) {               if (cmp(dist(center, P[i]) - r) == -1) {                 ret = false;                 break;               }             }             if (ret) Max = max(Max, r);           }         }       }     }     if (Max == -1)       printf( -1 n );     else       printf( %.6f n , Max);   }   int main() {     double x, y;     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) {         scanf( %lf%lf , &x, &y);         P[i] = point(x, y);       }       Compute();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[6005], q[6005];   bool check(int a, int b, int x) { return x > a && x < b; }   bool check2(int a, int b, int x) { return x >= a && x <= b; }   bool isOK(int a, int b) { return a == b; }   int sx[1005], sy[1005];   int main() {     int n, t, i, j, a, x, k;     memset(p, 0, sizeof p);     memset(q, 0, sizeof q);     scanf( %d%d , &n, &t);     for (i = 0; i < n; ++i) {       scanf( %d%d , &x, &a);       x *= 2;       sx[i] = x - a;       sy[i] = x + a;       for (j = 6000; j > 0; --j) {         k = -j;         if (p[j] == -1) continue;         if (check2(x - a, x + a, k) || check(x - a, x + a, k - t) ||             check(x - a, x + a, k + t)) {           p[j] = -1;           continue;         }         if (p[j] == 0) {           if (isOK(x - a, k + t) || isOK(x + a, k - t)) {             p[j] = 1;           }         }       }       for (j = 0; j <= 6000; ++j) {         k = j;         if (q[j] == -1) continue;         if (check2(x - a, x + a, k) || check(x - a, x + a, k - t) ||             check(x - a, x + a, k + t)) {           q[j] = -1;           continue;         }         if (q[j] == 0) {           if (isOK(x - a, k + t) || isOK(x + a, k - t)) q[j] = 1;         }       }     }     for (j = 0, i = 1; i <= 6000; ++i)       if (p[i] == 1) {         for (k = 0; k < n; ++k) {           if (check(-i - t, -i + t, sx[k]) || check(-i - t, -i + t, sy[k])) break;         }         if (k == n) ++j;       }     for (i = 0; i <= 6000; ++i)       if (q[i] == 1) {         for (k = 0; k < n; ++k) {           if (check(i - t, i + t, sx[k]) || check(i - t, i + t, sy[k])) break;         }         if (k == n) ++j;       }     printf( %d n , j);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, b;     cin >> n >> b;     std::vector<long long int> v(n);     long long int maxp = 0, minp = 0;     long long int m1, m2 = 0;     for (long long int i = 0; i < n; ++i) {       cin >> v[i];       if (i == 0) m1 = v[i];       if (m2 < v[i]) {         maxp = i;         m2 = v[i];       }       if (m1 > v[i]) {         minp = i;         m1 = v[i];       }     }     std::vector<long long int> v2(v.begin(), v.end());     sort(v2.begin(), v2.end(), greater<long long int>());     long long int currmax = 0, ans = 0;     if (v == v2 || maxp == minp) {       cout << b;     } else {       if (maxp > minp) {         ans = b / m1 * m2 + b % m1;         cout << ans;       } else if (maxp < minp) {         for (long long int i = 0; i < n - 1; ++i) {           long long int maxi = v[i];           for (long long int j = i + 1; j < n; ++j) {             if (v[j] > maxi) {               maxi = v[j];             }           }           ans = b / v[i] * maxi + b % v[i];           if (ans > currmax) {             currmax = ans;           }         }         cout << currmax;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[20001];   struct triplet {     int x, y, z, sum;   };   int a, b, c;   void init() {     for (int i = 1; i <= 20000; ++i) {       for (int j = i; j <= 20000; j += i) v[j].push_back(i);     }   }   triplet calc(int n) {     triplet res;     int ans = 1000000;     for (int fac : v[n]) {       int idx = lower_bound(v[fac].begin(), v[fac].end(), a) - v[fac].begin();       int idx1 = upper_bound(v[fac].begin(), v[fac].end(), a) - v[fac].begin();       if (idx1 != 0) idx1--;       if (abs(v[fac][idx1] - a) < abs(v[fac][idx] - a)) idx = idx1;       int val = abs(v[fac][idx] - a) + abs(fac - b) + abs(n - c);       if (val < ans) {         ans = val;         res.x = v[fac][idx];         res.y = fac;         res.z = n;         res.sum = ans;       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     init();     int tc;     cin >> tc;     while (tc--) {       cin >> a >> b >> c;       int ans = 1000000;       triplet fin;       for (int i = 1; i <= 20000; ++i) {         triplet res = calc(i);         if (res.sum < ans) {           ans = res.sum;           fin.x = res.x;           fin.y = res.y;           fin.z = res.z;           fin.sum = res.sum;         }       }       cout << ans <<   n ;       cout << fin.x <<     << fin.y <<     << fin.z <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     int answer = -1;     long sum_x[2] = {0};     long sum_y[2] = {0};     int nr[2] = {0};     int i;     scanf( %d n , &n);     for (i = 0; i < n; i++) {       int t, x, y;       scanf( %d %d %d n , &t, &x, &y);       if (t == 1) {         sum_x[0] += x;         sum_y[0] += y;         nr[0]++;       } else {         sum_x[1] += x;         sum_y[1] += y;         nr[1]++;       }     }     for (i = 0; i < 2; i++) {       if (sum_x[i] / nr[i] >= 5)         printf( LIVE n );       else         printf( DEAD n );     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int ret = 0;     while (n--) {       char str[1009];       int cnt = 0;       scanf( %s , str);       int flag = 1;       for (int i = 0; str[i]; i++) {         if (str[i] ==  4  || str[i] ==  7 ) {           cnt++;           if (cnt > m) {             flag = 0;             break;           }         }       }       if (flag == 1) {         ret++;       }     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct query {     int k, pos, ind;   } queries[200005];   struct arr {     int val, ind;   } a[200005];   long long n, q, cnt, res[200005], fw[200005], it[4 * 200005], len, b[200005];   bool cmp(arr a, arr b) {     if (a.val != b.val) return a.val > b.val;     return a.ind < b.ind;   }   bool que(query a, query b) { return a.k < b.k; }   void update(long long k, long long l, long long r, long long id) {     if (l == r) {       it[k] = 1;       return;     }     long long mid = (l + r) / 2;     if (id <= mid)       update(k * 2, l, mid, id);     else       update(k * 2 + 1, mid + 1, r, id);     it[k] = it[k * 2] + it[k * 2 + 1];   }   long long get(long long k, long long l, long long r, long long id) {     if (id > it[k]) return -1;     if (l == r) return l;     long long mid = (l + r) / 2;     if (id <= it[k * 2])       return get(k * 2, l, mid, id);     else       return get(k * 2 + 1, mid + 1, r, id - it[k * 2]);   }   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].val;       a[i].ind = i;       b[i] = a[i].val;     }     sort(a + 1, a + 1 + n, cmp);     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> queries[i].k >> queries[i].pos;       queries[i].ind = i;     }     sort(queries + 1, queries + 1 + q, que);     for (int i = 1; i <= q; i++) {       while (len != queries[i].k) {         len++;         update(1, 1, n, a[len].ind);       }       res[queries[i].ind] = b[get(1, 1, n, queries[i].pos)];     }     for (int i = 1; i <= q; i++) cout << res[i] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i, j, a[1000005], b[1000005], p = 0, q = 0, m, temp = 0,                                                flag = 0, ans, r = 0, s = 0;     vector<long long> v;     string str;     cin >> n;     map<long long, long long> mp;     while (1) {       if (mp[n] == 1) {         break;       }       mp[n] = 1;       p++;       n++;       while (n % 10 == 0) {         n = n / 10;       }     }     cout << p;     return 0;   }