#include <bits/stdc++.h> n using namespace std; n int n; n int X, t[10000], h[10000], m[10000], v[10000]; n int f(int x) { n   int ht = X; n   memset(v, 0, sizeof(v)); n   for (int i = (0); i < (n); i++) { n     int tmp = -1; n     for (int j = (0); j < (n); j++) { n       if (v[j] || t[j] != ((i + x) & 1) || h[j] > ht) continue; n       if (tmp == -1) tmp = j; n       if (m[j] > m[tmp]) tmp = j; n     } n     if (tmp == -1) return i; n     ht += m[tmp]; n     v[tmp] = 1; n   } n   return n; n } n int main() { n   scanf( %d%d , &n, &X); n   for (int i = (0); i < (n); i++) scanf( %d%d%d , t + i, h + i, m + i); n   int ans = 0, tmp = 0; n   ans = f(0); n   ans = max(ans, f(1)); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s; n set<string> aux; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     cin >> s; n     string ns =   ; n     for (int j = 0; j < s.size(); j++) { n       if (s[j] ==  u ) n         ns +=  oo ; n       else if (s[j] ==  h ) { n         while (!ns.empty() && ns.back() ==  k ) ns.pop_back(); n         ns += s[j]; n       } else n         ns += s[j]; n     } n     aux.insert(ns); n   } n   printf( %d n , aux.size()); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long int n #define inf 1e18 n #define F first n #define S second n #define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) n #define pb push_back n #define pll pair<ll,ll> n #define vl vector<ll> n #define all(x) (x).begin(),(x).end() n #define siz 300005 n #define MOD   998244353 n vector<vector<ll> > adj(siz); n vector<ll> vis(siz,0); n ll mod=MOD; n ll power(ll x, ll y){ n     if (y == 0) n         return 1; n     else if (y % 2 == 0) n         return ((power(x, y / 2))%mod * (power(x, y / 2))%mod)%mod; n     else n         return (x%mod * (power(x, y / 2))%mod * (power(x, y / 2))%mod)%mod; n } n ll foo(ll n){ n  return ( n*(n+1) )/2; n } n int main(){ n  ll q=1; n  cin>>q; n  while(q--){ n   string s; n   cin>>s; n   ll n=s.size(),gap=0,last=-1,l=0,r=0,ans=0; n   while(l<n){ n    //cout<<last<<   <<l<<   <<r<<   <<ans<<endl; n    if(r==n or (last!=-1 and s[r]!= ?  and  n     ((s[r]!=s[last] and gap%2==1) n      or(s[r]==s[last] and gap%2==0)) ) ){ n     if(r==n){ n      ans+=foo(r-l); n      break; n     } n     ll nl=last+1; n     ans+=(foo(r-l)-foo(r-nl)); n     if(last<nl)last=-1;l=nl; n    } n    else{ n     if(s[r]!= ? ){last=r;gap=0;} n     else gap++; n     r++; n    } n   } n   cout<<ans<<endl; n  } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, i, j, k, l; n   cin >> n >> m; n   k = (n - m) / 2; n   j = 1; n   while (j <= n) { n     if (j % (k + 1) == 0) { n       cout <<  1 ; n     } else { n       cout <<  0 ; n     } n     j++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxS = 2e5 + 5; n long long N, M; n long long A[201], B[201]; n long long DP[201][515]; n long long go(long long pos, long long prev) { n   if (pos == N + 1) return 0; n   if (DP[pos][prev] != -1) return DP[pos][prev]; n   long long ans = INT_MAX; n   for (long long i = 1; i <= M; i++) n     ans = min(ans, n               (prev | (A[pos] & B[i]) | go(pos + 1, (prev | (A[pos] & B[i]))))); n   return DP[pos][prev] = ans; n } n void code_idhr_h() { n   cin >> N >> M; n   for (long long i = 1; i <= N; i++) cin >> A[i]; n   for (long long i = 1; i <= M; i++) cin >> B[i]; n   memset(DP, -1, sizeof DP); n   cout << go(1, 0) <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long T = 1; n   for (long long t = 1; t <= T; t++) { n     code_idhr_h(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5000000 + 10; n const int mod = 51123987; n int n; n long long p[maxn], sum; n char s1[maxn], s[maxn]; n long long min(int a, int b) { return a < b ? a : b; } n inline void init() { n   s[0] =  $ ; n   for (int i = 1; i <= n; ++i) s[2 * i] = s1[i], s[2 * i - 1] =  # ; n   s[2 * n + 1] =  # ; n   n = 2 * n + 1; n } n inline void manacher() { n   init(); n   p[0] = 0; n   for (int i = 1, id = 0, mx = 0; i <= n; ++i) { n     if (mx > i) n       p[i] = min(mx - i + 1, p[2 * id - i]); n     else n       p[i] = 0; n     while (s[i - p[i]] == s[i + p[i]]) ++p[i]; n     if (i + p[i] - 1 > mx) id = i, mx = i + p[i] - 1; n     sum += (p[i] - 1) / 2; n     if (i % 2 == 0) ++sum; n   } n } n long long f[maxn], g[maxn]; n inline void solve() { n   sum %= mod; n   sum = sum * (sum - 1) / 2; n   sum %= mod; n   for (int i = 2; i <= n; i += 2) { n     ++f[i - p[i] + 2]; n     --f[i + 2]; n     ++g[i]; n     --g[i + p[i]]; n   } n   for (int i = 1; i <= n; i += 2) { n     ++f[i - p[i] + 2]; n     --f[i + 1]; n     ++g[i + 1]; n     --g[i + p[i]]; n   } n   for (int i = 2; i <= n; i += 2) { n     f[i] += f[i - 2]; n     f[i] %= mod; n     g[i] += g[i - 2]; n     g[i] %= mod; n   } n   f[n + 1] = 0; n   for (int i = n - 1; i >= 1; i -= 2) f[i] += f[i + 2]; n   for (int i = 2; i <= n; i += 2) { n     sum = sum - (g[i] * f[i + 2]) % mod; n     sum = (sum + mod) % mod; n   } n   sum = (sum + mod) % mod; n   printf( %I64d n , sum); n } n int main() { n   scanf( %d%s , &n, s1 + 1); n   manacher(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n using vi = vector<int>; n constexpr int MOD = 998244353; n int sum(int a, int b, int mod = MOD) { n   int c = a + b; n   if (c >= mod) { n     c -= mod; n   } n   return c; n } n inline int prod(int a, int b, int mod = MOD) { return (1LL * a * b) % mod; } n int modpow(int base, ll exp, int mod = MOD) { n   int res = 1; n   int cur = base; n   for (ll p = 1LL; p <= exp; p <<= 1LL) { n     if (p & exp) { n       res = prod(res, cur, mod); n     } n     cur = prod(cur, cur, mod); n   } n   return res; n } n inline int inv(int x, int mod = MOD) { return modpow(x, mod - 2, mod); } n constexpr int MAXN = 1e6 + 6; n int fact[MAXN], tcaf[MAXN]; n void gen_fact() { n   fact[0] = 1; n   for (int i = 1; i < MAXN; ++i) { n     fact[i] = prod(fact[i - 1], i); n   } n   tcaf[MAXN - 1] = inv(fact[MAXN - 1]); n   for (int i = MAXN - 2; i >= 0; --i) { n     tcaf[i] = prod(tcaf[i + 1], i + 1); n   } n } n int choose(int n, int k) { n   assert(n >= 0); n   assert(0 <= k and k <= n); n   return prod(fact[n], prod(tcaf[k], tcaf[n - k])); n } n int solve(ll n) { n   int ans = modpow(3, 1LL * n * n); n   for (int i = 1; i <= n; ++i) { n     int x = prod(choose(n, i), modpow(3, 1LL * (n * (n - i)) + i)); n     int v = prod(2, x); n     if (i % 2 == 0) { n       ans = sum(ans, v); n     } else { n       ans = sum(ans, MOD - v); n     } n   } n   for (int i = 1; i < n; ++i) { n     int v = prod(6, choose(n, i)); n     if ((i + n) % 2 == 0) { n       ans = sum(ans, v); n     } else { n       ans = sum(ans, MOD - v); n     } n   } n   ans = sum(ans, 3); n   int square_sum = 0; n   for (int i = 1; i < n; ++i) { n     int row_sum = modpow(1 + MOD - modpow(3, i), n); n     row_sum = sum(row_sum, MOD - 1); n     row_sum = sum(row_sum, MOD - modpow(MOD - modpow(3, i), n)); n     square_sum = n         sum(square_sum, prod(modpow(MOD - 1, i), prod(choose(n, i), row_sum))); n   } n   ans = sum(ans, prod(3, square_sum)); n   return sum(modpow(3, 1LL * n * n), MOD - ans); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   gen_fact(); n   int n; n   cin >> n; n   cout << solve(n); n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   string s; n   cin >> s; n   long long l = -1, r = -1; n   for (long long i = 0; i < s.length(); i++) { n     if (s[i] ==  [ ) { n       l = i; n       break; n     } n   } n   for (long long i = s.length(); i >= 0; i--) { n     if (s[i] ==  ] ) { n       r = i; n       break; n     } n   } n   if (l == -1 || r == -1 || r < l) n     cout <<  -1  n          <<   n , n         exit(0); n   s = s.substr(l, r - l + 1); n   l = -1; n   r = -1; n   for (long long i = 1; i < s.length() - 1; i++) { n     if (s[i] ==  : ) { n       l = i; n       break; n     } n   } n   for (long long i = s.length() - 2; i >= 1; i--) { n     if (s[i] ==  : ) { n       r = i; n       break; n     } n   } n   if (l == r || l == -1) cout <<  -1 n , exit(0); n   string v = s.substr(l, r - l + 1); n   long long ct = 0; n   for (auto it : v) { n     if (it ==  | ) ct++; n   } n   cout << ct + 4 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, car[101][101]; n   bool t[101] = {0}; n   vector<int> ans; n   ans.clear(); n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       scanf( %d , &car[i][j]); n       if (car[i][j] == 2) { n         t[j] = true; n       } else if (car[i][j] == 1) { n         t[i] = true; n       } else if (car[i][j] == 3) { n         t[i] = true; n         t[j] = true; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     if (t[i] == false) ans.push_back(i + 1); n   } n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); i++) { n     printf( %d , ans[i]); n     if (i < ans.size() - 1) printf(   ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4003; n int t[N][N]; n int a; n string s; n map<long long, long long> mp; n long long acc[N]; n int main() { n   cin >> a >> s; n   int n = s.size(); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) t[i][j] = (s[i] -  0 ) * (s[j] -  0 ); n   for (int i = 0; i < n; i++) { n     long long sum = 0; n     for (int j = 0; j <= i; j++) sum += (s[j] -  0 ); n     acc[i] = sum; n   } n   acc[-1] = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j <= i; j++) { n       long long sum = acc[i] - acc[j - 1]; n       mp[sum]++; n     } n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     long long sum = 0; n     for (int j = 0; j <= i; j++) { n       sum = acc[i] - acc[j - 1]; n       if (sum) n         if (a % sum == 0) { n           ans += mp[a / sum]; n         } n       if (!sum && !a) ans += n * (n + 1) / 2; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T sqr(T X) { n   return X * X; n } n const int maxn = 110; n const double zero = 1e-8; n int n, K; n double omiga; n struct COO { n   double x, y; n } ob[maxn], nuclear; n double p[maxn], f[maxn][maxn]; n double numb; n double ans; n void init() { n   scanf( %d , &n); n   scanf( %d%lf , &K, &omiga); n   omiga = 1.0 - omiga / 1000; n   scanf( %lf%lf , &nuclear.x, &nuclear.y); n   for (int i = 1; i <= n; i++) scanf( %lf%lf , &ob[i].x, &ob[i].y); n } n int ZO(double comX, double comY) { n   if (abs(comY - comX) <= zero) return 0; n   if (comX < comY) n     return -1; n   else n     return 1; n } n void work1(double R) { n   for (int i = 1; i <= n; i++) { n     double Di = sqr(nuclear.x - ob[i].x) + sqr(nuclear.y - ob[i].y); n     if (ZO(Di, sqr(R)) <= 0) n       p[i] = 1.0; n     else n       p[i] = exp(1 - Di / sqr(R)); n   } n } n void dp() { n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= n; j++) f[i][j] = 0.0; n   f[0][0] = 1.0; n   for (int i = 1; i <= n; i++) f[i][0] = f[i - 1][0] * (1 - p[i]); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= i; j++) n       f[i][j] = f[i - 1][j - 1] * p[i] + f[i - 1][j] * (1.0 - p[i]); n   numb = 0.0; n   for (int j = K; j <= n; j++) numb += f[n][j]; n } n void solve() { n   double Lx = 0, Rx = 4000.0; n   while (ZO(Lx, Rx) < 0) { n     double mid = (Lx + Rx) / 2; n     work1(mid); n     dp(); n     if (numb >= omiga) n       Rx = mid; n     else n       Lx = mid; n   } n   ans = Lx; n } n void print() { printf( %.10lf n , ans); } n int main() { n   init(); n   solve(); n   print(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const int nax = 1e3 + 20; n const int mod = 1e9 + 7; n int fact[nax]; n int binpow(int a, int e) { n   int ans = 1; n   while (e > 1) { n     if (e & 1) { n       ans = (1LL * ans * a) % mod; n       --e; n     } n     a = (1LL * a * a) % mod; n     e >>= 1; n   } n   ans = (1LL * ans * a) % mod; n   return ans; n } n int C(int n, int k) { n   if (k > n) return 0; n   return (1LL * fact[n] * n           (1LL * binpow(fact[n - k], mod - 2) * binpow(fact[k], mod - 2) % n            mod)) % n          mod; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << setprecision(20) << fixed; n   fact[0] = 1; n   for (int i = 1; i <= (int)nax - 1; ++i) { n     fact[i] = (1LL * fact[i - 1] * i) % mod; n   } n   int n, m, k; n   cin >> n >> m >> k; n   cout << (1LL * C(n - 1, 2 * k) * C(m - 1, 2 * k)) % mod <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class X, class Y> n void amax(X& x, const Y& y) { n   if (x < y) x = y; n } n template <class X, class Y> n void amin(X& x, const Y& y) { n   if (x > y) x = y; n } n const int INF = 1e9 + 10; n const long long INFL = (long long)1e18 + 10; n const int MAX = 2e5 + 10; n int n; n long long l[MAX], r[MAX]; n map<long long, long long> cnt, inc, ddec; n void process() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> l[i] >> r[i]; n   long long maxr = 0, minl = INFL; n   for (int i = 1; i <= n; i++) { n     inc[l[i]] = ddec[l[i]] = 0; n     inc[r[i]] = ddec[r[i]] = 0; n     amax(maxr, r[i]); n     amin(minl, l[i]); n   } n   ddec[maxr + 1] = 0; n   for (int i = 1; i <= n; i++) { n     inc[l[i]]++; n     auto p2 = ddec.find(r[i]); n     p2 = next(p2); n     p2->second++; n   } n   long long ppost = minl - 1; n   int psum = 0; n   for (auto p : inc) { n     psum -= ddec[p.first]; n     cnt[psum] += p.first - ppost - 1; n     psum += p.second; n     cnt[psum]++; n     ppost = p.first; n   } n   for (int i = 1; i <= n; i++) cout << cnt[i] <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   process(); n } n


#include <bits/stdc++.h> n int main() { n   long long int m, n, a; n   scanf( %lld %lld %lld , &m, &n, &a); n   if (m % a == 0 && n % a == 0) { n     printf( %lld , m * n / a / a); n   } n   if (m % a != 0 && n % a == 0) { n     printf( %lld , ((m + a) / a) * (n / a)); n   } n   if (m % a != 0 && n % a != 0) { n     printf( %lld , ((m + a) / a) * ((n + a) / a)); n   } n   if (m % a == 0 && n % a != 0) { n     printf( %lld , m / a * ((n + a) / a)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> e[200000 + 5]; n int main() { n   int T, n; n   int m, p; n   scanf( %d , &T); n   for (int t = 1; t <= T; ++t) { n     scanf( %d , &n); n     for (int i = 0; i <= n; ++i) e[i].clear(); n     for (int i = 1; i <= n; ++i) { n       scanf( %d%d , &m, &p); n       e[m].push_back(p); n     } n     priority_queue<int, vector<int>, greater<int> > que; n     long long ans = 0; n     for (int i = n; i >= 0; --i) { n       int len = e[i].size(); n       for (int j = 0; j < len; ++j) que.push(e[i][j]); n       while (que.size() > n - i) { n         ans += que.top(); n         que.pop(); n       } n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[200009]; n set<int> ss; n pair<int, int> help[200009]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     v[a].push_back(b); n   } n   for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end()); n   help[0] = pair<int, int>(0, 0); n   for (int i = 1; i <= n; i++) n     if (v[i].size() != 0) n       help[i] = pair<int, int>(v[i][v[i].size() - 1], i); n     else n       help[i] = pair<int, int>(0, 0); n   sort(help, help + n + 1); n   int q; n   cin >> q; n   for (int i = 0; i < q; i++) { n     ss.clear(); n     int k; n     cin >> k; n     for (int i = 0; i < k; i++) { n       int a; n       scanf( %d , &a); n       ss.insert(a); n     } n     int A, B; n     A = B = -1; n     for (int j = n; j >= 1; j--) { n       if (help[j].first == 0) break; n       if (A != -1 && B != -1) break; n       if (A == -1) { n         if (ss.find(help[j].second) == ss.end() && help[j].second != 0) n           A = help[j].second; n       } else { n         if (ss.find(help[j].second) == ss.end() && help[j].second != 0) n           B = help[j].second; n       } n     } n     if (B == -1 && A == -1) n       printf( 0 0 n ); n     else if (B == -1) n       printf( %d %d n , A, v[A][0]); n     else { n       int x = v[B][v[B].size() - 1]; n       int y = *lower_bound(v[A].begin(), v[A].end(), x); n       printf( %d %d n , A, y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[100010]; n int c[100010]; n const int mod = 1000000007; n long long Pow(long long a, long long b, long long c) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % c; n     b >>= 1; n     a = a * a % c; n   } n   return ans; n } n int main() { n   scanf( %s , a); n   int n = strlen(a), k; n   int cnt0 = count(a, a + n,  0 ); n   int cnt5 = count(a, a + n,  5 ); n   int cnt = 0; n   for (int i = 0; i <= n - 1; i++) { n     if (a[i] ==  0  || a[i] ==  5 ) { n       c[cnt++] = i; n     } n   } n   scanf( %d , &k); n   long long tmp1 = Pow(2, (long long)n * k, mod); n   tmp1 -= 1; n   if (tmp1 < 0) tmp1 += mod; n   long long tmp2 = Pow(2, n, mod); n   tmp2 -= 1; n   if (tmp2 < mod) tmp2 += mod; n   tmp2 = Pow(tmp2, mod - 2, mod); n   long long ans = 0; n   for (int i = 0; i <= cnt - 1; i++) { n     ans += Pow(2, c[i], mod) * tmp1 % mod * tmp2 % mod; n     if (ans >= mod) ans -= mod; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, ans = 0, xs, ys, xe, ye; n   char q[105][105]; n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       cin >> q[i][j]; n       if (q[i][j] ==  S ) { n         xs = i; n         ys = j; n       } n       if (q[i][j] ==  E ) { n         xe = i; n         ye = j; n       } n     } n   } n   string line; n   cin >> line; n   int x, y; n   for (int w = 0; w <= 3; ++w) { n     for (int l = 0; l <= 3; ++l) { n       for (int s = 0; s <= 3; ++s) { n         for (int r = 0; r <= 3; ++r) { n           if (w == l || w == s || w == r) { n             continue; n           } n           if (l == s || l == r) { n             continue; n           } n           if (s == r) { n             continue; n           } n           x = xs; n           y = ys; n           for (int i = 0; i < line.size(); ++i) { n             int p = line[i] -  0 ; n             if (p == w) { n               x++; n               if (x >= n) { n                 break; n               } n             } n             if (p == l) { n               y--; n               if (y < 0) { n                 break; n               } n             } n             if (p == s) { n               x--; n               if (x < 0) { n                 break; n               } n             } n             if (p == r) { n               y++; n               if (y >= m) { n                 break; n               } n             } n             if (x == xe && y == ye) { n               break; n             } n             if (q[x][y] ==  # ) { n               break; n             } n           } n           if (x == xe && y == ye) { n             ans++; n           } n         } n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double TOLL = 1e-9; n int N, L, K; n int a[210]; n double p[210]; n const int maxn = 400; n double dp[201][401][maxn + 2]; n double rec(int ind, int l, int cap) { n   if (cap < -202) cap = -200; n   if (cap > 202) cap = 200; n   if (ind == N) { n     if (l <= 0 && cap >= 0) return 1; n     return 0; n   } n   if (dp[ind][l + 200][cap + 200] > -.5) return dp[ind][l + 200][cap + 200]; n   double rv = p[ind] * rec(ind + 1, l - 1, cap + a[ind]) + n               (1 - p[ind]) * rec(ind + 1, l, cap); n   return dp[ind][l + 200][cap + 200] = rv; n } n int main() { n   while (cin >> N >> L >> K) { n     for (int i = 0; i < N; i++) { n       cin >> p[i]; n       p[i] /= 100; n     } n     for (int i = 0; i < N; i++) cin >> a[i]; n     memset(dp, -1, sizeof dp); n     printf( %.12lf n , rec(0, L, K)); n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) n using namespace std; n const int N = 2e5 + 100, sq = 1002, nsq = 200; n int cnt[nsq][N], b[nsq][N / 2]; n int a[N]; n map<int, int> mp, nmp; n vector<pair<int, pair<int, int> > > q; n void add(int id, int val) { n   while (id < nsq) { n     cnt[id][val]++; n     b[id][cnt[id][val]]++; n     id++; n   } n } n void rem(int id, int val) { n   while (id < nsq) { n     b[id][cnt[id][val]]--; n     cnt[id][val]--; n     id++; n   } n } n int get1(int id) { n   int val = a[id]; n   int pid = id / sq; n   int ans = cnt[pid][val]; n   int x = pid * sq; n   for (int i = x; i <= id; i++) { n     if (a[i] == val) ans++; n   } n   return ans; n } n int get2(int id) { n   int val = a[id]; n   int pid = id / sq; n   int w = cnt[pid][val]; n   int x = pid * sq; n   for (int i = x; i <= id; i++) { n     if (a[i] == val) w++; n   } n   int ans = b[pid][w]; n   for (int i = x; i <= id; i++) { n     cnt[pid][a[i]]++; n     if (cnt[pid][a[i]] == w) ans++; n   } n   for (int i = x; i <= id; i++) { n     cnt[pid][a[i]]--; n   } n   return ans; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   vector<int> mol; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     mol.push_back(a[i]); n   } n   int q1; n   cin >> q1; n   for (int i = 0; i < q1; i++) { n     int t, u, v; n     cin >> t >> u >> v; n     if (t == 1) mol.push_back(u); n     q.push_back({t, {u, v - 1}}); n   } n   sort(mol.begin(), mol.end()); n   mol.resize(unique(mol.begin(), mol.end()) - mol.begin()); n   for (int i = 0; i < mol.size(); i++) { n     mp[mol[i]] = i + 1; n     nmp[i + 1] = mol[i]; n   } n   for (int i = 0; i < n; i++) a[i] = mp[a[i]]; n   for (int i = 0; i < q1; i++) n     if (q[i].first == 1) q[i].second.first = mp[q[i].second.first]; n   int id = 0; n   while (id < n) { n     for (int i = 0; i < id; i++) { n       cnt[id / sq][a[i]]++; n     } n     for (int i = 0; i < N; i++) { n       b[id / sq][cnt[id / sq][i]]++; n     } n     for (int i = N - 1; i; i--) { n       b[id / sq][i] += b[id / sq][i + 1]; n     } n     id += sq; n   } n   for (int i = 0; i < q1; i++) { n     if (q[i].first == 1) { n       int v = q[i].second.first, p = q[i].second.second; n       int z = a[p]; n       add(p / sq + 1, v); n       rem(p / sq + 1, a[p]); n       a[p] = v; n     } else { n       int x = q[i].second.first, y = q[i].second.second; n       if (x == 1) n         cout << nmp[a[y]] <<   n ; n       else if (x % 2 == 0) { n         int ans = get1(y); n         cout << ans <<   n ; n       } else { n         int ans = get2(y); n         cout << ans <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T getint() { n   T x = 0, p = 1; n   char ch; n   do { n     ch = getchar(); n   } while (ch <=    ); n   if (ch ==  - ) p = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * p; n } n template <typename T1, typename T2> n bool umin(T1 &x, const T2 &y) { n   if (x > y) return x = y, true; n   return false; n } n template <typename T1, typename T2> n bool umax(T1 &x, const T2 &y) { n   if (x < y) return x = y, true; n   return false; n } n const int maxn = (int)6e5 + 10; n const int inf = (int)1e9 + 5; n const int mod = (int)1e9 + 7; n const long long llinf = (long long)1e18 - 1; n const long double pi = acos(-1.0); n int nxt[maxn][26]; n bool leaf[maxn]; n int diff[maxn]; n int c[maxn]; n char s[maxn]; n int n; n vector<int> g[maxn]; n int sz[maxn]; n int root[maxn]; n int T = 1; n int calc(int v) { n   int ret = leaf[v]; n   for (int i = (0); i < (26); i++) n     if (nxt[v][i]) ret += calc(nxt[v][i]); n   return ret; n } n void addTrie(int globroot, int root, int v) { n   for (int c = (0); c < (26); c++) { n     if (nxt[v][c] == 0) continue; n     if (nxt[root][c] == 0) { n       diff[globroot] += calc(nxt[v][c]); n       nxt[root][c] = nxt[v][c]; n       continue; n     } n     diff[globroot] += leaf[nxt[v][c]] - leaf[nxt[root][c]]; n     leaf[nxt[root][c]] |= leaf[nxt[v][c]]; n     addTrie(globroot, nxt[root][c], nxt[v][c]); n   } n } n void dfs(int v, int par = -1) { n   sz[v] = 1; n   int chi = -1; n   for (int x : g[v]) { n     if (x == par) continue; n     dfs(x, v); n     sz[v] += sz[x]; n     if (chi == -1 || sz[x] > sz[chi]) { n       chi = x; n     } n   } n   int &rt = root[v]; n   rt = T++; n   int &link = nxt[rt][s[v] -  a ]; n   if (chi != -1) { n     link = root[chi]; n     diff[rt] += diff[link]; n     for (int x : g[v]) { n       if (x == par || x == chi) continue; n       addTrie(rt, link, root[x]); n     } n   } else { n     link = T++; n   } n   leaf[link] = true; n   diff[rt]++; n   c[v] += diff[rt]; n } n int main() { n   scanf( %d , &n); n   for (int i = (0); i < (n); i++) scanf( %d , c + i); n   gets(s); n   gets(s); n   for (int i = (0); i < (n - 1); i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     --x; n     --y; n     g[x].push_back(y), g[y].push_back(x); n   } n   dfs(0, -1); n   int mx = c[0] + diff[0], cnt = 1; n   for (int i = (1); i < (n); i++) { n     int val = c[i]; n     if (val > mx) mx = val, cnt = 0; n     if (val == mx) cnt++; n   } n   printf( %d n%d n , mx, cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd; n const int N = 1e5 + 10; n long long a[N], pref[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, d, m; n   cin >> n >> d >> m; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) { n     pref[i] = pref[i - 1] + a[i]; n   } n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] <= m) { n       cnt++; n     } n   } n   long long ans = 0; n   for (int k = 0; k <= n - cnt; k++) { n     if (1ll * k * d + k + cnt < n) { n       continue; n     } n     if (1ll * (k - 1) * d + k > n) { n       continue; n     } n     int x = min(cnt, n - (k - 1) * d - k); n     ans = max(ans, pref[cnt] - pref[cnt - x] + pref[n] - pref[n - k]); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<pair<long long, long long>> vp; n   long long p, a, l = 0, r = 0, ss = 0; n   for (int i = 0; i < n; i++) { n     cin >> p >> a; n     if (p < 0) { n       ++l; n     } else { n       ++r; n     } n     ss += a; n     vp.push_back(make_pair(p, a)); n   } n   if (l == r or l == r + 1 or r == l + 1) { n     cout << ss <<   n ; n     return; n   } n   sort(vp.begin(), vp.end()); n   if (l == 0) { n     cout << vp[0].second <<   n ; n     return; n   } else if (r == 0) { n     cout << vp[n - 1].second <<   n ; n     return; n   } n   long long ans = 0; n   if (l < r) { n     for (int i = 0; i <= 2 * l; i++) { n       ans += vp[i].second; n     } n   } else { n     for (int i = l - r - 1; i < n; i++) { n       ans += vp[i].second; n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double work(int x) { n   if (x == 0) return 1; n   double n = 1.000000011; n   double ans = 1; n   while (x > 0) { n     if ((x & 1) == 1) ans *= n; n     n *= n; n     x /= 2; n   } n   return ans; n } n int main() { n   int n, t; n   cin >> n >> t; n   printf( %0.20lf n , work(t) * n); n   return 0; n } n


//Template Made By: Ojassvi Kumar n #include<bits/stdc++.h> n using namespace std; n   n #define ios ios_base::sync_with_stdio(false);cin.tie(NULL); n #define ll long long int n #define fo(i,a,b) for(long long int i=a; i<b; i++) n #define endl   n  n #define max3(a,b,c) max(max((a),(b)),(c)) n #define max4(a,b,c,d) max(max((a),(b)),max((c),(d))) n #define min3(a,b,c) min(min((a),(b)),(c)) n #define min4(a,b,c,d) min(min((a),(b)),min((c),(d))) n #define pb push_back n #define lb lower_bound n #define up upper_bound n #define all(V) V.begin(),V.end() n #define itv vector<long long int>::iterator n #define pll pair<long long int,long long int> n #define mp make_pair n #define itp vector<pair<long long int,long long int>>::iterator n #define sll set<long long int,greater<long long int>> n #define its set<long long int,greater<long long int>>::iterator n #define d0(x) cout<<(x)<<    n #define d1(x) cout<<(x)<<endl n #define d2(x,y) cout<<(x)<<   <<(y)<<endl n   n //const long double pi = 3.14159265358979323846264338; n //Template Ends n   n int main(){ n     ios n     #ifndef ONLINE_JUDGE n     freopen( INPUT.txt ,  r , stdin); n     freopen( OUTPUT.txt ,  w , stdout); n     #endif n     ll Tests=1; n     cin>>Tests; n     while(Tests--){ n         ll N,L,R,S; n         cin>>N>>L>>R>>S; n         ll num=R-L+1; n         ll Hsum=0,Lsum=0; n         fo(i,0,num){ n             Hsum+=(N-i); n             Lsum+=(i+1); n         } n         if(S>Hsum||S<Lsum){ n             cout<<-1<<endl; n         } n         else{ n             vector<ll> V(num); n             fo(i,0,V.size()) n                 V[i]=i+1; n             ll curS=Lsum; n             ll j=num-1; n             ll ceill=N; n             while(1){ n                 if(curS==S){ n                     break; n                 } n                 else{ n                     V[j]++; n                     curS++; n                     if(V[j]==ceill){ n                         j--; n                         ceill--; n                     } n                 } n             } n             set<ll> ST; n             fo(i,0,num) n                 ST.insert(V[i]); n             vector<ll> VV; n             fo(i,0,N){ n                 if(!ST.count(i+1)){ n                     VV.pb(i+1); n                 } n             } n             ll jj=0,jjj=0; n             fo(i,0,N){ n                 if(i>=(L-1)&&i<=(R-1)){ n                     cout<<V[jj]<<   ; n                     jj++; n                 } n                 else{ n                     cout<<VV[jjj]<<   ; n                     jjj++; n                 } n             } n             cout<<endl; n         } n     } n }


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n double PI = 3.1415926536; n const int inf = 1e9 + 7; n long long MAX(long long a, long long b) { return a > b ? a : b; } n long long MIN(long long a, long long b) { return a > b ? b : a; } n inline bool ispalindrome(string s) { n   int n = s.length(), i = 0, j = n - 1; n   while (i <= j) { n     if (s[i] != s[j]) return false; n     i++, j--; n   } n   return true; n } n inline bool isprime(long long n) { n   if (n % 2 == 0) return false; n   for (int i = 3; i * i <= n; i += 2) n     if (n % i == 0) return false; n   return true; n } n void solve() { n   int n, k; n   cin >> n >> k; n   queue<int> q; n   set<int> vals; n   for (int i = 0; i < n; ++i) { n     int id; n     cin >> id; n     if (!vals.count(id)) { n       if (int(q.size()) >= k) { n         int cur = q.front(); n         q.pop(); n         vals.erase(cur); n       } n       vals.insert(id); n       q.push(id); n     } n   } n   vector<int> res; n   while (!q.empty()) { n     res.push_back(q.front()); n     q.pop(); n   } n   reverse(res.begin(), res.end()); n   cout << res.size() <<   n ; n   for (auto it : res) cout << it <<    ; n   cout <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   string a[2 * n], b[2 * m]; n   for (int i = 0; i < 2 * n; i += 2) { n     cin >> a[i] >> a[i + 1]; n   } n   for (int i = 0; i < 2 * m; i += 2) { n     cin >> b[i] >> b[i + 1]; n   } n   for (int i = 1; i < 2 * m; i += 2) { n     for (int j = 1; j < 2 * n; j += 2) { n       string x = b[i]; n       if ((x.erase(x.size() - 1)).compare(a[j]) == 0) { n         cout << b[i - 1] <<     << b[i] <<   #  << a[j - 1]; n       } n     } n     cout <<   n ; n   } 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   long long t; n   double n; n   cin >> t; n   while (t--) { n     cin >> n; n     if (n * n - 4 * n < 0) { n       cout <<  N  << endl; n       continue; n     } n     if (n == 0) { n       double x = 0, y = 0; n       cout <<  Y   << fixed << setprecision(9) << x <<     << y << endl; n       continue; n     } n     double x = n + sqrt(n * n - 4 * n); n     x /= 2; n     double y = x / (x - 1); n     cout <<  Y   << fixed << setprecision(9) << x <<     << y << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n struct three_t { n   int x, y, z; n   inline three_t(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} n }; n std::vector<int> next[100010]; n std::vector<three_t> to[100010]; n int n, q, t[100010], v[100010], spc[100010], clr[100010], tag[100010], n     col[100010], tmp[100010]; n void build(int x, int p, int count, int delta) { n   if (spc[x]) { n     if (p) to[p].emplace_back(x, count, delta); n     count = delta = 0; n     p = x; n   } else { n     count += !col[x]; n     delta += 1; n   } n   for (auto &y : next[x]) build(y, p, count, delta); n } n void setBlack(int x) { n   if (!col[x]) return void(col[x] = 1); n   tag[x]++; n   for (auto &y : to[x]) { n     if (y.y < tag[x]) { n       setBlack(y.x); n     } n   } n } n void setWhite(int x) { n   clr[x] = 1; n   col[x] = 0; n   tag[x] = 0; n   for (auto &y : to[x]) { n     y.y = y.z; n     setWhite(y.x); n   } n } n void restore(int x, int setWhite, int setBlack) { n   if (spc[x]) { n     setWhite |= clr[x]; n     setBlack = tag[x]; n   } else { n     col[x] = tmp[x] && !setWhite; n     if (setBlack && !col[x]) col[x] = 1, --setBlack; n   } n   for (auto &y : next[x]) restore(y, setWhite, setBlack); n } n int main() { n   std::ios::sync_with_stdio(0); n   std::cin.tie(0); n   std::cout.tie(0); n   std::cin >> n >> q; n   for (int i = 2, x; i <= n; i++) std::cin >> x, next[x].push_back(i); n   for (int i = 1; i <= q; i++) std::cin >> t[i] >> v[i]; n   for (int i = 1; i <= q; i += 480) { n     memset(spc, 0, sizeof(spc)); n     memset(clr, 0, sizeof(clr)); n     memset(tag, 0, sizeof(tag)); n     memcpy(tmp, col, sizeof(tmp)); n     for (int i = 1; i <= n; i++) to[i].clear(); n     for (int j = 0; j < 480 && i + j <= q; j++) spc[v[i + j]] = 1; n     build(1, 0, 0, 0); n     for (int j = 0; j < 480 && i + j <= q; j++) { n       if (t[i + j] == 1) { n         setBlack(v[i + j]); n       } else if (t[i + j] == 2) { n         setWhite(v[i + j]); n       } else { n         std::cout << (col[v[i + j]] ?  black  :  white ) << std::endl; n       } n     } n     restore(1, 0, 0); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void bktk(int i, char *s, int val, int &ans, vector<int> &cnt) { n   if (!s[i]) { n     ans += cnt[val]; n     return; n   } n   val *= 3; n   if (s[i] ==  A ) { n     bktk(i + 1, s, val, ans, cnt); n     bktk(i + 1, s, val + 1, ans, cnt); n   } n   if (s[i] ==  a ) { n     bktk(i + 1, s, val + 2, ans, cnt); n   } n   if (s[i] ==  O ) { n     bktk(i + 1, s, val, ans, cnt); n   } n   if (s[i] ==  o ) { n     bktk(i + 1, s, val + 1, ans, cnt); n     bktk(i + 1, s, val + 2, ans, cnt); n   } n   if (s[i] ==  X ) { n     bktk(i + 1, s, val, ans, cnt); n     bktk(i + 1, s, val + 2, ans, cnt); n   } n   if (s[i] ==  x ) { n     bktk(i + 1, s, val + 1, ans, cnt); n   } n } n int main() { n   int w, n, m; n   scanf( %d %d %d , &w, &n, &m); n   vector<int> f(1 << w, 0); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     f[x]++; n   } n   vector<int> b3(1 << w, 0); n   for (int i = 0; i < (1 << w); i++) { n     for (int k = w - 1; k >= 0; k--) { n       b3[i] = b3[i] * 3 + ((i >> k) & 1); n     } n   } n   vector<int> cnt(531441, 0); n   for (int i = 0; i < (1 << w); i++) { n     for (int j = 0; j < (1 << w); j++) { n       cnt[b3[i] + b3[j]] += f[i] * f[j]; n     } n   } n   while (m--) { n     char s[14]; n     scanf( %s , s); n     int ans = 0; n     bktk(0, s, 0, ans, cnt); n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, w, x, sum = 0, mmax = 0, us = 0; n   cin >> n >> w; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &x); n     sum += x; n     us = min(us, sum); n     mmax = max(mmax, sum); n   } n   if (us < 0) n     us = -us; n   else n     us = 0; n   printf( %d n , max(w - mmax - us + 1, 0)); n   return 0; n } n


#include <bits/stdc++.h> n int MOD = 1000000007; n long long inf = 1e18; n using namespace std; n vector<int> A, B, C; n int as, bs, cs; n int a, b, c; n int k, n1, n2, n3, t1, t2, t3; n bool ok(int t) { n   if (a == n1) return false; n   int cntb = 0; n   for (int i = bs; i < B.size(); i++) { n     if (t + t1 < B[i] + t2) { n       cntb++; n     } n   } n   for (int i = as; i < A.size(); i++) { n     if (t + t1 < A[i] + t1 + t2) { n       cntb++; n     } n   } n   if (cntb >= n2) return false; n   int cntc = 0; n   for (int i = cs; i < C.size(); i++) { n     if (t + t1 + t2 < C[i] + t3) { n       cntc++; n     } n   } n   for (int i = bs; i < B.size(); i++) { n     if (t + t1 + t2 < B[i] + t2 + t3) { n       cntc++; n     } n   } n   for (int i = as; i < A.size(); i++) { n     if (t + t1 + t2 < A[i] + t1 + t2 + t3) { n       cntc++; n     } n   } n   if (cntc >= n3) return false; n   return true; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3; n   int t, x; n   bool cont; n   for (t = 1; t <= 30000001; t++) { n     if (k == 0 && c == 0 && b == 0 && a == 0) { n       break; n     } n     cont = true; n     while (c != 0 && cont) { n       x = C[cs]; n       cont = false; n       if (x + t3 == t) { n         cs++; n         c--; n         cont = true; n       } n     } n     cont = true; n     while (b != 0 && cont) { n       x = B[bs]; n       cont = false; n       if (x + t2 == t) { n         bs++; n         b--; n         cont = true; n         C.push_back(t); n         c++; n       } n     } n     cont = true; n     while (a != 0 && cont) { n       x = A[as]; n       cont = false; n       if (x + t1 == t) { n         as++; n         a--; n         cont = true; n         B.push_back(t); n         b++; n       } n     } n     cont = true; n     while (k != 0 && cont) { n       x = t; n       cont = false; n       if (ok(t)) { n         A.push_back(x); n         a++; n         cont = true; n         k--; n       } n     } n   } n   cout << t - 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int MAXN = (int)5e5 + 5; n int n; n struct node { n   int x, y; n } a[MAXN]; n struct BIT { n   long long sum[MAXN]; n   int n; n   void init(int _n) { n     n = _n; n     memset(sum, 0, sizeof(sum)); n     ; n   } n   int lowbit(int x) { return x & -x; } n   void update(int x, long long num) { n     while (x <= n) { n       sum[x] += num; n       x += lowbit(x); n     } n     return; n   } n   long long query(int x) { n     long long ans = 0; n     while (x) { n       ans += sum[x]; n       x -= lowbit(x); n     } n     return ans; n   } n } bita; n vector<int> v; n int getid(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; } n map<int, int> mpx; n int main() { n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; i++) n       scanf( %d%d , &a[i].x, &a[i].y), v.push_back(a[i].x), v.push_back(a[i].y); n     sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end()); n     for (int i = 1; i <= n; i++) { n       a[i].x = getid(a[i].x); n       a[i].y = getid(a[i].y); n     } n     sort(a + 1, a + 1 + n, [](node a, node b) { n       if (a.y != b.y) return a.y > b.y; n       return a.x < b.x; n     }); n     mpx.clear(); n     bita.init(MAXN); n     long long ans = 0; n     for (int i = 1; i <= n; i++) { n       int xx = a[i].x, yy = a[i].y, pre = 0; n       int now = i; n       while (a[now].y == a[i].y && now <= n) { n         if (!mpx[a[now].x]) { n           mpx[a[now].x] = 1; n           bita.update(a[now].x, 1ll); n         } n         now++; n       } n       now--; n       for (int j = i; j <= now; j++) { n         long long l = bita.query(a[j].x - 1) - bita.query(pre); n         long long r = bita.query(2 * n + 1) - bita.query(a[j].x); n         pre = a[j].x; n         ans += (long long)l * r + l + r + 1; n       } n       i = now; n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   scanf( %d%d , &a, &b); n   if (b > a) { n     printf( -1 n ); n   } else if (a == b) { n     printf( %d.000000000 n , a); n   } else { n     int k((a - b) / b); n     if (k & 1) { n       k--; n     } n     double ans1(1. * (a - b) / k); n     k = (a + b) / b; n     if (k & 1) { n       k--; n     } n     double ans2(1. * (a + b) / k); n     printf( %.9f n , min(ans1, ans2)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int n, m, k, i, j, a[200002], sum = 0; n   vector<long long int> v; n   set<pair<long long int, long long int>> s; n   cin >> n >> m >> k; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     s.insert(make_pair(a[i], i)); n   } n   set<pair<long long int, long long int>>::iterator it1, it2; n   it1 = s.begin(); n   it2 = s.end(); n   for (i = 0; i < m * k; i++) { n     it2--; n   } n   s.erase(it1, it2); n   for (i = 0; i < n; i++) { n     if (s.find(make_pair(a[i], i)) != s.end()) { n       sum += a[i]; n     } n   } n   long long int cnt = 0; n   for (i = 0; i < n; i++) { n     auto it = s.find(make_pair(a[i], i)); n     if (cnt == m * (k - 1)) { n       break; n     } n     if (it != s.end()) { n       cnt++; n       if (cnt % m == 0) { n         v.push_back(it->second + 1); n       } n     } n   } n   long long int sz = v.size(); n   cout << sum << endl; n   for (i = 0; i < sz; i++) { n     cout << v[i] <<    ; n   } n   cout << endl; 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 zf = 1; n   char ch = getchar(); n   while (ch !=  -  && !isdigit(ch)) ch = getchar(); n   if (ch ==  - ) zf = -1, ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * zf; n } n void write(long long y) { n   if (y < 0) putchar( - ), y = -y; n   if (y > 9) write(y / 10); n   putchar(y % 10 + 48); n } n void writeln(const long long y) { n   write(y); n   putchar(  n ); n } n int i, j, k, m, n, x, y, z, cnt, dx[10010], dy[10010]; n struct now { n   int t, x, y, p; n } q[1000010]; n int h, t; n long long dis[105][12][12][3]; n bool vis[105][12][12][3]; n void push(now x, long long ds) { n   if (x.x == dx[x.t] && x.y == dy[x.t]) x.t++; n   if (ds >= dis[x.t][x.x][x.y][x.p]) return; n   dis[x.t][x.x][x.y][x.p] = ds; n   if (!vis[x.t][x.x][x.y][x.p]) n     q[++t] = {x.t, x.x, x.y, x.p}, vis[x.t][x.x][x.y][x.p] = 1; n } n int main() { n   n = read(); n   for (register int i = 1; i <= n; i++) n     for (register int j = 1; j <= n; j++) { n       x = read(); n       dx[x] = i; n       dy[x] = j; n     } n   memset(dis, 10, sizeof(dis)); n   long long ans = 1000000000000ll; n   for (register int i = 0; i <= 2; i++) n     dis[2][dx[1]][dy[1]][i] = 0, vis[2][dx[1]][dy[1]][i] = 1; n   t = 3; n   q[1] = {2, dx[1], dy[1], 0}; n   q[2] = {2, dx[1], dy[1], 1}; n   q[3] = {2, dx[1], dy[1], 2}; n   while (h < t) { n     now u = q[++h]; n     vis[u.t][u.x][u.y][u.p] = 0; n     long long ds = dis[u.t][u.x][u.y][u.p]; n     if (u.t > n * n) { n       ans = min(ans, ds); n       continue; n     } n     long long b1 = ds + 1000000; n     if (u.p == 0) { n       for (register int i = 1; i <= n; i++) { n         push({u.t, i, u.y, u.p}, b1); n         push({u.t, u.x, i, u.p}, b1); n       } n     } n     if (u.p == 1) { n       for (register int i = -2; i <= 2; i++) n         for (register int j = -2; j <= 2; j++) n           if (i * j == 2 || i * j == -2) { n             int xx = u.x + i, yy = u.y + j; n             if (xx < 1 || xx > n || yy < 1 || yy > n) continue; n             push({u.t, xx, yy, u.p}, b1); n           } n     } n     if (u.p == 2) { n       for (register int i = -n; i <= n; i++) n         for (register int j = -1; j <= 1; j += 2) { n           int xx = u.x + i, yy = u.y + i * j; n           if (xx < 1 || xx > n || yy < 1 || yy > n) continue; n           push({u.t, xx, yy, u.p}, b1); n         } n     } n     for (register int i = 0; i <= 2; i++) push({u.t, u.x, u.y, i}, b1 + 1); n   } n   cout << ans / 1000000 <<     << ans % 1000000; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x0, y0, x, y; n   cin >> x0 >> y0 >> x >> y; n   if (x0 != x && y != y0 && abs(x - x0) != abs(y - y0)) { n     cout <<  -1  << endl; n     return 0; n   } n   int dx = abs(y - y0); n   int dy = abs(x0 - x); n   if (x0 == x) n     cout << x0 + dx <<     << y0 <<     << x + dx <<     << y << endl; n   else if (y0 == y) n     cout << x0 <<     << y0 + dy <<     << x <<     << y + dy << endl; n   else n     cout << x0 <<     << y <<     << x <<     << y0 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void read(T &n) { n   n = 0; n   T f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) f = -1, c = getchar(); n   while (isdigit(c)) n = n * 10 + c -  0 , c = getchar(); n   n *= f; n } n template <typename T> n void write(T n) { n   if (n < 0) putchar( - ), n = -n; n   if (n > 9) write(n / 10); n   putchar(n % 10 +  0 ); n } n struct Matrix { n   int n, m; n   long long a[3][3]; n   Matrix(int x = 0, int y = 0) : n(x), m(y) { memset(a, 0, sizeof(a)); } n   friend Matrix operator*(Matrix a, Matrix b) { n     Matrix c(a.n, b.m); n     for (int i = 1; i <= a.n; i++) { n       for (int j = 1; j <= b.m; j++) { n         for (int k = 1; k <= a.m; k++) { n           (c.a[i][j] += a.a[i][k] * b.a[k][j] % 998244353) %= 998244353; n         } n       } n     } n     return c; n   } n } s[500005 * 4], mat, ans; n int a[500005 * 4]; n void build(int p, int l, int r) { n   if (l == r) { n     s[p].n = s[p].m = 2; n     s[p].a[1][1] = a[l] + 1; n     s[p].a[2][1] = 1, s[p].a[2][2] = 0; n     if (l > 1 && a[l - 1] == 1) s[p].a[1][2] = 9 - a[l]; n     return; n   } n   build((p << 1), l, ((l + r) >> 1)), n       build((p << 1 | 1), ((l + r) >> 1) + 1, r); n   s[p] = s[(p << 1 | 1)] * s[(p << 1)]; n } n void update(int p, int l, int r, int u, int k) { n   if (l == r) { n     s[p].a[1][1] = k + 1; n     if (u > 1 && a[u - 1] == 1) n       s[p].a[1][2] = 9 - k; n     else n       s[p].a[1][2] = 0; n     a[u] = k; n     return; n   } n   if (((l + r) >> 1) >= u) n     update((p << 1), l, ((l + r) >> 1), u, k); n   else n     update((p << 1 | 1), ((l + r) >> 1) + 1, r, u, k); n   s[p] = s[(p << 1 | 1)] * s[(p << 1)]; n } n int n, m; n int main() { n   mat.n = 2, mat.m = 1; n   mat.a[1][1] = mat.a[2][1] = 1; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) scanf( %1d , &a[i]); n   build(1, 1, n); n   int x, y; n   for (int i = 1; i <= m; i++) { n     read(x), read(y); n     update(1, 1, n, x, y); n     if (x < n) update(1, 1, n, x + 1, a[x + 1]); n     ans = s[1] * mat; n     write(ans.a[1][1]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int long long n, i, k = 0; n   cin >> n; n   double a[n + 5], s = 0, b[n + 5]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     s += a[i]; n   } n   for (i = 0; i < n; i++) { n     double r = (s - a[i]) / (n - 1); n     if (r == a[i]) { n       b[k] = i + 1; n       k++; n     } n   } n   cout << k << endl; n   for (i = 0; i < k; i++) { n     cout << b[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long a, b, d, i, j, k = 0, h, c, p1, p2, q1, q2, A, B, c1, c2, l, m = 0, n                            n, t = 1, q = 0, r, e, x = 0, y = 0, o, s, mx1, n                            mx2 = 0, mx = 0, p = 0, v, mn = 0, z, w; n   string s1, s2, s3, s4; n   cin >> n; n   int arr[n]; n   for (i = 0; i < n; i++) cin >> arr[i]; n   sort(arr, arr + n); n   x = arr[0]; n   t = n / 2; n   i = 1; n   while (t--) { n     cout << arr[i] <<     << x << endl; n     i++; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int nvertices, nedges; n vector<vector<pair<int, int>>> adjList(110); n vector<bool> visited; n void dfs(int u, int c) { n   visited[u] = true; n   for (auto e : adjList[u]) { n     if (!visited[e.first] && (e.second == c)) { n       dfs(e.first, c); n     } n   } n } n int main() { n   cin >> nvertices >> nedges; n   for (int i = 0; i < nedges; i++) { n     int u, v, c; n     cin >> u >> v >> c; n     adjList[u].push_back({v, c}); n     adjList[v].push_back({u, c}); n   } n   int m; n   cin >> m; n   while (m--) { n     int u, v; n     cin >> u >> v; n     set<int> ans; n     for (auto e : adjList[u]) { n       visited.assign(110, false); n       visited[u] = true; n       dfs(e.first, e.second); n       if (visited[v] == true) ans.insert(e.second); n     } n     cout << ans.size() << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int readint() { n   char c; n   while (c = getchar(), (c <  0  || c >  9 ) && c !=  - ) n     ; n   bool flag = (c ==  - ); n   if (flag) c = getchar(); n   int x = 0; n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c - 48; n     c = getchar(); n   } n   return flag ? -x : x; n } n char readchar() { n   char c; n   while (c = getchar(), n          c !=  A  && c !=  C  && c !=  <  && c !=  >  && c !=  ^ ) n     ; n   return c; n } n const int maxn = 100005; n const int maxm = 15; n const int block = 300; n int n, m, q, x, y; n pair<int, int> pos; n char t[maxn][maxm]; n pair<int, int> nxt[maxn][maxm], go[maxn][maxm]; n inline bool on(pair<int, int> pos) { n   return pos.first >= 1 && pos.first <= n && pos.second >= 1 && pos.second <= m; n } n void calc(int x, int y) { n   if (!on(make_pair(x, y))) { n     nxt[x][y] = make_pair(x, y); n     return; n   } n   if (nxt[x][y].first != -2) return; n   if (t[x][y] ==  < ) { n     if (t[x][y - 1] ==  > ) n       nxt[x][y] = make_pair(-1, -1); n     else n       calc(x, y - 1), nxt[x][y] = nxt[x][y - 1]; n   } else if (t[x][y] ==  > ) { n     if (t[x][y + 1] ==  < ) n       nxt[x][y] = make_pair(-1, -1); n     else n       calc(x, y + 1), nxt[x][y] = nxt[x][y + 1]; n   } else n     nxt[x][y] = make_pair(x - 1, y); n } n void jump(int start, int finish) { n   for (int i = start; i <= finish && i <= n; i++) { n     if (i % block == 1) { n       for (int j = 1; j <= m; j++) go[i][j] = nxt[i][j]; n     } else { n       for (int j = 1; j <= m; j++) { n         if (!on(nxt[i][j])) n           go[i][j] = nxt[i][j]; n         else n           go[i][j] = go[nxt[i][j].first][nxt[i][j].second]; n       } n     } n   } n } n int main() { n   n = readint(); n   m = readint(); n   q = readint(); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       t[i][j] = readchar(), nxt[i][j] = make_pair(-2, -2); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) calc(i, j); n   jump(1, n); n   while (q--) { n     char type = readchar(); n     if (type ==  A ) { n       pos.first = readint(); n       pos.second = readint(); n       while (on(pos)) { n         pos = go[pos.first][pos.second]; n       } n       printf( %d %d n , pos.first, pos.second); n     } else { n       x = readint(); n       y = readint(); n       char op = readchar(); n       t[x][y] = op; n       for (int j = 1; j <= m; j++) nxt[x][j] = make_pair(-2, -2); n       for (int j = 1; j <= m; j++) calc(x, j); n       jump(x, x); n       jump(x + 1, (x / block + (x % block == 0 ? 0 : 1)) * block); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::cerr; n using std::cin; n using std::cout; n using std::deque; n using std::endl; n using std::fixed; n using std::ios_base; n using std::list; n using std::make_pair; n using std::make_tuple; n using std::map; n using std::nth_element; n using std::pair; n using std::queue; n using std::reverse; n using std::set; n using std::sort; n using std::stack; n using std::string; n using std::tuple; n using std::unordered_map; n using std::unordered_set; n using std::vector; n const int MAXN = 100000; n const int INF = 1e9; n const int MOD = 1e9 + 7; n const int64_t L_INF = 4e18; n int n; n vector<int64_t> numbers[64]; n list<int64_t> ans; n int get_top(int64_t num) { n   for (int i = 62; i >= 0; i--) { n     if (num & (1ll << i)) { n       return i; n     } n   } n   return -1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.precision(10); n   cout << fixed; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int64_t b; n     cin >> b; n     numbers[get_top(b)].push_back(b); n   } n   for (int i = 62; i >= 0; i--) { n     if (numbers[i].empty()) { n       continue; n     } n     if (numbers[i].size() > ans.size() + 1) { n       cout <<  No n ; n       exit(0); n     } n     auto iter = ans.begin(); n     iter = ans.insert(iter, numbers[i][0]); n     iter++; n     int j = 1; n     int64_t sum = numbers[i][0]; n     while (j < (int)numbers[i].size() && iter != ans.end()) { n       sum ^= *iter; n       iter++; n       if ((sum ^ numbers[i][j]) > sum) { n         iter = ans.insert(iter, numbers[i][j]); n         sum ^= *iter; n         iter++; n         j++; n       } n     } n     if (j != (int)numbers[i].size()) { n       cout <<  No n ; n       exit(0); n     } n   } n   cout <<  Yes n ; n   for (int64_t b : ans) { n     cout << b <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[101][101]; n long long b[101]; n int main() { n   int m, n; n   cin >> m >> n; n   for (int i = 0; i < m; i++) n     for (int j = 0; j < n; j++) cin >> a[i][j]; n   for (int i = 0; i < m; i++) { n     long long minn = 100000000000000; n     for (int j = 0; j < n; j++) { n       if (a[i][j] < minn) minn = a[i][j]; n     } n     b[i] = minn; n   } n   long long maxx = 0; n   for (int i = 0; i < m; i++) { n     if (b[i] > maxx) maxx = b[i]; n   } n   cout << maxx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   scanf( %d , &(n)); n   scanf( %d , &(k)); n   int A[101]; n   for (int(i) = 0; (i) < (n); (i)++) { n     scanf( %d , &(A[i])); n   } n   int x, y, ans = 0; n   for (int(i) = 0; (i) < (k); (i)++) { n     x = 0; n     y = 0; n     for (int(j) = 0; (j) < (n / k); (j)++) { n       if (A[j * k + i] == 2) n         y++; n       else n         x++; n     } n     ans += min(x, y); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_VAL = 1000000; n struct AInt { n   int sum; n   int minSum; n }; n AInt aInt[1 << 21]; n void update(int index, int left, int right, int addIndex, int addValue) { n   if (left == right) { n     aInt[index].sum += addValue; n     aInt[index].minSum += addValue; n   } else { n     int avg = (left + right) / 2; n     if (addIndex <= avg) { n       update(2 * index + 0, left, avg, addIndex, addValue); n     } else { n       update(2 * index + 1, avg + 1, right, addIndex, addValue); n     } n     aInt[index].sum = aInt[2 * index].sum + aInt[2 * index + 1].sum; n     aInt[index].minSum = n         std::min(aInt[2 * index].minSum + aInt[2 * index + 1].sum, n                  aInt[2 * index + 1].minSum); n   } n } n int query(int index, int suffSum, int left, int right) { n   if (aInt[index].minSum + suffSum >= 0) { n     return -1; n   } else if (left == right) { n     return left; n   } else { n     int avg = (left + right) / 2; n     int q2 = query(2 * index + 1, suffSum, avg + 1, right); n     if (q2 == -1) { n       int q1 = n           query(2 * index + 0, aInt[2 * index + 1].sum + suffSum, left, avg); n       return q1; n     } else { n       return q2; n     } n   } n } n void update(int value, int sign) { update(1, 1, MAX_VAL, value, sign); } n int query() { return query(1, 0, 1, MAX_VAL); } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int a[n]; n   int b[m]; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     update(a[i], -1); n   } n   for (int i = 0; i < m; i++) { n     scanf( %d , &b[i]); n     update(b[i], +1); n   } n   int q; n   scanf( %d , &q); n   for (int z = 0; z < q; z++) { n     int t, i, x; n     scanf( %d%d%d , &t, &i, &x); n     i--; n     if (t == 1) { n       update(a[i], +1); n       a[i] = x; n       update(a[i], -1); n     } else { n       update(b[i], -1); n       b[i] = x; n       update(b[i], +1); n     } n     printf( %d n , query()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long findGCD(long long a, long long b) { n   return ((b == 0) ? a : findGCD(b, a % b)); n } n map<long long, long long> width; n long long wit = 0; n vector<pair<long long, long long> > rect[200005]; n int main() { n   long long n; n   scanf( %lld , &n); n   for (long long i = (1); i <= (n); i += (1)) { n     long long w, h, f; n     scanf( %lld %lld %lld , &h, &w, &f); n     if (width.find(w) == width.end()) { n       width[w] = ++wit; n     } n     rect[width[w]].push_back({h, f}); n   } n   sort(rect[1].begin(), rect[1].end()); n   for (long long i = (2); i <= (wit); i += (1)) { n     if (rect[i - 1].size() != rect[i].size()) { n       printf( 0 n ); n       return 0; n     } n     sort(rect[i].begin(), rect[i].end()); n     for (long long j = (0); j <= ((long long)rect[i].size() - 1); j += (1)) { n       if (rect[i - 1][j].first != rect[i][j].first) { n         printf( 0 n ); n         return 0; n       } n     } n     long long gcd = findGCD(rect[i - 1][0].second, rect[i][0].second); n     long long n = rect[i - 1][0].second / gcd, dn = rect[i][0].second / gcd; n     for (long long j = (1); j <= ((long long)rect[i].size() - 1); j += (1)) { n       gcd = findGCD(rect[i - 1][j].second, rect[i][j].second); n       if (rect[i - 1][j].second / gcd != n || rect[i][j].second / dn != gcd) { n         printf( 0 n ); n         return 0; n       } n     } n   } n   long long tgcd = -1; n   for (long long j = (0); j <= ((long long)rect[1].size() - 1); j += (1)) { n     long long gcd = rect[1][j].second; n     for (long long i = (2); i <= (wit); i += (1)) { n       gcd = findGCD(gcd, rect[i][j].second); n     } n     if (tgcd == -1) n       tgcd = gcd; n     else n       tgcd = findGCD(tgcd, gcd); n   } n   long long ans = 0; n   for (long long i = (1); i <= (sqrt(tgcd)); i += (1)) { n     if (tgcd % i == 0) { n       if (tgcd == i * i) n         ans++; n       else n         ans += 2; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e5 + 11; n const int MAXN = 5e7 + 1; n const int BITMAX = 18; n const int INF = 2e9 + 88; n const long long LLINF = 1e17 + 3; n const int MOD = 1e9 + 7; n const long double Pi = acos(-1); n int a[MAX]; n int main() { n   int n, m; n   scanf( %d , &n); n   scanf( %d , &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   if (n == 1) return puts( 0 ), 0; n   sort(a + 1, a + n + 1); n   long long res = 0; n   int mx = 0; n   for (int i = 1; i < n; ++i) { n     res += a[i] - 1; n     if (a[i] > mx) mx++; n   } n   if (a[n] > mx) n     res += mx; n   else n     res += a[n] - 1; n   printf( %lld n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void init() { n   cin.tie(0); n   cin.sync_with_stdio(0); n } n int main() { n   init(); n   int n, z; n   cin >> n >> z; n   for (int i = 0; i < z; i++) { n     (n % 10 == 0) ? n /= 10 : n -= 1; n   } n   cout << n << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n const int mod = 998244353; n char str[N]; n char s[2][N]; n int nxt[2][N]; n int extend[2][N]; n void get_nxt(char *s, int *nxt) { n   int n = strlen(s), r = 0, pos = 1; n   nxt[0] = n; n   while (r + 1 < n && s[r] == s[r + 1]) ++r; n   nxt[1] = r; n   for (int i = 2; i < n; ++i) { n     nxt[i] = max(0, min(nxt[i - pos], r - i + 1)); n     while (i + nxt[i] < n && s[i + nxt[i]] == s[nxt[i]]) ++nxt[i]; n     if (i + nxt[i] - 1 > r) { n       r = i + nxt[i] - 1; n       pos = i; n     } n   } n } n void get_extend(char *s, char *t, int *nxt, int *extend) { n   int n = strlen(s), m = strlen(t), pos = 0, r; n   while (s[extend[0]] == t[extend[0]]) ++extend[0]; n   r = extend[0] - 1; n   for (int i = 1; i < n; ++i) { n     extend[i] = max(0, min(nxt[i - pos], r - i + 1)); n     while (i + extend[i] < n && extend[i] < m && n            s[i + extend[i]] == t[extend[i]]) n       ++extend[i]; n     if (i + extend[i] - 1 > r) { n       r = i + extend[i] - 1; n       pos = i; n     } n   } n } n int a[N << 2]; n int tag[N << 2]; n void pushdown(int x) { n   a[(x << 1)] = (a[(x << 1)] + tag[x]) % mod; n   tag[(x << 1)] = (tag[(x << 1)] + tag[x]) % mod; n   a[(x << 1 | 1)] = (a[(x << 1 | 1)] + tag[x]) % mod; n   tag[(x << 1 | 1)] = (tag[(x << 1 | 1)] + tag[x]) % mod; n   tag[x] = 0; n } n void add(int x, int l, int r, int ll, int rr, int p) { n   if (ll > rr) return; n   if (l >= ll && r <= rr) { n     a[x] = (a[x] + p) % mod; n     tag[x] = (tag[x] + p) % mod; n   } else { n     if (tag[x]) pushdown(x); n     if (((l + r) >> 1) >= ll) add((x << 1), l, ((l + r) >> 1), ll, rr, p); n     if (((l + r) >> 1) < rr) n       add((x << 1 | 1), ((l + r) >> 1) + 1, r, ll, rr, p); n   } n } n int query(int x, int l, int r, int pos) { n   if (pos == -1) return 1; n   if (l == r) n     return a[x]; n   else { n     if (tag[x]) pushdown(x); n     if (pos <= ((l + r) >> 1)) n       return query((x << 1), l, ((l + r) >> 1), pos); n     else n       return query((x << 1 | 1), ((l + r) >> 1) + 1, r, pos); n   } n } n int sum[N]; n int now; n int main() { n   scanf( %s %s %s , str, s[0], s[1]); n   int len = strlen(str); n   int lenl = strlen(s[0]); n   int lenr = strlen(s[1]); n   int f = (lenl == 1 && s[0][0] ==  0 ); n   get_nxt(s[0], nxt[0]); n   get_nxt(s[1], nxt[1]); n   get_extend(str, s[0], nxt[0], extend[0]); n   get_extend(str, s[1], nxt[1], extend[1]); n   int now = 1; n   sum[0] = mod - 1; n   for (int i = 0; i < len; ++i) { n     int l, r; n     if (str[i] ==  0 ) { n       if (f) n         l = r = i; n       else { n         now = (now + sum[i]) % mod; n         continue; n       } n     } else { n       l = i + lenl - 1; n       if (extend[0][i] != lenl && s[0][extend[0][i]] > str[i + extend[0][i]]) n         ++l; n       r = i + lenr - 1; n       if (extend[1][i] != lenr && (s[1][extend[1][i]] < str[i + extend[1][i]])) n         --r; n     } n     sum[l] = (sum[l] + now) % mod; n     sum[r + 1] = (sum[r + 1] - now + mod) % mod; n     now = (now + sum[i]) % mod; n   } n   printf( %d n , now); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, t; n std::vector<pair<long long, long long> > v; n long long dp[(1 << 15) + 5][226][4]; n long long solve(long long x, long long y, long long z) { n   if (x == 0) return 1; n   if (x < 0) return 0; n   if (dp[y][x][z] != -1) return dp[y][x][z]; n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     if (v[i].second != z and (y & (1 << i))) { n       ans = (ans + n              (solve(x - v[i].first, y - (1 << i), v[i].second)) % 1000000007) % n             1000000007; n     } n   } n   dp[y][x][z] = ans; n   return dp[y][x][z] % 1000000007; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> t; n   long long t1, t2; n   for (long long i = 0; i < (1 << 15) + 5; i++) n     for (long long j = 0; j < 226; j++) n       for (long long k = 0; k < 4; k++) dp[i][j][k] = -1; n   for (long long i = 0; i < n; i++) { n     cin >> t1 >> t2; n     v.push_back(make_pair(t1, t2)); n   } n   cout << solve(t, (1 << n) - 1, 0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<int, int>, pair<int, int> > p; n int res[100 + 10][100 + 10]; n int main() { n   int n, m, q, k, d, t, tem1, tem2, tem3, tem4, y = 1, sum = 0, ans = 0; n   string s, c; n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       p[{i, j}] = {i, j}; n     } n   } n   for (int i = 0; i < q; i++) { n     scanf( %d%d , &tem1, &tem2); n     tem2--; n     if (tem1 != 3) { n       if (tem1 == 1) { n         pair<int, int> here = p[{tem2, 0}]; n         for (int j = 0; j < m - 1; j++) { n           p[{tem2, j}] = p[{tem2, j + 1}]; n         } n         p[{tem2, m - 1}] = here; n       } else { n         pair<int, int> here = p[{0, tem2}]; n         for (int j = 0; j < n - 1; j++) { n           p[{j, tem2}] = p[{j + 1, tem2}]; n         } n         p[{n - 1, tem2}] = here; n       } n     } else { n       scanf( %d%d , &tem3, &tem4); n       tem3--; n       pair<int, int> here = p[{tem2, tem3}]; n       res[here.first][here.second] = tem4; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       printf( %d  , res[i][j]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct square { n   int r1, c1, r2, c2; n   square(int R1, int C1, int R2, int C2) { n     r1 = R1; n     c1 = C1; n     r2 = R2; n     c2 = C2; n   } n   bool same(int R1, int C1, int R2, int C2) { n     if (R1 != r1) return false; n     if (C1 != c1) return false; n     if (R2 != r2) return false; n     if (C2 != c2) return false; n     return true; n   } n   bool in(int x, int y) { n     if (r1 <= x && x <= r2 && c1 <= y && y <= c2) return true; n     return false; n   } n }; n vector<square *> S; n int main(void) { n   int n, m, q; n   scanf( %d %d %d , &n, &m, &q); n   while (q--) { n     int op; n     scanf( %d , &op); n     int r1, c1, r2, c2; n     scanf( %d %d %d %d , &r1, &c1, &r2, &c2); n     if (op == 1) { n       square *s = new square(r1, c1, r2, c2); n       S.push_back(s); n     } else if (op == 2) { n       int size = S.size(); n       for (int i = 0; i < size; i++) { n         square *s = S[i]; n         if (s->same(r1, c1, r2, c2)) { n           S.erase(S.begin() + i); n           break; n         } n       } n     } else if (op == 3) { n       bool find = false; n       for (square *s : S) n         if (s->in(r1, c1) != s->in(r2, c2)) { n           printf( No n ); n           find = true; n           break; n         } n       if (!find) printf( Yes n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 333333; n int ans[maxn]; n int fa[maxn]; n int nx[maxn]; n int visit[maxn]; n int n, m; n inline int query(int a) { return a == fa[a] ? a : fa[a] = query(fa[a]); } n inline void conbine(int a, int b) { n   a = query(a), b = query(b); n   if (a != b) fa[a] = b; n } n inline void paint(int l, int r, int x) { n   int i = l; n   while (i <= r) { n     int a = query(i); n     int j = nx[a]; n     if (j > r) return; n     if (ans[j] == 0) ans[j] = x; n     int b = query(j + 1); n     int _nx = nx[b]; n     conbine(a, b); n     nx[query(a)] = _nx; n     i = _nx; n   } n } n int main() { n   int n, m; n   while (scanf( %d%d , &n, &m) != EOF) { n     for (int i = 0; i <= n + 1; ++i) fa[i] = nx[i] = i, ans[i] = 0; n     for (int i = 0; i < m; ++i) { n       int l, r, x; n       scanf( %d%d%d , &l, &r, &x); n       paint(l, x - 1, x); n       paint(x + 1, r, x); n     } n     for (int i = 1; i <= n; ++i) { n       int tmp = ans[i]; n       printf( %d , tmp); n       if (i == n) n         printf(  n ); n       else n         printf(   ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1000000007; n const int MM = 998244353; n const long double PI = acos(-1); n const long long INF = 2e18; n template <typename T, typename T1> n void amax(T &a, T1 b) { n   if (b > a) a = b; n } n template <typename T, typename T1> n void amin(T &a, T1 b) { n   if (b < a) a = b; n } n long long power(long long b, long long e) { n   if (e == 0) return 1; n   if (e & 1) return b * power(b * b, e / 2); n   return power(b * b, e / 2); n } n long long power(long long b, long long e, long long m) { n   if (e == 0) return 1; n   if (e & 1) return b * power(b * b % m, e / 2, m) % m; n   return power(b * b % m, e / 2, m); n } n long long modinv(long long a, long long m) { return power(a, m - 2, m); } n int TLE_TERROR() { n   long long n, ans = 0; n   cin >> n; n   long long a[n], c[n + 1]; n   memset(c, 0, sizeof(c)); n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     ans ^= a[i]; n   } n   for (long long i = 2; i <= n; i++) { n     long long z = n / i; n     c[i - 1] += z; n     z *= i; n     long long zz = n - z; n     c[zz]++; n   } n   for (long long i = n - 1; i >= 0; i--) c[i] += c[i + 1]; n   for (long long i = 1; i <= n; i++) { n     if (c[i] % 2 != 0) ans ^= i; n   } n   cout << ans; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int TESTS = 1; n   while (TESTS--) TLE_TERROR(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n int s, p, i, j, k, z; n string s1, s2; n int const md = 1000000; n stack<char> st; n int a[5]; n int main() { n   int k1 = 0, k2 = 0, k3 = 0; n   cin >> k1 >> k2; n   for (i = 1; i <= k1; i++) { n     cin >> k3; n     n = n * k2 + k3; n   } n   cin >> k1 >> k2; n   for (i = 1; i <= k1; i++) { n     cin >> k3; n     m = m * k2 + k3; n   } n   if (n > m) n     cout <<  > ; n   else if (n < m) n     cout <<  < ; n   else n     cout <<  = ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n inline long long read() { n   long long k = 0, 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     k = k * 10 + ch -  0 ; n     ch = getchar(); n   } n   return k * f; n } n long long n, h, w, minx = 0, maxx = 0, miny = 0, maxy = 0, ans; n long long a[500010], b[500010]; n char s[500010]; n inline void shuchu() { n   printf( %lld , ans); n   exit(0); n } n signed main() { n   n = read(); n   h = read(); n   w = read(); n   scanf( %s , s + 1); n   long long cnt = 0, x = 0, y = 0, cc = 0; n   for (long long i = 1; i <= n; i++) { n     cnt++; n     if (s[i] ==  U ) x--; n     if (s[i] ==  D ) x++; n     if (s[i] ==  L ) y--; n     if (s[i] ==  R ) y++; n     if (x < minx) minx = x, ans = (ans + cnt * w) % MOD, h--; n     if (x > maxx) maxx = x, ans = (ans + cnt * w) % MOD, h--; n     if (y < miny) miny = y, ans = (ans + cnt * h) % MOD, w--; n     if (y > maxy) maxy = y, ans = (ans + cnt * h) % MOD, w--; n     if (h == 0 || w == 0) shuchu(); n   } n   if (x == 0 && y == 0) return puts( -1 ) & 0; n   for (long long i = 1; i <= n; i++) { n     cnt++; n     if (s[i] ==  U ) x--; n     if (s[i] ==  D ) x++; n     if (s[i] ==  L ) y--; n     if (s[i] ==  R ) y++; n     if (x < minx) n       minx = x, ans = (ans + cnt * w) % MOD, h--, a[++cc] = 1, b[cc] = cnt % n; n     if (x > maxx) n       maxx = x, ans = (ans + cnt * w) % MOD, h--, a[++cc] = 2, b[cc] = cnt % n; n     if (y < miny) n       miny = y, ans = (ans + cnt * h) % MOD, w--, a[++cc] = 3, b[cc] = cnt % n; n     if (y > maxy) n       maxy = y, ans = (ans + cnt * h) % MOD, w--, a[++cc] = 4, b[cc] = cnt % n; n     if (h == 0 || w == 0) shuchu(); n     if (cc && b[cc] == 0) b[cc] = n; n   } n   long long p = 2, i = 1; n   while (h != 0 && w != 0) { n     if (a[i] == 1 || a[i] == 2) n       ans = (ans + (p * n % MOD + b[i]) * w) % MOD, h--; n     if (a[i] == 3 || a[i] == 4) n       ans = (ans + (p * n % MOD + b[i]) * h) % MOD, w--; n     if (i == cc) n       i = 1, p++; n     else n       i++; n   } n   shuchu(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MN = 1e4 + 20; n vector<int> adj[MN], topo; n vector<pair<int, int>> edge; n int scc, st, s[MN], h[MN], t[MN]; n bool os[MN]; n stack<int> ms; n int n, m; n void add(int u, int v) { n   adj[u + m].push_back(v); n   adj[v + m].push_back(u); n   adj[u].push_back(v + m); n   adj[v].push_back(u + m); n } n void dfs(int v) { n   os[v] = 1; n   s[v] = h[v] = ++st; n   ms.push(v); n   for (int i : adj[v]) { n     if (!s[i]) dfs(i); n     if (os[i]) h[v] = min(h[v], h[i]); n   } n   if (h[v] == s[v]) { n     for (int i = ms.top();; i = ms.top()) { n       ms.pop(); n       os[i] = 0; n       h[i] = h[v]; n       t[i] = topo.size(); n       if (i == v) break; n     } n     scc++; n     topo.push_back(h[v]); n   } n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     if (v > u) swap(u, v); n     for (int j = 0; j < i; j++) { n       if (u == edge[j].first || u == edge[j].second || v == edge[j].first || n           v == edge[j].second) n         continue; n       if ((u < edge[j].first && u > edge[j].second) ^ n           (v < edge[j].first && v > edge[j].second)) n         add(i, j); n     } n     edge.push_back({u, v}); n   } n   for (int i = 0; i < 2 * m; i++) n     if (!s[i]) dfs(i); n   reverse(topo.begin(), topo.end()); n   for (int i = 0; i < m; i++) { n     if (h[i] == h[i + m]) return cout <<  Impossible , 0; n   } n   for (int i = 0; i < m; i++) { n     t[i] < t[i + m] ? cout <<  i  : cout <<  o ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Edge { n   int u, v, cap, cost, next; n } edge[555 * 1111]; n int head[555]; n int NV, NE, vs, vt; n void addEdge(int u, int v, int cap, int cost) { n   edge[NE].u = u; n   edge[NE].v = v; n   edge[NE].cap = cap; n   edge[NE].cost = cost; n   edge[NE].next = head[u]; n   head[u] = NE++; n   edge[NE].u = v; n   edge[NE].v = u; n   edge[NE].cap = 0; n   edge[NE].cost = -cost; n   edge[NE].next = head[v]; n   head[v] = NE++; n } n bool vis[555]; n int d[555], pre[555]; n bool SPFA() { n   for (int i = 0; i < NV; ++i) { n     vis[i] = 0; n     d[i] = (1 << 30); n   } n   vis[vs] = 1; n   d[vs] = 0; n   queue<int> que; n   que.push(vs); n   while (!que.empty()) { n     int u = que.front(); n     que.pop(); n     for (int i = head[u]; i != -1; i = edge[i].next) { n       int v = edge[i].v; n       if (edge[i].cap && d[v] > d[u] + edge[i].cost) { n         d[v] = d[u] + edge[i].cost; n         pre[v] = i; n         if (!vis[v]) { n           vis[v] = 1; n           que.push(v); n         } n       } n     } n     vis[u] = 0; n   } n   return d[vt] != (1 << 30); n } n int MCMF() { n   int res = 0; n   while (SPFA()) { n     int flow = (1 << 30), cost = 0; n     for (int u = vt; u != vs; u = edge[pre[u]].u) { n       flow = min(flow, edge[pre[u]].cap); n     } n     for (int u = vt; u != vs; u = edge[pre[u]].u) { n       edge[pre[u]].cap -= flow; n       edge[pre[u] ^ 1].cap += flow; n       cost += flow * edge[pre[u]].cost; n     } n     res += cost; n   } n   return res; n } n int tn, ch[55500][26], fail[55500]; n vector<int> vec[55500]; n void insert(char *s, int k) { n   int x = 0; n   for (int i = 0; s[i]; ++i) { n     int y = s[i] -  a ; n     if (ch[x][y] == 0) ch[x][y] = ++tn; n     x = ch[x][y]; n   } n   vec[x].push_back(k); n } n void getfail() { n   queue<int> que; n   for (int i = 0; i < 26; ++i) { n     if (ch[0][i]) que.push(ch[0][i]); n   } n   while (!que.empty()) { n     int x = que.front(); n     que.pop(); n     for (int i = 0; i < 26; ++i) { n       if (ch[x][i]) { n         fail[ch[x][i]] = ch[fail[x]][i]; n         que.push(ch[x][i]); n       } else n         ch[x][i] = ch[fail[x]][i]; n     } n   } n } n int val[111], len[111]; n void ac(char *s) { n   int x = 0; n   for (int i = 0; s[i]; ++i) { n     int y = s[i] -  a ; n     x = ch[x][y]; n     for (int tmp = x; tmp; tmp = fail[tmp]) { n       for (int j = 0; j < vec[tmp].size(); ++j) { n         int k = vec[tmp][j]; n         addEdge(i - len[k] + 1, i + 1, 1, -val[k]); n       } n     } n   } n } n char S[555], T[555]; n int main() { n   int n, m, x; n   scanf( %d%s%d , &n, S, &m); n   for (int i = 1; i <= m; ++i) { n     scanf( %s%d , T, val + i); n     len[i] = strlen(T); n     insert(T, i); n   } n   scanf( %d , &x); n   vs = n + 1; n   vt = vs + 1; n   NV = vt + 1; n   NE = 0; n   memset(head, -1, sizeof(head)); n   addEdge(vs, 0, x, 0); n   addEdge(n, vt, x, 0); n   for (int i = 1; i <= n; ++i) { n     addEdge(i - 1, i, (1 << 30), 0); n   } n   getfail(); n   ac(S); n   printf( %d , -MCMF()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x; n int f(int a, int b) { return (a * b + 1) / 2; } n bool ok(int n) { n   if (x == 3 && n == 3) return false; n   if (n % 2 == 0 && x % 4) return false; n   if (n % 2 == 0) { n     if (x / 4 <= f(n / 2 - 1, n / 2 - 1)) return true; n     return false; n   } n   int z = f(n, n); n   if (x > z) return false; n   return true; n } n int main() { n   cin >> x; n   for (int i = (int)(1), _n = (int)(100000); i < _n; i++) n     if (ok(i)) { n       cout << i << endl; n       break; n     } n   { n     int _; n     cin >> _; n   } 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   ; n   long long cdiff, d, diff, rem, c, n, m, i, k = 0, j, flag = 0, x, n                                              minstep = 10000000000; n   cin >> n; n   long long b[n]; n   for (i = 0; i < n; i++) cin >> b[i]; n   if (n < 3) n     cout <<  0 ; n   else { n     cdiff = b[0] - b[n - 1]; n     diff = abs(b[0] - b[n - 1]); n     rem = diff % (n - 1); n     d = cdiff / (n - 1); n     if (rem > 2 && rem < n - 3) n       cout << -1 << endl; n     else { n       if (rem == 2 || rem == 0 || rem == 1) { n         c = 0; n         flag = 0; n         for (i = 0; i < n; i++) { n           if (b[i] - (b[0] - (i * d)) > 1 || b[i] - (b[0] - (i * d)) < -1) { n             flag = 1; n             break; n           } else if (b[i] - (b[0] - (i * d)) != 0) { n             c++; n           } n         } n         if (flag == 0) minstep = min(c, minstep); n       } n       if (rem == 2 || rem == 0 || rem == 1) { n         c = 0; n         flag = 0; n         for (i = 0; i < n; i++) { n           if (b[i] - (b[0] + 1 - (i * d)) > 1 || n               b[i] - (b[0] + 1 - (i * d)) < -1) { n             flag = 1; n             break; n           } else if (b[i] - (b[0] + 1 - (i * d)) != 0) { n             c++; n           } n         } n         if (flag == 0) minstep = min(c, minstep); n       } n       if (rem == 2 || rem == 0 || rem == 1) { n         c = 0; n         flag = 0; n         for (i = 0; i < n; i++) { n           if (b[i] - (b[0] - 1 - (i * d)) > 1 || n               b[i] - (b[0] - 1 - (i * d)) < -1) { n             flag = 1; n             break; n           } else if (b[i] - (b[0] - 1 - (i * d)) != 0) { n             c++; n           } n         } n         if (flag == 0) minstep = min(c, minstep); n       } n       if (cdiff > 0) n         x = 1; n       else if (cdiff < 0) n         x = -1; n       else n         x = 0; n       d = (cdiff / (n - 1)) + x; n       if (rem == n - 2 || rem == n - 3) { n         c = 0; n         flag = 0; n         for (i = 0; i < n; i++) { n           if (b[i] - (b[0] - (i * d)) > 1 || b[i] - (b[0] - (i * d)) < -1) { n             flag = 1; n             break; n           } else if (b[i] - (b[0] - (i * d)) != 0) { n             c++; n           } n         } n         if (flag == 0) minstep = min(c, minstep); n       } n       if (rem == n - 3 || rem == n - 2) { n         c = 0; n         flag = 0; n         for (i = 0; i < n; i++) { n           if (b[i] - (b[0] + 1 - (i * d)) > 1 || n               b[i] - (b[0] + 1 - (i * d)) < -1) { n             flag = 1; n             break; n           } else if (b[i] - (b[0] + 1 - (i * d)) != 0) { n             c++; n           } n         } n         if (flag == 0) minstep = min(c, minstep); n       } n       if (rem == n - 3 || rem == n - 2) { n         c = 0; n         flag = 0; n         for (i = 0; i < n; i++) { n           if (b[i] - (b[0] - 1 - (i * d)) > 1 || n               b[i] - (b[0] - 1 - (i * d)) < -1) { n             flag = 1; n             break; n           } else if (b[i] - (b[0] - 1 - (i * d)) != 0) { n             c++; n           } n         } n         if (flag == 0) minstep = min(c, minstep); n       } n       if (minstep == 10000000000) n         cout << -1 << endl; n       else n         cout << minstep << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n inline int get_power(int a, int n) { n   int res = 1; n   while (n > 0) { n     res = n & 1 ? 1ll * res * a % mod : res; n     a = 1ll * a * a % mod; n     n >>= 1; n   } n   return res; n } n inline int get_inv(int x) { return get_power(x, mod - 2); } n inline int C2(int x) { return (x * (x - 1ll) >> 1) % mod; } n const int max_n = 2e3 + 5; n int power_p[max_n], power_q[max_n]; n int f[max_n], g[max_n], h[max_n][max_n]; n int main() { n   int n, a, b; n   scanf( %d%d%d , &n, &a, &b); n   int p = 1ll * a * get_inv(b) % mod; n   power_p[0] = power_q[0] = 1; n   for (int i = 1; i <= n; ++i) { n     power_p[i] = 1ll * power_p[i - 1] * p % mod; n     power_q[i] = power_q[i - 1] * (mod + 1ll - p) % mod; n   } n   h[1][0] = h[1][1] = 1; n   for (int i = 2; i <= n; ++i) n     for (int j = 0; j <= i; ++j) n       h[i][j] = (1ll * h[i - 1][j] * power_p[j] + n                  (j > 0 ? 1ll * h[i - 1][j - 1] * power_q[i - j] : 0)) % n                 mod; n   for (int i = 1; i <= n; ++i) { n     g[i] = 1; n     for (int j = 1; j <= i - 1; ++j) { n       g[i] -= 1ll * g[j] * h[i][j] % mod; n       g[i] += g[i] < 0 ? mod : 0; n     } n   } n   for (int i = 1; i <= n; ++i) { n     f[i] = 1ll * g[i] * h[i][i] % mod * C2(i) % mod; n     for (int j = 1; j <= i - 1; ++j) n       f[i] = (f[i] + 1ll * g[j] * h[i][j] % mod * n                          (1ll * f[j] + f[i - j] + C2(i) - C2(i - j) + mod)) % n              mod; n     f[i] = 1ll * f[i] * get_inv(mod + 1 - 1ll * g[i] * h[i][i] % mod) % mod; n   } n   printf( %d n , f[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<vector<char> > table(n + 1, vector<char>(m + 1)); n   int row = 0, col = 0, count = 0; n   for (int i = 1; i <= n; i++) { n     string tmp; n     cin >> tmp; n     for (int j = 0; j < tmp.length(); j++) { n       table[i][j + 1] = tmp[j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (table[i][j] ==  B ) { n         count++; n         row += i; n         col += j; n       } n     } n   } n   row /= count; n   col /= count; n   cout << row <<     << col << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T gcd(T a, T b) { n   if (a < b) { n     swap(a, b); n   } n   T t; n   while (b > 0) { n     t = a % b; n     a = b; n     b = t; n   } n   return a; n } n template <class T> n T gcdL(vector<T>& v) { n   int l = v.size(); n   if (l == 1) return v[0]; n   T g = gcd(v[0], v[1]); n   for (int i = 2; i < l; i++) { n     g = gcd(g, v[i]); n   } n   return g; n } n long long foo(long long x) { n   while (x % 2 == 0) x /= 2; n   while (x % 3 == 0) x /= 3; n   return x; n } n bool ok(vector<long long>& v) { n   for (int i = 0; i < (int)v.size(); i++) { n     v[i] = foo(v[i]); n   } n   for (int i = 0; i < (int)v.size(); i++) { n     if (v[i] == 1) n       continue; n     else n       return 0; n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout << setprecision(10); n   long long n, x; n   vector<long long> v; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     v.push_back(x); n   } n   long long g = gcdL(v); n   for (int i = 0; i < n; i++) { n     v[i] /= g; n   } n   if (ok(v)) n     cout <<  Yes ; n   else n     cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 0, input = 0, temp = 0, sum = 0, c = 0; n   cin >> n; n   for (int i = 0; i < 2 * n; i++) { n     cin >> temp; n   } n   if (sum % 2 == 0) { n     cout <<  Karen ; n   } else n     cout <<  Koyomi ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int K; n   vector<int> a(5, 0); n   for (int i = 0; i < 5; i++) cin >> a[i]; n   cin >> K; n   vector<int> b(K); n   for (int i = 0; i < K; i++) { n     string temp; n     cin >> temp; n     if (temp ==  XXL ) n       b[i] = 4; n     else if (temp ==  XL ) n       b[i] = 3; n     else if (temp ==  L ) n       b[i] = 2; n     else if (temp ==  M ) n       b[i] = 1; n     else n       b[i] = 0; n   } n   for (int i = 0; i < K; i++) { n     if (a[b[i]] > 0) { n       a[b[i]]--; n     } else { n       if (b[i] + 1 < 5 && a[b[i] + 1] > 0) { n         b[i]++; n         a[b[i]] -= 1; n       } else if (b[i] - 1 >= 0 && a[b[i] - 1] > 0) { n         b[i]--; n         a[b[i]] -= 1; n       } else if (b[i] + 2 < 5 && a[b[i] + 2] > 0) { n         b[i] += 2; n         a[b[i]] -= 1; n       } else if (b[i] - 2 >= 0 && a[b[i] - 2] > 0) { n         b[i] -= 2; n         a[b[i]] -= 1; n       } else if (b[i] + 3 < 5 && a[b[i] + 3] > 0) { n         b[i] += 3; n         a[b[i]] -= 1; n       } else if (b[i] - 3 >= 0 && a[b[i] - 3] > 0) { n         b[i] -= 3; n         a[b[i]] -= 1; n       } else if (b[i] + 4 < 5 && a[b[i] + 4] > 0) { n         b[i] += 4; n         a[b[i]] -= 1; n       } else if (b[i] - 4 >= 0 && a[b[i] - 4] > 0) { n         b[i] -= 4; n         a[b[i]] -= 1; n       } n     } n   } n   for (int i = 0; i < K; i++) { n     if (b[i] == 4) n       cout <<  XXL  << endl; n     else if (b[i] == 3) n       cout <<  XL  << endl; n     else if (b[i] == 2) n       cout <<  L  << endl; n     else if (b[i]) n       cout <<  M  << endl; n     else n       cout <<  S  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int output(int n) { n   int sum = 0; n   while (n != 1) { n     int i; n     for (i = 2; i * i <= n; i++) n       if (n % i == 0) { n         sum += n; n         n /= i; n         break; n       } n     if (i * i > n) { n       sum += n; n       break; n     } n   } n   return ++sum; n } n int main() { n   int t; n   t = 1; n   while (t--) { n     int n; n     cin >> n; n     cout << output(n) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n long long a, b, c, s; n long long gao(long long a, long long b, long long xl, long long xr) { n   if (xl > xr) return 0; n   if (a * xl + b < 0 && a * xr + b < 0) return 0; n   double key = -b * 1.0 / a; n   long long keyx; n   if (a > 0) { n     keyx = (key - EPS); n     keyx++; n   } else { n     keyx = (key + EPS); n   } n   if (a * xl + b < 0) { n     xl = keyx; n   } n   if (a * xr + b < 0) { n     xr = keyx; n   } n   long long ans = b * (xr - xl + 1); n   long long tmp = (xr + xl) * (xr - xl + 1) / 2; n   ans += tmp * a; n   return ans; n } n long long first_old(long long a, long long b, long long c) { n   long long ans = 0; n   long long i1, i2; n   long long jl, jr; n   long long tmp, oldAns; n   for (long long x = 0; x <= s; x++) { n     tmp = 0; n     oldAns = ans; n     long long keyi = min(a + x - b, s - x); n     if (keyi < 0) continue; n     i1 = a + x + 1 - b - c; n     i2 = s - 2 * x - a + c; n     i1 = min(keyi, i1); n     i2 = min(keyi, i2); n     if (i1 < 0 && i2 < 0) { n       jl = 0; n       jr = keyi; n       ans += gao(-1, s - x + 1, jl, jr); n     } else if (i1 < 0) { n       jl = 0; n       jr = i2; n       ans += gao(0, a + x - c + 1, jl, jr); n       jl = i2 + 1; n       jr = keyi; n       ans += gao(-1, s - x + 1, jl, jr); n     } else if (i2 < 0) { n       jl = 0; n       jr = i1; n       ans += gao(0, s - 2 * x - a - 1 + b + c + 1, jl, jr); n       jl = i1 + 1; n       jr = keyi; n       ans += gao(-1, s - x + 1, jl, jr); n     } else { n       if (i1 == i2) { n         jl = 0; n         jr = i1; n         ans += gao(1, b - 1 + 1, jl, jr); n         jl = i1 + 1; n         jr = keyi; n         ans += gao(-1, s - x + 1, jl, jr); n       } else if (i1 < i2) { n         jl = 0; n         jr = i1; n         ans += gao(1, b - 1 + 1, jl, jr); n         jl = i1 + 1; n         jr = i2; n         ans += gao(0, a + x - c + 1, jl, jr); n         jl = i2 + 1; n         jr = keyi; n         ans += gao(-1, s - x + 1, jl, jr); n       } else { n         jl = 0; n         jr = i2; n         ans += gao(1, b - 1 + 1, jl, jr); n         jl = i2 + 1; n         jr = i1; n         ans += gao(0, s - 2 * x - a - 1 + b + c + 1, jl, jr); n         jl = i1 + 1; n         jr = keyi; n         ans += gao(-1, s - x + 1, jl, jr); n       } n     } n   } n   return ans; n } n long long first(long long a, long long b, long long c) { n   long long ans = 0; n   for (long long x = 0; x <= s; x++) { n     if (b > a + x || c > a + x) continue; n     long long tmp = (s - x + 2) * (s - x + 1) / 2; n     if (s - x - (a + x + 1 - b) >= 0) n       tmp -= (s - x - (a + x + 1 - b) + 2) * (s - x - (a + x + 1 - b) + 1) / 2; n     if (s - x - (a + x + 1 - c) >= 0) n       tmp -= (s - x - (a + x + 1 - c) + 2) * (s - x - (a + x + 1 - c) + 1) / 2; n     if (s - x - (a + x + 1 - b) - (a + x + 1 - c) >= 0) { n       tmp += (s - x - (a + x + 1 - b) - (a + x + 1 - c) + 2) * n              (s - x - (a + x + 1 - b) - (a + x + 1 - c) + 1) / 2; n     } n     long long sum = a + x - b - c; n     if (sum >= 0) { n       sum = min(sum, s - x); n       tmp -= (sum + 2) * (sum + 1) / 2; n     } n     ans += tmp; n   } n   return ans; n } n long long second(long long a, long long b, long long c) { n   long long ans = 0; n   for (long long i = max(a, b);; i++) { n     if (i < c) continue; n     long long t = i - a + i - b; n     t = s - t; n     if (t < 0) break; n     if (c + t > i) { n       ans += i - c + 1; n     } else { n       ans += t + 1; n     } n   } n   return ans; n } n long long third(long long a, long long b, long long c) { n   long long ans = 0; n   long long t = max(a, b); n   t = max(t, c); n   for (long long i = t;; i++) { n     long long used = 3 * i - a - b - c; n     if (used > s) break; n     ans++; n   } n   return ans; n } n void solve_old() { n   long long ans = 0; n   ans += first(a, b, c); n   ans += first(b, a, c); n   ans += first(c, a, b); n   ans -= second(a, b, c); n   ans -= second(b, c, a); n   ans -= second(a, c, b); n   ans += third(a, b, c); n   printf( %I64d n , ans); n } n long long new_first(long long a, long long b, long long c) { n   long long ans = 0; n   for (long long x = 0; x <= s; x++) { n     if (a + x - b - c < 0) continue; n     long long tmp = min(a + x - b - c, s - x); n     ans += (tmp + 2) * (tmp + 1) / 2; n   } n   return ans; n } n long long new_second(long long a, long long b, long long c) { n   long long ans = 0; n   for (long long x = max(a, b);; x++) { n     if (x - a + x - b > s) break; n     long long tmp = s - (x - a + x - b); n     if (2 * x - c > 0) tmp -= (2 * x - c); n     if (tmp >= 0) ans += tmp + 1; n   } n   return ans; n } n void solve() { n   long long ans = (s + 3) * (s + 2) * (s + 1) / 6; n   ans -= new_first(a, b, c); n   ans -= new_first(b, a, c); n   ans -= new_first(c, a, b); n   printf( %I64d n , ans); n } n int main() { n   while (scanf( %I64d%I64d%I64d%I64d , &a, &b, &c, &s) != EOF) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long l, r; n   int now; n   vector<pair<int, int> > v; n } st[250005 * 4]; n int pi, ri, n, N; n int p[250005], m[250005]; n long long r, sp[250005]; n pair<long long, int> d[250005]; n queue<int> q; n vector<long long> rr; n bool vis[250005]; n void init(int id, int l, int r) { n   if (l == r) { n     st[id].l = rr[l - 1] + 1; n     st[id].r = rr[l]; n     int L = lower_bound(d + 2, d + n + 2, make_pair(rr[l - 1] + 1, 0)) - d; n     int R = upper_bound(d + 2, d + n + 2, make_pair(rr[l], 1000000000)) - d; n     for (int i = L; i < R; i++) { n       st[id].v.push_back(make_pair(m[d[i].second], d[i].second)); n     } n     sort(st[id].v.begin(), st[id].v.end()); n     return; n   } n   int mid = l + r >> 1; n   init(id * 2, l, mid); n   init(id * 2 + 1, mid + 1, r); n   st[id].l = st[id * 2].l; n   st[id].r = st[id * 2 + 1].r; n   st[id].v.insert(st[id].v.begin(), st[id * 2].v.begin(), st[id * 2].v.end()); n   st[id].v.insert(st[id].v.end(), st[id * 2 + 1].v.begin(), n                   st[id * 2 + 1].v.end()); n   sort(st[id].v.begin(), st[id].v.end()); n } n void query(int id, int l, int r, long long L, long long R, int p) { n   if (R < st[id].l || st[id].r < L) return; n   if (L <= st[id].l && st[id].r <= R) { n     int len = st[id].v.size(); n     while (st[id].now < len && st[id].v[st[id].now].first <= p) { n       if (!vis[st[id].v[st[id].now].second]) n         q.push(st[id].v[st[id].now].second); n       vis[st[id].v[st[id].now].second] = 1; n       st[id].now++; n     } n     return; n   } n   int mid = l + r >> 1; n   query(id * 2, l, mid, L, R, p); n   query(id * 2 + 1, mid + 1, r, L, R, p); n } n int main() { n   long long x, y, xi, yi; n   scanf( %I64d%I64d%d%I64d%d , &xi, &yi, &p[1], &r, &n); n   r *= r; n   sp[1] = r; n   rr.push_back(r); n   for (int i = 2; i <= n + 1; i++) { n     scanf( %I64d%I64d%d%d%I64d , &x, &y, &m[i], &p[i], &r); n     x -= xi; n     y -= yi; n     d[i].first = x * x + y * y; n     d[i].second = i; n     r *= r; n     sp[i] = r; n     rr.push_back(r); n   } n   rr.push_back(0); n   sort(rr.begin(), rr.end()); n   rr.resize(unique(rr.begin(), rr.end()) - rr.begin()); n   N = rr.size() - 1; n   sort(d + 2, d + n + 2); n   init(1, 1, N); n   q.push(1); n   while (!q.empty()) { n     int now = q.front(); n     q.pop(); n     query(1, 1, N, 1, sp[now], p[now]); n   } n   int cnt = 0; n   for (int i = 2; i <= n + 1; i++) { n     if (vis[i]) { n       cnt++; n     } n   } n   printf( %d n , cnt); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string str; n   cin >> str; n   for (int i = 1; i < str.size() - 1; i++) { n     if (str[i + 1] !=  .  && str[i - 1] !=  .  && str[i] !=  . ) { n       if (str[i + 1] != str[i - 1] && str[i - 1] != str[i] && n           str[i + 1] != str[i]) { n         cout <<  Yes  << endl; n         return 0; n       } n     } n   } n   cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100; n int mem[MAXN + 10]; n int main() { n   int N; n   cin >> N; n   mem[0] = 0, mem[1] = 1, mem[2] = 2, mem[3] = 4; n   for (int i = 4; i <= N; ++i) { n     mem[i] = i + mem[i - 2]; n   } n   cout << mem[N] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long modexp(long long base, long long exp) { n   if (exp == 1) n     return base; n   else if (exp == 0) n     return 1; n   else { n     if (exp % 2 == 0) { n       long long base1 = pow(modexp(base, exp / 2), 2); n       if (base1 >= 1000000007) n         return base1 % 1000000007; n       else n         return base1; n     } else { n       long long ans = (base * pow(modexp(base, (exp - 1) / 2), 2)); n       if (ans >= 1000000007) n         return ans % 1000000007; n       else n         return ans; n     } n   } n } n long long gcd(long long a, long long b) { n   if (!a) return b; n   return gcd(b % a, a); n } n map<int, int> d; n set<int> s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int a[n]; n   for (long long i = 0; i < n; ++i) cin >> a[i]; n   for (long long i = 0; i < n; ++i) d[a[i]]++; n   long long ans = 0; n   for (long long i = 0; i < n; ++i) { n     d[a[i]]--; n     if (!d[a[i]]) { n       d.erase(a[i]); n     } n     if (s.find(a[i]) == s.end()) { n       ans += d.size(); n       s.insert(a[i]); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 10; n bool valid; n int n, p[maxn], a[maxn], head, tail; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; ++i) { n       scanf( %d , &p[i]); n       a[p[i]] = i; n     } n     head = a[1], tail = n; n     valid = true; n     for (int i = 1; i <= n; ++i) { n       if (a[i] != a[i - 1] + 1 && a[i] != head) { n         valid = false; n         break; n       } n       if (a[i] == tail) { n         tail = head - 1; n         head = a[i + 1]; n       } n     } n     if (valid) n       puts( Yes ); n     else n       puts( No ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N=2e5+10; n int a[N],tt; n int cnt[N]; n int pre[N]; n int main(){ n     int t; n     scanf( %d ,&t); n     while(t--){ n         int n; n         tt=0; n         scanf( %d ,&n); n         for(int i=1;i<=n;i++) scanf( %d ,&a[i]); n         sort(a+1,a+n+1); n         for(int i=1;i<=n;i++){ n             if(a[i]==a[i-1]) cnt[tt]++; n             else{ n                 tt++; n                 cnt[tt]++; n             } n         } n         priority_queue<int>s; n         for(int i=1;i<=tt;i++) { n             s.push(cnt[i]); n             cnt[i]=0; n         } n         int sh=0; n         int ans; n         while(1){ n             if(s.size()==1) { n                 ans = s.top(); n                 break; n             } n             if(s.empty()){ n                 ans=0; n                 break; n             } n             int a=s.top(); n             s.pop(); n             int b=s.top(); n             s.pop(); n             a--; n             b--; n             if(a!=0) n                 s.push(a); n             if(b!=0) n                 s.push(b); n  n         } n         printf( %d n ,ans); n     } n     return 0; n } n