#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const ll mod=1e9+7;
int p[maxn][150];//q记录互质的1-m之间个数gcd(x,y)=a;
vector<int>g[maxn]; ll dp[maxn];
int prime[maxn], k=0, u[maxn]; bool vis[maxn];
int cac(int x, int y){
    int ans=0;
    for(int i=0;i<g[x].size();i++){
        int v=g[x][i];
        ans+=u[v]*(y/v);
    }
    return ans;
}
void init(int n){
    vis[0]=vis[1]=1; u[0]=0; u[1]=1;
    for(int i=2;i<=n;i++){
        if(vis[i]==0) prime[++k]=i, u[i]=-1;
        for(int j=1;j<=k&&1LL*prime[j]*i<=n;j++){
            vis[prime[j]*i]=1;
            if(i%prime[j]==0){
                u[prime[j]*i]=0; break;
            }
            u[prime[j]*i]=-u[i];
        }
    }
    for(int i=2;i<=n;i++){
        int ub=(int)sqrt(i+0.5);
        for(int j=1;j<=ub;j++){
            if(i%j==0){
                g[i].push_back(j);
                if(j*j!=i) g[i].push_back(i/j);
            }
        }
        sort(g[i].begin(),g[i].end());
        for(int j=0;j<g[i].size();j++){
            int w=g[i][j];
            if(i==w) p[i][j]=n/i;
            else p[i][j]=cac(i/w,n/w); //printf("%d %d %d\n",i,w,p[i][j]);
        }
    }
}
ll qpow(ll a, ll b){
    ll ans=1;
    while(b){
        if(b&1) ans*=a, ans%=mod;
        b>>=1; a=a*a%mod;
    }
    return ans;
}
int main(){
    int n;
    scanf("%d",&n);  init(n);  dp[1]=1;
    for(int i=2;i<=n;i++){
        ll ans=n;
        for(int j=0;j<g[i].size()-1;j++){
            ans+=1LL*p[i][j]*dp[g[i][j]]; ans%=mod;
        }
        ans*=qpow(n-p[i][g[i].size()-1],mod-2);
        dp[i]=ans%mod;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[i]; ans%=mod;
    }
    printf("%lld\n",ans*qpow(n,mod-2)%mod);
    return 0;
}


#include <stdio.h>

int main () {
 char s[10], m=0; int cnt=0, i;
 gets(s);
 int l = strlen(s);
 for(i=0; i<l; i++)
  if (s[i] > m) {
   m = s[i];
   cnt = 1;
  } else
     if (s[i] == m)
      cnt++;
  for(i=0; i<cnt; i++)
  printf("%c", m);
}


#include <bits/stdc++.h>
using namespaces std;

int main()
{
    long long a, b;
    cin >> a >>b;
    long long num[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    long long ans =0;
    for(long long i=a; i<=b; ++i){
        long long temp = i;
        while(temp){
            ans += num[temp%10];
            temp/=10;
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
const int maxn=500100;
char s[maxn],r[maxn];
int n,d;
ull p[maxn],hash[maxn],rhash[maxn];
bool ok(int ed,int d)
{
	ed++;
	int st=ed-d+1;
	if(st<0) return true;
	if((rhash[ed]-rhash[st-1]*p[d])*p[st-1]!=hash[ed]-hash[st-1])
		return true;
	return false;
}
bool dfs(int x,int t)
{
	if(x==n)
	{
		puts(r);
		return true;
	}
	for(r[x]=(t?s[x]:'a');r[x]<='z';r[x]++)
	{
		hash[x+1]=hash[x]+r[x]*p[x];
		rhash[x+1]=rhash[x]*175+r[x];
		if(ok(x,d)&&ok(x,d+1)&&dfs(x+1,t&&(r[x]==s[x])))
			return true;
	}
	return false;
}

int main()
{
	cin>>d;
	cin>>s;
	n=strlen(s);
	int i=n-1;
	for(;i>=0&&s[i]=='z';i--)
		s[i]='a';
	if(i<0)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	s[i]++;p[0]=1;
	for(int i=1;i<n+100;i++)
		p[i]=p[i-1]*175;
	if(dfs(0,1)==false)
		cout<<"Impossible"<<endl;
	return 0;
}


#include <stdio.h>
#include <math.h>
int main(){
	long long x1,y1,x2,y2;
	while (scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2)!=EOF){
		long long x,y;
		scanf("%lld%lld",&x,&y);
		long long lenx,leny;
		lenx=x2-x1;
		leny=y2-y1;
		if(lenx<0)
		lenx*=(-1);
		if(leny<0)
		leny*=(-1);
		if(leny==0&&(lenx/x)%2==0||lenx==0&&(leny/y)%2==0){
			printf ("YES\n");
		}
		else if ((lenx*1.0)/x==(leny*1.0)/y){
			printf ("YES\n");
		}
		else{
			printf ("NO\n");
		}
	}


#include <iostream>
#include <string>
using namespace std;
int n,x1,y1,x2,y2,n1,n2;
int main()
{
 cin>>n>>x1>>y1>>x2>>y2;
 if(x1>=y1)n1=x1+y1+1;else n1=4*n-x1+y1;
 if(x2>=y2)n2=x2+y2+1;else n2=4*n-x2+y2;
 cout<<min(abs(n1-n2),4*n-abs(n1-n2)+1)<<endl;
 return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
using namespace std;
int main()
{
    int n; scanf("%d",&n);
    if (n % 2 == 0) cout << 0;
    else{
        if (n == 1) count << 1;
        if (n == 3) cout << 18;
        if (n == 5) cout << 1800;
        if (n == 7) cout << 670320;
        if (n == 9) cout << 734832000;
        if (n == 11) cout << 890786230;
        if (n == 13) cout << 695720788;
        if (n == 15) cout << 150347555;
        }
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
double x[1005][5];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	FOR(i, n) {
		FOR(j, 5) cin >> x[i][j];
	}
	vector<int> v;
	FOR(i, n) {
		bool ok = true;
		// int cnt = 0;
		FOR(j, n) {
			if (j == i) continue;
			for (int k = j+1; k < n; k++) {
				if (k == i) continue;
				double u[5], v[5], uv = 0, u2 = 0, v2 = 0;
				FOR(c, 5) {
					u[c] = x[j][c]-x[i][c];
					v[c] = x[k][c]-x[i][c];
					uv += u[c]*v[c];
					u2 += u[c]*u[c];
					v2 += v[c]*v[c];
				}
				if (acos(uv/sqrt(u2*v2))*2.0 < M_PI) ok = false;
				// cnt++;
			}
		}
		// cout << cnt << endl;
		if (ok) v.push_back(i+1);
	}
	cout << v.size() << endl;
	FOR(i, v.size()) cout << v[i] << endl;
	return 0;
}


#include <cstdio>
using namespace std;
typedef long long ll
const int P = 1e9 + 7;
const int N = 2e6 + 10;
int n, k, pc;
int pw[N], mu[N], p[N], b[N * 2];
bool vis[N];

void sieve();
int pow(int x, int k);

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= k; ++i)
        pw[i] = pow(i, n);
    sieve();
    for (int x = 1; x <= k; ++x) {
        for (int i = 1; i * x <= k; ++i) {
            b[i * x] = (b[i * x] + (ll)pw[i] * (P + mu[x]) % P) % P;
            b[i * x] = (b[i * x] - (ll)pw[i - 1] * (P + mu[x] % P)) % P;
            if (b[i * x] < 0)
                b[i * x] += P;
        }
    }
    int ans = 0;
    for (int i = 1; i <= k; ++i) {
        b[i] = (b[i] + b[i - 1]) % P;
        ans = (ans + (b[i] ^ i) % P) % P;
    }
    printf("%d\n", ans);
    return 0;
}

void sieve() {
    mu[1] = 1;
    for (int x = 2; x <= k; ++x) {
        if (!vis[x]) {
            p[++pc] = x;
            mu[x] = -1;
        }
        for (int j = 1; x * p[j] <= k; ++j)
            if (x % p[j] == 0) {
                mu[x * p[j]] = 0;
                vis[x * p[j]] = true;
                break;
            } else {
                mu[x * p[j]] = -mu[x];
                vis[x * p[j]] = true;
            }
    }
}
int pow(int x, int k) {
    int ret = 1;
    while (k) {
        if (k & 1)
            ret = (ll)ret * x % P;
        x = (ll)x * x % P;
        k >>= 1;
    }
    return ret;
}


#include<iostream>
#include<vector>
#include<algorithm>
// #include<math.h>
// #include<ctime>
// #include<cmath>
// #include<utility>
// #include<cstdlib>
// #include<bitset>
#include<map>
// #include<set>
// #include<queue>
// #include<stack>
// #include<iomanip>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const ll M = 1e9 + 7;

ll N = 4004;
const ll MOD = 1e9 + 7;

ll add(ll x, ll y){
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

ll mul(ll x, ll y){
    return (x * y) % MOD;
}

ll binpow(ll x, ll y){
    if(y == 0ll){
        return 1ll;
    }
    if(y == 1ll){
        return x;
    }
    ll z = binpow(x, y/2);
    z = mul(z, z);
    if(y%2 == 0ll){
        return z;
    }
    z = mul(z, x);
    return z;
}

ll inv(ll x){
    return binpow(x, MOD - 2);
}

ll divide(ll x, ll y){
    return mul(x, inv(y));
}

vector<ll> fact(N, 0);

void precalc(){
    fact[0] = 1;
    for(int i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

int C(int n, int k){
    return divide(fact[n], mul(fact[k], fact[n - k]));
}

void print(vector<ll> &a){
    int n = a.size();
    for(int i=0; i<10; i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}

vector<ll> dp(N, 0ll), cf(N, 0ll);

void fill(ll n){
    for(ll i=0; i<n; i++){
        ll term = mul(C(n-1, i), cf[n-i-1]);
        dp[n] = add(dp[n], term);
    }
    cf[n] = add(cf[n-1], dp[n]);
}

void ini(){
    precalc();
    dp[0] = 1;
    cf[0] = 1;
    for(ll i=1; i<N; i++){
        fill(i);
    }
}

ll solve(ll n){
    ll ans = cf[n-1];
    for(ll i=0; i<=n-2; i++){
        ll m = mul(C(n-1, i), n-i-1);
        if(i == 0){
            m = mul(m, cf[n-2-i]-1);
            ans = add(ans, m+1);
        }
        else{
            m = mul(m, cf[n-2-i]);
            ans = add(ans, m);
        }
    }
    return ans;
}

int main(){

    fastio;
    ll n;
    clock_t time_req;
    time_req = clock();
    cin>>n;
    N = n+5;
    ini();
    print(dp);
    print(cf);
    ll ans = solve(n);
    cout<<ans<<endl;
    time_req = clock()-time_req;
    cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
    return 0;
}


#include <bits/stdc++.h>
//#include <sys/resource.h>
#define initrand mt19937 mt_rand(time(0));
#define rand mt_rand()
#define int long long
#define MOD 1000000007
#define INF 1000000000
#define mid(l, u) ((l+u)/2)
#define rchild(i) (i*2 + 2)
#define lchild(i) (i*2 + 1)
#define mp(a, b) make_pair(a, b)
#define lz lazup(l, u, i);
using namespace std;
const int N = 505;
int dp[N][N*N], p[N][N*N], nCr[N][N], fac[N];
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, mod;
    cin>>n>>mod;
    dp[0][0] = 1;
    dp[0][0] %= mod;
    for(int i = 1;i<=n;i++){
        int sum = 0;
        int maxi = i*(i-1)/2;
        for(int j = 0;j<=maxi;j++){
            sum += dp[i-1][j];
            if((j - i)>=0) sum -= dp[i-1][j-i];
            sum %= mod;
            sum += mod;
            sum %= mod;
            dp[i][j] = sum;
        }
        p[i][maxi] = dp[i][maxi];
        for(int j = maxi-1;j>=0;j--){
            p[i][j] = dp[i][j] + p[i][j+1];
            p[i][j] %= mod;
        }
    }
    fac[0] = 1;
    for(int i = 1;i<N;i++){
        fac[i] = i*fac[i-1];
        fac[i] %= mod;
    }
    nCr[0][0] = 1;
    nCr[0][0] %= mod;
    for(int i = 1;i<N;i++) nCr[0][i] = 0;
    for(int i = 1;i<N;i++){
        nCr[i][0] = nCr[i][i] = 1;
        nCr[i][i] %= mod;
        for(int j = 1;j<i;j++){
            nCr[i][j] = nCr[i-1][j] + nCr[i-1][j-1];
            nCr[i][j] %= mod;
        }
    }
    int ans = 0;
    for(int i = 1;i<=(n-1);i++){
        int b = nCr[n][i+1];
        b *= fac[n-i-1];
        b %= mod;
        int maxi = i*(i-1)/2;
        int bb = 0;
        int ww = 0;
        for(int k = maxi;k>=0;k--){
            ww -= bb;
            if((k+2) <= maxi) ww += p[i][k+2]*i;
            ww %= mod;
            ww += mod;
            ww %= mod;

            if((k+i+1)<=mod) bb -= p[i][k+i+2];
            if((k+2) <= mod) bb += p[i][k+2];
            bb %= mod;
            bb += mod;
            bb %= mod;
            int xx = 0;
            for(int j = 2;j<=(i+1);j++){
                xx += p[i][k+j]*(i+ 2 - j);
                xx %= mod;
            }
            int toAdd = b;
            toAdd *= dp[i][k];
            toAdd %= mod;
            toAdd *= ww;
            ans += toAdd;
            ans %= mod;
        }
    }
    cout<<ans<<endl;
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BRG1", "BRG1\BRG1.vcxproj", "{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|x64 = Debug|x64
		Debug|x86 = Debug|x86
		Release|x64 = Release|x64
		Release|x86 = Release|x86
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}.Debug|x64.ActiveCfg = Debug|x64
		{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}.Debug|x64.Build.0 = Debug|x64
		{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}.Debug|x86.ActiveCfg = Debug|Win32
		{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}.Debug|x86.Build.0 = Debug|Win32
		{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}.Release|x64.ActiveCfg = Release|x64
		{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}.Release|x64.Build.0 = Release|x64
		{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}.Release|x86.ActiveCfg = Release|Win32
		{38B88C7C-488F-4D9F-8A6B-38B49B277BD9}.Release|x86.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


#include <bits/stdc++.h>
using namespace std;
const int64_t base=998244353;
int64_t power(int64_t x, int64_t y){
  if(y==0) return 1;
  int64_t t=power(x, y/2);
  t=(t*t)%base;
  if(y%2) t=(t*x)%base;
  return t;
}
int64_t inverse(int64_t x){//modular inverse
  return power(x, base-2);
}
vector <int64_t> f({1}), iv({1});

int64_t C(int64_t n, int64_t k){
    return ((f[n]*iv[k]%base)*iv[n-k])%base;
}
int64_t star(int64_t n, int64_t k){
    return C(n+k-1, k-1);
}
int64_t countGame(int64_t n, int64_t k, int64_t x){//n points total, k players, no player can have x point or more
  if(k==0) return !(n==0);
  int64_t ans=0
  for(int i=0; i<=k; i++){
    int64_t t=n-x*i;
    if(t<0) break;
    if(i%2) ans=(ans-C(k, i)*star(t, k))%base;
    else ans=(ans+C(k, i)*star(t, k))%base;
  }
  return ans;
}
int main(){
  int p, s, r;
  int64_t gameSize=countGame(s-r, p, 1e18);
  gameSize=inverse(gameSize);
  cin>>p>>s>>r;
  for(int i=1; i<5555; i++){
    f.push_back((f[i-1]*i)%base);
    iv.push_back(inverse(f[i]));
  }
  int64_t ans=0;
  for (int q=r; q<=s; q++){
    for(int i=0; i<p; i++){//exactly i people have the same score
        int64_t t=s-(i+1)*q;
        if(t<0) break;
        ans=(ans+(((C(p-1, i)*countGame(t, p-i-1, q))%base)*gameSize%base)*inverse(i+1))%base;
    }
  }
  cout<<ans<<'\n';
}


#include <bits/stdc+.h>

using namespace std;

int d1[1001],d2[1001],n,tg;

int main(){
cin>>n;
for(int i=1;i<=n;i++)
{cin>>tg;
d1[tg]++;
}
for (int i=1;i<=n;i++){
cin>>tg;
d2[tg]++;
}
for (int i=1;i<=1000;i++) if (d1[i]<d2[i]) {
cout<<"NO";
return 0;
}
cout<<"YES";
}


#include <cstdio>

using ull = unsigned long long;
using L = __uint128_t;

using namespace std;

struct FastMod {
	ull b, m;

	FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}

	ull operator()(ull a) {
		ull q = (ull) ((L(m) * a) >> 64);
		ull r = a - q * b;  // can be proven that 0 <= r < 2*b
		return r >= b ? r - b : r;
	}
} R(2);

int mod;
inline void add(int &x, int y) {
  if ((x += y - mod) < 0)
    x += mod;
}

const int N = 400;
int n;
int f[N + 5][N + 5], ans;

int main() {
  scanf("%d%d", &n, &mod), R = FastMod(mod);
  f[0][0] = 1;
  for (int k = 1; 2 * k <= n + 1; ++k) {
    for (int i = 1; i <= n - k + 1; ++i)
      f[k][i] = R((2ULL * f[k][i - 1] + f[k - 1][i - 1]) * k);
    add(ans, f[k][n - k + 1]);
  }
  printf("%d\n", ans);
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

const int maxn = 80 + 5;
const int INF = 1 << 29;

ll dp[maxn][maxn][maxn][2];
int a[maxn], b[maxn], c[maxn];
char s[maxn];

void upmin(int &a, int b)
{
    a = min(a, b);
}

int main()
{
    int n;
    scanf("%d%s", &n, s + 1);
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(s[i] == 'V') a[++cnt1] = i;
        else if(s[i] == 'K') b[++cnt2] = i;
        else c[++cnt3] = i;
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0][0][0] = 0;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j <= cnt1; ++j)
        {
            for(int k = 0; k <= cnt2; ++k)
            {
                for(int l = 0; l < 2; ++l)
                {
                    int m = i - j - k;
                    if(i - j - k <= cnt3)
                    {
                        int p = upper_bound(a + 1, a + j + 1, c[m]) - a - 1, q = upper_bound(b + 1, b + k + 1, c[m]) - b - 1;
                        upmin(dp[i][j][k][0], dp[i - 1][j][k][l] + abs(c[m] + j - p + k - q - i));
                    }
                    if(j < cnt1)
                    {
                        int p = upper_bound(b + 1, b + k + 1, a[j + 1]) - b - 1, q = upper_bound(c + 1, c + m, a[j + 1]) - c - 1;
                        upmin(dp[i][j + 1][k][1], dp[i - 1][j][k][l] + abs(a[j + 1] + k - p + m - 1 - q - i));
                    }
                    if(k < cnt2 && l != 1)
                    {
                        int p = upper_bound(c + 1, c + m, b[k + 1]) - c - 1, q = upper_bound(a + 1, a + j + 1, b[k + 1]) - a - 1;
                        upmin(dp[i][j][k + 1][0], dp[i - 1][j][k][l] + abs(b[k + 1] + m - 1 - p + j - q - i));
                    }
                }
            }
        }
    }
    printf("%I64d\n", min(dp[n][cnt1][cnt2][0], dp[n][cnt1][cnt2][1]));
    return 0;
}


#include <iostream>
using namespace std;
 int n,i,j,x,d=0;

int main(){
    cin>>n;
 for (i=0; i<n; i++){
     for(j=0; j<n; j++){
     cin>>x;
     if (i==j || i==(n/2) || j==(n/2) || (n-i)==j+1)

    d=d+x;

    //  system ("PAUSE");
       return 0;
       }


#include<bits/stdc++.h>
using namespace std;

int n, d, ans;

	int main(){

		int arr[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		cin >> n >> d;
		int m = d;
		for (int i = d; i <= arr[n] + d; i++)
		{
			if (m == 7){
				m = 1;
				ans++;
			}
			m++;
		}
		cout << ans << endl;

		return 0;


#include <bits/stdc++.h>
using namespace std;

const int maxn = 500050;

int mx[maxn], lx[maxn], rx[maxn], v[maxn], tag[maxn], rev[maxn];
int fa[maxn], c[maxn][2], size[maxn], sum[maxn];
int n, m, rt, cnt, id[maxn], a[maxn];
char op[30];
queue<int> q;

inline void read(int &x)
{
    int f = 1;
    x = 0; char c = '.';
    while(c < '0' || c > '9') {if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9') x = x*10 + c-'0', c=getchar();
    x *= f;
}

inline int max(int a,int b){return (a > b ? a : b);}

inline void pushup(int k)
{
    int l = c[k][0], r = c[k][1];
    sum[k] = v[k] + sum[l] + sum[r];
    size[k] = size[l] + size[r] + 1;
    mx[k] = max(mx[l], max(mx[r], rx[l]+v[k]+lx[r]));
    lx[k] = max(lx[l], sum[l]+v[k]+lx[r]);
    rx[k] = max(rx[r], sum[r]+v[k]+rx[l]);
}

inline void pushdown(int k)
{
    int l = c[k][0], r = c[k][1];
    if(tag[k])
    {
        rev[k] = tag[k] = 0;
        if(l) tag[l] = 1, v[l] = v[k], sum[l] = v[k]*size[l];
        if(r) tag[r] = 1, v[r] = v[k], sum[r] = v[k]*size[r];
        if(v[k] >= 0)
        {
            if(l) lx[l] = rx[l] = mx[l] = sum[l];
            if(r) lx[r] = rx[r] = mx[r] = sum[r];
        }
        else
        {
            if(l) lx[l] = rx[l] = 0, mx[l] = v[k];
            if(r) lx[r] = rx[r] = 0, mx[r] = v[k];
        }
    }
    if(rev[k])
    {
        rev[k] ^= 1; rev[l] ^= 1; rev[r] ^=1;
        swap(c[l][0],c[l][1]); swap(c[r][0], c[r][1]);
        swap(lx[l], rx[l]); swap(lx[r], rx[r]);
    }
}

void rotate(int x,int &k)
{
    int y = fa[x], z = fa[y], l, r;
    l = (c[y][1]==x); r = l^1;
    if(y == k) k = x;
    else c[z][(c[z][1]==y)] = x;
    fa[x] = z; fa[y] = x; fa[c[x][r]] = y;
    c[y][l] = c[x][r]; c[x][r] = y;
    pushup(y); pushup(x);
}

void splay(int x,int &k)
{
    while(x != k)
    {
        int y = fa[x], z = fa[y];
        if(y != k)
        {
            if(c[y][0]==x^c[z][0]==y) rotate(x,k);
            else rotate(y,k);
        }
        rotate(x,k);
    }
}

int find(int k,int rk)
{
    pushdown(k);
    int l = c[k][0], r = c[k][1];
    if(size[l]+1 == rk) return k;
    else if(size[l] >= rk) return find(l,rk);
    else return find(r,rk-size[l]-1);
}

int split(int k,int tot)
{
    int x = find(rt,k), y = find(rt,k+tot+1);
    splay(x,rt); splay(y,c[x][1]);
    return c[y][0];
}

void rec(int k)
{
    if(!k) return;
    int l = c[k][0], r = c[k][1];
    rec(l); rec(r); q.push(k);
    c[k][0] = c[k][1] = fa[k] = 0;
    tag[k] = rev[k] = 0;
}

void build(int l,int r,int f)
{
    if(l > r) return;
    int mid = l+r >> 1;
    int now = id[mid], last = id[f];
    if(l == r)
    {
        sum[now] = a[l]; size[now] = 1;
        tag[now] = rev[now] = 0;
        if(a[l] >= 0) lx[now] = rx[now] = mx[now] = a[l];
        else lx[now] = rx[now] = 0, mx[now] = a[l];
    } else build(l,mid-1,mid), build(mid+1,r,mid);
    v[now] = a[mid]; fa[now] = last; pushup(now);
    c[last][mid>=f] = now;
}

void insert(int k,int tot)
{
    fo(i,1,tot) read(a[i]);
    fo(i,1,tot)
        if(!q.empty()) id[i] = q.front(), q.pop();
        else id[i] = ++ cnt;
    build(1,tot,0); int z = id[(tot+1)>>1];
    int x = find(rt,k+1), y = find(rt,k+2);
    splay(x,rt); splay(y,c[x][1]);
    c[y][0] = z; fa[z] = y;
    pushup(y); pushup(x);
}

void delet(int k,int tot)
{
    int x = split(k,tot), y = fa[x];
    rec(x); c[y][0] = 0;
    pushup(y); pushup(fa[y]);
}

void modify(int k,int tot,int c)
{
    int x = split(k,tot), y = fa[x];
    tag[x] = 1; v[x] = c; sum[x] = c*size[x];
    if(c >= 0) lx[x] = rx[x] = mx[x] = sum[x];
    else lx[x] = rx[x] = 0, mx[x] = c;
    pushup(y); pushup(fa[y]);
}

void rever(int k,int tot)
{
    int x = split(k,tot), y = fa[x];
    if(!tag[x])
    {
        rev[x] ^= 1;
        swap(c[x][0], c[x][1]); swap(lx[x], rx[x]);
        pushup(y); pushup(fa[y]);
    }
}

void query(int k,int tot)
{
    int x = split(k,tot);
    printf("%d\n",sum[x]);
}
int aa[] = {0, 1, 9, 245, 126565, 54326037, 321837880, 323252721, 754868154, 328083248, 838314395, 220816781, 893672292, 166441208, 251255697, 114256285, 118775501, 482714697, 11784725, 460862131, 550384565, 106742050, 425241115, 626692854, 674266678, 320014275, 345949512, 527320049, 897822749, 137190263, 491039182, 810384961, 482023334, 658099864, 886790989, 845381174, 371433224, 278969124, 420088324, 696766322, 388302635, 141033366, 46387851, 932125021, 278342766, 371131134, 922501918, 110778457, 506223573, 806353719, 391845991, 923507761, 780307355, 109951115, 830090230, 605558495, 344686604, 988110893, 944684429, 715019947, 799898820, 384672708, 907325090, 758952329, 550672104, 368337206, 394915145, 401744167, 923781939, 831857516, 407845661, 329267374, 927004007, 891609656, 897919613, 481297880, 737337940, 651873737, 287246681, 973133651, 679864988, 784719328, 820504764, 875613823, 806512665, 164851642, 500228957, 951814419, 447763649, 273141670, 979349615, 964027956, 809510400, 276634497, 116631976, 426739449, 175282420, 885948162, 62270880, 974395255, 675165056, 759589968, 837957573, 931897605, 152352780, 585420109, 1772087, 333401718, 898833639, 745874265, 786209423, 691982338, 498790927, 473374639, 274302623, 971280670, 241671319, 13070005, 302088807, 550276351, 436592588, 631667314, 548656698, 730626984, 146295220, 674398632, 400383348, 454138904, 786220712, 118620797, 233440672, 217349271, 274853536, 310607544, 105221205, 769566615, 853585061, 800665807, 695377419, 924327065, 388199705, 551624811, 721435546, 501720515, 308465454, 825369234, 396065729, 451899519, 295058424, 142088952, 473485086, 378771634, 734511215, 462404399, 959198328, 337668263, 794122911, 38911400, 951992982, 472696081, 373904752, 105884826, 630251717, 28980684, 845136347, 353665773, 691661192, 19922354, 231463797, 757917231, 242739918, 979036950, 713722080, 234689388, 2243164, 209872853, 240808787, 539523346, 425797848, 913772061, 224613100, 421742777, 222232478, 92712941, 215137570, 949901408, 274827432, 15162482, 593145989, 274574232, 239282092, 762720192, 804146934, 500629424, 565985054, 81127381, 671811155, 655565571, 890331075, 237994348, 743647404, 667160634, 713914299, 668506729, 741341289, 277636808, 762781382, 14272789, 902864131, 567443405, 149113383, 648844381, 825489976, 933016723, 192288078, 734493315, 240985733, 861817693, 762711459, 525904609, 532463481, 377133989, 620711079, 772561562, 980733194, 227599811, 162774370, 209512798, 787116594, 3509258, 748795368, 378035466, 612938915, 802091952, 857679599, 481748937, 493370392, 358420805, 48301629, 412001241, 463126722, 509578422, 967799131, 994766554, 687287243, 863623583, 771554899, 690911527, 855314994, 923686429, 246862514, 192479791, 133487041, 703444043, 295281758, 801816257, 920762934, 749306433, 973004841, 848644684, 560026478, 952127278, 616654635, 839390326, 975154012, 409583672, 635350249, 343228425, 335331602, 223826406, 952341037, 589677800, 249747234, 555694261, 137143500, 628190328, 461598392, 431912756, 29349807, 759199489, 783281228, 781971312, 915823407, 388508707, 718062705, 27424111, 309999451, 963383322, 831185229, 132910888, 347028136, 850484840, 223055285, 142335980, 144754000, 772005560, 81796039, 167696020, 79454283, 172772542, 201056991, 484957644, 716630285, 763194701, 211505841, 903448791, 926964672, 257752668, 482951716, 411539070, 620249847, 592476107, 170473128, 814662613, 898000271, 57354872, 361106091, 488697643, 889007954, 138725767, 684860983, 36248116, 304610143, 137633385, 413715776, 99010024, 779653665, 100387568, 286328069, 564731826, 621740468, 943513219, 506666491, 249987886, 553719884, 769853086, 337485319, 702455584, 809637762, 755400257, 892290368, 502180086, 364275817, 118162370, 873374339, 261271695, 970132574, 744105500, 434447173, 117975095, 383088393, 625447969, 180281249, 545367713, 133236931, 360175662, 148087453, 806871297, 498529036, 886076476, 65645000, 465138299, 967109895, 331362616, 472283705, 796894900, 199697765, 503759892, 472807906, 187586706, 941198065, 782234442, 57693411, 18678611, 82626204, 395317191, 570588915, 152519440, 449852456, 63696518, 763741345, 878748386, 494317541, 444782633, 93316211, 929164666, 529288371, 165769871, 730546850, 955877127, 994202767, 492009567, 275683011, 415902127, 95725776, 718047399, 786963365, 73091278, 986172399, 174591541, 913259286};

int n;

int main()
{
	cin >> n;
	cout << aa[n];
	return 0;
}


#include<bits/stdc++.h>
 using namespace std; long long n,p,l1,r1,ans,cnt,q[105],r[105],Q,R,P,pw[55]; void exgcd(long long a,long long b,long long &x,long long &y){ 	if(b==0){ 		x=1;y=0; 		return; 	} 	exgcd(b,a%b,x,y); 	int t=x; 	x=y;y=t-y*(a/b); 	return; } struct fe{ 	long long rem,x; 	fe operator *(const fe &o)const{ 		return (fe){rem+o.rem,x*o.x%Q}; 	} 	fe operator *(long long o)const{ 		int y=0;while(o%P==0)y++,o/=P; 		return (fe){rem+y,x*o%Q}; 	} 	fe inv(){ 		long long a,b;exgcd(x,Q,a,b); 		if(a<0)a+=Q; 		return (fe){-rem,a}; 	} 	long long get(){ 		if(rem>=R)return 0; 		return pw[rem]*x%Q; 	} }fc[100005],fi[100005]; long long C(long long x,long long y){ 	if(y<0||x<0||x<y)return 0; 	return (fc[x]*fi[y]*fi[x-y]).get(); } long long calc(long long n,long long p,long long k){ 	long long nowx=0,nowy=1; 	for(int i=0;i<cnt;i++){ 		P=q[i],R=r[i];Q=1;for(int i=0;i<R;i++)Q*=P; 		pw[0]=1;for(int i=1;i<R;i++)pw[i]=pw[i-1]*P;pw[R]=0; 		fc[0]=(fe){0,1};for(int i=1;i<=n;i++)fc[i]=fc[i-1]*i; 		fi[n]=fc[n].inv(); 		for(int i=n;i;i--)fi[i-1]=fi[i]*i; 		long long ans=0; 		for(int i=0;i<=n;i++)if((n-i+k)%2==0){ 			ans=(ans+C(n,i)*C(n-i,(n-i+k)/2))%Q; 		} 		long long a,b;exgcd(Q,nowy,a,b); 		long long u=nowy*b,v=a*Q; 		nowx=nowx*v+ans*u,nowy*=Q; 		nowx%=nowy;if(nowx<0)nowx+=nowy; 	} 	return nowx; } int main(){ 	scanf("%I64d%I64d%I64d%I64d",&n,&p,&l1,&r1); 	long long m=p; 	for(long long i=2;i*i<=p;i++)if(m%i==0){ 		q[cnt]=i; 		while(m%i==0)m/=i,r[cnt]++; 		cnt++; 	} 	if(m>1){ 		q[cnt]=m;r[cnt]=1; 		cnt++; 	} 	int s=l1,e=r1; 	if(s%2==1)s++;if(e%2==1)e--; 	if(s<=e)ans=(ans+calc(n,p,s)-calc(n,p,e+2)+p)%p; 	s=l1,e=r1; 	if(s%2==0)s++;if(e%2==0)e--; 	if(s<=e)ans=(ans+calc(n,p,s)-calc(n,p,e+2)+p)%p; 	printf("%lld\n",ans); 	return 0; }

1


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

/* Name of the class has to be "Main" only if the class is public. */
class Solution
{
	public static BigInteger MOD = new BigInteger("1000000007");
	public static BigInteger negOne = new BigInteger("-1");
	public static BigInteger pre[][] = new BigInteger[2010][2010];
	public static int vis[][][] = new int[2010][2010][2];
	public static BigInteger DP[][][] = new BigInteger[2010][2010][2];

	public static void initial ( int n )
	{
		for ( int i = 0; i <= 2 * n; i++ )
			for ( int j = 0; j <= 2 * n; j++ )
				pre[i][j] = negOne;
	}

	public static BigInteger precalc ( int i, int open )
	{
		if ( open < 0 )
			return BigInteger.ZERO;
		if ( i == 0 )
		{
			if ( open == 0 )
				return pre[i][open] = BigInteger.ONE;
			return pre[i][open] = BigInteger.ZERO;
		}

		if ( pre[i][open] != negOne )
			return pre[i][open];

		return pre[i][open] = (precalc ( i - 1, open + 1 ).add(precalc ( i - 1, open - 1 ))).mod ( MOD );
	}

	public static BigInteger dp ( int i, int open, int f )
	{
		if ( i == 0 )
			return BigInteger.ZERO;
		if ( vis[i][open][f] == 1 )
			return DP[i][open][f];

		if ( f == 0 )
		{
			if ( pre[i - 1][open + 1].equals(pre[i][open]) )
				DP[i][open][f] = dp ( i - 1, open + 1, 0 ).max ( dp ( i - 1, open + 1, 1 ).add ( BigInteger.ONE ) );
			else if ( pre[i - 1][open + 1].equals(BigInteger.ZERO) )
				DP[i][open][f] = dp ( i - 1, open - 1, 0 ).max ( dp ( i - 1, open - 1, 1 ).add ( BigInteger.ONE ) );
			else
			{
				DP[i][open][f] = dp ( i - 1, open + 1, 1 ).add(dp ( i - 1, open - 1, 0 ).add(BigInteger.ONE));
				DP[i][open][f] = DP[i][open][f].max(dp ( i - 1, open + 1, 0 ).add(dp ( i - 1, open - 1, 1 ).add(BigInteger.ONE)));
				DP[i][open][f] = DP[i][open][f].max(dp ( i - 1, open + 1, 0 ).add(dp ( i - 1, open - 1, 0 )));
			}
		}
		else
		{
			if ( pre[i - 1][open + 1].equals(pre[i][open]) )
				DP[i][open][f] = dp ( i - 1, open + 1, 0 );
			else if ( pre[i - 1][open + 1].equals(BigInteger.ZERO) )
				DP[i][open][f] = dp ( i - 1, open - 1, 0 );
			else
				DP[i][open][f] = dp ( i - 1, open - 1, 0 ).add(dp ( i - 1, open + 1, 0 ));
		}

		DP[i][open][f] = DP[i][open][f].mod(MOD);

		vis[i][open][f] = 1;
		return DP[i][open][f];
	}

	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner ( System.in );
		int N = in.nextInt();
		initial(N);
		precalc ( 2 * N, 0 );
		System.out.println ( dp ( 2 * N, 0, 0 ).mod(MOD) );
	}
}


#include <bits/stdc++.h>
using namespace std ;

int main()
{
    int a ;
    cin >> a ;
    int ans ;
    ans = ( a== 1) : 1 : 2 * (a - 1 ) ;
    cout << ans << '\n' << "1 2 " << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long ll;
vector <vector <pair<ll,ll> > > dp(50,vector <pair<ll,ll> > (50));
vector <vector <char> > trace_back(50,vector <char> (50));
string t;
void trace_path(ll i,ll j){
    if(i==0&&j==0){
        return;
    }
    else{
        if(j0 && dp[i][j].first==dp[i][j-1].first){
            t.push_back('M');
            trace_path(i,j-1);
        }
        else{
            t.push_back('H');
            trace_path(i-1,j);
        }
    }
}
int main(){
    ll n;cin >> n;
    string s;cin >> s;
    dp[0][0]=make_pair(0,0);trace_back[0][0]=' ';
    for(ll j=1;j<=n;j++){
        dp[0][j].second+=dp[0][j-1].second+(s[2*n-j]-'0')*pow(10,j-1);
        trace_back[0][j]='M';
    }
    for(ll i=1;i<=n;i++){
        dp[i][0].first+=dp[i-1][0].first+(s[2*n-i]-'0')*pow(10,i-1);
        trace_back[i][0]='H';
    }
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            ll MAX=0;
            MAX=max(dp[i][j-1].second+(s[2*n-i-j]-'0')*pow(10,j-1)+dp[i][j-1].first,dp[i-1][j].first +(s[2*n-i-j]-'0')*pow(10,i-1)+dp[i-1][j].second);
            if(MAX==dp[i][j-1].second+(s[2*n-i-j]-'0')*pow(10,j-1)+dp[i][j-1].first){
                dp[i][j].second= dp[i][j-1].second+(s[2*n-i-j]-'0')*pow(10,j-1);
                dp[i][j].first = dp[i][j-1].first;
                trace_back[i][j]='M';
            }
            else{
                dp[i][j].first = dp[i-1][j].first +(s[2*n-i-j]-'0')*pow(10,i-1);
                dp[i][j].second= dp[i-1][j].second;
                trace_back[i][j]='H';
            }
        }
    }
    /*for(ll i=0;i<=n;i++){
        for(ll j=0;j<=n;j++){
            cout << setfill(' ') << setw(n) << dp[i][j].first;
            cout << "-" ;
            cout << setfill(' ') << setw(n) << dp[i][j].second << " ";
        }
        cout << endl;
    }
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=n;j++){
            cout << trace_back[i][j] << " ";
        }
        cout << endl;
    }*/
    trace_path(n,n);
    cout << t << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long int
const long long N=1e6+5;

map<string, char> m;
map<ll,ll> cache[30];
ll n,q;
ll dp(char reqd, ll len)
{
	if(len==n)
	{
		return 1;
	}
	if(cache[reqd-'a'].find(len)!=cache[reqd-'a'].end())
	{
		return cache[reqd-'a'][len];
	}
	ll ans=0;
	for(auto it:m)
	{
		if(it.ss==reqd)
		{
			ans+=dp((it.ff)[0],len+1);
		}
	}
	cache[reqd-'a'][len]=ans;
	return ans;
}
int main()
{

	cin>>n>>q;
	for(int i=0;i<q;i++)
	{
		string a;
		char b;
		cin>>a>>b;
		m[a]=b;
	}
	cout<<dp('a',1);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
int t,s,q,count=1;
cin >> t >> s >>q;
do{
s+=s*(q-1);
if(s<t)
{
count++;
}
}while(s<t)
cout << count;
}


#include <iostream>
#include <string>
#include <math.h>
using namespace std;

void main() {
	string uni[] = { "Zero","one","two","three","four","five","six","seven","eight","nine","ten" };
	string teens[] = { "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen" };
	string tens[] = { "twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety" };
	int x;
	cin >> x;
	if (x >= 0 && x <= 10) {
		cout << uni[x] << endl;
	}
	else if (x > 10 && x <= 19) {
		cout << teens[(x % 10) - 1] << endl;
	}
	else {
		int y = ceil(x / 10);
		if (x - y == 0)
			cout <<tens[y-2]<< endl;

		else if((x-y)!=0)
			cout << tens[y - 2] << "-" << uni[x-(y*10)] << endl;
	}

}


#include <iostream>
#include <math.h>
using namespace std;
int main() {
   int t;
   cin>>t;
   while(t--){
       int n;
       cin>>n;
       int x=sqrt(n);
       int y=cbrt(n);
       int c=pow(n,0.166667);
       cout<<x+y-c<<endl;
   }
}#include <bits/stdc++.h>
using namespace std;
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

/*...............Short-hand .................*/

#define endl "\n"
#define int long long
#define ll long long
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vpi;
typedef pair<ll, ll> pi;
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()

/* .................Debugger Section..................*/
#define debugv(v)         \
    for (auto x : v)      \
        cout << x << " "; \
    cout << endl;

#define debugm(m)    \
    for (auto x : m) \
        cout << x.first << " " << x.second << endl;

int mod = 1e9 + 7;

ld pie = 3.14159265358979323;
// up, right, down, left
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
// int dy[8] = {0, -1, 1, 1, -1, 1, -1, 1};

/***********Use-full function **********************************/

bool isSafe(int x, int y, int row, int col)
{
    if (x < 0 || y < 0 || y >= col || x >= row)
        return 0;

    return 1;
}

bool isPrime(ll n)
{
    if (n == 1)
        return 0;
    if (n == 2)
        return 1;
    for (int i = 2; i <= sqrt(n); i++)
        if (n % i == 0)
            return 0;
    return 1;
}

int ceiling_(int x, int y)
{
    return x / y + (x % y > 0);
}

int power(int a, int n)
{
    int result = 1;
    while (n)
    {
        if (n & 1)
            result = (result * a) % mod;
        n >>= 1;
        a = (a * a) % mod;
    }

    return result % mod;
}
/*
....................Experience.....................................................................
> Sieve of Eratosthenes base is prime number of power
> always remember Merge Sort
> take all the alphabet as a string instead of taking the array of char
abcdefghijklmnopqrstuvwxyz

> if intial like pattern is equal to the final pattern the in
1-D array : all even have same turn and all even postion have same turn
2-D : {(i+j)%2 == 1} have same turn and {(i+j)%2 == 0} have same turn.

> For manhattan distance based question try to find the logic using a 2-D grid
> Read the question very carefully
> Some time also remind priority_queue
> If the question is based on string trying to think around the 26 char array
> Multiset , set , map , priority_queue
> cout<<fixed << setprecision(6) << (float variable) << endl;
> vector<vector<int>> v(n, vector<int>(n, 2));
> check 2nd Bit set or not of 'x' (x &(1<<2))
> If the answer lies b/w the range try
BINARY SEARCH
> Group based question try Connected Component
*/

void solve()
{
    set<int> s;
    for (int i = 1; i <= 100000; i++)
    {
        int t = i * i;
        int t2 = i * i * i;
        s.insert(t);
        s.insert(t2);
    }

    int n;
    cin >> n;

    int cnt = 0;
    for (auto x : s)
    {
        if (x <= n)
            cnt++;
    }
    cout << cnt << endl;
}

signed main()
{
    FIO;
    int test = 1;
    cin >> test;

    for (int i = 1; i <= test; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
}


#include <iostream>
using namespace std;

int main()
{

	int n,x=0,arr[100];
	cin>>n;

	for(int i=1;i<=n;i++)
	{
	cin>>arr[i];
	}
	if(n==1&&arr[n]!=15&&arr[n]!=0)
	{
	cout<<"-1"<<endl;
	return 0;
	}
	if(n==1&&arr[n]==0)
	{
	    cout<<"UP"<<endl;
	    return 0;
	}
	if(arr[n]<arr[n-1]&&arr[n]==0)
	{
	    cout<<"UP"<<endl
	    return 0;
	}
	if(arr[n]>arr[n-1]&&arr[n]!=15)
		cout<<"UP"<<endl;
	else
	{
		cout<<"DOWN"<<endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <map>
using namespace std;

const int maxN = 100005;
int n1, n2, m;

struct Tque{int t, u, L;}q[maxN];
struct Tnode{Tnode *son[27];}node[maxN], *nod[maxN];
int nodes;

int lev[maxN], r[maxN];
int up[maxN][20], lg[maxN];

int wa[maxN], wb[maxN], sum[maxN], Jum[maxN], sa[maxN], rank[maxN];

int tree[2][maxN];

struct Region{int L, R;}reg[maxN];
int sta[maxN], Last[maxN];

Tnode *newnode(){
    nodes++;
    return node+nodes;
}

void Readln(){
    scanf( "%d\n", &m );
    n1 = n2 = 1;
    lev[n2] = 1;
    nod[n1] = newnode();
    for (int i=1; i<=m; i++){
        int t, u, let;
        char ch;
        scanf( "%d%d ", &t, &u );
        scanf( "%c", &ch );
        let = ch-97+1;
        q[i].t = t;
        q[i].L = let;
        if (t==1){
            if (nod[u] -> son[let] == NULL){
                nod[u] -> son[let] = newnode();
            }
            n1++;
            nod[n1] = nod[u] -> son[let];
            q[i].u = n1;
        }else{
            n2++;
            up[n2][0] = u;
            r[n2] = let;
            lev[n2] = lev[u]+1;
            q[i].u = n2;
        }
    }
}

bool cmp(int *r, int a, int b){
    return r[a] == r[b] && r[Jum[a]] == r[Jum[b]];
}

void da(int *r, int *sa, int n, int m){
    int i, j, p, *x=wa, *y=wb, *t, cal = 1;
    for (i=1; i<=n; i++) sum[x[i] = r[i]]++;
    for (i=1; i<=m; i++) sum[i] += sum[i-1];
    for (i=n; i>=1; i--) sa[sum[x[i]]--] = i;
    for (i=1; i<=n; i++) Jum[i] = up[i][0];
    for (j=1, p=1; j<=2*n; j*=2, m=p){
        for (p=0, i=1; i<=n; i++) if (lev[i]<=j) y[++p] = i;
        for (i=0; i<=m; i++) sum[i] = 0;
        for (i=1; i<=n; i++) if (lev[i] > j) sum[x[Jum[i]]]++;
        for (i=1; i<=m; i++) sum[i] += sum[i-1];
        for (i=n; i>=1; i--)
        if (lev[i] > j){
            y[p+sum[x[Jum[i]]]] = i;
            sum[x[Jum[i]]]--;
        }
        p = n;
        for (i=0; i<=m; i++) sum[i] = 0;
        for (i=1; i<=n; i++) sum[x[y[i]]]++;
        for (i=1; i<=m; i++) sum[i] += sum[i-1];
        for (i=n; i>=1; i--) sa[sum[x[y[i]]]--] = y[i];
        for (t = x, x = y, y = t, p = 1, x[sa[1]] = 1, i = 2; i <= n; i++)
        x[sa[i]] = cmp(y, sa[i-1], sa[i])?p:++p;
        for (i=1; i<=n; i++) y[i] = Jum[Jum[i]];
        for (i=1; i<=n; i++) Jum[i] = y[i];
    }
}

int lowbit(int a){return a & (-a);}

int Jump(int now, int stp){
    for (int i=stp; i>0; i-=lowbit(i)){
        now = up[now][lg[lowbit(i)]];
    }
    return r[now];
}

void inserttree(int now, int val, int t){
    for (int i=now; i<=n2; i+=lowbit(i)) tree[t][i] += val;
}

int asktree(int now, int t){
    int ret = 0;
    for (int i=now; i>0; i-=lowbit(i)) ret += tree[t][i];
    return ret;
}

int findpred(int lef, int rig, int p, int val){
    lef--;rig++;
    while (lef +1 < rig){
        int mid = (lef+rig)/2;
        if (Jump(sa[mid], p) >= val) rig = mid; else lef = mid;
    }
    return rig;
}

int findsucc(int lef, int rig, int p, int val){
    lef--;rig++;
    while (lef+1 < rig){
        int mid = (lef+rig)/2;
        if (Jump(sa[mid], p) <= val) lef = mid; else rig = mid;
    }
    return lef;
}

void Match(){
    int tot = 1;
    sta[1] = 1;
    reg[1].L = 1;
    reg[1].R = n2;
    Last[1] = 1;

    while (tot > 0){
        int now = sta[tot];
        while (Last[now] < 27 && node[now].son[Last[now]] == NULL) Last[now]++;
        if (Last[now] >= 27) {tot--; continue;}
        tot++;
        sta[tot] = node[now].son[Last[now]] - node;
        int nex = sta[tot];
        Last[nex] = 1;
        if (reg[now].L > reg[now].R) {
            reg[nex] = reg[now];
        }else{
            reg[nex].L = findpred(reg[now].L, reg[now].R, tot-2, Last[now]);
            reg[nex].R = findsucc(reg[now].L, reg[now].R, tot-2, Last[now]);
        }
        Last[now]++;
    }
}

void Solve(){
    lg[1] = 0;
    for (int i=1; (1<<i) <=n2; i++){
        for (int j=1; j<=n2; j++) up[j][i] = up[up[j][i-1]][i-1];
        lg[(1<<i)] = i;
    }
    r[0] = r[1] = 0;
    da(r, sa, n2, 30);
    Match();
    long long ans = 1;
    inserttree(1, 1, 0);
    inserttree(1, 1, 1);
    for (int i=1; i<=n2; i++) rank[sa[i]] = i;
    for (int i=1; i<=m; i++){
        if (q[i].t == 1){
            int now = nod[q[i].u]-node;
            if (reg[now].L <= reg[now].R){
                inserttree(reg[now].L, 1, 0);
                inserttree(reg[now].R+1, -1, 0);
                ans += asktree(reg[now].R, 1)-asktree(reg[now].L-1, 1);
            }
        }else{
            int now = rank[q[i].u];
            ans += asktree(now, 0);
            inserttree(now, 1, 1);
        }
        printf( "%I64d\n", ans );
    }
}

int main(){
    Readln();
    Solve();
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
const long long M=998244353;
long long dp[5001][5001][2];
long long factorial(int l,int r){
    long long ans=1;
    for (int i=l;i<=r;++i) ans=(ans*i)%M;
    return ans;
}
long long mi(long long x,long long y){
    long long base=x;
    long long ans=1;
    while (y!=0){
        if (y&1) ans=(ans*base)%M;
        base=(base*base)%M;
        y>>=1;
    }
    return ans;
}
int main()
{
    int n,k,l;
    scanf("%d%d%d",&n,&k,&l);
    l%=M;
    dp[0][0][0]=1;
    for (int i=1;i<=2*n+1;++i){
        for (int j=0;j<=i;++j){
            for (int m=0;m<=1;++m){
                if (j-1>=0) dp[i][j][m]=(dp[i][j][m]+dp[i-1][j-1][m])%M;
                dp[i][j][m]=(dp[i][j][m]+dp[i-1][j+1][m]*(j+1)%M)%M;
            }
            if (j>=k) dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][0])%M;
        }
    }
    //q^(M-2)*p*l
    long long ans=mi(factorial(n+1,2*n+1),M-2)*dp[2*n+1][0][1]%M*mi(2,n)%M*l%M;
    printf("%lld",ans);
}


# include <cstdio>
# include <iostream>
# include <stack>
# include <cstdlib>
# include <map>
# include <vector>
# include <cmath>
# include <queue>
# include <deque>
# include <iomanip>
# include <sstream>
# include <string>
# include <list>
# include <algorithm>
# include <set>
# include <bitset>

using namespace std;

long long getMin(const long long& s, const long long& e)
{
    if (e/10 < s)
    {
        double l = log10(e);
        return floor(l+1e-5) == ceil(l) ? e:s;

    }
    else
    {
        long long res = 1;
        while(res <= e)
        {
            res *= 10;
        }

        return res /= 10;
    }
}

long long getStart(long long t)
{
    long long res = 1;
    while(t)
    {
        res *= 10;
        t /= 10;
    }

    return res-1;
}

unsigned long long run(const long long& s, const long long& e)
{
    unsigned long long res = 0;
    long long head = getStart(s);
    map<int, bool> used;
    for(long long i=s; i<=e; ++i)
    {
        if (used[i]) continue;

        used[i] = used[start-i] = true;
        res = max(res, (unsigned long long)i*(head-i));
    }

    return res;
}

int main()
{
   // freopen("input.txt", "r", stdin);
    long long a,b;
    cin >> a >> b;
    //cout << run(a,maxA) << " " << run(minB, b) << endl;
    cout << run(getMin(a,b), b);

    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using std::min;
using std::lower_bound;
using std::sort;
using std::unique;
using std::vector;
inline int abs(int x)
{
	return x<0?-x:x;
}
const int mod=998244353;
inline int add(int a,int b)
{
	return (a+=b)>=mod?a-mod:a;
}
inline int sub(int a,int b)
{
	return (a-=b)<0?a+mod:a;
}
inline int mul(int a,int b)
{
	return (long long)a*b%mod;
}
inline int qpow(int a,int b)
{
	int res=1;
	for(;b;a=mul(a,a),b>>=1)
		if(b&1)
			res=mul(res,a);
	return res;
}
const int N=105;
int n,t,ans;
struct cell
{
	int x,y;
}c[N];
vector<int> V,Vx,Vy;
int sw,w[N],sumw[N];
struct task
{
	int t,l,r,k;
};
vector<task> ta;
int f[N];
namespace lglr
{
	int n;
	int x[N],y[N];
	// inline void print()
	// {
	// 	register int i;
	// 	for(i=1;i<=n;i++)
	// 		fprintf(stderr,"x:%d y:%d\n",x[i],y[i]);
	// 	return;
	// }
	inline int get(int x0)
	{
		int res=0,cur;
		register int i,j;
		for(i=1;i<=n;i++)
		{
			cur=1;
			for(j=1;j<=n;j++)
				if(i!=j)
					cur=mul(cur,mul(sub(x0,x[j]),qpow(sub(x[i],x[j]),mod-2)));
			res=add(res,mul(cur,y[i]));
		}
		return res;
	}
}
namespace zkw
{
	int M;
	int Min[N<<2],lazy[N<<2],cnt[N<<2];
	inline void push_up(int x)
	{
		Min[x]=min(Min[x<<1],Min[x<<1|1])+lazy[x];
		cnt[x]=(Min[x<<1]+lazy[x]==Min[x])*cnt[x<<1]+(Min[x<<1|1]+lazy[x]==Min[x])*cnt[x<<1|1];
		return;
	}
	inline void build(int n)
	{
		register int i;
		for(M=1;M<=n;M<<=1);
		memset(lazy,0,sizeof(int)*(M<<1));
		memset(cnt,0,sizeof(int)*(M<<1));
		for(i=1;i<=n;i++)
			Min[M+i]=0,cnt[M+i]=w[i];
		for(i=M-1;i;i--)
			push_up(i);
		return;
	}
	inline void modify(int l,int r,int k)
	{
		for(l=M+l-1,r=M+r+1;l^r^1;l>>=1,r>>=1,push_up(l),push_up(r))
			(l&1)?0:(Min[l^1]+=k,lazy[l^1]+=k),(r&1)?(Min[r^1]+=k,lazy[r^1]+=k):0;
		for(l>>=1;l;l>>=1)
			push_up(l);
		return;
	}
	inline int query()
	{
		return sw-(Min[1]==0)*cnt[1];
	}
}
inline int calc(int t)
{
	int cl,cr,res=0;
	register int i;
	Vx.clear();Vy.clear();
	for(i=1;i<=n;i++)
	{
		Vx.push_back(c[i].x-t);
		Vx.push_back(c[i].x+t+1);
		Vy.push_back(c[i].y-t);
		Vy.push_back(c[i].y+t+1);
	}
	sort(Vx.begin(),Vx.end());
	Vx.erase(unique(Vx.begin(),Vx.end()),Vx.end());
	sort(Vy.begin(),Vy.end());
	Vy.erase(unique(Vy.begin(),Vy.end()),Vy.end());
	sw=0;
	for(i=1;i<(int)Vy.size();i++)
		w[i]=Vy[i]-Vy[i-1],sw+=w[i];
	ta.clear();
	for(i=1;i<=n;i++)
	{
		cl=lower_bound(Vy.begin(),Vy.end(),c[i].y-t)-Vy.begin()+1;
		cr=lower_bound(Vy.begin(),Vy.end(),c[i].y+t+1)-Vy.begin();
		ta.push_back(task{c[i].x-t,cl,cr,1});
		ta.push_back(task{c[i].x+t+1,cl,cr,-1});
	}
	sort(ta.begin(),ta.end(),[](task a,task b)->bool
	{
		return a.t<b.t;
	});
	zkw::build((int)Vy.size()-1);
	for(i=0;i<(int)ta.size()-1;i++)
	{
		// fprintf(stderr,"%d:%d %d %d\n",ta[i].t,ta[i].l,ta[i].r,ta[i].k);
		zkw::modify(ta[i].l,ta[i].r,ta[i].k);
		// fprintf(stderr,"q:%d %d\n",ta[i+1].t-ta[i].t,zkw::query());
		res=add(res,mul(ta[i+1].t-ta[i].t,zkw::query()%mod));
	}
	// fprintf(stderr,"%d:OK(%d)\n",t,res);
	return res;
}
inline int solve(int l,int r)
{
	int res=0;
	register int i;
	if(r-l+1<3)
	{
		for(i=l;i<=r;i++)
			res=add(res,calc(i));
		return res;
	}
	for(i=l;i<=l+2;i++)
		f[i-l]=calc(i);
	// fprintf(stderr,"hhhh\n");
	for(i=l+1;i<=l+2;i++)
		f[i-l]=add(f[i-l],f[i-l-1]);
	lglr::n=4;
	lglr::x[1]=l;lglr::y[1]=0;
	for(i=l;i<=l+2;i++)
		lglr::x[i-l+2]=i+1,lglr::y[i-l+2]=f[i-l];
	// fprintf(stderr,"hhhh\n");
	// lglr::print();
	return sub(lglr::get(r+1),lglr::get(l));
}
signed main()
{
	int d;
	register int i,j;
	scanf("%d%d",&n,&t);
	for(i=1;i<=n;i++)
		scanf("%d%d",&c[i].x,&c[i].y);
	V.push_back(0);V.push_back(t+1);
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			if((d=(max(abs(c[i].x-c[j].x),abs(c[i].y-c[j].y))+1)/2)<=t)
			V.push_back(d);
	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());
	for(i=0;i<(int)V.size()-1;i++)
		ans=add(ans,solve(V[i],V[i+1]-1));
	// fprintf(stderr,"%d\n",ans);
	ans=sub(mul(t+1,calc(t)),ans);
	printf("%d\n",ans);
	return 0;
}


//...author:MAUNIE...//
#include<bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
	int n;
  cin >> n;
	cout << n * (n - 1) / 2 * 4 + 1 << '\n';
  return 0;
}
/


/* .................................................................................................................................. */

/** Header **/

#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <list>
#include <set>
#include <map>

using namespace std;

/** Repeat **/

#define REP(I, N) for (int I=0;I<int(N);++I)
#define FOR(I, A, B) for (int I=int(A);I<int(B);++I)
#define DWN(I, B, A) for (int I=int(B-1);I>=int(A);--I)
#define REP_1(I, N) for (int I=1;I<=int(N);++I)
#define FOR_1(I, A, B) for (int I=int(A);I<=int(B);++I)
#define DWN_1(I, B, A) for (int I=int(B);I>=int(A);--I)
#define REP_C(I, N) for (int N____=int(N),I=0;I<N____;++I)
#define FOR_C(I, A, B) for (int B____=int(B),I=A;I<B____;++I)
#define DWN_C(I, B, A) for (int A____=int(A),I=B-1;I>=A____;--I)
#define REP_1_C(I, N) for (int N____=int(N),I=1;I<=N____;++I)
#define FOR_1_C(I, A, B) for (int B____=int(B),I=A;I<=B____;++I)
#define DWN_1_C(I, B, A) for (int A____=int(A),I=B;I>=A____;--I)
#define DO(N) while(N--)
#define DO_C(N) int N____ = N; while(N____--)
#define TO(i, a, b) int s_=a<b?1:-1,b_=b+s_;for(int i=a;i!=b_;i+=s_)
#define TO_1(i, a, b) int s_=a<b?1:-1,b_=b;for(int i=a;i!=b_;i+=s_)
#define SQZ(I, J, A, B) for (int I=int(A),J=int(B)-1;I<J;++I,--J)
#define SQZ_1(I, J, A, B) for (int I=int(A),J=int(B);I<=J;++I,--J)

/** Micro Mezzo Macro Flation -- Overheated Economy **/

#define ALL(A) A.begin(), A.end()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define SRT(A) sort(ALL(A))
#define BSC(A, X) find(ALL(A), X) // != A.end()
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)

#define Rush int T____; RD(T____); DO(T____)
#pragma comment(linker, "/STACK:36777216")
#define Ruby system("ruby main.rb")
#define Haskell system("runghc main.hs")
#define Pascal system("fpc main.pas")

/** Typedef **/

typedef long long LL;
typedef double DB;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<DB> VD;
typedef set<int> SI;
typedef set<string> SS;
typedef set<LL> SL;
typedef set<DB> SD;
typedef map<int, int> MI;
typedef map<string, int> MS;
typedef map<LL, int> ML;
typedef map<DB, int> MD;
typedef pair<int, int> PII;
typedef pair<int, bool> PIB;
typedef vector<PII> VII;
typedef set<PII> SII;
typedef map<PII, int> MII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

/** I/O Accelerator **/

/* ... :" We are I/O Accelerator ... Use us at your own risk ;) ... " .. */

template<class T> inline void RD(T &x){
    //cin >> x;
    //scanf("%d", &x);
    char c; for (c = getchar(); c < '0'; c = getchar()); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';
    //char c; c = getchar(); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';

}

template<class T> inline void OT(const T &x){
    cout << x << endl;
    //printf("%d", x);
    //printf("%.2lf", x);
    //printf("Case %d: %d", ____T, ans)
}

template<class T> inline T& _RD(T &x){ RD(x); return x;}
inline int RD(){ int x; RD(x); return x;}
inline LL RD_LL(){ int x; RD(x); return x;}
inline DB RD_DB(){ DB x; RD(x); return x;}

template<class T0, class T1> inline void RD(T0 &x0, T1 &x1){RD(x0), RD(x1);}
template<class T0, class T1, class T2> inline void RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2);}
template<class T0, class T1, class T2, class T3> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);}

template<class T0, class T1> inline void OT(T0 &x0, T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(T0 &x0, T1 &x1, T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}

template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}

template<class T> inline void CLR(T &A){A.clear();}
template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}
template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}
template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}
template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}
//template<class T> inline void CLR_(T &A){REP}

template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2){FLC(A0), FLC(A1), FLC(A2);}
template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3){FLC(A0), FLC(A1), FLC(A2), FLC(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);}

/** Add - On **/

template<class T> inline void checkMin(T &a, T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a, T b){if (b>a) a=b;}
template<class T> inline T sqr(T x){return x * x;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}

/* .................................................................................................................................. */

const int MOD = 1000000007;
const int INF = 0x7fffffff;
const DB EPS = 1e-6;
const DB OO = 1e15;

const int N = 20000 + 5;

bool A[3], B[3], _B[3], B_[3];
int x[3], m[3], l[3], u[3];
int res;

void dfs(){

    int _i, i_;

/*
    if (x[0] == 10 && x[1] == 9){
        cout << _B[0] << " " << _B[1] << endl;
    }*/

    REP(i, 3) if (!_B[i]){

        if (i == 0) _i = 1, i_ = 2; else if (i == 1) _i = 0, i_ = 2; else _i = 0, i_ = 1;

        if (B[i] && !B_[i]){ // ����

            if (u[i] == i_) swap(_i, i_);

            B_[i] = true, _B[_i] = false;

            if (B[_i] && !B_[_i]){

                checkMax(res, x[i] + l[i] + l[_i] +  (A[i_] ? 0 : m[i_]));

            }

            else {

                int x_i = x[_i];

                FOR_1(j, -l[i], l[i]) if (j != 0){

                    int xx = x[i] + j;

                    if (x[i_] != xx && (abs(x[i_] - xx) == 1 || j == 1 || j == l[i])) {

                        checkMax(res, xx);

                        x[_i] = xx,

                        dfs();

                        x[_i] = x_i;

                    }

                }
            }

            _B[_i] = true, B_[i] = false;

        }
        else { // ���� ...

            if (!B[i]){

#define Grab(i_, d) if (!_B[i_] && x[i_] == x[i] + d) {x[i_] = x[i], B[i] = _B[i_] = true, u[i] = i_, dfs(), x[i_] = x[i] + d; B[i] = _B[i_] = false;}

                Grab(_i, -1); Grab(_i, 1); Grab(i_, -1); Grab(i_, 1);
            }

            if (!A[i]){ // ��· ..
                A[i] = true; int xi = x[i];
                FOR_1(j, -m[i], m[i]) if (j != 0){
                    int xx = xi + j;
                    if (x[_i] != xx && x[i_] != xx)
                        //(abs(x[_i] - xx) == 1 || abs(x[i_] - xx) == 1 || j == m[i] || j == -m[i])){
                        checkMax(res, xx); x[i] = xx, dfs(), x[i] = xi;
                    }
                }
                A[i] = false;
            }
        }
    }
}

int main(){

   // freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios::sync_with_stdio(false);

    REP(i, 3) RD(x[i], m[i], l[i]); res = max(x[0], x[1], x[2]);

    //x[0] = 10, x[1] = 9; x[2] = -18;
    //x[0] = 8, x[1] = 9, x[2] = -18;A[0] = true;

    dfs(); OT(res);
}


#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long ll;
int getint(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
#define N 112345
int a[2][2];
int b[2][2];
void calc(){
	if( a[ b[ a[0][1] ][ a[1][0] ] ][ a[ b[1][0] ][ a[0][0] ] ]==0) {
		for(int i=0;i<2;i++) for(int j=0;j<2;j++) cout<<i<<"*"<<j<<"=="<<a[i][j]<<endl;;
		for(int i=0;i<2;i++) for(int j=0;j<2;j++) cout<<i<<"+"<<j<<"=="<<b[i][j]<<endl;;
	}
	system("pause");
}
void dms(int i,int j){

	if(i==2&&j==2) calc();
	else if(i==2) dms(0,j+1);
	else for(int k=0;k<=1;k++) b[i][j]=k,dms(i+1,j);
}
void dfs(int i,int j){	//cout<<i<<" "<<j<<endl;
	if(i==2&&j==2) dms(0,0);
	else if(i==2) dfs(0,j+1);
 	else for(int k=0;k<=1;k++) a[i][j]=k,dfs(i+1,j);
}
/*
int operator *(int x,int y){
	return x^y;
}
int operator +(int x,int y){
	return x|y;
}
int operator -(int x,int y){
	return x&y;
}*/
int a[20]={1,0,0,0,1,0,1,0,2,1,1,2,0,1,0,0,0};
int main(){
	int n=getint(),ans=0;
	while(n) {
		ans+=a[n%16]; n/=16;
	}
	cout<<ans<<endl;
	return 0;
}


/*
  Nome: Mateus Barros Rodrigues
  NUSP: 7991037
  MAC0327 - 2o Sem 2015
  3a Aval
  Problema PXX - 181C - Trading Business
*/

#include <bits/stdc++.h>

using namespace std;

int n,m,k;

struct Prod{
  int buy,sell,quant;

  bool operator<(const Prod& p) const{
    return buy > p.buy;
  }
}products[2000];

Prod p[2000];

int main(){

  cin >> n >> m >> k;

  int aux = 0;
  for(int i = 0; i < n; i++){
    string bla;
    cin >> bla;
    for(int j = 0; j < m; j++){
      int a,b,c;
      cin >> a >> b >> c;
      products[i*m + j].buy = a;
      products[i*m + j].sell = b;
      products[i*m + j].quant = c;
    }
  }

  int sum = 0;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      if(i==j)continue;

      for(int x = 0; x < m; x++){
	p[x].buy = products[i*m + x].sell - products[j*m + x].buy;
	p[x].quant = products[j*m+x].quant;
      }

      sort(p,p+m);

      int capacity = k;
      int resp = 0;

      for(int x = 0; x < m; x++){
	if(p[x].buy < 0) break;
	int qt = min(capacity,p[x].quant);
	capacity -= qt;
	resp += qt*p[x].buy;
      }
    }
    sum = max(sum,resp);
  }

  cout << sum << endl;

  return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
const int N=500005,mn=1e9;
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T> using tr=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
int x,y,h[N],v[N],nxt[N],ec,p[N],sz[N],bb[N],tp[N],f[N],c[N],id[N],ct,po[N],n,k,d[N];
struct no{
	int x,y;
};
int operator <(no x,no y){
	return x.x<y.x||(x.x==y.x&&x.y<y.y);
}
tr<no>t[N];
no a[N];
decltype(begin(t[0]))d[N];
void add(int x,int y){v[++ec]=y;nxt[ec]=h[x];h[x]=ec;}
no operator +(no x,no y){
	return (no){min(x.y,max(x.x,y.x)),min(x.y,max(x.x,y.y))};
}
int rk(tr<no>x,int v){
	return x.order_of_key((no){v,mn});
}
int ck(int x,int v,int g){
	int a=rk(t[x],v)+g,b=((int)t[x].size())+1-a;
	return b-a<v;
}
void cg(int x,int &v,int g){
	while (ck(x,v-1,g))v--;
	while (!ck(x,v,g))v++;
}
no qu(int o,int l,int r,int x,int y){
	if (x<=l&&r<=y)return a[o];
	int md=(l+r)/2;
	if (x<=md&&y>md)return qu(o*2,l,md,x,y)+qu(o*2+1,md+1,r,x,y);
	if (x<=md)return qu(o*2,l,md,x,y);
	return qu(o*2+1,md+1,r,x,y);
}
void mod(int o,int l,int r,int x){
	if (l==r){
		int y=bb[l];
		if (d[y]==1&&y!=1){
			if (c[y])a[o]=(no){mn,mn};
			else a[o]=(no){-mn,-mn};
		}
		else{
			cg(y,a[o].x,1);
			cg(y,a[o].y,0);
		}
		return;
	}
	int md=(l+r)/2;
	if (x<=md)mod(o*2,l,md,x);
	else mod(o*2+1,md+1,r,x);
	a[o]=a[o*2]+a[o*2+1];
}
void d1(int x,int fa){
	sz[x]=1;
	for (int i=h[x];i;i=nxt[i])
		if (v[i]!=fa){
			d1(v[i],x);
			sz[x]+=sz[v[i]];
			if (sz[p[x]]<sz[v[i]])p[x]=v[i];
		}
}
void d2(int x,int fa,int tt){
	f[x]=fa;
	tp[x]=tt;
	id[x]=++ct;
	bb[ct]=x;
	if (p[x]){
		d2(p[x],x,tt);
		po[x]=po[p[x]];
	}
	else po[x]=id[x];
	for (int i=h[x];i;i=nxt[i])
		if (v[i]!=fa&&v[i]!=p[x]){
			d2(v[i],x,v[i]);
			d[v[i]]=t[x].insert((no){qu(1,1,n,id[v[i]],po[v[i]]).x,x}).first;
		}
	mod(1,1,n,id[x]);
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
		d[x]++;
		d[y]++;
	}
	for (int i=1;i<=n;i++)scanf("%d",&c[i]);
	d1(1,0);
	d2(1,0,1);
	int Q;
	scanf("%d",&Q);
	while (Q--){
		int opt;
		scanf("%d",&opt);
		if (opt==1){
			scanf("%d",&x);
			if (k>=qu(1,1,n,id[x],po[x]).x)puts("0");
			else puts("1");
		}
		else if (opt==2){
			int x,cl;
			x=rd();
			cl=rd();
			c[x]=cl;
			while(1){
				mod(1,1,n,id[x]);
				x=tp[x];
				if (x==1)break;
				t[f[x]].erase(d[x]);
				d[x]=t[f[x]].insert((no){qu(1,1,n,id[x],po[x]).x,x}).first;
				x=f[x];
			}
		}
		else scanf("%d",&k);
	}
}


using namespace std;
#define Int register int
#define MAXN 6005
int n,len,belong[MAXN];
void read (int &x)
{
    x = 0;char c = getchar();
    while (c < '0' || c > '9');
    while (c >= '0' && c <= '9')x = (x << 3) + (x << 1) + c - '0',c = getchar();
    return ;
}
void write (int x)
{
    if (x < 0){x = -x;putchar ('-');}
    if (x > 9) write (x / 10);
    putchar (x % 10 + '0');
}
bool zs (int n)
{
    if (n == 1 || n == 0) return 0;
    for (Int i = 2;i * i <= n;++ i)
        if (n % i == 0) return 0;
    return 1;
}
void Work (int tot,bool flag)
{
    if (flag) tot -= 3,belong[3] = 3;
    int ans1 = 0;
    for (Int i = 2;i <= n;++ i)
        if (zs (i) && zs (tot - i))
        {
            belong[i] = 1;
            break;
        }
    for (Int i = 1;i <= n;++ i)
        if (belong[i]) write (belong[i]),putchar (' ');
        else write (2),putchar (' ');
    putchar ('\n');
    exit (0);
}
signed main()
{
    read(n);
    if (n < 5)
    {
        else if (n == 2)
            printf ("1 1\n");
        else if (n == 3)
            printf ("1 1 2\n");
        else if (n == 4)
            printf ("1 1 2 2\n");
        return 0;
    }
    int tot =n*(n + 1)>>1;
    if (zs(tot-2))
    {
        for (Int i = 1;i <= n;++ i)
            if (i == 2) write (2),putchar (' ');
            else write (1),putchar (' ');
        putchar('\n');
        return 0;
    }
    return Work (tot,tot%2),0;
}


#include <bits/stdc++.h>

#ifdef DEBUG
    #include </home/hdd/cp/lib/debug.hpp>
#else
    #define dbg( ... )
#endif

using namespace std;

#if __cplusplus >= 202002L
    namespace rg = ranges;
    namespace rv = ranges::views;
    auto rep( auto x, auto y ) { return rg::iota_view( x, y ); }
#endif

template< const int &MOD >
struct ModInt {
public:
    int val {};

public:
    ModInt( int64_t v = 0 ) {
        if( v < 0 )
            v = v % MOD + MOD;

        if( v >= MOD )
            v %= MOD;

        val = static_cast< int >( v );
    }

    ModInt( uint64_t v ) {
        if( v >= 0 )
            v %= MOD;

        val = static_cast< int >( v );
    }

    ModInt( int v ) : ModInt( static_cast< int64_t >( v ) ) {}
    ModInt( unsigned v ) : ModInt( static_cast< uint64_t >( v ) ) {}

public:
    explicit operator int() const { return val; }
    explicit operator unsigned() const { return val; }
    explicit operator int64_t() const { return val; }
    explicit operator uint64_t() const { return val; }
    explicit operator double() const { return val; }
    explicit operator long double() const { return val; }

    ModInt& operator+=( const ModInt &oth ) {
        val -= MOD - oth.val;
        if( val < 0 )
            val += MOD;

        return *this;
    }

    ModInt& operator-=( const ModInt &oth ) {
        val -= oth.val;
        if( val < 0 )
            val += MOD;

        return *this;
    }

    static unsigned fast_mod( uint64_t x, unsigned m = MOD ) {
#if !defined( _WIN32 ) || defined( _WIN64 )
        return static_cast< unsigned >( x % m );
#endif

        unsigned xHigh { static_cast< unsigned >( x >> 32 ) };
        unsigned xLow { static_cast< unsigned >( x ) };
        unsigned quot, rem;

        asm( "divl %4\n" : "=a" ( quot ), "=d" ( rem ) : "d" ( xHigh ), "a" ( xLow ), "r" ( m ) );
        return rem;
    }

    ModInt& operator*=( const ModInt &oth ) {
        val = fast_mod( static_cast< unsigned >( val ) * oth.val );
        return *this;
    }

    ModInt& operator/=( const ModInt &oth ) {
        return *this *= oth.inv();
    }

    friend ModInt operator+( const ModInt &a, const ModInt &b ) {
        return static_cast< ModInt >( a ) += b;
    }

    friend ModInt operator-( const ModInt &a, const ModInt &b ) {
        return static_cast< ModInt >( a ) -= b;
    }

    friend ModInt operator*( const ModInt &a, const ModInt &b ) {
        return static_cast< ModInt >( a ) *= b;
    }

    friend ModInt operator/( const ModInt &a, const ModInt &b ) {
        return static_cast< ModInt >( a ) /= b;
    }

    ModInt& operator++() {
        val = ( val == MOD - 1 ? 0 : val + 1 );
        return *this;
    }

    ModInt& operator--() {
        val = ( val == 0 ? MOD - 1 : val - 1 );
        return *this;
    }

    ModInt operator++( int ) {
        ModInt before { *this };
        ++*this;
        return before;
    }

    ModInt operator--( int ) {
        ModInt before { *this };
        --*this;
        return before;
    }

    ModInt operator-() const {
        return val == 0 ? 0 : MOD - val;
    }

    friend bool operator==( const ModInt &a, const ModInt &b ) { return a.val == b.val; }
    friend bool operator!=( const ModInt &a, const ModInt &b ) { return a.val != b.val; }
    friend bool operator<( const ModInt &a, const ModInt &b ) { return a.val < b.val; }
    friend bool operator>( const ModInt &a, const ModInt &b ) { return a.val > b.val; }
    friend bool operator<=( const ModInt &a, const ModInt &b ) { return a.val <= b.val; }
    friend bool operator>=( const ModInt &a, const ModInt &b ) { return a.val >= b.val; }

public:
    static const int SAVE_INV { static_cast< int >( 1e6 ) + 5 };
    static ModInt saveInv[SAVE_INV];

    static void prepare_inv() {
        for( int64_t p { 2 }; p * p <= MOD; p += ( p & 1 ) + 1 )
            assert( !( MOD % p ) );

        saveInv[0] = 0;
        saveInv[1] = 1;

        for( int i { 2 }; i < SAVE_INV; ++i )
            saveInv[i] = saveInv[MOD % i] * ( MOD - MOD / i );
    }

    ModInt inv() const {
        if( !saveInv[1] )
            prepare_inv();

        if( val < SAVE_INV )
            return saveInv[val];

        ModInt prod { 1 };
        int v { val };

        do {
            prod *= ( MOD - MOD / v );
            v = MOD % v;
        } while( v >= SAVE_INV );

        return prod * saveInv[v];
    }

    ModInt pow( int64_t p ) const {
        if( p < 0 )
            return inv().pow( -p );

        ModInt a { *this }, res { 1 };

        while( p ) {
            if( p & 1 )
                res *= a;

            p >>= 1;
            if( p )
                a *= a;
        }

        return res;
    }

    friend ostream& operator<<( ostream &os, const ModInt &mod ) {
        return os << mod.val;
    }
};

template< const int &MOD > ModInt< MOD > ModInt< MOD >::saveInv[ModInt< MOD >::SAVE_INV];

int MOD { static_cast< int >( 1e9 ) + 7 };
using mod_int = ModInt< MOD >;

inline void run_case() {
    int N;
    cin >> N >> MOD;

    vector< mod_int > dp( N + 1 );
    dp[1] = 1;
    int pref { 1 };

    for( int i : rep( 2, N + 1 ) ) {
        dp[i] = sum;

        for( int j { 1 }; j * j <= i; ++j ) {
            dp[i] += ( dp[j] * mod_int( i / j - i / ( j + 1 ) ) );

            if( i / j != j && j > 1 )
                dp[i] += dp[i / j];
        }

        sum += dp[i];
    }

    cout << dp[N] << endl;
}

int32_t main() {
    ios::sync_with_stdio( false );
    cin.tie( nullptr );

    int T { 1 };
    //cin >> T;

    for( int test { 1 }; test <= T; ++test ) {
        //cout << "Case #" << ": ";
        run_case();
    }
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <stack>

int main()
{
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for (llong i = 0; i <= 100000000; i++) {
		if ((i / k) * (i % k) == n) {
			cout << i;
			break;
		}
	}
	return(0);
}


#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

vector<int> next[64];
vector<int> cost[64];
vector<int> candies;
bool visited[64];
int n, k;

bool solve(int time, int currNode, int toEat) {
    // cout << time << "  " << currNode << "  " << toEat << endl; ///////////
    if (time < 0) {
        return false;
    }

    toEat -= candies[currNode];
    if (toEat <= 0) {
        return true;
    }

    visited[currNode] = true;
    bool res = false;
    for (int i = 0; i < next[currNode].size() && !res; ++i) {
        int nextNode = next[currNode][i];
        if (visited[nextNode]) {
            continue;
        }
        res = solve(time - cost[currNode][i], nextNode, toEat);
    }
    visited[currNode] = false;
    return res;
}

int main() {
    int s, sum = 0;
    cin >> n >> s >> k;
    s--;
    candies.resize(n + 1);
    for (int i = 0; i < n; ++i) {
        cin >> candies[i];
        sum += candies[i];
    }

    candies[n] = 0;
    string colors;
    cin >> colors;
    if (sum < k) {
        cout << -1 << endl;
        return 0;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i == j) {
                continue;
            }

            if (colors[i] == colors[j]) {
                continue;
            }

            if (candies[i] <= candies[j]) {
                continue;
            }

            next[i].push_back(j);
            cost[i].push_back(abs(i - j));
        }
    }

    for (int i = 0; i < n; ++i) {
        next[n].push_back(i);
        cost[n].push_back(abs(i - s));
    }

    int l = 0, r = n * n;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (solve(mid, n, k)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    if (!solve(r, n, k)) {
        cout << -1 << endl;
    } else {
        cout << r << endl;
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <iostream>
#include <cstring>
#include <bitset>
#include <ctime>
#include <functional>
#include <numeric>
#include <random>

typedef int64_t LL;
typedef uint64_t uLL;
typedef __int128_t sLL;
#define fir first
#define sec second
#define eb emplace_back
#define em emplace
#define pb pop_back
#define pii std::pair<int, int>
#define mkp(a, b) std::make_pair(a, b)
#define bitcount(x) __builtin_popcount(x)
#define bitcountll(x) __builtin_popcountll(x)
#define bitparity(x) __builtin_parity(x)
#define bitparityll(x) __builtin_parityll(x)

int read() {
    int s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

LL readl() {
    LL s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

///////////////////////////////////// wanna become a grandmaster

// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/hash_policy.hpp>
// using namespace __gnu_pbds;
// using rbtree = tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update> ;
// order_of_key() rank (return int) start from 0
// find_by_order() kth (return iterator) start from 0

/*
    读入是否需要开LL？
*/

const int maxn = 5e4 + 10;
const int MOD = 998244353;

int n, m;
int a[maxn][maxn];
int nxt[1030][10];

void add(int &v1, int v2) {
    v1 += v2;
    if (v1 > MOD) v1 -= MOD;
}

int main() {
    n = read();
    m = read();
    for (int i = 1 ; i <= m ; i++ ) {
        int u = read(), v = read();
        a[u][v] = a[v][u] = 1;
    }
    for (int s = 0 ; s < (1 << 10) ; s++ ) {
        for (int i = 0 ; i < 10 ; i++ ) {
            if (s & (1 << i)) {
                nxt[s][i] = (1 << i);
                for (int j = 0 ; j < i ; j++ ) {
                    if (!a[i][j]) {
                        nxt[s][i] |= (1 << j);
                    } else {
                        if (s & (1 << j)) nxt[s][i] |= (1 << j);
                    }
                }
                for (int j = i + 1 ; j < 10 ; j++ ) {
                    if (!a[i][j]) {
                        nxt[s][i] |= (1 << j);
                    }
                }
            }
        }
    }
    std::vector<int> dp(1 << 10, 0);
    dp[(1 << 10) - 1] = 1;
    for (int i = 1 ; i <= n ; i++ ) {
        std::vector<int> dp2(1 << 10, 0);
        for (int s = 0 ; s < (1 << 10) ; s++ ) {
            for (int j = 0 ; j < 10 ; j++ ) {
                if (s & (1 << j)) {
                    add(dp2[nxt[s][j]], dp[s]);
                }
            }
        }
        std::swap(dp, dp2);
    }
    int ans = 0;
    for (const auto &val : dp) {
        add(ans, val);
    }
    printf("%d\n", ans);
    return 0;
}


#include<bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
int main()
int a[10000];
{
    int n,k;
    cin>>n>>k;
    forinc(i,1,n) cin>>a[i];
    int res=0,l=0;
    forinc(i,1,n)
    {
        if(a[i]<=k) kq++;
        l=i;
        else break;
    }
    fordec(i,n,l+1)
    {
        if(a[i]<=k) kq++;
        else break;
    }
    cout<<kq;
}


#include <iostream>

using namespace std;

int main()
{
    int a, c, ad[20] = {0}, an(0), cd[20] = {0}, cn(0);
    cin >> a >> c;

    while (a != 0)
    {
        ad[an++] = a % 3;
        a /= 3;
    }

    while (c != 0)
    {
        cd[cn++] = c % 3;
        c /= 3;
    }

    int tor(0);
    for (int i = max(an, cn) - 1; i >= 0; --i)
    {
        tor = tor * 3 + (cd[i] + 3 - ad[i]) % 3;
    }
    cout << tor << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include <set>
#include <queue>

using namespace std;

typedef pair<int, int> PP;
typedef pair<long long, long long> LPP;
typedef long long LL;
#define INF 1000000000LL
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
const int mod = 1000000007;

int bits[1 << 20], p[1 << 20];
int n, l, r, x[50], y[50], a[50];
bool cmp(int & x, int & y){
	return bits[x] < bits[y];
}

double q[1 << 20];
double pi = acos(-1);

double f(double b, int k){
	if (a[k] == 0) return 0;
	if (b - x[k] >= tan((90 - a[k]) * pi / 180) * y[k]) return r;
	if (a[k] == 90) return y[k]*y[k]*1.0/(x[k] - b);
	double t = tan(a[k] * pi / 180);
	return x[k] + y[k] * ((t - (x[k] - b)/y[k])/(1 + t * (x[k] - b)/y[k]));
}

int main() {
	#ifdef _TEST_
	freopen("input.txt", "r", stdin);
	#endif
	cin >> n >> l >> r; r -= l;
	int u, v, d;
	memset(bits, 0, sizeof(bits));
	for (int i = 0; i < 1 << n; i ++)
		bits[i] += bits[i - (i & -i)], p[i] = i;
	sort(p, p + n, cmp);

	for (int i = 0; i < n; i ++){
		cin >> u >> v >> d;
		x[i] = u - l; y[i] = abs(v); a[i] = d;
	}
	memset(q, 0, sizeof(q));
	for (int i = 1; i < 1 << n; i ++){
		int t = p[i];
		for (int j = 0; j < n; j ++)
			if ((t >> j) & 1) {
				q[t] = max(q[t], min((double)r, q[t - (1 << j)] + f(q[t - (1 << j)], j)));
			}
	}

	cout << setprecision(9) << fixed << q[(1 << n) - 1] << endl;
	return 0;

}


#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define md(l, r) l + (r - l) / 2
#define ll long long
#define btw(a, l, r) a.begin() + l, a.begin() + r + 1
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int(x.size()))
#define sqr(x) (x) * (x)
#define endl '\n'

#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define clr(x, y) memset((x), (y), sizeof (x))
#define ld long double
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<vector<pair<int, int> > > vvpii;
typedef vector<vector<pair<ll, ll> > > vvpll;
typedef pair<int, pair<int, int> > piii;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef vector<vector<ll> > vvll;
typedef vector<pair<ll, pair<ll, ll> > > vplll;
typedef pair<ll, ll> pll;

const ld eps = -1e9;
const long long N = 200001, P = 1e9 + 7, P1 = 1e9 + 13, iINF = 1e9, INF = 2e18, K = 73, K1 = 79;

ll dstF(ll x, ll y, ll xx, ll yy) {
    return (sqr(x - xx) + sqr(y - yy));
}

ld dstSqrtF(ll x, ll y, ll xx, ll yy) {
    return (sqrt(sqr(x - xx) + sqr(y - yy)));
}

ll _bp(ll val, ll st, ll p) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2, p);
    temp = sqr(temp);
    temp %= p;
    if (st % 2 == 1) {
        temp *= val;
        temp %= p;
    }
    return temp;
}

ll _bp(ll val, ll st) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2);
    temp = sqr(temp);
    if (st % 2 == 1) {
        temp *= val;
    }
    return temp;
}

ll nok(ll a, ll b) {
    return (a / __gcd(a, b) * b);
}

#define int long long

int n, ans = 1e18;
int st[100], dp[100];

void solve() {
    cin >> n;
    int n1 = n;
    int k = 0;
    while (n1 != 0) {
        k++;
        n1 /= 10;
    }
    int tp = n;
    st[0] = 1;
    for (int i = 1; i <= k + 1; i++) {
        st[i] = st[i - 1] * 10 + 1;
    }
    k++;
    multiset<int> s;
    s.insert({0, tp});
    d[tp] = 0;
    while (!s.empty()) {
        int x = s.begin()->S;
        int x1 = x, cnt = 0;
        while (x1 != 0) {
            cnt++;
            x1 /= 10;
        }
        if (abs(x1 - st[cnt + 1]) <= st[cnt + 1]) {
            if (dp.find(abs(x1 - st[cnt + 1])) == dp.end() || dp[abs(x1 - st[cnt + 1])] > dp[x] + cnt + 1) {
                s.erase({dp[abs(x1 - st[cnt + 1])], abs(x1 - st[cnt + 1])});
                dp[abs(x1 - st[cnt + 1])] = dp[x] + cnt + 1;
                s.insert({dp[abs(x1 - st[cnt + 1])], abs(x1 - st[cnt + 1])});
            }
        }
    }
}

signed main() {
    fast_io;
    int q;
    q = 1;
    //cin >> q;
    while (q != 0) {
        solve();
        --q;
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define TAM				100//500100
#define SZ				2
#define NBUCKETS		(TAM/SZ+2)

ll a[TAM];
ll lazy[NBUCKES];
unordered_map<ll, int> first[NBUCKETS], last[NBUCKETS];

void update (

int main ( )
{
	return 0;
}


#include <cstdio>
int h,m,k,h1,m1,h2,m2;
long long cut(int a,int b){for(;--b>0;a/=10);return a;}
int ch(int a){for(int ret=0;;a/=10)if(a%10)ret++;else if(!a)return ret;}
long long calc(int a,int b){return cut(a,k-ch(m-1))+cut(m-1,k)*a+cut(b,k);}
int main(){
  scanf("%d%d%d%d%d%d%d",&h,&m,&k,&h1,&m1,&h2,&m2);
  if(h1<h2||(h1==h2&&m1<=m2)) printf("%lld\n",calc(h2,m2)-calc(h1,m1));
  else printf("%lld\n",calc(h-1,m-1)+(ch(h-1)+ch(m-1)>=k)-calc(h1,m1)+calc(h2,m2));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

//c++ templte for help.......................................................................................................................................................

typedef long long ll;

template<typename... T>
void print1(T... t){
    ((cerr<<t<<" "),...);
}

template<typename... T>
void print2(T... t){
        vector<vector<ll>> ans={t...};
        for(ll i=0;i<(ll)ans.size();i++){
            if(i!=0) cerr<<"\t\t";
            else cerr<<"\t";
            for(ll j=0;j<(ll)ans[i].size();j++){
                cerr<<ans[i][j]<<" ";
            }
            if(i!=(ll)ans.size()-1)
            cerr<<endl;
        }
}
#define deb(...) {cerr<<" [ "#__VA_ARGS__<<" : "; print1(__VA_ARGS__); cerr<<"]"<<endl; }
#define vdeb(...) {cerr<<" [ "#__VA_ARGS__<<" : "; print2(__VA_ARGS__); cerr<<"]"<<endl;}

// to return everything in string
#define ret(...) {stringstream returnn;returnn<<__VA_ARGS__;return returnn.str();}

stringstream retvec;
template<typename... T>
void returnvector(T... t){
        vector<vector<ll>> ans={t...};
        for(ll i=0;i<(ll)ans.size();i++){
            for(ll j=0;j<(ll)ans[i].size();j++){
                retvec<<ans[i][j];
                if(j!=(ll)ans[i].size()-1)
                    retvec<<" ";
            }
            if(i!=(ll)ans.size()-1)
                retvec<<endl;
        }
}
#define vret(...) {retvec.clear();returnvector(__VA_ARGS__);return retvec.str();}

//for loop
#define fo(i,n) for(int i=0;i<(ll)n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)

//to print vector element
template<typename T>
void printV(T vec){
    fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
    cout<<endl;
    }

#define M ll(998244353)
const ll INF=ll(1e9+5);

//iterate map
template<typename T>
void itR(T map){
     for(auto itr=map.begin();itr!=map.end();itr++){
                deb(itr->first,itr->second);
            }
    cout<<endl;
}

typedef tree<
ll,
null_type,
greater<int>,
rb_tree_tag,
tree_order_statistics_node_update>
pods;

//c++ template for help.....................................................................................................................................................

string solve(){
	// CALM DOWN : - )

	string s;
	cin>>s;

	ll i=0;
	ll ans=0;
	while(i<=(ll)s.size()-2 and s.find("VK",i)!=string::npos){
		i=s.find("VK",i)+1;
		s[i]='0';
		s[i+1]='0';
		ans++;
	}

	if(s.size>=2 and (s.find("VV")!=string::npos or s.find("VV")!=string::npos)){
		ans++;
	}

	ret(ans);

ret("");
}

int main() {
    cout<<setprecision(10);
    ios::sync_with_stdio(0);
    cin.tie(0);

    //ll testCase;
    //cin>>testCase;
    //for(ll tt=0;tt<testCase;tt++){
        string ans1=solve();
        if(ans1!="")
            cout<<ans1<<endl;
    //}
    return 0;
}


#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
using namespace std;
const int N = 1 << 20;
int mod;
namespace yg {

int fac[123], cnt, omg, omk;
void getfac(int x) {
	for(int i = 2; i <= sqrt(x); i++)
		if(x % i == 0) {
			fac[++cnt] = i;
			while(x % i == 0) x /= i;
		}
}
int qpow(int x, int y, int pmod) {
	int res = 1;
	if(x == 0) return 0;
	for(; y; x = 1ll * x * x % pmod, y >>= 1) if(y & 1) res = 1ll * res * x % pmod;
	return res;
}
bool cheak(int x) {
	for(int i = 1; i <= cnt; i++)
		if(qpow(x, (mod - 1) / fac[i], mod) == 1) return 0;
	return 1;
}
int find() {
	getfac(mod - 1);
	for(int i = 2; i < mod; i++)
		if(cheak(i)) {
			return i;
		}
	return -1;
}

}
int _G;

#define add(a, b) (a + b >= mod ? a + b - mod : a + b)
#define dec(a, b) (a < b ? a - b + mod : a - b)
int qpow(int x, int y = mod - 2) {
	int res = 1;
	for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
	return res;
}
int fac[N], ifac[N], inv[N];
void init(int x) {
	fac[0] = ifac[0] = inv[1] = 1;
	L(i, 2, x) inv[i] = (ll) inv[mod % i] * (mod - mod / i) % mod;
	L(i, 1, x) fac[i] = (ll) fac[i - 1] * i % mod, ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
}
int C(int x, int y) {
	return y < 0 || x < y ? 0 : (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int rt[N], Lim;
void Pinit(int x) {
	for(Lim = 1; Lim <= x; Lim <<= 1) ;
	for(int i = 1; i < Lim; i <<= 1) {
		int sG = qpow (_G, (mod - 1) / (i << 1));
		rt[i] = 1;
		L(j, i + 1, i * 2 - 1) rt[j] = (ll) rt[j - 1] * sG % mod;
	}
}
struct poly {
	vector<int> a;
	int size() { return sz(a); }
	int & operator [] (int x) { return a[x]; }
	int v(int x) { return x < 0 || x >= sz(a) ? 0 : a[x]; }
	void clear() { vector<int> ().swap(a); }
	void rs(int x = 0) { a.resize(x); }
	poly (int n = 0) { rs(n); }
	poly (vector<int> o) { a = o; }
	poly (const poly &o) { a = o.a; }
	poly Rs(int x = 0) { vi res = a; res.resize(x); return res; }
	inline void dif() {
		int n = sz(a);
		for (int l = n >> 1; l >= 1; l >>= 1)
			for(int j = 0; j < n; j += l << 1)
				for(int k = 0, *w = rt + l; k < l; k++, w++) {
					int x = a[j + k], y = a[j + k + l];
					a[j + k] = add(x, y);
					a[j + k + l] = (ll) * w * dec(x, y) % mod;
				}
	}
	void dit () {
		int n = sz(a);
		for(int i = 2; i <= n; i <<= 1)
			for(int j = 0, l = (i >> 1); j < n; j += i)
				for(int k = 0, *w = rt + l; k < l; k++, w++) {
					int pa = a[j + k], pb = (ll) a[j + k + l] * *w % mod;
					a[j + k] = add(pa, pb), a[j + k + l] = dec(pa, pb);
				}
		reverse(a.begin() + 1, a.end());
		for(int i = 0, iv = qpow(n); i < n; i++) a[i] = (ll) a[i] * iv % mod;
	}
	friend poly operator * (poly aa, poly bb) {
		if(!sz(aa) || !sz(bb)) return {};
		int lim, all = sz(aa) + sz(bb) - 1;
		for(lim = 1; lim < all; lim <<= 1);
		aa.rs(lim), bb.rs(lim), aa.dif(), bb.dif();
		L(i, 0, lim - 1) aa[i] = (ll) aa[i] * bb[i] % mod;
		aa.dit(), aa.a.resize(all);
		return aa;
	}
	poly Inv() {
		poly res, f, g;
		res.rs(1), res[0] = qpow(a[0]);
		for(int m = 1, pn; m < sz(a); m <<= 1) {
			pn = m << 1, f = res, g.rs(pn), f.rs(pn);
			for(int i = 0; i < pn; i++) g[i] = (*this).v(i);
			f.dif(), g.dif();
			for(int i = 0; i < pn; i++) g[i] = (ll) f[i] * g[i] % mod;
			g.dit();
			for(int i = 0; i < m; i++) g[i] = 0;
			g.dif();
			for(int i = 0; i < pn; i++) g[i] = (ll) f[i] * g[i] % mod;
			g.dit(), res.rs(pn);
			for(int i = m; i < min(pn, sz(a)); i++) res[i] = (mod - g[i]) % mod;
		}
		return res.rs(sz(a)), res;
	}
	poly Shift (int x) {
		poly zm (sz(a) + x);
		L(i, 0, sz(a) - 1) zm[i + x] = a[i];
		return zm;
	}
	friend poly operator * (poly aa, int bb) {
		poly res(sz(aa));
		L(i, 0, sz(aa) - 1) res[i] = (ll) aa[i] * bb % mod;
		return res;
	}
	friend poly operator + (poly aa, poly bb) {
		vector<int> res(max(sz(aa), sz(bb)));
		L(i, 0, sz(res) - 1) res[i] = add(aa.v(i), bb.v(i));
		return poly(res);
	}
	friend poly operator - (poly aa, poly bb) {
		vector<int> res(max(sz(aa), sz(bb)));
		L(i, 0, sz(res) - 1) res[i] = dec(aa.v(i), bb.v(i));
		return poly(res);
	}
	poly & operator += (poly o) {
		rs(max(sz(a), sz(o)));
		L(i, 0, sz(a) - 1) (a[i] += o.v(i)) %= mod;
		return (*this);
	}
	poly & operator -= (poly o) {
		rs(max(sz(a), sz(o)));
		L(i, 0, sz(a) - 1) (a[i] += mod - o.v(i)) %= mod;
		return (*this);
	}
	poly & operator *= (poly o) {
		return (*this) = (*this) * o;
	}
	poly Integ() {
		if(!sz(a)) return poly();
		poly res(sz(a) + 1);
		L(i, 1, sz(a)) res[i] = (ll) a[i - 1] * inv[i] % mod;
		return res;
	}
	poly Deriv() {
		if(!sz(a)) return poly();
		poly res(sz(a) - 1);
		L(i, 1, sz(a) - 1) res[i - 1] = (ll) a[i] * i % mod;
		return res;
	}
	poly Ln() {
		poly g = ((*this).Inv() * (*this).Deriv()).Integ();
		return g.rs(sz(a)), g;
	}
	poly Exp() {
		poly res(1), f;
		res[0] = 1;
		for(int m = 1, pn; m < sz(a); m <<= 1) {
			pn = min(m << 1, sz(a)), f.rs(pn), res.rs(pn);
			for(int i = 0; i < pn; i++) f[i] = (*this).v(i);
			f -= res.Ln(), (f[0] += 1) %= mod, res *= f, res.rs(pn);
		}
		return res.rs(sz(a)), res;
	}
	poly pow(int x, int rx = -1) { // x : the power % mod; rx : the power % (mod - 1)
		if(rx == -1) rx = x;
		int cnt = 0;
		while (a[cnt] == 0 && cnt < sz(a)) cnt += 1;

		poly res = (*this);
		L(i, cnt, sz(a) - 1) res[i - cnt] = res[i];
		L(i, sz(a) - cnt, sz(a) - 1) res[i] = 0;
		int c = res[0], w = qpow (res[0]);
		L(i, 0, sz(res) - 1) res[i] = (ll) res[i] * w % mod;
		res = res.Ln();
		L(i, 0, sz(res) - 1) res[i] = (ll) res[i] * x % mod;
		res = res.Exp();
		c = qpow (c, rx);
		L(i, 0, sz(res) - 1) res[i] = (ll) res[i] * c % mod;

		if((ll) cnt * x > sz(a)) L(i, 0, sz(a) - 1) res[i] = 0;
		else if(cnt) {
			R(i, sz(a) - cnt * x - 1, 0) res[i + cnt * x] = res[i];
			L(i, 0, cnt * x - 1) res[i] = 0;
		}
		return res;
	}
	void Rev() {
		reverse(a.begin(), a.end());
	}
} ;

int n;

poly Get(poly A) {
	int n = sz(A);
	L(i, 1, n - 1) A[i] = (mod - A[i]) % mod;
	A[0] = 1;
	A = A.Ln();
	L(i, 1, n - 1) A[i] = (mod - A[i]) % mod;
	return A;
}

int f[N];
int xg[N];
int main () {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> mod;
//	cin >> n;
//	mod = 998244353;
	_G = yg :: find();
	init(1 << 18);
	Pinit(1 << 18);

	poly f(n + 1), g(n + 1);
	f[1] = 1, xg[0] = 1, xg[1] = 1;
	L(i, 2, n) {
//		L(j, 0, i - 1) (xg[i] += (ll) f[i - j] * xg[j] % mod) %= mod;
//		xg[i] = (ll) xg[i] * inv[i] % mod;
		poly ns(n + 1);
		L(j, 1, i - 1)
			ns += f.pow(j) * ifac[j - 1];
		f[i] = ns[i - 1];
//		L(j, 1, i)
//			(f[i] += (ll) f[j] * xg[i - j] % mod) %= mod;
	}
	/* F = x * (F * EXP(F) + 1), a dc fft could work */

//	L(i, 1, n) {
//		cout << i << " : " << (ll) f[i] * fac[i] % mod << '\n';
//	}
//	cout << '\n';

	L(i, 1, n) g[i] = f[i];
	g = g.Exp();
	R(i, n, 1) g[i] = g[i - 1];
	g[0] = 0;

//	L(i, 0, n)
//		cout << (ll) g[i] * fac[i] % mod << ",";
//	cout << '\n';

	f[1] = 0;
	poly h(n + 1);
	L(i, 1, n)
		h[i] = (f[i - 1] + g[i - 1]) % mod;

//	cout << "h : ";
//	L(i, 0, n) cout << h[i] << ",";
//	cout << '\n';

	f = Get(h + f + g) - Get(g) - f;
	f = f.Exp();
	cout << (ll) f[n] * fac[n] % mod << '\n';
	return 0;
}


#include <iostream>
#include <cstdio>

#include <utility>

#include <cassert>
#include <ctime>
#include <iomanip>

using namespace std;

const int MAXN = 1e5 + 100;

typedef long long ll;
#define tll(x) static_cast<ll>(x)

typedef pair<int, int> pii;
#define mp make_pair
#define ff first
#define ss second

int N, root;

const int MAXS = MAXN * 1000;
struct PBT {
public:
  int c[MAXS][2], v[MAXS], sz[MAXS], h[MAXS];
  int NXT;
  PBT() : NXT(1) {v[0] = -1, sz[0] = 0, h[0] = 0;};
  int upd(int n) {
    if(not(0 < n)) return n;
    sz[n] = sz[c[n][0]] + sz[c[n][1]] + 1;
    h[n] = max(h[c[n][0]], h[c[n][1]]) + 1;
    assert(n != c[n][0] and n != c[n][1]);
    return n;
  }
  int gsz(int n) {
    if(n == 0) return 0;
    return gsz(c[n][0]) + gsz(c[n][1]) + 1;
  }
  void asst(int n) {assert(gsz(n) == sz[n]);}
  int nn(const int& n = -1) {
    if(n == 0) return 0;
    if(0 < n) {
      for(int i = 0;i < 2;i++) c[NXT][i] = c[n][i];
      v[NXT] = v[n];
    } else {
      for(int i = 0;i < 2;i++) c[NXT][i] = 0;
      v[NXT] = -1;
    }
    upd(NXT);
    return NXT++;
  }
  int nnr(const int& q) {
    int n = nn();
    v[n] = q;
    return n;
  }
  int L(int& n, int p = 0) {
    assert(c[n][1]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][1]); else n = c[n][1];
    c[o][1] = c[n][0];
    upd(c[n][0] = o);
    return upd(n);
  }
  int R(int& n, int p = 0) {
    assert(c[n][0]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][0]); else n = c[n][0];
    c[o][0] = c[n][1];
    upd(c[n][1] = o);
    return upd(n);
  }
  bool bal(int& n, bool p = false) {   //here, we assume that n is already a copy
    int q = NXT;
    int b = h[c[n][0]] - h[c[n][1]], s, o = n;
    if(b < -1) {
      assert(s = c[n][1]);
      if(h[c[s][1]] + 1 == h[s]) {
        L(n, p ? 1 : 0);
      } else if(h[c[s][0]] + 1 == h[s]) {
        R(c[n][1], p ? 2 : 0);
        L(n, 0);
      } else assert(false);
    }
    else if(b > 1) {
      assert(s = c[n][0]);
      if(h[c[s][0]] + 1 == h[s]) {
        R(n, p ? 1 : 0);
      } else if (h[c[s][1]] + 1 == h[s]) {
        L(c[n][0], p ? 2 : 0);
        R(n, 0);
      } else assert(false);
    }
    else return false;
    return true;
  }
  int join(int a, int b, bool p = true) {  //here we assume a and b are already copies
    if(a == 0 or b == 0) return a ? a : b;
    if(h[a] < h[b]) {
      c[b][0] = join(a, p ? nn(c[b][0]) : c[b][0], p);
      upd(b);
      bal(b, p);
      return b;
    } else {
      c[a][1] = join(p ? nn(c[a][1]) : c[a][1], b, p);
      upd(a);
      bal(a, p);
      return a;
    }
  }
  int join2(int l, int m, int r) {    //assume all are copies, merges L and R at M
    if(h[l] + 1 < h[r]) {c[r][0] = join2(l, m, nn(c[r][0])); return upd(r);}
    if(h[r] + 1 < h[l]) {c[l][1] = join2(nn(c[l][1]), m, r); return upd(l);}
    c[m][1] = r;
    c[m][0] = l;
    upd(m);
    bal(m, 1);
    return m;
  }
  pii split(int a, int k) {   //always create new nodes, assume a is NOT a copy
    if(k == 0) return mp(0, nn(a));
    assert(0 < k);
    if(sz[c[a][0]] < k) {
      pii q = split(c[a][1], k - sz[c[a][0]] - 1);
      int r = join2(nn(c[a][0]), nnr(v[a]), q.ff);
      return mp(r, q.ss);
    } else {
      pii q = split(c[a][0], k);
      int r = join2(q.ss, nnr(v[a]), nn(c[a][1]));
      return mp(q.ff, r);
    }
  }
  int get(int l, int r) {   //inclusive - exclusive
    while(not(l < N)) l -= N, r -= N;
    while(l < 0) l += N, r += N;

    if(r > N) return join(get(l, N), get(N, r));
    pii f1 = split(root, r);
    pii f2 = split(f1.ff, l);

    return f2.ss;
  }
  void fill(int n, int * a, int * t = new int(0)) {
    if(n == 0) return;
    fill(c[n][0], a, t);
    a[(*t)++] = v[n];
    fill(c[n][1], a, t);
  }
  void pout(int n = root) {
    if(n == 0) return;
    pout(c[n][0]);
    cerr << v[n] << " ";
    pout(c[n][1]);
    if(n == root) cerr << "\n\n";
  }
} pbt;

int M, S;
ll T;

int to[40][MAXN];

void gen() {
  root = 0;
  for(int i = 0;i < N;i++) root = pbt.join(root, pbt.nnr(i), 0);
  for(int i = 1;i < N;i++) {
    int a = pbt.get(i, i + M);
    int b = pbt.get(M - i, N - i);
    assert(pbt.sz[a] == M and pbt.sz[b] == N - M);
    root = pbt.join(a, b);
    //pbt.pout();
    assert(pbt.sz[root] == N);
  }
  pbt.fill(root, to[0]);
}

void run() {
  for(int i = 1;i < 40;i++) {
    for(int j = 0;j < N;j++) {
      to[i][j] = to[i-1][to[i-1][j]];
    }
  }
}

void brute() {
  int q = static_cast<int>(T%N);
  for(;q;q--,T--) {
    if(S < M) S = (S + q)%N;
    else S = (S - q + N)%N;
  }
  assert(T%N == 0);
}

void solve() {
  scanf("%d%lld", &S, &T);
  --S;
  brute();
  int k = T/N;
  for(int i = 0;1 << i < k;i++) {
    if(k&(1<<i)) S = to[i][S];
  }
  printf("%d\n", S + 1);
}

int main() {
  clock_t timer = clock();
  cerr << setprecision(6);

  scanf("%d%d", &N, &M);
  gen();
  run();
  //for(int i = 0;i < N;i++) printf("%d\n", to[0][i]);
  solve();

  cerr << "Time Elapsed: " << static_cast<double>(clock() - timer)/CLOCKS_PER_SEC << "\n";

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fre(i,a) for (auto& i: a)
#define ll long long

struct Rect{
	long long x1, y1, x2, y2;
	long long area(){
		return (y2-y1)*(x2-x1);
	}
};

int intersect(Rect p, Rect q){
    long long xOverlap = max(0,min(p.x2,q.x2)-max(p.x1,q.x1));
    long long yOverlap = max(0,min(p.y2,q.y2)-max(p.y1,q.y1));
    return xOverlap*yOverlap;
}

Rect a, b, c;

int main(){
	cin.tie(0)->sync_with_stdio(0);

	cin >> a.x1 >> a.y1 >> a.x2 >> a.y2;
	cin >> b.x1 >> b.y1 >> b.x2 >> b.y2;
	cin >> c.x1 >> c.y1 >> c.x2 >> c.y2;

	if(a.area() - (intersect(a,b) + intersect(a,c) - intersect(b,c)) == 0)
		cout << "NO";
	else
		cout << "YES";

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long f,t,t0,a1,t1,p1,a2,t2,p2,ans=(1LL<<60);
int main(){
	cin>>f>>t>>t0>>a1>>t1>>p1>>a2>>t2>>p2;
	for(int i=0;t1*i<=t;++i){
		long long lef=f-i,ret=(i+a1-1)/a1*p1;
		if(t0<t2){
			if(lef*t0+t1*i<=t)ans=min(ans,ret);
			continue;
		}
		int lb=-1,ub=(t-t1*i)/t2;
		while(ub>lb+1){
			long long mid=(lb+ub)>>1;
			if(t1*i+t2*mid+max(0LL,(f-i-mid))*t0<=t) ub=mid;
			else lb=mid;
		}
		if(t1*i+t2*ub+max(0LL,(f-i-ub))*t0>t) continue;
		ret+=(ub+a2-1)/a2*p2;
		if(i%a1==0||ub%a2==0) ans=min(ans,ret);
	}
	if(ans>=INF) puts("-1");
	else cout<<ans;
	return 0;
}