#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int md = 998244353;   inline void add(int &x, int y) {     x += y;     if (x >= md) {       x -= md;     }   }   inline void sub(int &x, int y) {     x -= y;     if (x < 0) {       x += md;     }   }   inline int mul(int x, int y) { return (long long)x * y % md; }   inline int power(int x, int y) {     int result = 1;     for (; y; y >>= 1, x = mul(x, x)) {       if (y & 1) {         result = mul(result, x);       }     }     return result;   }   template <typename T>   class fenwick_t {    public:     vector<T> fenw;     int n;     fenwick_t(int n) : n(n) { fenw.resize(n); }     void modify(int x, T value) {       while (x < n) {         fenw[x] += value;         x |= x + 1;       }     }     T query(int x) {       T result{};       while (x >= 0) {         result += fenw[x];         x = (x & x + 1) - 1;       }       return result;     }     T get(int l, int r) { return query(r) - query(l - 1); }   };   int main() {     int n;     scanf( %d , &n);     if (n == 1) {       puts( 0 );       return 0;     }     vector<int> w(n + 1);     w[1] = 0;     w[2] = 1;     for (int i = 3; i <= n; ++i) {       w[i] = mul(i - 1, w[i - 1] + w[i - 2]);     }     vector<int> fact(n + 1);     fact[0] = 1;     for (int i = 1; i <= n; ++i) {       fact[i] = mul(fact[i - 1], i);     }     vector<vector<int>> f(n + 1, vector<int>(n + 1));     for (int i = 0; i <= n; ++i) {       f[i][0] = fact[i];       for (int j = 1; j <= i; ++j) {         f[i][j] = f[i][j - 1];         sub(f[i][j], f[i - 1][j - 1]);       }     }     vector<vector<int>> a(n, vector<int>(n));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , &a[i][j]);         --a[i][j];       }     }     int answer = 0;     {       fenwick_t<int> fenw(n);       for (int i = 0; i < n; ++i) {         fenw.modify(i, 1);       }       int coef = power(w[n], n - 1);       for (int i = 0; i < n; ++i) {         fenw.modify(a[0][i], -1);         add(answer, mul(fact[n - i - 1], mul(coef, fenw.query(a[0][i] - 1))));       }     }     for (int i = 1; i < n; ++i) {       fenwick_t<int> foo(n), bar(n);       vector<int> cnt(n);       int current = 0;       auto insert = [&](int x) {         if (++cnt[x] == 2) {           ++current;           foo.modify(x, 1);         }       };       auto get = [&](int x, int y) { return y < 0 || y > x ? 0 : f[x][y]; };       int coef = power(w[n], n - i - 1);       for (int j = n - 1; ~j; --j) {         insert(a[i - 1][j]);         insert(a[i][j]);         bar.modify(a[i][j], 1);         int u = foo.query(a[i][j] - 1), v = bar.query(a[i][j] - 1) - u;         add(answer,             mul(coef,                 mul(u, get(n - j - 1, current - (cnt[a[i - 1][j]] == 2) - 1))));         add(answer,             mul(coef, mul(v, get(n - j - 1, current - (cnt[a[i - 1][j]] == 2)))));         if (cnt[a[i - 1][j]] == 2 && a[i - 1][j] < a[i][j]) {           sub(answer, mul(coef, get(n - j - 1, current - 2)));         }       }     }     printf( %d n , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[200001];   long long int q[200001];   long long int pre[200001];   long long int binarysearch(long long int n, long long int p) {     long long int low = 1, high = n;     while (low <= high) {       long long int mid = (low + high) / 2;       if (pre[mid] <= p)         low = mid + 1;       else         high = mid - 1;     }     return high;   }   int main() {     long long int n, q1;     cin >> n >> q1;     for (long long int i = 1; i <= n; i++) cin >> a[i];     for (long long int i = 1; i <= q1; i++) cin >> q[i];     pre[1] = a[1];     for (long long int i = 2; i <= n; i++) pre[i] = a[i] + pre[i - 1];     long long int cal = 0;     for (long long int i = 1; i <= q1; i++) {       long long int ser = q[i] + cal;       long long int ans = binarysearch(n, ser);       if (ans < n)         cout << n - ans <<   n ;       else         cout << n <<   n ;       cal += q[i];       if (ans == n) cal = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, cost = 0, r, min = 100000000;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = 1; i <= a[n - 1]; i++) {       t = i;       for (int j = 0; j < n; j++) {         if (a[j] - t > 1) {           cost = cost + a[j] - (t + 1);         } else if (t - a[j] > 1) {           cost = cost + t - 1 - a[j];         }       }       if (cost < min) {         min = cost;         r = t;       }       cost = 0;     }     cout << r <<     << min;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     cin >> n >> m;     if (m == 0) {       cout <<  YES  << endl;       return 0;     }     vector<long long int> v(m);     for (long long int i = 0; i < m; cin >> v[i++])       ;     sort(v.begin(), v.end());     if (v[0] == 1 || v[m - 1] == n) {       cout <<  NO  << endl;       return 0;     }     int ind = 1, ans = 0;     for (int i = 0; i < (m - 2); i++) {       if ((v[i] == (v[i + 1] - 1)) && (v[i + 1] == (v[i + 2] - 1))) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int dp[1010][1010];   vector<int> arr;   int m;   int solve(int idx, int mod) {     if (idx == (int)arr.size())       return (mod == 0);     else if (dp[idx][mod] != -1)       return dp[idx][mod];     int ret = solve(idx + 1, mod);     if (ret) return (dp[idx][mod] = ret);     ret = solve(idx + 1, (mod + arr[idx]) % m);     return (dp[idx][mod] = ret);   }   int main() {     ios_base::sync_with_stdio(false);     for (int i = (int)(0); i < (int)(1010); i++)       for (int j = (int)(0); j < (int)(1010); j++) dp[i][j] = -1;     int n;     cin >> n >> m;     arr.resize(n);     for (int i = (int)(0); i < (int)(n); i++) cin >> arr[i];     if (n > m)       cout <<  YES  << endl;     else {       int yes = 0;       for (int i = (int)(0); i < (int)(n); i++) yes |= solve(i + 1, arr[i] % m);       if (yes)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   long long bigmod(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % 1000000007;       b >>= 1;       a = (a * a) % 1000000007;     }     return ret;   }   long long inverse(long long n) { return bigmod(n, 1000000007 - 2); }   long long add(long long a, long long b) {     long long ret = a + b;     if (ret >= 1000000007) ret %= 1000000007;     return ret;   }   long long subtract(long long a, long long b) {     long long ret = a - b;     if (ret < 0) ret += 1000000007;     return ret;   }   long long mult(long long a, long long b) {     long long ret = a * b;     if (ret >= 1000000007) ret %= 1000000007;     return ret;   }   bool checkBit(int n, int i) { return (n & (1 << i)); }   int setBit(int n, int i) { return (n | (1 << i)); }   int resetBit(int n, int i) { return (n & (~(1 << i))); }   long long a[500010], p[500010];   int main() {     int n, k;     scanf( %d%d , &n, &k);     long long sum = 0;     for (int i = 0; i < n; ++i) {       scanf( %lld , &a[i]);       sum += a[i];     }     sort(a, a + n);     long long avg = sum / n, rem = sum % n;     for (int i = 0; i < n; ++i) p[i] = avg;     for (int i = n - 1; rem; --i) {       --rem;       ++p[i];     }     long long up = 0, down = n - 1, days = 0;     for (int i = 0; i < n; ++i) {       if (a[i] <= p[i]) {         up = i;         days += p[i] - a[i];       } else         break;     }     for (int i = n - 1; i >= 0; --i) {       if (a[i] >= p[i])         down = i;       else         break;     };     ;     ;     if (k >= days) {       printf( %lld n , p[n - 1] - p[0]);       return 0;     }     long long mn = -1, mx = -1;     sum = 0, days = 0;     for (int i = 0; i < up + 1; ++i) {       ++sum;       long long x = a[i], y = min(a[i + 1], p[i + 1]);       days += sum * (y - x);       ;       if (days == k) {         mn = y;         break;       } else if (days > k) {         days -= sum * (y - x);         rem = k - days;         ;         mn = a[i] + rem / sum;         break;       }     };     sum = 0, days = 0;     for (int i = n - 1; i >= down; --i) {       ++sum;       long long x = a[i], y = max(a[i - 1], p[i - 1]);       days += sum * (x - y);       ;       if (days == k) {         mx = y;         break;       } else if (days > k) {         days -= sum * (x - y);         rem = k - days;         ;         mx = a[i] - rem / sum;         break;       }     };     cout << mx - mn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using Long = long long;   vector<vector<int>> G(100010);   int D[100010];   int dist[100010];   int P[100010];   int ep1 = -1, ep1lvl = -1, ep2 = -1, ep2lvl = -1;   void dfs(int u, int p, int lvl) {     if (lvl > ep1lvl) {       ep1lvl = lvl;       ep1 = u;     }     for (auto v : G[u]) {       if (v != p) dfs(v, u, lvl + 1);     }   }   void dfs1(int u, int p, int lvl) {     P[u] = p;     if (lvl > ep2lvl) {       ep2lvl = lvl;       ep2 = u;     }     for (auto v : G[u]) {       if (v != p) dfs1(v, u, lvl + 1);     }   }   int md;   vector<int> path;   void getMid(int u) {     while (P[u] != -1) {       path.push_back(u);       u = P[u];     }     path.push_back(u);     reverse(path.begin(), path.end());   }   bool ok = true;   int n, k;   int main() {     cin >> n >> k;     memset(D, 0, sizeof(D));     for (int i = 0; i < 100000; i++) P[i] = -1, dist[i] = 1 << 30;     int first = 0;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--, v--;       if (!i) first = u;       G[u].push_back(v);       G[v].push_back(u);       D[u]++, D[v]++;     }     dfs(first, -1, 1);     dfs1(ep1, -1, 1);     if (ep2lvl <= k) {       puts( No );       return 0;     }     getMid(ep2);     md = path[k];     queue<int> Q;     Q.push(md);     dist[md] = 0;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       if (u == md) {         if (D[u] < 3) ok = false;       } else {         if (dist[u] != k && (D[u] - 1) < 3) ok = false;         if (dist[u] == k && D[u] > 1) ok = false;       }       for (int v : G[u]) {         if (dist[v] == 1 << 30) {           dist[v] = dist[u] + 1;           Q.push(v);         }       }     }     (ok) ? puts( Yes ) : puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     if (e == 0) return 1;     if (e % 2 == 0) {       long long t = bigmod(p, e / 2, M);       return (T)((t * t) % M);     }     return (T)(((long long)bigmod(p, e - 1, M) * (long long)(p)) % M);   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   long long seg[4000001], ar[1000001], val[1000001];   void insert(int idx, int s, int e, int p, int v) {     if (s == e) {       seg[idx] = v;       return;     }     int mid = (s + e) / 2;     if (p <= mid)       insert(idx * 2 + 1, s, mid, p, v);     else       insert(idx * 2 + 2, mid + 1, e, p, v);     seg[idx] = seg[idx * 2 + 1] + seg[idx * 2 + 2];   }   long long query(int idx, int s, int e, int p) {     if (seg[idx] < p) return -1;     if (s == e) return s;     int mid = (s + e) / 2;     if (p <= seg[idx * 2 + 1])       return query(idx * 2 + 1, s, mid, p);     else       return query(idx * 2 + 2, mid + 1, e, p - seg[idx * 2 + 1]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long a, b, c, d, e, f, g, h = 1, x, y, z;     cin >> a >> b;     for (int i = (0); i < (b); ++i) cin >> ar[i];     c = 0;     for (int i = (0); i < (a); ++i) {       cin >> d;       if (d == -1) {         for (int j = (0); j < (b); ++j) {           e = query(0, 1, 1000000, ar[j] - j);           if (e == -1) break;           insert(0, 1, 1000000, e, 0);         }       } else {         c++;         val[c] = d;         insert(0, 1, 1000000, c, 1);       }     }     if (seg[0] == 0)       cout <<  Poor stack!  << endl;     else {       for (int i = (1); i < (seg[0] + 1); ++i) {         e = query(0, 1, 1000000, i);         cout << val[e];       }     }   }


#include <bits/stdc++.h>   using namespace std;   int row[1008], col[1008], n, m, a, b, cnt;   int main() {     cin >> n >> m;     for (int i = 0; i < n + 1; i++) row[i] = col[i] = true;     while (m--) {       cin >> a >> b;       row[a] = col[b] = false;     }     for (int i = 2; i < n; i++) cnt += (row[i] + col[i]);     if (n % 2) cnt -= (row[n / 2 + 1] && col[n / 2 + 1]);     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     out <<  (  << p.first <<  ,  << p.second <<  ) ;     return out;   }   template <class T1, class T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <class T>   istream& operator>>(istream& in, vector<T>& v) {     for (T& x : v) in >> x;     return in;   }   template <class T>   ostream& operator<<(ostream& out, vector<vector<T>>& v) {     for (vector<T>& x : v) out << x <<   n ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, vector<T>& v) {     for (T& x : v) out << x <<    ;     return out;   }   long long gcd(long long a, long long b) {     if (b > a) swap(a, b);     return (b ? gcd(b, a % b) : a);   }   using ll = long long;   using pii = pair<int, int>;   using pll = pair<long long, long long>;   using tiii = pair<pair<int, int>, int>;   using vi = vector<int>;   using vl = vector<long long>;   using vvi = vector<vector<int>>;   using vvl = vector<vector<long long>>;   const int h = 1000000007;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.setstate(ios::failbit);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vi v(n);       cin >> v;       vi x{v[0]};       for (int i = (1); i < (n); i++) {         if (v[i] == x.back() + 1)           x.back()++;         else           x.push_back(v[i]);       }       int y = true;       for (int i = (1); i < (x.size()); i++)         if (x[i - 1] < x[i]) y = false;       cout << (y ?  Yes  :  No ) <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize(2)   using namespace std;   const int maxn = 2e5 + 10;   char s[maxn];   int N, K;   long long T;   int A[22][22];   long long DP[1 << 22];   long long t[22];   int mask[22];   int main() {     scanf( %d %d %lld , &N, &K, &T);     scanf( %s , s + 1);     for (int i = 0; i < K; ++i) {       scanf( %lld , &t[i]);     }     for (int i = 0; i < K; ++i) {       for (int j = 0; j < K; ++j) {         scanf( %d , &A[i][j]);       }     }     for (int i = 0; i < K; ++i) {       DP[1 << i] = t[i];       mask[i] = -1;     }     int S = 0;     for (int i = 1; i <= N; ++i) {       int x = s[i] -  A ;       S |= (1 << x);       for (int j = 0; j < K; ++j) {         if (mask[j] >= 0) {           if ((mask[j] & (1 << j)) == 0 && (mask[j] & (1 << x)) == 0) {             DP[mask[j]] += A[j][x];             DP[mask[j] | (1 << j)] -= A[j][x];             DP[mask[j] | (1 << x)] -= A[j][x];             DP[mask[j] | (1 << j) | (1 << x)] += A[j][x];           }           mask[j] |= (1 << x);         }       }       mask[x] = 0;     }     for (int i = 0; i < K; ++i) {       for (int s = 0; s < (1 << K); ++s) {         if (s & (1 << i)) {           DP[s] += DP[s ^ (1 << i)];         }       }     }     long long ret = 0;     for (int s = 0; s < (1 << K); ++s) {       if ((s & S) == s && DP[s] <= T && s != S) {         ++ret;       }     }     printf( %lld n , ret);   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, m, n, x, y, z, ans, counting;   int ara[2000];   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> ara[i];     }     sort(ara, ara + n);     for (i = 0; i < n; i++) {       if (ara[i] != 0) break;     }     for (j = i + 1, counting = 1; j < n; j++) {       if (ara[j] == ara[j - 1]) {         counting++;       } else {         counting = 1;       }       if (counting > 2) {         printf( -1 );         return 0;       } else if (counting == 2)         ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int isWinning(string str) {     int n = str.length();     int arr[n + 1][n + 1];     for (int i = 0; i <= n; i++) arr[i][i] = 1;     return arr[1][n];   }   int main() {     int n;     cin >> n;     int arr[n];     long long ans;     long long sum = 0;     for (int i = 0; i < (n); ++i) {       cin >> arr[i];       sum += arr[i];     }     sort(arr, arr + n);     ans = sum;     if (n - 2 >= 0) {       for (int i = 0; i < n - 2; i++) {         ans += sum;         sum -= arr[i];       }       ans += arr[n - 2];       ans += arr[n - 1];     } else if (n == 1)       ans = arr[0];     else {       ans = 2 * sum;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char st[1000010];   int n, K;   int main() {     int i, j;     scanf( %d%d , &n, &K);     scanf( %s , st + 1);     for (i = 1; i < n && K; ++i)       if (st[i] ==  4  && st[i + 1] ==  7 ) {         if (i % 2)           st[i + 1] =  4 ;         else {           st[i] =  7 ;           if (i > 1 && st[i - 1] ==  4 ) {             if (K % 2 == 0) st[i] =  4 ;             break;           }         }         K--;       }     printf( %s n , st + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> go(int x, int d) {     long long mx = 0;     for (int i = 1; i <= d; i++) mx += 1ll << i;     if (mx < x) return vector<int>();     return vector<int>();   }   void solve() {     int n;     cin >> n;     long long x = n - 1;     long long curr = 1;     vector<long long> ans;     while (x > 0) {       if (curr <= x && x <= 2 * curr) {         ans.push_back(x - curr);         break;       } else if (x <= 4 * curr) {         ans.push_back(x / 2 - curr);         ans.push_back(x % 2);         break;       }       ans.push_back(curr);       curr *= 2;       x -= curr;     }     cout << ((int)ans.size()) <<   n ;     for (long long i : ans) cout << i <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int INF = 0x3f3f3f3f;   int a[110][110];   int dp[100][2];   const int M = 1e5 + 10;   int vis[M], prime[M];   void prim() {     memset(vis, 0, sizeof(vis));     memset(prime, 0, sizeof(prime));     int cun = 1;     for (int i = 2; i <= M; i++) {       if (vis[i] == 0) {         prime[cun++] = i;       }       for (int j = 1; j <= cun && prime[j] * i < M; j++) {         vis[i * prime[j]] = 1;         if (i % prime[j] == 0) {           break;         }       }     }   }   int main() {     int t;     cin >> t;     int sum = 0;     prim();     while (t--) {       long long n, m;       cin >> n >> m;       int temp = n + m - 2;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) a[i][j] += i - i + j - j;       }       for (int i = 0; i <= (temp / 2); i++) {         dp[i][0] = 0;         dp[i][1] = 0;       }       if (temp % 2) {         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             int fl = i + j;             if (fl <= temp / 2)               dp[fl][a[i][j]]++;             else               dp[temp - fl][a[i][j]]++;           }         }         int ans = 0;         for (int i = 0; i <= temp / 2; i++) {           ans += min(dp[i][0], dp[i][1]);         }         cout << ans << endl;       } else {         int ans = 0;         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             int fl = i + j;             if (fl == temp / 2) continue;             if (fl < temp / 2)               dp[fl][a[i][j]]++;             else {               dp[temp - fl][a[i][j]]++;             }           }         }         for (int i = 0; i <= (temp / 2 - 1); i++) {           ans += min(dp[i][0], dp[i][1]);         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 350009;   long long Q, N, currentS[NMAX], s[NMAX], t[NMAX], l[NMAX], r[NMAX], v[NMAX],       type[NMAX];   vector<long long> ts;   map<long long, long long> inverseT;   void read() {     scanf( %I64d , &Q);     for (int i = 1; i <= Q; i++) {       scanf( %I64d , &type[i]);       if (type[i] == 1)         scanf( %I64d %I64d , &t[i], &s[i]), ts.push_back(t[i]);       else if (type[i] == 2)         scanf( %I64d , &t[i]);       else {         scanf( %I64d %I64d %I64d , &l[i], &r[i], &v[i]);         ts.push_back(l[i]), ts.push_back(r[i]);       }     }     sort(ts.begin(), ts.end());     ts.erase(unique(ts.begin(), ts.end()), ts.end()), N = ts.size();     for (long long i = 0; i < N; i++) inverseT[ts[i]] = i + 1;     long long lastVal = ts[N - 1];     ts.push_back(lastVal);     for (int i = 1; i <= Q; i++)       if (type[i] <= 2)         t[i] = inverseT[t[i]];       else         l[i] = inverseT[l[i]], r[i] = inverseT[r[i]];   }   set<long long> currTimes;   long long sum[4 * NMAX], mi[4 * NMAX];   long long vl[4 * NMAX];   bool lzy[4 * NMAX];   long long getLength(long long x, long long y) { return ts[y] - ts[x - 1]; }   void split(long long nod, long long st, long long mij, long long dr,              long long f1, long long f2) {     if (lzy[nod] == 0) return;     lzy[f1] = lzy[f2] = 1;     vl[f1] = vl[f2] = vl[nod];     sum[f1] = 1LL * vl[nod] * getLength(st, mij);     mi[f1] = min(0LL, sum[f1]);     sum[f2] = 1LL * vl[nod] * getLength(mij + 1, dr);     mi[f2] = min(0LL, sum[f2]);     lzy[nod] = 0;   }   void setValue(long long nod, long long st, long long dr, long long x,                 long long y, long long s) {     if (x <= st && dr <= y) {       vl[nod] = s, lzy[nod] = 1;       sum[nod] = 1LL * s * getLength(st, dr);       mi[nod] = min(0LL, sum[nod]);       return;     }     long long mij = (st + dr) >> 1, f1 = nod << 1, f2 = f1 | 1;     split(nod, st, mij, dr, f1, f2);     if (x <= mij) setValue(f1, st, mij, x, y, s);     if (mij < y) setValue(f2, mij + 1, dr, x, y, s);     sum[nod] = sum[f1] + sum[f2];     mi[nod] = min(mi[f1], sum[f1] + mi[f2]);   }   long double ansQ = -1.0;   const long double eps = 1e-9;   long long curr;   void query(long long nod, long long st, long long dr, long long x,              long long y) {     if (ansQ > -0.5) return;     if (x <= st && dr <= y) {       long long mij = (st + dr) >> 1, f1 = nod << 1, f2 = f1 | 1;       if (st == dr) {         if (mi[nod] + curr > 0) {           curr += sum[nod];           return;         }         long long t1 = ts[st - 1], t2 = ts[st];         assert(vl[nod] < 0);         ansQ = t1 + 1.0 * curr / (-vl[nod]);         assert(ansQ > -0.5);         return;       }       split(nod, st, mij, dr, f1, f2);       if (curr + mi[f1] <= 0) {         query(f1, st, mij, x, y);         assert(ansQ > -0.5);       } else if (curr + sum[f1] + mi[f2] <= 0) {         curr += sum[f1], query(f2, mij + 1, dr, x, y);         assert(ansQ > -0.5);       } else         curr += sum[nod];       return;     }     long long mij = (st + dr) >> 1, f1 = nod << 1, f2 = f1 | 1;     split(nod, st, mij, dr, f1, f2);     if (x <= mij) query(f1, st, mij, x, y);     if (mij < y) query(f2, mij + 1, dr, x, y);   }   int main() {     read();     for (long long i = 1; i <= Q; i++) {       if (type[i] == 1) {         currTimes.insert(t[i]);         auto it = currTimes.find(t[i]);         it++;         long long rgt = N;         if (it != currTimes.end()) rgt = (*it) - 1;         setValue(1, 1, N, t[i], rgt, s[i]);         currentS[t[i]] = s[i];         continue;       }       if (type[i] == 2) {         auto it = currTimes.find(t[i]);         long long s = 0;         if (it != currTimes.begin()) {           auto it2 = it;           it2--;           s = currentS[*it2];         }         it++;         long long rgt = N;         if (it != currTimes.end()) rgt = (*it) - 1;         setValue(1, 1, N, t[i], rgt, s);         currTimes.erase(t[i]), currentS[t[i]] = 0;         continue;       }       ansQ = -1.0;       if (v[i] == 0) {         printf( %I64d n , ts[l[i] - 1]);         continue;       }       if (l[i] != r[i]) {         auto it = currTimes.lower_bound(l[i]);         if (it != currTimes.end() && (*it) < r[i])           curr = v[i], query(1, 1, N, *it, r[i] - 1);       }       assert(ansQ <= ts[r[i] - 1] + eps);       cout << setprecision(15) << ansQ <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5;   int d[maxn];   std::vector<int> G[maxn];   int dp(int u) {     if ((int)G[u].size() == 0) {       return d[u] = 1;     } else if (d[u]) {       return d[u];     }     for (int i : G[u]) {       d[u] += dp(i);     }     return d[u];   }   int c[maxn];   int main(int argc, char const *argv[]) {     int n;     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 2; i <= n; ++i) {       int u;       cin >> u;       G[u].push_back(i);     }     dp(1);     for (int i = 1; i <= n; ++i) {       c[d[i]]++;     }     int sum = c[1];     int res = 1;     for (int i = 1; i <= n; ++i) {       while (i > sum) {         sum += c[++res];       }       cout << res <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T nextInt() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) {       p = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * p;   }   const int maxN = (int)3e5 + 10;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   const long long LLINF = (long long)1e18;   const long double pi = acos(-1.0);   int x[2];   int y[2];   int r[2];   long double d;   long double solve(int xa, int ya, int ra, int xb, int yb, int rb) {     long double angle =         2 * acos((rb * 1LL * rb - ra * 1LL * ra - d * d) / (-2 * ra * d));     return pi * ra * ra * angle / (2 * pi) - 1LL * ra * ra * sin(angle) / 2;   }   int main() {     cin >> x[0] >> y[0] >> r[0] >> x[1] >> y[1] >> r[1];     d = sqrtl((x[0] - x[1]) * 1LL * (x[0] - x[1]) +               (y[0] - y[1]) * 1LL * (y[0] - y[1]));     cout.precision(21);     if (d >= r[0] + r[1]) {       cout << 0 <<   n ;       return 0;     }     if (d <= abs(r[0] - r[1])) {       cout << pi * min(r[0], r[1]) * min(r[0], r[1]) <<   n ;       return 0;     }     cout << solve(x[0], y[0], r[0], x[1], y[1], r[1]) +                 solve(x[1], y[1], r[1], x[0], y[0], r[0])          <<   n ;     return 0;   }


#include <bits/stdc++.h>   int abss(int x) { return x > 0 ? x : -x; }   int main() {     int n, m, x1, y1, x2, y2;     while (scanf( %d %d %d %d %d %d , &n, &m, &x1, &y1, &x2, &y2) == 6) {       int chax = abss(x1 - x2);       int chay = abss(y1 - y2);       bool ansflag = 0;       if (x1 == x2 && y1 == y2)         ansflag = 1;       else {         if (chax == 0 || chay == 0) {           if (chax + chay <= 4) ansflag = 1;         } else {           if (chax < chay)             chay--;           else             chax--;           if ((chax < 3 && chay <= 3) || (chax <= 3 && chay < 3)) ansflag = 1;         }       }       if (ansflag)         puts( First );       else         puts( Second );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string obj;   bool solve(int x) {     string s = to_string(x);     string ans;     for (int i = 0; i < s.size(); i++)       if (s[i] ==  7  || s[i] ==  4 ) ans.push_back(s[i]);     return ans == obj;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int a, b;     cin >> a >> b;     obj = to_string(b);     int i = a + 1;     while (!solve(i)) i++;     cout << i <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0;     char c;     while ((c = getchar()) <  0  || c >  9 )       ;     do {       s = s * 10 + c -  0 ;     } while ((c = getchar()) >=  0  && c <=  9 );     return s;   }   bool descending(int a, int b) { return a > b; }   string toStr(char c) { return string(1, c); }   const int maxN = (int)1e2 + 10;   const int inf = (int)1e9;   int x;   int a[maxN];   long long dp[maxN];   vector<int> vl;   int main() {     int n;     cin >> n;     int cnt = 0;     for (int i = 0; i < (n); i++) {       cin >> x;       cnt += x;     }     cout << fixed << setprecision(12);     cout << cnt / double(n) << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long a[501][501];   bool visited[501];   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       visited[i] = false;       for (long long j = 0; j < n; j++) {         cin >> a[i][j];       }     }     vector<long long> order(n);     for (long long i = 0; i < n; i++) {       cin >> order[i];       order[i]--;     }     visited[order[n - 1]] = true;     vector<long long> values;     for (long long k = 0; k < n; k++) {       long long ans = 0;       long long p = order[n - k - 1];       visited[p] = true;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < n; j++) {           a[i][j] = min(a[i][j], a[i][p] + a[p][j]);           if (visited[i] && visited[j] && visited[p]) {             ans += a[i][j];           }         }       }       values.push_back(ans);     }     for (long long i = 0; i < n; i++) {       cout << values[n - 1 - i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   class Node {    public:     Node<T> *prev;     Node<T> *next;     T data;     Node(T data);   };   template <class T>   Node<T>::Node(T data) {     this->data = data;   }   template <class T>   class Stack {    public:     Node<T> *top;     int size;     Stack();     bool empty();     void push(T a);     void pop();     void clear();   };   template <class T>   Stack<T>::Stack() {     top = NULL;     size = 0;   }   template <class T>   bool Stack<T>::empty() {     return (size == 0);   }   template <class T>   void Stack<T>::push(T data) {     Node<T> *t = new Node<T>(data);     t->next = top;     top = t;     size++;     return;   }   template <class T>   void Stack<T>::pop() {     top = top->next;     size--;     return;   }   template <class T>   void Stack<T>::clear() {     top = NULL;     size = 0;   }   int main() {     Stack<int> *st = new Stack<int>();     int n;     cin >> n;     int a;     int answer = 0;     int size = 0;     int leftSum = 0, rightSum = 0;     for (int i = 0; i < n; i++) {       cin >> a;       rightSum = rightSum + a;       st->push(a);       size++;     }     while (!st->empty()) {       leftSum = leftSum + st->top->data;       rightSum = rightSum - st->top->data;       if (leftSum == rightSum && size != 1) answer++;       st->pop();       size--;     }     cout << answer;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cekTanda(char ch) {     switch (ch) {       case  > :         return 8;       case  < :         return 9;       case  + :         return 10;       case  - :         return 11;       case  . :         return 12;       case  , :         return 13;       case  [ :         return 14;       case  ] :         return 15;     }   }   int main() {     char str[1024];     scanf( %s , str);     int panjang = strlen(str);     int res = 0;     for (int i = 0; i < panjang; i++) {       res = (res << 4) % 1000003;       res += cekTanda(str[i]);       res %= 1000003;     }     printf( %d , res);   }


#include <bits/stdc++.h>   const long long N = 500005;   const long long mod = 1e9 + 7;   using namespace std;   std::vector<long long> adj[N];   std::vector<bool> vis(N);   void solve() {     long long n, m, k, x = 0, y = 0, c = 0, q, ans = 0;     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     x = 0;     for (int i = 1; i <= n; ++i) {       if (x < adj[i].size()) {         x = adj[i].size();         y = i;       }     }     std::vector<pair<long long, long long> > v;     queue<long long> nodes;     nodes.push(y);     vis[y] = 1;     while (!nodes.empty()) {       x = nodes.front();       nodes.pop();       for (auto i : adj[x]) {         if (!vis[i]) {           vis[i] = 1;           nodes.push(i);           v.push_back({x, i});         }       }     }     for (int i = 0; i < v.size(); ++i) {       cout << v[i].first <<     << v[i].second <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int nb;     scanf( %d , &nb);     int arr[nb];     for (int i = 0; i < nb; i++) scanf( %d , arr + i);     sort(arr, arr + nb);     int occ[3] = {0};     for (int i = 0; i < nb; i++) {       for (int j = 0; j < 3; j++)         if (arr[i] == arr[j]) occ[j]++;     }     if ((occ[0] == 1 && occ[1] == 1) || (occ[0] == 2)) {       printf( %d , occ[2]);       return 0;     }     if (occ[0] == 1 && occ[1] >= 2) {       long long res = (occ[1] * (long long)(occ[1] - 1)) / 2;       printf( %lld , res);       return 0;     }     long long res = (occ[0] * (long long)(occ[0] - 1) * (occ[0] - 2)) / 6;     printf( %lld , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   void solve() {     int n, k, d;     cin >> n >> k >> d;     vector<int> a(n);     map<int, int> used;     for (int i = 0; i < n; i++) cin >> a[i];     int cnt = 0, ans = INF;     for (int i = 0; i < d; i++) {       if (used[a[i]] == 0) cnt++;       used[a[i]]++;     }     for (int i = d; i < n; i++) {       ans = min(ans, cnt);       used[a[i - d]]--;       if (used[a[i - d]] == 0) cnt--;       if (used[a[i]] == 0) cnt++;       used[a[i]]++;     }     ans = min(cnt, ans);     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int _t;     cin >> _t;     for (int _q = 0; _q < _t; _q++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int *arr = new int[n];       for (int i = 0; i < n; i++) cin >> arr[i];       int j, k;       for (int i = 0; i < n; i++) {         if (arr[i] == 1) {           j = i;           break;         }       }       for (int i = n - 1; i >= 0; i--) {         if (arr[i] == 1) {           k = i;           break;         }       }       int ans = 0;       for (int i = j; i <= k; i++) {         if (arr[i] == 0) ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, d, bd[4];   vector<long long> pst[4][100069];   int main() {     long long i, j, ii, k, l, z = 1, y, x, p;     bool ft = 1;     scanf( %lld%lld%lld , &n, &m, &d);     for (i = 0; i < d; i++) {       scanf( %lld%lld , &k, &l);       for (ii = 0; ii < 4; ii++) {         pst[ii][k].push_back(l);         l = m + 1 - l;         swap(k, l);         swap(n, m);       }     }     for (ii = 0; ii < 4; ii++) {       for (i = 1; i <= n; i++) {         sort(pst[ii][i].begin(), pst[ii][i].end());         pst[ii][i].push_back(m + 1);       }       bd[ii] = m + 1;       swap(n, m);     }     y = 1;     x = 1;     for (ii = 0; 1; ii = (ii + 1) % 4) {       p = min(bd[ii], *upper_bound(pst[ii][y].begin(), pst[ii][y].end(), x)) - 1;       k = p - x;       bd[(ii + 3) % 4] = n + 1 - y;       x = p;       z += k;       if (k == 0 && !ft) {         break;       }       ft = 0;       x = m + 1 - x;       swap(y, x);       swap(n, m);     }     if (z == n * m - d) {       printf( Yes n );     } else {       printf( No n );     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   void SieveOfEratosthenes(long long n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long p = 2; p <= n; p++)       if (prime[p]) v.push_back(p);   }   signed main() {     long long n;     cin >> n;     SieveOfEratosthenes(n);     long long m = v.size();     vector<long long> ans;     long long ct = 0;     for (long long i = 0; i < m; i++) {       long long p = v[i];       while (p <= n) {         ct++;         ans.push_back(p);         p = p * v[i];       }     }     cout << ct <<   n ;     long long k = ans.size();     for (long long i = 0; i < k; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   struct sp {     int x, y;     bool operator<(const sp &a) const { return x < a.x || x == a.x && y < a.y; }     bool operator==(const sp &a) const { return x == a.x && y == a.y; }   };   namespace std {   template <>   struct hash<sp> {     size_t operator()(sp a) const { return a.x * 9875321 + a.y; }   };   }  // namespace std   unordered_map<sp, int> m1;   vector<int> b;   vector<int> a[110000];   int n, m, ans;   int main() {     int i, j, k, x, y, d;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       a[x].push_back(y);       m1[sp{x, y}] = 1;     }     m = sqrt(n);     for (i = 0; i <= 100000; i++)       if (a[i].size() >= m) b.push_back(i);     for (i = 0; i < b.size(); i++)       for (j = i + 1; j < b.size(); j++) {         d = b[j] - b[i];         x = b[i];         for (k = 0; k < a[x].size(); k++) {           y = a[x][k];           if (m1.count(sp{x + d, y}) && m1.count(sp{x, y + d}) &&               m1.count(sp{x + d, y + d}))             ans++;         }       }     for (i = 0; i <= 100000; i++)       if (a[i].size() < m) {         sort(a[i].begin(), a[i].end());         x = i;         for (j = 0; j < a[x].size(); j++) {           y = a[x][j];           for (k = j + 1; k < a[x].size(); k++) {             d = a[x][k] - a[x][j];             if (m1.count(sp{x + d, y}) && m1.count(sp{x + d, y + d})) ans++;             if (x - d >= 0 && a[x - d].size() >= m)               if (m1.count(sp{x - d, y}) && m1.count(sp{x - d, y + d})) ans++;           }         }       }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   constexpr int kN = int(4E3 + 10), kInf = int(1E9 + 10);   int a[kN];   void solve() {     int n, m, k, lft, ans = 0, tmp;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     m--;     k = min(k, m);     lft = m - k;     for (int i = 0; i <= k; i++) {       tmp = kInf;       for (int j = 0; j <= lft; j++)         tmp = min(tmp, max(a[i + j + 1], a[n - (k - i) - (lft - j)]));       ans = max(ans, tmp);     }     printf( %d n , ans);   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   const long long int MOD = 1000000007;   const long long int MAXN = 1000005;   const long long int INF = 100000000000005;   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n), pos, neg;     for (long long int i = 0; i < n; ++i) cin >> a[i];     long long int ans = 1;     if (n == 5) {       for (long long int i = 0; i < n; ++i) {         ans = ans * a[i];       }       cout << ans << endl;       return;     }     for (auto itr : a) {       if (itr < 0) {         neg.push_back(itr);       } else {         pos.push_back(itr);       }     }     if (pos.size() == 0 and neg.size() == 0) {       ans = 0;     } else if (pos.size() == 0) {       sort(neg.begin(), neg.end());       reverse(neg.begin(), neg.end());       if (neg.size() < 5) {         ans = 0;       } else {         for (long long int i = 0; i < 5; ++i) {           ans = ans * neg[i];         }       }     } else if (neg.size() == 0) {       sort(pos.begin(), pos.end());       reverse(pos.begin(), pos.end());       if (pos.size() < 5) {         ans = 0;       } else {         for (long long int i = 0; i < 5; ++i) {           ans = ans * pos[i];         }       }     } else {       sort(pos.begin(), pos.end());       sort(neg.begin(), neg.end());       long long int si_pos = pos.size(), si_neg = neg.size(), res = -INF;       if (si_neg + si_pos < 5) {         ans = 0;       } else {         if (si_pos >= 5) {           res = max(res, pos[si_pos - 1] * pos[si_pos - 2] * pos[si_pos - 3] *                              pos[si_pos - 4] * pos[si_pos - 5]);         }         if (si_pos >= 3 and si_neg >= 2) {           res = max(res, pos[si_pos - 1] * pos[si_pos - 2] * pos[si_pos - 3] *                              neg[0] * neg[1]);         }         if (si_pos >= 1 and si_neg >= 4) {           res = max(res, pos[si_pos - 1] * neg[2] * neg[3] * neg[0] * neg[1]);         }         ans = res;       }     }     cout << ans << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num[200005];   int lis[200005];   int main() {     int n1, n2, n3;     cin >> n1 >> n2 >> n3;     for (int i = 1; i <= n1 + n2 + n3; i++) {       cin >> num[i];     }     sort(num + 1, num + 1 + n1);     sort(num + 1 + n1, num + 1 + n1 + n2);     sort(num + 1 + n1 + n2, num + 1 + n1 + n2 + n3);     int st = 1, et = 1;     lis[1] = num[1];     for (int i = 2; i <= n1 + n2 + n3; i++) {       int l = st, r = et;       if (num[i] >= lis[et]) {         et++;         lis[et] = num[i];         continue;       }       while (l < r) {         int mid = (l + r) >> 1;         if (lis[mid] < num[i]) {           l = mid + 1;         } else {           r = mid;         }       }       lis[l] = num[i];     }     cout << n1 + n2 + n3 - et << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       long long ans = 0;       for (int i = 0; i <= 8 && i <= n; i++) {         for (int j = 0; j <= (i == 0 ? 8 : 4) && i + j <= n; j++) {           ans += n + 1 - i - j;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, ar, b, fi;   int i, j, ans, o1[3000], o2[3000];   int main() {     ios_base::sync_with_stdio(0);     cin >> a >> b;     ar = a;     reverse(ar.begin(), ar.end());     for (; i < b.size(); ++i) {       if (a.find(b[i]) == string::npos) {         cout <<  -1 n ;         return 0;       }     }     for (i = 0; i < b.size();) {       for (j = 1; i + j <= b.length(); ++j) {         fi = b.substr(i, j);         if (a.find(fi) == string::npos && ar.find(fi) == string::npos) {           if (a.find(b.substr(i, j - 1)) == string::npos) {             o1[ans] = a.length() - ar.find(b.substr(i, j - 1));             o2[ans] = a.length() - ar.find(b.substr(i, j - 1)) - j + 2;           } else {             o1[ans] = a.find(b.substr(i, j - 1)) + 1;             o2[ans] = a.find(b.substr(i, j - 1)) + j - 1;           }           i += j - 1;           ++ans;           break;         } else if (i + j == b.length()) {           if (a.find(b.substr(i, j)) == string::npos) {             o1[ans] = a.length() - ar.find(b.substr(i, j));             o2[ans] = a.length() - ar.find(b.substr(i, j)) - j + 1;           } else {             o1[ans] = a.find(b.substr(i, j)) + 1;             o2[ans] = a.find(b.substr(i, j)) + j;           }           i += j;           ++ans;         }       }     }     cout << ans <<   n ;     for (i = 0; i < ans; ++i) cout << o1[i] <<     << o2[i] <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   inline void amin(T &x, const T &y) {     if (y < x) x = y;   }   template <class T>   inline void amax(T &x, const T &y) {     if (x < y) x = y;   }   template <class Iter>   void rprintf(const char *fmt, Iter begin, Iter end) {     for (bool sp = 0; begin != end; ++begin) {       if (sp)         putchar(   );       else         sp = true;       printf(fmt, *begin);     }     putchar(  n );   }   int N;   int T[100011];   int X[100011];   int Y[100011];   int val[100011];   void MAIN() {     int R;     scanf( %d%d , &R, &N);     for (int i = 0, i_len = (N); i < i_len; ++i)       scanf( %d%d%d , T + i, X + i, Y + i);     const int INF = 1 << 29;     for (int i = 0, i_len = (N); i < i_len; ++i) {       val[i] = -INF;       if (X[i] + Y[i] - 2 <= T[i]) val[i] = 1;       for (int j = i - 1; j >= 0; j--) {         if (abs(X[i] - X[j]) + abs(Y[i] - Y[j]) <= T[i] - T[j]) {           amax(val[i], val[j] + 1);         }         if (T[i] - T[j] > 2000) break;       }     }     int ans = 0;     for (int i = 0, i_len = (N); i < i_len; ++i) amax(ans, val[i]);     printf( %d n , ans);   }   int main() {     int TC = 1;     for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   pair<long long, long long> dp[20][1 << 10];   int a[20];   long long pw[20];   int change(long long n) {     int cnt = 0;     while (n) {       if (n & 1) cnt++;       n /= 2;     }     return cnt;   }   int k;   long long pow(int e, int n) {     long long ans = 1;     while (n--) {       ans *= e;     }     return ans;   }   pair<long long, long long> dfs(int len, long long Set, bool zero, bool limit) {     if (len == 0) {       if (change(Set) <= k) return make_pair(1, 0);       return make_pair(0, 0);     }     if (!limit && dp[len][Set].first != 0 && !zero) return dp[len][Set];     int u = limit ? a[len - 1] : 9;     pair<long long, long long> ans = make_pair(0, 0);     for (int i = 0; i <= u; i++) {       pair<long long, long long> tem = make_pair(0, 0);       if (change(Set | (1 << i)) > k) continue;       if (zero && i == 0)         tem = dfs(len - 1, Set, zero, i == u && limit);       else {         tem = dfs(len - 1, Set | (1 << i), zero && i == 0, i == u && limit);       }       ans.first += tem.first;       ans.first %= mod;       ans.second =           (ans.second + i * tem.first % mod * pw[len - 1] % mod + tem.second) %           mod;     }     if (!limit && !zero) dp[len][Set] = ans;     return ans;   }   void init() {     pw[0] = 1;     for (int i = 1; i < 20; i++) pw[i] = (pw[i - 1] * 10) % mod;     for (int i = 0; i < 20; i++)       for (int j = 0; j < 1 << 9; j++) dp[i][j].first = dp[i][j].second = 0;   }   long long solve(long long n) {     int len = 0;     init();     while (n) {       a[len++] = n % 10;       n /= 10;     }     return dfs(len, 0, 1, 1).second;   }   int main() {     long long l, r;     while (cin >> l >> r >> k) {       cout << (solve(r) - solve(l - 1) + mod) % mod << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> ans(n);     int a1, a2, a3;     cout <<  ? 1 2  << endl;     fflush(stdout);     cin >> a1;     cout <<  ? 1 3  << endl;     fflush(stdout);     cin >> a2;     cout <<  ? 2 3  << endl;     fflush(stdout);     cin >> a3;     int t = (a1 + a2 - a3) / 2;     ans[0] = t;     ans[2] = a2 - t;     ans[1] = a3 - ans[2];     for (int i = 3; i < n; i++) {       int now = 0;       cout <<  ? 1   << i + 1 << endl;       fflush(stdout);       cin >> now;       ans[i] = now - t;     }     cout <<  !  ;     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a, ok, ans, occ[10];   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a);       int total = k + 1;       memset(occ, 0, sizeof(occ));       while (a) {         if (!occ[a % 10] && (a % 10 <= k)) {           total--;         }         occ[a % 10] = 1;         a /= 10;       }       if (!total) {         ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int R = 1000;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, s, d;     cin >> n >> s >> d;     vector<bitset<R>> a(s);     for (int i = 0, k, x; i < s; ++i) {       cin >> k;       while (k--) cin >> x, a[i][x - 1] = 1;     }     vector<pair<int, bitset<R>>> f1;     int m = min(s, 10);     for (int i = 0; i < 1 << m; ++i) {       f1.push_back({0, {}});       for (int j = 0; j < m; ++j)         if (i >> j & 1) ++f1.back().first, f1.back().second ^= a[j];     }     unordered_map<bitset<R>, int> mp;     int m2 = s - m;     for (int i = 0; i < 1 << m2; ++i) {       bitset<R> b;       int c = 0;       for (int j = 0; j < m2; ++j)         if (i >> j & 1) ++c, b ^= a[m + j];       if (!mp.count(b))         mp[b] = c;       else         mp[b] = min(mp[b], c);     }     for (int k, x; d--;) {       cin >> k;       bitset<R> b;       while (k--) cin >> x, b[x - 1] = 1;       int ans = 1 << 30;       for (auto &i : f1) {         b ^= i.second;         if (mp.count(b)) ans = min(ans, i.first + mp[b]);         b ^= i.second;       }       if (ans == 1 << 30) ans = -1;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 10000 + 10;   int n, m;   int second[200], a[200];   bool vis[200];   int main() {     scanf(  %d %d , &n, &m);     for (int i = 0; i < m; i++) scanf(  %d , &second[i]);     for (int i = 0; i < m; i++) second[i]--;     bool win = true;     for (int i = 0; i < m - 1; i++) {       int next = second[i + 1];       if (next <= second[i]) next += n;       if (a[second[i]] == 0 ||           a[second[i]] != 0 && a[second[i]] == next - second[i])         a[second[i]] = next - second[i];       else         win = false;     }     for (int i = 0; i < n; i++) {       if (vis[a[i]] && a[i] != 0) win = false;       vis[a[i]] = true;     }     if (win) {       int ind = 1;       for (int i = 0; i < n; i++) {         if (a[i] == 0) {           while (vis[ind]) ind++;           a[i] = ind;           vis[ind] = true;         }       }       for (int i = 0; i < n; i++) {         if (i > 0) printf(   );         printf( %d , a[i]);       }       printf(  n );     } else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e3 + 10;   int n, a[MAXN], k, dp[MAXN];   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     long long l = -1, r = 2e9 + 1;     while (l + 1 < r) {       long long mid = (r + l) / 2;       bool flag = false;       for (int i = 0; i < n; i++) {         dp[i] = i;         for (int j = 0; j < i; j++) {           if (abs(a[i] - a[j]) > (i - j) * mid) continue;           dp[i] = min(dp[i], dp[j] + i - j - 1);         }         if (dp[i] + n - i - 1 <= k) {           flag = true;           break;         }       }       if (flag)         r = mid;       else         l = mid;     }     cout << r;   }


#include <bits/stdc++.h>   using namespace std;   long long* parent;   long long* size;   void make_set(long long v) {     parent[v] = v;     size[v] = 1;   }   long long find_set(long long v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_set(long long u, long long v) {     long long p1, p2;     p1 = find_set(u);     p2 = find_set(v);     if (p1 != p2) {       if (size[p1] < size[p2]) swap(p1, p2);       parent[p2] = p1;       size[p1] += size[p2];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     vector<long long> vc(n + 1);     parent = new long long[n + 1];     size = new long long[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> vc[i];       make_set(i);     }     long long a, b;     for (long long i = 0; i < m; i++) {       cin >> a >> b;       union_set(a, b);     }     unordered_map<long long, long long> mp;     vector<vector<long long> > ele(n + 1);     vector<vector<long long> > ind(n + 1);     long long k;     long long p = 0, pp;     for (long long i = 1; i <= n; i++) {       k = find_set(i);       if (mp[k] == 0) {         p++;         pp = p;         mp[k] = p;       } else {         pp = mp[k];       }       ele[pp].push_back(vc[i]);       ind[pp].push_back(i);     }     for (long long i = 1; i <= p; i++) {       sort(ele[i].begin(), ele[i].end(), greater<long long>());       sort(ind[i].begin(), ind[i].end());       for (long long j = 0; j < ele[i].size(); j++) {         vc[ind[i][j]] = ele[i][j];       }     }     for (long long i = 1; i <= n; i++) cout << vc[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   const int MAX_N = 3e5 + 2;   struct Ant {     int id;     long long pos, speed;     Ant(){};     Ant(int id, long long pos, long long speed) {       this->id = id;       this->pos = pos;       this->speed = speed;     }   };   bool comparePosition(Ant a, Ant b) { return (a.pos < b.pos); }   long long mod(long long x, long long m) { return ((x % m) + m) % m; }   int ans[MAX_N];   std::vector<Ant> startPosition, endPosition;   int main() {     int n;     long long cycleLength, time;     std::cin >> n >> cycleLength >> time;     for (int i = 1; i <= n; i++) {       int pos;       char dir;       std::cin >> pos >> dir;       startPosition.push_back(Ant(i, pos, (dir ==  R ) ? 1 : -1));     }     std::sort(startPosition.begin(), startPosition.end(), comparePosition);     for (int i = 0; i < (int)startPosition.size(); i++)       endPosition.push_back(startPosition[i]);     long long cyclicShift = 0;     for (int i = 0; i < n; i++) cyclicShift += startPosition[i].speed;     cyclicShift = mod(cyclicShift * (time / cycleLength), n);     time %= cycleLength;     for (int i = 0; i < n; i++) {       endPosition[i].pos =           mod((startPosition[i].pos - 1) + time * startPosition[i].speed,               cycleLength) +           1;       if (startPosition[i].speed == 1) {         if (endPosition[i].pos < startPosition[i].pos) cyclicShift++;       } else {         if (endPosition[i].pos > startPosition[i].pos) cyclicShift--;       }     }     cyclicShift = mod(cyclicShift, n);     std::sort(endPosition.begin(), endPosition.end(), comparePosition);     for (int i = 0; i < n; i++) {       endPosition[i].id = startPosition[mod(i - cyclicShift, n)].id;       ans[endPosition[i].id] = endPosition[i].pos;     }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 810;   int gi() {     int x = 0, o = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   int n, ans[N], pos[N], odd[N], p[N];   bool vis[10];   int query(vector<int> a) {     cout <<  ?   << int(a.size());     for (auto x : a) cout <<     << x;     cout << endl;     int t = gi();     if (t == -1) throw  orzxzz ;     return t;   }   int query_3(int x) {     if (query({pos[1], pos[2], x})) return 0;     if (query({pos[1], pos[3], x})) return 2;     return 1;   }   int query_5(int x) {     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= 4; i++) {       int val = (5 - (3 * n - 3 + i) % 5) % 5;       if (query({pos[n], pos[n - 1], pos[n - 2], pos[i], x})) return val;       vis[val] = 1;     }     for (int i = 0; i < 5; i++)       if (!vis[i]) return i;     throw  orzxzz ;   }   int query_7(int x) {     memset(vis, 0, sizeof(vis));     int cnt = 0;     for (int i = 1; i <= 4 && cnt <= 5; i++)       for (int j = 1; j <= 4 && cnt <= 5; j++) {         int val = (7 - (4 * n + 4 - i - (n - j + 1)) % 7) % 7;         if (vis[val]) continue;         vector<int> vec = {x};         for (int k = 1; k <= 4; k++)           if (i != k) vec.push_back(pos[k]);         for (int k = 1; k <= 4; k++)           if (j != k) vec.push_back(pos[n - k + 1]);         if (query(vec)) return val;         vis[val] = 1;         ++cnt;       }     for (int i = 0; i < 7; i++)       if (!vis[i]) return i;     throw  orzxzz ;   }   int query_8(int x) {     int ret = odd[x];     for (int i = 1; i <= 4; i++) {       int val = (4 - (10 - i) % 4) % 4;       if (val != ret) continue;       vector<int> vec = {x};       for (int j = 1; j <= 4; j++)         if (i != j) vec.push_back(pos[j]);       if (!query(vec)) ret += 2;       break;     }     for (int i = 1; i <= 4; i++) {       int val = (8 - (4 * n + 4 - i) % 8) % 8;       if (val != ret && val != ret + 4) continue;       vector<int> vec = {x};       for (int j = 1; j <= 4; j++)         if (i != j) vec.push_back(pos[j]);       for (int j = 1; j <= 4; j++) vec.push_back(pos[n - j + 1]);       if (query(vec) ^ (val == ret)) ret += 4;       break;     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       vector<int> vec;       for (int j = 1; j <= n; j++)         if (i != j) vec.push_back(j);       if (query(vec)) {         if (!pos[1])           pos[1] = i, ans[i] = 1;         else           pos[n] = i, ans[i] = n;       }     }     for (int i = 1; i <= n; i++)       if (!ans[i]) {         if (query({pos[1], i})) odd[i] = 1;       }     for (int t = 2; 2 * t <= n && t <= 4; t++) {       for (int i = 1; i <= n; i++)         if (!ans[i]) {           vector<int> vec;           for (int j = 1; j <= n; j++)             if (!ans[j] && j != i) vec.push_back(j);           if (query(vec)) {             if (!pos[t])               pos[t] = i;             else               pos[n - t + 1] = i;           }         }       if (odd[pos[t]] != (t & 1)) swap(pos[t], pos[n - t + 1]);       ans[pos[t]] = t;       ans[pos[n - t + 1]] = n - t + 1;     }     for (int i = 1; i <= n; i++)       if (!ans[i]) {         int a = query_3(i), b = query_5(i), c = query_7(i), d = query_8(i);         for (int j = 1; j <= n; j++)           if (j % 3 == a && j % 5 == b && j % 7 == c && j % 8 == d) {             ans[i] = j;             break;           }       }     if (ans[1] > n / 2) {       for (int i = 1; i <= n; i++) ans[i] = n + 1 - ans[i];     }     cout <<  ! ;     for (int i = 1; i <= n; i++) cout <<     << ans[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> v(n);     vector<int> c(m + 5, 0);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int l = 0, r = 0;     int res = 1;     c[v[0] - 1]++;     int maxC = 1;     int maxI = v[0] - 1;     while (r < n) {       if (c[v[r] - 1] > maxC) {         maxC = c[v[r] - 1];         maxI = v[r] - 1;       }       if (c[v[l] - 1] > maxC) {         maxC = c[v[l] - 1];         maxI = v[l] - 1;       }       if (r - l + 1 - maxC > k) {         if (v[l] - 1 == maxI) {           maxC--;         }         c[v[l] - 1]--;         l++;       } else if (r == n - 1) {         break;       } else {         r++;         c[v[r] - 1]++;         if (c[v[r] - 1] > maxC) {           maxC = c[v[r] - 1];           maxI = v[r] - 1;         }         if (r - l + 1 - maxC <= k) {           res = max(res, maxC);         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 0, BAR = 1e6, LIM = 5e6;   int x, y, n;   int main() {     scanf( %d , &n);     int xa = inf, xb = -inf, ya = inf, yb = -inf;     while (n--) {       scanf( %d%d , &x, &y);       x += BAR, y += BAR;       xa = min(xa, x - y - 1), xb = max(xb, x + y + 1);       ya = min(ya, x - (LIM - y + 1)), yb = max(yb, x + (LIM - y + 1));     }     int ans = 0;     int rya = (LIM - (yb - ya) / 2);     ans += (yb - ya) % 2;     int ryb = (xb - xa) / 2;     ans += (xb - xa) % 2;     ans += 2 * (ryb - rya);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7f7f7f7f;   int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};   vector<int> arr;   int main() {     int n;     string st;     int x;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       arr.push_back(x);     }     cin >> st;     int beg = 0;     int flag = 0;     for (int i = 0; i < st.size(); i++) {       if (st[i] ==  1  && flag == 0) {         beg = i;         flag = 1;       } else if (st[i] ==  0 ) {         if (flag) {           sort(arr.begin() + beg, arr.begin() + i + 1);           flag = 0;           beg = -1;         }       }     }     if (flag == 1) sort(arr.begin() + beg, arr.end());     bool f = 0;     for (int i = 0; i < n; i++) {       if (arr[i] != i + 1) {         f = 1;         break;       }     }     if (f == 1)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, x, t;     char card, ha;     map<int, pair<int, int> > mh;     map<int, pair<int, int> > ma;     map<int, pair<int, int> >::iterator it;     string h, a;     cin >> h >> a;     cin >> n;     for (i = 0; i < n; i++) {       cin >> t >> ha;       getchar();       cin >> x >> card;       getchar();       if (ha ==  a ) {         for (it = ma.begin(); it != ma.end(); it++) {           if ((it->second).first == x) break;         }         if (it == ma.end() && card ==  y )           ma[t] = make_pair(x, 1);         else if (it == ma.end() && card ==  r )           ma[t] = make_pair(x, 2);         else if (it != ma.end() && (it->second).second == 1) {           ma[t] = make_pair(x, 2);           ma.erase(it);         }       }       if (ha ==  h ) {         for (it = mh.begin(); it != mh.end(); it++) {           if ((it->second).first == x) break;         }         if (it == mh.end() && card ==  y )           mh[t] = make_pair(x, 1);         else if (it == mh.end() && card ==  r )           mh[t] = make_pair(x, 2);         else if (it != ma.end() && (it->second).second == 1) {           mh[t] = make_pair(x, 2);           mh.erase(it);         }       }     }     for (i = 0; i <= 90; i++) {       if (ma[i].second == 2) cout << a <<     << ma[i].first <<     << i << endl;       if (mh[i].second == 2) cout << h <<     << mh[i].first <<     << i << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 101000;   struct p {     long long x, y;   } a[N];   long long n, m;   long long pro(p o, p b, p c) {     return (b.x - o.x) * (c.y - o.y) - (c.x - o.x) * (b.y - o.y);   }   int main() {     scanf( %I64d , &n);     for (long long i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i].x, &a[i].y);     scanf( %I64d , &m);     for (long long i = 1; i <= m; i++) {       p b;       scanf( %I64d%I64d , &b.x, &b.y);       if (pro(a[1], a[2], b) >= 0 || pro(a[1], a[n], b) <= 0) {         puts( NO );         return 0;       }       long long l = 2, r = n;       while (l < r) {         long long mid = (l + r) / 2;         if (pro(a[1], a[mid], b) >= 0)           r = mid;         else           l = mid + 1;       }       if (pro(a[l], a[l - 1], b) <= 0) {         puts( NO );         return 0;       }     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     char s[60];     cin >> n >> s;     for (i = 0, j = 0; i < n; i += ++j) cout << s[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma optimize( -O3 )   string to_string(string s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(const bool& b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(const A& v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) res +=  ,  ;       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T>   inline void _read(T& x) {     cin >> x;   }   template <typename A, typename B>   inline void _read(pair<A, B>& x) {     _read(x.first);     _read(x.second);   }   template <typename T>   inline void _read(vector<T>& x) {     for (auto& v : x) _read(v);   }   void R() {}   template <typename T, typename... U>   void R(T& head, U&... tail) {     _read(head);     R(tail...);   }   template <typename T>   inline void _write(const T& x) {     cout << x <<    ;   }   template <typename A, typename B>   inline void _write(const pair<A, B>& x) {     _write(x.first);     _write(x.second);   }   template <typename T>   inline void _write(const vector<T>& in) {     for (const auto& x : in) _write(x);   }   void W() { cout <<   n ; }   template <typename T, typename... U>   void W(const T& head, const U&... tail) {     _write(head);     W(tail...);   }   void go();   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     go();     return 0;   }   const int M = 1 << 4;   const int N = 1 << 17;   const int K = 4;   const int mod = 1e9 + 7;   int dp[N][M][1 << K];   void go() {     int n, k, m;     R(n, k, m);     dp[0][0][0] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j <= k; j++)         for (int s = 0; s < (1 << m); s++) {           int t = (s << 1) % (1 << m);           (dp[i + 1][j][t] += dp[i][j][s]) %= mod;           if (j < k) {             int w = __builtin_popcount(s) + 1;             (dp[i + 1][j + 1][t | 1] += 1LL * w * dp[i][j][s] % mod) %= mod;           }         }     long long ans = 0;     for (int s = 0; s < (1 << m); s++) (ans += dp[n][k][s]) %= mod;     W(ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005, INF = 9999999;   const long long P = 1e9 + 7;   template <typename T>   inline void read(T& first, char s = getchar()) {     first = 0;     while (s >  9  || s <  0 ) s = getchar();     while (s <=  9  && s >=  0 ) first = first * 10 + s -  0 , s = getchar();   }   int k, a, b;   int main() {     read(k), read(a), read(b);     if (a < k && b < k) {       cout << -1 << endl;       return 0;     }     if (a < k || b < k) {       if (a < b) swap(a, b);       if (a % k != 0) {         cout << -1 << endl;         return 0;       } else {         cout << (a / k) << endl;         return 0;       }     }     int ans = a / k + b / k;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> t >> s;     set<char> b(t.begin(), t.end());     int n;     cin >> n;     for (int k = 0; k < n; ++k) {       cin >> t;       int i = 0;       int j = 0;       while (i < s.size() || j < t.size()) {         if (s[i] ==  ? ) {           if (b.find(t[j]) != b.end()) {             ++i;             ++j;           } else {             break;           }         } else if (s[i] ==  * ) {           int x = t.size() - s.size() + 1;           if (x < 0) {             break;           } else if (all_of(t.begin() + i, t.begin() + i + x,                             [&](char c) { return b.find(c) == b.end(); })) {             ++i;             j += x;           } else {             break;           }         } else {           if (s[i] == t[j]) {             ++i;             ++j;           } else {             break;           }         }       }       if (i == s.size() && j == t.size())         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 998244353, N = 2e5 + 5, M = 59, S = 32771;   inline int poww(int x, int y) {     int ans = 1;     for (; y; y >>= 1, x = 1ll * x * x % mo)       if (y & 1) ans = 1ll * ans * x % mo;     return ans;   }   int n, m, i, j, k, mi[N], C[M][M], ct[M];   long long a[M], x, val[2][S];   vector<long long> ve;   bool bb[M];   inline void solve1(vector<long long> ve) {     int p1 = 0, p2 = min(15, (int)ve.size()), p3 = ve.size();     for (i = 0; i < 1 << p2 - p1; ++i)       for (j = 0; j < p2 - p1; ++j)         if (i >> j & 1) val[0][i] ^= ve[j];     for (i = 0; i < 1 << p3 - p2; ++i)       for (j = 0; j < p3 - p2; ++j)         if (i >> j & 1) val[1][i] ^= ve[j + p2];     int s1 = (1 << p2) - 1, s2 = ((1 << p3) - 1) ^ s1;     for (i = 0; i < 1 << p3; ++i)       ++ct[__builtin_popcountll(val[0][i & s1] ^ val[1][(i & s2) >> p2])];   }   int id[M], xb;   inline void solve2() {     for (i = 0; i < m; ++i)       if (!bb[i]) id[xb++] = i;     vector<long long> v2;     for (i = 0; i < xb; ++i) {       long long x = 1 << i;       for (j = 0; j < ve.size(); ++j)         if (ve[j] >> id[i] & 1) x |= 1ll << j + xb;       v2.push_back(x);     }     solve1(v2);     static int cc[M], dd[M];     for (i = 0; i <= m; ++i) dd[i] = ((long long)ct[i] << ve.size()) % mo;     for (i = 0; i <= m; ++i)       for (j = 0; j <= m; ++j)         for (k = 0; k <= i; ++k)           if (k <= j && i - k <= m - j)             cc[i] = (cc[i] + 1ll * C[j][k] * C[m - j][i - k] % mo *                                  (k & 1 ? mo - dd[j] : dd[j])) %                     mo;     for (i = 0; i <= m; ++i)       cc[i] = 1ll * cc[i] * poww((1ll << m) % mo, mo - 2) % mo;     memcpy(ct, cc, sizeof cc);   }   int main() {     for (i = ** C = 1; i < M; ++i)       for (j = *C[i] = 1; j <= i; ++j)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mo;     for (i = *mi = 1; i < N; ++i) mi[i] = 2 * mi[i - 1] % mo;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; ++i) {       scanf( %lld , &x);       for (j = m - 1; j >= 0; --j)         if (x >> j & 1) {           if (!a[j]) {             a[j] = x;             break;           }           x ^= a[j];         }     }     for (i = 0; i < m; ++i)       if (a[i])         for (j = i + 1; j < m; ++j)           if (a[j] >> i & 1) a[j] ^= a[i];     for (i = 0; i < m; ++i)       if (a[i]) ve.push_back(a[i]), bb[i] = 1;     if (ve.size() <= 26)       solve1(ve);     else       solve2();     for (i = 0; i <= m; ++i) ct[i] = 1ll * ct[i] * mi[n - ve.size()] % mo;     for (i = 0; i <= m; ++i) printf( %d%c , ct[i], i == m ?   n  :    );   }


#include <bits/stdc++.h>   using namespace std;   const int Inf = (int)1e9 + 7;   const long long LongInf = (long long)1e18 + 7;   namespace {   const int N = 1007;   const int MOD = (int)1e9 + 7;   int k, pa, pb;   long long dp[N][N];   long long pw(long long x, int m) {     if (m == 0) return 1;     long long y = pw(x, m / 2);     y = (y * y) % MOD;     if (m % 2) y = (y * x) % MOD;     return y;   }   long long inv(int x) { return pw(x, MOD - 2); }   void solve() {     cin >> k >> pa >> pb;     long long s = inv(pa + pb);     pa = (pa * s) % MOD;     pb = (pb * s) % MOD;     long long res = 0;     dp[1][0] = 1;     long long rem = (pa * inv(pb)) % MOD;     for (int i = 1; i <= k; i++) {       for (int j = 0; j <= k; j++) {         if (i + j >= k) {           res += (dp[i][j] * (i + j + rem)) % MOD;           res %= MOD;         } else {           (dp[i + 1][j] += (dp[i][j] * pa) % MOD) %= MOD;           (dp[i][i + j] += (dp[i][j] * pb) % MOD) %= MOD;         }       }     }     cout << res <<   n ;   }   }  // namespace   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(9);     cout << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     char str[n];     scanf( %s , &str);     int count = 0;     for (int i = 0; i < n; i++)       if (str[i] == str[i + 1]) count++;     printf( %d , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e4 + 10;   int n, b, q;   pair<int, int> h[MaxN];   unordered_map<int, int> e[MaxN];   vector<int> c[MaxN];   int flow, parent[MaxN], mini, curr;   void dfs(int x) {     if (parent[q + 6] != -1) return;     for (int i = 0; i < c[x].size(); i++) {       if (e[x][c[x][i]] > 0 && parent[c[x][i]] == -1) {         parent[c[x][i]] = x;         dfs(c[x][i]);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> b >> q;     for (int i = 0; i < q; i++) cin >> h[i].first >> h[i].second;     for (int i = 1; i <= 5; i++) {       c[0].push_back(i);       c[i].push_back(0);       e[0][i] = n / 5;       e[i][0] = 0;     }     sort(h, h + q);     h[q].first = b;     h[q].second = n;     q++;     for (int i = q - 1; i >= 0; i--) {       e[i + 6][q + 6] = h[i].second;       e[q + 6][i + 6] = 0;       c[i + 6].push_back(q + 6);       c[q + 6].push_back(i + 6);       if (i < q - 1) {         e[i + 7][q + 6] -= h[i].second;         if (e[i + 7][q + 6] < 0) {           cout <<  unfair ;           return 0;         }       }       for (int j = 0; j < 5; j++) {         e[j + 1][i + 6] = h[i].first / 5;         if (j > 0 && h[i].first % 5 >= j) e[j + 1][i + 6]++;         e[i + 6][j + 1] = 0;         c[j + 1].push_back(i + 6);         c[i + 6].push_back(j + 1);         if (i < q - 1) e[j + 1][i + 7] -= e[j + 1][i + 6];       }     }     while (true) {       for (int i = 0; i < MaxN; i++) parent[i] = -1;       parent[0] = 0;       dfs(0);       if (parent[q + 6] == -1) break;       curr = q + 6;       mini = 1e6;       while (curr != 0) {         mini = min(mini, e[parent[curr]][curr]);         curr = parent[curr];       }       flow += mini;       curr = q + 6;       while (curr != 0) {         e[parent[curr]][curr] -= mini;         e[curr][parent[curr]] += mini;         curr = parent[curr];       }     }     if (flow == n)       cout <<  fair ;     else       cout <<  unfair ;     return 0;   }


#include <bits/stdc++.h>   int main() {     const int maxN = 3002;     bool tests[maxN] = {0};     int n(0);     scanf( %d , &n);     for (int k = 0; k < n; k++) {       int temp;       scanf( %d , &temp);       tests[temp] = 1;     }     for (int index = 1; index < maxN; index++) {       if (!tests[index]) {         printf( %d n , index);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     cin >> n;     bool isLR = false;     char a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] ==  L  || a[i] ==  R ) isLR = true;     }     bool flag = false;     int count = 0;     for (int i = 0; i < n; i++) {       if (a[i] ==  .  && flag == true)         count++;       else if (a[i] ==  L )         flag = true;       else if (a[i] ==  R ) {         sum += count;         count = 0;         flag = false;       }     }     flag = false;     count = 0;     for (int i = 0; i < n; i++) {       if (a[i] ==  .  && flag == true)         count++;       else if (a[i] ==  R )         flag = true;       else if (a[i] ==  L ) {         if (count % 2 != 0) sum++;         count = 0;         flag = false;       }     }     count = 0;     for (int i = 0; i < n; i++) {       if (a[i] ==  . )         count++;       else if (a[i] ==  L )         break;       else if (a[i] ==  R ) {         sum += count;         break;       }     }     count = 0;     for (int i = n - 1; i >= 0; i--) {       if (a[i] ==  . )         count++;       else if (a[i] ==  R )         break;       else if (a[i] ==  L ) {         sum += count;         break;       }     }     if (isLR == true)       cout << sum;     else       cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 5, inf = 1e16;   long long a[N], p[N], b[N], seg[N << 2], m;   void shift(long long id) {     if (seg[id] == 0) return;     seg[id << 1] += seg[id], seg[id << 1 | 1] += seg[id];     seg[id] = 0;   }   void add(long long l, long long r, long long val, long long L = 0,            long long R = m + 1, long long id = 1) {     if (r <= L || R <= l) return;     if (l <= L && R <= r) {       seg[id] += val;       return;     }     shift(id);     long long mid = (L + R) >> 1;     add(l, r, val, L, mid, id << 1);     add(l, r, val, mid, R, id << 1 | 1);     return;   }   long long get(long long l, long long L = 0, long long R = m + 1,                 long long id = 1) {     if (R - L == 1) return seg[id];     shift(id);     long long mid = (L + R) >> 1;     if (l < mid)       return get(l, L, mid, id << 1);     else       return get(l, mid, R, id << 1 | 1);   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) cin >> p[i];     cin >> m;     for (long long i = 1; i <= m; i++) cin >> b[i];     add(1, m + 1, inf);     for (long long i = 0; i < n; i++) {       long long x = lower_bound(b, b + m + 1, a[i]) - b, val = inf * 10;       if (a[i] == b[x]) val = get(x - 1);       if (p[i] < 0)         add(0, m + 1, p[i]);       else         add(0, x, p[i]);       if (val < get(x)) add(x, x + 1, val - get(x));     }     if (get(m) > 1e15) return cout <<  NO n , 0;     cout <<  YES n  << get(m) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point(int x = 0, int y = 0) : x(x), y(y) {}   };   point p[305];   int n;   point operator-(point a, point b) { return point(a.x - b.x, a.y - b.y); }   int cp(point a, point b) { return a.x * b.y - a.y * b.x; }   double work() {     int i, j, k, f1, f2;     double s1, s2, ans = 0;     for (i = 1; i <= n; ++i)       for (j = i + 1; j <= n; ++j) {         s1 = s2 = 0;         f1 = f2 = 0;         for (k = 1; k <= n; ++k)           if (k != i && k != j) {             if (cp(p[i] - p[j], p[k] - p[j]) < 0) {               s1 = max(s1, -(double)cp(p[i] - p[j], p[k] - p[j]) / 2);               f1 = 1;             } else {               s2 = max(s2, (double)cp(p[i] - p[j], p[k] - p[j]) / 2);               f2 = 1;             }           }         if (f1 && f2) ans = max(ans, s1 + s2);       }     return ans;   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d%d , &p[i].x, &p[i].y);     printf( %.10lf n , work());     return 0;   }


#include <bits/stdc++.h>   #define debug(x) cout << #x <<   =   << x << endl   #define REP(i, n) for (Long i = 0; i < (Long)n; i++)   using namespace std;      typedef long long Long;      const int MX = 3e5;   vector<Long> adj[MX];   set<pair<Long,Long>> queries[MX];   Long saved[MX];   Long single[MX];   Long cnt[2 * MX + 8];   Long ans = 0;      void merge(Long u, Long v, Long gU, Long gV, Long lowLimit, Long &curGroup, map<pair<Long, Long>, Long> &crossedCnt) {    //u to v    if (queries[saved[u]].size() > queries[saved[v]].size()) {     swap(u, v);     swap(gU, gV);    }     for (auto p : queries[saved[u]]) {     Long x = p.first;     auto it = queries[saved[v]].lower_bound({x, -1});     if (it != queries[saved[v]].end() && it->first == x) {      pair<Long, Long> pairIndex = {p.second, it->second};      queries[saved[v]].erase(it);      if (pairIndex.first < lowLimit) {       pairIndex.first = gU;      }      if (pairIndex.second < lowLimit) {       pairIndex.second = gV;      }           Long a = min(pairIndex.first, pairIndex.second);      Long b = max(pairIndex.first, pairIndex.second);      if (a != lowLimit) {       crossedCnt[{a, b}]++;       cnt[a]--;       cnt[b]--;      } else {       cnt[b]--;      }           } else {      Long gInsert = p.second;      if (gInsert < lowLimit) {       gInsert = gU;      }      queries[saved[v]].insert({x, gInsert});     }    }    curGroup = gV;    saved[u] = saved[v];   }      Long groups = 1;   void dfs(Long u, Long p = -1) {    Long sz = queries[u].size();    Long T = 2 * single[u] + sz;    Long cur = 0;        map<pair<Long, Long>, Long> crossedCnt;        for (Long v : adj[u]) {     if (v != p) {      dfs(v, u);     }    }    Long lowLimit = groups;    groups++;    Long curGroup = lowLimit;;    for (Long v : adj[u]) {     if (v != p) {      sz = queries[saved[v]].size();      T += sz;      cur -= sz * (sz - 1) / 2;      Long g = groups++;      cnt[g] += sz;      Long gU = curGroup;      merge(u, v, gU, g, lowLimit, curGroup, crossedCnt);     }    }    sz = queries[saved[u]].size();    T += sz;    cur -= sz * (sz - 1) / 2;    assert(T % 2 == 0);    T /= 2;        cur += T * (T - 1) / 2;    for (auto crossed : crossedCnt) {     sz = crossed.second;     cur += sz * (sz - 1) / 2;    }    for (Long i = lowLimit + 1; i < groups; i++) {     cur += cnt[i] * (cnt[i] - 1) / 2;    }    ans += cur;   }      int main() {    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    Long n;    cin >> n;    REP(i , n - 1) {     Long u, v;     cin >> u >> v;     u--;     v--;     adj[u].push_back(v);     adj[v].push_back(u);    }    REP(i , n) {     saved[i] = i;    }    Long m;    cin >> m;        REP(i, m) {     Long u , v;     cin >> u >> v;     u--;     v--;     if (u != v) {      queries[u].insert({i, 0});      queries[v].insert({i, 0});     } else {      single[u]++;     }       }    dfs(0);    assert(groups <= 2 * n);    cout << ans <<   n ;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MOD = 1e9 + 7;   long long int power(long long int a, long long int b) {     long long int res = 1;     a = a % MOD;     while (b > 0) {       if (b & 1) {         res = (res * a) % MOD;         b--;       }       a = (a * a) % MOD;       b >>= 1;     }     return res;   }   long long int fermat_inv(long long int y) { return power(y, MOD - 2); }   long long int gcd(long long int a, long long int b) {     return (b == 0) ? a : gcd(b, a % b);   }   long long int min(long long int a, long long int b) { return (a > b) ? b : a; }   long long int max(long long int a, long long int b) { return (a > b) ? a : b; }   bool prime[1000001];   vector<int> primes;   void SieveOfEratosthenes(int n) {     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (int p = 2; p < 1000001; p++)       if (prime[p]) primes.push_back(p);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       long long int n, a, b;       string s;       cin >> n >> a >> b >> s;       long long int cost = n * a + (n + 1) * b;       vector<int> v;       long long int j = 1;       for (int i = 1; i < n; i++) {         if (s[i] == s[i - 1])           j++;         else {           v.push_back(j);           j = 1;         }       }       if (v.empty()) {         cout << cost <<   n ;         continue;       }       v.erase(v.begin());       cost += 2 * a;       for (int i = 0; i < v.size(); i++) {         if (i % 2 == 0)           cost += (long long int)(v[i] + 1) * b;         else {           if (2 * a <= (long long int)(v[i] - 1) * b)             cost += 2 * a;           else             cost += (long long int)(v[i] - 1) * b;         }       }       cout << cost <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   char str;   int n, m, g;   int num[20480];   struct edge {     int to;     int nxt;     int val;   } nd[8 * 20480];   int head[20480], cnt;   int cur[20480], dep[20480];   queue<int> q;   int ans;   template <class X>   inline void read(X &x) {     x = 0;     X f = 1;     while (!isdigit(str)) {       if (str ==  - ) {         f = -1;       }       str = getchar();     }     while (isdigit(str)) {       x *= 10;       x += str -  0 ;       str = getchar();     }     x *= f;     return;   }   void init() {     memset(head, -1, sizeof(head));     cnt = 0;     return;   }   void add(int x, int y, int z) {     nd[cnt].to = y;     nd[cnt].nxt = head[x];     nd[cnt].val = z;     head[x] = cnt++;     return;   }   bool bfs(int s, int t) {     memset(dep, 0x3f, sizeof(dep));     memcpy(cur, head, sizeof(cur));     while (q.size()) {       q.pop();     }     q.push(s);     dep[s] = 0;     while (q.size()) {       int x = q.front();       q.pop();       for (int i = head[x]; i != -1; i = nd[i].nxt) {         int tt = nd[i].to;         if (dep[tt] == 0x3f3f3f3f && nd[i].val) {           dep[tt] = dep[x] + 1;           q.push(tt);         }       }     }     return dep[t] != 0x3f3f3f3f;   }   int dfs(int x, int t, int lim) {     if (x == t || !lim) {       return lim;     }     int ff = 0, f;     for (int i = cur[x]; i != -1; i = nd[i].nxt) {       cur[x] = i;       int tt = nd[i].to;       if (dep[tt] == dep[x] + 1 && (f = dfs(tt, t, min(lim, nd[i].val)))) {         ff += f;         lim -= f;         nd[i].val -= f;         nd[i ^ 1].val += f;         if (!lim) {           break;         }       }     }     return ff;   }   void dinic(int s, int t) {     while (bfs(s, t)) {       ans -= dfs(s, t, 0x3f3f3f3f);     }     return;   }   int main() {     init();     read(n), read(m), read(g);     for (int i = 1; i <= n; i++) {       read(num[i]);     }     for (int i = 1; i <= n; i++) {       int x;       read(x);       if (num[i]) {         add(i, n + m + 1, x);         add(n + m + 1, i, 0);       } else {         add(0, i, x);         add(i, 0, 0);       }     }     for (int i = 1; i <= m; i++) {       int opt, x, k;       read(opt), read(x), read(k);       ans += x;       for (int j = 1; j <= k; j++) {         int y;         read(y);         if (opt == 0) {           add(n + i, y, 0x3f3f3f3f);           add(y, n + i, 0);         } else {           add(y, n + i, 0x3f3f3f3f);           add(n + i, y, 0);         }       }       int z;       read(z);       if (opt == 0) {         add(0, n + i, z * g + x);         add(n + i, 0, 0);       } else {         add(n + i, n + m + 1, z * g + x);         add(n + m + 1, n + i, 0);       }     }     dinic(0, n + m + 1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, min_m, max_n, min_n, x;     scanf( %d%d , &n, &m);     scanf( %d , &max_n);     min_n = max_n;     n--;     while (n--) {       scanf( %d , &x);       if (x > max_n) {         max_n = x;       } else if (x < min_n) {         min_n = x;       }     }     scanf( %d , &min_m);     m--;     while (m--) {       scanf( %d , &x);       if (x < min_m) {         min_m = x;       }     }     if (min_m <= max_n) {       printf( -1 );       return 0;     }     int t = max_n;     while (t < min_m) {       if (2 * min_n <= t) {         printf( %d , t);         return 0;       }       t++;     }     printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 25, INF = 1e9 + 5;   inline int read() {     char c = getchar();     int x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int n, m, a[N][N];   bool check() {     for (int i = 1; i <= n; i++) {       int cnt = 0;       for (int j = 1; j <= m; j++)         if (a[i][j] != j) cnt++;       if (cnt > 2) return false;     }     return true;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) a[i][j] = read();     if (check()) {       puts( YES );       return 0;     }     for (int i = 1; i <= m; i++)       for (int j = i + 1; j <= m; j++) {         for (int z = 1; z <= n; z++) swap(a[z][i], a[z][j]);         if (check()) {           puts( YES );           return 0;         }         for (int z = 1; z <= n; z++) swap(a[z][i], a[z][j]);       }     puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, x;     cin >> n;     int s1 = 0, s2 = 0;     for (int i = 0; i < n; i++) {       cin >> x;       s1 += x;     }     for (int i = 0; i < n; i++) {       cin >> x;       s2 += x;     }     cout << (s2 <= s1 ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) s = s * 10 + ch -  0 , ch = getchar();     return s;   }   const int N = 1e5 + 5;   int n, m, k, p;   long long h[N], a[N], c[N];   inline bool check(long long x) {     memset(c, 0, sizeof(c));     priority_queue<pair<long long, int>, vector<pair<long long, int>>,                    greater<pair<long long, int>>>         q;     for (int i = 1; i <= n; i++)       if (x - a[i] * m < h[i]) q.push({x / a[i], i});     for (int i = 1; i <= m && !q.empty(); i++)       for (int j = 1; j <= k && !q.empty(); j++) {         auto u = q.top();         q.pop();         if (u.first < i) return 0;         c[u.second]++;         if (x + c[u.second] * p - a[u.second] * m < h[u.second])           q.push({(x + c[u.second] * p) / a[u.second], u.second});       }     return q.empty();   }   int main() {     n = read(), m = read(), k = read(), p = read();     for (int i = 1; i <= n; i++) h[i] = read(), a[i] = read();     long long l = 0, r = 1e16, ans = 0;     for (int i = 1; i <= 60; i++) {       long long mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<char, int> mp;     string s;     int i, j, n, off;     cin >> n >> s;     for (i = 0; i < s.size(); i++) {       mp[s[i]] = 1;     }     int max = mp.size();     if (n > max) {       cout <<  NO ;     } else {       int c = 0;       cout <<  YES  << endl;       for (i = 0; i < s.size(); i++) {         if (mp[s[i]] == 1 && c < n - 1) {           mp[s[i]] = 0;           c++;           j = i;           while (mp[s[j++]] == 0) {             cout << s[i];             i = j;           }           i--;           cout << endl;         } else {           cout << s[i];         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e5 + 5;   const int MAX = 0x7fffffff;   const int MIN = 0x80000000;   int n, k;   struct node {     int num, index;     bool friend operator<(node a, node b) { return a.num > b.num; }   };   node a[N];   char ch[N];   int pos[N] = {0};   int dp[N] = {0};   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i].num);       a[i].index = i;     }     scanf( %s , ch);     long long sum = 0;     sort(a, a + n);     pos[0] = 0;     for (int i = 1; i < n; i++) {       if (ch[i] == ch[i - 1])         pos[i] = pos[i - 1];       else         pos[i] = i;     }     for (int i = 0; i < n; i++) {       if (dp[pos[a[i].index]] < k) {         sum += a[i].num;         dp[pos[a[i].index]]++;       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a[30005];   int main() {     int n, m, p, q, i, j;     vector<int> v;     cin >> n >> m;     for (i = 0; i < m; i++) {       scanf( %d%d , &p, &q);       a[p].push_back(q);     }     for (i = 1; i < n; i++) sort(a[i].begin(), a[i].end());     for (i = 1; i <= n; i++) {       v.push_back(i);       j = i - 2;       while (j >= 0) {         if (binary_search(a[v[j]].begin(), a[v[j]].end(), i)) {           swap(v[j], v[j + 1]);           j--;         } else           break;       }     }     for (i = 0; i < n - 1; i++)       if (binary_search(a[v[i]].begin(), a[v[i]].end(), v[i + 1])) {         cout << -1 << endl;         return 0;       }     for (i = 0; i < n; i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long xx = 0, yy = 0;     for (int i = 0; i < 2 * n; i++) {       int x, y;       cin >> x >> y;       xx += x;       yy += y;     }     cout << xx / n <<     << yy / n;     return 0;   }


#pragma GCC optimize( O3 )   #include <bits/stdc++.h>   using namespace std;      //#include <ext/pb_ds/assoc_container.hpp>   //#include <ext/pb_ds/tree_policy.hpp>   //using namespace __gnu_pbds;      //template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;   //template<class T> using omultiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;      //find_by_order   //order_of_key      #define x first   #define y second   #define pb push_back   #define all(a) a.begin(),a.end()      typedef long long ll;   typedef long double ld;   typedef unsigned long long ull;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   typedef vector<ll> vl;   typedef vector<int> vi;   typedef vector<bool> vb;   typedef vector<vi> vvi;   typedef vector<vl> vvl;   typedef vector<pii> vii;   typedef vector<pll> vll;      mt19937 rnd(time(nullptr));      const int N = 2e5+5;      int t[4*N], p[4*N];   string s, f;      void push(int v, int tl, int tr) {       if (tl == tr || p[v] == -1)           return;       int tm = tl+tr >> 1;       int vv = v << 1;       t[vv] = p[v]*(tm-tl+1);       t[vv+1] = p[v]*(tr-tm);       p[vv] = p[v];       p[vv+1] = p[v];       p[v] = -1;   }      void build(int v, int tl, int tr) {       if (tl == tr) {           t[v] = f[tl]- 0 ;           p[v] = -1;           return;       }       int tm = tl+tr >> 1;       int vv = v << 1;       push(v, tl, tr);       build(vv, tl, tm);       build(vv+1, tm+1, tr);       t[v] = t[vv]+t[vv+1];   }      void upd(int v, int tl, int tr, int l, int r, int val) {       if (tl > r || l > tr)           return;       if (l <= tl && tr <= r) {           t[v] = (tr-tl+1)*val;           p[v] = val;           return;       }       int tm = tl+tr >> 1;       int vv = v << 1;       push(v, tl, tr);       upd(vv, tl, tm, l, r, val);       upd(vv+1, tm+1, tr, l, r, val);       t[v] = t[vv]+t[vv+1];   }      int get(int v, int tl, int tr, int l, int r) {       if (l > tr || tl > r)           return 0;       if (l <= tl && tr <= r)           return t[v];       int tm = tl+tr >> 1;       int vv = v << 1;       push(v, tl, tr);       return get(vv, tl, tm, l, r)+get(vv+1, tm+1, tr, l, r);   }            void solve() {       int n, q; cin >> n >> q;       cin >> s >> f;       s =  # +s, f =  # +f;       vii ask(q);       for (pii& cur : ask)           cin >> cur.x >> cur.y;       reverse(all(ask));       build(1, 1, n);       for (pii cur : ask) {           int sum = get(1, 1, n, cur.x, cur.y);           int len = cur.y-cur.x+1;           if (sum*2 == len) {               cout <<  NO n ;               return;           }           if (sum <= (len-1)/2) {               upd(1, 1, n, cur.x, cur.y, 0);           }           else {               upd(1, 1, n, cur.x, cur.y, 1);           }       }       for (int i=1; i<=n; ++i) {           if (get(1, 1, n, i, i)+ 0  != s[i]) {               cout <<  NO n ;               return;           }       }       cout <<  YES n ;   }            int main() {       ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);       int t; cin >> t;       while(t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int solve(int n, int k, vector<int> &arr, int mn) {     int MX = int(1e6);     if (k >= mn - 1) return mn;     int i, j;     for (i = mn; i >= k + 1; i--) {       int tot = 0;       for (j = 0; j <= MX; j += i) {         int mx = min(j + k, MX);         tot += (arr[mx] - (j > 0 ? arr[j - 1] : 0));       }       if (tot == n) return i;     }     return -33;   }   int main() {     int MX = (1e6) + 2;     vector<int> arr(MX - 1, 0);     int n;     scanf( %d , &n);     int k;     scanf( %d , &k);     int i, j;     int mn = MX;     for (i = 0; i < n; i++) {       int temp;       scanf( %d , &temp);       mn = min(mn, temp);       arr[temp]++;     }     for (i = 1; i < MX; i++) arr[i] += arr[i - 1];     printf( %d n , solve(n, k, arr, mn));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a, m, x, tk, i, tr, tl, r, l;     scanf( %d %d %d , &n, &k, &a);     scanf( %d , &m);     tk = (n + 1) / (a + 1);     set<int> ceils;     map<int, pair<int, int> > intv;     ceils.insert(n);     intv[n] = pair<int, int>(1, tk);     for (i = 1; i <= m; i++) {       scanf( %d  , &x);       auto it = ceils.lower_bound(x);       tk -= intv[*it].second;       r = intv[*it].first;       l = *it;       ceils.erase(it);       if (x > r) {         tr = ((x - r) + 1) / (a + 1);         ceils.insert(x - 1);         intv[x - 1] = pair<int, int>(r, tr);         tk += tr;       }       if (x < l) {         tl = ((l - x) + 1) / (a + 1);         ceils.insert(l);         intv[l] = pair<int, int>(x + 1, tl);         tk += tl;       }       if (tk < k) break;     }     if (i > m)       printf( -1 n );     else       printf( %d n , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   long long n, T, a[maxn], x, y, t1, t2, k;   long long b[maxn];   long long cmp(long long x, long long y) { return x > y; }   long long cmp1(long long x, long long y) { return x > y; }   long long check(long long len) {     for (long long i = 1; i <= len; i++) {       if (i % t1 == 0 && i % t2 == 0)         b[i] = x + y;       else if (i % t1 == 0)         b[i] = x;       else if (i % t2 == 0)         b[i] = y;     }     sort(b + 1, b + 1 + len, cmp1);     long long ans = 0;     for (long long i = 1; i <= len; i++) {       ans += b[i] * a[i];     }     if (ans >= k) return 1;     return 0;   }   int main() {     cin >> T;     while (T--) {       cin >> n;       for (long long i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + 1 + n, cmp);       cin >> x >> t1 >> y >> t2 >> k;       k *= 100;       long long l = 0, r = n, ans = 0x7f7f7f7f;       while (l <= r) {         long long mid = (l + r) / 2;         memset(b, 0, sizeof(b));         if (check(mid)) {           r = mid - 1;           ans = mid;         } else {           l = mid + 1;         }       }       if (ans == 0x7f7f7f7f)         cout <<  -1  << endl;       else         cout << ans << endl;     }   }