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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n vector<char> a; n int x, y, n; n void update(pair<int, int> &pos, int i, int d) { n   if (a[i] ==  U ) n     pos.second += d; n   else if (a[i] ==  D ) n     pos.second -= d; n   else if (a[i] ==  R ) n     pos.first += d; n   else n     pos.first -= d; n } n bool ok(pair<int, int> pos, int len) { n   int d = abs(x - pos.first) + abs(y - pos.second); n   if (d <= len && d % 2 == len % 2) return true; n   return false; n } n bool can(int len) { n   pair<int, int> pos = make_pair(0, 0); n   for (int i = len; i < a.size(); i++) update(pos, i, 1); n   int l = 0, r = len; n   while (1) { n     if (ok(pos, len)) return true; n     if (n == r) break; n     update(pos, l++, 1); n     update(pos, r++, -1); n   } n   return false; n } n int main() { n   cin >> n; n   cin.ignore(); n   for (int i = 0; i < n; i++) { n     char temp; n     cin >> temp; n     a.push_back(temp); n   } n   cin >> x >> y; n   if (!ok(make_pair(0, 0), n)) n     cout << -1 << endl; n   else { n     int l = -1, r = n; n     while (r - l > 1) { n       int len = (r + l) / 2; n       if (can(len)) n         r = len; n       else n         l = len; n     } n     cout << r << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void chkmin(T &a, T b) { n   if (a > b) a = b; n } n template <class T> n inline void chkmax(T &a, T b) { n   if (a < b) a = b; n } n int main() { n   int N, x, M, y, d, len1, len2, len, r1, r2, r, i; n   long long ans; n   scanf( %d%d%d%d , &N, &x, &M, &y); n   if (N < M) { n     swap(x, y); n     swap(N, M); n   } n   d = abs(x - y); n   ans = N + M + 1 - max(min(M, N - d), 0); n   for (i = 1; i <= N; i++) { n     if (i <= d) n       len1 = d - i + 1; n     else n       len1 = i - d; n     len2 = 1; n     r1 = d + i; n     r2 = M; n     len = max(len1, len2); n     r = min(r1, r2); n     ans += 2 * max(0, r - len + 1); n     if (len1 <= r2) ans--; n     if (r1 <= r2) ans -= 2; n   } n   printf( %I64d n , ans); n   return 0; n } n


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 510000; n char s[maxn]; n int n, maxtime; n int house; n bool ok(int need) { n   int time = 0, candy = need, total = house; n   int p = 0, q = 0; n   int i; n   for (i = 0; i < n; i++) { n     p += (s[i] ==  H ); n     q += (s[i] ==  S ); n     if (p == total && (q + need) >= house) break; n   } n   if (!(p == total && (q + need) >= house)) return 0; n   if (2 * (i + 1) - 1 <= maxtime) return 1; n   for (int i = 0; i < n; i++) { n     if (!total) return time <= maxtime; n     if (++time > maxtime) return 0; n     if (s[i] ==  S ) { n       candy++; n     } else if (s[i] ==  H ) { n       if (candy) { n         candy--; n         total--; n         continue; n       } n       int h2 = 0, k = 0, j; n       for (j = i; j < n; j++) { n         if (s[j] ==  H ) n           k++, h2++; n         else if (s[j] ==  S ) n           k--, s[j] =  . ; n         if (k == 0) break; n       } n       if (k) return 0; n       time += 2 * (j - i); n       time--; n       candy += h2; n       i--; n     } n   } n   return time <= maxtime; n } n char str[maxn]; n int main() { n   while (scanf( %d%d , &n, &maxtime) != EOF) { n     scanf( %s , str); n     house = 0; n     for (int i = 0; i < n; i++) { n       house += (str[i] ==  H ); n     } n     int l = 0, r = n; n     int ans = -1; n     while (l <= r) { n       int m = (l + r) >> 1; n       memcpy(s, str, sizeof s); n       if (ok(m)) { n         r = m - 1; n         ans = m; n       } else n         l = m + 1; n     } n     printf( %d n , ans); n   } n   return 0; n } n