#include <bits/stdc++.h>   using namespace std;   int dp[128][128][15];   int board[128][128];   int dy[] = {-1, 1};   int N, M, K;   int solve(int x, int y, int k) {     if (dp[x][y][k] != -2) return dp[x][y][k];     if (x == 0) {       if (board[x][y] % K == k)         return dp[x][y][k] = board[x][y];       else         return dp[x][y][k] = -1;     }     int curr = board[x][y];     int ans = -1;     int req = (K + k - (curr % K)) % K;     for (int i = 0; i < 2; i++) {       int nx = x - 1, ny = y + dy[i];       if (nx < 0 || ny < 0 || nx >= N || ny >= M) continue;       int ret = solve(nx, ny, req);       if (ret != -1) {         ans = max(ans, curr + ret);       }     }     return dp[x][y][k] = ans;   }   void print(int x, int y, int k) {     int curr = board[x][y];     int req = (K + k - (curr % K)) % K;     for (int i = 0; i < 2; i++) {       int nx = x - 1, ny = y + dy[i];       if (nx < 0 || ny < 0 || nx >= N || ny >= M) continue;       if (dp[x][y][k] == curr + dp[nx][ny][req]) {         if (i == 0)           cout <<  L ;         else           cout <<  R ;         print(nx, ny, req);         return;       }     }   }   int main() {     cin >> N >> M >> K;     K += 1;     for (int i = 0; i < N; i++) {       string s;       cin >> s;       for (int j = 0; j < M; j++) board[i][j] = s[j] -  0 ;     }     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++)         for (int k = 0; k < K; k++) dp[i][j][k] = -2;     int ans = -1;     int maxI = 0;     for (int i = 0; i < M; i++) {       int ret = solve(N - 1, i, 0);       if (ret != -1 && ret > ans) {         ans = ret;         maxI = i;       }     }     if (ans == -1) {       cout << -1 << endl;       return 0;     }     cout << ans << endl;     cout << maxI + 1 << endl;     print(N - 1, maxI, 0);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gr[110][110];   int main() {     int n, m, a[110], b[100];     cin >> n >> m;     int nn = 0;     int mm = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       nn ^= a[i];     }     for (int i = 0; i < m; i++) {       scanf( %d , &b[i]);       mm ^= b[i];     }     if (nn != mm) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     memset(gr, 0, sizeof gr);     for (int i = 0; i < n; i++) {       gr[i][m - 1] = a[i];     }     for (int j = 0; j < m; j++) {       gr[n - 1][j] = b[j];     }     gr[n - 1][m - 1] = mm ^ b[m - 1] ^ a[n - 1];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         printf( %d  , gr[i][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int Get() {     int res = 0, q = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) q = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return res * q;   }   const double eps = 1e-3, pi = M_PI;   const int oo = (int)2e9, mod = (int)1e9 + 7;   const long long INF = (long long)1e17;   struct vec {     double x, y;   };   struct line {     vec p, t;   };   vec operator+(const vec &a, const vec &b) {     return (vec){a.x + b.x, a.y + b.y};   }   vec operator-(const vec &a, const vec &b) {     return (vec){a.x - b.x, a.y - b.y};   }   vec operator*(const double &a, const vec &b) { return (vec){a * b.x, a * b.y}; }   double operator/(const vec &a, const vec &b) {     return fabs(b.x) > 0 ? a.x / b.x : a.y / b.y;   }   double operator*(const vec &a, const vec &b) { return a.x * b.y - a.y * b.x; }   double operator^(const vec &a, const vec &b) { return a.x * b.x + a.y * b.y; }   bool operator==(const vec &a, const vec &b) { return a.x == b.x && a.y == b.y; }   inline bool Equal(double a, double b) { return fabs(a - b) < eps; }   inline double Dist(vec a) { return sqrt(((a.x) * (a.x)) + ((a.y) * (a.y))); }   inline vec Line_Cross(line a, line b) {     vec P = b.p - a.p;     double t = (P * b.t) / (a.t * b.t);     return a.p + t * a.t;   }   vec Rot(vec x, double y) {     vec d;     d.x = x.x * cos(y) - x.y * sin(y);     d.y = x.y * cos(y) + x.x * sin(y);     return d;   }   double Random() { return 0.95 + (double)(rand() / 5 * 2) / (double)RAND_MAX; }   const int N = 100;   line a[N + 10];   int n;   double ang, l[N + 10];   int main() {     srand(time(NULL));     scanf(          %d            n ,         &n);     if (n <= 4) return printf( No solution n ), 0;     ang = 2 * pi / n;     a[1].t = (vec){400, 0}, a[1].p = (vec){0, 0};     for (int i = (2), end = (n); i <= end; ++i) {       a[i].p = a[i - 1].p + a[i - 1].t;       a[i].t = Rot(a[i - 1].t, ang);     }     for (;;) {       bool ext = 1;       for (int i = (1), end = (n); i <= end; ++i) {         l[i] = Dist(a[i].t);         bool flag = 0;         for (int j = (1), end = (i - 1); j <= end; ++j)           if (Equal(l[i], l[j])) {             flag = 1;             break;           }         if (!flag) continue;         ext = 0;         int nx = i % n + 1, nt = nx % n + 1;         double p = Random();         vec cr;         for (;; p = Random()) {           if (fabs(p - 1) < eps) continue;           vec np = a[i].p + p * a[i].t;           line next = (line){np, a[nx].t};           cr = Line_Cross(next, a[nt]);           vec dt = cr - np;           if ((dt / a[nx].t) < eps) continue;           a[i].t = p * a[i].t, a[nx].p = a[i].p + a[i].t, a[nt].p = cr;           a[nx].t = a[nt].p - a[nx].p;           l[i] = Dist(a[i].t), l[nx] = Dist(a[nx].t), l[nt] = Dist(a[nt].t);           if (l[i] - 1 < eps || 1000 - l[i] < eps) continue;           if (l[nx] - 1 < eps || 1000 - l[nx] < eps) continue;           if (l[nt] - 1 < eps || 1000 - l[nt] < eps) continue;           bool ck = 1;           for (int j = (1), end = (n); j <= end; ++j)             if (j != i)               if (Equal(l[i], l[j])) {                 ck = 0;                 break;               }           if (ck) break;         }       }       if (ext) break;     }     for (int i = (1), end = (n); i <= end; ++i)       printf(            %.10lf                           %.10lf              n ,           a[i].p.x, a[i].p.y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   vector<long long> fib = {1, 2};   map<pair<long long, long long>, long long> dp;   long long f(long long n, int j) {     if (fib[j] > n) return 0;     if (fib[j] == n) return 1;     long long tot = 0;     for (int j2 = 0; j2 < j; j2++) {       tot += f(n - fib[j], j2);     }     return tot;   }   int f2(long long n) {     int sz = fib.size();     vector<bool> cur(sz);     for (int i = sz - 1; i >= 0; i--) {       if (n >= fib[i]) {         cur[i] = 1;         n -= fib[i];       }     }     queue<vector<bool>> q;     q.push(cur);     int ans = 0;     set<vector<bool>> vis;     vis.insert(cur);     while (q.size()) {       ans++;       cur = q.front();       q.pop();       for (int i = 2; i < sz; i++) {         if (cur[i] && !cur[i - 1] && !cur[i - 2]) {           auto cur2 = cur;           cur2[i] = 0;           cur2[i - 1] = 1;           cur2[i - 2] = 1;           auto it = vis.find(cur2);           if (it == vis.end()) {             vis.insert(cur2);             q.push(cur2);           }         }       }     }     return ans;   }   long long f3(long long n) {     int sz = fib.size();     vector<bool> cur(sz);     vector<int> v;     for (int i = sz - 1; i >= 0; i--) {       if (n >= fib[i]) {         cur[i] = 1;         v.push_back(i);         n -= fib[i];       }     }     reverse(v.begin(), v.end());     int m = v.size();     vector<long long> dp1(m), dp2(m);     dp1[0] = 1;     dp2[0] = v[0] / 2;     for (int i = 1; i < m; i++) {       dp1[i] = dp1[i - 1] + dp2[i - 1];       dp2[i] = ((v[i] - v[i - 1]) / 2) * dp2[i - 1] +                ((v[i] - v[i - 1] - 1) / 2) * dp1[i - 1];     }     return dp1[m - 1] + dp2[m - 1];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     while (fib.back() < 1e18) {       int n = fib.size();       fib.push_back(fib[n - 1] + fib[n - 2]);     }     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long ans = 0;       cout << f3(n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     scanf( %d , &n);     vector<vector<int> > p(n);     for (int i = 0; i < n; i++) {       int sz;       scanf( %d , &sz);       p[i].resize(sz);       for (int j = 0; j < sz; j++) scanf( %d , &p[i][j]);     }     for (int i = 0; i < n; i++) {       bool can = true;       for (int j = 0; j < n; j++) {         if (i == j || p[j].size() > p[i].size()) continue;         int has[101] = {0};         bool ok = true;         for (int k = 0; k < p[j].size(); k++) has[p[j][k]]++;         for (int k = 0; k < p[i].size(); k++) has[p[i][k]]++;         for (int k = 0; k < p[j].size(); k++)           if (has[p[j][k]] != 2) ok = false;         can &= !(ok);       }       if (can)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       getline(cin >> ws, s);       string one =  1 , two =  1 ;       int prevOne = 1, prevTwo = 1;       for (int i = 1; i < n; i++) {         int num = s[i] -  0 ;         if (prevOne == prevTwo) {           if (num == 2) {             one +=  1 ;             two +=  1 ;             prevOne = 1;             prevTwo = 1;           } else if (num == 1) {             one +=  1 ;             two +=  0 ;             prevOne = 1;             prevTwo = 0;           } else {             one +=  0 ;             two +=  0 ;             prevOne =  0 ;             prevTwo =  0 ;           }         } else {           for (int j = i; j < n; j++) {             one +=  0 ;             two += s[j];           }           break;         }       }       cout << one <<   n  << two <<   n ;     }   }


#include<bits/stdc++.h>      #define y1 dmytxdy   #define pb push_back   #define fi first   #define se second   #define mp make_pair      using namespace std;      typedef long long ll;   typedef unsigned long long ull;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   typedef long double ld;      template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}   template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}      int readint(){    int x=0,f=1; char ch=getchar();    while(ch< 0 ||ch> 9 ){if(ch== - )f=-1;ch=getchar();}    while(ch>= 0 &&ch<= 9 ){x=x*10+ch- 0 ;ch=getchar();}    return x*f;   }      const int cys=998244353,g=3,invg=(cys+1)/g;   int n,k,N,l;   ll fac[100005],inv[100005];   int A[300000],B[300000],r[300000];      ll mod(ll x){return x>=cys?x-cys:x;}      ll qpow(ll x,ll p){    ll ret=1;    for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;    return ret;   }      void init(int m){    l=0;    for(N=1;N<m;N<<=1) l++;    for(int i=1;i<N;i++) r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));   }      void ntt(int *A,int N,int f){    for(int i=1;i<N;i++) if(i<r[i]) swap(A[i],A[r[i]]);    for(int i=1;i<N;i<<=1){     int wn=qpow(f>0?g:invg,(cys-1)/(i<<1));     for(int j=0;j<N;j+=(i<<1)){      for(int k=j,w=1;k<j+i;k++,w=1ll*w*wn%cys){       int x=A[k],y=1ll*w*A[k+i]%cys;       A[k]=mod(x+y); A[k+i]=mod(x+cys-y);      }     }    }    if(f<0){     ll invn=qpow(N,cys-2);     for(int i=0;i<N;i++) A[i]=A[i]*invn%cys;    }   }      int main(){    n=readint(); k=readint();    fac[0]=inv[0]=1;    for(int i=1;i<=k;i++) fac[i]=fac[i-1]*i%cys;    inv[k]=qpow(fac[k],cys-2);    for(int i=k-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%cys;    for(int i=0;i<=k;i++) A[i]=i&1?cys-inv[i]:inv[i];    for(int i=0;i<=k;i++) B[i]=qpow(i,k)*inv[i]%cys;    init(k+k+1);    ntt(A,N,1); ntt(B,N,1);    for(int i=0;i<N;i++) A[i]=1ll*A[i]*B[i]%cys;    ntt(A,N,-1);    ll now=1,ans=0;    for(int i=1;i<=k;i++){     now=now*(n-i+1)%cys;     if(!now) break;     ans=(ans+A[i]*now%cys*qpow(n+1,n-i))%cys;    }    printf( %lld n ,ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str1[100 + 10], str2[100 + 10];   int main() {     int m, s;     while (~scanf( %d%d , &m, &s)) {       for (int i = 0; i < m; i++) str1[i] = str2[i] =  0 ;       int ss = s;       if (m == 1 && s == 0) {         printf( 0 0 n );         continue;       }       if (s == 0 || s > m * 9) {         printf( -1 -1 n );         continue;       }       for (int i = 0; i < m; i++) {         if (ss > 9) {           str1[i] =  9 ;           ss -= 9;         } else {           str1[i] = ss +  0 ;           ss -= ss;         }       }       ss = s;       for (int i = m - 1; i >= 0; i--) {         if (ss > 9) {           str2[i] =  9 ;           ss -= 9;         } else {           if (i == 0) {             str2[i] =  0  + ss;             ss -= ss;           } else {             str2[i] =  0  + ss - 1;             ss -= ss - 1;             str2[0] =  1 ;             break;           }         }       }       str1[m] = str2[m] =   0 ;       printf( %s %s n , str2, str1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int m;     cin >> n >> m;     vector<vector<bool>> arr(n, vector<bool>(m, 0));     long long int answ = 0;     vector<int> hor(n, 0);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int temp;         cin >> temp;         if (!temp) {           hor[i]++;         }         arr[i][j] = (bool)temp;       }     }     vector<int> vert(m, 0);     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++) {         if (!arr[i][j]) {           vert[j]++;         }       }     }     for (int i = 0; i < n; i++) {       int past = 0;       for (int j = 0; j < m; j++) {         if (arr[i][j]) {           answ += hor[i] - past;           break;         } else {           past++;         }       }       past = 0;       for (int j = m - 1; j >= 0; j--) {         if (arr[i][j]) {           answ += hor[i] - past;           break;         } else {           past++;         }       }     }     for (int j = 0; j < m; j++) {       int past = 0;       for (int i = 0; i < n; i++) {         if (arr[i][j]) {           answ += vert[j] - past;           break;         } else {           past++;         }       }       past = 0;       for (int i = n - 1; i >= 0; i--) {         if (arr[i][j]) {           answ += vert[j] - past;           break;         } else {           past++;         }       }     }     cout << answ << endl;     return 0;   }


#include <bits/stdc++.h>   char a[1005], b[1005];   int alen, blen, cnt1, cnt2;   int gcd(int a, int b) {     if (a % b == 0)       return b;     else       return gcd(b, a % b);   }   int lcm(int a, int b) { return a * b / gcd(a, b); }   void work(int t) {     int i;     for (i = 0; i < t; i++) switch (a[i % alen] - b[i % blen]) {         case 1:           cnt1++;           break;         case 2:           cnt1++;           break;         case 3:           cnt2++;           break;         case -1:           cnt2++;           break;         case -2:           cnt2++;           break;         case -3:           cnt1++;           break;       }   }   int main() {     int i, n, t, s;     while (~scanf( %d , &n)) {       cnt1 = 0, cnt2 = 0;       scanf( %s%s , a, b);       alen = strlen(a);       blen = strlen(b);       t = lcm(alen, blen);       work(t);       s = n / t;       cnt1 *= s;       cnt2 *= s;       work(n % t);       printf( %d %d n , cnt1, cnt2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using int64 = long long;   int main() {     string s;     cin >> s;     int v[26] = {};     for (auto &c : s) v[c -  a ]++;     deque<int> odd;     for (int i = 0; i < 26; i++) {       if (v[i] % 2 == 1) odd.emplace_back(i);     }     while (odd.size() >= 2) {       int p = odd.front();       int q = odd.back();       odd.pop_front();       odd.pop_back();       v[p]++;       v[q]--;     }     string pre;     for (int i = 0; i < 26; i++) {       int t = v[i] / 2;       while (t--) pre += (char)(i +  a );     }     cout << pre;     if (odd.size()) cout << (char)( a  + odd[0]);     reverse(begin(pre), end(pre));     cout << pre << endl;   }


#include <bits/stdc++.h>   using namespace ::std;   const long double PI = acos(-1);   const long long MOD = 1000000000 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long add(long long a, long long b, long long m = MOD) {     return (a % m + b % m + 2 * m) % m;   }   long long mul(long long a, long long b, long long m = MOD) {     return ((a % m + m) * (b % m + m)) % m;   }   long long pow_mod(long long a, long long b, long long m = MOD) {     long long res = 1LL;     a = a % m;     while (b) {       if (b & 1) res = mul(res, a, m);       b >>= 1;       a = mul(a, a, m);     }     return res;   }   long long fastexp(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) res = res * a;       b >>= 1;       a *= a;     }     return res;   }   int gcdExtendido(int a, int b, int *x, int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     int x1, y1;     int gcd = gcdExtendido(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int modInverso(int a, int m) {     int x, y;     int g = gcdExtendido(a, m, &x, &y);     if (g != 1)       return -1;     else       return (x % m + m) % m;   }   const int MAX = 1000000 + 5;   const int N = 100 + 5;   int n, m;   int v[N];   long double memo[2][MAX];   int main() {     scanf( %d %d , &(n), &(m));     int S = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &(v[i]));       S += v[i];     }     long double ans = 0.0;     if (m > 1) {       memo[0][0] = m - 1;       for (int i = 0; i < n; i++) {         int next = (i + 1) & 1;         int act = i & 1;         for (int j = 1; j <= n * m; j++) {           memo[act][j] += memo[act][j - 1];         }         for (int j = 0; j <= n * m; j++) {           memo[next][j] = 0.0;         }         int next_chosen = v[i + 1];         for (int j = 0; j <= i * m; j++) {           memo[next][j + 1] += memo[act][j] / (m - 1);           memo[next][j + m + 1] -= memo[act][j] / (m - 1);           memo[next][j + next_chosen] -= memo[act][j] / (m - 1);           memo[next][j + next_chosen + 1] += memo[act][j] / (m - 1);         }       }       for (int j = 1; j <= n * m; j++) {         memo[n & 1][j] += memo[n & 1][j - 1];       }       for (int j = 0; j < S; j++) {         ans += memo[n & 1][j];       }     }     ans += 1.0;     printf( %.16Lf n , ans);     return 0;   }


#include <bits/stdc++.h>   int debugnum = 0;   using namespace std;   const long long MOD = 998244353;   inline long long add(long long a, long long b) { return (a + b) % MOD; }   int toint(bitset<10> bs) {     int ret = 0;     for (int i = 9; i >= 0; i--) {       ret = (ret << 1) | bs[i];     }     return ret;   }   long long chpow(long long a, long long b) {     long long ret = 1;     for (long long i = 1; i <= b; i <<= 1) {       if (i & b) ret = ret * a % MOD;       a = a * a % MOD;     }     return ret;   }   long long DP[20][10][1024];   long long sum[20][10][1024];   void init() {     memset(DP, 0, sizeof DP);     memset(sum, 0, sizeof sum);     for (int i = (0); i < (10); i++) DP[0][i][1 << i] = 1;     for (int i = (0); i < (10); i++) sum[0][i][1 << i] = i;     for (int i = (1); i < (19); i++) {       for (int j = (0); j < (10); j++) {         for (int S = (0); S < (1024); S++) {           long long &tmp = DP[i][j][S];           long long &tmp2 = sum[i][j][S];           bitset<10> bs = S, bs1;           if (bs[j] == 0) continue;           bs1 = bs;           bs1[j] = 0;           for (int j1 = (0); j1 < (10); j1++) {             tmp += DP[i - 1][j1][S] + DP[i - 1][j1][toint(bs1)];             tmp2 += sum[i - 1][j1][S] + sum[i - 1][j1][toint(bs1)];             tmp %= MOD;             tmp2 %= MOD;           }           tmp2 += tmp * (j * chpow(10, i) % MOD) % MOD;           tmp2 %= MOD;         }       }     }   }   long long solve(long long N, long long K, bitset<10> S0, long long extra = 0) {     long long ret = 0;     long long Ai = N, p = 1, i = 0;     while (Ai >= 10) Ai /= 10, p *= 10, i++;     if (i == 0) {       long long cnt = 0;       for (int i = (0); i < (Ai + 1); i++) {         if ((S0 | bitset<10>(1 << i)).count() <= K) cnt += i + extra;       }       cnt %= MOD;       return cnt;     }     if (S0.count() == 0) {       unsigned long long p = 1;       for (int i = (0); i < (19); i++) {         for (int j = (1); j < (10); j++) {           if ((1LL + j) * p > N) break;           for (int S1 = (0); S1 < (1024); S1++) {             bitset<10> S = S1;             if (S.count() <= K) {               ret += sum[i][j][S1];               ret %= MOD;             }           }         }         p *= 10;       }     } else {       for (int j = (0); j < (Ai); j++) {         for (int S1 = (0); S1 < (1024); S1++) {           bitset<10> S = bitset<10>(S1) | S0;           if (S.count() <= K) {             ret += DP[i][j][S1] * extra % MOD + sum[i][j][S1];             ret %= MOD;           }         }       }     }     S0[Ai] = 1;     if ((N - Ai * p) * 10 < p) S0[0] = 1;     if (N >= 10) ret += solve(N - Ai * p, K, S0, (extra + Ai * p % MOD) % MOD);     ret %= MOD;     return ret;   }   int main() {     init();     long long N, M, K;     while (cin >> N >> M >> K) {       N--;       long long output = (MOD + solve(M, K, 0) - solve(N, K, 0)) % MOD;       cout << output << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans1 = 0, ans2 = 0, x, y;   char s[1100], m[1100];   int main() {     scanf( %d , &n);     scanf( %s%s , s, m);     sort(s, s + n);     sort(m, m + n);     x = y = 0;     while (x < n && y < n) {       if (m[y] >= s[x]) {         x++;         y++;       } else         y++, ans1++;     }     x = y = 0;     while (x < n && y < n) {       if (m[y] > s[x]) {         x++;         y++;         ans2++;       } else         y++;     }     printf( %d n%d , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void doRoutine() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   void minus1(string &s) {     long long i = (long long)s.size() - 1;     while (i >= 0 && s[i] ==  0 ) {       s[i] =  9 ;       --i;     }     --s[i];     if (i == 0 && s[i] ==  0 ) {       s.erase(s.begin());     }   }   void solve_ez(string &s) {     long long n = s.size();     string t(n - 2,  9 );     cout << t << endl;   }   void solve(string &s) {     if (s.size() % 2 == 1) {       cout << string((long long)s.size() - 1,  9 ) << endl;       return;     }     long long n = s.size();     vector<long long> pref(n + 1);     for (long long i = 0; i < n; ++i) {       pref[i + 1] = pref[i] + (s[i] -  0 );     }     vector<long long> odd(10);     long long max_pref = 0;     for (long long i = 0; i < n; ++i) {       long long dig = s[i] -  0 ;       odd[dig] = (odd[dig] + 1) % 2;       vector<long long> odds;       for (long long c = 0; c < 10; ++c) {         if (odd[c]) {           odds.push_back(c);         }       }       bool ok = false;       long long cnt = odds.size();       if (n - i - 1 >= cnt) {         if (pref[n - cnt] - pref[i + 1] > 0) {           ok = true;         } else {           ok = true;           for (long long j = 0; j < cnt; ++j) {             long long s_dig = (s[n - cnt + j] -  0 );             long long cur_dig = odds[j];             if (cur_dig < s_dig) {               break;             } else if (cur_dig > s_dig) {               ok = false;             }           }         }       }       if (!ok) {         break;       } else {         max_pref = i + 1;       }     }     if (max_pref == n) {       cout << s << endl;       return;     }     for (long long c = (s[max_pref] -  0 ) - 1; c >= (max_pref == 0 ? 1 : 0);          --c) {       fill(odd.begin(), odd.end(), 0);       for (long long i = 0; i < max_pref; ++i) {         long long dig = s[i] -  0 ;         odd[dig] = (odd[dig] + 1) % 2;       }       odd[c] = (odd[c] + 1) % 2;       vector<long long> odds;       for (long long x = 9; x >= 0; --x) {         if (odd[x]) {           odds.push_back(x);         }       }       if ((long long)odds.size() <= n - max_pref - 1) {         string res;         for (long long i = 0; i < max_pref; ++i) {           res.push_back(s[i]);         }         res.push_back((char)(c +  0 ));         for (long long i = 0; i < n - max_pref - 1 - (long long)odds.size();              ++i) {           res.push_back( 9 );         }         for (auto el : odds) {           res.push_back((char)(el +  0 ));         }         cout << res << endl;         return;       }     }     solve_ez(s);   }   signed main() {     doRoutine();     long long n;     cin >> n;     while (n--) {       string s;       cin >> s;       minus1(s);       solve(s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T &chmin(T &a, const T &b) {     return a = min(a, b);   }   template <typename T>   T &chmax(T &a, const T &b) {     return a = max(a, b);   }   template <typename T>   T gcd(const T a, const T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   T lcm(const T a, const T b) {     return a / gcd(a, b) * b;   }   template <typename T>   T ceil(const T a, const T b) {     return (a + b - 1) / b;   }   template <typename T>   long double dist(const T x1, const T y1, const T x2, const T y2) {     long double x = x1 - x2;     long double y = y1 - y2;     return sqrt(x * x + y * y);   }   template <typename T>   void aout(const T *a, const int n) {     for (int i = 0; i < (n); ++i) cout << a[i] <<    ;     cout <<   n ;   }   template <typename T>   void vout(const vector<T> &v) {     for (int i = 0; i < ((int)(v).size()); ++i) cout << v[i] <<    ;     cout <<   n ;   }   const int di4[4] = {-1, 0, 1, 0};   const int dj4[4] = {0, 1, 0, -1};   const int di8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};   const int dj8[8] = {0, 1, 1, 1, 0, -1, -1, -1};   const int dik[8] = {2, 1, -1, -2, -2, -1, 1, 2};   const int djk[8] = {1, 2, 2, 1, -1, -2, -2, -1};   const int maxn = 100100;   const int mod = 1e9 + 7;   const int inf = INT_MAX;   const long double eps = 1e-9;   const long double pi = acos(-1.0);   int n;   void solve() {     cin >> n;     long long ans = (long long)(n - 2) * (n - 2);     cout << (ans) <<   n ;   }   void init() {}   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(10);     cout << fixed;     int tc = 1;     for (int i = 1; i <= (tc); ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 15e4 + 5;   const int M = 3e2 + 5;   const long long NINF = -1e12 + 5;   long long dp[2][N], a[M], b[M], t[M], n, m, d, interval, curr, nxt;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> d;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i] >> t[i];     }     for (int i = 1; i <= m; i++) {       nxt = i & 1;       curr = nxt ^ 1;       interval = min(n, (t[i] - t[i - 1]) * d);       deque<long long> dq;       for (int j = 1; j <= interval; j++) {         while (!dq.empty() && dp[curr][dq.back()] <= dp[curr][j]) dq.pop_back();         dq.push_back(j);       }       for (int j = 1; j <= n; j++) {         int k = j + interval;         if (k <= n) {           while (!dq.empty() && dp[curr][dq.back()] <= dp[curr][k]) dq.pop_back();           dq.push_back(k);         }         dp[nxt][j] = dp[curr][dq.front()] + b[i] - abs(a[i] - j);         while (!dq.empty() && dq.front() <= (j - interval)) dq.pop_front();       }     }     long long ans = NINF;     for (int i = 1; i <= n; i++) ans = max(ans, dp[nxt][i]);     cout << ans <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] += i;     }     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) {       a[i] -= i;       if (i && a[i] < a[i - 1]) {         cout <<  :(  << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  W  && s[i + 1] ==  U  && s[i + 2] ==  B ) {         s.erase(i, 3);         i--;         cout <<    ;       } else         cout << s[i];     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     for (int i = (int)s.length() - 1, cnt = 0; i >= 0; --i) {       if (s[i] ==  0 )         ++cnt;       else if (cnt)         --cnt;       else         s[i] =  0 ;     }     cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXK = 55, MAXN = 111;   int K, X, N, M;   int second[MAXK], F[MAXK];   long long tmemo[MAXK];   long long times(int k) {     if (k < 2) return tmemo[k];     times(k - 1);     if (tmemo[k - 1] > X) return tmemo[k] = tmemo[k - 1];     F[k] = F[k - 2];     second[k] = second[k - 1];     tmemo[k] = tmemo[k - 1] + tmemo[k - 2];     if (second[k - 2] == 1 && F[k - 1] == 0) tmemo[k]++;     return tmemo[k];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> K >> X >> N >> M;     K--;     for (int i = 0; i <= (N + 1) / 2 - 1; i++) {       for (int j = 0; j <= (M + 1) / 2 - 1; j++) {         for (int back = 0; back <= 2; back++) {           for (int front = 0; front <= 2; front++) {             for (int b = 0; b <= 2; b++) {               for (int f = 0; f <= 2; f++) {                 memset(tmemo, 0, sizeof(tmemo));                 memset(second, 0, sizeof(second));                 memset(F, 0, sizeof(F));                 tmemo[0] = i;                 tmemo[1] = j;                 second[0] = back;                 second[1] = b;                 F[0] = front;                 F[1] = f;                 if (N == 1 && back != front) continue;                 if (M == 1 && b != f) continue;                 bool usefa = true, useba = true;                 bool usefb = true, usebb = true;                 if (i > 0 && 2 * i + 1 == N) {                   if (second[0] == 1) {                     F[0] = 1;                     usefa = false;                   } else                     useba = false;                 }                 if (j > 0 && 2 * j + 1 == M) {                   if (second[1] == 1) {                     F[1] = 1;                     usefb = false;                   } else                     usebb = false;                 }                 if (back == 0 && front == 1 && N == 2) tmemo[0]++;                 if (b == 0 && f == 1 && M == 2) tmemo[1]++;                 if (times(K) == X) {                   if (usefa) cout <<  CAG [F[0]];                   int done = usefa;                   for (int x = 0; x < i; x++) {                     cout <<  AC ;                     done += 2;                   }                   while (done + 1 < N) {                     cout <<  G ;                     done++;                   }                   if (done < N) cout <<  CAG [second[0]];                   cout <<   n ;                   if (usefb) cout <<  CAG [F[1]];                   done = usefb;                   for (int x = 0; x < j; x++) {                     cout <<  AC ;                     done += 2;                   }                   while (done + 1 < M) {                     cout <<  G ;                     done++;                   }                   if (done < M) cout <<  CAG [second[1]];                   cout <<   n ;                   return 0;                 }               }             }           }         }       }     }     cout <<  Happy new year! n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long rowNum[] = {-1, 0, 0, 1};   long long colNum[] = {0, -1, 1, 0};   int main() {     int n, d, h;     cin >> n >> d >> h;     if (d > n - 1 || d < h || d > 2 * h || (n > 2 && h < 2 && d == h)) {       cout <<  -1 n ;       return 0;     }     int prev = 0;     for (long long i = 1; i < h + 1; i++) {       cout << prev + 1 <<     << i + 1 << endl;       prev = i;     }     if (d == h) {       for (long long i = h + 1; i < n; i++) {         cout <<  2   << i + 1 << endl;       }       return 0;     }     prev = 0;     for (long long i = h + 1; i < d + 1; i++) {       cout << prev + 1 <<     << i + 1 << endl;       prev = i;     }     for (long long i = d + 1; i < n; i++) {       cout <<  1   << i + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int M = 1e5 + 10;   int n, m, vis[M * 12], ans[M * 12], tot;   vector<int> vt[10][M * 12], tmp;   vector<vector<int> > now, nxt;   void add(int x, int y, int id) {     while (id / 10) vt[id % 10][++tot].push_back(y), y = tot, id /= 10;     vt[id][x].push_back(y);   }   void bfs() {     vis[1] = 1;     now.push_back(vector<int>(1, 1));     while (!now.empty()) {       for (int p = 0; p < now.size(); p++) {         vector<int> a = now[p];         for (int w = 0; w < 10; w++) {           tmp.clear();           for (int i = 0; i < a.size(); i++) {             int x = a[i];             for (int j = 0; j < vt[w][x].size(); j++) {               int y = vt[w][x][j];               if (vis[y]) continue;               vis[y] = 1;               ans[y] = (10LL * ans[x] % mod + w) % mod;               tmp.push_back(y);             }           }           if (tmp.size()) nxt.push_back(tmp);         }       }       now = nxt;       nxt.clear();     }   }   int main(int argc, char const *argv[]) {     scanf( %d%d , &n, &m);     tot = n;     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y, i);       add(y, x, i);     }     bfs();     for (int i = 2; i <= n; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, C;   vector<pair<int, pair<int, int> > > V;   int A[505][505], R[505];   int main() {     int x, y, t;     scanf( %d %d , &N, &M);     memset(A, 40, sizeof A);     for (int i = 1; i <= M; i++) {       scanf( %d %d %d , &x, &y, &t);       A[x][y] = A[y][x] = t;       V.push_back(make_pair(t, make_pair(x, y)));     }     for (int i = 1; i <= N; i++) A[i][i] = 0;     for (int k = 1; k <= N; k++)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) A[i][j] = min(A[i][j], A[i][k] + A[k][j]);     for (int i = 1; i <= N; i++) {       memset(R, 0, sizeof R);       for (typeof(V.begin()) it = V.begin(); it != V.end(); it++) {         if (A[i][it->second.first] + it->first == A[i][it->second.second])           ++R[it->second.second];         if (A[i][it->second.second] + it->first == A[i][it->second.first])           ++R[it->second.first];       }       for (int j = i + 1; j <= N; j++) {         int ans = 0;         for (int k = 1; k <= N; k++)           if (A[i][k] + A[k][j] == A[i][j]) ans += R[k];         printf( %d  , ans);       }     }     cerr <<   nTime:   << (double)clock() / CLOCKS_PER_SEC <<   seconds.  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long int dp[5001][5001];   long long int f[5001];   long long int power(long long int x, long long int b) {     long long int res = 1;     while (b) {       if (b & 1) res = res * x % mod;       x = x * x % mod;       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     dp[0][0] = 1;     for (int i = 1; i <= 5000; i++)       for (int j = 1; j <= i; j++)         dp[i][j] =             ((dp[i - 1][j - 1] - dp[i - 1][j] * (i - 1)) % mod + mod) % mod;     f[0] = 1;     long long int fac = n;     long long int inv = power(m, mod - 2), p = inv;     for (int i = 1; i <= k; i++) {       f[i] = fac * p % mod;       for (int j = 1; j < i; j++) f[i] -= dp[i][j] * f[j] % mod;       f[i] = (f[i] % mod + mod) % mod;       fac = fac * (n - i) % mod;       p = inv * p % mod;     }     cout << f[k] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     set<char> S;     int ans = 0;     for (int i = 0; i <= s.size(); ++i) {       if (i == s.size() || isupper(s[i])) {         ans = max(ans, (int)S.size());         S.clear();       } else {         S.insert(s[i]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100000];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int cnt = 0;     if (a[0] != 0) cnt = 1;     for (int i = 1; i < n; i++) {       if (a[i] != 0) {         if (a[i] != a[i - 1]) cnt++;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using ll = int;   const ll mod = 1e15 + 7;   const ll N = 1e5 + 5;   const int base = 400;   using ull = unsigned long long;   using namespace std;   ll n, m, t, k, T, a[N], dp[N], lab[N], u, v, b[N], d[N], tong, cnt, q, fe[N],       f[N][20], g[N][20], h[N], P[N][20];   ll ans;   vector<ll> adj[N];   vector<pair<ll, ll> > kq;   void add(ll id, ll val) {     for (; id <= n; id += id & -id) fe[id] += val;   }   ll get(ll id) {     ll total = 0;     for (; id > 0; id -= id & -id) total += fe[id];     return total;   }   ll sum(ll l, ll r) { return get(r) - get(l - 1); }   void hop(ll u, ll v) {     lab[u] += lab[v];     lab[v] = u;   }   ll findp(ll u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); }   pair<ll, ll> p[N];   ll dis(pair<ll, ll> x, pair<ll, ll> y) {     return (x.first - y.first) * (x.first - y.first) +            (x.second - y.second) * (x.second - y.second);   }   ll getmn(ll l, ll r) {     ll total = mod;     for (int i = l; i < r; i++) {       for (int j = i + 1; j <= r; j++) total = min(total, dis(p[i], p[j]));     }     ans = min(ans, total);     return total;   }   void findmn(vector<pair<ll, ll> > pi) {     sort(pi.begin(), pi.end());     for (int i = 0; i < pi.size(); i++) {       for (int j = i + 1; j < pi.size(); j++) {         if ((p[i].first - p[j].first) * (pi[i].first - pi[j].first) > ans) break;         ans = min(ans, dis(pi[i], pi[j]));       }     }   }   ll cal(ll l, ll r) {     if (r - l <= 3) return getmn(l, r);     ll mid = (l + r) / 2;     ll total = min(cal(l, mid), cal(mid, r));     kq.clear();     for (int i = l; i <= r; i++) {       if ((p[i].first - p[mid].first) * (p[i].first - p[mid].first) <= ans)         kq.push_back({p[i].second, p[i].first});     }     findmn(kq);     total = min(total, ans);     return total;   }   void sol() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> P[i][0] >> t;       P[i][0] = max(P[i][0], (ll)0);       if (P[i][0]) h[i] = h[P[i][0]] + 1;       if (t == 0)         f[i][0] = 1;       else if (t == 1)         g[i][0] = 1;     }     for (int j = 1; j <= 18; j++) {       for (int i = 1; i <= n; i++) {         P[i][j] = P[P[i][j - 1]][j - 1];         f[i][j] = f[i][j - 1] & f[P[i][j - 1]][j - 1];         g[i][j] = g[i][j - 1] & g[P[i][j - 1]][j - 1];       }     }     cin >> m;     while (m-- > 0) {       cin >> q >> u >> v;       int x = 1, y = 1, z = 1, ui = u, vi = v;       for (int i = 18; i >= 0; i--) {         if (h[v] >= h[u] + (1 << i)) {           x &= f[v][i];           y &= g[v][i];           v = P[v][i];         }       }       for (int i = 18; i >= 0; i--) {         if (h[u] >= h[v] + (1 << i)) {           z &= f[u][i];           u = P[u][i];         }       }       if (u != v) {         for (int i = 18; i >= 0; i--) {           if (P[u][i] != 0 && P[u][i] != P[v][i]) {             x &= f[v][i];             y &= g[v][i];             z &= f[u][i];             u = P[u][i];             v = P[v][i];           }         }         x &= f[v][0];         y &= g[v][0];         z &= f[u][0];         u = P[u][0];         v = P[v][0];       }       if (q == 1) {         if (ui != vi && ui == u && x)           cout <<  YES  <<   n ;         else           cout <<  NO  <<   n ;       } else {         if (u != vi && z && y)           cout <<  YES  <<   n ;         else           cout <<  NO  <<   n ;       }     }   }   int main() {     if (fopen( pieaters                 .inp ,                r )) {       freopen(            pieaters             .inp ,            r , stdin);       freopen(            pieaters             .out ,            w , stdout);     }     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int ntest;     ntest = 1;     while (ntest-- > 0) sol();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, a, b, c, d;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c >> d;       int diff = n * (a - b), sum = n * (a + b);       if ((diff > c + d) || (sum < c - d))         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   template <class T>   void dispvector(vector<T> v) {     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout <<   n ;   }   template <class T>   void disparray(T *v, int n) {     for (int i = 0; i < n; i++) cout << v[i] <<    ;     cout <<   n ;   }   template <class T>   int sizeofarr(T *v) {     return sizeof(v) / sizeof(T);   }   signed main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     if (n % 2 == 0) {       cout <<  NO             <<   n ;       return 0;     } else {       cout <<  YES             <<   n ;       vector<long long int> arr(2 * n);       long long int num = 1;       long long int idx1 = 0;       long long int idx2 = n;       bool ok = true;       for (long long int i = 0; i < n; i++) {         if (ok) {           arr[idx1] = num;           arr[idx2] = num + 1;         } else {           arr[idx1] = num + 1;           arr[idx2] = num;         }         num += 2;         idx1++;         idx2++;         if (ok)           ok = false;         else           ok = true;       }       dispvector(arr);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long long p, q;       cin >> p >> q;       if (p % q != 0)         cout << p << endl;       else {         long long x = q;         long long ans = 1;         for (long long i = 2; i <= (long long)sqrt(x); i++) {           if (x % i == 0) {             while (x % i == 0) x /= i;             long long tp = p;             while (tp % q == 0) tp /= i;             ans = max(ans, tp);           }         }         if (x > 1) {           long long tp = p;           while (tp % q == 0) tp /= x;           ans = max(ans, tp);         }         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   mt19937 rnf(2106);   const int N = 200005, INF = 1000000009;   struct ban {     int x, y;   };   bool operator<(const ban& a, const ban& b) {     return make_pair(a.x, a.y) < make_pair(b.x, b.y);   }   double dist(const ban& a, const ban& b) {     return sqrt((a.x - b.x) * 1LL * (a.x - b.x) +                 (a.y - b.y) * 1LL * (a.y - b.y));   }   long long F(const ban& t1, const ban& t2, const ban& t) {     return (t.x - t1.x) * 1LL * (t2.y - t1.y) -            (t.y - t1.y) * 1LL * (t2.x - t1.x);   }   int n, k;   ban a[N];   bool so(int i, int j) { return a[i] < a[j]; }   bool c[N];   double solv() {     int u = -1;     for (int i = 1; i <= 3; ++i) {       for (int j = i + 1; j <= 3; ++j) {         int q = 0;         for (int k = 1; k <= n; ++k) {           if (F(a[i], a[j], a[k])) ++q;         }         if (q == 1) {           for (int k = 1; k <= n; ++k) {             if (F(a[i], a[j], a[k])) {               u = k;               break;             }           }         }       }     }     assert(u != -1);     c[u] = true;     vector<int> v;     for (int i = 1; i <= n; ++i) {       if (i == u) continue;       v.push_back(i);     }     sort((v).begin(), (v).end(), so);     double ans = INF;     if (k == u) {       for (int i = 0; i < ((int)(v).size()); ++i) {         ans =             min(ans, dist(a[k], a[v[i]]) + dist(a[v[0]], a[v.back()]) * 2 -                          max(dist(a[v[i]], a[v[0]]), dist(a[v[i]], a[v.back()])));       }     } else {       ans = min(ans, dist(a[v[0]], a[v.back()]) + dist(a[v[0]], a[k]) +                          dist(a[v.back()], a[u]));       ans = min(ans, dist(a[v[0]], a[v.back()]) + dist(a[v.back()], a[k]) +                          dist(a[v[0]], a[u]));       bool z = false;       for (int i = 0; i < ((int)(v).size()) - 1; ++i) {         if (v[i] == k) {           ans =               min(ans, dist(a[k], a[v[0]]) + dist(a[v[0]], a[u]) +                            min(dist(a[u], a[v[i + 1]]), dist(a[u], a[v.back()])) +                            dist(a[v[i + 1]], a[v.back()]));           z = true;         }         if (z)           ans = min(ans, dist(a[v[0]], a[v[i]]) + dist(a[k], a[v[0]]) +                              dist(a[v[i]], a[u]) + dist(a[u], a[v[i + 1]]) +                              dist(a[v[i + 1]], a[v.back()]));       }       reverse((v).begin(), (v).end());       z = false;       for (int i = 0; i < ((int)(v).size()) - 1; ++i) {         if (v[i] == k) {           ans =               min(ans, dist(a[k], a[v[0]]) + dist(a[v[0]], a[u]) +                            min(dist(a[u], a[v[i + 1]]), dist(a[u], a[v.back()])) +                            dist(a[v[i + 1]], a[v.back()]));           z = true;         }         if (z)           ans = min(ans, dist(a[v[0]], a[v[i]]) + dist(a[k], a[v[0]]) +                              dist(a[v[i]], a[u]) + dist(a[u], a[v[i + 1]]) +                              dist(a[v[i + 1]], a[v.back()]));       }     }     return ans;   }   double solv0() {     vector<int> v;     for (int i = 1; i <= n; ++i) {       if (i == k) continue;       v.push_back(i);     }     double ans = INF;     do {       double yans = dist(a[k], a[v[0]]);       for (int i = 0; i < ((int)(v).size()) - 1; ++i)         yans += dist(a[v[i]], a[v[i + 1]]);       ans = min(ans, yans);     } while (next_permutation((v).begin(), (v).end()));     return ans;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     cout.setf(ios::fixed);     cout.setf(ios::showpoint);     cout.precision(9);     int tt = 1;     while (tt--) {       cin >> n >> k;       for (int i = 1; i <= n; ++i) cin >> a[i].x >> a[i].y;       set<pair<int, int> > s;       c[k] = true;       s.insert(make_pair(a[k].x, a[k].y));       for (int i = 1; i <= n; ++i) {         if (s.find(make_pair(a[i].x, a[i].y)) != s.end()) continue;         c[i] = true;         s.insert(make_pair(a[i].x, a[i].y));       }       vector<ban> v;       bool z = false;       for (int i = 1; i <= n; ++i) {         if (c[i]) {           c[i] = false;           v.push_back(a[i]);           if (i == k && z == false) {             z = true;             k = ((int)(v).size());           }         }       }       n = ((int)(v).size());       for (int i = 1; i <= n; ++i) a[i] = v[i - 1];       cout << solv() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   long long arr[N], dp[N], n;   long long go(int indx) {     if (indx == n) return 0;     long long &ret = dp[indx];     if (~ret) return ret;     long long sum = arr[indx], j = indx + 1;     while (j != n && arr[j] == arr[indx]) sum += arr[j++];     ret = go(j);     while (j != n && arr[j] - arr[indx] == 1) j++;     return ret = max(ret, sum + go(j));   }   int main() {     memset(dp, -1, sizeof dp);     cin >> n;     for (int i = 0; i < n; cin >> arr[i++])       ;     sort(arr, arr + n);     cout << go(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   long long n, m, q;   int main() {     scanf( %lld%lld , &n, &q);     while (q--) {       long long x;       scanf( %lld , &x);       while (1) {         if (x & 1) break;         x = x + (n - x / 2);       }       cout << x / 2 + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e8 - 3;   struct Data {     int a, i;     bool operator<(const Data& d) const {       if (a == d.a) {         return i < d.i;       }       return a < d.a;     }   };   const int N = 1e5 + 10;   int C[N];   int lowbit(int first) { return first & -first; }   void update(int first, int k) {     while (first < N) {       C[first] += k;       first += lowbit(first);     }   }   int query(int first) {     int sum = 0;     while (first > 0) {       sum += C[first];       first -= lowbit(first);     }     return sum;   }   int main() {     int n;     cin >> n;     vector<Data> a(n), b(n);     for (int i = 0; i < n; i++) {       cin >> a[i].a;       a[i].i = i;     }     for (int i = 0; i < n; i++) {       b[i].a = b[i].i = i;     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     vector<int> c(n);     for (int i = 0; i < n; i++) {       c[b[i].i] = a[i].i;     }     vector<pair<int, int> > res;     for (int it = 0; it < n; it++) {       for (int i = 0; i < n - 1; i++) {         if (c[i] > c[i + 1]) {           res.push_back({c[i + 1], c[i]});           swap(c[i], c[i + 1]);         }       }     }     cout << res.size() << endl;     for (auto& p : res) {       cout << p.first + 1 <<     << p.second + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 1000111;   int n;   pair<int, int> a[MN], b[MN];   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     while (scanf( %d , &n) == 1) {       for (int i = (1), _b = (n); i <= _b; ++i) {         scanf( %d , &a[i].first);         a[i].second = i;       }       for (int i = (1), _b = (n); i <= _b; ++i) {         scanf( %d , &b[i].first);         b[i].second = i;       }       try {         while (true) {           map<int, pair<int, int> > id;           id[0] = make_pair(0, 0);           int ia = 0, ib = 0;           int diff = 0;           while (ia < n || ib < n) {             if (ia == n) {               diff -= b[++ib].first;             } else if (ib == n) {               diff += a[++ia].first;             } else if (diff <= 0) {               diff += a[++ia].first;             } else {               diff -= b[++ib].first;             }             if (id.count(diff)) {               int ja = id[diff].first;               int jb = id[diff].second;               printf( %d n , ia - ja);               for (int x = (ja + 1), _b = (ia); x <= _b; ++x)                 printf( %d  , a[x].second);               puts(  );               printf( %d n , ib - jb);               for (int x = (jb + 1), _b = (ib); x <= _b; ++x)                 printf( %d  , b[x].second);               puts(  );               puts(  );               throw 1;             }             id[diff] = make_pair(ia, ib);           }           throw 2;           random_shuffle(a + 1, a + n + 1);           random_shuffle(b + 1, b + n + 1);         }       } catch (int e) {       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10;   const long double EPS = 1e-9;   double a[MAXN][MAXN];   double x[MAXN];   int answer[MAXN], X[MAXN];   int ans;   int n, m;   int main() {     for (int i = 1; i < 8; i++) {       int v[4];       for (int j = 0; j < 4; j++) v[j] = (i & (1 << (3 - j))) != 0;       int k = 0;       for (int x = 0; x < 4; x++)         for (int y = x + 1; y < 4; y++) a[k++][i - 1] = (int)(v[x] != v[y]);     }     n = 6;     m = 7;     int ans = 0;     for (int i = 0; i < 6; i++) {       cin >> a[i][m];       ans += (int)a[i][m] + 1;     }     int p[MAXN];     for (int i = 0; i <= m; i++) p[i] = i;     for (int I = 0; I < n; I++) {       for (int j = I; j < m; j++)         if (fabs(a[I][p[I]]) < fabs(a[I][p[j]])) swap(p[I], p[j]);       for (int i = I + 1; i < n; i++) {         long double c = a[i][p[I]] / a[I][p[I]];         for (int j = m; j >= I; j--) a[i][p[j]] -= a[I][p[j]] * c;       }     }     bool flag = false;     for (int iter = 0; iter <= ans; iter++) {       x[p[m - 1]] = iter;       for (int i = n - 1; i >= 0; i--) {         long double s = 0;         for (int j = i + 1; j < m; j++) s += x[p[j]] * a[i][p[j]];         x[p[i]] = (a[i][p[m]] - s) / a[i][p[i]];       }       for (int i = 0; i < m; i++) answer[i] = (int)(x[i] + 0.5);       bool f = true;       for (int i = 0; i < m; i++)         f &=             (x[i] > -EPS) && (fabs(answer[i] - x[i]) < EPS) && (x[i] - EPS < ans);       if (!f) continue;       int res = 0;       for (int i = 0; i < m; i++) res += answer[i];       if (res >= ans) continue;       flag = true;       memmove(X, answer, sizeof(X));       ans = res;     }     if (!flag) {       puts( -1 );       return 0;     }     printf( %d n , ans);     for (int i = 0; i < 4; i++) {       for (int j = 0; j < m; j++)         for (int x = X[j]; x; x--)           printf( %c , ((j + 1) & (1 << (3 - i))) == 0 ?  a  :  b );       printf(  n );     }     fprintf(stderr,  Time execute: %.3lf n , clock() / (double)CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, v0, f[200012], nu = 0;   struct eve {     int x, v, l;     inline bool operator<(const eve &b) const {       return (x < b.x) || ((x == b.x) && (v < b.v));     }   };   multiset<eve> s;   inline void cha(int x, int v) {     f[x] = v;     if (v + v0 <= 1e9) s.insert((eve){v + v0, 0, -1});   }   int d[200012 << 2], ma[200012 << 2];   inline void Add(int p, int v) {     d[p] += v;     ma[p] += v;   }   inline void pd(int x) {     if (d[x]) {       Add(x << 1, d[x]);       Add(x << 1 | 1, d[x]);       d[x] = 0;     }   }   void build(int p, int l, int r) {     ma[p] = r;     if (l == r) return;     int mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);   }   void change(int p, int l, int r, int L, int R, int v) {     if ((R < l) || (r < L)) return;     if ((L <= l) && (r <= R)) {       Add(p, v);       return;     }     pd(p);     int mid = (l + r) >> 1;     change(p << 1, l, mid, L, R, v);     change(p << 1 | 1, mid + 1, r, L, R, v);     ma[p] = max(ma[p << 1], ma[p << 1 | 1]);   }   int Ask(int p, int l, int r, int L, int R) {     if ((R < l) || (r < L)) return 0;     if ((L <= l) && (r <= R)) return ma[p];     pd(p);     int mid = (l + r) >> 1;     return max(Ask(p << 1, l, mid, L, R), Ask(p << 1 | 1, mid + 1, r, L, R));   }   int main() {     scanf( %d%d , &n, &v0);     int i, l, r, x, o;     eve p;     memset(f, 0x3f, sizeof(f));     build(1, 0, n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &l, &r);       if (r < 0) continue;       l = max(l, 0);       s.insert((eve){l, 1, l});       s.insert((eve){r + 1, -1, l});     }     cha(r = 0, -0x3f3f3f3f);     while (!s.empty()) {       p = *s.begin();       nu += p.v;       l = p.x;       s.erase(s.begin());       if (p.l >= 0) change(1, 0, n, lower_bound(f, f + n + 1, p.l) - f, n, -p.v);       if ((!s.empty()) && ((s.begin()->x) == l)) continue;       x = upper_bound(f, f + n + 1, l - v0) - f - 1;       o = nu + Ask(1, 0, n, 0, x);       while ((r < n) && (r < o)) cha(++r, l);     }     printf( %d , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long modpow(long long x, long long y, long long m) {     long long z = 1;     while (y) {       if (y & 1) z = (z * x) % m;       x = (x * x) % m;       y >>= 1;     }     return z;   }   int egcd(int a, int b, int& x, int& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int x1, y1;     int gcd = egcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return gcd;   }   string z[2] = { NO ,  YES };   long long modinv(long long x, long long mod) { return modpow(x, mod - 2, mod); }   vector<int> pri(1.5e6 + 1), r;   vector<bool> done(1.5e6 + 1);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     int i, j, k, n, m;     string s;     while (t--) {       for (i = 2; i * i <= 1.5e6; ++i) {         if (pri[i]) continue;         pri[i] = i;         for (j = 2 * i; j <= 1.5e6; j += i)           if (!pri[j]) pri[j] = i;       }       k = 1;       for (i = 2; i <= 1.5e6; ++i) {         if (!pri[i]) pri[i] = i;         if (pri[i] == i) r.push_back(i);       }       cin >> n;       vector<int> a(n);       for (i = 0; i < n; ++i) cin >> a[i];       cout << a[0] <<    ;       j = a[0];       set<int> fc;       for (i = 2; i < 1.5e6 + 1; ++i) fc.insert(i);       while (j > 1) {         if (fc.count(pri[j])) {           for (k = pri[j]; k <= 1.5e6; k += pri[j]) fc.erase(k);           done[pri[j]] = 1;         }         j /= pri[j];       }       bool as = 1;       for (i = 1; i < n; ++i) {         j = 2;         if (as) j = a[i];         auto x = fc.lower_bound(j);         cout << *x <<    ;         if (*x != a[i]) as = 0;         k = *x;         while (k > 1) {           if (!done[pri[k]]) {             for (int p = pri[k]; p <= 1.5e6; p += pri[k]) fc.erase(p);             done[pri[k]] = 1;           }           k /= pri[k];         }       }     }     return 0;   }


#include <bits/stdc++.h>   void swap(int *a, int *b) {     int temp = *a;     *a = *b;     *b = temp;   }   int max(int a, int b) { return (a > b) ? a : b; }   int main() {     int t, n, k, a[1005], b[1005];     scanf( %d , &t);     while (t--) {       int total = 0;       scanf( %d %d , &n, &k);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         total += a[i];       }       for (int i = 0; i < n; i++) {         scanf( %d , &b[i]);       }       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           if (a[i] > a[j]) swap(&a[i], &a[j]);           if (b[i] < b[j]) swap(&b[i], &b[j]);         }       }       for (int i = 0; i < k; i++) {         total -= a[i];         total += max(a[i], b[i]);       }       printf( %d n , total);     }   }


#include <bits/stdc++.h>   using namespace std;   long long int j, k, n;   int main() {     long long int q;     string x, y;     map<string, string> m;     map<string, string>::iterator it;     cin >> q;     while (q--) {       cin >> x >> y;       if (m.count(x)) {         string z;         z = m[x];         m.erase(x);         m[y] = z;       } else {         m[y] = x;       }     }     cout << m.size() << endl;     for (it = m.begin(); it != m.end(); it++)       cout << it->second <<     << it->first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[200010];   string s;   int main() {     int t, n;     cin >> t;     while (t--) {       cin >> n;       cin >> s;       for (int i = 0; i < n; i++) {         arr[i] = s[i] -  0 ;       }       int cur1, cur2, ans, ind;       for (int i = 0; i <= 10; i++) {         for (int j = 0; j < n; j++) {           if (arr[j] > i) {             ind = j;             break;           }         }         ans = i;         bool flag = 1;         cur1 = 0;         cur2 = 0;         for (int j = 0; j < n; j++) {           int look = arr[j];           if (look < i) {             if (look < cur1) {               flag = 0;             } else {               cur1 = look;             }           } else if (look > i) {             if (look < cur2) {               flag = 0;             } else {               cur2 = look;             }           } else {             if (j > ind) {               if (look < cur1) {                 flag = 0;               } else {                 cur1 = look;               }             }           }         }         if (flag == 1) {           break;         }       }       if (ans <= 9) {         for (int i = 0; i < n; i++) {           if (arr[i] < ans) {             cout <<  1 ;           } else if (arr[i] > ans) {             cout <<  2 ;           } else {             if (i < ind) {               cout <<  2 ;             } else {               cout <<  1 ;             }           }         }         cout << endl;       } else {         cout <<  -  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, dif, l;   int a[N], f[N], g[N];   deque<int> dmax, dmin, df;   void Push(int x) {     while (!dmax.empty() && a[dmax.back()] <= a[x]) dmax.pop_back();     dmax.push_back(x);     while (!dmin.empty() && a[dmin.back()] >= a[x]) dmin.pop_back();     dmin.push_back(x);   }   int main() {     cin >> n >> dif >> l;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int c = 1;     for (int i = 1; i <= n; i++) {       Push(i);       while (c <= i && a[dmax.front()] - a[dmin.front()] > dif) {         if (dmax.front() == c) dmax.pop_front();         if (dmin.front() == c) dmin.pop_front();         if (!df.empty() && df.front() == c - 1) df.pop_front();         c++;       }       if (i - l >= c - 1 && f[i - l] != 1e9) {         while (!df.empty() && f[i - l] < f[df.back()]) df.pop_back();         df.push_back(i - l);       }       if (df.empty())         f[i] = 1e9;       else         f[i] = f[df.front()] + 1;     }     if (f[n] == 1e9)       cout << -1;     else       cout << f[n];   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target( avx,avx2 )   using namespace std;   const long double eps = 1e-6;   long double inf = 0;   const long long mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int count_dels(long long m) {     int c = 0;     for (long long i = 1; i * i <= m; ++i) {       if (m % i != 0) continue;       ++c;       if (i != m / i) ++c;     }     return c;   }   int main() {     cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       long long a, m;       cin >> a >> m;       long long d = gcd(a, m);       long long m1 = m / d;       long long ans = m1;       for (long long i = 2; i * i <= m1; ++i) {         if (m1 % i == 0) {           ans -= ans / i;           while (m1 % i == 0) m1 /= i;         }       }       if (m1 != 1) ans -= ans / m1;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A[50];   int main() {     long long n;     A[0] = A[1] = 1;     scanf( %lld , &n);     for (long long i = 1; i <= 50; ++i) {       A[i] = A[i - 1] * i;     }     long long ans = A[n] / A[n / 2] / A[n / 2] / 2;     ans *= A[n / 2 - 1] * A[n / 2 - 1];     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0;     char ch = getchar();     bool f = 0;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = 1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return f ? -x : x;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(long long x) {     write(x);     puts(  );   }   void writep(long long x) {     write(x);     putchar(   );   }   const int N = 5e5 + 5, mo = 1e9 + 7;   int n, m, a[N], fac[N], inv[N], b[N];   char s[N];   int C(int n, int m) {     if (n < m) return 0;     return (long long)fac[n] * inv[m] % mo * inv[n - m] % mo;   }   int ksm(int x, int p) {     int res = 1;     for (; p; p >>= 1, x = (long long)x * x % mo)       if (p & 1) res = (long long)res * x % mo;     return res;   }   void init(int n) {     fac[0] = 1;     for (int i = (int)(1); i <= (int)(n); i++)       fac[i] = (long long)i * fac[i - 1] % mo;     inv[n] = ksm(fac[n], mo - 2);     for (int i = (int)(n - 1); i >= (int)(0); i--)       inv[i] = (long long)(i + 1) * inv[i + 1] % mo;   }   int upd(int x, int y) {     x += y;     if (x >= mo) x -= mo;     return x;   }   int main() {     init(N - 1);     n = read();     m = read();     scanf( %s , s + 1);     for (int i = (int)(1); i <= (int)(n); i++) a[i] = s[i] -  0 ;     reverse(a + 1, a + n + 1);     int sum = 0, now = 1;     b[1] = C(n - 1, m);     for (int i = (int)(2); i <= (int)(n); i++) {       sum = upd(sum, (long long)now * C(n - i, m - 1) % mo);       now = (long long)10 * now % mo;       b[i] = upd(sum, (long long)now * C(n - i, m) % mo);     }     int ans = 0;     for (int i = (int)(1); i <= (int)(n); i++)       ans = upd(ans, (long long)b[i] * a[i] % mo);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int N;   string S;   void precompute() {     int cur = 1;     while ((int)S.size() <= 1000) {       int x = cur++;       string tmp;       while (x > 0) {         tmp.push_back(x % 10 +  0 );         x /= 10;       }       for (int i = (int)tmp.size() - 1; i >= 0; i--) S.push_back(tmp[i]);     }   }   int main() {     precompute();     scanf( %d , &N);     printf( %c n , S[N - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   const long long mod = 1000000000 + 7;   struct node {     int l, r;     mutable long long v;     node(int L, int R = -1, long long v = 0) : l(L), r(R), v(v){};     bool operator<(const node &x) const { return l < x.l; }   };   long long quick(long long a, long long n, long long p) {     a %= p;     long long ans = 1;     while (n) {       if (n & 1) ans = ans * a % p;       a = a * a % p;       n >>= 1;     }     return ans;   }   set<node> s;   set<node>::iterator spilt(int pos) {     set<node>::iterator it = s.lower_bound(node(pos));     if (it != s.end() && it->l == pos) return it;     it--;     int R = it->r, L = it->l;     long long V = it->v;     s.erase(it);     s.insert(node(L, pos - 1, V));     return s.insert(node(pos, R, V)).first;   }   void assign_val(int l, int r, long long val) {     set<node>::iterator itr = spilt(r + 1), itl = spilt(l);     s.erase(itl, itr);     s.insert(node(l, r, val));   }   void add(int l, int r, long long val) {     set<node>::iterator itr = spilt(r + 1), itl = spilt(l);     for (; itl != itr; itl++) itl->v += val;   }   long long ranks(int l, int r, int k) {     vector<pair<long long, int> > vp;     set<node>::iterator itr = spilt(r + 1), itl = spilt(l);     for (; itl != itr; itl++) {       vp.push_back({itl->v, itl->r - itl->l + 1});     }     sort(vp.begin(), vp.end());     for (int i = 0; i < vp.size(); i++) {       k -= vp[i].second;       if (k <= 0) return vp[i].first;     }   }   long long sum(int l, int r, int ex, long long p) {     set<node>::iterator itr = spilt(r + 1), itl = spilt(l);     long long ret = 0;     for (; itl != itr; itl++) {       ret += 1ll * (itl->r - itl->l + 1) * quick(itl->v, ex, p) % p;       ret %= p;     }     return ret;   }   int n, m;   long long seed, vmax, a[maxn];   long long rnd() {     long long ret = seed;     seed = (seed * 7 + 13) % mod;     return ret;   }   int main() {     cin >> n >> m >> seed >> vmax;     for (int i = 1; i <= n; i++) {       a[i] = (rnd() % vmax) + 1;       s.insert(node(i, i, a[i]));     }     s.insert(node(n + 1, n + 1, 0));     int x, y;     for (int i = 1; i <= m; i++) {       int op = int(rnd() % 4) + 1;       int l = int(rnd() % n) + 1;       int r = int(rnd() % n) + 1;       if (l > r) swap(l, r);       if (op == 3)         x = int(rnd() % (r - l + 1)) + 1;       else         x = int(rnd() % vmax) + 1;       if (op == 4) y = int(rnd() % vmax) + 1;       if (op == 1)         add(l, r, x);       else if (op == 2)         assign_val(l, r, x);       else if (op == 3)         cout << ranks(l, r, x) << endl;       else         cout << sum(l, r, x, y) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long double V;   long double vx[111111], vy[111111];   int m, N;   struct point {     long double x, y;     bool operator<(const point &b) const {       return (x != b.x) ? (x < b.x) : (y > b.y);     }   } ans[111111], a[111111];   pair<long double, int> k[111111], b[111111], c[111111];   long double cs[111111];   int main() {     double V2;     scanf( %d%lf , &n, &V2);     V = V2;     for (int i = 1; i <= n; ++i) {       double ang;       scanf( %lf , &ang);       long double t = ang;       long double x = cos(t) * V * sin(t) * V / (0.5 * (9.8));       ans[i].x = x;       ans[i].y = 0;       k[i] = make_pair(tan(ang), i);     }     scanf( %d , &m);     long double mn = 1e9;     int arc = 0;     for (int i = 1; i <= m; ++i) {       double x, y;       scanf( %lf%lf , &x, &y);       a[i].x = x;       a[i].y = y;       long double A = 0.5 * (9.8) * x * x;       long double B = -x * V * V;       long double C = 0.5 * x * x * (9.8) + y * V * V;       long double D = B * B - 4 * A * C;       if (D < 0) {         if (x < mn) {           mn = x;           arc = i;         }       } else {         b[++N] = make_pair((sqrt(D) - B) / 2 / A, i);         c[N] = make_pair((-sqrt(D) - B) / 2 / A, i);       }     }     sort(k + 1, k + 1 + n);     sort(b + 1, b + 1 + N);     int j = 0;     long double mn2 = mn;     for (int i = 1; i <= n; ++i) {       for (; j < N && b[j + 1].first <= k[i].first;) {         ++j;         mn = min(a[b[j].second].x, mn);       }       int pos = k[i].second;       if (mn < ans[pos].x) {         ans[pos].x = mn;         ans[pos].y = mn * k[i].first - 0.5 * (9.8) * mn * mn *                                            (1 + k[i].first * k[i].first) / V / V;       }     }     sort(c + 1, c + 1 + N);     j = N + 1;     mn = mn2;     for (int i = n; i >= 1; --i) {       for (; j > 1 && c[j - 1].first >= k[i].first;)         mn = min(a[c[--j].second].x, mn);       int pos = k[i].second;       if (mn < ans[pos].x) {         ans[pos].x = mn;         ans[pos].y = mn * k[i].first - 0.5 * (9.8) * mn * mn *                                            (1 + k[i].first * k[i].first) / V / V;       }     }     for (int i = 1; i <= n; ++i) {       double x = ans[i].x, y = ans[i].y;       printf( %lf %lf n , x, y);     }   }


#include <bits/stdc++.h>   using namespace std;   void OJ() {}   void solve() {     string s;     cin >> s;     string temp =   ;     int alice = 0, flag = 0, l;     while (1) {       int cnt = 0, mx_cnt = 0, mx_l = -1, mx_r = -1, d_l = -1;       l = s.size();       for (int i = 0; i < l; i++) {         if (s[i] ==  0 )           cnt = 0;         else if (cnt == 0) {           d_l = i;           cnt++;         } else           cnt++;         if (cnt > mx_cnt) {           mx_cnt = cnt;           mx_l = d_l;           mx_r = i;         }       }       if (mx_l == -1) break;       temp =   ;       for (int i = 0; i < l; i++) {         if (i >= mx_l && i <= mx_r) continue;         temp += s[i];       }       s = temp;       if (!flag) alice += mx_cnt;       flag = !flag;     }     cout << alice <<   n ;   }   int main() {     OJ();     int tc = 1;     cin >> tc;     while (tc--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using cat = long long;   struct edge {     int u, v, id;   };   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(10);     int N, M, K;     cin >> N >> M >> K;     vector<int> W(N), D(N, 0);     for (int i = 0; i < N; i++) cin >> W[i];     vector<edge> E(M);     for (int i = 0; i < M; i++) {       cin >> E[i].u >> E[i].v;       D[--E[i].u]++;       D[--E[i].v]++;       E[i].id = i;     }     vector<edge> E0 = E;     int M0 = M;     vector<edge> E_final;     while (true) {       bool stop = true;       for (int i = 0; i < M; i++)         if (min(D[E[i].u], D[E[i].v]) <= 2) {           D[E[i].u]--;           D[E[i].v]--;           E_final.push_back(E[i]);           swap(E.back(), E[i]);           E.pop_back();           M--;           stop = false;           break;         }       for (int i = 0; i < M; i++)         if ((D[E[i].u] - 1) / 2 + (D[E[i].v] - 1) / 2 < K) {           D[E[i].u]--;           D[E[i].v]--;           E_final.push_back(E[i]);           swap(E.back(), E[i]);           E.pop_back();           M--;           stop = false;           break;         }       if (stop) break;     }     reverse(begin(E_final), end(E_final));     vector<vector<int> > S_final(N, vector<int>(K, 0));     vector<int> ans_id(M0, 0);     int ans = 0;     if (M > 0) {       vector<vector<int> > seqs(10000, vector<int>(K));       for (int i = 0; i < 10000; i++)         for (int j = 0; j < K; j++) {           seqs[i][j] = j;           swap(seqs[i][j], seqs[i][rand() % (j + 1)]);         }       for (int r = 0; r < 50; r++) {         srand(r);         for (int i = 0; i < M; i++) swap(E[rand() % (i + 1)], E[i]);         vector<char> used(M, 0);         vector<vector<int> > S(N, vector<int>(K, 0)), S_cnt(N, vector<int>(3, 0));         vector<int> S_min(N, 0);         for (int i = 0; i < N; i++) S_cnt[i][0] = K;         int cur = 0;         vector<int> cur_id(M0, 0);         for (int r2 = 0; r2 < (400 / K); r2++) {           auto cur_old = cur;           auto used_old = used;           auto cur_id_old = cur_id;           auto S_min_old = S_min;           auto S_old = S;           auto S_cnt_old = S_cnt;           for (int i = 0; i < M; i++)             if (used[i] && rand() % 4 == 0) {               int s = cur_id[E[i].id] - 1, u = E[i].u, v = E[i].v;               if (S[u][s] == S_min[u] && S_cnt[u][2]) continue;               if (S[v][s] == S_min[v] && S_cnt[v][2]) continue;               cur_id[E[i].id] = 0;               S_cnt[u][S[u][s] - S_min[u]]--;               S_cnt[v][S[v][s] - S_min[v]]--;               if (S[u][s] == S_min[u]) {                 S_cnt[u][2] = S_cnt[u][1];                 S_cnt[u][1] = S_cnt[u][0];                 S_cnt[u][0] = 0;                 S_min[u]--;               }               if (S[v][s] == S_min[v]) {                 S_cnt[v][2] = S_cnt[v][1];                 S_cnt[v][1] = S_cnt[v][0];                 S_cnt[v][0] = 0;                 S_min[v]--;               }               S[u][s]--;               S[v][s]--;               S_cnt[u][S[u][s] - S_min[u]]++;               S_cnt[v][S[v][s] - S_min[v]]++;               cur -= W[u] + W[v];               used[i] = 0;             }           for (int i = 0; i < M; i++)             if (!used[i]) {               int seq_id = rand() % 10000, u = E[i].u, v = E[i].v;               int s = -1;               for (int j = 0; j < K; j++) {                 int cur_s = seqs[seq_id][j];                 if (S[u][cur_s] == 2 + S_min[u]) continue;                 if (S[v][cur_s] == 2 + S_min[v]) continue;                 s = cur_s;                 break;               }               if (s == -1) continue;               cur_id[E[i].id] = s + 1;               S_cnt[u][S[u][s] - S_min[u]]--;               S_cnt[v][S[v][s] - S_min[v]]--;               if (S_cnt[u][0] == 0) {                 S_cnt[u][0] = S_cnt[u][1];                 S_cnt[u][1] = S_cnt[u][2];                 S_cnt[u][2] = 0;                 S_min[u]++;               }               if (S_cnt[v][0] == 0) {                 S_cnt[v][0] = S_cnt[v][1];                 S_cnt[v][1] = S_cnt[v][2];                 S_cnt[v][2] = 0;                 S_min[v]++;               }               S[u][s]++;               S[v][s]++;               S_cnt[u][S[u][s] - S_min[u]]++;               S_cnt[v][S[v][s] - S_min[v]]++;               cur += W[u] + W[v];               used[i] = 1;             }           if (cur < cur_old) {             cur = cur_old;             used = used_old;             cur_id = cur_id_old;             S_min = S_min_old;             S = S_old;             S_cnt = S_cnt_old;           }         }         if (cur > ans) {           ans = cur;           ans_id = cur_id;           S_final = S;         }       }     }     for (auto e : E_final) {       int min_u = 1000000, min_v = 1000000;       for (int i = 0; i < K; i++) min_u = min(min_u, S_final[e.u][i]);       for (int i = 0; i < K; i++) min_v = min(min_v, S_final[e.v][i]);       for (int i = 0; i < K; i++)         if (S_final[e.u][i] + 1 <= min_u + 2 &&             S_final[e.v][i] + 1 <= min_v + 2) {           S_final[e.u][i]++;           S_final[e.v][i]++;           ans_id[e.id] = i + 1;           ans += W[e.u] + W[e.v];           break;         }     }     cerr << ans <<   n ;     for (int i = 0; i < M0; i++) cout << ans_id[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     getline(cin, s);     for (int i = 0; i <= s.length() - 1; i++) {       if (s[i] ==  .  && s[i - 1] ==  9 ) {         cout <<  GOTO Vasilisa. ;         return 0;       }       if (s[i] ==  .  && s[i + 1] <  5 ) {         for (int j = 0; j <= i - 1; j++) cout << s[j];       }       if (s[i] ==  .  && s[i + 1] >=  5 ) {         for (int j = 0; j <= i - 2; j++) cout << s[j];         cout << char(s[i - 1] + 1);       }     }     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   struct node {     int ch[27], len, fa;   } dian[N];   struct edge {     int v, nxt;   } e[N];   int n, q, head[N], cnt, las = 1, tot = 1, fl[N], pos[N], ot, x, m, ans;   char s[N], t[N];   void ad(int u, int v) {     e[++cnt].v = v;     e[cnt].nxt = head[u];     head[u] = cnt;   }   void add(int c, int id) {     int np = ++tot, p = las;     fl[np] = id;     dian[np].len = dian[p].len + 1;     for (; p && !dian[p].ch[c]; p = dian[p].fa) dian[p].ch[c] = np;     if (!p)       dian[np].fa = 1;     else {       int q = dian[p].ch[c];       if (dian[q].len == dian[p].len + 1)         dian[np].fa = q;       else {         int nq = ++tot;         dian[nq] = dian[q];         dian[nq].len = dian[p].len + 1;         for (; p && dian[p].ch[c] == q; p = dian[p].fa) dian[p].ch[c] = nq;         dian[np].fa = nq;         dian[q].fa = nq;       }     }     las = np;   }   void dfs(int u) {     if (fl[u]) pos[++ot] = fl[u];     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].v;       dfs(v);     }   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++) {       add(s[i] -  a , i);     }     for (int i = 2; i <= tot; i++) {       ad(dian[i].fa, i);     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %d , &x);       scanf( %s , t + 1);       ot = 0;       m = strlen(t + 1);       int u = 1, f = 0;       for (int j = 1; j <= m; j++) {         int to = t[j] -  a ;         u = dian[u].ch[to];         if (!u) {           f = 1;           break;         }       }       if (f) {         printf( -1 n );         continue;       }       dfs(u);       sort(pos + 1, pos + 1 + ot);       ans = 999999999;       for (int j = x; j <= ot; j++) {         ans = min(ans, pos[j] - (pos[j - x + 1] - m + 1) + 1);       }       if (ans == 999999999) {         printf( -1 n );         continue;       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long MOD = 998244353;   template <class T>   inline void chmax(T &a, const T &b) {     if ((a) < (b)) (a) = (b);   }   template <class T>   inline void chmin(T &a, const T &b) {     if ((a) > (b)) (a) = (b);   }   template <typename T>   using PQ = priority_queue<T, vector<T>, greater<T>>;   struct Fast {     Fast() {       std::cin.tie(0);       ios::sync_with_stdio(false);     }   } fast;   long long solve() {     long long n;     cin >> n;     vector<string> a(n);     vector<long long> dcnt(11, 0);     for (long long i = (long long)(0); i < (long long)(n); ++i) {       cin >> a[i];       dcnt[((long long)(a[i]).size())]++;     }     42;     42;     auto f = [&](string s, long long d) {       long long m = ((long long)(s).size());       long long res = 0;       long long mul = 1;       long long cnt = 0;       for (long long i = (long long)((m)-1); i >= (long long)(0); --i) {         long long x = s[i] -  0 ;         res += mul * x;         if (cnt < d) {           mul *= 100;         } else {           mul *= 10;         }         mul %= MOD;         res %= MOD;         cnt++;       }       return res;     };     42;     auto g = [&](string s, long long d) {       long long m = ((long long)(s).size());       long long res = 0;       long long mul = 10;       long long cnt = 0;       for (long long i = (long long)((m)-1); i >= (long long)(0); --i) {         long long x = s[i] -  0 ;         res += mul * x;         if (cnt < d - 1) {           mul *= 100;         } else {           mul *= 10;         }         mul %= MOD;         res %= MOD;         cnt++;       }       return res;     };     42;     long long ans = 0;     for (long long i = (long long)(0); i < (long long)(n); ++i) {       for (long long d = (long long)(1); d < (long long)(11); ++d) {         ans += f(a[i], d) * dcnt[d];         ans += g(a[i], d) * dcnt[d];         ans %= MOD;       }     }     cout << ans << endl;     return 0;   }   signed main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7;   const int M = 2e6 + 7;   long long g[M], q[M];   int n, a[N];   void push(int v, int lr, int rl) {     g[v << 1] += q[v];     g[v << 1 | 1] += q[v];     q[v << 1] += q[v];     q[v << 1 | 1] += q[v];     q[v] = 0;   }   void upd1(int v, int lr, int rl, int l, int x) {     if ((lr & rl) == l) {       g[v] += x;       return;     }     push(v, lr, rl);     int m = (lr + rl) >> 1;     if (l <= m)       upd1(v << 1, lr, m, l, x);     else       upd1(v << 1 | 1, m + 1, rl, l, x);     g[v] = max(g[v << 1], g[v << 1 | 1]);   }   void upd2(int v, int lr, int rl, int l, int r, int x) {     if (l > r) return;     if (lr == l && rl == r) {       q[v] += x;       g[v] += x;       push(v, lr, rl);       return;     }     push(v, lr, rl);     int m = (lr + rl) >> 1;     upd2(v << 1, lr, m, l, min(m, r), x);     upd2(v << 1 | 1, m + 1, rl, max(l, m + 1), r, x);     g[v] = max(g[v << 1], g[v << 1 | 1]);   }   int get(int v, int lr, int rl) {     if (g[v] < 0) return -1;     push(v, lr, rl);     if (lr == rl) return (g[v] ? -1 : lr);     int m = (lr + rl) >> 1;     int first = get(v << 1, lr, m);     int second = get(v << 1 | 1, m + 1, rl);     g[v] = max(g[v << 1], g[v << 1 | 1]);     return max(first, second);   }   int main() {     int w, z = 1;     scanf( %d %d , &n, &w);     while (z < n) z <<= 1;     long long sum = 0;     memset(g, (-1000000000000000007), sizeof(g));     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       g[z - 1 + i] = a[i] - sum;       sum += a[i];     }     for (int i = z - 1; i; --i) g[i] = max(g[i << 1], g[i << 1 | 1]);     for (int i = 0, x, y; i < w; ++i) {       scanf( %d %d , &x, &y);       upd1(1, 1, z, x, y - a[x]);       upd2(1, 1, z, x + 1, n, a[x] - y);       a[x] = y;       printf( %d n , get(1, 1, z));     }     return 0;   }


/*─────────▄▄▄▄▄▄▄▄▄▄▄▄▄   ────────▄▀▀─────────────▀▀▄   ───────█───────────────────█   ──────█─────────────────────█   ─────█───▄▄▄▄▄▄▄───▄▄▄▄▄▄▄───█   ────█───█████████─█████████───█   ────█──██▀────▀█████▀────▀██──█   ───██████───█▀█─███───█▀█─██████   ───██████───▀▀▀─███───▀▀▀─██████   ────█──▀█▄────▄██─██▄────▄█▀──█   ────█────▀█████▀───▀█████▀────█   ────█───────────────▄▄▄───────█   ────█───────▄▄▄▄██▀▀█▀▀█▄─────█   ────█─────▄██▄█▄▄█▄▄█▄▄██▄────█   ────█─────▀▀█████████████▀────█   ───▐▓▓▌─────────────────────▐▓▓▌   ───▐▐▓▓▌▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▐▓▓▌▌   ───█══▐▓▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄▓▌══█   ──█══▌═▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌═▐══█   ──█══█═▐▓▓▓▓▓▓▄▄▄▄▄▄▄▓▓▓▓▓▓▌═█══█   ──█══█═▐▓▓▓▓▓▓▐██▀██▌▓▓▓▓▓▓▌═█══█   ──█══█═▐▓▓▓▓▓▓▓▀▀▀▀▀▓▓▓▓▓▓▓▌═█══█       ──█───█─█──█─█▀▀█─▀▀█▀▀─▀█─█─▀█──   ──█▄█▄█─█▀▀█─█▄▄█───█───█▀─▀─█▀──   ───▀─▀──▀──▀─▀──▀───▀───▄──▄─▄───                 TAKE LOVE AND PRAY FOR ME :) :) :)       */           #include<bits/stdc++.h>   using namespace std;   #define ull unsigned long long   #define ll long long   #define deciset(x) cout <<setprecision(x) <<fixed;   #define pb push_back   #define mp make_pair   #define PI 2*acos(0.0)   #define boost ios::sync_with_stdio(false);cin.tie(0)      int main()   {      boost;      ll t;      cin>>t;      while(t--)      {          ll a,b;          cin>>a>>b;        char arr[a][b];        ll brr[a][b];        for(int i=0;i<a;i++)         for(int j=0;j<b;j++) { cin>>arr[i][j]; brr[i][j]=0; }        int x=1;        for(int i=0;i<a;i++)        for(int j=0;j<b;j++)        {            if(arr[i][j]== * ) brr[i][j]=x;           else if(arr[i][j]== .  && arr[i][j-1]== *  && j>0) x++;        }        ll ans=0;        for(int i=0;i<a;i++)        for(int j=0;j<b;j++)        {            if(arr[i][j]== * ){                        ll kk=1,h=1;                for(ll k=i+1;k<a;k++){                    if(arr[k][j]== *  && brr[k][j+kk]!=0 && brr[k][j-kk]==brr[k][j+kk] && j-kk>=0 && j+kk<b )                      {                             h++;                          kk++;                      }                      else break;                                    }                ans+=h;            }        }        cout<<ans<<endl;      }                                  }


#include <bits/stdc++.h>   using namespace std;   int N;   pair<int, int> a[200002 + 1];   int min(int a, int b) { return a > b ? b : a; }   int abs(int a) { return a < 0 ? -a : a; }   int main() {     cin >> N;     N *= 2;     int b;     for (int i = 0; i < N; i++) {       cin >> b;       a[i] = {b, i};     }     sort(a, a + N);     long long ans = a[0].second + a[1].second;     for (int i = 2; i < N; i += 2) {       ans += min(abs(a[i - 2].second - a[i].second) +                      abs(a[i - 1].second - a[i + 1].second),                  abs(a[i - 1].second - a[i].second) +                      abs(a[i - 2].second - a[i + 1].second));     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<char> a;   int x, y, n;   void update(pair<int, int> &pos, int i, int d) {     if (a[i] ==  U )       pos.second += d;     else if (a[i] ==  D )       pos.second -= d;     else if (a[i] ==  R )       pos.first += d;     else       pos.first -= d;   }   bool ok(pair<int, int> pos, int len) {     int d = abs(x - pos.first) + abs(y - pos.second);     if (d <= len && d % 2 == len % 2) return true;     return false;   }   bool can(int len) {     pair<int, int> pos = make_pair(0, 0);     for (int i = len; i < a.size(); i++) update(pos, i, 1);     int l = 0, r = len;     while (1) {       if (ok(pos, len)) return true;       if (n == r) break;       update(pos, l++, 1);       update(pos, r++, -1);     }     return false;   }   int main() {     cin >> n;     cin.ignore();     for (int i = 0; i < n; i++) {       char temp;       cin >> temp;       a.push_back(temp);     }     cin >> x >> y;     if (!ok(make_pair(0, 0), n))       cout << -1 << endl;     else {       int l = -1, r = n;       while (r - l > 1) {         int len = (r + l) / 2;         if (can(len))           r = len;         else           l = len;       }       cout << r << 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 main() {     int N, x, M, y, d, len1, len2, len, r1, r2, r, i;     long long ans;     scanf( %d%d%d%d , &N, &x, &M, &y);     if (N < M) {       swap(x, y);       swap(N, M);     }     d = abs(x - y);     ans = N + M + 1 - max(min(M, N - d), 0);     for (i = 1; i <= N; i++) {       if (i <= d)         len1 = d - i + 1;       else         len1 = i - d;       len2 = 1;       r1 = d + i;       r2 = M;       len = max(len1, len2);       r = min(r1, r2);       ans += 2 * max(0, r - len + 1);       if (len1 <= r2) ans--;       if (r1 <= r2) ans -= 2;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 5;   const int M = 1e3 + 10;   const int mod = 9973;   using namespace std;   long long m, n, x, y, l, r, t, a1, r1, a2, r2;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void e_gcd(long long a, long long b, long long &g, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0, g = a;       return;     } else {       e_gcd(b, a % b, g, y, x);       y -= (a / b) * x;     }   }   inline long long crt() {     long long ans, sum = 0, g, x, y;     e_gcd(a1, a2, g, x, y);     if ((r2 - r1) % g != 0) return 0;     t = (r2 - r1) / g;     x *= t;     t = a2 / g;     x = (x % t + t) % t;     ans = r1 + a1 * x;     t = abs(a1 * a2 / g);     l = max(l, max(r1, r2));     if (l > r) return 0;     if (ans <= r) sum += (r - ans) / t + 1;     if (ans < l) sum -= (l - ans - 1) / t + 1;     return sum;   }   int main() {     scanf( %I64d%I64d%I64d%I64d%I64d%I64d , &a1, &r1, &a2, &r2, &l, &r);     printf( %I64d n , crt());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   unsigned int dp[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, cnt = 0;     cin >> n;     string s;     cin >> s;     if (n % 2 == 1) {       cout << 0 <<   n ;       return 0;     }     dp[0] = 1;     for (int i = 0; i < n; i++) {       if (s[i] !=  ? )         cnt++;       else {         for (int j = (i + 1) / 2; j > 0; j--) dp[j] = dp[j] + dp[j - 1];       }     }     unsigned int ans = dp[n / 2];     for (int i = 0; i < n / 2 - cnt; i++) ans *= 25;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   long long arr[100005];   using namespace std;   int main() {     cin.tie(0);     std::ios::sync_with_stdio(false);     ;     int n;     cin >> n;     for (int i = 0; i < n; cin >> arr[i++])       ;     sort(arr, arr + n);     cout << arr[n - 1] <<    ;     for (int i = 1; i < n - 1; i++) {       cout << arr[i] <<    ;     }     cout << arr[0];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int j, t, n, m = 0, i;     unsigned long long p = 0, q = 0;     char a[1000001];     cin >> a;     n = strlen(a);     for (j = 0; j < n; j++) {       if (a[j] ==  ^ ) {         break;       }     }     for (i = j - 1; i >= 0; i--) {       if ((a[i] >=  1 ) && (a[i] <=  9 )) {         t = abs(j - i);         p += (t * ((int)a[i] - 48));       }     }     for (i = j + 1; i < n; i++) {       if ((a[i] >=  1 ) && (a[i] <=  9 )) {         t = abs(j - i);         q += (t * ((int)a[i] - 48));       }     }     if (p == q) {       cout <<  balance  << endl;     } else if (p > q) {       cout <<  left  << endl;     } else {       cout <<  right  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   double b[100005];   struct node {     double he, cheng;   } a[100005 * 4];   node merge(node a, node b) {     node c;     c.cheng = a.cheng * b.cheng;     c.he = a.he + a.cheng * (b.he - 1);     return c;   }   void build(int x, int l, int r) {     if (l == r) {       a[x].he = 1 + b[l];       a[x].cheng = b[l];       return;     }     int mid = (l + r) / 2;     build(x * 2, l, mid);     build(x * 2 + 1, mid + 1, r);     a[x] = merge(a[x * 2], a[x * 2 + 1]);   }   void modify(int x, int l, int r, int wh, double val) {     if (l == r) {       a[x].cheng = val;       a[x].he = 1 + val;       return;     }     int mid = (l + r) / 2;     if (mid >= wh)       modify(x * 2, l, mid, wh, val);     else       modify(x * 2 + 1, mid + 1, r, wh, val);     a[x] = merge(a[x * 2], a[x * 2 + 1]);   }   node query(int x, int l, int r, int tx, int ty) {     if (l >= tx && r <= ty) return a[x];     int mid = (l + r) / 2;     if (mid >= tx && mid < ty)       return merge(query(x * 2, l, mid, tx, ty),                    query(x * 2 + 1, mid + 1, r, tx, ty));     if (mid >= tx)       return query(x * 2, l, mid, tx, ty);     else       return query(x * 2 + 1, mid + 1, r, tx, ty);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       double x, y;       scanf( %lf%lf , &x, &y);       double t = x / y;       b[i] = (1 - t) / t;     }     build(1, 1, n);     while (m--) {       int type;       scanf( %d , &type);       if (type == 1) {         int wh;         scanf( %d , &wh);         double x, y;         scanf( %lf%lf , &x, &y);         double t = x / y;         t = (1 - t) / t;         modify(1, 1, n, wh, t);       } else {         int x, y;         scanf( %d%d , &x, &y);         printf( %.10lf n , 1.0 / query(1, 1, n, x, y).he);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50010;   const int inf = 1e9;   inline int read() {     int p = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       p = p * 10 + ch -  0 ;       ch = getchar();     }     return p * f;   }   struct node {     int x, y, d, c, next;   } edge[N << 4];   int len, first[N];   void ins(int x, int y, int c, int d) {     len++;     edge[len].x = x;     edge[len].y = y;     edge[len].c = c;     edge[len].d = d;     edge[len].next = first[x];     first[x] = len;     len++;     edge[len].x = y;     edge[len].y = x;     edge[len].c = 0;     edge[len].d = -d;     edge[len].next = first[y];     first[y] = len;   }   bool v[N];   int d[N];   queue<int> q;   int pre[N], pos[N];   int s, t;   bool bfs() {     while (!q.empty()) q.pop();     q.push(s);     memset(d, -63, sizeof(d));     d[s] = 0;     memset(v, 0, sizeof(v));     v[s] = 1;     while (!q.empty()) {       int x = q.front();       for (int k = first[x]; k != -1; k = edge[k].next) {         int y = edge[k].y;         if (d[y] < d[x] + edge[k].d && edge[k].c) {           d[y] = d[x] + edge[k].d;           pos[y] = x;           pre[y] = k;           if (!v[y]) {             v[y] = 1;             q.push(y);           }         }       }       q.pop();       v[x] = 0;     }     return d[t] >= 0;   }   int n, a[N];   int main() {     len = 1;     memset(first, -1, sizeof(first));     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     int ss = 2 * n + 1;     s = ss + 1;     t = s + 1;     ins(s, ss, 4, 0);     for (int i = 1; i <= n; i++) {       ins(ss, i + n, 1, 0);       ins(i + n, i, 1, 1);       ins(i, t, 1, 0);     }     for (int i = 1; i <= n; i++) {       int cnt = 0;       for (int j = i + 1; j <= n; j++)         if ((a[i] - a[j] == 1) && cnt < 1) {           ins(i, j + n, inf, 0);           cnt++;         }       cnt = 0;       for (int j = i + 1; j <= n; j++)         if ((a[i] - a[j] == -1) && cnt < 1) {           ins(i, j + n, inf, 0);           cnt++;         }       cnt = 0;       for (int j = i + 1; j <= n; j++)         if ((a[i] % 7 == a[j] % 7) && cnt < 1) {           ins(i, j + n, inf, 0);           cnt++;         }       ins(i + n, i, inf, 0);     }     int ans = 0;     while (bfs()) {       for (int i = t; i != s; i = pos[i])         ans += edge[pre[i]].d, edge[pre[i]].c--, edge[pre[i] ^ 1].c++;     }     return printf( %d n , ans), 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 14;   const int INF = 0x3f3f3f3f;   int N, M;   vector<int> G[Maxn + 5];   void addedge(int u, int v) { G[u].push_back(v), G[v].push_back(u); }   int f[(1 << Maxn) + 5];   pair<int, int> last[(1 << Maxn) + 5];   int lasts[(1 << Maxn) + 5];   bool go[Maxn + 3][Maxn + 3][(1 << Maxn) + 3];   int lastnode[Maxn + 3][Maxn + 3][(1 << Maxn) + 3];   inline int lowbit(int x) { return x & (-x); }   inline int bitcount(int x) {     int ret = 0;     while (x) ret++, x -= lowbit(x);     return ret;   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 1; i <= M; i++) {       int u, v;       scanf( %d %d , &u, &v);       addedge(u, v);     }     memset(f, 0x3f, sizeof f);     for (int u = 1; u <= N; u++)       for (auto v : G[u]) go[u][v][0] = true, lastnode[u][v][0] = u;     for (int s = 0; s < (1 << N); s++)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) {           if ((s & (1 << (i - 1))) || (s & (1 << (j - 1))) || i == j ||               !go[i][j][s])             continue;           for (auto k : G[j]) {             if (s & (1 << (k - 1)) || k == i && s == 0) continue;             int t = s ^ (1 << (j - 1));             if (!go[i][k][t]) go[i][k][t] = true, lastnode[i][k][t] = j;           }         }     f[1] = 0;     for (int s = 0; s < (1 << N); s++)       for (int t = s; t; t = (t - 1) & s) {         int lst = s ^ t;         int cnt = bitcount(t) + 1;         if (f[lst] + cnt >= f[s]) continue;         for (int u = 1; u <= N; u++) {           if (!(lst & (1 << (u - 1)))) continue;           for (int v = 1; v <= N; v++) {             if (!(lst & (1 << (v - 1)))) continue;             if (go[u][v][t]) {               f[s] = f[lst] + cnt;               last[s] = make_pair(u, v);               lasts[s] = t;             }           }         }       }     if (f[(1 << N) - 1] == INF) {       puts( -1 );       return 0;     }     printf( %d n , f[(1 << N) - 1]);     int t = (1 << N) - 1;     while (t != 1) {       int lst = lasts[t];       int x = last[t].first, y = last[t].second;       t ^= lst;       while (lst) {         int z = lastnode[x][y][lst];         printf( %d %d n , y, z);         lst ^= (1 << (z - 1));         y = z;       }       printf( %d %d n , x, y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T, cnt = 0;     cin >> T;     while (T--) {       long long int k, n, a, b;       cin >> k >> n >> a >> b;       k -= n * a;       if (k > 0)         cout << n <<   n ;       else {         k = -k;         long long int dif = a - b;         long long int turns = (k + dif) / dif;         if (turns > n)           cout <<  -1 n ;         else           cout << n - turns <<   n ;       }     }     return 0;   }