/* practice with Dukkha */
#include <stdio.h>

long long gcd(long long a, long long b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	static char cc[1048576], *s = cc;
	long long x, y;

	scanf("%lld%lld", &x, &y);
	if (gcd(x, y) != 1) {
		printf("Impossible\n");
		return 0;
	}
	while (x > 1 || y > 1) {
		long long k;
		char c;

		if (x > y) {
			k = x / y;
			if (y == 1)
				k--;
			x %= y;
			c = 'A';
		} else {
			k = y / x;
			if (x == 1)
				k--;
			y %= x;
			c = 'B';
		}
		s += sprintf(s, "%lld%c", k, c);
	}
	printf("%s\n", cc);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
#define LL long long
uLL exgcd64(uLL a,uLL b,uLL *x,uLL *y)
{
	static uLL gcd;
	if (a==0)
	{
		*x=0;*y=1;
		return b;
	}
	else
	{
		gcd=exgcd64(b%a,a,y,x);
		*x-=(b/a)*(*y)+b;
		*y+=a;
		return gcd;
	}
}
int main()
{
	freopen("in.in","r",stdin);
	LL i,j,k,n,m,a,b,c,d,x,y,vx,vy;
	scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x,&y,&vx,&vy);
	if ((vx==0)||(vy==0))
	{
		if (vx==0)
		{
			if ((x==0)||(x==n))
			{
				if (vy<0) {printf("%lld 0\n",x);}
				else {printf("%lld %lld\n",x,m);}
			}
			else
			{
				printf("-1\n");
			}
		}
		if (vy==0)
		{
			if ((y==0)||(y==m))
			{
				if (vx<0) {printf("0 %lld\n",y);}
				else {printf("%lld %lld\n",n,y);}
			}
			else
			{
				printf("-1\n");
			}
		}
	}
	else
	{
		if (vx<0)
		{
			x=n-x;
		}
		if (vy<0)
		{
			y=m-y;
		}
		//printf("%lld %lld %lld %lld\n",n,m,x,y);
		c=exgcd64(m,n,&a,&b);
		d=x-y;
		if (d<0) {d=(d%m+m)%m;}
		if (d%c!=0) {printf("-1\n");}
		else
		{
			c=(d/c)*(b/c)%(m/c);
			if (c==0) {c+=m/c;}
			d=(c*n-(x-y))/m;
			//printf("%lld %lld %lld %lld\n",c,d,n,m);
			c=c&1;d=d&1;
			if (vx<0) {c=c^1;}
			if (vy<0) {d=d^1;}
			c=c*n;d=d*m;
			printf("%lld %lld\n",c,d);
		}
	}
	return 0;
}


#include <stdio.h>

long long power_mod (long long a, long long b, long long mod_num) {
  long long ans = 1LL;

  if (b > 0LL) {
    ans = power_mod(a, b/2LL, mod_num);
    ans = (ans * ans) % mod_num;
    if (b%2LL == 1LL) {
      ans = (ans * a) % mod_num;
    }
  }

  return ans;
}

int main () {
  int n = 0;
  int k = 0;

  int res = 0;

  long long ans = 0LL;
  long long mod_num = 1000000007LL;

  long long fact[100001] = {};
  long long invf[100001] = {};

  res = scanf("%d", &n);
  res = scanf("%d", &k);

  if (n <= k) {
    printf("%lld\n", power_mod(2LL, (long long)n, mod_num));
    return 0;
  }

  fact[0] = 1LL;
  for (int i = 0; i < n; i++) {
    fact[i+1] = fact[i];
    fact[i+1] *= (long long) (i+1);
    fact[i+1] %= mod_num;
  }

  invf[n] = power_mod(fact[n], mod_num-2LL, mod_num);
  for (int i = n; i > 0; i--) {
    invf[i-1] = invf[i];
    invf[i-1] *= (long long)i;
    invf[i-1] %= mod_num;
  }

  for (int i = 0; i <= k; i++) {
    long long tmp = invf[i];
    tmp = (tmp*invf[n-i])%mod_num;
    ans = (ans+tmp)%mod_num;
  }

  ans = (ans*fact[n])%mod_num;
  printf("%lld\n", ans);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	500
#define N_	(1 << 9)	/* N_ = pow2(ceil(log2(N))) */
#define INF	0x3f3f3f3f3f3f3f3fLL

long long min(long long a, long long b) { return a < b ? a : b; }

int *oh[N][N], *ot[N][N], *ox[N][N], oo[N][N];

void link(int i, int j, int h, int t, int x) {
	int o = oo[i][j]++;

	if (o >= 2 && (o & o - 1) == 0) {
		oh[i][j] = (int *) realloc(oh[i][j], o * 2 * sizeof *oh[i][j]);
		ot[i][j] = (int *) realloc(ot[i][j], o * 2 * sizeof *ot[i][j]);
		ox[i][j] = (int *) realloc(ox[i][j], o * 2 * sizeof *ox[i][j]);
	}
	oh[i][j][o] = h, ot[i][j][o] = t, ox[i][j][o] = x;
}

long long *st_, *lz_; int h_, n_;

void put(int i, long long x) {
	st_[i] += x;
	if (i < n_)
		lz_[i] += x;
}

void pus(int i) {
	if (lz_[i]) {
		put(i << 1, lz_[i]), put(i << 1 | 1, lz_[i]);
		lz_[i] = 0;
	}
}

void pul(int i) {
	if (!lz_[i])
		st_[i] = min(st_[i << 1], st_[i << 1 | 1]);
}

void push(int i) {
	int h;

	for (h = h_; h > 0; h--)
		pus(i >> h);
}

void pull(int i) {
	while (i > 1)
		pul(i >>= 1);
}

void update(int l, int r, long long x) {
	int l_ = l += n_, r_ = r += n_;

	push(l_), push(r_);
	for ( ; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			put(l++, x);
		if ((r & 1) == 0)
			put(r--, x);
	}
	pull(l_), pull(r_);
}

void update1(int i, long long x) {
	push(i += n_);
	st_[i] = x;
	pull(i);
}

long long query(int l, int r) {
	long long x;

	push(l += n_), push(r += n_);
	x = INF;
	for ( ; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			x = min(x, st_[l++]);
		if ((r & 1) == 0)
			x = min(x, st_[r--]);
	}
	return x;
}

int main() {
	static long long xx[N][N], st[N][N_ * 2], lz[N][N_ * 2], sti[N_ * 2], lzi[N_ * 2];
	int n, m, k, i, j;

	scanf("%d%d%d", &n, &m, &k);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++) {
			oh[i][j] = (int *) malloc(2 * sizeof *oh[i][j]);
			ot[i][j] = (int *) malloc(2 * sizeof *ot[i][j]);
			ox[i][j] = (int *) malloc(2 * sizeof *ox[i][j]);
		}
	while (k--) {
		int d, t, x;
		int meet1, meet2, meet3, meet4;

		scanf("%d%d%d%d%d", &i, &j, &d, &t, &x);
		meet1 = meet2 = meet3 = meet4 = 0;
		if (i + j >= t && (i + j) % 4 == t % 4)
			xx[i][j] += x, meet1 = 1;
		if (i + j >= t && (i + j) % 4 == (t + 1) % 4)
			xx[i + d][j - d] += x, meet2 = 1;
		if (i + j + d >= t && (i + j + d) % 4 == (t + 2) % 4)
			xx[i + d][j] += x, meet3 = 1;
		if (i + j + d >= t && (i + j + d) % 4 == (t + 2) % 4)
			xx[i][j + d] += x, meet4 = 1;
		if (meet1 && meet3)
			link(i + d, j, i, 0, x);
		if (meet1 && meet4)
			link(i, j + d, j, 1, x);
		if (meet2 && meet3)
			link(i + d, j, j - d, 1, x);
	}
	h_ = 0;
	while (1 << h_ < n || 1 << h_ < m)
		h_++;
	n_ = 1 << h_;
	for (i = 0; i < n; i++) {
		memset(sti, 0, n_ * 2 * sizeof *sti);
		memset(lzi, 0, n_ * 2 * sizeof *lzi);
		for (j = 0; j < m; j++) {
			int o;
			long long x;

			for (o = 0; o < oo[i][j]; o++) {
				int h = oh[i][j][o], t = ot[i][j][o], x = ox[i][j][o];

				if (t == 0)
					st_ = st[j], lz_ = lz[j], update(0, h, -x);
				else
					st_ = sti, lz_ = lzi, update(0, h, -x);
			}
			if (i == 0 && j == 0)
				x = 0;
			else {
				x = INF;
				if (i > 0)
					st_ = st[j], lz_ = lz[j], x = min(x, query(0, i - 1));
				if (j > 0)
					st_ = sti, lz_ = lzi, x = min(x, query(0, j - 1));
			}
			st_ = st[j], lz_ = lz[j], update1(i, x), update(0, i, xx[i][j]);
			st_ = sti, lz_ = lzi, update1(j, x), update(0, j, xx[i][j]);
		}
	}
	st_ = st[m - 1], lz_ = lz[m - 1];
	printf("%lld\n", query(n - 1, n - 1));
	return 0;
}


#include <stdio.h>
#include <string.h>

char s[101];
int k, n, i, j, x, ok[30];

void read(){
	scanf("%d%s", &k, s);
}

int process(){
	n = strlen(s);
	x=n/2;
	for(i=0, j=n-1;i<x;i++, j--){
		if(s[i]=='?' && s[j]!='?')s[i]=s[j];
		else if(s[j]=='?' && s[i]!='?')s[j]=s[i];
		else if(s[j] != s[i])return 0;

		ok[s[i]-'a']=1;
		ok[s[j]-'a']=1;
	}
	x+=n%2;--x;
	for(i=k-1;x>=0&&i>=0;x--){

		if(s[x]=='?'){
			while(i>0&&ok[i])--i;
			s[x]=s[n-x-1]='a'+i;
			ok[s[x]-'a']=1;
		}
	}
	for(i=0;i<k;i++)if(!ok[i])return 0;
	return 1;
}

int main (){
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	read();
	if(process())printf("%s", s);
	else printf("IMPOSSIBLE");

	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define LEN 78777
#define MAX 1000010
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define chkbit(ar, i) (((ar[(i) >> 6]) & (1 << (((i) >> 1) & 31))))
#define setbit(ar, i) (((ar[(i) >> 6]) |= (1 << (((i) >> 1) & 31))))
#define isprime(x) (( (x) && ((x)&1) && (!chkbit(ar, (x)))) || ((x) == 2))

int p, x, y, prime[LEN];
unsigned int ar[(MAX >> 6) + 5] = {0};

void sieve(){
    int i, j, k;
    setbit(ar, 0), setbit(ar, 1);

    for (i = 3; (i * i) < MAX; i += 2){
        if (!chkbit(ar, i)){
            k = i << 1;
            for (j = (i * i); j < MAX; j += k) setbit(ar, j);
        }
    }

    p = 0;
    prime[p++] = 2;
    for (i = 3; i < MAX; i += 2){
        if (isprime(i)) prime[p++] = i;
    }
}

int expo(int a, int b){
    int res = 1;

    while (b){
        if (b & 1) res = (long long)res * a % MOD;
        a = (long long)a * a % MOD;
        b >>= 1;
    }
    return res;
}

int mobius(int n){
    if (n == 1) return 1;

    int i, j, x, counter = 0;
    for (i = 0; i < p; i++){
        if (prime[i] * prime[i] > n) break;
        for (j = 0; (n % prime[i]) == 0; j++, n /= prime[i]) {}
        if (j > 1) return 0;
        counter += (j == 1);
    }

    return (counter & 1) ? 1 : -1;
}

int count(int n, int d){
    return (mobius(d) * expo(2, (n / d) - 1) + MOD) % MOD;
}

int solve(int x, int y){
    int d, n, res = 0;
    if ((y % x) != 0) return 0;

    n = y / x;
    for (d = 1; d * d <= n; d++){
        if (n % d == 0){
            res = (res + count(n, d)) % MOD;
            if ((n / d) != d) res = (res + count(n, n / d)) % MOD;
        }
    }

    return res;
}

int main(){
    sieve();
    scanf("%d %d", &x, &y);
    printf("%d\n", solve(x, y));
    return 0;
}


#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

int determine(int *guesses, int *bulls, int *cows, int n);
bool is_solution(int *K, int *guesses, int *bulls, int *cows, int n);
bool fits(int *K, int guess, int bulls, int cows);

int main() {
	int n = 0, k = 0, result = 0;
	int *guesses = NULL;
	int *bulls = NULL;
	int *cows = NULL;

	scanf("%d", &n);

	guesses = calloc(n, sizeof(int));
	bulls = calloc(n, sizeof(int));
	cows = calloc(n, sizeof(int));

	for(k=0; k<n; k++) {
		scanf("%d %d %d", &guesses[k], &bulls[k], &cows[k]);
	}

	result = determine(guesses, bulls, cows, n);

	switch(result) {
		case (-1):
			printf("Incorrect data");
			break;
		case (-2):
			printf("Need more data");
			break;
		default:
			if(result<1000)
				printf("0");
			printf("%d", result);
			break;
	}

	printf("\n");

	free(guesses);
	free(bulls);
	free(cows);

	return 0;
}

int determine(int *guesses, int *bulls, int *cows, int n) {
	int i0 = 0, i1 = 0, i2 = 0, i3=0, result=-1;
	int K[4];
	bool found = false;

	for(i3=0;i3<10;i3++){
		for(i2=0;i2<10;i2++){
			if(i2==i3) continue;
			for(i1=0;i1<10;i1++){
				if(i1==i2 || i1==i3) continue;
				for(i0=0;i0<10;i0++){
					if(i0==i1 || i0==i2 || i0==i3) continue;
					K[0]=i0;
					K[1]=i1;
					K[2]=i2;
					K[3]=i3;
					if(is_solution(K, guesses, bulls, cows, n)) {
						if(found)
							return (-2);
						else {
							result = K[0]+10*K[1]+100*K[2]+1000*K[3];
							found = true;
						}
					}
				}
			}
		}
	}

	return result;

}

bool is_solution(int *K, int *guesses, int *bulls, int *cows, int n) {
	bool cont = true;
	int j = 0;

	while(cont && j<n) {
		cont = fits(K, guesses[j], bulls[j], cows[j]);
		j++;
	}

	return cont;
}

bool fits(int *K, int guess, int bulls, int cows) {
	int Guess[4];
	bool selected[4];
	int j = 0, i = 0, weight = 1, weightx = 10, countb = 0, countc = 0;

	for(j=0; j<4; j++) {
		Guess[j] = (guess%weightx) / weight;
		weight = weightx;
		weightx *= 10;
	}

	for(j=0; j<4; j++) {
		if(Guess[j]==K[j])
			countb++;
	}

	if(bulls != countb)
		return false;

	for(j=0; j<4; j++)
		selected[j] = false;

	for(i=0; i<4; i++)
		for(j=0; j<4; j++) {
			if(i!=j && !selected[i] && Guess[i]==K[j]) {
				countc++;
				selected[i] = true;
			}
		}

	if(cows != countc)
		return false;

	return true;
}


/*
 #include<stdio.h>
#define P 1000000007
int n,i,j;__int64 t=1,s;
int main(){
    scanf("%d",&n);
    for(i=1;i<=n;++i)t=t*i%P;
    for(j=P-3,s=t;j;j>>=1,s=s*s%P)
        if(j&1)t=t*s%P;
    for(i=n;i<n<<1;++i)t=t*i%P;
    return printf("%I64d\n",(t*2-n+P)%P),0;
}
*/

#include<stdio.h>
#include<stdlib.h>
#define modd 1000000007
long long fast_expo(long long a,long long b)
{
    long long res=1;
    while(b>0)
    {
        if(b&1)
        res=(res*a)%modd;
        a=(a*a)%modd;
        b=b>>1;
    }
    return res;
}
int main()
{
    long long fact[200001];
    int i,n;
    fact[0]=1;
    for(i=1;i<200001;i++){
        fact[i]=(fact[i-1]*i)%modd;
    //  printf("fact[%d] = %d  \n",i, fact[i]);
        }
    while(scanf("%d",&n)==1)
    {
        long long ans=(fact[(n<<1)-1]*((fast_expo(fact[n],modd-2)*fast_expo(fact[n-1],modd-2))%modd))%modd;
        ans=(ans<<1)-n;
        if(ans<0)
            printf("%I64d\n",(ans+modd)%modd);
        else printf("%I64d\n",ans%modd);
    }
    return 0;
}


/* upsolve with kaiboy */
#include <stdio.h>
#include <string.h>

#define N	1000000
#define M	1000000
#define K	20

int aa[N + 1], kk[N + 1];

void init() {
	int a, b, b_, k;

	for (a = 2; a <= N; a++) {
		if (aa[a])
			continue;
		b = 1, b_ = N / a, k = 0;
		while (b <= b_) {
			b *= a, k++;
			aa[b] = a, kk[b] = k;
		}
	}
}

int main() {
	static char used[M * K + 1];
	static int cc[K + 1];
	int n, m, a, b, b_, j, k, cnt;
	long long ans;

	init();
	scanf("%d%d", &n, &m);
	cnt = 0;
	for (k = 1; k <= K; k++) {
		for (j = 1; j <= m; j++)
			if (!used[j * k])
				used[j * k] = 1, cnt++;
		cc[k] = cnt;
	}
	ans = 1;
	for (a = 2; a <= n; a++)
		if (aa[a] == a) {
			b = 1, b_ = n / a, k = 0;
			while (b <= b_)
				b *= a, k++;
			ans += cc[k];
		}
	printf("%lld\n", ans);
	return 0;
}


#include <stdio.h>

#define M	100
#define MD	1000000007

void mult(int aa[][M], int bb[][M], int cc[][M], int m) {
	int i, j, k;

	for (i = 0; i < m; i++) {
		int *ci = cc[i];

		for (j = 0; j < m; j++)
			ci[j] = 0;
		for (k = 0; k < m; k++) {
			int *bk = bb[k], a = aa[i][k];

			for (j = 0; j < m; j++)
				ci[j] = (ci[j] + (long long) a * bk[j]) % MD;
		}
	}
}

void power(int aa[][M], int pp[][M], int tt[][M], int m, long long k) {
	if (k == 0) {
		int i, j;

		for (i = 0; i < m; i++)
			for (j = 0; j < m; j++)
				pp[i][j] = i == j;
		return;
	}
	if (k % 2 == 0) {
		power(aa, tt, pp, m, k / 2);
		mult(tt, tt, pp, m);
	} else {
		power(aa, pp, tt, m, k / 2);
		mult(pp, pp, tt, m);
		mult(tt, aa, pp, m);
	}
}

int main() {
	static int aa[M][M], pp[M][M], tt[M][M];
	long long n;
	int m, i, j, ans;

	scanf("%lld%d", &n, &m);
	if (n < m) {
		printf("1\n");
		return 0;
	}
	for (i = 0; i < m - 1; i++)
		aa[i][i + 1] = 1;
	aa[m - 1][0] = aa[m - 1][m - 1] = 1;
	power(aa, pp, tt, m, n - m + 1);
	ans = 0;
	for (j = 0; j < m; j++)
		ans = (ans + pp[m - 1][j]) % MD;
	printf("%d\n", ans);
	return 0;
}


#include<stdio.h>
int comp(const void * a,const void * b)
{
    return (*(int*)a  - *(int*)b);
}
int main()
{
    int n,m,i,j,arr[10000],k,xx,xy,l,z,p,pp=0,qq=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
    qsort(arr,n,sizeof(int),comp);
    l=0;
    xx=0;
    xy=0;
    z=n-k;
    for(i=0;i<=z;i++){
            l=0;
    m=0;
        for(j=i;j<n;j++){
                if(m>=k)
                break;
        if(arr[i]==arr[j])
                m++;
                else{
                        xy=arr[j];
                        p=0;
                    while(xy>arr[i]){
                        xy/=2;
                        p++;
                    }
                    if(xy==arr[i]){
                        m++;
                        l+=p;
                    }
                }
        }
        if(i==0 && m>=k){
            xx=l;
            qq++;

        }
        else if((xx>l && m>=k)|| (qq==0)){
            xx=l;
            qq++;
        }
            if(i==z){
                pp=0;l=0;
                for(i=0;i<k;i++){
                    while(arr[i]>0){
                        arr[i]/=2;
                    l++;
                    }
                }
                pp=l;
                if(pp<xx || qq==0)
                    xx=pp;
                    break;
            }
    }
    printf("%d\n",xx);

}


#include <stdio.h>
long long int n, k, M, D;

long long int max(long long int a, long long int b)
{
	if (a > b)
		return a;
	return b;
}

int main()
{
	scanf("%I64d %I64d %I64d %I64d", &n, &k, &M, &D);
	long long int ans = M;
	for (long long int i = D; i >= 2; i--)
	{
		if (n/i < k)
			continue;
		long long int beg = 1, end = M;

		while (beg <= end)
		{
			long long int mid = (beg+end)/2;
			long long int num = n/mid;
			//printf("%d, %d, %d\n", i, mid, num);
			if (num < k*(i-1)+1)
			{
				end = mid-1;
			}
			else if (i == D && num >= k*i+1)
			{
				beg = mid+1;
			}
			else if (num >= k*(i-1)+1)
			{
				ans = max(ans, (i)*mid);
				beg = mid+1;
			}
			else
			{
				beg = mid+1;
				ans = max(ans, (i)*mid);
			}
		}
	}

	printf("%I64d\n", ans);
	return 0;
}


#include<stdio.h>
#include<string.h>
#define maxn 210

int p[maxn], num[maxn], bef[maxn][maxn], vis[maxn], an[4];

int min(int a, int b, int c){
	a = a < b ? a : b;
	return a < c ? a : c;
}

int gao(int start, int n){
	int finish = 0, ans = 0, f = 0, now, flag = 0, i, j;
	memset(vis, 0, sizeof(vis));
	while(finish != n){
		for(now = 1; now <= 3; now++){
			if(now == start){
				flag = 1;
			}
			if(flag == 1){
				for(i = 1; i <= n; i++){
					if(p[i] == now){
						if(!num[i] && !vis[i]){
							ans++;
							//printf("+");//
							vis[i] = 1;
							finish++;
							//printf("%d ", i);//
							i = 0;
						}else{
							f = 0;
							for(j = 1; j <= num[i]; j++){
								if(!vis[bef[i][j]]){
									f = 1;
								}
							}
							if(f == 0 && !vis[i]){
								ans++;
								//printf("+");//
								vis[i] = 1;
								finish++;
								//printf("%d ", i);//
								i = 0;
							}
						}
					}
				}
			}
			if(flag == 1 && finish != n){
				ans++;
				//printf("(+)");//
			}
		}
	}
	//printf("\n");//
	return ans;
}

int main(void){
	int n, i, j, ans;
	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		scanf("%d", &p[i]);
	}
	for(i = 1; i <= n; i++){
		scanf("%d", &num[i]);
		for(j = 1; j <= num[i]; j++){
			scanf("%d", &bef[i][j]);
		}
	}

	for(i = 1; i <= 3; i++){
		an[i] = gao(i, n);
		//printf("%d\n", an[i]);//
	}
	ans = min(an[1], an[2], an[3]);
	printf("%d", ans);
	return 0;
}


/* https://codeforces.com/contest/1185/submission/55797221 (Dukkha) */
#include <stdio.h>

#define N	50
#define T	2500
#define MD	1000000007

int dp[N + 1][N + 1][N + 1], dq[N + 1][N + 1][N + 1][3];

void init(int na, int nb, int nc) {
	int ma, mb, mc, x0, x1, x2;

	for (ma = 0; ma <= na; ma++)
		for (mb = 0; mb <= nb; mb++)
			for (mc = 0; mc <= nc; mc++) {
				x0 = ma > 0 ? (long long) dq[ma - 1][mb][mc][0] * ma % MD : 0;
				x1 = mb > 0 ? (long long) dq[ma][mb - 1][mc][1] * mb % MD : 0;
				x2 = mc > 0 ? (long long) dq[ma][mb][mc - 1][2] * mc % MD : 0;
				if (ma == 0 && mb == 0 && mc == 0) {
					dp[ma][mb][mc] = 1;
					dq[ma][mb][mc][0] = dq[ma][mb][mc][1] = dq[ma][mb][mc][2] = 1;
				} else {
					dp[ma][mb][mc] = ((long long) x0 + x1 + x2) % MD;
					dq[ma][mb][mc][0] = (x1 + x2) % MD;
					dq[ma][mb][mc][1] = (x0 + x2) % MD;
					dq[ma][mb][mc][2] = (x0 + x1) % MD;
				}
			}
}

void solve1(int *aa, int t, int n, int da[][N + 1]) {
	int i, s, m, a;

	for (s = 0; s <= t; s++)
		for (m = 0; m <= n; m++)
			da[0][0] = 0;
	da[0][0] = 1;
	for (i = 0; i < n; i++) {
		a = aa[i];
		for (s = t; s >= a; s--)
			for (m = 1; m <= n; m++)
				da[s][m] = (da[s][m] + da[s - a][m - 1]) % MD;
	}
}

void solve2(int *aa, int *bb, int t, int na, int nb, int dab[][N + 1][N + 1]) {
	static int da[T + 1][N + 1];
	int i, b, s, ma, mb;

	solve1(aa, t, na, da);
	for (s = 0; s <= t; s++)
		for (ma = 0; ma <= na; ma++) {
			dab[s][ma][0] = da[s][ma];
			for (mb = 1; mb <= nb; mb++)
				dab[s][ma][mb] = 0;
		}
	for (i = 0; i < nb; i++) {
		b = bb[i];
		for (s = t; s >= b; s--)
			for (ma = 0; ma <= na; ma++)
				for (mb = 1; mb <= nb; mb++)
					dab[s][ma][mb] = (dab[s][ma][mb] + dab[s - b][ma][mb - 1]) % MD;
	}
}

int main() {
	static int aa[N], bb[N], cc[N], dab[T + 1][N + 1][N + 1], dc[T + 1][N + 1];
	int n, na, nb, nc, t, tab, tc, ma, mb, mc, xab, xc, ans;

	scanf("%d%d", &n, &t);
	na = nb = nc = 0;
	while (n--) {
		int a, g;

		scanf("%d%d", &a, &g);
		if (g == 1)
			aa[na++] = a;
		else if (g == 2)
			bb[nb++] = a;
		else
			cc[nc++] = a;
	}
	init(na, nb, nc);
	solve1(cc, t, nc, dc);
	solve2(aa, bb, t, na, nb, dab);
	ans = 0;
	for (tab = 0; tab <= t; tab++) {
		tc = t - tab;
		for (ma = 0; ma <= na; ma++)
			for (mb = 0; mb <= nb; mb++)
				if ((xab = dab[tab][ma][mb]))
					for (mc = 0; mc <= nc; mc++)
						if ((xc = dc[tc][mc]))
							ans = (ans + (long long) xab * xc % MD * dp[ma][mb][mc]) % MD;
	}
	printf("%d\n", ans);
	return 0;
}


/* practice with Dukkha */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	30
#define T	(30 * 31 / 2)
#define NU	(N * T)
#define NV	(NU * 3)

char *strndup_(char *s, int n) {
	char *s_ = malloc(n + 1);

	strncpy(s_, s, n);
	s_[n] = 0;
	return s_;
}

struct V {
	char *s;
	int i, h;
} vv_[NV], *vv[NV];

int compare(const void *a, const void *b) {
	struct V *u = *(struct V **) a;
	struct V *v = *(struct V **) b;
	int mu = strlen(u->s), mv = strlen(v->s);
	int c;

	if (mu != mv)
		return mu - mv;
	c = strcmp(u->s, v->s);
	return c != 0 ? c : u->i - v->i;
}

int score(char *s) {
	int n = strlen(s), i;
	int sum, max;

	sum = max = 0;
	for (i = 0; i < n; i++) {
		int a = s[i] - 'a' + 1;

		sum += a;
		if (max < a)
			max = a;
	}
	return sum * max;
}

int xx[NU + 1];
char ww[NU + 1];
int ss[NU + 1], tt[NU + 1];

void push(int p, int i) {
	int s = tt[i] + xx[i], t = ss[i];

	if (!ww[p]) {
		if (!ww[i])
			ww[p] = 1, ss[p] = s, tt[p] = t;
		else if (ss[p] < s || ss[p] == s && tt[p] > t)
			ss[p] = s, tt[p] = t;
	} else if (!ww[i] && (ss[p] < s || ss[p] == s && tt[p] > t))
		ss[p] = s, tt[p] = t;
}

int main() {
	static int pp[NU + 1], qq[NU + 1];
	int n, nv, k, i;

	scanf("%d", &n);
	nv = 0;
	for (i = 0; i < n; i++) {
		static char s[32];
		int m, l, r;

		scanf("%s", s), m = strlen(s);
		for (l = 0; l < m; l++)
			for (r = l; r < m; r++) {
				struct V *v, *p, *q;
				char *t = strndup_(s + l, r - l + 1);

				v = vv[nv] = &vv_[nv], nv++;
				v->s = t, v->i = i;
				p = vv[nv] = &vv_[nv], nv++;
				p->s = strndup_(t + 1, r - l), p->i = -1;
				q = vv[nv] = &vv_[nv], nv++;
				q->s = strndup_(t, r - l), q->i = -1;
			}
	}
	qsort(vv, nv, sizeof *vv, compare);
	k = 0;
	for (i = 0; i < nv; ) {
		char *s = vv[i]->s;
		int x, j;

		for (j = i; j < nv && strcmp(vv[j]->s, s) == 0; j++)
			vv[j]->h = k;
		x = score(s);
		while (i < j) {
			if (vv[i]->i != -1 && (i + 1 == j || vv[i]->i != vv[i + 1]->i))
				x++;
			i++;
		}
		xx[k++] = x;
	}
	for (i = 0; i < nv; i += 3) {
		struct V *v = &vv_[i + 0];
		struct V *p = &vv_[i + 1];
		struct V *q = &vv_[i + 2];

		pp[v->h] = p->h;
		qq[v->h] = q->h;
	}
	for (i = k - 1; i > 0; i--) {
		push(pp[i], i);
		push(qq[i], i);
	}
	printf(ww[0] ? "First\n" : "Second\n");
	printf("%d %d\n", ss[0], tt[0]);
	return 0;
}


#include <stdio.h>
#include <string.h>
#define M 1000000009

typedef long long LL;
int n,m,sz,son[110][4],fail[110],term[110],par[110],l[110];
LL f[1010][110][20];
void init(int u,int d);
LL dp(int i,int u,int o);

int main(void)
{
    //freopen("gene.in","r",stdin);
    //freopen("gene.out","w",stdout);
    scanf("%d%d",&n,&m);
    memset(son,0,sizeof(son));
    memset(term,0,sizeof(term));
    sz=1;  l[1]=0;
    int i,j,u,t;
    char str[20];
    for(i=1;i<=m;i++)
    {
        scanf("%s",str);
        for(u=1,j=0;str[j];j++)
        {
            if(str[j]=='A') t=0;
            else if(str[j]=='C') t=1;
            else if(str[j]=='G') t=2;
            else t=3;
            if(!son[u][t])
            {
                l[++sz]=l[u]+1;
                son[u][t]=sz;
            }
            par[son[u][t]]=u;
            u=son[u][t];
        }
        term[u]=1;
    }
    memset(fail,-1,sizeof(fail));
    fail[1]=0;
    for(i=0;i<4;i++)
        fail[son[1][i]]=1;
    init(1,-1);
    memset(f,-1,sizeof(f));
    printf("%I64d\n",dp(0,1,0));
    return 0;
}

void init(int u,int d)
{
    int i,v;
    if(fail[u]<0)
        for( fail[u]=1,v=fail[par[u]] ; v ; v=fail[v] )
            if(son[v][d])
            {
                fail[u]=son[v][d];
                break;
            }
    for(i=0;i<4;i++)
        if(son[u][i])
            init(son[u][i],i);
}

LL dp(int i,int u,int o)
{
    if(f[i][u][o]>=0) return f[i][u][o];
    else if(i==n)
        return f[i][u][o] = o ? 0 : 1;
    f[i][u][o]=0;
    int j,v,w,t;
    for(j=0;j<4;j++)
    {
        for( w=0,v=u ; v&&l[v]>=o ; v=fail[v] )
            if(son[v][j])
            {
                w=son[v][j];
                break;
            }
        if(w)
        {
            for(t=w;l[t]>=o+1;t=fail[t])
                if(term[t]) break;
            f[i][u][o] = ( f[i][u][o] + dp(i+1,w,l[t]<o+1 ? o+1 : 0) )%M;
        }
    }
    return f[i][u][o];
}


#include<stdio.h>
long long f[23],n,s,sum;
long long power(long long a, long long b, long long MOD) {
long long x = 1, y = a;
    while(b > 0) {
        if(b%2 == 1) {
            x=(x*y);
            if(x>MOD) x%=MOD;
        }
        y = (y*y);
        if(y>MOD) y%=MOD;
        b /= 2;

    }
    return x;
}

long long modInverse(long long a,long long m) {
    return power(a,m-2,m);
}

long long binomialCoeff(long long n, long long k)
{
    long long i,res = 1;
    if (k >( n - k))
        k = n - k;
    for ( i = 0; i < k; ++i)
    {
        res =(res* ((n - i)%1000000007))%1000000007;
        res =(res* modInverse((i + 1),1000000007))%1000000007;
    }

    return res;
}
void recursion(long long i,long long pow,int fac){
	if(pow>s)	return;
	if(i==n+1){
		sum=(sum+fac*binomialCoeff(n+s-pow-1,s-pow))%1000000007;
		return;
	}
	recursion(i+1,pow,fac);
	recursion(i+1,pow+f[i]+1,fac*-1);
}
int main(){
	long long i,j,k,l;
	scanf("%lld %lld",&n,&s);
	for(i=1;i<=n;i++)	scanf("%lld",&f[i]);
	recursion(1,0,1);
	sum=(sum+1000000007)%1000000007;
	printf("%lld\n",sum);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

#define DUBEG 0
#define OFFSET 1200000
#define TOOBIG 24000000

int vals[51], n, smol[51], larg[51], bitc[1<<24], possib[25][(OFFSET<<1) + 1], ansar[2][51];

int cmpfn(const void *_a, const void *_b){
  int *a, *b;
  a = (int *)_a;
  b = (int *)_b;
  return (*a) - (*b);
}

int get_sum(int mask, int *ar){
  int a, b, i;
  a = b = 0;
  for(i = 0;i < n - 1;i++)if(mask&(1<<i))a += ar[i]; else b += ar[i];
  return a - b;
}

int get_smol(int mask){
  return get_sum(mask, smol);
}

int get_larg(int mask){
  return get_sum(mask, larg);
}

int main(){
  int i, j;
  scanf("%d", &n);
  for(i = 0;i < (n<<1);i++)scanf("%d", vals + i);
  qsort(vals, (n<<1), sizeof(int), cmpfn);
  if(DUBEG){printf("vals:");for(i = 0;i < (n<<1);i++)printf(" %d", vals[i]);printf("\n");}

  ansar[0][0] = vals[0];
  ansar[1][n - 1] = vals[1];
  for(i = 0 + 2;i < 2 + (n - 1);i++)smol[i - 2] = vals[i];
  for(i = 0 + 2 + (n - 1);i < (n<<1);i++)larg[n - 2 - (i - (2 + (n - 1)))] = vals[i];
  if(DUBEG){printf("smol:");for(i = 0;i < n - 1;i++)printf(" %d", smol[i]);printf("\n");}
  if(DUBEG){printf("larg:");for(i = 0;i < n - 1;i++)printf(" %d", larg[i]);printf("\n");}

  for(i = 0;i <= (n - 1);i++)for(j = 0;j <= (OFFSET<<1);j++)possib[i][j] = 0;
  for(i = 0;i < (1<<(n - 1));i++){
    int x;
    for(x = i, bitc[i] = 0;x;bitc[i]++, x&=x-1);
    possib[bitc[i]][get_smol(i) + OFFSET] = 1;
  }
  for(i = 0;i <= (n - 1);i++){
    int prev = TOOBIG;
    for(j = (OFFSET<<1);j >= 0;j--){
      possib[i][j] = possib[i][j] ? (j - OFFSET) : prev;
      prev = possib[i][j];
    }
  }
  int best, besti;
  best = TOOBIG;
  for(i = 0;i < (1<<(n - 1));i++){
    int reqbits, diff;
    diff = -get_larg(i);
    reqbits = n - 1 - bitc[i];
    if(possib[reqbits][diff + OFFSET] != TOOBIG)if(best > possib[reqbits][diff + OFFSET] - diff){
	best = possib[reqbits][diff + OFFSET] - diff;
	besti = i;
      }
  }

  //derive ansar from besti
  int prefil = 0;
  for(i = 0;i < n - 1;i++){
    if(besti&(1<<i)) ansar[1][prefil++] = larg[i];
    else ansar[0][n - 1 - (i - prefil)] = larg[i];
  }
  int diff = -get_larg(besti);
  for(i = 0;i < (1<<(n - 1));i++)if(bitc[i] + bitc[besti] == n - 1)if(get_smol(i) - diff == best){
	for(j = 0;j < n - 1;j++){
	  if(i&(1<<j)) ansar[1][prefil++] = smol[j];
	  else ansar[0][n - 1 - (j + (n - 1) - prefil)] = smol[j];
	}
	break;
      }
  for(i = 0;i < n;i++)printf("%d ", ansar[0][i]);printf("\n");
  for(i = 0;i < n;i++)printf("%d ", ansar[1][i]);printf("\n");
  return 0;
}


#include <stdio.h>

#define N	1024

int min(int a, int b) { return a < b ? a : b; }

int query(int i) {
	if (i == -1) {
		printf("R\n"), fflush(stdout);
		return 0;
	} else {
		static char s[2];

		printf("? %d\n", i + 1), fflush(stdout);
		scanf("%s", s);
		return s[0] == 'N';
	}
}

int ii_[N], cnt1_;

int solve(int *ii, int cnt1, int *jj, int cnt2, int k) {
	int h, g, cnt2_;

	if (cnt2 == 0) {
		for (h = 0; h < cnt1; h++)
			ii_[cnt1_++] = ii[h];
		return 0;
	}
	for (h = 0; h < cnt1; h++)
		query(ii[h]);
	cnt2_ = 0;
	for (h = 0; h < cnt2; h++) {
		int j = jj[h];

		if (query(j))
			jj[cnt2_++] = j;
	}
	for (h = 0; h < cnt1 - 1; h++) {
		int i = ii[h];

		if (h == 0)
			for (g = 0; g < k * 2 + 1 - cnt1 - cnt2; g++)
				query(ii[cnt1 - 1]);
		if (query(i))
			ii_[cnt1_++] = i;
	}
	ii_[cnt1_++] = ii[cnt1 - 1];
	query(-1);
	return cnt2_;
}

int main() {
	static int ii[N], jj[N];
	int n, k, g, cnt1, cnt2;

	scanf("%d%d", &n, &k);
	cnt1 = 0;
	for (g = 0; g < n / k; g++) {
		int l = g * k, r = (g + 1) * k, h, i;

		cnt2 = 0;
		for (i = l; i < r; i++)
			if (query(i))
				jj[cnt2++] = i;
		query(-1);
		cnt1_ = 0;
		for (h = 0; h < cnt1; h += k)
			cnt2 = solve(ii + h, min(cnt1 - h, k), jj, cnt2, k);
		cnt1 = 0;
		for (h = 0; h < cnt1_; h++)
			ii[cnt1++] = ii_[h];
		for (h = 0; h < cnt2; h++)
			ii[cnt1++] = jj[h];
	}
	printf("! %d\n", cnt1), fflush(stdout);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define K	1000000
#define L_	21	/* L_ = ceil(log2(K * 2 + 1)) */
#define N_	(1 << L_)
#define MD	998244353

long long power(long long a, int k) {
	long long p = 1;

	while (k) {
		if (k & 1)
			p = p * a % MD;
		a = a * a % MD;
		k >>= 1;
	}
	return p;
}

int inv(int a) {
	return a == 1 ? 1 : (long long) inv(a - MD % a) * (MD / a + 1) % MD;
}

int vv[K + 1], ff[K + 1], gg[K + 1];
int *wu[L_ + 1], *wv[L_ + 1];

void init() {
	int i, l, u, v;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= K; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
		ff[i] = (long long) ff[i - 1] * i % MD;
		gg[i] = (long long) gg[i - 1] * vv[i] % MD;
	}
	u = power(3, MD - 1 >> L_), v = power(u, MD - 2);
	for (l = L_; l > 0; l--) {
		int n = 1 << l - 1;

		wu[l] = (int *) malloc(n * sizeof *wu[l]);
		wv[l] = (int *) malloc(n * sizeof *wv[l]);
		wu[l][0] = wv[l][0] = 1;
		for (i = 1; i < n; i++) {
			wu[l][i] = (long long) wu[l][i - 1] * u % MD;
			wv[l][i] = (long long) wv[l][i - 1] * v % MD;
		}
		u = (long long) u * u % MD, v = (long long) v * v % MD;
	}
}

int choose(int n, int k) {
	return k < 0 || k > n ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

void ntt_(int *aa, int l, int inverse) {
	if (l > 0) {
		int n = 1 << l, m = n >> 1, i, j, *ww = inverse ? wv[l] : wu[l];

		ntt_(aa, l - 1, inverse), ntt_(aa + m, l - 1, inverse);
		for (i = 0; (j = i + m) < n; i++) {
			int a = aa[i], b = (long long) aa[j] * ww[i] % MD;

			if ((aa[i] = a + b) >= MD)
				aa[i] -= MD;
			if ((aa[j] = a - b) < 0)
				aa[j] += MD;
		}
	}
}

void ntt(int *aa, int l_, int inverse) {
	int n = 1 << l_, i, j;

	for (i = 1, j = 0; i < n; i++) {
		int b, tmp;

		b = n >> 1;
		while ((j ^= b) < b)
			b >>= 1;
		if (i < j)
			tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	ntt_(aa, l_, inverse);
}

int main() {
#if 0
	static int dp[11][11], dq[11][11];
	int n = 10, l = 3, i, j, k;

	init();
	dp[0][0] = 1, dq[0][0] = 0;
	for (i = 1; i <= n; i++) {
		for (j = i; j <= n; j++)
			for (k = 0; k <= j; k++) {
				dp[i][j] = (dp[i][j] + (long long) dp[i - 1][k] * choose(j, k)) % MD;
				dq[i][j] = (dq[i][j] + (long long) dq[i - 1][k] * choose(j, k) + (long long) dp[i - 1][k] * choose(j, k) % MD * choose(j - k, l)) % MD;
			}
		printf("(%d %d)\n", dp[i][i], dq[i][i]);
	}
	/* guess: (# of more-equal arrays with a_1 = a_2 = ... = a_l) == (n + 1)^(n - l) */
#else
	static int aa[N_], bb[N_];
	int n, k, n_, l_, i, v, f, p, ans;

	init();
	scanf("%d%d", &n, &k);
	l_ = 0;
	while (1 << l_ <= k + k)
		l_++;
	n_ = 1 << l_;
	for (i = 0; i <= k; i++)
		aa[i] = (long long) (i % 2 == 0 ? 1 : MD - 1) * gg[i] % MD;
	for (i = 0; i <= k; i++)
		bb[i] = power(i, k) * gg[i] % MD;
	ntt(aa, l_, 0), ntt(bb, l_, 0);
	for (i = 0; i < n_; i++)
		aa[i] = (long long) aa[i] * bb[i] % MD;
	ntt(aa, l_, 1);
	v = inv(n_);
	for (i = 0; i < n_; i++)
		aa[i] = (long long) aa[i] * v % MD;
	ans = 0;
	f = 1, p = power(n + 1, n), v = inv(n + 1);
	for (i = 1; i <= k; i++) {
		f = (long long) f * (n - i + 1) % MD;
		p = (long long) p * v % MD;
		ans = (ans + (long long) aa[i] * f % MD * p) % MD;
	}
	printf("%d\n", ans);
#endif
	return 0;
}


#include <stdlib.h>
#include <stdio.h>

typedef long long int lli;

#define TRUE         (1==1)
#define FALSE        (!TRUE)

#define fo3(a,b,c)   for(a=(int)(b);a<=(int)(c);a++)
#define of3(a,b,c)   for(a=(int)(b);a>=(int)(c);a--)
#define in32(a)      scanf("%d",&(a))
#define in64(a)      scanf("%I64d",&(a))
#define out32(a)     printf("%d\n",(a))
#define out64(a)     printf("%I64d\n",(a))
#define instr(a)     scanf("%s",(a))
#define outstr(a)    printf("%s\n",(a))
#define max(a,b)     (((a)<(b))?(b):(a))
#define min(a,b)     (((a)>(b))?(b):(a))

lli gcd(lli a, lli b) {
    return (b == 0) ? a : gcd(b, a % b);
}
lli lcm(lli a, lli b) {
    lli g = gcd(a, b);
    return a * (b / g);
}

int facts(lli val, lli * arr, int st) {
    if (val == 1) {
        arr[0] = 1;
        return 1;
    }
    int i = st,k;
    while (i * i <= val) {
        if (val % i == 0) {
            int pow = 0;
            while (val % i == 0) {
                pow ++;
                val/=i;
            }
            int cur = facts(val,arr,i+1);
            int res = cur * (pow + 1);
            fo3(k,cur,res-1)
                arr[k] = arr[k-cur]*i;
            return res;
        }
        i++;
    }
    arr[0] = 1;
    arr[1] = val;
    return 2;
}

#define MOD 1000000007
#define SENT -1
lli memo[1010][1010];

lli rec(int a, int b) {
    if (a == 0 && b == 0)
        return 0;
    if (a < 0)
        return 0;
    if (b < 0)
        return 0;
    if (a < b)
        return 0;
    if (memo[a][b] != SENT)
        return memo[a][b];
    int ret = 0;
    if ((a+b)&1)
        ret = 1;
    ret += rec(a-1,b);
    ret += rec(a,b-1);
    while(ret>=MOD)
        ret-=MOD;
    memo[a][b] = ret;
    return ret;
}

int main(void)
{
    int n,i,j;
    in32(n);
    fo3(i,0,n)
        fo3(j,0,n)
            memo[i][j] = SENT;
    out64(rec(n,n));
    return EXIT_SUCCESS;
}


#include <stdio.h>

#define N	200000
#define MD	998244353

long long power(int a, int k) {
	long long p;

	if (k == 0)
		return 1;
	p = power(a, k >> 1);
	p = p * p % MD;
	if (k & 1)
		p = p * a % MD;
	return p;
}

int ff[N + 1], gg[N + 1];

void init() {
	int i, f;

	f = 1;
	for (i = 0; i <= N; i++) {
		gg[i] = power(ff[i] = f, MD - 2);
		f = (long long) f * (i + 1) % MD;
	}
}

int ch(int n, int k) {
	return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

int main() {
	int n, c, ans;
	long long k;

	init();
	scanf("%d%lld", &n, &k);
	ans = 0;
	if (k == 0)
		ans = ff[n];
	else if (k < n) {
		int x;

		x = 0;
		for (c = n - k; c >= 0; c--)
			x = (x + ((n - k - c) % 2 == 0 ? 1 : -1) * (ch(n - k, c) * power(c, n))) % MD;
		ans = (long long) ch(n, n - k) * x * 2 % MD;
		if (ans < 0)
			ans += MD;
	}
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

char str[77];
int n, vmax, kmax, xmax, ar[77], dp[77][77][77][3];

int fill(char visited[77], int c, int d){
	int i, x = 0;
	for (i = 0; i < n; i++){
		if (ar[i] == d){
			if (x == c) return i;
			x++;
			visited[i] = 1;
		}
	}
	return n;
}

int swap_count(int index, char visited[77]){
	int i, res = 0;
	for (i = 0; i < index; i++){
		if (!visited[i]) res++;
	}
	return res;
}

int F(int v, int k, int x, int l){
	if (v == vmax && k == kmax && x == xmax) return 0;
	if (dp[v][k][x][l] != -1) return dp[v][k][x][l];

	char visited[77] = {0};
	int a, b, c, r, res = 1 << 20;
	a = fill(visited, v, 0);
	b = fill(visited, k, 1);
	c = fill(visited, x, 2);

	if (v != vmax){
		r = F(v + 1, k, x, 0) + swap_count(a, visited);
		if (r < res) res = r;
	}
	if (k != kmax && l != 0){
		r = F(v, k + 1, x, 1) + swap_count(b, visited);
		if (r < res) res = r;
	}
	if (x != xmax){
		r = F(v, k, x + 1, 2) + swap_count(c, visited);
		if (r < res) res = r;
	}

	return (dp[v][k][x][l] = res);
}

int main(){
	int i, res;

	while (scanf("%d", &n) != EOF){
		scanf("%s", str);
		for (i = 0; i < n; i++){
			ar[i] = 2;
			if (str[i] == 'V') ar[i] = 0;
			if (str[i] == 'K') ar[i] = 1;
			vmax += (ar[i] == 0);
			kmax += (ar[i] == 1);
			xmax += (ar[i] == 2);
		}

		memset(dp, -1, sizeof(dp));
		res = F(0, 0, 0, 2);
		printf("%d\n", res);
	}
	return 0;
}


#include <stdio.h>

#define MOD 998244353LL

long long f[200001];

long long power(long long x, long long n){
    long long res;
    if(n==0){
        return 1;
    }
    if(n==1){
        return x%MOD;
    }

    res=power(x, n/2);
    res%=MOD;
    res*=res;
    res%=MOD;
    if(n & 1LL){
        res*=x;
        res%=MOD;
    }
    return res%MOD;
}

long long fibo(){
    int i;
    for(i=3; i<=200000; ++i){
        f[i]=f[i-2]+f[i-1];
        f[i]%=MOD;
    }
}

int main(void){
    long long N, res;

    scanf("%lld", &N);
    if(N==1){
        printf("%lld", power(2, MOD-2)%MOD);
        return 0;
    }
    else if(N==2){
        printf("%lld", power(4, MOD-2)%MOD);
        return 0;
    }
    f[1]=f[2]=1;
    fibo();

    res=((f[N]%MOD)*(power(power(2, N)%MOD, MOD-2)%MOD))%MOD;
    //(2*N-5)/2^N
    printf("%lld", res);

    return 0;
}

/*
x^MOD == x (mod MOD)
x^(MOD-1) == 1 (mod MOD)
x * x^(MOD-2) == 1 (mod MOD)

2*N-5 mod MOD * (2^N)^-1 mod MOD
*/


#include <stdio.h>
#include <stdlib.h>

int n, sum;
int a[16];
int b[4][4];

int cmp(const void *a, const void *b)
{
    return *((int *)a) - *((int *)b);
}

int dfs(int x, int y, int z)
{
    int p, q, i, j;

    if (x == n && y == 0) return 1;

    p = x;
    q = y + 1;

    if (q == n) {
        p = x + 1;
        q = 0;
    }

    for (i = 0; i < n * n; i++) {
        if ((z >> i) & 1) continue;

        if (x == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[j][y];

            if (s + a[i] != sum) continue;
        }

        if (y == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[x][j];

            if (s + a[i] != sum) continue;
        }

        if (x == n - 1 && y == 0) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[j][n - j - 1];

            if (s + a[i] != sum) continue;
        }

        if (x == n - 1 && y == n - 1) {
            int s = 0;

            for (j = 0; j < n - 1; j++) s += b[j][j];

            if (s + a[i] != sum) continue;
        }

        b[x][y] = a[i];

        if (dfs(p, q, z | (1 << i)) == 1) return 1;

        for (j = i + 1; j < n * n; j++) {
            if (a[i] != a[j]) break;
        }

        i = j - 1;
    }

    return -1;
}

int main()
{
    int i, j;

    scanf("%d", &n);

    for (i = 0; i < n * n; i++) {
        scanf("%d", &a[i]);

        sum += a[i];
    }

    sum /= n;

    printf("%d\n", sum);

    qsort(a, n * n, sizeof(int), cmp);

    dfs(0, 0, 0);

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (j > 0) putchar(' ');

            printf("%d", b[i][j]);
        }

        puts("");
    }

    return 0;
}


#include <stdio.h>
#include <stdint.h>
#define ll int64_t

struct pr
{
    ll f, s;
} a[100001], b[100001];

int cmp(const void* p1, const void* p2)
{
    ll d = - ((const struct pr*)p1)->f + ((const struct pr*)p2)->f;
    if (d) return d < 0 ? -1 : 1;
    return ((const struct pr*)p1)->s - ((const struct pr*)p2)->s > 0 ? 1 : -1;
}

int main()
{
    int n, m; ll d;
    scanf("%d%d%I64d", &n, &m, &d);
    for(int i = 0; i < n; ++i)
    {
        scanf("%I64d%I64d", &(a[i].f), &(a[i].s));
    }
    for(int i = 0; i < m; ++i)
    {
        scanf("%I64d%I64d", &(b[i].f), &(b[i].s));
    }
    qsort(a, n, sizeof(struct pr), cmp);
    qsort(b, m, sizeof(struct pr), cmp);
    for(int i = 1; i < n; ++i)
    {
        a[i].f += a[i-1].f;
        a[i].s += a[i-1].s;
    }
    for(int i = 1; i < m; ++i)
    {
        b[i].f += b[i-1].f;
        b[i].s += b[i-1].s;
    }
    int i = 0, j = 0;
    if (a[0].s + b[0].s > d)
    {
        printf("0");
        return 0;
    }
    while(i < n && a[i].s + b[0].s <= d) ++i;
    ll ans = 0;
    while(j < m && i >= 0)
    {
        if (i < n && a[i].s + b[j].s <= d)
        {
            if (a[i].f + b[j].f > ans) ans = a[i].f + b[j].f;
            ++j;
        }
        else --i;
    }
    printf("%I64d", ans);
    return 0;
}


#include <stdio.h>
#include <string.h>

#define N	20000

long long min(long long a, long long b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

long long dot2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * x2 + (long long) y1 * y2;
}

long long cross2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

int xx[N + 1], yy[N + 1];

long long cross(int i, int j, int k) {
	return cross2(xx[j] - xx[i], yy[j] - yy[i], xx[k] - xx[i], yy[k] - yy[i]);
}

int aa[N + 1], dp[N + 1], dq[N + 1];

void solve(int l, int r) {
	static int qu[N + 1], qq[N + 1], pp[N + 1];
	int m, h, i, j, q, p, cnt;

	if (r - l == 1)
		return;
	m = (l + r) / 2;
	solve(l, m);
	solve(m, r);
	q = 0;
	for (i = m - 1; i >= l; i--)
		qq[i] = q = max(q, aa[i]);
	p = 0;
	for (i = m; i < r; i++)
		pp[i] = p, p = max(p, aa[i]);
	cnt = 0;
	for (j = m, i = m - 1, h = 0; j < r; j++) {
		while (i >= l && qq[i] <= pp[j]) {
			xx[i] = i, yy[i] = dp[i];
			while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
				cnt--;
			qu[cnt++] = i;
			if (h >= cnt - 2)
				h = cnt - 1;
			i--;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], pp[j], -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], pp[j], -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], pp[j] * j - dot2(xx[qu[h]], yy[qu[h]], pp[j], -1));
	}
	cnt = 0;
	for (j = r - 1, i = l, h = 0; j >= m; j--) {
		while (i < m && qq[i] > pp[j]) {
			xx[i] = qq[i], yy[i] = dp[i] - qq[i] * i;
			if (cnt && xx[qu[cnt - 1]] == xx[i]) {
				if (yy[qu[cnt - 1]] > yy[i])
					cnt--;
				else {
					i++;
					continue;
				}
			}
			while (cnt >= 2 && cross(qu[cnt - 2], qu[cnt - 1], i) >= 0)
				cnt--;
			qu[cnt++] = i;
			if (h >= cnt - 2)
				h = cnt - 1;
			i++;
		}
		while (h > 0 && dot2(xx[qu[h]], yy[qu[h]], -j, -1) < dot2(xx[qu[h - 1]], yy[qu[h - 1]], -j, -1))
			h--;
		if (cnt)
			dq[j] = min(dq[j], -dot2(xx[qu[h]], yy[qu[h]], -j, -1));
	}
}

int main() {
	int n, k, i;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	memset(dp, 0x3f, (n + 1) * sizeof *dp), dp[0] = 0;
	while (k--) {
		memset(dq, 0x3f, (n + 1) * sizeof *dq);
		solve(0, n + 1);
		memcpy(dp, dq, (n + 1) * sizeof *dp);
	}
	printf("%d\n", dp[n]);
	return 0;
}


#include<stdio.h>
#include<string.h>

int tree[4*3000][4*3000], node;
long long g, x, y, z;
#define MAXINT 0x7fffffff

int nextg(){
	int ret=g;
	g=(g*x+y)%z;
	return ret;
}

int min(int a, int b){
	return a<b?a:b;
}

void build1(int n, int l, int r, int l2, int r2){
	if(l+1==r){
		if(l2+1==r2){
			tree[node][n]=nextg();
		}
		else{
			tree[node][n]=min(tree[2*node+1][n], tree[2*node+2][n]);
		}
		return;
	}
	int m=(l+r)/2;
	build1(2*n+1, l, m, l2, r2);
	build1(2*n+2, m, r, l2, r2);
	tree[node][n]=min(tree[node][2*n+1], tree[node][2*n+2]);
}

void build2(int n, int l, int r, int rd){
	if(l+1==r){
		node=n;
		build1(0, 0, rd, l, r);
		return;
	}
	int m=(l+r)/2;
	build2(2*n+1, l, m, rd);
	build2(2*n+2, m, r, rd);
	node=n;
	build1(0, 0, rd, l, r);
}

int query1(int n, int l, int r, int ql, int qr){
	if(qr<=l || r<=ql) return MAXINT;
	if(ql<=l && r<=qr){
		return tree[node][n];
	}
	int m=(l+r)/2;
	return min(query1(2*n+1, l, m, ql, qr),
			query1(2*n+2, m, r, ql, qr));
}

int query2(int n, int l, int r, int r2, int ql, int qr, int ql2, int qr2){
	if(qr<=l || r<=ql) return MAXINT;
	if(ql<=l && r<=qr){
		node=n;
		return query1(0, 0, r2, ql2, qr2);
	}
	int m=(l+r)/2;
	return min(query2(2*n+1, l, m, r2, ql, qr, ql2, qr2),
			query2(2*n+2, m, r, r2, ql, qr, ql2, qr2));
}

int main(){
	memset(tree, 0x7f, sizeof(tree));
	int i, j, n, m, a, b;
	long long sum=0;
	scanf("%d %d %d %d %I64d %I64d %I64d %I64d", &n, &m, &a, &b, &g, &x, &y, &z);
	build2(0, 0, n, m);
	for(i=0;i+a<=n;++i){
		for(j=0;j+b<=m;++j){
			sum+=(long long)query2(0, 0, n, m, i, i+a, j, j+b);
		}
	}
	printf("%I64d\n", sum);
	return 0;
}


/* http://catb.org/esr/intercal/ick.htm */
/* find xor of largest and last array elements */
#include <stdio.h>

#define N	10

int main() {
	static int aa[N];
	int n, i, max;

	scanf("%d", &n);
	max = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		if (max < aa[i])
			max = aa[i];
	}
	printf("%d\n", max ^ aa[n - 1]);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned long ulong;

long long int sort(long long int a[] , int n){
    long long int tmp = 0;
    for(ll  i = 1 ; i < n ; i++)
        {
            for(ll j = i ; j < n ; j++){
                if(a[i] > a[j]){
                    tmp = a[j];
                    a[j] = a[i];
                    a[i] = tmp;
                }
            }

        }
}

long long int min(long long int a , long long int b){
    if(a > b)
        return b;
    return a;
}
#define For(i, n) for(i=0;i<(n);++i)
#define ForL(i, m, n) for(i=(m);i<(n);++i)

#define Clear(X) memset( (X), 0, sizeof( (X) ) )
#define Fill(X) memset( (X), -1, sizeof( (X) ) )

#define ArraySize(X) (sizeof(X)/sizeof(X[0]))

void _main();

int main() {
  // COUNTER CODE STARTS HERE
  _main();
  // COUNTER CODE ENDS HERE

  return 0;
}

// ACTUAL CODE STARTS BELOW

ll a, b, c, l;
ll ans = 0;

ll exclude(ll a, ll b, ll c, ll r) {
  if (a < b + c) return 0;
  ll v = min(r, a - b - c);
  return ((v + 1) * (v + 2)) >> 1;

}

void _main() {
    scanf("%d %d %d %d", &a , &b , &c , &l);
  for (ll i = 0; i <= l; ++i) {
    ans += (((i + 1) * (i + 2)) >> 1);
  }

  for (ll i = 0; i <= l; ++i) {
    ans -= exclude(a + i, b, c, l - i);
    ans -= exclude(b + i, a, c, l - i);
    ans -= exclude(c + i, b, a, l - i);
  }
    printf("%I64d\n", ans);
}


#include <stdio.h>
#include <string.h>

#define N	200100
#define MD	1000000007

int main() {
	static int dp[N + 1], dq[N + 1], tmp[N + 1];
	int a, b, k, t, n, m, i, j, sum;

	scanf("%d%d%d%d", &a, &b, &k, &t);
	n = a + k * 2 * t;
	m = b + k * 2 * t;
	dp[a] = 1;
	dq[b] = 1;
	while (t-- > 0) {
		sum = 0;
		for (i = 0; i <= n; i++) {
			tmp[i] = sum = (sum + dp[i]) % MD;
			if (i >= k * 2)
				sum = (sum - dp[i - k * 2] + MD) % MD;
		}
		memcpy(dp, tmp, (n + 1) * sizeof *tmp);
		sum = 0;
		for (j = 0; j <= m; j++) {
			tmp[j] = sum = (sum + dq[j]) % MD;
			if (j >= k * 2)
				sum = (sum - dq[j - k * 2] + MD) % MD;
		}
		memcpy(dq, tmp, (m + 1) * sizeof *tmp);
	}
	for (j = 1; j <= m; j++)
		dq[j] = (dq[j] + dq[j - 1]) % MD;
	sum = 0;
	for (i = 1; i <= n; i++)
		sum = (sum + (long long) dp[i] * dq[i - 1 < m ? i - 1 : m] % MD) % MD;
	printf("%d\n", sum);
	return 0;
}


/* ����ʯͷ��
[O]��A���Ӯ�Ĵ���
[] ��A����Ӯ�Ĵ���

1.ʯͷ
2.����
3.��
*/
#include<stdio.h>
int main()
{
	int n,a1,a2,a3,b1,b2,b3,maxwin1,maxwin2,maxwin3,maxwin,minwin1,minwin2,minwin3,minwin4,minwin;
	scanf("%d",&n);
	scanf("%d%d%d",&a1,&a2,&a3);
	scanf("%d%d%d",&b1,&b2,&b3);
	/**maxwin**/
	/*a1 beats b2*/
	if(a1>b2)
		maxwin1=b2;
	else
		maxwin1=a1;
	/*a2 beats b3*/
	if(a2>b3)
		maxwin2=b3;
	else
		maxwin2=a2;
	/*a3 beats b1*/
	if(a3>b1)
		maxwin3=b1;
	else
		maxwin3=a3;

	maxwin=maxwin1+maxwin2+maxwin3;

	/*minwin**/
	/*a1 cannot beat b1 b3*/
	if(a1-b1-b3<0)
		minwin1=0;
	else
		minwin1=a1-b1-b3;
	/*a2 cannot beat b1 b2*/
	if(a2-b1-b2<0)
		minwin2=0;
	else
		minwin2=a2-b1-b2;
	/*a3 cannot beat b2 b3*/
	if(a3-b2-b3<0)
		minwin3=0;
	else
		minwin3=a3-b2-b3;

	minwin=minwin1+minwin2+minwin3;
	printf("%d %d\n",minwin,maxwin);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

long long i,a[200000],x,n,k;
long long w;

int main()
{
    scanf("%I64d", &n);
    k=100;
    for(i=0; i<n; i++)
    {
        scanf("%I64d", &a[i]);
        if(a[i]<k)k=a[i];
    }

    x=0;

    for(i=0; i<n; i++)
    {
        if(a[i]==k)x++;
    }

    if(x>n/2)printf("Bob\n");
    else printf("Alice\n");

    return 0;
}


#include <stdio.h>

int main()
{
  int array[1001], n, c, d, e,swap;
  scanf("%d", &n);
  for (c = 0; c < n; c++)
    scanf("%d", &array[c]);

  for (c = 0 ; c < ( n - 1 ); c++)
  {
    for (d = 0 ; d < n - c - 1; d++)
    {
      if (array[d] > array[d+1])
      {
        swap       = array[d];
        array[d]   = array[d+1];
        array[d+1] = swap;
      }
    }
  }

  for(e=0;e<1000006;e++)
    printf("");
  for(e=0;e<1006;e++)
    printf("");

  printf("%d",array[0]);
  for ( c = 1 ; c < n ; c++ )
     printf(" %d", array[c]);

  return 0;
}


#include <stdio.h>

int query(long long i) {
	int x;

	printf("? %lld\n", i), fflush(stdout);
	scanf("%d", &x);
	return x;
}

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		long long n, m, l, r, c;
		int turn;

		scanf("%lld", &n);
		l = 0;
		for (m = n - 1; m > 0; m /= 4)
			l -= (m + 1) / 2;
		l = 1 - l, r = l, m = n - 1, turn = 0;
		query(r);
		c = 1;
		for (m = n - 1; m > 0; m /= 2, turn ^= 1)
			if (turn == 0) {
				if (query(l -= (m + 1) / 2))
					r -= (m + 1) / 2, m--;
				else
					c += (m + 1) / 2;
			} else {
				if (query(r += (m + 1) / 2))
					l += (m + 1) / 2, m--;
				else
					c += (m + 1) / 2;
			}
		printf("= %lld\n", c), fflush(stdout);
	}
	return 0;
}


#include <stdio.h>

int main() {
	int a, b, n, p, k, k_, cnt, lower, upper, l, r;

	scanf("%d%d", &a, &b);
	n = a + b;
	cnt = 0;
	for (p = 1; p <= (k = n / p); p++)
		if (a / k >= a % k && a % k <= n % p)
			cnt++;
	k_ = k;
	for (k = 1; k <= k_; k++)
		if (a / k >= a % k) {
			lower = 0, upper = n + 1;
			while (upper - lower > 1) {
				p = (lower + upper) / 2;
				if (a % k <= n - (long long) k * p)	/* n % p = n - k * p */
					lower = p;
				else
					upper = p;
			}
			r = lower;
			lower = 0, upper = n + 1;
			while (upper - lower > 1) {
				p = (lower + upper) / 2;
				if (n / p <= k)
					upper = p;
				else
					lower = p;
			}
			l = p = upper;
			cnt += l <= r ? r - l + 1 : 0;
		}
	printf("%d\n", cnt);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 2520
int a[30],index[MOD+10];
__int64 dps[23][2550][50];

void init(){
    int i,k=1;
    for(i=1;i<=MOD;i++){
        if(MOD%i==0)
            index[i]=k++;
    }
    k--;
}
int gcd(int a , int b)
{
    return b == 0 ? a : gcd(b , a % b);
}

int lcm(int a, int b)
{
    return a / gcd(a,b) * b;
}
__int64 dp(int pos,int sum,int mod,int doing){
    int i,tem,max,nowsum,nowmod;
    __int64 result=0;
    if(pos==-1){
        return sum%mod==0;
    }
    if(doing==0 && dps[pos][sum][index[mod]]!=-1)
        return dps[pos][sum][index[mod]];

    if(doing)
        max=a[pos];
    else
        max=9;

    for(i=0;i<=max;i++){
        nowsum=0;
        nowsum=(sum*10+i)%MOD;
        nowmod=0;
        nowmod=mod;
        if(i)
            nowmod=lcm(mod,i);
        if(doing && i==max){
            result+=dp(pos-1,nowsum,nowmod,1);
        }
        else{
            result+=dp(pos-1,nowsum,nowmod,0);
        }

    }
    if(!doing){
        dps[pos][sum][index[mod]]=result;
    }

}
__int64 cal(__int64 num){
    __int64 tem;
    int i;
    tem=num;
    i=1;
    while(tem){
        a[i++]=tem%10;
        tem/=10;
    }
    dp(i-1,0,1,1);
}
int main()
{
    int t,T;
    __int64 l,r,i,j,k;
    scanf("%d",&T);
    init();
    for(t=1;t<=T;t++){
        for(i=0;i<=22;i++)
            for(j=0;j<=2540;j++)
                for(k=0;k<=49;k++)
                    dps[i][j][k]=-1;
        scanf("%I64d %I64d",&l,&r);
        printf("%I64d\n",cal(r)-cal(l-1));
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

const i32 mod = 1000000007;

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

void run (void) {
  const i32 n = read_int();
  i32 *factor = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 i = 1; i <= n; ++i) {
    factor[i] = i;
  }
  for (i32 i = 2; i * i <= n; ++i) {
    if (factor[i] < i) continue;
    for (i32 j = i * i; j <= n; j += i) {
      factor[j] = i;
    }
  }
  i32 *dp = (i32 *) calloc (n + 1, sizeof (i32));
  dp[1] = 0;
  for (i32 i = 2; i <= n; ++i) {
    i32 f[64];
    f[0] = 1;
    i32 len = 1;
    i32 t = i;
    while (t > 1) {
      i32 p = factor[t];
      while (t % p == 0) {
	t /= p;
      }
      for (i32 j = 0; j < len; ++j) {
	f[j + len] = f[j] * p;
      }
      len *= 2;
    }
    if (f[len - 1] != i) {
      dp[i] = dp[f[len - 1]];
      continue;
    }
    i32 prob[64];
    for (i32 j = 0; j < len; ++j) {
      prob[j] = (i64) (n / f[j]) * inv(n) % mod;
    }
    for (i32 j = len - 1; j >= 0; --j) {
      for (i32 k = j - 1; k >= 0; --k) {
	if ((j & k) == k) {
	  prob[k] = (prob[k] - prob[j] + mod) % mod;
	}
      }
    }
    i32 local = 1;
    for (i32 j = 0; j < len - 1; ++j) {
      local = (local + (i64) prob[j] * dp[f[j]]) % mod;
    }
    dp[i] = local * inv((1 - prob[len - 1] + mod) % mod) % mod;
  }
  i32 ans = 1;
  for (i32 i = 1; i <= n; ++i) {
    ans = (ans + (i64)dp[i] * inv(n)) % mod;
  }
  print_int(ans);
  puts("");
}

int main (void) {
  run ();
  return 0;
}


#include <stdio.h>

#define MAX 1000010

int p, primes[78777], flag[MAX];

void Sieve(){
    int i, j, d;

    flag[2] = 1;
    for (i = 3; i < MAX; i++, i++) flag[i] = 1;
    for (i = 3; i < 1001;){
        d = i << 1;
        for (j = (i * i); j < MAX; j += d) flag[j] = 0;
        do{
            i++;
        }while (!flag[++i]);
    }

    for (i = 0; i < MAX; i++){
        if (flag[i]) primes[p++] = i;
    }
}

int isPrime(long long x){
    int i;
    for (i = 0; ; i++){
        long long y = primes[i];
        if ((y * y) > x) return 1;
        if ((x % y) == 0) return 0;
    }
}

int F(int i, long long a){
    if (a == 1) return 1;
    long long y = primes[i];
    if ((y + 1) > a) return 0;

    if (((y * y) + 1) > a){
        if (isPrime(a - 1)) return 1;
        return 0;
    }

    long long x = 1;
    int res = F(i + 1, a);

    for (; ;){
        x *= y;
        if ((x + 1) > a) break;

        if ((a % (x + 1)) == 0) res = res + F(i + 1, a / (x + 1));
    }
    return res;
}

int Solve(long long a){
    if (a < 5) return (a != 2);
    return F(0, a);
}

int main(){
    Sieve();
    long long a;
    while (scanf("%I64d", &a) != EOF) printf("%d\n", Solve(a));
    return 0;
}


#include<stdio.h>
int main()
{
double n,m;
while(scanf("%lf%lf",&n,&m)!=EOF)
printf("%.16lf\n",1.0/n+((n-1)*(m-1))/(n*(n*m-1)));
return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int x1, x2, a, b, fg, fgg;
  int mod;
  int stone;

  while(scanf("%d%d%d%d",&x1,&x2,&a,&b)==4){
    stone = x2 - x1;
    fg = 0;
    if(stone < 0) stone *= -1, k = a, a = b, b = k, a *= -1, b *= -1, fg = 1;
    if(b <= 0){ puts("DRAW"); continue; }

    if(a <= 0) fgg = 1, a = 1;
    mod = stone % (a+b);
    if(mod == 0){
      if(fgg) puts("DRAW"); else puts("SECOND");
      continue;
    }
    if(mod < a){
      puts("DRAW");
      continue;
    }

    stone -= mod;
    puts("FIRST");
    if(fg==0) printf("%d\n",x2-stone);
    else      printf("%d\n",x2+stone);
  }

  return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
	int t,n,l,k,d[200],a[200],flag,i,tmr,temp;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d %d",&n,&k,&l);
		for(i=0;i<n;i++)
		{
			scanf("%d",&d[i]);
		}
		flag=0,tmr=1000;
		for(i=0;i<n;i++)
		{
			if(d[i]+k<=l)
			{
				a[i]=d[i];
				tmr=1000;
			}
			else if(d[i]>l)
			{
				flag=1;
				// printf("%d-%d\n",d[i],i);
				break;
			}
			else if(d[i]+k>l)
			{
				if(i==0 || tmr==1000)
				{
					a[i]=l;
					tmr=l-d[i];
				}
				else
				{
					if(tmr>0)
					{
						temp=a[i-1]-d[i-1];
						a[i]=d[i]+temp-1;
						if(a[i]<=l)
						{
							tmr=tmr-1;
						}
						else
						{
							temp=l-a[i];
							tmr=tmr-temp;
							a[i]=l;
						}
					}
					else
					{
						if(a[i-1]+1>l)
						{
							flag=1;
							// printf("hi\n");
							break;
						}
						else
						{
							a[i]=d[i]-tmr+1;
							tmr=tmr-1;
						}
						if(tmr==-k)
						{
							tmr=k;
						}
					}
				}
			}
		}
		if(flag==1)
		{
			printf("No\n");
		}
		else
		{
			printf("Yes\n");
		}
	}
}


#include<stdio.h>
long long int min(long long int n,long long int k)
{
	if(n<k)
		return n;
	else
		return k;
}
long long int value(long long int n,long long int k)
{
	long long int x=0;
	while(n!=0)
	{
		x+=min(n,k);
		n-=min(n,k);
		n-=(n/10);
	}
	return x;
}
int main()
{
	long long int x,m,n,k,l=1,ans,r;
	scanf("%lld",&n);
	r=n;
	ans=r;
	while(l<=r)
	{
		k=(l+r)/2;
		x=value(n,k);
		if(x*2>=n)
		{
			ans=k;
			r=k-1;
		}
		else
			l=k+1;
	}
	printf("%lld\n",ans);
}


#include <stdio.h>
#include <string.h>

int low[7][7], high[7][7];
int cost[7][7];
int n;
int flow[7][7];
int inFlow[7];
int outFlow[7];
int minFlow = 100, maxCost = -1;

int rec(int v, int to) {
    if(v == n - 1) {
        int isValid = 1;
        int i, j;
        int total = inFlow[n - 1];
        int ccost = 0;
        for(i = 0; i < n; i++) {
            for(j = i + 1; j < n; j++) {
                if(flow[i][j] < low[i][j] || flow[i][j] > high[i][j])
                    isValid = 0;
                if(flow[i][j] > 0)
                    ccost += flow[i][j] * flow[i][j] + cost[i][j];
            }
            if(inFlow[i] != outFlow[i] && (i > 0 && i < n - 1)) {
                isValid = 0;
            }
        }
        if(isValid) {
            if(minFlow == total) {
                if(ccost > maxCost)
                    maxCost = ccost;
            } else if(minFlow > total) {
                minFlow = total;
                maxCost = ccost;
            }
        }
    } else if(to == n)
        rec(v + 1, v + 2);
    else {
        int i;
        for(i = 0; i <= high[v][to]; i++) {
            inFlow[to] += i;
            outFlow[v] += i;
            flow[v][to] = i;
            rec(v, to + 1);
            inFlow[to] -= i;
            outFlow[v] -= i;
        }
    }
}

int main() {
    scanf("%d", &n);
    int i, from, to, j;
    for(i = 0; i < n * (n - 1) / 2; i++) {
        scanf("%d %d", &from, &to);
        from--;
        to--;
        scanf("%d %d %d", &low[from][to], &high[from][to], &cost[from][to]);
    }
    rec(0, 1);
    if(minFlow == 100)
        puts("-1 -1");
    else
        printf("%d %d\n", minFlow, maxCost);
    return 0;
}


#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define ll long long

int cmpfunc(const void *a, const void *b);
int cmp(const void *a, const void *b);
int cmp1(const void *x, const void *y);
void swap(int *a, int *b);
int lower_bound(int a[][2], int left, int right, int *val);
int upper_bound(int a[], int left, int right, int *val);

int main(int argc, char **argv){
    int a,b,l,r;
    scanf("%d %d %d %d",&a,&b,&l,&r);
    int k;
    k=(int)floor(1.0*(l-a-1)/(a+b));
    if(l>=a+1 && k*(a+b)>=r-a-b){
        printf("1\n");
        return 0;
    }
    int u,v,m,n;
    u=l/(a+b);
    v=l%(a+b);
    m=r/(a+b);
    n=r%(a+b);

    if(b>=a){
        if(r-l>=2*a+b-1){
            printf("%d\n",a+1);
            return 0;
        } else if(u==m){
            int xd;
            if(n>a) xd=a-v+1;
            else xd=n-v+1;
            printf("%d\n",xd);
            return 0;
        } else{
            int xd;
            if(v<=a){
                if(n>=a) xd=a+1;
                else if(a-v+1+n<=a) xd=a-v+1+n;
                else xd=a;
            }else {
                if(n>=a) xd=a+1;
                else xd=n+1;
            }
            printf("%d\n",xd);
            return 0;
        }
    }

    if(b<a){
        if(r-l>=2*a+b-1){
            printf("%d\n",2*a-b);
            return 0;
        } else if(u==m){
            int xd;
            if(n>a) xd=a-v+1;
            else xd=n-v+1;
            printf("%d\n",xd);
            return 0;
        } else{
            int xd;
            if(v<a){
                if(n>=a) xd=2*a-b;
                else if(a-v+1+n<=a) xd=a-v+1+n;
                else if(n>=b && v<=b) xd=a+n-b;
                else xd=a;
            } else {
                if(n>=a) xd=a+1;
                else xd=n+1;
            }
            printf("%d\n",xd);
            return 0;
        }
    }
    return 0;
}

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

// ascending order
int cmpfunc(const void *a, const void *b) { return (*(int *)a - *(int *)b); }

int cmp(const void *x, const void *y) {
  const int *a = (const int *)x;
  const int *b = (const int *)y;
  if (a[0] == b[0])
    return a[1] - b[1];
  else
    return a[0] - b[0];
}

int cmp1(const void *x, const void *y) {
  const int *a = (const int *)x;
  const int *b = (const int *)y;
  if (a[1] == b[1])
    return a[0] - b[0];
  else
    return a[1] - b[1];
}

int lower_bound(int a[][2], int left, int right, int *val) {
  int middle;
  while (left < right) {
    middle = left + (right - left) / 2;
    if (a[middle][0] == *val)
      return middle;
    else if (a[middle][0] < *val)
      left = middle + 1;
    else
      right = middle;
  }
  if (a[left][0] <= *val)
    return left;
  else
    return left - 1;
}

int upper_bound(int a[], int left, int right, int *val) {
  int middle;
  while (left < right) {
    middle = left + (right - left) / 2;
    if (a[middle] == *val)
      return middle;
    else if (a[middle] < *val)
      left = middle + 1;
    else
      right = middle;
  }
  if (a[left] >= *val)
    return left;
  else
    return left + 1;
}