#include <bits/stdc++.h>   using namespace std;   int mat[1005][1005];   int main() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); i++) {       for (int j = (0); j < (n); j++) {         scanf( %d , &mat[i][j]);       }     }     int akt = 0;     for (int i = (0); i < (n); i++) akt = (akt + mat[i][i]) % 2;     int q;     scanf( %d , &q);     for (int i = (0); i < (q); i++) {       int nr;       scanf( %d , &nr);       if (nr == 1 || nr == 2) {         akt = 1 - akt;         int x;         scanf( %d , &x);       } else         printf( %d , akt);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.14159265358979323846;   void rw() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     vector<long long> s;     long long n, c, f, se;     cin >> n;     s.push_back(4);     s.push_back(7);     for (int i = 0; i < s.size(); i++) {       f = 0, se = 0;       c = s[i];       while (c) {         if (c % 10 == 4)           f++;         else           se++;         c /= 10;       }       if (s[i] >= n && f == se) {         cout << s[i] <<   n ;         break;       } else {         s.push_back(s[i] * 10 + 4);         s.push_back(s[i] * 10 + 7);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, k = 0;     long long x, y, z = 0;     long long hsl[1002];     cin >> a;     for (int i = 1; i <= a; i++) {       y = 0;       z = 0;       cin >> b >> k >> x;       if (x % 2 == 0) {         y = x / 2;         z = x / 2;       } else {         z = x / 2 + 1;         y = x / 2;       }       z = z * b;       y = y * k;       z = z - y;       hsl[i] = z;     }     for (int i = 1; i <= a; i++) {       cout << hsl[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   pair<long long int, long long int> a[500001];   int main() {     ios::sync_with_stdio(false);     cout << fixed << setprecision(10);     long long int i, j, n, f;     double lo, mid, hi, ans = -1, last;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     lo = 0;     hi = 1e10;     for (i = 0; i < 100; i++) {       mid = (lo + hi) / 2.0;       f = 0;       last = -1e100;       for (j = 1; j <= n; j++) {         if (a[j].second > 0)           last = max(last, 1.0 * (a[j].first + 1.0 * a[j].second * mid));         else {           if (1.0 * (a[j].first + 1.0 * a[j].second * mid) < last) {             f = 1;             break;           }         }       }       if (f) {         hi = mid;         ans = mid;       } else         lo = mid;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct st {     int t, l, r, p;     bool operator<(const st& B) const { return t < B.t; }   } a[100005];   int N, M, K, s[100005];   vector<st> u[100005], v[100005];   long long b[100005], ans[100005];   int sum(int x) {     int d = 0;     for (int i = x; i; i -= i & -i) d += s[i];     return d;   }   void ins(int x, int d) {     for (int i = x; i <= M; i += i & -i) s[i] += d;   }   int find(int k) {     int p = 0;     for (int i = 20; i >= 0; i--)       if (p + (1 << i) <= M && s[p + (1 << i)] < k) k -= s[p += 1 << i];     return p + 1;   }   void init() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++)       scanf( %d%d%d , &a[i].t, &a[i].l, &a[i].r), b[i] = a[i].t, a[i].p = i;     sort(a + 1, a + N + 1), sort(b + 1, b + N + 1),         K = unique(b + 1, b + N + 1) - b - 1;   }   void work(long long t, int p) {     for (auto i : u[p]) v[i.r].push_back(i), ins(i.r, 1);     for (auto i : v[p]) ans[i.p] = t;     ins(p, -u[p].size() - v[p].size());     u[p].clear(), v[p].clear();   }   void doit() {     b[++K] = 1e18;     long long t = 0;     for (int i = 1, j = 1, p = 1; i <= K; i++) {       for (; t < b[i];) {         int n = sum(M), d = sum(p), u = n - sum(p - 1), q;         if (!n) {           t = b[i];           continue;         }         if (u >= d) {           q = find(n - u + 1);           if (t + q - p <= b[i])             t += q - p, p = q, work(t, p);           else             p += b[i] - t, t = b[i];         } else {           q = find(d);           if (t + p - q <= b[i])             t += p - q, p = q, work(t, p);           else             p -= b[i] - t, t = b[i];         }       }       for (; j <= N && a[j].t == b[i]; j++)         ins(a[j].l, 1), u[a[j].l].push_back(a[j]);     }     for (int i = 1; i <= N; i++) printf( %I64d n , ans[i]);   }   int main() {     init();     doit();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, x, n, k, m = 0, f = 0, j = 1;     int a[26];     string s;     cin >> s;     n = s.length();     cin >> k;     k = k + n;     for (i = 0; i < 26; i++) {       cin >> a[i];       m = max(m, a[i]);     }     for (i = 0; i < n; i++) {       f = f + a[s[i] -  a ] * j;       j++;     }     f = f + ((k * (k + 1)) / 2 - (n * (n + 1)) / 2) * m;     cout << f << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long modInverse(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long nCmmod(long long n, long long m, long long mod) {     vector<long long> a(200001, 1);     for (__typeof(1) i = 1; i < 200001; i += 1) {       a[i] = (a[i - 1] * i) % mod;     }     long long p = 1;     p = (p * a[n]) % mod;     p = (p * modInverse(a[m], mod)) % mod;     p = (p * modInverse(a[n - m], mod)) % mod;     return p;   }   vector<long long> p(long long n) {     long long x = 0;     vector<long long> v;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i) {           v.push_back(i);         } else {           v.push_back(i);           v.push_back(n / i);         }       }     }     sort(v.begin(), v.end());     return v;   }   long long bsearch(vector<long long> arr, long long l, long long r, int x) {     if (r >= l) {       long long mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return bsearch(arr, l, mid - 1, x);       return bsearch(arr, mid + 1, r, x);     }     return l + (r - l) / 2;   }   string decToBinary(long long n) {     string s =   ;     long long f = 0;     for (int i = 31; i >= 0; i--) {       int k = n >> i;       if (k & 1)         s +=  1 ;       else         s +=  0 ;     }     return s;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int power(long long int x, long long int y) {     long long int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return (temp % 1000000007 * temp % 1000000007) % 1000000007;     else {       if (y > 0)         return (x % 1000000007 * temp % 1000000007 * temp % 1000000007) %                1000000007;       else         return (temp % 1000000007 * temp % 1000000007) % 1000000007 / x;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       string s;       cin >> s;       long long m = n / k;       long long cn = (k + 1) / 2;       long long r = 0;       for (__typeof(cn) i = 0; i < cn; i += 1) {         vector<long long> A(26, 0);         char c = s[i];         for (__typeof(m) j = 0; j < m; j += 1) {           A[s[j * k + i] -  a ] += 1;         }         for (__typeof(m) j = 0; j < m; j += 1) {           A[s[j * k + k - 1 - i] -  a ] += 1;         }         long long ma = -1;         for (__typeof(26) j = 0; j < 26; j += 1) {           if (A[j] > ma) {             ma = A[j];           }         }         if (k % 2 == 1 && i == cn - 1)           r += m - ma / 2;         else           r += 2 * m - ma;       }       cout << r << endl;     }   }


#include <bits/stdc++.h>   const double pi = 3.1415926535897932384626433832795;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   using namespace std;   void ifd() {}   void tme() {}   int main() {     ifd();     string s, t, tmp;     getline(cin, s);     vector<string> d;     vector<int> check;     vector<int> r;     stringstream p;     p.clear();     p << s;     while (p >> t) d.push_back(t);     bool f = true;     for (int i = (0); i < (d.size()); ++i) {       tmp = d[i];       while (tmp.size() < 6) tmp =  ?  + tmp;       tmp = tmp.substr(tmp.size() - 6, 6);       if (tmp[2] ==  l  && tmp[3] ==  i  && tmp[4] ==  o  && tmp[5] ==  s ) {         check.push_back(1);         r.push_back(0);       } else if (tmp[2] ==  e  && tmp[3] ==  t  && tmp[4] ==  r  &&                  tmp[5] ==  a ) {         check.push_back(2);         r.push_back(1);       } else if (tmp[3] ==  e  && tmp[4] ==  t  && tmp[5] ==  r ) {         check.push_back(2);         r.push_back(0);       } else if (tmp[1] ==  l  && tmp[2] ==  i  && tmp[3] ==  a  &&                  tmp[4] ==  l  && tmp[5] ==  a ) {         check.push_back(1);         r.push_back(1);       } else if (tmp ==  initis ) {         check.push_back(3);         r.push_back(0);       } else if (tmp ==  inites ) {         check.push_back(3);         r.push_back(1);       } else {         cout <<  NO  << endl;         return 0;       }     }     int te = r[0];     for (int i = (0); i < (r.size()); ++i)       if (r[i] != te) f = false;     if (!f) {       cout <<  NO  << endl;       return 0;     }     if (check.size() == 1) {       cout <<  YES  << endl;       return 0;     }     int n1 = 0, n2 = 0, n3 = 0;     for (int i = (0); i < (check.size()); ++i) {       if (check[i] == 1) n1++;       if (check[i] == 2) n2++;       if (check[i] == 3) n3++;       if (i > 0 && check[i] < check[i - 1]) {         cout <<  NO  << endl;         return 0;       }     }     if (n1 >= 0 && n2 == 1 && n3 >= 0)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     tme();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   int n, m, tin[N], up[N], dw[N];   bool ans[N];   vector<int> edge[N], redge[N];   void topo() {     queue<int> q;     for (int i = 1; i <= n; i++)       if (!tin[i]) q.push(i);     while (q.size()) {       int at = q.front();       q.pop();       for (auto to : edge[at])         if (!--tin[to]) q.push(to);     }   }   void dfs2(int at, int rt, int rev) {     if (!rev) {       up[at] = rt;       for (auto to : edge[at])         if (!up[to]) dfs2(to, rt, rev);     } else {       dw[at] = rt;       for (auto to : redge[at])         if (!dw[to]) dfs2(to, rt, rev);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       edge[x].push_back(y);       redge[y].push_back(x);       tin[y]++;     }     topo();     int ok = 1;     for (int i = 1; i <= n; i++)       if (tin[i]) ok = 0;     if (!ok)       cout << -1 <<   n ;     else {       for (int i = 1; i <= n; i++) {         if (!up[i]) dfs2(i, i, 0);         if (!dw[i]) dfs2(i, i, 1);       }       int cnt = 0;       for (int i = 1; i <= n; i++)         if (up[i] == i and dw[i] == i) ans[i] = 1, cnt++;       cout << cnt <<   n ;       for (int i = 1; i <= n; i++) cout << (ans[i] ?  A  :  E );       cout <<   n ;     }   }


#include <bits/stdc++.h>   const long long inf = 1e18;   using namespace std;   int n;   long long x[100005];   long long lb, ub, mid;   long long sum, S;   long long cnt[3];   int main(void) {     cin >> n;     for (int i = 1; i <= n; i++) cin >> x[i];     lb = inf, ub = -inf;     for (int i = 1; i <= n; i++) {       lb = min(lb, x[i]);       ub = max(ub, x[i]);     }     if (ub - lb <= 1) {       cout << n << endl;       for (int i = 1; i <= n; i++) {         cout << x[i];         if (i != n) cout <<    ;       }       cout << endl;       return 0;     }     mid = lb + 1;     for (int i = 1; i <= n; i++) {       sum += x[i];       if (x[i] == lb) cnt[0]++;       if (x[i] == ub) cnt[2]++;       if (x[i] == mid) cnt[1]++;     }     S = sum - mid * n;     bool flag = false;     long long tmp, ans = n, ans_p;     if (S < 0) S *= -1, flag = true;     for (long long p = S; 2 * p <= n + S; p++) {       long long m = p - S;       if (flag)         tmp = min(ans, min(p, cnt[0]) + min(m, cnt[2]) + min(n - p - m, cnt[1]));       else         tmp = min(ans, min(p, cnt[2]) + min(m, cnt[0]) + min(n - p - m, cnt[1]));       if (ans > tmp) {         ans = tmp;         ans_p = p;       }     }     long long ans_m = ans_p - S;     if (flag) {       long long t = ans_m;       ans_m = ans_p;       ans_p = t;     }     cout << ans << endl;     for (int i = 1; i <= ans_p; i++) cout << ub <<    ;     for (int i = 1; i <= ans_m; i++) cout << lb <<    ;     for (int i = 1; i <= n - ans_p - ans_m; i++) cout << mid <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 0;     int d = 0;     string s;     cin >> n >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  A )         a++;       else         d++;     }     cout << (a == d ?  Friendship  : (a > d ?  Anton  :  Danik ));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long N;     cin >> N;     vector<long long> V;     long long Sum = N;     for (long long i = 0; i < N; i++) {       long long X;       cin >> X;       V.push_back(X);     }     long long L = 0;     long long Cnt = 0;     for (long long i = 0; i < N; i++) {       if (V[i] == V[L])         Cnt++;       else {         if (Cnt >= 2) Sum += Cnt * (Cnt - 1) / 2;         while (V[L] != V[i]) {           L++;           Cnt--;         }         Cnt++;       }     }     if (Cnt >= 2) Sum += Cnt * (Cnt - 1) / 2;     cout << Sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long s, total, ans, leaves[maxn];   int n;   vector<pair<long long, long long>> tree[maxn];   void dfs(int u, int prev,            priority_queue<pair<long long, pair<long long, long long>>>& pq) {     leaves[u] = (long long)(tree[u].size() == 1);     for (auto e : tree[u]) {       long long v = e.second, w = e.first;       if (v == prev) continue;       dfs(v, u, pq);       leaves[u] += leaves[v];       pq.push({w * leaves[v] - w / 2ll * leaves[v], {w, leaves[v]}});       total += w * leaves[v];     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       cin >> n >> s;       for (int i = 0; i < n; ++i) {         leaves[i] = 0;         tree[i].clear();       }       for (int i = 0; i < n - 1; ++i) {         long long u, v, w;         cin >> u >> v >> w;         u--, v--;         tree[u].push_back({w, v});         tree[v].push_back({w, u});       }       priority_queue<pair<long long, pair<long long, long long>>> pq;       total = ans = 0;       dfs(0, -1, pq);       while (total > s) {         auto cur = pq.top();         pq.pop();         long long w = cur.second.first, cnt = cur.second.second;         total -= w * cnt;         w /= 2ll;         total += w * cnt;         if (w > 0ll) pq.push({w * cnt - w / 2ll * cnt, {w, cnt}});         ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = (int)1e9 + 1;   const int MAX = 1e5 + 1;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x, arr[3] = {};     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       arr[x]++;     }     if (!arr[1])       cout << 0 << endl;     else if (arr[1] > arr[2])       cout << arr[2] + (arr[1] - arr[2]) / 3 << endl;     else if (arr[2] >= arr[1])       cout << arr[1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans, reg[26] = {1};   char s[100][100];   bool dfs(int dep) {     if (reg[dep] == n) return true;     if (dep >= ans || reg[dep] > n) return false;     ++dep;     for (int i = -1; i < (dep); ++i)       for (int j = 0; j < (dep); ++j) {         int ii = i;         if (ii == -1) ii = 25;         for (int k = 1; k <= 8; k <<= 1) {           reg[dep] = reg[ii] + k * reg[j];           if (dfs(dep)) {             sprintf(s[dep],  lea e%cx, [e%cx + %d*e%cx] , dep +  a , ii +  a , k,                     j +  a );             return true;           }         }       }     return false;   }   int main() {     scanf( %d , &n);     for (ans = 0; !dfs(0); ++ans)       ;     printf( %d n , ans);     for (int i = 1; i < (ans + 1); ++i) printf( %s n , s[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string tostring(int x) {     ostringstream o;     o << x;     return o.str();   }   int toint(string s) {     istringstream st(s);     int i;     st >> i;     return i;   }   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int inf = 2e9;   const double eps = 1e-7;   const long long INF = (long long)1e18;   int n;   long long h, k;   long long a[N];   int main() {     cin >> n >> h >> k;     for (int i = 0; i < (n); ++i) cin >> a[i];     int i = 0, j = 0;     long long sum = 0;     long long left = 0;     long long ans = 0;     while (i < n) {       j = i;       sum = left;       while (j < n && sum + a[j] <= h) {         sum += a[j];         j++;       }       ans += sum / k;       left = sum % k;       if (j < n && left + a[j] > h) {         ans++;         left = 0;       }       i = j;     }     if (left) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   long long gi() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? x : -x;   }   std::mt19937 rnd(time(NULL));   template <class T>   void cxk(T& a, T b) {     a = a > b ? a : b;   }   template <class T>   void cnk(T& a, T b) {     a = a < b ? a : b;   }   int a[100010];   int main() {     int qwq = gi(), n, k;     while (qwq--) {       n = gi(), k = gi();       for (int i = 1; i <= n; ++i) a[i] = gi();       bool s1 = 0, s2 = n == 1;       for (int i = 1; i <= n; ++i) s1 |= a[i] == k;       for (int i = 1; i < n; ++i) s2 |= a[i] >= k && a[i + 1] >= k;       for (int i = 1; i + 1 < n; ++i) s2 |= a[i] >= k && a[i + 2] >= k;       puts((s1 & s2) ?  yes  :  no );     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int n;   vector<set<int> > g(200000);   vector<int> used(200000);   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> x(m);     vector<int> y(m);     for (int i = 0; i < m; i++) {       cin >> x[i] >> y[i];       x[i]--;       y[i]--;       g[x[i]].insert(y[i]);       g[y[i]].insert(x[i]);     }     set<pair<int, int> > s;     vector<int> v(n);     for (int i = 0; i < n; i++) {       s.insert(make_pair(g[i].size(), i));       v[i] = g[i].size();     }     while (s.size()) {       int a = s.begin()->first;       int b = s.begin()->second;       if (a < k) {         s.erase(make_pair(a, b));         v[b] = 0;         for (auto i = g[b].begin(); i != g[b].end(); i++)           if (v[*i] >= k) {             s.erase(make_pair(v[*i], *i));             v[*i]--;             s.insert(make_pair(v[*i], *i));           }       } else         break;     }     vector<int> ans(m);     ans[m - 1] = s.size();     for (int i = m - 1; i >= 1; i--) {       int fl = 0;       if (s.find(make_pair(v[x[i]], x[i])) != s.end()) fl++;       if (s.find(make_pair(v[y[i]], y[i])) != s.end()) fl++;       if (fl != 2)         ans[i - 1] = ans[i];       else {         s.erase(make_pair(v[x[i]], x[i]));         s.erase(make_pair(v[y[i]], y[i]));         v[x[i]]--;         v[y[i]]--;         s.insert(make_pair(v[x[i]], x[i]));         s.insert(make_pair(v[y[i]], y[i]));         g[x[i]].erase(y[i]);         g[y[i]].erase(x[i]);         while (s.size()) {           int a = s.begin()->first;           int b = s.begin()->second;           if (a < k) {             s.erase(make_pair(a, b));             v[b] = 0;             for (auto i = g[b].begin(); i != g[b].end(); i++)               if (v[*i] >= k) {                 s.erase(make_pair(v[*i], *i));                 v[*i]--;                 s.insert(make_pair(v[*i], *i));               }           } else             break;         }         ans[i - 1] = s.size();       }     }     for (int i = 0; i < m; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, val;     cin >> n;     vector<int> vet;     for (int i = 0; i < n; i++) {       cin >> val;       vet.push_back(val);     }     sort(vet.begin(), vet.end());     vector<int> ans;     while (ans.size() < n) {       set<int> opa;       for (int i = 0; i < n; i++) {         if (vet[i] != -1) opa.insert(vet[i]);       }       set<int>::iterator it = opa.begin();       while (it != opa.end()) {         ans.push_back(*it);         it++;       }       for (int i = 0; i < n; i++) {         if (opa.count(vet[i])) {           opa.erase(vet[i]);           vet[i] = -1;         }       }     }     int resp = 0;     for (int i = 0; i < n - 1; i++) {       if (ans[i + 1] > ans[i]) resp++;     }     cout << resp <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Max(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ b; }   int Min(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ a; }   long long GCD(long long a, long long b) { return b != 0 ? GCD(b, a % b) : a; }   long long LCM(long long a, long long b) { return a * (b / GCD(a, b)); }   long long Pow(long long n, long long e) {     if (e == 0) return 1;     if (e == 1)       return n;     else if (e & 1) {       long long t = Pow(n, e / 2);       return n * t * t;     } else {       long long t = Pow(n, e / 2);       return t * t;     }   }   const long long MOD = 1000000007;   long long PowMod(long long n, long long e, long long m) {     if (e == 0) return 1;     if (e == 1)       return n % m;     else if (e & 1) {       long long t = PowMod(n, e / 2, m) % m;       return (((t * t) % m) * (n % m)) % m;     } else {       long long t = PowMod(n, e / 2, m) % m;       return (t * t) % m;     }   }   long long C(long long n, long long k) {     if (n == k || k == 0) return 1;     if (k > n / 2) k = n - k;     long long a = 1;     for (int i = (1), max_ = (k + 1); i < max_; ++i) {       a = (a * (n - i + 1)) % MOD;     }     long long b = 1;     for (int i = (1), max_ = (k + 1); i < max_; ++i) {       b = (b * i) % MOD;     }     a = (a * PowMod(b, MOD - 2, MOD)) % MOD;     return a;   }   long long a[2005], r[2005], inv[2005];   int main() {     int N, K;     scanf( %d %d , &N, &K);     for (int i = 0, max_ = (N); i < max_; ++i) scanf( %d , &a[i]);     if (K == 0) {       for (int i = 0, max_ = (N); i < max_; ++i) r[i] = a[i];     } else {       for (int i = (1), max_ = (2005); i < max_; ++i)         inv[i] = PowMod(i, MOD - 2, MOD);       r[0] = a[0];       for (int i = (1), max_ = (N); i < max_; ++i) {         r[i] = a[i];         long long curr = K;         int n = K;         int k = 1;         int j = i - 1;         while (j >= 0) {           long long tmp = (a[j] * curr) % MOD;           r[i] = (r[i] + tmp) % MOD;           ++n;           ++k;           curr = (curr * n) % MOD;           curr = (curr * inv[k]) % MOD;           --j;         }       }     }     for (int i = 0, max_ = (N); i < max_; ++i) printf( %I64d  , r[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int stack[90], n, k, ans, bag, a[90], tim[90];   int vec[90][90], zoom[90];   bool vis[90];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vec[a[i]][0]++;       vec[a[i]][vec[a[i]][0]] = i;     }     for (int i = 1; i <= n; i++)       tim[i] = vec[i][1], vec[i][vec[i][0] + 1] = n + 1, zoom[i] = 1;     for (int i = 1; i <= n; i++) {       if (!vis[a[i]]) {         if (bag < k)           bag++;         else {           int now, ref = 0;           for (int i = 1; i <= n; i++)             if (vis[i] && ref <= tim[i]) {               now = i;               ref = tim[i];             }           vis[now] = false;         }         ans++;         zoom[a[i]]++;         tim[a[i]] = vec[a[i]][zoom[a[i]]];         vis[a[i]] = true;       } else {         zoom[a[i]]++;         tim[a[i]] = vec[a[i]][zoom[a[i]]];       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     long long r = (n * (n - 1));     r = (r >> 1);     if (r > k) {       for (long long i = 0; i < n; i++) {         cout << 0 <<     << i <<   n ;       }       return 0;     }     cout <<  no solution n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5001;   long long x11[10];   long long y11[10];   long long x22[10];   long long y22[10];   long long deltax[10];   long long deltay[10];   int main() {     bool flag1 = 0;     bool flag2 = 0;     bool flag3 = 0;     for (int i = 0; i < 4; i++) {       scanf( %lld %lld %lld %lld , &x11[i], &y11[i], &x22[i], &y22[i]);       if (x11[i] == x22[i] && y11[i] == y22[i]) flag3 = 1;       deltax[i] = x11[i] - x22[i];       deltay[i] = y11[i] - y22[i];       if (deltax[i] == 0) flag1 = 1;       if (deltay[i] == 0) flag2 = 1;     }     if (!flag1 || !flag2 || flag3) {       printf( NO n );       return 0;     }     for (int i = 0; i < 4; i++) {       if (deltax[i] != 0 && deltay[i] != 0) {         printf( NO n );         return 0;       }     }     vector<long long> vx;     vector<long long> vy;     map<long long, int> mp1;     map<long long, int> mp2;     for (int i = 0; i < 4; i++) {       vx.push_back(x11[i]);       vx.push_back(x22[i]);       vy.push_back(y11[i]);       vy.push_back(y22[i]);       mp1[x11[i]]++;       mp1[x22[i]]++;       mp2[y11[i]]++;       mp2[y22[i]]++;     }     if (mp1.size() != 2 || mp2.size() != 2) {       printf( NO n );     } else {       bool tempflag = 0;       for (auto it : mp1) {         if (it.second != 4) tempflag = 1;       }       for (auto it : mp2) {         if (it.second != 4) tempflag = 1;       }       if (!tempflag)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   int main() {     ll n;     cin >> n;     vector<ll> a(n + 1);     ll curr = 0;     vector<ll> iseven(2);     ll ans = 0;     for (int i = 1; i <= n; i++) {       ll x;       cin >> x;       x = __builtin_popcountll(x);       a[i] = x;       curr = (curr + x) % 2;       ans += iseven[curr];       if (i > 1) {         if (curr == 0) ans++;         if (x % 2 == 0) ans--;       }       iseven[curr]++;     }     for (ll i = 1; i <= n; i++) {       ll maxi = a[i];       ll sum = a[i];       for (ll j = i - 1; j >= max(1ll, i - 62); j--) {         sum += a[j];         maxi = max(maxi, a[j]);         if (sum % 2 == 0 && 2 * maxi > sum) {           ans--;         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct Seg {     int sa, ea, sb, eb;   } p[200005];   int cmp(Seg &a, Seg &b) {     if (a.ea != b.ea)       return a.ea < b.ea;     else       return a.sa < b.sa;   }   int n, mx[4 * 200005], mi[4 * 200005];   void creat(int l, int r, int k) {     if (l == r) {       mx[k] = p[l].sb, mi[k] = p[l].eb;       return;     }     int mid = (l + r) / 2;     creat(l, mid, 2 * k);     creat(mid + 1, r, 2 * k + 1);     mx[k] = max(mx[2 * k], mx[2 * k + 1]);     mi[k] = min(mi[2 * k], mi[2 * k + 1]);   }   int querymin(int l, int r, int al, int ar, int k) {     if (l == al && r == ar) return mi[k];     int mid = (l + r) / 2;     if (ar <= mid)       return querymin(l, mid, al, ar, 2 * k);     else if (al > mid)       return querymin(mid + 1, r, al, ar, 2 * k + 1);     else       return min(querymin(l, mid, al, mid, 2 * k),                  querymin(mid + 1, r, mid + 1, ar, 2 * k + 1));   }   int querymax(int l, int r, int al, int ar, int k) {     if (l == al && r == ar) return mx[k];     int mid = (l + r) / 2;     if (ar <= mid)       return querymax(l, mid, al, ar, 2 * k);     else if (al > mid)       return querymax(mid + 1, r, al, ar, 2 * k + 1);     else       return max(querymax(l, mid, al, mid, 2 * k),                  querymax(mid + 1, r, mid + 1, ar, 2 * k + 1));   }   int ea[200005];   int solve() {     std::sort(p + 1, p + 1 + n, cmp);     creat(1, n, 1);     for (int i = 1; i <= n; i++) ea[i] = p[i].ea;     for (int i = 1; i <= n; i++) {       if (i == 1) continue;       int left = p[i].sa;       int ans = lower_bound(ea + 1, ea + i, left) - ea;       if (ans > i - 1) continue;       int maxL = querymax(1, n, ans, i - 1, 1);       int minR = querymin(1, n, ans, i - 1, 1);       if (minR < p[i].sb || maxL > p[i].eb) return 0;     }     return 1;   }   int main() {     int i, j, k, sig = 1;     scanf( %d , &n);     for (i = 1; i <= n; i++)       scanf( %d %d %d %d , &p[i].sa, &p[i].ea, &p[i].sb, &p[i].eb);     sig &= solve();     for (i = 1; i <= n; i++) swap(p[i].sa, p[i].sb), swap(p[i].ea, p[i].eb);     sig &= solve();     if (sig)       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int tem;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) scanf( %d , &arr[i]);       int flag = 1;       for (int i = 0; i < n - 1; i++) {         if (abs(arr[i] - arr[i + 1]) > 1) {           printf( YES n%d %d n , i + 1, i + 2);           flag = 0;           break;         }       }       if (flag) printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   void lire_input() { freopen( input.txt ,  r , stdin); }   void ecrire_output() { freopen( output.txt ,  w , stdout); }   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 1) {       for (int i = 0; i < n; i++) {         printf( %d  , i);       }       printf(  n );       for (int i = 1; i <= n; i++) {         if (i != n)           printf( %d  , i);         else           printf( %d  , 0);       }       printf(  n );       for (int i = 0; i < n; i++) {         if (i != n)           printf( %d  , (2 * i + 1) % n);         else           printf( %d  , i % n);       }     } else       cout <<  -1 ;     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool posible(int a, int b, int a2, int b2) {     if ((a + a2 == b && b == b2) || (a + b2 == b && b == a2) ||         (b + b2 == a && a == a2) || (b + a2 == a && a == b2)) {       return true;     }     return false;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int a, b, a2, b2;       cin >> a >> b >> a2 >> b2;       if (posible(a, b, a2, b2)) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, p, last[10];   struct node {     int x, y;   };   int s[10];   char a[1005][1005];   int vis[1005][1005], ans[10], can[10];   queue<node> que[10];   int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   void bfs() {     for (int i = 1; i <= p; i++) {       while (!que[i].empty()) que[i].pop();     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] !=  .  && a[i][j] !=  # ) {           que[a[i][j] -  0 ].push({i, j});           vis[i][j] = a[i][j] -  0 ;           last[a[i][j] -  0 ]++;         }       }     }     bool flag = true;     while (flag) {       flag = false;       for (int idx = 1; idx <= p; idx++) {         for (int ss = 1; ss <= s[idx] && can[idx] == 0; ss++) {           int num = last[idx];           last[idx] = 0;           for (int t = 1; t <= num; t++) {             node now = que[idx].front();             que[idx].pop();             ans[idx]++;             for (int i = 0; i < 4; i++) {               int xx = now.x + d[i][0], yy = now.y + d[i][1];               if (xx >= 0 && xx < n && yy >= 0 && yy < m && vis[xx][yy] == 0 &&                   a[xx][yy] ==  . ) {                 que[idx].push({xx, yy});                 vis[xx][yy] = idx;                 last[idx]++;               }             }           }           if (que[idx].empty()) can[idx] = idx;         }       }       for (int i = 1; i <= p; i++)         if (!que[i].empty()) flag = true;     }     for (int i = 1; i <= p; i++) printf( %d  , ans[i]);     printf(  n );   }   int main() {     while (scanf( %d %d %d , &n, &m, &p) != EOF) {       memset(a, 0, sizeof(a));       memset(s, 0, sizeof(s));       memset(ans, 0, sizeof(ans));       memset(vis, 0, sizeof(vis));       memset(last, 0, sizeof(last));       memset(can, 0, sizeof(can));       for (int i = 1; i <= p; i++) scanf( %d , &s[i]);       getchar();       for (int i = 0; i < n; i++) scanf( %s , a[i]);       bfs();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int inf = 1e9;   int main() {     long long n, m, grt = 0, eq = 0, less = 0, i;     cin >> n >> m;     for (i = 0; i < n; i++) {       long long temp;       cin >> temp;       if (temp == m)         eq++;       else if (temp < m)         less++;       else         grt++;     }     long long ans = 0, tot;     if (eq == 0) {       eq++;       ans++;     }     tot = less + eq + grt;     long long temp = (tot + 1) / 2;     if (less + eq < temp) {       ans += grt - less - eq;       less += grt - less - eq;     } else if (tot - (grt + eq) > temp) {       ans += less - eq - grt;       grt += less - eq - grt;     }     tot = less + eq + grt;     temp = (tot + 1) / 2;     if (less == temp) ans++;     if (grt == tot - temp + 1) ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool prime(int n) {     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   int main() {     int n;     cin >> n;     if (prime(n)) {       cout << 1 <<   n  << n << endl;       return 0;     }     if (prime(n - 2)) {       cout << 2 <<   n  << 2 <<   n  << n - 2 << endl;       return 0;     }     cout << 3 <<   n  << 3 << endl;     n -= 3;     for (int i = 2; i <= n; i++) {       if (prime(i) and prime(n - i)) {         cout << i <<   n  << n - i << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   const int INF = 2000000000;   const ll LLINF = 9000000000000000000;   int main() {     int N;     scanf( %d , &N);     vi A(N, 0LL), B(N, 0LL);     for (int i = 0; i < N; ++i) {       int v;       scanf( %d , &v);       A[i] = ll(v);       B[i] = A[i] + (i > 0 ? B[i - 1] : 0LL);     }     ll mx = 0LL;     for (int i = 0; i < N; ++i) mx += ll(i + 1) * A[i];     vii lns;     vector<ld> start(1, -std::numeric_limits<ld>::infinity());     lns.push_back({0, 0});     for (int i = 0; i < N; ++i) {       while (lns.size() > 1 && start.back() >= ld(-B[i] - lns.back().second) /                                                    ld(lns.back().first - i - 1)) {         lns.pop_back();         start.pop_back();       }       start.push_back(ld(-B[i] - lns.back().second) /                       ld(lns.back().first - i - 1));       lns.push_back({i + 1, -B[i]});     }     ll bestchange = 0LL;     int D = 5;     for (int i = 0; i < N; ++i) {       ll change = B[i] - A[i] * ll(i + 1);       int l = 0, r = int(lns.size()) - 1;       while (l < r) {         int m = (l + r + 1) / 2;         if (start[m] > A[i])           r = m - 1;         else           l = m;       }       for (int j = max(0, l - D); j < min(int(lns.size()), l + D + 1); ++j) {         if (bestchange < change + A[i] * lns[j].first + lns[j].second) {           bestchange = change + A[i] * lns[j].first + lns[j].second;         }       }     }     cout << (mx + bestchange) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(vector<T> &a, long long n) {     T x;     a.clear();     for (long long i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }   }   template <class T>   void write(vector<T> &a) {     for (T x : a) cout << x <<    ;     cout << endl;   }   const int N = 300005;   const int S = 500;   long long sum[S][S];   long long ans[N];   vector<pair<pair<int, int>, int> > q;   int n, m;   int w[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> w[i];     cin >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       q.push_back(make_pair(make_pair(a, b), i));     }     sort(q.begin(), q.end());     reverse(q.begin(), q.end());     int pos = n;     for (int i = 0; i < q.size(); i++) {       int a = q[i].first.first;       int b = q[i].first.second;       int id = q[i].second;       while (pos >= a) {         for (int j = 1; j < S; j++) sum[j][pos % j] += w[pos];         pos--;       }       if (b < S)         ans[id] = sum[b][a % b];       else {         long long res = 0;         for (int j = a; j <= n; j += b) res += w[j];         ans[id] = res;       }     }     for (int i = 0; i < m; i++) cout << ans[i] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> mp1, mp2;     map<int, int>::iterator it;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       mp1[a] = b;     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       if (mp1.find(a) != mp1.end()) {         it = mp1.find(a);         if (it->second > b) {           continue;         } else {           mp1.erase(it);           mp2[a] = b;         }       } else {         mp2[a] = b;       }     }     long long sum = 0;     it = mp1.begin();     while (it != mp1.end()) {       sum += it->second;       it++;     }     it = mp2.begin();     while (it != mp2.end()) {       sum += it->second;       it++;     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long test(long long k) {     long long a[] = {-1, 1, k + 2};     int c = -1;     long long cur = 0, res = 0;     for (int i = 0; i < 3; i++) {       cur += a[i];       if (cur < 0) {         cur = 0;         c = i;       }       res = max(res, (i - c) * cur);     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long k;     cin >> k;     int a = k + 2000;     cout << 2000 << endl << -1 <<    ;     for (int i = 1; i < 2000; i++) {       cout << min(a, (int)1e6) <<    ;       a -= min(a, (int)1e6);     }     return 0;   }


#include <bits/stdc++.h>   #define task  suffixarray    #define ll long long   #define FOR( i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)   #define FOD( i, l, r) for(int i = (l), _r = (r); i >= _r; --i)   #define REP( i, n)    for(int i = 0, _n = (n); i < _n; ++i)   #define pii pair<int,int>   #define fi  first   #define se  second   #define MASK(x)  (1ll << (x))   #define BIT(x,k) (((x) >> (k)) & 1ll)   #define OFF(x,k) ((x) & ~(1ll << (k)))   #define ON(x,k)  ((1ll << (k)) | (x))   #define endl   n    #define __builtin_popcount __builtin_popcountll   /*    Author: Diem Quynh :>> //d_quynh_2811   */   using namespace std;   int const N = 4e5 + 5;   int const mod = 998244353;   int n, k, a[N], idx[N], fact[N], ifact[N];   int num = 1, ans;   void inp()   {       cin >> n >> k;       FOR( i, 1, n)       {           cin >> a[i];           ++a[i];           idx[a[i]] = i;       }   }   int Pow(int a, int b)   {       if(b == 0)           return 1;       int tmp = Pow(a, b / 2);       if(b & 2)           return (1ll * tmp * tmp) % mod * a % mod;       return 1ll * tmp * tmp % mod;   }   int nCk(int n, int k)   {       return 1ll * fact[n] * ifact[k] % mod * ifact[n - k] % mod;   }   void solve()   {       FOR( i, 1, n - 1) k += idx[a[i] + 1] < idx[a[i + 1] + 1];       if(n > k)       {           cout << 0;           return;       }       fact[0] = 1;       FOR( i, 1, k) fact[i] = (1ll * fact[i - 1] * i) % mod;       ifact[k] = Pow(fact[k], mod - 2);       FOD( i, k - 1, 0) ifact[i] = 1ll * (i + 1) * ifact[i + 1] % mod;       cout << nCk(k, n);   }   int main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);   //    freopen(task .inp , r ,stdin);   //    freopen(task .out , w ,stdout);       inp();       solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fu = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   template <typename T>   struct hash_map_t {     vector<T> v, val, nxt;     vector<int> head;     int mod, tot, lastv;     T lastans;     bool have_ans;     hash_map_t(int md = 0) {       head.clear();       v.clear();       val.clear();       nxt.clear();       tot = 0;       mod = md;       nxt.resize(1);       v.resize(1);       val.resize(1);       head.resize(mod);       have_ans = 0;     }     bool count(int x) {       int u = x % mod;       for (register int i = head[u]; i; i = nxt[i]) {         if (v[i] == x) {           have_ans = 1;           lastv = x;           lastans = val[i];           return 1;         }       }       return 0;     }     void ins(int x, int y) {       int u = x % mod;       nxt.push_back(head[u]);       head[u] = ++tot;       v.push_back(x);       val.push_back(y);     }     int qry(int x) {       if (have_ans && lastv == x) return lastans;       count(x);       return lastans;     }   };   const int N = 755, MAXN = 1e7 + 5;   queue<int> q;   char c[MAXN];   vector<int> adj[N << 1];   int ch[MAXN][2], fail[MAXN], id[MAXN], l[N], r[N], pre[N << 1], used[N << 1],       vis[N << 1];   int f[N][N], n, len, tot, dfn, ans;   int dfs1(int u) {     for (register unsigned i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (used[v] != dfn) {         used[v] = dfn;         if (!pre[v] || dfs1(pre[v])) {           pre[v] = u;           pre[u] = v;           return 1;         }       }     }     return 0;   }   void dfs2(int u) {     vis[u] = 1;     for (register unsigned i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (!vis[v] && pre[v]) vis[v] = 1, dfs2(pre[v]);     }   }   int main() {     read(n);     for (register int i = 1; i <= n; i++) {       scanf( %s , c + r[i - 1] + 1);       len = strlen(c + r[i - 1] + 1);       l[i] = r[i - 1] + 1;       r[i] = l[i] + len - 1;       int now = 0;       for (register int j = l[i]; j <= r[i]; j++) {         int x = c[j] -  a ;         if (!ch[now][x]) ch[now][x] = ++tot;         now = ch[now][x];       }       id[now] = i;     }     for (register int i = 0; i <= 1; i++)       if (ch[0][i]) q.push(ch[0][i]);     while (!q.empty()) {       int u = q.front();       q.pop();       for (register int i = 0; i <= 1; i++) {         int v = ch[u][i];         if (!v) continue;         int now = fail[u], last = 1;         while (last) {           if (ch[now][i]) {             fail[v] = ch[now][i];             break;           }           last = now;           now = fail[now];         }         if (!id[v]) id[v] = id[fail[v]];         q.push(v);       }     }     for (register int i = 1; i <= n; i++) {       int now = 0;       for (register int j = l[i]; j <= r[i]; j++) {         int x = c[j] -  a ;         now = ch[now][x];         if (j == r[i])           f[i][id[fail[now]]] = 1;         else           f[i][id[now]] = 1;       }     }     for (register int k = 1; k <= n; k++) {       for (register int i = 1; i <= n; i++) {         for (register int j = 1; j <= n; j++) {           f[i][j] |= (f[i][k] & f[k][j]);         }       }     }     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= n; j++) {         if (f[i][j]) {           adj[i].push_back(j + n);           adj[j + n].push_back(i);         }       }     }     ans = n;     for (register int i = 1; i <= n; i++)       if (!pre[i]) ++dfn, ans -= dfs1(i);     print(ans,   n );     for (register int i = 1; i <= n; i++)       if (!pre[i]) dfs2(i);     for (register int i = 1; i <= n; i++)       if (vis[i] && !vis[i + n]) print(i,    );     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   int main() {     int arr[1000], n, i, j, k, counter = 99999999, x, y;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %d , &arr[i]);     }     for (j = 1; j < n; ++j) {       for (k = j - 1; k < j; ++k) {         if (abs(arr[j] - arr[k]) < counter) {           counter = abs(arr[j] - arr[k]);           x = j + 1;           y = k + 1;         }       }     }     if (abs(arr[0] - arr[n - 1]) < counter) {       counter = abs(arr[0] - arr[n - 1]);       x = 1;       y = n;     }     printf( %d %d , y, x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int eps = -1e6;   const int MAX = 200010;   long long int n, k, x;   long long int a[MAX], pre[MAX], s[MAX];   long long int expo(long long int a, long long int b) {     long long int x = 1, y = a;     while (b > 0) {       if (b & 1) x = (x * y);       y = (y * y);       b >>= 1;     }     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k >> x;     for (int i = 0, _n = (n); i < _n; ++i) {       cin >> a[i];       if (i == 0)         pre[i] = a[i];       else         pre[i] = pre[i - 1] | a[i];     }     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1)         s[i] = a[i];       else         s[i] = s[i + 1] | a[i];     }     long long int tmp = expo(x, k);     long long int res = 0;     for (int i = 0, _n = (n); i < _n; ++i) {       long long int z = a[i] * 1ll * tmp;       if (i == 0)         res = max(res, z | s[1]);       else if (i == n - 1)         res = max(res, pre[n - 2] | z);       else         res = max(res, pre[i - 1] | z | s[i + 1]);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100000];   int pre[100000];   int leftMax;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       int maxLen = 0;       int n, x;       cin >> n >> x;       for (int i = 0; i < n; i++) cin >> arr[i];       pre[0] = arr[0];       for (int i = 1; i < n; i++) pre[i] = arr[i] + pre[i - 1];       leftMax = -1;       for (int i = 0; i < n; i++) {         pre[i] = pre[i] % x;         if (pre[i] != 0) maxLen = i + 1;         if (pre[i] != 0 && leftMax == -1) leftMax = i;       }       if (maxLen == 0)         cout <<  -1 n ;       else {         int finalLen = maxLen;         for (int i = 0; i < n; i++) {           if (pre[i] == 0)             finalLen = max(finalLen, max(abs(i - leftMax), abs(i - maxLen)));         }         cout << finalLen <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   constexpr int INF = 1073741823;   constexpr int MINF = -1073741823;   constexpr ll LINF = ll(4661686018427387903);   constexpr ll MOD = 1000000007;   const long double PI = acosl(-1.0L);   using namespace std;   void scans(string& str) {     char c;     str =   ;     scanf( %c , &c);     if (c ==   n ) scanf( %c , &c);     while (c !=   n  && c != -1 && c !=    ) {       str += c;       scanf( %c , &c);     }   }   void scanc(char& str) {     char c;     scanf( %c , &c);     if (c == -1) return;     while (c ==   n ) {       scanf( %c , &c);     }     str = c;   }   double acot(double x) { return PI / 2 - atan(x); }   ll LSB(ll n) { return (n & (-n)); }   ll p(ll a) { return a * a; }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int r, g, b;       scanf( %d%d%d , &r, &g, &b);       vector<int> R(r), G(g), B(b);       for (int i = 0; i < (r); ++i) scanf( %d , &R[i]);       for (int i = 0; i < (g); ++i) scanf( %d , &G[i]);       for (int i = 0; i < (b); ++i) scanf( %d , &B[i]);       sort((R).begin(), (R).end());       sort((G).begin(), (G).end());       sort((B).begin(), (B).end());       ll ans = LINF;       for (int i = 0; i < (r); ++i) {         auto itegreen1 = lower_bound((G).begin(), (G).end(), R[i]),              iteblue1 = lower_bound((B).begin(), (B).end(), R[i]);         ll green1 = -1;         if (itegreen1 != G.end())           green1 = *itegreen1;         else           green1 = G[G.size() - 1];         if (itegreen1 != G.begin()) --itegreen1;         ll green2 = -1;         if (itegreen1 != G.begin())           green2 = *itegreen1;         else           green2 = G[0];         ll blue1 = -1;         if (iteblue1 != B.end())           blue1 = *iteblue1;         else           blue1 = B[B.size() - 1];         if (iteblue1 != B.begin()) --iteblue1;         ll blue2 = -1;         if (iteblue1 != B.begin())           blue2 = *iteblue1;         else           blue2 = B[0];         ans =             min<ll>({(green1 != -1 and blue1 != -1)                          ? p(green1 - R[i]) + p(R[i] - blue1) + p(blue1 - green1)                          : LINF,                      (green2 != -1 and blue1 != -1)                          ? p(green2 - R[i]) + p(R[i] - blue1) + p(blue1 - green2)                          : LINF,                      (green1 != -1 and blue2 != -1)                          ? p(green1 - R[i]) + p(R[i] - blue2) + p(blue2 - green1)                          : LINF,                      (green2 != -1 and blue2 != -1)                          ? p(green2 - R[i]) + p(R[i] - blue2) + p(blue2 - green2)                          : LINF,                      ans});       }       for (int i = 0; i < (g); ++i) {         auto itered1 = lower_bound((R).begin(), (R).end(), G[i]),              iteblue1 = lower_bound((B).begin(), (B).end(), G[i]);         ll red1 = -1;         if (itered1 != R.end())           red1 = *itered1;         else           red1 = R[R.size() - 1];         if (itered1 != R.begin()) --itered1;         ll red2 = -1;         if (itered1 != R.begin())           red2 = *itered1;         else           red2 = R[0];         ll blue1 = -1;         if (iteblue1 != B.end())           blue1 = *iteblue1;         else           blue1 = B[B.size() - 1];         if (iteblue1 != B.begin()) --iteblue1;         ll blue2 = -1;         if (iteblue1 != B.begin())           blue2 = *iteblue1;         else           blue2 = B[0];         ans = min<ll>({(red1 != -1 and blue1 != -1)                            ? p(red1 - G[i]) + p(G[i] - blue1) + p(blue1 - red1)                            : LINF,                        (red2 != -1 and blue1 != -1)                            ? p(red2 - G[i]) + p(G[i] - blue1) + p(blue1 - red2)                            : LINF,                        (red1 != -1 and blue2 != -1)                            ? p(red1 - G[i]) + p(G[i] - blue2) + p(blue2 - red1)                            : LINF,                        (red2 != -1 and blue2 != -1)                            ? p(red2 - G[i]) + p(G[i] - blue2) + p(blue2 - red2)                            : LINF,                        ans});       }       for (int i = 0; i < (b); ++i) {         auto itered1 = lower_bound((R).begin(), (R).end(), B[i]),              itegreen1 = lower_bound((G).begin(), (G).end(), B[i]);         ll green1 = -1;         if (itegreen1 != G.end())           green1 = *itegreen1;         else           green1 = G[G.size() - 1];         if (itegreen1 != G.begin()) --itegreen1;         ll green2 = -1;         if (itegreen1 != G.begin())           green2 = *itegreen1;         else           green2 = G[0];         ll red1 = -1;         if (itered1 != R.end())           red1 = *itered1;         else           red1 = R[R.size() - 1];         if (itered1 != R.begin()) --itered1;         ll red2 = -1;         if (itered1 != R.begin())           red2 = *itered1;         else           red2 = R[0];         ans = min<ll>({(red1 != -1 and green1 != -1)                            ? p(red1 - B[i]) + p(B[i] - green1) + p(green1 - red1)                            : LINF,                        (red2 != -1 and green1 != -1)                            ? p(red2 - B[i]) + p(B[i] - green1) + p(green1 - red2)                            : LINF,                        (red1 != -1 and green2 != -1)                            ? p(red1 - B[i]) + p(B[i] - green2) + p(green2 - red1)                            : LINF,                        (red2 != -1 and green2 != -1)                            ? p(red2 - B[i]) + p(B[i] - green2) + p(green2 - red2)                            : LINF,                        ans});       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct cmp {     bool operator()(long long a, long long b) { return a > b; }   };   multiset<long long> mex, msy;   multiset<long long, cmp> msx, mey;   int main() {     long long n;     cin >> n;     long long sx[n], ex[n], sy[n], ey[n];     for (long long i = 0; i < n; i++) {       cin >> sx[i] >> ey[i] >> ex[i] >> sy[i];       msx.insert(sx[i]);       mex.insert(ex[i]);       msy.insert(sy[i]);       mey.insert(ey[i]);     }     for (long long i = 0; i < n; i++) {       msx.erase(msx.find(sx[i]));       mex.erase(mex.find(ex[i]));       msy.erase(msy.find(sy[i]));       mey.erase(mey.find(ey[i]));       if (*msx.begin() <= *mex.begin() && *msy.begin() >= *mey.begin()) {         cout << *msx.begin() <<     << *msy.begin() << endl;         return 0;       }       msx.insert(sx[i]);       mex.insert(ex[i]);       msy.insert(sy[i]);       mey.insert(ey[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     pair<int, int> cc[105];     for (int i = 1; i <= m; i++) {       int a, b, c, d;       cin >> a >> b >> c >> d;       for (int j = a; j <= b; j++) {         if (!cc[j].first || c < cc[j].first) {           cc[j].first = c;           cc[j].second = d;         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++) ans += cc[i].second;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long q_pow(long long a, long long b, long long c) {     if (b == 0) return 1;     long long ret = q_pow(a, b / 2, c);     ret = (ret * ret) % c;     if (b & 1) ret = (ret * a) % c;     return ret;   }   int main() {     scanf( %d%d , &n, &m);     long long ans = (q_pow(3, n, m) + m - 1) % m;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const char nl =   n ;   const int mod = 1000000007;   const double pi = 4 * atan(1);   const int inf = 2000000000;   const long long linf = (long long)1e18;   const int pr = 37;   const int maxn = 1000001;   const int maxn_big = 1000001;   string s;   vector<int> v;   unsigned long long h[maxn], p[maxn];   unsigned long long get_hash(int l, int r) {     int len = (r - l) + 1;     if (!l) return h[r];     return h[r] - h[l - 1] * p[len];   }   bool check(int pf) {     unsigned long long pref_hash = get_hash(0, pf);     bool has_ans = 0;     for (int i = 1; i < ((int)(s.size())) - 1; ++i) {       int r = i + pf;       if (r >= ((int)(s.size())) - 1) break;       if (get_hash(i, r) == pref_hash) {         has_ans = 1;         break;       }     }     return has_ans;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     srand(time(NULL));     cin >> s;     h[0] = s[0];     p[0] = 1;     for (int i = 1; i < ((int)(s.size())); ++i) {       h[i] = h[i - 1] * pr + s[i];       p[i] = p[i - 1] * pr;     }     for (int i = 0; i < ((int)(s.size())); ++i) {       int l = ((int)(s.size())) - 1 - i;       if (get_hash(0, i) == get_hash(l, ((int)(s.size())) - 1)) v.push_back(i);     }     if (!((int)(v.size()))) {       cout <<  Just a legend ;       return 0;     }     int l = -1, r = ((int)(v.size()));     bool has = 0;     while (r - l > 1) {       int mid = (r + l) / 2;       if (check(v[mid])) {         l = mid;         has = 1;       } else {         r = mid;       }     }     if (!has) {       cout <<  Just a legend ;       return 0;     }     string res =   ;     for (int i = 0; i <= v[l]; ++i) res += s[i];     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 25;   int main(int argc, char *argv[]) {     long long n;     cin >> n;     long long ret1 = (1LL << 60);     long long ret2 = 0;     for (long long x = 1; x * x <= n; ++x) {       if (n % x) continue;       long long m = n / x;       for (long long y = 1; y * y <= m; ++y) {         if ((n / x) % y) continue;         long long z = m / y;         long long a = x + 1;         long long b = y + 2;         long long c = z + 2;         ret1 = min(a * b * c - n, ret1);         ret2 = max(a * b * c - n, ret2);         b = x + 2;         c = z + 2;         a = y + 1;         ret1 = min(a * b * c - n, ret1);         ret2 = max(a * b * c - n, ret2);         a = z + 1;         b = x + 2;         c = y + 2;         ret1 = min(a * b * c - n, ret1);         ret2 = max(a * b * c - n, ret2);       }     }     cout << ret1 <<     << ret2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1000000000 )   using namespace std;   inline void solve();   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }   string abc =  abcdefghijklmnopqrstuvwxyz ;   string ABC =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   string digits =  0123456789 ;   void solve() {     vector<long long> ind[30];     string s;     cin >> s;     long long n = s.length();     for (long long i = 0; i < n; i++) ind[s[i] -  a ].push_back(i);     double ans = 0;     s = s + s;     long long p[30] = {0};     for (long long i = 0; i < 26; i++) {       for (long long len = 1; len < n; len++) {         long long c[30] = {0};         for (long long l = 0; l < ind[i].size(); l++) {           c[s[ind[i][l] + len] -  a ]++;         }         long long cnt = 0;         for (long long j = 0; j < 30; j++)           if (c[j] == 1) cnt++;         p[i] = max(p[i], cnt);       }       ans += p[i] * 1. / n;     }     cout << setprecision(15) << fixed << ans;   }


#include <bits/stdc++.h>   using namespace std;   void qmax(long long &x, long long y) {     if (x < y) x = y;   }   void qmin(long long &x, long long y) {     if (x > y) x = y;   }   inline long long read() {     char s;     long long k = 0, base = 1;     while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s)))       ;     if (s == EOF) exit(0);     if (s ==  - ) base = -1, s = getchar();     while (isdigit(s)) {       k = k * 10 + (s ^  0 );       s = getchar();     }     return k * base;   }   inline void write(long long x) {     static char cnt, num[15];     cnt = 0;     if (!x) {       putchar( 0 );       return;     }     for (; x; x /= 10) num[++cnt] = x % 10;     for (; cnt; putchar(num[cnt--] + 48))       ;   }   const long long maxn = 100000 + 100;   long long n, d, b, d1;   long long a[maxn];   long long s1[maxn], s2[maxn];   signed main() {     n = read();     d = read();     b = read();     d1 = n / 2 * b;     for (long long i = 1; i <= n; i++) a[i] = read();     for (long long i = 1; i <= n; i++) {       s1[i] = min(a[i], d1) + s1[i - 1];       d1 -= min(d1, a[i]);     }     d1 = n / 2 * b;     for (long long i = n; i >= 1; i--) {       s2[i] = min(a[i], d1) + s2[i + 1];       d1 -= min(d1, a[i]);     }     d1 = 0;     long long R = n / 2, r = 0, ans1 = 0, ans2 = 0;     for (long long i = 1; i <= R; i++) {       r += d + 1;       r = min(n, r);       if (d1 + b <= s1[r])         d1 += b;       else         ans1++;     }     R = (n + 1) / 2 + 1;     d1 = 0;     r = 0;     long long l = n + 1;     for (long long i = n; i >= R; i--) {       l -= d + 1;       l = max(1ll, l);       if (d1 + b <= s2[l])         d1 += b;       else         ans2++;     }     cout << max(ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, d, x, y, javab1, javab2, ans[1000];     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n >> x >> y >> d;       javab1 = javab2 = n;       if ((y - x) % d == 0) {         ans[i] = ((abs(y - x)) / d);       } else if ((y - 1) % d == 0 || (n - y) % d == 0) {         if ((n - y) % d == 0) {           javab1 = (n - x + d - 1) / d;           javab1 += (n - y) / d;         }         if ((y - 1) % d == 0) {           javab2 = (x - 1 + d - 1) / d;           javab2 += (y - 1) / d;         }         ans[i] = (min(javab2, javab1));       } else {         ans[i] = -1;       }     }     for (int i = 0; i < t; i++) {       cout << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using gg = long long;   constexpr gg MAX = 1e6 + 5;   constexpr gg mod = 1e9 + 7;   constexpr gg INF = 1e10;   constexpr double thre = 1e-7;   gg ti, ni, mi, ki, di, pi, xi, yi;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ti = 1;     cin >> ti;     while (ti--) {       string a, b;       cin >> ni >> a >> b;       map<char, set<char>> m;       for (gg i = 0; i < ni; ++i) {         if (a[i] != b[i]) {           m[a[i]].insert(b[i]);         }       }       gg ans = 0;       bool f = true;       while (not m.empty()) {         auto& [i, j] = *m.begin();         if (*j.begin() < i) {           f = false;           break;         }         if (j.size() != 1) {           for (auto k = next(j.begin()); k != j.end(); ++k) {             m[*j.begin()].insert(*k);           }         }         m.erase(m.begin());         ans++;       }       cout << (f ? ans : -1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, h, m, qh, qm, qhm, d;     cin >> n >> s;     qh = 0, qm = 0;     qhm = 0;     for (int i = 0; i < n; i++) {       cin >> h >> m;       d = h * 60 + m;       if (i == 0 && d >= s + 1) {         cout << 0 <<     << 0;         return 0;       }       if (d - qhm >= 2 * s + 2) {         qhm += s + 1;         cout << qhm / 60 <<     << qhm % 60;         return 0;       }       qhm = d;     }     qhm += s + 1;     cout << qhm / 60 <<     << qhm % 60;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   const int maxN = 3000;   int dist[maxN + 10][maxN + 10], n, m, a, b, s[2], t[2], l[2], ans;   vector<int> e[maxN + 10];   void bfs(int u) {     memset(dist[u], -1, sizeof(dist[u]));     dist[u][u] = 0;     queue<int> q;     q.push(u);     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < e[x].size(); i++) {         int y = e[x][i];         if (dist[u][y] == -1) {           dist[u][y] = dist[u][x] + 1;           q.push(y);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       e[a].push_back(b);       e[b].push_back(a);     }     for (int i = 0; i < 2; i++) {       cin >> s[i] >> t[i] >> l[i];       s[i]--;       t[i]--;     }     for (int i = 0; i < n; i++) {       bfs(i);     }     if (dist[s[0]][t[0]] > l[0] || dist[s[1]][t[1]] > l[1]) return cout << -1, 0;     ans = dist[s[0]][t[0]] + dist[s[1]][t[1]];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int d1 = dist[s[0]][i] + dist[i][j] + dist[j][t[0]];         int d2 = dist[s[1]][i] + dist[i][j] + dist[j][t[1]];         if (d1 <= l[0] && d2 <= l[1]) {           ans = min(ans, d1 + d2 - dist[i][j]);         }         d2 = dist[t[1]][i] + dist[i][j] + dist[j][s[1]];         if (d1 <= l[0] && d2 <= l[1]) {           ans = min(ans, d1 + d2 - dist[i][j]);         }         d1 = dist[t[0]][i] + dist[i][j] + dist[j][s[0]];         if (d1 <= l[0] && d2 <= l[1]) {           ans = min(ans, d1 + d2 - dist[i][j]);         }         d2 = dist[s[1]][i] + dist[i][j] + dist[j][t[1]];         if (d1 <= l[0] && d2 <= l[1]) {           ans = min(ans, d1 + d2 - dist[i][j]);         }       }     }     cout << m - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 2e3 + 1;   const int maxm = 2e3 + 1;   char a[maxn], b[maxn];   int num[maxn];   int m, d;   long long dp[maxn][maxm];   int len;   int judge(const char* s, int lena) {     int mod = 0;     for (int i = 1; i <= lena; i++) {       mod = (mod * 10 + s[i]) % m;       if ((i & 1) == 0 && s[i] != d) {         return 0;       }       if ((i & 1) && s[i] == d) return 0;     }     return (mod == 0);   }   int val[maxn];   long long dfs(int pos, int mod, bool limit) {     if (pos == len + 1) {       return mod == 0;     }     if (!limit && dp[pos][mod] != -1) return dp[pos][mod];     int up = (limit ? num[pos] : 9);     long long res = 0;     for (int i = 0; i <= up; i++) {       int tmod = (mod * 10 + i) % m;       if ((pos & 1) && (i == d)) continue;       if (!(pos & 1) && (i != d)) continue;       res = (res + dfs(pos + 1, tmod, limit && i == up)) % MOD;     }     if (!limit) dp[pos][mod] = res;     return res;   }   long long solve(const char* s, int lena) {     for (int i = 1; i <= lena; i++) num[i] = s[i];     len = lena;     memset(dp, -1, sizeof(dp));     return dfs(1, 0, true) % MOD;   }   int main() {     cin >> m >> d;     cin >> (a + 1);     cin >> (b + 1);     int lena = strlen(a + 1), lenb = strlen(b + 1);     for (int i = 1; i <= lena; i++) a[i] -=  0 ;     for (int i = 1; i <= lenb; i++) b[i] -=  0 ;     cout << ((solve(b, lenb) - solve(a, lena) + judge(a, lena)) % MOD + MOD) % MOD          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = LLONG_MAX;   struct minimum_cost_bipartite_matching {     int nl, nr;     long long mc = 0;     vector<int> ml, mr, ly;     minimum_cost_bipartite_matching(int nl, int nr, vector<vector<long long>> &c)         : nl(nl), nr(nr), ml(nl, -1), mr(nr, -1), ly(nr) {       vector<long long> s(nl), t(nr);       for (int i = 0; i < nl; i++) {         int x = i, y = -1;         vector<bool> u(nr);         vector<long long> md(nr, inf);         while (x != -1) {           long long ny = -1, d = inf;           for (int j = 0; j < nr; j++)             if (!u[j]) {               long long v = c[x][j] - s[x] - t[j];               if (v < md[j]) md[j] = v, ly[j] = y;               if (md[j] < d) d = md[j], ny = j;             }           s[i] += d;           mc += d;           for (int j = 0; j < nr; j++)             if (u[j])               s[mr[j]] += d, t[j] -= d;             else               md[j] -= d;           y = ny;           u[y] = true;           x = mr[y];         }         while (y != -1) {           mr[y] = ly[y] != -1 ? mr[ly[y]] : i;           ml[mr[y]] = y;           y = ly[y];         }       }     }   };   int charToInt(char c) { return c >=  a  && c <=  z  ? c -  a  : c -  A  + 26; }   char intToChar(int c) { return c < 26 ?  a  + c :  A  + c - 26; }   int main() {     int n, k;     cin >> n >> k;     string s[2];     cin >> s[0] >> s[1];     vector<vector<long long>> c(k, vector<long long>(k));     for (int i = 0; i < n; i++) c[charToInt(s[0][i])][charToInt(s[1][i])]--;     minimum_cost_bipartite_matching mcbm(k, k, c);     cout << -mcbm.mc <<   n ;     for (int i = 0; i < k; i++) cout << intToChar(mcbm.ml[i]);     cout <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( O8 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long int N = 4e6 + 20, mod = 1e9 + 7, inf = 1e9, dlt = 12250,                       maxm = 2e6;   int poww(long long a, int k) {     if (!k) return 1;     if (k == 1) return a;     long long r = poww(a, k / 2);     return (((r * r) % mod) * poww(a, k & 1)) % mod;   }   int trie[N][3], cnt;   long long a[N / 10];   void build(string s) {     int p = 0;     string t =   ;     for (char ch : s) {       int u = ch -  0 ;       t += ch;       if (!trie[p][u]) {         cnt++;         trie[p][u] = cnt;       }       p = trie[p][u];     }   }   long long que(long long x) {     int p = 0, h = 0;     long long y = 0;     for (int i = 0; i < 40; i++) {       if (!trie[p][0] && !trie[p][1]) return y;       bool f = (!(x & (1ll << (39 - i))));       if (!trie[p][0] || (trie[p][1] && f)) {         if (f) y += (1ll << (39 - i));         p = trie[p][1];         continue;       }       if (!f) y += (1ll << (39 - i));       p = trie[p][0];     }     return y;   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     long long x = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       x ^= a[i];     }     long long ans = x;     string st =   ;     for (int i = 0; i < 40; i++) st +=  0 ;     build(st);     long long y = 0;     for (int i = 0; i < n; i++) {       x ^= a[i];       y ^= a[i];       string s =   ;       for (int j = 0; j < 40; j++) {         if (y & (1ll << j))           s =  1  + s;         else           s =  0  + s;       }       build(s);       ans = max(que(x), ans);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   int main() {     long long a, b;     scanf( %lld , &a);     scanf( %lld , &b);     while (a > 0 && b > 0 && (a >= 2 * b || b >= 2 * a))       if (a >= 2 * b)         a %= 2 * b;       else         b %= 2 * a;     printf( %lld %lld n , a, b);   }


#include <bits/stdc++.h>   using namespace std;   void boost() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long mod = 1000000007;   int tablica[2];   long long potega(long long base, long long pot) {     if (pot == 0) return 1;     if (pot == 1) return base;     if (pot % 2 == 0) {       long long res = potega(base, pot / 2);       return ((res * res) % mod);     } else       return ((potega(base, pot - 1) * base) % mod);   }   int bs(int pocz, int kon, int szu) {     int sr;     while (pocz < kon) {       sr = (pocz + kon) / 2;       if (tablica[sr] >= szu)         kon = sr;       else         pocz = sr + 1;     }     return pocz;   }   int n, k, a[1007], ile;   void reset_arrays() { ile = 0; }   void solve() {     reset_arrays();     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     for (int i = 1; i < n; i++) {       int pom = (k - a[i]) / a[0];       ile += pom;     }     printf( %d n , ile);   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long UNDEF = -1;   const long long INF = 1e18;   template <typename T>   inline bool chkmax(T &aa, T bb) {     return aa < bb ? aa = bb, true : false;   }   template <typename T>   inline bool chkmin(T &aa, T bb) {     return aa > bb ? aa = bb, true : false;   }   static char stdinBuffer[1024];   static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);   static const char *stdinPos = stdinDataEnd;   void readAhead(size_t amount) {     size_t remaining = stdinDataEnd - stdinPos;     if (remaining < amount) {       memmove(stdinBuffer, stdinPos, remaining);       size_t sz = fread(stdinBuffer + remaining, 1,                         sizeof(stdinBuffer) - remaining, stdin);       stdinPos = stdinBuffer;       stdinDataEnd = stdinBuffer + remaining + sz;       if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;     }   }   int readInt() {     readAhead(16);     int x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }   char readCh() {     readAhead(16);     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     char ans = *stdinPos;     ++stdinPos;     return ans;   }   inline int rri() {     char c;     while (c = getchar(), c <=    )       ;     bool sign = c ==  - ;     if (sign) {       c = getchar();     }     int res = c -  0 ;     while (c = getchar(), c >=  0  && c <=  9 ) {       res = res * 10 + (c -  0 );     }     return sign ? -res : res;   }   inline long long rrl() {     char c;     while (c = getchar(), c <=    )       ;     bool sign = c ==  - ;     if (sign) {       c = getchar();     }     long long res = c -  0 ;     while (c = getchar(), c >=  0  && c <=  9 ) {       res = res * 10 + (c -  0 );     }     return sign ? -res : res;   }   inline char rrc() {     char c;     while (c = getchar(), c <=    )       ;     return c;   }   inline int rrs(char *target) {     char c;     while (c = getchar(), c <=    )       ;     int idx = -1;     target[++idx] = c;     while (1) {       c = getchar();       if (c <=    ) {         target[++idx] =   0 ;         return idx;       }       target[++idx] = c;     }   }   vector<vector<int> > matrixUnit(long long n) {     vector<vector<int> > res(n, vector<int>(n));     for (long long i = 0; i < n; i++) res[i][i] = 1;     return res;   }   vector<vector<int> > matrixMul(const vector<vector<int> > &a,                                  const vector<vector<int> > &b) {     long long n = a.size();     long long m = a[0].size();     long long k = b[0].size();     vector<vector<int> > res(n, vector<int>(k));     for (long long i = 0; i < n; i++)       for (long long j = 0; j < k; j++)         for (long long p = 0; p < m; p++)           res[i][j] = (res[i][j] + (long long)a[i][p] * b[p][j]) % 1000000007LL;     return res;   }   void matrixMult(vector<vector<int> > &res, const vector<vector<int> > &a,                   const vector<vector<int> > &b) {     long long n = a.size();     long long m = a[0].size();     long long k = b[0].size();     for (long long i = 0; i < n; i++)       for (long long j = 0; j < k; j++) {         long long ans = 0;         for (long long p = 0; p < m; p++)           ans = (ans + (long long)a[i][p] * b[p][j]) % 1000000007LL;         res[i][j] = ans;       }   }   const int mn = 2004;   bitset<mn> g[mn];   bool bf(int n) {     vector<vector<int> > inp;     inp.resize(n);     for (int x = 0; x < n; x++) {       inp[x].resize(n);       for (int y = 0; y < n; y++) inp[x][y] = g[x][y];     }     vector<vector<int> > a = inp;     for (int k = 0; k < 500; k++) {       bool ok = 1;       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           if (a[i][j] == 0) {             ok = 0;             break;           }         }       if (ok) return 1;       a = matrixMul(a, inp);     }     return 0;   }   bitset<mn> h[mn];   bitset<mn> seen;   bool solve2(int n) {     queue<int> q;     for (int x = 0; x < n; x++) {       if (h[0][x]) q.push(x);     }     seen = h[0];     while (!q.empty()) {       int x = q.front();       q.pop();       for (int y = 0; y < n; y++) {         if ((!seen[y]) && h[x][y]) {           q.push(y);           seen[y] = true;         }       }     }     assert(seen.count() <= n);     return (int)seen.count() == n;   }   bool solve(int n) {     int spec = -1;     for (int k = 0; k < n; k++)       if (g[k][k]) spec = k;     assert(spec != -1);     for (int x = 0; x < n; x++)       for (int y = 0; y < n; y++) {         int sx = (x == spec || x == 0) ? x ^ spec : x;         int sy = (y == spec || y == 0) ? y ^ spec : y;         h[sx][sy] = g[x][y];       }     assert(h[0][0]);     if (!solve2(n)) return 0;     for (int x = 0; x < n; x++)       for (int y = 0; y < n; y++) {         g[x][y] = h[y][x];       }     for (int x = 0; x < n; x++) h[x] = g[x];     if (!solve2(n)) return 0;     return 1;   }   void test() {     srand(time(0) + clock() + rand());     for (int j = 0; j < 1000; j++) {       int n = (rand() % 6) + 1;       for (int x = 0; x < n; x++) {         h[x].reset();         g[x].reset();         for (int y = 0; y < n; y++) g[x][y] = rand() & 1;       }       int k = rand() % n;       g[k][k] = 1;       bool b = bf(n);       bool s = solve(n);       if (b != s) {         for (int x = 0; x < n; x++) {           for (int y = 0; y < n; y++) printf( %d , (int)g[x][y]);           printf(  n );         }         printf( b:%d s:%d n , b, s);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n = readInt();     for (int x = 0; x < n; x++)       for (int y = 0; y < n; y++) {         int t = readInt();         t = (t > 0) ? 1 : 0;         g[x][y] = t;       }     bool final = solve(n);     if (final)       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     scanf( %lld%lld , &n, &m);     long long t = m / 2;     if (t >= n) {       printf( 0 n );     } else {       if (m % 2 == 1) {         printf( %lld n , min(t, n - (t + 1) + 1));       } else {         printf( %lld n , min(t - 1, n - (t + 1) + 1));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 3e4 + 1;   long long n, m, d;   const long long K = 3e4 + 5;   const long long huge = 1e15;   long long dp[K][500];   long long a[K], ps[K];   long long solve(long long i, long long j) {     if (i >= M) return 0;     long long jj = j - (d - 250);     if (dp[i][jj] != -1) return dp[i][jj];     long long ans = 0;     if (j != 1)       ans = a[i] + max(solve(i + j, j),                        max(solve(i + j + 1, j + 1), solve(i + j - 1, j - 1)));     else       ans = a[i] + max(solve(i + j, j), solve(i + j + 1, j + 1));     return dp[i][jj] = ans;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n;     cin >> d;     while (n--) {       cin >> m;       a[m]++;     }     memset(dp, -1, sizeof dp);     cout << a[0] + solve(d, d);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     for (int i = 1; i < n - 1; i++)       if (s[i] == s[i - 1] && s[i] == s[i + 1]) {         if (s[i] ==  a )           s[i] =  b ;         else           s[i] =  a ;       }     for (int i = 1; i < n; i++)       if (s[i] == s[i - 1]) {         if (s[i] ==  a ) {           if (i != n - 1 && s[i + 1] !=  b )             s[i] =  b ;           else             s[i] =  c ;         } else if (s[i + 1] !=  a )           s[i] =  a ;         else if (s[i] !=  b )           s[i] =  b ;         else           s[i] =  c ;       }     cout << s;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     if (n == 1) {       cout << 1;       exit(0);     }     cout << fixed << setprecision(12)          << 1.0 / n + (1.0 * (n - 1)) / n * (1.0 * (m - 1)) / (m * n - 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > p;     int a[n + 1], b[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) {       if (a[i] != b[i]) {         for (int j = i + 1; j <= n; j++) {           if (a[i] == b[j]) {             for (int k = j; k > i; k--) {               p.push_back(make_pair(k - 1, k));               swap(b[k], b[k - 1]);             }             break;           }         }       }     }     cout << p.size() << endl;     for (int i = 0; i < p.size(); i++)       cout << p[i].first <<     << p[i].second << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1002], b[1002], n, m;     while (cin >> n >> m) {       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       double be = m;       bool flag = 0;       for (int i = n - 1; i >= 0; i--) {         be = be * b[(i + 1) % n] / (b[(i + 1) % n] - 1);         if (be > 1000000000) {           flag = 1;           break;         }         be = be * a[i] / (a[i] - 1);       }       if (flag)         cout << -1 << endl;       else         cout << fixed << setprecision(10) << be - m << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     a %= 1000000007;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;       b >>= 1;     }     return res;   }   long long int modinv(long long int p) { return power(p, 1000000007 - 2); }   vector<long long int> arr[200000];   long long int dp[100005][2] = {0};   void dfs(long long int s, long long int p, long long int a[]) {     if (a[s] == 0) {       long long int su = 1;       dp[s][1] = 0;       for (auto it : arr[s]) {         if (it != p) {           dfs(it, s, a);           su *= (dp[it][0] + dp[it][1]);           su %= 1000000007;         }       }       dp[s][0] = su % 1000000007;       for (auto it : arr[s]) {         if (it != p) {           if (dp[it][0] + dp[it][1] > 0) {             dp[s][1] += (dp[it][1] *                          ((su * modinv(dp[it][0] + dp[it][1])) % 1000000007)) %                         1000000007;             dp[s][1] %= 1000000007;           }         }       }     } else {       dp[s][0] = 0;       dp[s][1] = 1;       for (auto it : arr[s]) {         if (it != p) {           dfs(it, s, a);           dp[s][1] *= (dp[it][0] + dp[it][1]) % 1000000007;           dp[s][1] %= 1000000007;         }       }     }   }   int main() {     long long int n;     cin >> n;     long long int q;     for (long long int x = 1; x < n; x++) {       cin >> q;       arr[q].push_back(x);       arr[x].push_back(q);     }     long long int a[n];     for (int x = 0; x < n; x++) {       cin >> a[x];     }     dfs(0, -1, a);     cout << dp[0][1] % 1000000007 <<   n ;   }


#include <bits/stdc++.h>   const int N = 2e4 + 42, M = 1e6 + 61, LN = 16;   struct edge {     int to, next, w;   } e[M << 1];   int head[M], cnt = 1, nc;   void addedge(int x, int y, int z) {     if (!y) return;     e[++cnt] = (edge){y, x[head], z}, x[head] = cnt;     e[++cnt] = (edge){x, y[head], 0}, y[head] = cnt;   }   int fa[N][LN], pt[N][LN], dep[N], eid[N];   std::vector<std::pair<int, int> > g[N];   void dfs(int x, int p) {     x[fa][0] = p, x[pt][0] = ++nc;     addedge(nc, x, 1e9);     for (int i = 1; i < LN; i++) {       x[fa][i] = x[fa][i - 1][fa][i - 1], x[pt][i] = ++nc;       addedge(nc, x[pt][i - 1], 1e9), addedge(nc, x[fa][i - 1][pt][i - 1], 1e9);     }     for (auto [nx, id] : x[g])       if (nx != p) nx[eid] = id, nx[dep] = x[dep] + 1, dfs(nx, x);   }   int lca(int x, int y) {     if (x[dep] < y[dep]) std::swap(x, y);     for (int i = LN - 1; i >= 0; i--)       if (x[fa][i][dep] >= y[dep]) x = x[fa][i];     if (x == y) return x;     for (int i = LN - 1; i >= 0; i--)       if (x[fa][i] != y[fa][i]) x = x[fa][i], y = y[fa][i];     return x[fa][0];   }   int get(int x, int k) {     for (int i = 0; i < LN; i++)       if ((k >> i) & 1) x = x[fa][i];     return x;   }   void link(int p, int x, int y) {     if (x == y) return;     int sub = x[dep] - y[dep];     int k = 31 - __builtin_clz(sub);     addedge(p, x[pt][k], 1e9);     addedge(p, get(x, sub - (1 << k))[pt][k], 1e9);   }   int lv[M], cur[M];   bool bfs(int s, int t) {     memset(lv, 0, sizeof lv);     std::queue<int> q;     for (s[lv] = 1, q.push(s); !q.empty(); q.pop())       for (int x = q.front(), i = x[cur] = x[head], nx; i; i = e[i].next)         if (!(nx = e[i].to)[lv] && e[i].w) nx[lv] = x[lv] + 1, q.push(nx);     return t[lv];   }   int dfs(int s, int t, int f) {     if (s == t || !f) return f;     int r = 0, tt;     for (int &i = s[cur], nx; i; i = e[i].next)       if ((nx = e[i].to)[lv] == s[lv] + 1 &&           (tt = dfs(nx, t, std::min(f, (int)e[i].w)))) {         e[i].w -= tt, e[i ^ 1].w += tt, r += tt, f -= tt;         if (!f) return r;       }     if (f) s[lv] = 0;     return r;   }   int dinic(int s, int t) {     int r = 0;     while (bfs(s, t)) r += dfs(s, t, 1e9);     return r;   }   bool vis[M];   void dfs2(int x) {     x[vis] = true;     for (int i = x[head], nx; i; i = e[i].next)       if (e[i].w && !(nx = e[i].to)[vis]) dfs2(nx);   }   std::vector<int> v1, v2;   int n, m, S, T, c_pt[N];   int main() {     scanf( %d%d , &n, &m), nc = n;     for (int i = 1, x, y; i < n; i++) {       scanf( %d%d , &x, &y);       x[g].push_back({y, i});       y[g].push_back({x, i});     }     dep[1] = 1, dfs(1, 0);     S = ++nc, T = ++nc;     for (int i = 1; i <= n; i++) addedge(i, T, 1);     for (int i = 1, x, y; i <= m; i++) {       scanf( %d%d , &x, &y);       int l = lca(x, y), p = ++nc;       c_pt[i] = p;       addedge(S, p, 1);       link(p, x, l), link(p, y, l);     }     printf( %d n , dinic(S, T));     dfs2(S);     for (int i = 1; i <= m; i++)       if (!c_pt[i][vis]) v1.push_back(i);     for (int i = 2; i <= n; i++)       if (i[vis]) v2.push_back(eid[i]);     printf( %lu , v1.size());     for (int i : v1) printf(  %d , i);     puts(  );     printf( %lu , v2.size());     for (int i : v2) printf(  %d , i);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   const double one = 1.0;   const double PI = 3.14159265;   const long long maxn = 2e3 + 10;   const long long maxx = 1e6 + 10;   const long double eps = 1e-14;   const long long max_len = 1e6 + 1;   const long long mod1 = 1000000007;   const long long mod2 = 998244353;   long long dp[maxn][maxn];   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> vl(n + 2);     for (long long i = 1; i < long long(n + 1); i++) cin >> vl[i];     for (long long i = 0; i < long long(n + 1); i++) {       for (long long j = 0; j < long long(n + 1); j++) dp[i][j] = 0;     }     for (long long i = 1; i < long long(n + 1); i++) {       for (long long j = 0; j < long long(i + 1); j++) {         dp[i][j] = max(dp[i][j], dp[i - 1][j] + (i - j == vl[i]));         if (j > 0) dp[i][j] = max(dp[i - 1][j - 1], dp[i][j]);       }     }     long long ans = 1000000000000000000;     for (long long j = 0; j < long long(n + 1); j++) {       if (dp[n][j] >= k) ans = min(ans, j);     }     if (ans >= 1000000000000000000) ans = -1;     cout << ans << endl;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     long long t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   int a, b, k;   int main() {     scanf( %d%d%d , &b, &a, &k);     if (b + k < a) {       printf( %.12f n , 0.0f);       return 0;     }     double ans = 1;     for (int i = 0; i <= k; i++) {       ans *= (a - i);       ans /= (b + 1 + i);     }     ans = 1 - ans;     printf( %.12f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SZ = (int)3e7 + 10;   int cnt[SZ];   int n[3], t[3], sum[3];   int main() {     int k;     cin >> k;     for (int i = 0; i < 3; i++) cin >> n[i];     for (int i = 0; i < 3; i++) cin >> t[i];     for (int i = 0; i < 3; i++) sum[i] = 0;     for (int tme = 0;; tme++) {       int mn = k;       for (int s = 0; s < 3; s++) {         mn = min(mn, n[s] - sum[s]);       }       cnt[tme] = mn;       k -= mn;       if (k == 0) {         printf( %d , tme + t[0] + t[1] + t[2]);         return 0;       }       for (int s = 0; s < 3; s++) {         sum[s] += mn;         if (tme - t[s] + 1 >= 0) sum[s] -= cnt[tme - t[s] + 1];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long double ans, eps = 1e-10, l, v1, v2;   bool solve(long double mid) {     int x = (n + k - 1) / k;     long double tl = mid, pos = l;     while (x--) {       if (tl < 0) return 0;       long double trav = (v2 * v1 * tl - v2 * pos) / (v1 - v2);       if (trav > pos) return 0;       long double oldTime = tl;       tl -= trav / v2 + (trav - v1 * trav / v2) / (v1 + v2);       pos -= v1 * (oldTime - tl);     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> l >> v1 >> v2 >> k;     double long hi = 1e10, lo = 0;     while (hi - lo >= eps) {       long double mid = (hi + lo) / 2;       if (solve(mid)) {         ans = mid;         hi = mid - eps;       } else         lo = mid + eps;     }     cout << setprecision(12) << ans;     solve(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[212345], s1[212345], s2[212345], pos1[212345], pos2[212345], n;   vector<pair<int, int> > res;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       s1[i] = s1[i - 1] + (a[i] == 1);       s2[i] = s2[i - 1] + (a[i] == 2);     }     for (int i = n; i >= 1; i--) {       pos1[s1[i]] = i;       pos2[s2[i]] = i;     }     for (int i = 1; i <= n; i++) pos1[s1[n] + i] = pos2[s2[n] + i] = n + 1;     for (int t = 1; t <= n; t++) {       int curPos = 0;       int win1 = 0;       int win2 = 0;       while (curPos < n) {         curPos = min(pos1[s1[curPos] + t], pos2[s2[curPos] + t]);         if (curPos <= n) {           if (a[curPos] == 1)             win1++;           else             win2++;         }       }       if (curPos == n && win1 != win2 && ((win1 > win2) == (a[curPos] == 1)))         res.push_back(make_pair(max(win1, win2), t));     }     sort(res.begin(), res.end());     cout << (int)res.size() << endl;     for (int i = 0; i < (int)res.size(); i++)       cout << res[i].first <<     << res[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long d = 0;     for (int i = 9; n > 0; i *= 10) {       d += n;       n -= i;     }     cout << d << endl;   }


#include <bits/stdc++.h>   using namespace std;   namespace FGF {   const int N = 1e5 + 5, mo = 1e9 + 7, inv2 = (mo + 1) / 2;   int a[N], b[N], pre[N], lst[N], nxt[N], sum[N << 2][4], ta[N << 2][2], n, st[N],       tp, mi[N], mx[N], ans, cnt[N];   void pushtag(int ro, int l, int r, int x, int o) {     sum[ro][3] = 1ll * x * sum[ro][o ^ 1] % mo;     sum[ro][o] = 1ll * (r - l + 1) * x % mo;     ta[ro][o] = x;     if (!o) sum[ro][2] = 1ll * (r + l) * (r - l + 1) % mo * inv2 % mo * x % mo;   }   void pushdown(int ro, int l, int r) {     for (int i = 0; i <= 1; i++)       if (ta[ro][i])         pushtag(ro << 1, l, ((l + r) >> 1), ta[ro][i], i),             pushtag(ro << 1 | 1, ((l + r) >> 1) + 1, r, ta[ro][i], i),             ta[ro][i] = 0;   }   void pushup(int ro) {     for (int i = 0; i < 4; i++)       sum[ro][i] = (sum[ro << 1][i] + sum[ro << 1 | 1][i]) % mo;   }   void updat(int ro, int l, int r, int L, int R, int x, int o) {     if (L <= l && r <= R) return pushtag(ro, l, r, x, o);     pushdown(ro, l, r);     if (L <= ((l + r) >> 1)) updat(ro << 1, l, ((l + r) >> 1), L, R, x, o);     if (R > ((l + r) >> 1)) updat(ro << 1 | 1, ((l + r) >> 1) + 1, r, L, R, x, o);     pushup(ro);   }   int query(int ro, int l, int r, int L, int R, int o) {     if (L <= l && r <= R) return sum[ro][o];     pushdown(ro, l, r);     return ((L <= ((l + r) >> 1) ? query(ro << 1, l, ((l + r) >> 1), L, R, o)                                  : 0) +             (R > ((l + r) >> 1)                  ? query(ro << 1 | 1, ((l + r) >> 1) + 1, r, L, R, o)                  : 0)) %            mo;   }   void work() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), b[i] = a[i];     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;     for (int i = 1; i <= n; i++) pre[i] = lst[a[i]] + 1, lst[a[i]] = i;     for (int i = n; i; i--) lst[i] = n + 1;     for (int i = n; i; i--) nxt[i] = lst[a[i]] - 1, lst[a[i]] = i;     for (int i = n; i; i--) {       while (tp && pre[i] > pre[st[tp]]) tp--;       mx[i] = tp ? st[tp] - 1 : n, st[++tp] = i;     }     tp = 0;     for (int i = n; i; i--) {       while (tp && nxt[i] < nxt[st[tp]]) tp--;       mi[i] = tp ? st[tp] - 1 : n, st[++tp] = i;     }     for (int i = n, j = n; i; i--) {       updat(1, 1, n, i, mx[i], pre[i], 0), updat(1, 1, n, i, mi[i], nxt[i], 1);       cnt[a[i]]++;       while (cnt[a[i]] > 1) cnt[a[j]]--, j--;       ans = (ans + 1ll * i * query(1, 1, n, i, j, 1) % mo +              query(1, 1, n, i, j, 2) -              1ll * i * (i + j) % mo * (j - i + 1) % mo * inv2 % mo -              query(1, 1, n, i, j, 3)) %             mo;     }     printf( %d n , (ans + mo) % mo);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = 3.14159265;   const double E = 2.718281828459;   const double EPS = 1e-8;   const int M = 2e5 + 5;   long long n, A;   long long a[M];   int main() {     while (~scanf( %I64d %I64d , &n, &A)) {       long long sumb = 0;       for (int i = 0; i < n; i++) {         scanf( %I64d , a + i);         sumb += a[i];       }       long long minb = n - 1;       bool first = true;       for (int i = 0; i < n; i++) {         long long cnt = 0;         long long x = A - minb;         if (a[i] > x) cnt += a[i] - x;         long long y = A - (sumb - a[i]);         if (y > 0) cnt += y - 1;         if (first) {           printf( %I64d , cnt);           first = false;         } else           printf(  %I64d , cnt);       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int v;     int id;   } node[110];   int t[110];   bool cmp(Node x, Node y) { return x.v > y.v; }   int main() {     int n, w;     cin.sync_with_stdio(false);     while (cin >> n >> w) {       for (int i = 0; i < n; i++) {         cin >> node[i].v;         node[i].id = i;       }       bool flag = true;       for (int i = 0; i < n; i++) {         if (node[i].v & 1)           t[i] = node[i].v / 2 + 1, w -= t[i];         else           t[i] = node[i].v / 2, w -= t[i];         if (w < 0) {           flag = false;           printf( -1 n );           break;         }       }       if (!flag) continue;       sort(node, node + n, cmp);       for (int i = 0; i < n; i++) {         if (w > (node[i].v - t[node[i].id])) {           int d = node[i].v - t[node[i].id];           t[node[i].id] = node[i].v;           w = w - d;         } else {           t[node[i].id] += w;           break;         }       }       for (int i = 0; i < n - 1; i++) cout << t[i] <<    ;       cout << t[n - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 2;   int n;   struct Node {     int l, r;   };   Node a[maxn];   bool cmp(Node x, Node y) {     if (x.r == y.r) return x.l < y.l;     return x.r < y.r;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, w;       scanf( %d%d , &x, &w);       a[i].l = x - w;       a[i].r = x + w;     }     sort(a + 1, a + n + 1, cmp);     int max = a[1].r, ans = 1;     for (int i = 2; i <= n; i++)       if (a[i].l >= max) {         ans++;         max = a[i].r;       }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned int dp[100100];   char s[100100];   int main() {     unsigned int n;     cin >> n;     if (n & 1) {       return !printf( 0 );     }     scanf( %s , s + 1);     int m = n / 2;     dp[0] = 1;     for (int i = 1; i <= n; i++) {       if (s[i] ==  ? ) {         for (int j = i / 2; j >= max(1, i - m); j--) dp[j] += dp[j - 1];       }     }     for (int i = 1; i <= n; i++) {       if (s[i] ==  ? ) continue;       m--;     }     for (int i = 1; i <= m; i++) dp[n / 2] *= 25;     cout << dp[n / 2] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int modInverse(int a, int m);   int gcd(int a, int b);   int power(int x, unsigned int y, unsigned int m);   void pairsort(int a[], int b[], int n);   int logint(int x, int y);   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int power(int x, unsigned int y, unsigned int m) {     if (y == 0) return 1;     int p = power(x, y / 2, m) % m;     p = (p * p) % m;     return (y % 2 == 0) ? p : (x * p) % m;   }   int modInverse(int a, int m) {     int m0 = m;     int y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       int q = a / m;       int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   void pairsort(int a[], int b[], int n) {     pair<int, int> pairt[n];     for (int i = 0; i < n; i++) {       pairt[i].first = a[i];       pairt[i].second = b[i];     }     sort(pairt, pairt + n);     for (int i = 0; i < n; i++) {       a[i] = pairt[i].first;       b[i] = pairt[i].second;     }   }   int logint(int x, int y) {     int ans = 0;     int a = 1;     for (int i = 0; i < x; i++) {       if (x <= a) {         return ans;       }       ans++;       a *= y;     }     return -1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int mink;     int k = 0;     int a[n];     for (int i = 0; i < n; i++) {       int t;       cin >> t;       a[i] = t;       if (i == 0)         mink = t;       else         mink = min(mink, t);     }     for (int i = 0; i < n; i++) {       int t = a[i];       if (t == mink) k++;     }     if (k > (n / 2)) {       cout <<  Bob ;     } else {       cout <<  Alice ;     }     return 0;   }