#include <bits/stdc++.h>   using namespace std;   namespace IO {   inline bool read() { return true; }   template <class T1, class... T2>   bool read(T1 &a, T2 &...rest) {     return (cin >> a) ? read(rest...) : 0;   }   template <class... T>   bool read(char *a, T &...rest) {     return (cin >> a) ? read(rest...) : 0;   }   template <class... T>   bool read(char *a, char *b, T &...rest) {     return (cin >> a >> b) ? read(rest...) : 0;   }   template <class... T>   bool read(char *a, char *b, char *c, T &...rest) {     return (cin >> a >> b >> c) ? read(rest...) : 0;   }   void put() { cout <<   n ; }   template <class T1, class... T2>   void put(const T1 num, const T2... rest) {     cout << num <<    ;     put(rest...);   }   void yes() { put( YES ); }   void no() { put( NO ); }   void ff() { cout.flush(); }   }  // namespace IO   using namespace IO;   using db = double;   using vi = vector<int>;   using pii = pair<int, int>;   using ll = long long;   using cp = complex<double>;   const int mod = 998244353, inv2 = (mod + 1) / 2;   const int maxn = 1e3 + 10;   const int inf = 1e9 + 3;   short d[41][maxn][maxn];   ll n, m, k;   void prepare() {}   short a[maxn][maxn];   queue<pair<short, short> > q[41];   vector<pair<short, short> > c[41];   short fff = 2e4;   short dx[4] = {1, -1, 0, 0};   short dy[4] = {0, 0, 1, -1};   void bfs(int k, short (&d)[maxn][maxn], queue<pair<short, short> > &q) {     vi vis(44);     vis[k] = 1;     while (!q.empty()) {       auto x = q.front().first, y = q.front().second;       q.pop();       if (!vis[a[x][y]])         for (auto g : c[a[x][y]]) {           auto x1 = g.first, y1 = g.second;           if (d[x1][y1] == fff) {             d[x1][y1] = d[x][y] + 1;             q.push(make_pair(x1, y1));           }         }       vis[a[x][y]] = 1;       for (int i = 0; i < 4; i++) {         auto xx = x + dx[i], yy = y + dy[i];         if (d[xx][yy] != fff) continue;         d[xx][yy] = d[x][y] + 1;         q.push(make_pair(xx, yy));       }     }   }   void Solve(int cas = 1) {     read(n, m, k);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int q = 1; q <= k; q++) {           d[q][i][j] = fff;         }         read(a[i][j]);         c[a[i][j]].emplace_back(i, j);         d[a[i][j]][i][j] = 0;         q[a[i][j]].push(make_pair(i, j));       }     }     for (int i = 1; i <= k; i++) {       bfs(1, d[i], q[i]);     }     int q;     read(q);     while (q--) {       short r1, c1, r2, c2;       read(r1, c1, r2, c2);       int min1 = abs(r1 - r2) + abs(c1 - c2);       for (int i = 1; i <= k; i++) {         min1 = min(min1, d[i][r1][c1] + 1 + d[i][r2][c2]);       }       put(min1);     }   }   void Solvem() {     int T;     read(T);     for (int i = 1; i <= T; i++) Solve(i);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     prepare();     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long l1, l2, r1, r2, q;   long long p1, p2;   int main() {     scanf( %lld , &q);     for (int i = 1; i <= q; i++) {       scanf( %lld%lld%lld%lld , &l1, &r1, &l2, &r2);       p1 = l1;       p2 = l2;       if (p1 == p2) p2 = r2;       printf( %lld %lld n , p1, p2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) { return (!y ? x : gcd(y, x % y)); }   long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }   void file() {}   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     file();   }   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   const double eps = 1e-9;   const int mod = 1e9 + 7;   const int N = 1e5 + 5;   int n;   string s;   int dp[N][10][2];   int upd(int x) {     int sum = 0;     while (x) sum += x % 10, x /= 10;     return sum;   }   int solve(int idx, int sum, bool ok) {     if (idx == n) {       if (sum % 3 == 0) return 0;       return 1e9;     }     int &ret = dp[idx][sum][ok];     if (~ret) return ret;     ret = solve(idx + 1, sum, ok) + 1;     if (ok || s[idx] !=  0 )       ret = min(ret, solve(idx + 1, upd(sum + s[idx] - 48), 1));     return ret;   }   void solve2(int idx, int sum, bool ok) {     if (idx == n) {       return;     }     int &ret = dp[idx][sum][ok];     if (ret == solve(idx + 1, sum, ok) + 1) {       solve2(idx + 1, sum, ok);       return;     }     cout << s[idx];     solve2(idx + 1, upd(sum + s[idx] - 48), 1);     return;   }   int main() {     fast();     memset((dp), -1, sizeof(dp));     cin >> s;     n = (int)s.size();     bool ok = 0;     for (int i = 0; i < (int)s.size(); i++) {       ok |= s[i] ==  0 ;     }     int x = solve(0, 0, 0);     if (x == n) {       if (!ok)         cout << -1;       else         cout << 0;       return 0;     }     solve2(0, 0, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double x[111111];   double sX, sY;   int n, K;   double Solve(int l, int r) {     if (l > r) return 0;     return min(hypot(x[l] - sX, sY), hypot(x[r] - sX, sY)) + x[r] - x[l];   }   int main() {     scanf( %d%d , &n, &K);     K--;     for (int i = 0; i < n; ++i) scanf( %lf , x + i);     scanf( %lf%lf , &sX, &sY);     double ans = 1e100;     if (K == n) {       sort(x, x + n);       ans = Solve(0, n - 1);       return printf( %.9f n , ans), 0;     }     K = x[K];     sort(x, x + n);     K = lower_bound(x, x + n, K) - x;     for (int l = 0; l <= K; l++) {       double a = x[K] - x[l], b = x[n - 1] - x[K], t;       ans = min(ans, 2 * b + a + hypot(x[l] - sX, sY) + Solve(0, l - 1));       ans = min(ans, 2 * a + b + hypot(x[n - 1] - sX, sY) + Solve(0, l - 1));     }     for (int r = K; r < n; r++) {       double a = x[K] - x[0], b = x[r] - x[K], t;       ans = min(ans, 2 * b + a + hypot(x[0] - sX, sY) + Solve(r + 1, n - 1));       ans = min(ans, 2 * a + b + hypot(x[r] - sX, sY) + Solve(r + 1, n - 1));     }     printf( %.9f n , ans);     return 0;   }


#include <bits/stdc++.h>   const int mod = 998244353;   using namespace std;   int a[200010], b[200010];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int x;     for (int i = 1; i <= n; i++) cin >> x, b[i] = a[i] - x;     sort(b + 1, b + n + 1);     long long ans = 0;     for (int i = 1; i <= n - 1; i++) {       if (b[i] > 0)         ans += n - i;       else {         int j = upper_bound(b + 1, b + n + 1, -b[i]) - b;         ans += max(0, n - j + 1);       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void swapll(long long *a, long long *b) {     long long tmp = *a;     *a = *b;     *b = tmp;   }   void swapc(char *a, char *b) {     char tmp = *a;     *a = *b;     *b = tmp;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, t;     cin >> n;     cin >> t;     vector<long long> v(n, 0);     for (long long i = 0; i < n; i++) cin >> v[i];     ;     long long count = 0;     for (long long i = 0; i < n; i++) {       t -= (86400 - v[i]);       count++;       if (t <= 0) {         break;       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0, y;     int a[100];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       x = max(x, a[i]);     }     y = a[n - 1];     printf( %d , y ^ x);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 250;   int t, a[N];   void read_input() {     for (int i = 0; i < N; i++) cin >> a[i];   }   void solve() {     int sum = 0;     for (int i = 0; i < N; i++) sum += a[i] * a[i];     double P = sqrt(1. * sum / N);     for (int i = 0; i < N; i++)       if (abs(a[i]) > 2 * P) {         cout <<  poisson n ;         return;       }     cout <<  uniform n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     for (cin >> t; t--; read_input(), solve())       ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (j == 1 || i == 1)             cout <<  B ;           else {             cout <<  W ;           }         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   long long s[101000], d[101000], ad[101000];   int find(int l, int r, long long v) {     int re = 0;     while (l <= r) {       int mid = (l + r) / 2;       if (d[mid] <= v) {         re = max(re, mid);         l = mid + 1;       } else {         r = mid - 1;       }     }     return re;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &s[i]);     sort(s + 1, s + n + 1);     for (int i = 1; i < n; i++) {       d[i] = s[i + 1] - s[i];     }     d[0] = 0;     d[n] = 1000000000000000010LL;     sort(d + 1, d + n + 1);     for (int i = 1; i <= n; i++) ad[i] = ad[i - 1] + d[i];     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       long long l, r;       scanf( %I64d%I64d , &l, &r);       long long len = r - l;       int k = find(0, n, len);       printf( %I64d  , (len + 1) * (n - k) + ad[k]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1E6 + 10;   int n, a[maxn][20], b[maxn][20], c[maxn], LOG[maxn];   bool Judge(int l, int r) {     int len = LOG[r - l + 1];     int A = 100 * max(a[l][len], a[r - (1 << len) + 1][len]);     int B = min(b[l][len], b[r - (1 << len) + 1][len]);     return A < B;   }   int main() {     int k;     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %d , &a[i][0]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i][0]);     for (int j = 1; j < 20; j++)       for (int i = 1; i <= n; i++) {         if (i + (1 << j - 1) > n) break;         a[i][j] = max(a[i][j - 1], a[i + (1 << (j - 1))][j - 1]);         b[i][j] = min(b[i][j - 1], b[i + (1 << (j - 1))][j - 1]);       }     int now = 0, sum = 1;     for (int i = 1; i <= n; i++) {       if (sum >= i)         LOG[i] = now - 1;       else {         sum <<= 1;         ++now;         LOG[i] = now - 1;       }     }     LOG[1] = 0;     for (int i = 1; i <= n; i++) {       int L, R;       L = i;       R = n;       while (R - L > 1) {         int mid = (L + R) >> 1;         if (Judge(i, mid))           L = mid;         else           R = mid;       }       int len = LOG[L - i + 1];       int A = 100 * max(a[i][len], a[L - (1 << len) + 1][len]);       int B = min(b[i][len], b[L - (1 << len) + 1][len]);       c[i] = min(A, B);       len = LOG[R - i + 1];       A = 100 * max(a[i][len], a[R - (1 << len) + 1][len]);       B = min(b[i][len], b[R - (1 << len) + 1][len]);       c[i] = max(c[i], min(A, B));     }     sort(c + 1, c + n + 1);     double ans = 0;     double N = n - 1;     double M = k - 1;     double v = (double)(k) / (double)(n);     for (int i = 1; i <= n; i++) {       if (n - i < k - 1) break;       ans += v * (double)(c[i]);       v = v / N * (N - M);       N -= 1.00;     }     printf( %.10f , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool found;   int n, x, nums[1000], smaller, larger, eq;   void Naive() {     int median = ((n + 1) / 2);     sort(nums, nums + n);     if (nums[--median] == x) {       printf( 0 );       return;     }     if (found) {       for (int i = 0; i < n && nums[i] <= x; i++)         if (x == nums[i] && abs(smaller - median) > abs(i - median)) smaller = i;     }     larger = n - smaller - found;   }   void Smart() {     larger = n - smaller - eq;     if (found) {       eq--;       int diff = abs(smaller - larger);       if (larger <= smaller) {         if (diff <= eq) {           larger = smaller;           eq -= diff;           larger += eq / 2 + (eq % 2);           smaller += eq / 2;         } else {           larger += eq;           eq = 0;         }       } else {         if (diff <= eq) {           smaller = larger;           eq -= diff;           larger += eq / 2 + (eq % 2);           smaller += eq / 2;         } else {           smaller += eq;           eq = 0;         }       }     }   }   void Greedy() {     Smart();     printf( %d , !found + abs(smaller - larger) - (larger > smaller));   }   int main() {     found = false;     scanf( %d %d , &n, &x);     for (int i = 0; i < n; i++) {       scanf( %d , &nums[i]);       smaller += (nums[i] < x);       eq += (nums[i] == x);       found |= (nums[i] == x);     }     Greedy();   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 5050;   const int MM = 27272;   int a[MM], b[MM];   vector<int> adj[NN];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , a + i, b + i);       adj[a[i]].push_back(b[i]);     }     int mx = 0;     for (int i = 1; i <= n; i++) {       mx = max(mx, (int)adj[i].size());       sort(adj[i].begin(), adj[i].end());     }     for (int i = 1; i <= n; i++) {       int ans = 0;       for (int j = 1; j <= n; j++)         if (!adj[j].empty()) {           int it = lower_bound(adj[j].begin(), adj[j].end(), j) - adj[j].begin();           if (it == adj[j].size()) it = 0;           int ed = adj[j][it];           if (ed < j) ed += n;           if (j < i) ed += n;           int sz = adj[j].size();           ans = max(ans, (sz - 1) * n + ed - i);         }       cout << ans <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f(long long x) {     long long ans = x;     while (ans) {       x *= 10;       x += (ans % 10);       ans /= 10;     }     return x;   }   int main() {     long long k, p;     cin >> k;     cin >> p;     long long sum = 0;     for (long long i = 1; i <= k; i++) sum += f(i);     sum %= p;     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;      using ll = long long;   using ld = long double;      int a[25][50005];      const int MOD = 998244353;      int add(int a, int b){       a += b;       if(a >= MOD) a -= MOD;       return a;   }      int mul(int a, int b){       return (1LL*a*b)%MOD;      }      int pw(int a, int b){       if(b == 0) return 1;       int res = pw(a, b/2);       res = mul(res, res);       if(b%2) res = mul(res, a);       return res;   }      int main(){       ios_base::sync_with_stdio(false), cin.tie(0);       cout.precision(10);       cout << fixed;          int n, m;       cin >> n >> m;       for(int i=1; i<=n; i++){           for(int j=1; j<=m; j++){               cin >> a[i][j];               a[i][j]--;           }       }       int res = 0;       for(int j=1; j<=m; j++){           vector <int> vec;           for(int i=1; i<=n; i++){               vec.push_back(a[i][j]);           }           sort(vec.begin(), vec.end());           int ways = 1;           for(int g=0; g<vec.size(); g++){               ways = mul(ways, vec[g] - g);           }           if(ways == 0) continue;           res = add(res, ways);       }       int fact = 1;       for(int i=1; i<=n; i++) fact = mul(fact, i);       int p = add(mul(fact, m), MOD - res);       p = mul(p, pw(fact, MOD-2));       cout << p;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, cnt;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     cin >> n >> x;     for (int i = 1; i <= n; i++) {       if (x % i == 0 && x / i <= n) {         cnt++;       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int num;     cin >> num;     if (num <= 9) {       cout << num << endl;     } else if (10 < num && num <= 189) {       num = num - 9;       int tmp = num / 2;       tmp = 9 + tmp + num % 2;       if (num % 2)         cout << tmp / 10 << endl;       else         cout << tmp % 10 << endl;     } else if (190 <= num) {       num = num - 189;       int tmp = num / 3;       if (num % 3 != 0)         tmp = 100 + tmp;       else         tmp = 99 + tmp;       if (num % 3 == 0) {         cout << tmp % 10 << endl;       } else if (num % 3 == 1) {         cout << tmp / 100 << endl;       } else {         tmp = tmp / 10;         tmp = tmp % 10;         cout << tmp << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, ans1 = 0, ans2 = 0;     cin >> n;     vector<int> c(n);     for (int i = 0; i < n; i++) cin >> c[i];     cin >> a >> b;     if (a > b) swap(a, b);     a--;     b--;     for (int i = a; i < b; i++) {       ans1 += c[i];     }     for (int i = 0; i < a; i++) {       ans2 += c[i];     }     for (int i = b; i < n; i++) {       ans2 += c[i];     }     cout << min(ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   const int MOD = 1e9 + 7;   vector<int> g[N + N];   int mat[N][N], p[N + N], sub[N + N], vis[N + N];   int ans[N + N], instack[N + N], go = true, ct = 0;   vector<pair<int, int>> extime;   void putNumbers(int node) {     vis[node] = 1;     instack[node] = true;     ct++;     for (auto it : g[node]) {       if (!vis[it]) {         putNumbers(it);       } else if (instack[it])         go = false;     }     instack[node] = false;     extime.push_back({ct, node});     ct++;   }   void getAns(int node) {     vis[node] = 1;     ans[node] = max(ans[node], 1);     for (auto it : g[node])       if (!vis[it]) {         ans[it] = max(ans[it], ans[node] + 1);       }   }   int root(int u) {     while (p[u] != u) {       p[u] = p[p[u]];       u = p[u];     }     return u;   }   void merge(int uu, int vv) {     int u = root(uu), v = root(vv);     if (u == v) return;     if (sub[u] < sub[v]) swap(u, v);     p[v] = u;     sub[u] += sub[v];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, i, j;     cin >> n >> m;     for (i = 1; i <= n + m; i++) {       p[i] = i;       sub[i] = 1;     }     for (i = 1; i <= n; i++) {       string s;       cin >> s;       for (j = 0; j < m; j++) {         if (s[j] ==  < )           mat[i][j + 1] = -1;         else if (s[j] ==  = ) {           merge(i, n + j + 1);           mat[i][j + 1] = 0;         } else           mat[i][j + 1] = 1;       }     }     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         int u = root(i), v = root(n + j);         if (mat[i][j] < 0) {           if (u == v) {             cout <<  No n ;             return 0;           }           g[u].push_back(v);         }         if (mat[i][j] > 0) {           if (u == v) {             cout <<  No n ;             return 0;           }           g[v].push_back(u);         }       }     for (i = 1; i <= n + m; i++)       if (!vis[i] && p[i] == i) {         putNumbers(i);         if (!go) {           cout <<  No n ;           return 0;         }       }     sort(extime.begin(), extime.end());     reverse(extime.begin(), extime.end());     memset(vis, 0, sizeof(vis));     for (auto it : extime)       if (!vis[it.second]) {         getAns(it.second);       }     cout <<  Yes n ;     for (i = 1; i <= n + m; i++) {       cout << ans[root(i)] <<    ;       if (i == n) cout <<   n ;     }     cout <<   n ;     return 0;   }


#include<iostream>   #include<string>   #include<cstring>   #include<cmath>   #include<algorithm>   #include<queue>   #include<iomanip>   #include<map>   #include<cstdio>   #include<stack>   #include<set>   using namespace std;   #define endl    n    #define IOS ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)   typedef long long ll;   typedef unsigned long long ull;   typedef pair<int, int> pii;   typedef pair<long, long>pll;   const int inf = 0x3f3f3f3f;   const ll lnf = 0x3f3f3f3f3f3f3f3f;   const double pi = acos(-1.0);   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }   #define re(i,a,b) for(int i = a;i <= b;i++)   #define rre(i,a) for(int i = 0;i < a;i++)   #define prre(i,a) for(int i = a;i >= 0;i--)   #define pre(i,a) for(int i = a;i > 0;i--)   #define bug system( pause )   const double eps = 1e-6;   const int N = 1e6 + 10;   const int M = 2e6 + 10;   const int mod = 1e9 + 7;      int n, t, x;   map<pii, int>mp;   int ask(int l, int r)   {    if (mp.count(make_pair(l, r)))return mp[make_pair(l, r)];    cout <<  ?   << l <<     << r << endl;    cout.flush();    int sum;    cin >> sum;    int num = r - l + 1 - sum;    mp[make_pair(l, r)] = num;    return num;   }      int query(int l, int r, int k)   {    if (l == r)return l;    int mid = (l + r) >> 1;    int v = ask(l, mid);    if (v < k)return query(mid + 1, r, k - v);    else return query(l, mid, k);   }      void update(int l, int r, int pos)   {    if (mp.count(make_pair(l, r)))mp[make_pair(l, r)]--;    if (l == r)return;    int mid = (l + r) >> 1;    if (pos <= mid)update(l, mid, pos);    if (pos > mid)update(mid + 1, r, pos);   }      int main()   {    cin >> n >> t;    for (int i = 1; i <= t; i++)    {     cin >> x;     int pos = query(1, n, x);     update(1, n, pos);     cout <<  !   << pos << endl;     cout.flush();    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const int LOGN = 31;   int fwt[MAXN];   int P[MAXN] = {0};   int n;   void update(int v, int d) {     v++;     for (; v <= n; v += v & -v) fwt[v] += d;   }   int query(int v) {     int sum = 0;     for (; v > 0; v -= v & -v) sum += fwt[v];     return sum;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int j = 0; j < 2; j++) {       memset(fwt, 0, sizeof(fwt));       for (int i = 0; i < n; i++) {         int v;         cin >> v;         P[i] += v - query(v);         update(v, 1);       }     }     int c = 0;     for (int i = n - 1; i >= 0; i--) {       int mod = n - i;       if (P[i] >= mod) {         P[i] -= mod;         if (i) P[i - 1]++;       }     }     memset(fwt, 0, sizeof(fwt));     for (int i = 0; i < n; i++) update(i, 1);     for (int i = 0; i < n; i++) {       int sum = 0;       int pos = 0;       for (int j = LOGN; j >= 0; j--) {         if (pos + (1LL << j) < n && sum + fwt[pos + (1LL << j)] < P[i] + 1) {           sum += fwt[pos + (1LL << j)];           pos += (1LL << j);         }       }       cout << (pos) <<    ;       update(pos, -1);     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int count = 0, size;     cin >> size;     char c;     vector<char> num;     for (int i = 0; i < size; i++) {       cin >> c;       num.push_back(c);     }     for (int i = 0; i < num.size(); i++) {       if (num[i] ==  8 ) count++;       if ((size / 11) < count) count = (size / 11);     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3000;   vector<int> E[MAXN];   long long dp[MAXN][MAXN];   int P[MAXN][MAXN];   int T[MAXN][MAXN];   int n;   bool cmp(int a, int b) { return dp[a] > dp[b]; }   void dfs(int x, int p, int r) {     P[r][x] = p;     int d = 1;     for (int i = 0; i < E[x].size(); ++i) {       int v = E[x][i];       if (v != p) {         dfs(v, x, r);         d += T[r][v];       }     }     T[r][x] = d;   }   long long dp_get(int u, int v) {     if (u == v || dp[u][v] != 0) return dp[u][v];     long long d =         max(dp_get(u, P[u][v]), dp_get(v, P[v][u])) + T[u][v] * 1LL * T[v][u];     dp[u][v] = d;     dp[v][u] = d;     return d;   }   void solve() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       --x, --y;       E[x].push_back(y);       E[y].push_back(x);     }     for (int i = 0; i < n; ++i) dfs(i, -1, i);     long long bestres = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < i; ++j) bestres = max(bestres, dp_get(i, j));     printf( %I64d n , bestres);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class ReverseBit {    public:     ReverseBit(int size) : bit_(size + 1, 0) {}     void Add(int pos, int num);     int GetMax(int pos) const;       private:     static int Lsb(int num) { return num & -num; }     vector<int> bit_;   };   void ReverseBit::Add(int pos, int num) {     pos = bit_.size() - pos;     while (pos < (int)bit_.size()) {       bit_[pos] = max(bit_[pos], num);       pos += Lsb(pos);     }   }   int ReverseBit::GetMax(int pos) const {     pos = bit_.size() - pos;     int res = 0;     while (pos > 0) {       res = max(res, bit_[pos]);       pos -= Lsb(pos);     }     return res;   }   struct Receipt {     int sum;     int time;   };   int main() {     int n;     cin >> n;     vector<Receipt> last_receipts(n);     for (auto &r : last_receipts) {       cin >> r.sum;       r.time = 0;     }     int updates;     cin >> updates;     ReverseBit bit(updates + 2);     for (int i = 1; i <= updates; i += 1) {       int type;       cin >> type;       if (type == 1) {         int id, sum;         cin >> id >> sum;         last_receipts[id - 1] = Receipt{.sum = sum, .time = i};       } else {         int sum;         cin >> sum;         bit.Add(i, sum);       }     }     for (const auto &r : last_receipts) {       cout << max(r.sum, bit.GetMax(r.time + 1)) <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000010];   int main() {     int k;     cin >> k;     scanf( %s , s);     int n = strlen(s);     int a[n + 1];     a[0] = 0;     for (int i = 1; i < n + 1; i++) {       a[i] = a[i - 1] + ((s[i - 1] ==  1 ) ? 1 : 0);     }     long long int ans = 0;     for (int i = 1; i < n + 1; i++) {       int ss = a[i - 1] + k;       if (a[n] < ss) continue;       int g = lower_bound(a + i, a + n + 1, ss) - a;       int h = upper_bound(a + i, a + n + 1, ss) - a;       ans += (h - g);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(long long x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     long long f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   long long Power(long long a, long long n, long long mod) {     long long res = 1;     while (n) {       if (n % 2 != 0) {         res = ((res % mod) * (a % mod)) % mod;         n--;       } else {         a = ((a % mod) * (a % mod)) % mod;         n /= 2;       }     }     return res;   }   void AllPossibilities(vector<long long> &arr, vector<long long> &answers,                         long long index, long long sum) {     if (index == arr.size()) {       answers.push_back(sum);       return;     }     AllPossibilities(arr, answers, index + 1, sum + arr[index]);     AllPossibilities(arr, answers, index + 1, sum);   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long getSum(long long n) {     long long sum = 0;     while (n != 0) {       sum = sum + n % 10;       n = n / 10;     }     return sum;   }   long long myceil(long long n, long long x) {     long long y;     if (n % x == 0) {       y = n / x;       return y;     } else {       y = n / x + 1;       return y;     }   }   long long md = 1000000007;   vector<long long> fact, inv;   void inverse(long long n) {     if (n >= inv.size()) {       long long size = inv.size();       size = size == 0 ? 1 : size;       inv.resize(n + 1);       inv[0] = 1;       for (long long i = size; i <= n; i++) inv[i] = Power(fact[i], md - 2, md);     }   }   void factorial(long long n) {     if (n >= fact.size()) {       long long size = fact.size();       size = size == 0 ? 1 : size;       fact.resize(n + 1);       fact[0] = 1;       for (long long i = size; i <= n; i++) fact[i] = (fact[i - 1] * i) % md;     }   }   long long ncr(long long n, long long r) {     return (((fact[n] * inv[r]) % md) * inv[n - r]) % md;   }   long long primes[1300000];   void Sieve() {     bool IsPrime[1300000];     memset(IsPrime, true, sizeof(IsPrime));     for (long long p = 2; p * p < 1300000; p++) {       if (IsPrime[p] == true) {         for (long long i = p * p; i < 1300000; i += p) IsPrime[i] = false;       }     }     long long index = 0;     for (long long p = 2; p < 1300000; p++)       if (IsPrime[p]) {         primes[index] = p;         index++;       }   }   void q1();   void q2();   void q3();   void q4();   void q5();   void pr(vector<vector<long long>> v);   int32_t main() {     q1();     return 0;   }   void q1() {     long long n;     cin >> n;     long long sum = 0;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       sum += x;     }     long long resp = 0;     for (long long i = 1; i <= 5; i++)       if ((i + sum) % (n + 1) != 1) resp++;     cout << resp;   }   void pr(vector<vector<long long>> v) {}   void q2() {     long long n;     cin >> n;     long long arr[n];     for (long long i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     bool set = true;     for (long long i = 0; i < n - 1; i++) {       if (arr[i] == arr[i + 1]) {         set = false;         break;       }     }     if (set)       cout <<  NO             <<   n ;     else {       cout <<  YES             <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxx = 1e6 + 7;   const long long maxn = 1e6 + 7;   const long long mod = 998244353;   const long long maxs = 500000 + 7;   const long long maxm = 400000 + 7;   const long long maxk = 1008 + 7;   const long long maxw = 100 + 7;   const long long maxh = 100 + 7;   const double pi = 3.1415926;   const long long ten = 10;   const long long ooi = 1000000;   const long long ool = 1e18 + 7;   const long double eps = 1e-8;   const int apsz = 26;   long long n;   void init() { cin >> n; }   void solve() {     vector<long long> a(n, 0);     vector<long long> b(n, 0);     vector<long long> pos(n);     for (long long i = (0); i < (n); i++) cin >> a[i];     for (long long i = (0); i < (n); i++) cin >> b[i];     sort(b.begin(), b.end());     for (long long i = (0); i < (n); i++) {       long long ans = 0;       long long lt = i;       long long rt = n - i - 1;       ans = (lt + 1) * (rt + 1);       ans *= a[i];       pos[i] = ans;     }     sort(pos.begin(), pos.end(), greater<long long>());     long long ans = 0;     long long p1 = 0;     while (p1 < n) {       pos[p1] %= mod;       ans += (b[p1] * pos[p1]) % mod;       ans %= mod;       p1++;     }     cout << ans << endl;   }   int main(void) {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string int_to_string(int a) {     stringstream ss;     ss << a;     return ss.str();   }   string double_to_string(double a) {     stringstream ss;     ss << a;     return ss.str();   }   string float_to_string(float a) {     stringstream ss;     ss << a;     return ss.str();   }   string long_to_string(long a) {     stringstream ss;     ss << a;     return ss.str();   }   string long_long_to_string(long long a) {     stringstream ss;     ss << a;     return ss.str();   }   int string_to_int(string s) { return atoi(s.c_str()); }   float string_to_float(string s) { return atof(s.c_str()); }   long string_to_long(string s) { return atol(s.c_str()); }   long long string_to_long_long(string s) { return atoll(s.c_str()); }   int main() {     long long n, c = 0;     cin >> n;     for (long long i = 1; i <= n; i *= 10) c += (n - (i - 1));     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 1, INF = 1e9 + 1;   int n, q, a, b, p, t;   pair<long double, long double> st[N], lf, rg;   pair<long double, long double> merge(pair<long double, long double> a,                                        pair<long double, long double> b) {     long double l1 = a.first, r1 = a.second, l2 = b.first, r2 = b.second;     if (a.first < 0 and a.second < 0) return b;     if (b.first < 0 and b.second < 0) return a;     return pair<long double, long double>(         l1 * l2 / (1 - r1 * (1 - l2)),         r2 + r1 * l2 * (1 - r2) / (1 - (r1 * (1 - l2))));   }   pair<long double, long double> query(int l, int r) {     lf = rg = pair<long double, long double>(-1, -1);     l += n - 1, r += n;     while (l < r) {       if (l & 1) lf = merge(lf, st[l++]);       if (r & 1) rg = merge(st[--r], rg);       l /= 2, r /= 2;     }     return merge(lf, rg);   }   void update(int k, long double v) {     k += n - 1;     st[k] = pair<long double, long double>(v, v);     while (k) k /= 2, st[k] = merge(st[2 * k], st[2 * k + 1]);   }   int main() {     scanf( %d%d , &n, &q);     for (int i = n; i < 2 * n; ++i) {       scanf( %d%d , &a, &b);       st[i] = pair<long double, long double>(1.0 * a / b, 1.0 * a / b);     }     for (int i = n - 1; i >= 0; --i) st[i] = merge(st[2 * i], st[2 * i + 1]);     for (int i = 0; i < q; ++i) {       scanf( %d , &t);       if (t == 1) {         scanf( %d%d%d , &p, &a, &b);         update(p, 1.0L * a / b);       } else {         scanf( %d%d , &a, &b);         printf( %lf n , (double)query(a, b).first);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int num = 0;     register char ch = getchar();     while (ch >  9  || ch <  0 ) ch = getchar();     while (ch <=  9  && ch >=  0 ) num = num * 10 + ch -  0 , ch = getchar();     return num;   }   int num[10];   inline void write(int x) {     register int cnt = 0;     if (!x) {       printf( 0 );       return;     }     while (x) num[++cnt] = x % 10, x /= 10;     while (cnt) putchar(num[cnt--] +  0 );   }   struct node {     int next, to, w;   } e[300020 * 2];   int n, m;   int head[300020], cnt;   int sz[300020], fa[300020], tag[300020], a[300020], tot, flag;   long long dth[300020], ans, mx[300020], dis[300020];   inline void adde(int x, int y, int w) {     e[++cnt].to = y;     e[cnt].next = head[x];     e[cnt].w = w;     head[x] = cnt;   }   void dfs(int x) {     for (int i = head[x]; i; i = e[i].next) {       if (e[i].to == fa[x]) continue;       dth[e[i].to] = dth[x] + e[i].w;       fa[e[i].to] = x;       dfs(e[i].to);     }   }   void dfs2(int x) {     sz[x] = 1;     for (int i = head[x]; i; i = e[i].next) {       if (e[i].to == fa[x] || tag[e[i].to]) continue;       dis[x] = max(dis[x], dis[e[i].to] + e[i].w);       dfs2(e[i].to);       sz[x] += sz[e[i].to];     }   }   void init() {     dfs(1);     int x = n;     while (x) tag[x] = 1, a[++tot] = x, x = fa[x];     for (register int i = 1; i <= tot + 1; i++) mx[i] = -1e16;     for (register int i = tot; i >= 1; i--) {       int x = a[i];       dfs2(x);       if (sz[x] > 1) mx[i] = max(mx[i + 1], dis[x] + dth[x]);       if (i < tot) {         ans = max(ans, dth[n] + dis[x] - dth[x] + mx[i + 1]);         if (sz[x] > 1)           ans = max(ans, dth[n] + dis[x] - dth[x] + dth[a[i + 1]]);         else if (i < tot - 1)           ans = max(ans, dth[n] + dis[x] - dth[x] + dth[a[i + 2]]);       }       if (sz[x] > 2) flag = 1;     }   }   int main() {     scanf( %d %d , &n, &m);     for (register int i = 1; i <= n - 1; i++) {       int x, y, w;       scanf( %d %d %d , &x, &y, &w);       adde(x, y, w), adde(y, x, w);     }     init();     while (m--) {       int l = read();       long long cur = min(dth[n], ans + l);       if (flag) cur = max(cur, dth[n]);       printf( %I64d n , cur);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int ret = 0, f = 1;     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar();     return ret * f;   }   const double inf = 1e30, eps = 1e-10;   const int mx = 100005, md = 1e6;   struct P {     double x, y;     bool operator<(const P& a) const { return x == a.x ? y < a.y : x < a.x; }     bool operator==(const P& a) const {       return fabs(x - a.x) < eps && fabs(y - a.y) < eps;     }     bool operator!=(const P& a) const {       return fabs(x - a.x) > eps || fabs(y - a.y) > eps;     }     double operator*(const P& a) const { return x * a.y - y * a.x; }     P operator-(const P& a) const { return (P){x - a.x, y - a.y}; }   } t[mx], st, ed;   int f[mx], s[mx][2], rt, tot;   inline void rot(int x) {     int y = f[x], z = f[y], p = y[s][0] == x;     if (z)       z[s][z[s][1] == y] = x;     else       rt = x;     f[x] = z, f[y] = x, s[x][p][f] = y;     s[y][p ^ 1] = s[x][p], s[x][p] = y;   }   inline void spl(int x, int o = 0) {     for (int y = 0; f[x] ^ o; rot(x))       if (f[y = f[x]] ^ o) rot((s[y][0] == x) == (s[f[y]][0] == y) ? y : x);   }   inline int ins(P x) {     int cu = rt, ls = 0;     while (cu) {       if (t[cu] == x) {         spl(cu);         return cu;       }       ls = cu, cu = s[cu][t[cu] < x];     }     f[++tot] = ls, s[ls][t[ls] < x] = tot, t[tot] = x;     spl(tot);     return tot;   }   inline int fnd(P x) {     int cu = rt;     while (cu) {       if (t[cu] == x) return cu;       cu = s[cu][t[cu] < x];     }     return -1;   }   inline int pre(int id) {     spl(id);     int cu = s[rt][0];     while (s[cu][1]) cu = s[cu][1];     return cu;   }   inline int nxt(int id) {     spl(id);     int cu = s[rt][1];     while (s[cu][0]) cu = s[cu][0];     return cu;   }   inline void del(int id) {     int pr = pre(id), nx = nxt(id);     spl(pr), spl(nx, rt), s[s[rt][1]][0] = 0;   }   inline void add(P a) {     int id = ins(a);     int pr = pre(id), nx = nxt(id), ppr, nnx;     if (pr && nx && t[nx] != ed && ((t[pr] - a) * (t[nx] - a)) > 0) {       del(fnd(a));       return;     }     while (1) {       pr = pre(id);       ppr = pre(pr);       if (ppr && ((t[pr] - t[ppr]) * (a - t[ppr])) <= 0)         del(pr);       else         break;     }     while (1) {       nx = nxt(id);       nnx = nxt(nx);       if (t[nx] != ed && nnx && t[nnx] != ed && ((t[nx] - a) * (t[nnx] - a)) <= 0)         del(nx);       else         break;     }   }   inline int qry(double a) {     int cu = rt, re = 0;     t[0].x = -1;     while (cu) {       if (t[cu].x <= a + eps && t[re].x < t[cu].x) re = cu;       cu = s[cu][t[cu].x <= a + eps];     }     return re;   }   int n, ls;   double m;   int main() {     cin >> n >> m;     st = (P){0, 0}, ed = (P){inf, inf};     t[rt = tot = 1] = st;     ins(ed);     for (int i = 1; i <= n; i++) {       int op = read(), a = (ls + read()) % md + 1, b = (ls + read()) % md + 1;       if (op == 1) {         add((P){(double)a, (double)b});       } else {         double x = (double)b / a, y = (double)m / a;         int po = qry(x), nx = nxt(po);         if (fabs(t[po].x - x) < eps && t[po].y < y + eps)           ls = i, printf( YES n );         else if (t[nx] == ed)           printf( NO n );         else {           double inc =               t[po].y + (t[nx].y - t[po].y) / (t[nx].x - t[po].x) * (x - t[po].x);           if (inc <= y + eps)             ls = i, printf( YES n );           else             printf( NO n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)7 + (int)1e9;   const int N = 1000005;   const double PI = 4 * atan(1);   const double eps = 1e-10;   const long long oo = 1e10;   const int K = 26;   struct query {     int a, t, x;     query() { a = -1, t = -1, x = -1; }     query(int _a, int _t, int _x) {       a = (_a);       t = (_t);       x = (_x);     }   };   int n;   unordered_map<int, int> ma;   vector<query> qu;   set<int> ss;   set<int> t[N];   unordered_map<int, int> maa[N];   int mx = 1;   int mt = 0;   int sz[N];   vector<int> tree[N];   void update(int val, int pos, int upd) {     for (; pos <= sz[val]; pos += (pos) & (-pos)) {       tree[val][pos] += upd;     }   }   int get(int val, int pos) {     int to = 0;     for (; pos; pos -= (pos) & (-pos)) {       to += tree[val][pos];     }     return to;   }   void ins(int x, int t) { update(x, t, 1); }   void rem(int x, int t) { update(x, t, -1); }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       int x, y, w;       cin >> x >> y >> w;       qu.push_back(query(x, y, w));       ss.insert(w);     }     for (int u : ss) {       ma[u] = mx++;     }     for (query& q : qu) {       q.x = ma[q.x];       t[q.x].insert(q.t);     }     for (int i = 1; i <= mx; i++) {       if (t[i].size() == 0) continue;       mt = 1;       for (int u : t[i]) {         maa[i][u] = mt++;       }       sz[i] = mt;       tree[i].resize(sz[i] + 1);     }     for (query& q : qu) {       q.t = maa[q.x][q.t];     }     for (query q : qu) {       if (q.a == 1) {         ins(q.x, q.t);       } else if (q.a == 2) {         rem(q.x, q.t);       } else {         cout << get(q.x, q.t) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<int, int> a, pair<int, int> b) {     return (a.first == b.first) ? a.second < b.second : a.first < b.first;   }   long long int modInverse(long long int a) {     long long int m = 1000000007;     long long int y = 0, x = 1;     while (a > 1) {       long long int q = a / m;       long long int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += 1000000007;     return x;   }   long long int binpow(long long int a, long long int p) {     if (p == 0) return 1;     long long int ret = binpow(a, p / 2);     ret *= ret;     ret %= 1000000007;     if (p % 2) {       ret *= a;       ret %= 1000000007;     }     return ret;   }   int f[54][54][54][54];   char a[100], b[100];   int n;   bool check(int x, int y) { return (a[x] == a[y] || b[x] == b[y]); }   int dfs(int i, int j, int l, int r) {     if (f[i][j][l][r]) return 0;     if (i == 3) return check(j, r) && check(l, r);     if (check(l, r))       if (dfs(i - 1, i - 3, j, r)) return 1;     if (check(i - 3, r))       if (dfs(i - 1, r, j, l)) return 1;     f[i][j][l][r] = 1;     return 0;   }   void solve() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];     if (n == 1 || dfs(n, n - 2, n - 1, n))       cout <<  YES ;     else       cout <<  NO ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 2;   long long fact[N];   void factorial() {     fact[0] = fact[1] = 1;     for (long long i = 2; i < N; i++) fact[i] = (fact[i - 1] * i) % 1000000007;   }   long long power(long long a, long long b, long long mod) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2) {         x = (x * y) % mod;       }       y = (y * y) % mod;       b /= 2;     }     return x % mod;   }   long long modular_inverse(long long n, long long mod) {     return power(n, mod - 2, mod);   }   long long nCr(long long n, long long k, long long mod) {     if (k > n)       return 0;     else if (n == k)       return 1;     return (fact[n] * ((modular_inverse(fact[k], 1000000007) *                         modular_inverse(fact[n - k], 1000000007)) %                        mod)) %            mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     long long int n = s.size(), temp = 0, p = 1, ans = 0;     for (long long int i = 0; i < n; i++) {       temp += s[i] -  0 ;     }     for (long long int i = n - 1; i >= 0; i--) {       temp -= s[i] -  0 ;       ans = (ans + (((p * (n - i)) % 1000000007) * (temp)) % 1000000007) %             1000000007;       ans = (ans + (((((i * (i + 1) / 2) % 1000000007) * p) % 1000000007) *                     (s[i] -  0 )) %                        1000000007) %             1000000007;       p *= 10;       p %= 1000000007;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long max_N = 100003;   const long long max_M = 200003;   vector<pair<long long, long long> > briaunos[max_N];   bool nepavyko_uzdavinys = false;   struct reiskinys {     long long skaicius, a;     long double a_reiksme;     bool isreikstas;     bool isvestas;     long double a_reiksme_kai_reisinys_nulis;     reiskinys() {       isreikstas = false;       isvestas = false;       skaicius = 0;       a = 0;     }     void tapk_pradiniu() {       skaicius = 0;       a = 1;       isreikstas = true;     }     long double reiksme() {       return (long double)a_reiksme * (long double)a + (long double)skaicius;     }     void kada_tampa_nuliu() {       if ((a == 0) && (skaicius == 0))         a_reiksme_kai_reisinys_nulis = 0;       else if (a == 0)         a_reiksme_kai_reisinys_nulis = 1000000000;       else         a_reiksme_kai_reisinys_nulis =             ((long double)0 - (long double)skaicius) / (long double)a;     }     bool operator<(const reiskinys &kitas) const {       return a_reiksme_kai_reisinys_nulis < kitas.a_reiksme_kai_reisinys_nulis;     }   };   reiskinys virsuniu_reiksmes[max_N];   void isreisk(reiskinys &turimas, reiskinys &norimas, long long suma) {     norimas.a = 0 - turimas.a;     norimas.skaicius = suma - turimas.skaicius;     norimas.isreikstas = true;   }   pair<bool, long double> rask_a_reiksme(reiskinys &pirmas, reiskinys &antras,                                          long double suma) {     long long skaicius = 0 - (suma - pirmas.skaicius - antras.skaicius);     long long a = 0 - pirmas.a - antras.a;     if ((a == 0) && (skaicius != 0)) {       nepavyko_uzdavinys = true;       return {false, 0};     } else if (a == 0) {       return {false, 0};     } else {       long double a_reiksme = (long double)skaicius / (long double)a;       return {true, a_reiksme};     }   }   bool tenkina(reiskinys &pirmas, reiskinys &antras, long double suma) {     if (pirmas.reiksme() + antras.reiksme() == suma) return true;     return false;   }   void ieskok_minimalaus_a(vector<long long> komponente) {     for (long long i = 0; i < komponente.size(); i++) {       virsuniu_reiksmes[komponente[i]].kada_tampa_nuliu();     }     sort(komponente.begin(), komponente.end(), [&](long long &i, long long &j) {       return virsuniu_reiksmes[i] < virsuniu_reiksmes[j];     });     reiskinys neigiami;     reiskinys teigiami;     long double a_reiksme =         virsuniu_reiksmes[komponente[0]].a_reiksme_kai_reisinys_nulis - 1;     bool ar_teigiamas[komponente.size()];     for (long long i = 0; i < komponente.size(); i++) {       virsuniu_reiksmes[komponente[i]].a_reiksme = a_reiksme;       if (virsuniu_reiksmes[komponente[i]].reiksme() > (long double)0) {         ar_teigiamas[i] = true;         teigiami.a += virsuniu_reiksmes[komponente[i]].a;         teigiami.skaicius += virsuniu_reiksmes[komponente[i]].skaicius;       } else {         ar_teigiamas[i] = false;         neigiami.a -= virsuniu_reiksmes[komponente[i]].a;         neigiami.skaicius -= virsuniu_reiksmes[komponente[i]].skaicius;       }     }     neigiami.a_reiksme = a_reiksme;     teigiami.a_reiksme = a_reiksme;     long double minimalus_ats = teigiami.reiksme() + neigiami.reiksme();     long double minimali_a_reiksme = a_reiksme;     for (long long i = 0; i < komponente.size(); i++) {       long double a_reiksme =           virsuniu_reiksmes[komponente[i]].a_reiksme_kai_reisinys_nulis;       neigiami.a_reiksme = a_reiksme;       teigiami.a_reiksme = a_reiksme;       if (ar_teigiamas[i]) {         teigiami.a -= virsuniu_reiksmes[komponente[i]].a;         teigiami.skaicius -= virsuniu_reiksmes[komponente[i]].skaicius;         neigiami.a -= virsuniu_reiksmes[komponente[i]].a;         neigiami.skaicius -= virsuniu_reiksmes[komponente[i]].skaicius;       } else {         neigiami.a += virsuniu_reiksmes[komponente[i]].a;         neigiami.skaicius += virsuniu_reiksmes[komponente[i]].skaicius;         teigiami.a += virsuniu_reiksmes[komponente[i]].a;         teigiami.skaicius += virsuniu_reiksmes[komponente[i]].skaicius;       }       if (teigiami.reiksme() + neigiami.reiksme() < minimalus_ats) {         minimalus_ats = teigiami.reiksme() + neigiami.reiksme();         minimali_a_reiksme = a_reiksme;       }     }     for (long long i = 0; i < komponente.size(); i++)       virsuniu_reiksmes[komponente[i]].a_reiksme = minimali_a_reiksme;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long N, M;     cin >> N >> M;     for (long long i = 0; i < M; i++) {       long long a, b, tipas;       cin >> a >> b >> tipas;       briaunos[a].push_back({b, tipas});       briaunos[b].push_back({a, tipas});     }     bool surastas[N + 1];     for (long long i = 1; i <= N; i++) surastas[i] = false;     for (long long i = 1; i <= N; i++) {       if (surastas[i]) continue;       queue<long long> eile;       vector<long long> komponente;       eile.push(i);       komponente.push_back(i);       surastas[i] = true;       virsuniu_reiksmes[i].tapk_pradiniu();       while (!eile.empty()) {         long long g = eile.front();         eile.pop();         for (long long j = 0; j < briaunos[g].size(); j++) {           long long kitas = briaunos[g][j].first;           if (surastas[kitas]) continue;           if (g == kitas) continue;           isreisk(virsuniu_reiksmes[g], virsuniu_reiksmes[kitas],                   briaunos[g][j].second);           surastas[kitas] = true;           eile.push(kitas);           komponente.push_back(kitas);         }       }       bool radau_a_reiksme = false;       long double a_reiksme;       for (long long j = 0; j < komponente.size(); j++) {         long long dab = komponente[j];         for (long long x = 0; x < briaunos[dab].size(); x++) {           long long kitas = briaunos[dab][x].first;           pair<bool, long double> ats =               rask_a_reiksme(virsuniu_reiksmes[dab], virsuniu_reiksmes[kitas],                              briaunos[dab][x].second);           radau_a_reiksme = ats.first;           a_reiksme = ats.second;           if (radau_a_reiksme) {             break;           }         }         if (radau_a_reiksme) break;       }       if (radau_a_reiksme) {         for (long long j = 0; j < komponente.size(); j++) {           virsuniu_reiksmes[komponente[j]].a_reiksme = a_reiksme;         }         for (long long j = 0; j < komponente.size(); j++) {           long long dab = komponente[j];           for (long long x = 0; x < briaunos[dab].size(); x++) {             long long kitas = briaunos[dab][x].first;             if (!tenkina(virsuniu_reiksmes[dab], virsuniu_reiksmes[kitas],                          briaunos[dab][x].second)) {               nepavyko_uzdavinys = true;             }           }         }       } else {         ieskok_minimalaus_a(komponente);       }     }     if (nepavyko_uzdavinys)       cout <<  NO ;     else {       cout <<  YES n ;       for (long long i = 1; i <= N; i++)         cout << fixed << setprecision(9) << virsuniu_reiksmes[i].reiksme() <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int i, l = s.length();     char max = s[0];     for (i = 1; i < l; i++) {       if (s[i] > max) max = s[i];     }     for (i = 0; i < l; i++) {       if (max == s[i]) cout << max;     }   }


#include <bits/stdc++.h>   using namespace std;   int used[200001];   int socks[200001];   bool used2[200001];   map<pair<int, int>, int> colors;   map<pair<int, int>, int>::iterator it;   int Stage = 0;   vector<vector<int> > V;   pair<int, int> P;   int MaXS = 0;   int countOfSocks = 0;   void Dfs(int v) {     countOfSocks++;     P.first = Stage;     P.second = socks[v];     colors[P]++;     MaXS = max(MaXS, colors[make_pair(Stage, socks[v])]);     for (int i = 0; i < V[v].size(); i++) {       if (used[V[v][i]] != true) {         used[V[v][i]] = true;         Dfs(V[v][i]);       }     }   }   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> socks[i];       vector<int> a;       V.push_back(a);     }     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       l--;       r--;       V[l].push_back(r);       V[r].push_back(l);       used2[l] = true;       used2[r] = true;     }     long long ans = 0;     if (m == 0) {       cout << 0;       return 0;     }     for (int i = 0; i < n; i++) {       if (used[i] == false && used2[i] == true) {         MaXS = 0;         countOfSocks = 0;         used[i] = true;         Dfs(i);         ans += countOfSocks - MaXS;         Stage++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     int i;     int j;   } AXIS;   AXIS D[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   bool DFS(char maze[][505], AXIS S, int &k, int &n, int &m) {     maze[S.i][S.j] =  * ;     for (int i = 0; i < 4; i++) {       AXIS next;       next.i = S.i + D[i].i;       next.j = S.j + D[i].j;       if (maze[next.i][next.j] ==  .  && 0 <= next.i && next.i < n &&           0 <= next.j && next.j < m && DFS(maze, next, k, n, m)) {         maze[next.i][next.j] =  X ;         k--;       }       if (!k) return 0;     }     return 1;   }   int main() {     int n, m, k;     char maze[505][505];     AXIS start = {-1, -1};     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> maze[i][j];         if (start.i < 0 && maze[i][j] ==  . ) {           start.i = i;           start.j = j;         }       }     }     DFS(maze, start, k, n, m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (maze[i][j] ==  * ) {           cout <<  . ;         } else {           cout << maze[i][j];         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   vector<int> ans[N];   int a[N], b[N], c[N];   int n, k, p;   int main() {     scanf( %d%d%d , &n, &k, &p);     int s = 0;     int _x = 0, _y = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       s += a[i];       if (a[i] & 1)         b[_x++] = a[i];       else         c[_y++] = a[i];     }     if ((k - p) & 1) {       if (s % 2 == 0) {         printf( NO n );         return 0;       }     }     if ((k - p) % 2 == 0) {       if (s & 1) {         printf( NO n );         return 0;       }     }     int j = 0;     if (_y >= p) {       for (int i = 0; i < p; ++i) {         ans[j++].push_back(c[i]);       }       if (_x < (k - p)) {         printf( NO n );         return 0;       } else {         for (int i = 0; i < k - p; ++i) {           ans[j++].push_back(b[i]);         }         for (int i = p; i < _y; ++i) ans[j - 1].push_back(c[i]);         for (int i = k - p; i < _x; ++i) ans[j - 1].push_back(b[i]);       }     } else {       for (int i = 0; i < _y; ++i) {         ans[j++].push_back(c[i]);       }       if (_x / 2 < (p - _y)) {         printf( NO n );         return 0;       }       for (int i = 0; i < p - _y; ++i) {         ans[j].push_back(b[i * 2]);         ans[j++].push_back(b[i << 1 | 1]);       }       if ((_x - (p - _y) * 2) < (k - p)) {         printf( NO n );         return 0;       } else {         for (int i = 2 * (p - _y); i < (2 * (p - _y) + k - p); ++i) {           ans[j++].push_back(b[i]);         }         for (int i = (2 * (p - _y) + k - p); i < _x; ++i)           ans[j - 1].push_back(b[i]);       }     }     printf( YES n );     for (int i = 0; i < j; ++i) {       int n = ans[i].size();       printf( %d  , n);       for (int k = 0; k < n; ++k) {         printf( %d  , ans[i][k]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2, class T3 = hash<T1>>   using umap = unordered_map<T1, T2, T3>;   template <class T>   using uset = unordered_set<T>;   template <class T>   using vec = vector<T>;   const long long infll = numeric_limits<long long>::max() >> 1;   const int inf = numeric_limits<int>::max() >> 1;   const int maxN = 2e6 + 1;   const int mod = 1e9 + 7;   const int N = 50001;   const int L = 30;   int n, m, cur;   int arr[N];   struct Trie {     int cnt[maxN];     int nxt[maxN][2];     int bit[maxN][L];   } trie;   void insert(int key) {     int node = 0;     for (int i = L - 1; i >= 0; --i) {       int j = key >> i & 1;       if (!trie.nxt[node][j]) {         trie.nxt[node][j] = ++cur;       }       node = trie.nxt[node][j];     }     trie.cnt[node]++;     for (int i = 0; i < L; ++i) {       if (key >> i & 1) {         trie.bit[node][i]++;       }     }   }   void dfs(int u = 0) {     for (int i = 0; i < 2; ++i) {       int v = trie.nxt[u][i];       if (!v) {         continue;       }       dfs(v);       trie.cnt[u] += trie.cnt[v];       for (int j = 0; j < L; ++j) {         trie.bit[u][j] += trie.bit[v][j];       }     }   }   int cnt_query(int key, int lim) {     int res = 0;     int node = 0;     for (int i = L - 1; i >= 0; --i) {       int j = key >> i & 1;       int k = lim >> i & 1;       if (!k) {         res += trie.nxt[node][j] ? trie.cnt[trie.nxt[node][j]] : 0;         node = trie.nxt[node][!j];       } else {         node = trie.nxt[node][j];       }       if (!node) {         return res;       }     }     res += trie.cnt[node];     return res;   }   int sum_query(int key, int lim) {     int res = 0;     int node = 0;     for (int i = L - 1; i >= 0; --i) {       int j = key >> i & 1;       int k = lim >> i & 1;       if (!k) {         int sum = 0;         for (int b = 0; b < L; ++b) {           int s = trie.cnt[trie.nxt[node][j]];           int x = trie.bit[trie.nxt[node][j]][b];           int c[2] = {s - x, x};           sum += ((1ll * c[key >> b & 1]) << b) % mod;           sum %= mod;         }         res += trie.nxt[node][j] ? sum : 0;         res %= mod;         node = trie.nxt[node][!j];       } else {         node = trie.nxt[node][j];       }       if (!node) {         return res;       }     }     int sum = 0;     for (int b = 0; b < L; ++b) {       int s = trie.cnt[node];       int x = trie.bit[node][b];       int c[2] = {s - x, x};       sum += ((1ll * c[key >> b & 1]) << b) % mod;       sum %= mod;     }     res += sum;     res %= mod;     return res;   }   void input() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> arr[i];       insert(arr[i]);     }     dfs();   }   int count(int q) {     long long res = 0;     for (int i = 1; i <= n; ++i) {       res += cnt_query(~arr[i], q);     }     return res / 2;   }   int compute(int q) {     int res = 0;     for (int i = 1; i <= n; ++i) {       res += sum_query(~arr[i], q);       res %= mod;     }     return 1ll * res * (mod + 1) / 2 % mod;   }   int bin_search(int l, int r) {     while (l < r) {       int q = l + r + 1 >> 1;       if (count(q) < m) {         r = q - 1;       } else {         l = q;       }     }     return l;   }   void solve() {     int q = bin_search(0, inf);     int c = count(q);     int res = compute(q) - 1ll * (c - m) * q % mod;     res += mod;     res %= mod;     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     input();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, sum, mbit;   int Ask(vector<int> vec) {     int ret = 0;     printf( ? %d  , vec.size());     for (int i = 0; i < vec.size(); i++) printf( %d  , vec[i]);     puts(  );     fflush(stdout);     scanf( %d , &ret);     return ret;   }   int Solve(vector<int> a) {     vector<int> tmp;     int l = 0, r = a.size() - 1, ans = 0;     sort(a.begin(), a.end());     while (l <= r) {       int mid = (l + r) >> 1;       for (int i = 0; i <= mid; i++) tmp.push_back(a[i]);       int ret = Ask(tmp);       tmp.clear();       if (ret == y || ret == (y ^ x))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return a[ans];   }   int main() {     vector<int> vec;     scanf( %d%d%d , &n, &x, &y);     for (int i = 0; i <= 9; i++) {       for (int j = 1; j <= n; j++)         if (j >> i & 1) vec.push_back(j);       if (!vec.size()) break;       int ret = Ask(vec);       vec.clear();       if (ret == y || ret == (y ^ x)) sum |= (1 << i), mbit = i;     }     vector<int> ta, tb;     for (int i = 1; i <= n; i++)       if (i >> mbit & 1)         ta.push_back(i);       else         tb.push_back(i);     if (ta.size() > tb.size()) swap(ta, tb);     int pos1 = Solve(ta), pos2 = (sum ^ pos1);     if (pos1 > pos2) swap(pos1, pos2);     printf( ! %d %d n , pos1, pos2);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, s1;   int a[1000];   set<string> l;   void fun() {     memset(a, 0, sizeof(a));     int len = s.length();     int j = 0;     for (int i = len - 1; i >= 0; i--) {       a[j++] = s[i] -  0 ;     }     a[0]++;     for (int i = 0; i < len; i++) {       if (a[i] >= 10) {         a[i + 1] += a[i] / 10;         a[i] %= 10;       }     }     if (a[len] != 0) len++;     int index;     for (int i = 0; i < len; i++) {       if (a[i] == 0) continue;       index = i;       break;     }     for (int i = len - 1; i >= index; i--) {       s1 += a[i] +  0 ;     }   }   int main() {     while (cin >> s) {       l.clear();       l.insert(s);       s1 =   ;       fun();       int sum = 1;       while (l.count(s1) != 1) {         l.insert(s1);         s = s1;         s1 =   ;         fun();         sum++;       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = long unsigned long;   using ld = double long;   template <class T, int N, int B>   struct asym_ra {     T a[N + 1];     T b[N / B + 2];     T get(int r) {       if (r <= 0) return T();       if (r > N) r = N;       return a[r] + b[r / B];     }     T operator()(int l, int r) { return get(r) - get(l); }     void add(int p, const T& v) {       for (int i = p + 1; i % B && i <= N; i++) a[i] += v;       for (int i = p / B + 1; i < N / B + 2; i++) b[i] += v;     }   };   int n;   int a[200005];   const int H = 300000;   asym_ra<ll, H + 5, 512> cnt;   asym_ra<ll, H + 5, 512> sum;   int main() {     ios::sync_with_stdio(!cin.tie(0));     cin >> n;     ll sol = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       for (int j = 0; j <= H; j += x) {         sol += sum(j, j + x) - cnt(j, j + x) * 1ll * j;       }       for (int q = 1;;) {         int r = x / q;         int l = x / (q + 1) + 1;         r++;         sol += x * cnt(l, r) - q * sum(l, r);         if (l == 1) break;         q = x / (l - 1);       }       sol += x * 1ll * cnt(x + 1, H + 1);       cout << sol <<    ;       cnt.add(x, 1);       sum.add(x, x);     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, cnt = 0;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++)       if (s[i] ==  2 ) cnt++;     if (cnt == 0) {       cout <<  YES  <<   n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (i == j)             cout <<  X ;           else             cout <<  = ;         }         cout <<   n ;       }     } else if (cnt == 1 || cnt == 2)       cout <<  NO  <<   n ;     else {       char a[n][n];       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) a[i][j] =  0 ;       }       cout <<  YES  <<   n ;       for (int i = 0; i < n; i++) {         bool win = 1;         for (int j = 0; j < n; j++) {           if (i == j)             a[i][j] =  X ;           else {             if (s[j] ==  1 )               a[i][j] =  = , a[j][i] =  = ;             else {               if (a[i][j] ==  0  and a[j][i] ==  0 ) {                 if (win)                   a[i][j] =  + , a[j][i] =  - , win = 0;                 else                   a[i][j] =  - , a[j][i] =  + ;               }             }           }         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) cout << a[i][j];         cout <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     while (n--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     T = 1;     while (T--) {       int n;       cin >> n;       vector<int> v;       int c = 0;       for (int i = 0; i < n; i++) {         int in;         cin >> in;         if (in == 5) {           c++;         }         v.push_back(in);       }       int nn = c / 9;       if (c == n) {         cout <<  -1  << endl;       } else {         string s =   ;         if (nn == 0) {           cout <<  0  << endl;         } else {           for (int i = 0; i < nn * 9; i++) {             s = s +  5 ;           }           for (int i = 0; i < n - c; i++) {             s = s +  0 ;           }           cout << s << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, c = 0;     char a;     cin >> n >> m;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> a;         if (a ==  C  || a ==  M  || a ==  Y ) c++;       }     }     if (c == 0)       cout <<  #Black&White  << endl;     else       cout <<  #Color  << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   int even[1 << 17];   bool used[1 << 17];   vector<int> path;   void addV(int v) {     path.push_back(v + 1);     even[v] ^= 1;   }   void dfs(int v, int p) {     used[v] = true;     addV(v);     for (int i(0); i <= ((long long)(((int)g[v].size())) - 1); ++i) {       int to(g[v][i]);       if (to == p) continue;       if (!used[to]) {         dfs(to, v);         addV(v);       }     }     if (even[v]) {       if (p == v) {         path.pop_back();       } else {         addV(p);         addV(v);       }     }   }   void solve() {     int n, m;     scanf( %d%d , &n, &m);     g.resize(n);     for (int i(0); i <= ((long long)(m)-1); ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       g[a].push_back(b);       g[b].push_back(a);     }     for (int i(0); i <= ((long long)(n)-1); ++i) scanf( %d , &even[i]);     bool ok(false);     for (int i(0); i <= ((long long)(n)-1); ++i) {       if (!used[i]) {         if (even[i] && ok) {           puts( -1 );           return;         }         if (even[i]) {           dfs(i, i);           ok = true;         }       }     }     printf( %d n , ((int)path.size()));     for (int i(0); i <= ((long long)(((int)path.size())) - 1); ++i)       printf( %d%c , path[i], i + 1 == ((int)path.size()) ?   n  :    );   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   const int mod7 = 1e9 + 7;   const int mod = 1e9 + 7;   void read(int &a) {     a = 0;     int d = 1;     char ch;     while (ch = getchar(), ch >  9  || ch <  0 )       if (ch ==  - ) d = -1;     a = ch ^ 48;     while (ch = getchar(), ch >=  0  && ch <=  9 )       a = (a << 3) + (a << 1) + (ch ^ 48);     a *= d;   }   int b[N][35], p[N][35];   void ins(int x, int v) {     for (register int i = 0; i <= 30; i++) {       p[x][i] = p[x - 1][i];       b[x][i] = b[x - 1][i];     }     int now = x;     for (register int i = 30; i >= 0; i--) {       if (v & (1 << i)) {         if (!b[x][i]) {           b[x][i] = v;           p[x][i] = now;           return;         }         if (p[x][i] < now) {           swap(b[x][i], v);           swap(p[x][i], now);         }         v ^= b[x][i];       }     }   }   int query(int l, int r) {     int ans = 0;     for (register int i = 30; i >= 0; i--)       if (p[r][i] >= l && (b[r][i] ^ ans) > ans) ans ^= b[r][i];     return ans;   }   int main() {     int n;     read(n);     for (register int i = 1, x; i <= n; i++) {       read(x);       ins(i, x);     }     int T;     read(T);     while (T--) {       int l, r;       read(l), read(r);       printf( %d n , query(l, r));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n, x, y;   int ABS(int x) { return (x < 0) ? (-x) : (x); }   int main() {     scanf( %d%d%d%d , &m, &x, &n, &y);     if (m > n) {       swap(m, n);       swap(x, y);     }     int d = ABS(x - y);     long long ans = 1 + m + n;     for (int i = 1; i <= m; i++) {       int b = i + d - 1, a = ABS(d - i) + 1;       a = max(a, 1);       b = min(b, n);       if (a <= b) ans += (b - a + 1) * 2 - 1;       if (i > d) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, w;     cin >> n >> m >> w;     vector<long long> A(n);     for (int x = 0; x < n; x++) cin >> A[x];     long long low = 1, high = (long long)1e9 + m;     long long ans = low, mid;     while (high >= low) {       mid = (low + high) / 2;       long long left = 0;       vector<long long> tmp(n + 1);       long long add = 0;       vector<long long> B = A;       for (int x = 0; x < n; x++) {         add += tmp[x];         B[x] += add;         if (B[x] < mid) {           long long needed = mid - B[x];           tmp[min(n, w + x)] -= needed;           add += needed;           left += needed;         }       }       if (left <= m)         ans = max(mid, ans), low = mid + 1;       else         high = mid - 1;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int nextInt() {     int x;     scanf( %d , &x);     return x;   }   const int MAX_N = 1e5 + 100;   int arr[MAX_N];   int main() {     int n = nextInt();     for (int i = 0; i < n; ++i) arr[i] = nextInt();     sort(arr, arr + n);     for (int i = 1; i < n; ++i) {       if (arr[i] % arr[0] != 0) {         cout << -1 << endl;         return 0;       }     }     cout << arr[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, bool> ma;     char ch[100][100];     int n, m, answer = 0;     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; cin >> ch[i][j++])         ;     for (int i = 0; i < m; ++i) {       char Max = NULL;       for (int j = 0; j < n; Max = max(Max, ch[j++][i]))         ;       for (int j = 0; j < n; ++j)         if (ch[j][i] == Max && !ma[j]) {           ++answer;           ma[j] = true;         }     }     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 200010;   int a[maxN];   long long presum[maxN];   int n;   set<long long> st;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       presum[i] = presum[i - 1] + a[i];     }     for (int i = 1; i <= n; i++) {       long long M = 1;       while (M <= a[i]) M += M;       for (int j = i + 2; j <= n && presum[j - 1] - presum[i] <= M; j++)         if ((a[i] ^ a[j]) == (presum[j - 1] - presum[i]))           st.insert(1LL * i * n + j);       for (int j = i - 2; j >= 1 && presum[i - 1] - presum[j] <= M; j--)         if ((a[j] ^ a[i]) == (presum[i - 1] - presum[j]))           st.insert(1LL * j * n + i);     }     printf( %d n , (int)st.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = n;     sum += n / 2;     cout << sum << endl;     for (int i = 2; i <= n; i += 2) {       cout << i <<    ;     }     for (int i = 1; i <= n; i += 2) {       cout << i <<    ;     }     for (int i = 2; i <= n; i += 2) {       cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f ^= 1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return f ? x : -x;   }   int tar;   int val[26];   int tp[26];   int ans;   char cmd[26][105];   void dfs(int i) {     if (val[i - 1] == tar) {       printf( %d n , i - 1);       for (int j = 0; j < (int)(i - 1); ++j) puts(cmd[j + 1]);       exit(0);     }     if (i - 1 >= ans) return;     for (int j = 0; j < (int)(i); ++j)       for (int coef = 0; coef < (int)(4); ++coef) {         int mul = 1 << coef;         tp[i] = j * 10 + mul;         val[i] = mul * val[j];         sprintf(cmd[i],  lea e%cx, [%d*e%cx] , i +  a , mul, j +  a );         if (val[i] <= tar) dfs(i + 1);       }     for (int j = 0; j < (int)(i); ++j)       for (int k = 0; k < (int)(i); ++k)         for (int coef = 0; coef < (int)(4); ++coef) {           int mul = 1 << coef;           tp[i] = (j * 26 + k) * 10 + mul;           val[i] = val[j] + mul * val[k];           sprintf(cmd[i],  lea e%cx, [e%cx + %d*e%cx] , i +  a , j +  a , mul,                   k +  a );           if (val[i] <= tar) dfs(i + 1);         }   }   int main() {     tar = read();     val[0] = 1;     for (ans = 0; ans <= 26; ++ans) dfs(1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, l, k, a[100005], x = 1;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n; i++) {       if (a[i] == 25) {         l++;       } else if (a[i] == 50) {         if (l < 1) {           x = 0;           break;         } else {           l--;           k++;         }       } else {         if (l > 0 && k > 0) {           l--;           k--;         } else if (l >= 3) {           l -= 3;         } else {           x = 0;           break;         }       }     }     if (x == 1)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   bool f;   int col[N];   long long p1 = 0, p2 = 0;   const long long mod = 998244353;   vector<int> E[N];   void dfs(int u) {     if (col[u] == 1)       p1++;     else       p2++;     for (int i = 0; i < E[u].size(); i++) {       int v = E[u][i];       if (!col[v]) {         if (col[u] == 1)           col[v] = 2;         else if (col[u] == 2)           col[v] = 1;         dfs(v);       } else if (col[u] == col[v])         f = 0;     }   }   long long fast_mod(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       b >>= 1;       a = (a * a) % mod;     }     return res;   }   int main() {     int t, n, m;     cin >> t;     while (t--) {       f = 1;       long long ans = 1;       cin >> n >> m;       for (int i = 1; i <= m; i++) {         int u, v;         cin >> u >> v;         E[u].push_back(v);         E[v].push_back(u);       }       for (int i = 1; i <= n; i++) {         if (!col[i]) {           col[i] = 1;           p1 = 0;           p2 = 0;           dfs(i);           ans = ans * ((fast_mod(2, p1) + fast_mod(2, p2)) % mod) % mod;         }       }       if (!f)         cout << 0 << endl;       else         cout << ans << endl;       for (int i = 1; i <= n; i++) E[i].clear(), col[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5001;   bool dp1[N][N], dp2[N][N];   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     }     string s;     memset(dp1, false, sizeof dp1);     memset(dp2, false, sizeof dp2);     cin >> s;     long long n = s.length();     for (long long i = 0; i < n; i++) {       long long curr = 0;       for (long long j = i; j < n; j++) {         if (s[j] ==  ) )           curr--;         else           curr++;         if (curr >= 0)           dp1[i][j] = true;         else           break;       }     }     for (long long i = n - 1; i >= 0; i--) {       long long curr = 0;       for (long long j = i; j >= 0; j--) {         if (s[j] ==  ( )           curr--;         else           curr++;         if (curr >= 0)           dp2[j][i] = true;         else           break;       }     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       for (long long j = i; j < n; j++) {         if (dp1[i][j] && dp2[i][j] && (j - i + 1) % 2 == 0) ans++;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int gcd(int a, int b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   bool sortbysec(const pair<char, int> &a, const pair<char, int> &b) {     return (a.second < b.second);   }   bool checkParity(long long int a, long long int b) {     if (a % 2 == 0 && b % 2 == 0 || a % 2 == 1 && b % 2 == 1) return true;     return false;   }   bool isPrime(int n) {     if (n <= 1) return false;     for (int i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cerr.tie(NULL);     ;     int n;     cin >> n;     string s;     cin >> s;     string p =   ;     for (long long int i = 0; i < s.size(); i++) p += s[i];     int count = 0;     for (long long int i = 0; i < s.size() - 1; i++) {       if (s[i] == s[i + 1]) {         if (s[i] ==  R ) {           if (i + 2 <= s.size() - 1) {             if (s[i + 2] ==  B ) {               count++;               s[i + 1] =  G ;             } else if (s[i + 2] ==  G ) {               count++;               s[i + 1] =  B ;             } else               s[i + 1] =  G ;           } else             s[i + 1] =  G ;         } else if (s[i] ==  G ) {           if (i + 2 <= s.size() - 1) {             if (s[i + 2] ==  B ) {               count++;               s[i + 1] =  R ;             } else if (s[i + 2] ==  R ) {               count++;               s[i + 1] =  B ;             } else               s[i + 1] =  R ;           } else             s[i + 1] =  R ;         } else {           if (i + 2 <= s.size() - 1) {             if (s[i + 2] ==  G ) {               count++;               s[i + 1] =  R ;             } else if (s[i + 2] ==  R ) {               count++;               s[i + 1] =  G ;             } else               s[i + 1] =  R ;           } else             s[i + 1] =  R ;         }       }     }     int l = 0;     for (long long int i = 0; i < n; i++)       if (p[i] != s[i]) l++;     cout << l << endl;     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int Max() { return -1000000007; }   int Min() { return 1000000007; }   template <typename... Args>   int Max(int a, Args... args) {     return max(a, Max(args...));   }   template <typename... Args>   int Min(int a, Args... args) {     return min(a, Min(args...));   }   long long a[7][7];   int main() {     for (int i = (1); i <= (5); ++i) {       for (int j = (1); j <= (5); ++j) {         scanf( %lld , &a[i][j]);       }     }     vector<long long> vc;     for (int i = (1); i <= (5); ++i) vc.push_back((long long)i);     long long ans = 0LL;     do       ans = max(ans, (a[vc[0]][vc[1]] + a[vc[1]][vc[0]]) +                          (a[vc[2]][vc[3]] + a[vc[3]][vc[2]]) +                          (a[vc[1]][vc[2]] + a[vc[2]][vc[1]]) +                          (a[vc[3]][vc[4]] + a[vc[4]][vc[3]]) +                          (a[vc[2]][vc[3]] + a[vc[3]][vc[2]]) +                          (a[vc[3]][vc[4]] + a[vc[4]][vc[3]]));     while (next_permutation(vc.begin(), vc.end()));     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> ans[1000];   int main() {     cin >> n;     int k = 2;     while ((k * (k + 1)) / 2 <= n) k++;     int cnt = 1;     for (int i = 1; i <= k; i++)       for (int j = 1; j < i; j++) {         ans[i].push_back(cnt);         ans[j].push_back(cnt);         cnt++;       }     cout << k << endl;     for (int i = 1; i <= k; i++) {       for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void openfile() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int nmax = 1 << 16;   int n, k;   int a[nmax];   vector<string> name;   map<string, int> num;   vector<vector<int> > g;   int main() {     cin >> n >> k;     g.resize(n);     name.resize(n);     for (int i = 0; i < n; i++) {       cin >> name[i];       num[name[i]] = i;     }     for (int i = 0; i < k; i++) {       string s1, s2;       cin >> s1 >> s2;       int v1 = num[s1], v2 = num[s2];       g[v1].push_back(v2);       g[v2].push_back(v1);     }     int ans, cans = 0;     for (int i = 0; i < nmax; i++) {       int cur = 0;       for (int j = 0; j < n; j++) {         if (i & (1 << j)) cur++;       }       for (int j = 0; j < n; j++) {         if (i & (1 << j)) {           for (int q = 0; q < ((int)((g[j]).size())); q++) {             if (i & (1 << g[j][q])) {               cur = 0;               break;             }           }         }       }       if (cur > cans) {         ans = i;         cans = cur;       }     }     cout << cans << endl;     set<string> b;     for (int i = 0; i < n; i++) {       if (ans & (1 << i)) {         b.insert(name[i]);       }     }     for (set<string>::iterator it = b.begin(); it != b.end(); it++) {       cout << *it << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[400005];     int n, k;     char c =  a ;     int T[26];     memset(T, 0, sizeof(T));     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf(  %c , &s[i]);       T[s[i] -  a ]++;     }     int maxx;     for (int i = 0; i < 26; i++) {       if (k >= T[i])         k -= T[i];       else {         maxx = i, T[i] = k;         break;       }     }     for (int i = 0; i < n; i++) {       if (s[i] -  a  <= maxx && T[s[i] -  a ] > 0)         T[s[i] -  a ]--, s[i] =  * ;       else         printf( %c , s[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int sum[1010][1010];   char mp[1010][1010];   int getsum(int x1, int y1, int x2, int y2) {     return sum[x1][y1] - sum[x2 + 1][y1] - sum[x1][y2 + 1] + sum[x2 + 1][y2 + 1];   }   bool check(int a, int b, int x, int y) {     while (1) {       if (x + a - 1 > n || y + b - 1 > m) return 0;       if (getsum(x, y, x + a - 1, y + b - 1) != a * b) return 0;       if (getsum(x + a, y, n, y) > 0 && getsum(x, y + b, x, m) > 0) return 0;       if (sum[x + a][y] == 0 && sum[x][y + b] == 0) break;       if (getsum(x + a, y, n, y) > 0) {         x++;         if (getsum(x + a - 1, y, x + a - 1, y + b - 1) > 0 &&             getsum(x + a - 1, y, x + a - 1, y + b - 1) != b)           return 0;       } else {         y++;         if (getsum(x, y + b - 1, x + a - 1, y + b - 1) > 0 &&             getsum(x, y + b - 1, x + a - 1, y + b - 1) != a)           return 0;       }     }     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , mp[i] + 1);     memset(sum, 0, sizeof(sum));     int x0, y0;     x0 = y0 = 10000;     for (int i = n; i >= 1; i--)       for (int j = m; j >= 1; j--) {         sum[i][j] =             sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1] + (mp[i][j] ==  X );         if (mp[i][j] ==  X ) {           x0 = min(x0, i);           y0 = min(y0, j);         }       }     int ans = n * m + 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (i * j >= ans) continue;         if (check(i, j, x0, y0)) ans = i * j;       }     if (ans > n * m)       printf( -1 n );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int c = 1, flag = 0, flag1 = 0, flag2 = 0, flag3 = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  U ) {         if (flag1 == 1) {           c++;           flag2 = 0, flag3 = 0, flag1 = 0;         }         flag = 1;       }       if (s[i] ==  D ) {         if (flag == 1) {           c++;           flag2 = 0, flag3 = 0, flag = 0;         }         flag1 = 1;       }       if (s[i] ==  L ) {         if (flag2 == 1) {           flag = 0, flag1 = 0, flag2 = 0;           c++;         }         flag3 = 1;       }       if (s[i] ==  R ) {         if (flag3 == 1) {           c++;           flag1 = 0, flag = 0, flag3 = 0;         }         flag2 = 1;       }     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   int n, k, s;   int main() {     scanf( %d%d , &k, &n);     while (n > k && n % k == 0) {       s++;       n /= k;     }     if (n != k)       printf( NO n );     else       printf( YES n%d n , s);   }


#include <bits/stdc++.h>   using namespace std;   template <class __Ty>   bool minimize(__Ty& a, __Ty b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class __Ty>   bool maximize(__Ty& a, __Ty b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int N = 2003;   const int mod = 1e9 + 7;   int f[N][N] = {0};   int n, k;   vector<int> g[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= i; ++j)         if (i % j == 0) g[i].push_back(j);     }     for (int j = 1; j <= n; ++j) f[1][j] = 1;     for (int i = 2; i <= k; ++i)       for (int j = 1; j <= n; ++j) {         for (int v : g[j]) {           f[i][j] = (f[i][j] + f[i - 1][v]) % mod;         }       }     int ans = 0;     for (int i = 1; i <= n; ++i) ans = (ans + f[k][i]) % mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using int64 = long long;   template <class T>   struct Matrix {     vector<vector<T> > A;     Matrix() {}     Matrix(size_t n, size_t m) : A(n, vector<T>(m, 0)) {}     Matrix(size_t n) : A(n, vector<T>(n, 0)){};     size_t height() const { return (A.size()); }     size_t width() const { return (A[0].size()); }     inline const vector<T> &operator[](int k) const { return (A.at(k)); }     inline vector<T> &operator[](int k) { return (A.at(k)); }     static Matrix I(size_t n) {       Matrix mat(n);       for (int i = 0; i < n; i++) mat[i][i] = 1;       return (mat);     }     Matrix &operator+=(const Matrix &B) {       size_t n = height(), m = width();       assert(n == B.height() && m == B.width());       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) (*this)[i][j] += B[i][j];       return (*this);     }     Matrix &operator-=(const Matrix &B) {       size_t n = height(), m = width();       assert(n == B.height() && m == B.width());       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) (*this)[i][j] -= B[i][j];       return (*this);     }     Matrix &operator*=(const Matrix &B) {       size_t n = height(), m = B.width(), p = width();       assert(p == B.height());       vector<vector<T> > C(n, vector<T>(m, 0));       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           for (int k = 0; k < p; k++)             C[i][j] = (C[i][j] + (*this)[i][k] * B[k][j]);       A.swap(C);       return (*this);     }     Matrix &operator^=(long long k) {       Matrix B = Matrix::I(height());       while (k > 0) {         if (k & 1) B *= *this;         *this *= *this;         k >>= 1LL;       }       A.swap(B.A);       return (*this);     }     Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }     Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }     Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }     Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); }     friend ostream &operator<<(ostream &os, Matrix &p) {       size_t n = p.height(), m = p.width();       for (int i = 0; i < n; i++) {         os <<  [ ;         for (int j = 0; j < m; j++) {           os << p[i][j] << (j + 1 == m ?  ] n  :  , );         }       }       return (os);     }     T determinant() {       Matrix B(*this);       assert(width() == height());       T ret = 1;       for (int i = 0; i < width(); i++) {         int idx = -1;         for (int j = i; j < width(); j++) {           if (B[j][i] != 0) idx = j;         }         if (idx == -1) return (0);         if (i != idx) {           ret *= -1;           swap(B[i], B[idx]);         }         ret *= B[i][i];         T vv = B[i][i];         for (int j = 0; j < width(); j++) {           B[i][j] /= vv;         }         for (int j = i + 1; j < width(); j++) {           T a = B[j][i];           for (int k = 0; k < width(); k++) {             B[j][k] -= B[i][k] * a;           }         }       }       return (ret);     }   };   template <int mod>   struct ModInt {     int x;     ModInt() : x(0) {}     ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}     ModInt &operator+=(const ModInt &p) {       if ((x += p.x) >= mod) x -= mod;       return *this;     }     ModInt &operator-=(const ModInt &p) {       if ((x += mod - p.x) >= mod) x -= mod;       return *this;     }     ModInt &operator*=(const ModInt &p) {       x = (int)(1LL * x * p.x % mod);       return *this;     }     ModInt &operator/=(const ModInt &p) {       *this *= p.inverse();       return *this;     }     ModInt operator-() const { return ModInt(-x); }     ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }     ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }     ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }     ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }     bool operator==(const ModInt &p) const { return x == p.x; }     bool operator!=(const ModInt &p) const { return x != p.x; }     ModInt inverse() const {       int a = x, b = mod, u = 1, v = 0, t;       while (b > 0) {         t = a / b;         a -= t * b;         swap(a, b);         u -= t * v;         swap(u, v);       }       return ModInt(u);     }     friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {       return os << p.x;     }     friend istream &operator>>(istream &is, ModInt<mod> &a) {       long long x;       is >> x;       a = ModInt<mod>(x);       return (is);     }   };   const int mod = 1e9 + 7;   using modint = ModInt<mod>;   int main() {     int64 N, M;     cin >> N >> M;     map<int64, vector<pair<int, int> > > add;     for (int i = 0; i < N; i++) {       int64 A, L, R;       cin >> A >> L >> R;       --A;       add[L - 1].emplace_back(A, 1);       add[R].emplace_back(A, -1);     }     add[1].emplace_back(-1, -1);     add[M].emplace_back(-1, -1);     vector<modint> sum(3, 0);     Matrix<modint> mat(3, 3);     vector<int> inc(3, 0);     int64 pv = -1;     for (auto &p : add) {       for (auto &v : p.second) {         if (~v.first) inc[v.first] += v.second;       }       Matrix<modint> mat2(3, 3);       for (int i = 0; i < 3; i++) {         for (int j = -1; j <= 1; j++) {           int k = i + j;           if (k < 0 || k >= 3) continue;           if (inc[k] == 0) mat2[i][k] = 1;         }       }       if (~pv) {         mat ^= p.first - pv;         vector<modint> sum2(3);         for (int i = 0; i < 3; i++) {           for (int j = 0; j < 3; j++) {             sum2[j] += sum[i] * mat[i][j];           }         }         sum.swap(sum2);       } else {         sum[1] = 1;       }       mat = mat2;       pv = p.first;     }     cout << sum[1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   struct Matrix {     int n;     vector<vector<long long>> a;     Matrix(int _n) {       n = _n;       a = vector<vector<long long>>(n, vector<long long>(n, 0));     }     Matrix operator+(Matrix o) {       Matrix ans(n);       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) ans[i][j] = a[i][j] + o[i][j];       ans.modulate();       return ans;     }     Matrix operator*(Matrix o) {       Matrix ans(n);       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           for (int k = 0; k < n; k++) ans[i][j] += a[i][k] * o[k][j];       ans.modulate();       return ans;     }     vector<long long>& operator[](int index) { return a[index]; }     void modulate() {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) a[i][j] %= MOD;     }     void eye() {       a = vector<vector<long long>>(n, vector<long long>(n, 0));       for (int i = 0; i < n; i++) a[i][i] = 1;     }   };   Matrix mod_pow(Matrix a, long long e) {     Matrix ans(2);     ans.eye();     while (e) {       if (e & 1) ans = ans * a;       a = a * a;       e >>= 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long A, B, n, x;     cin >> A >> B >> n >> x;     Matrix ans(2);     ans[0][0] = A;     ans[0][1] = B;     ans[1][1] = 1;     ans = mod_pow(ans, n);     cout << (ans[0][0] * x + ans[0][1]) % MOD <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000010];   int main() {     char str;     int i, n, x, maxn = 0, num = 0;     cin >> n;     while (n--) {       cin >> str >> x;       if (str ==  + ) {         num++;         a[x] = 1;         maxn = max(maxn, num);       } else {         if (a[x]) {           num--;           a[x] = 0;         } else {           maxn++;         }       }     }     cout << maxn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void chkmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void chkmax(T &a, T b) {     if (a < b) a = b;   }   int n;   double q0, a0, b0;   double y_best[6000], x[6000], chain[6000];   double quad_min(double a, double b, double c) { return -b / (2.0 * a); }   double bound(double h, double v) { return max(1.0 + h, min(q0, v)); }   void pull_chain(int j0, double h, double a, double b, double c,                   double &res_yopt, int &res_j) {     for (int j = j0; j >= 0; j--) {       double yi_nat = bound(h, quad_min(a, b, c));       if (y_best[j] < yi_nat - h - b0) {         double ny = x[j] + h + b0;         chain[j] = b0;         h += b0;         a += 1.0;         b += -2.0 * ny;         c += ny * ny;       } else if (y_best[j] > yi_nat - h - a0) {         double ny = x[j] + h + a0;         chain[j] = a0;         h += a0;         a += 1.0;         b += -2.0 * ny;         c += ny * ny;       } else {         res_yopt = yi_nat;         res_j = j;         return;       }     }     res_yopt = bound(h, quad_min(a, b, c));     res_j = -1;   }   void fill_in_y(int i) {     while (i >= 0) {       double anything;       int j;       pull_chain(i - 1, 0.0, 1.0, -2.0 * x[i], x[i] * x[i], anything, j);       for (int k = i - 1; k > j; k--) {         y_best[k] = y_best[k + 1] - chain[k];       }       i = j;     }   }   int main() {     scanf( %d%lf%lf%lf , &n, &q0, &a0, &b0);     for (int i = 0; i < n; i++) scanf( %lf , &x[i]);     for (int i = 0; i < n; i++) y_best[i] = x[i];     for (int i = 0; i < n; i++) chain[i] = 0.0;     for (int i = 1; i < n; i++) {       double yopt;       int j;       pull_chain(i - 1, 0.0, 1.0, -2.0 * x[i], x[i] * x[i], yopt, j);       y_best[i] = yopt;     }     fill_in_y(n - 1);     double total = 0.0;     for (int i = 0; i < n; i++) {       total = total + (y_best[i] - x[i]) * (y_best[i] - x[i]);     }     for (int i = 0; i < n; i++) {       printf( %.8f  , y_best[i]);     }     printf(  n%.8lf n , total);     return 0;   }