#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 {
		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<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.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;}

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(i, j, k) ((((i) & 1) * (n + 1) + (j)) * (n + 1) + (k))

void run (void) {
  const i32 n = read_int();
  const i32 m = read_int();
  const i32 mod = 998244353;
  i64 *dp = ALLOC (2 * (n + 1) * (n + 1), i64);
  dp[POS(1, 1, 1)] = 1;
  for (i32 i = 1; i < n; ++i) {
    memset (dp + POS(i + 1, 0, 0), 0, sizeof (*dp) * (n + 1) * (n + 1));
    for (i32 j = 1; j <= i; ++j) {
      for (i32 k = 1; k <= i; ++k) {
        dp[POS(i, j, k)] %= mod;
        dp[POS(i + 1, MAX (j, k + 1), k + 1)] += dp[POS(i, j, k)];
        dp[POS(i + 1, j, 1)] += dp[POS(i, j, k)];
      }
    }
  }
  i64 *way = ALLOC (n + 1, i64);
  for (i32 j = 1; j <= n; ++j) {
    for (i32 k = 1; k <= j; ++k) {
      way[j] += dp[POS(n, j, k)] % mod;
    }
  }
  for (i32 i = 1; i <= n; ++i) {
    way[i] %= mod;
  }
  i64 ans = 0;
  for (i32 i = 1; i <= n; ++i) {
    for (i32 j = 1; j <= n; ++j) {
      if (i * j < m) {
        ans += way[i] * way[j] % mod;
      }
    }
  }
  ans = 2 * ans % mod;
  print_int (ans);
  puts ("");
}

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


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

#define N	200000
#define K	447	/* K = floor(sqrt(N)) */

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

int main() {
	static int aa[N], *ii[N], kk[N], ii1[N + 1], ii2[K + 2], ll[N], ll_[N];
	int n, i, k, a, a_, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]), aa[i]--;
		kk[aa[i]]++;
	}
	for (a = 0; a < n; a++)
		ii[a] = (int *) malloc(kk[a] * sizeof *ii[a]), kk[a] = 0;
	memset(ii1, -1, (K + 2) * sizeof *ii1), memset(ii2, -1, (K + 2) * sizeof *ii2);
	ans = 0, a_ = -1;
	for (i = 0; i < n; i++) {
		a = aa[i];
		ii[a][kk[a]++] = i;
		if (a_ == -1 || kk[a_] < kk[a])
			a_ = a;
		for (k = 1; k <= kk[a] && k <= K + 1; k++)
			if (ii1[k] < ii[a][kk[a] - k])
				ii2[k] = ii1[k], ii1[k] = ii[a][kk[a] - k];
			else if (ii2[k] < ii[a][kk[a] - k])
				ii2[k] = ii[a][kk[a] - k];
		for (k = 1; k <= K; k++)
			if (ii2[k] > ii1[k + 1])
				ans = max(ans, i - ii1[k + 1]);
		ll[i] = ii1[K + 1];
	}
	for (i = 0; i < n; i++)
		ll_[i] = i + 1;
	for (a = 0; a < n; a++)
		if (a != a_ && kk[a] > K) {
			int d;

			memset(ii1, -1, (n + 1) * sizeof *ii1), ii1[0] = 0;
			d = 0;
			for (i = 0; i < n; i++) {
				if (aa[i] == a_)
					d++;
				else if (aa[i] == a)
					d--;
				if (d >= 0) {
					if (ii1[d] == -1)
						ii1[d] = i + 1;
					ll_[i] = min(ll_[i], ii1[d]);
				}
			}
		}
	for (i = n - 1; i >= 0; i--) {
		if (ll_[i] <= ll[i])
			ans = max(ans, i - ll_[i] + 1);
		if (ll_[i] == 0)
			break;
	}
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>

#define MD	1000000007

int power(int n, int k) {
	int p;

	if (k == 0)
		return 1;
	p = power(n, k / 2);
	p = (long long) p * p % MD;
	if (k % 2 == 1)
		p = (long long) p * n % MD;
	return p;
}

int main() {
	int n, m, k, sum, x;

	scanf("%d%d", &n, &m);
	sum = 0;
	for (k = 0; k < n; k++) {
		x = power(m + m - 1, k); /* Binomial theorem */
		sum = (sum + (long long) x * m % MD * power(m, n - 1 - k)) % MD;
	}
	printf("%d\n", (sum + power(m, n)) % MD);
	return 0;
}


#include <stdio.h>

#define MD	1000000007

int power(int n, int k) {
	int p;

	if (k == 0)
		return 1;
	p = power(n, k / 2);
	p = (long long) p * p % MD;
	if (k % 2 == 1)
		p = (long long) p * n % MD;
	return p;
}

int main() {
	int n, m, k, sum, x;

	scanf("%d%d", &n, &m);
	sum = 0;
	for (k = 0; k < n; k++) {
		x = power(m + m - 1, k); /* Binomial theorem */
		sum = (sum + x * m % MD * power(m, n - 1 - k)) % MD;
	}
	printf("%d\n", (sum + power(m, n)) % MD);
	return 0;
}


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

#define N	102
#define N_	(N * 2)
#define L	50
#define M	(1 + L)

long long add(long long a, long long b) { return a != -1 && b != -1 && a < LLONG_MAX - b ? a + b : -1; }

int *lj[N_], *lk[N_], lo[N_], *rj[N_], *rk[N_], ro[N_], *oj[N_], oo[N_];

void init() {
	int i;

	for (i = 0; i < N_; i++) {
		lj[i] = (int *) malloc(2 * sizeof *lj[i]);
		lk[i] = (int *) malloc(2 * sizeof *lk[i]);
		rj[i] = (int *) malloc(2 * sizeof *rj[i]);
		rk[i] = (int *) malloc(2 * sizeof *rk[i]);
		oj[i] = (int *) malloc(2 * sizeof *oj[i]);
	}
}

void append1(int **oj, int *oo, int i, int j) {
	int o = oo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		oj[i] = (int *) realloc(oj[i], o * 2 * sizeof *oj[i]);
	oj[i][o] = j;
}

void append2(int **oj, int **ok, int *oo, int i, int j, int k) {
	int o = oo[i]++;

	if (o >= 2 && (o & o - 1) == 0) {
		oj[i] = (int *) realloc(oj[i], o * 2 * sizeof *oj[i]);
		ok[i] = (int *) realloc(ok[i], o * 2 * sizeof *ok[i]);
	}
	oj[i][o] = j, ok[i][o] = k;
}

int tt[1 + M][2]; char bad[1 + M];

int build(int m) {
	static int ff[1 + M], qu[1 + M];
	int n, i, head, cnt;

	n = 2;
	while (m--) {
		int l, a;

		scanf("%d", &l);
		i = 1;
		while (l--) {
			scanf("%d", &a);
			if (!tt[i][a])
				tt[i][a] = n++;
			i = tt[i][a];
		}
		bad[i] = 1;
	}
	tt[0][0] = tt[0][1] = 1;
	head = cnt = 0;
	ff[1] = 0, qu[head + cnt++] = 1;
	while (cnt) {
		int e, a;

		i = qu[cnt--, head++], e = ff[i];
		bad[i] |= bad[e];
		for (a = 0; a < 2; a++) {
			int j = tt[i][a], f = tt[e][a];

			if (j)
				ff[j] = f, qu[head + cnt++] = j;
			else
				tt[i][a] = f;
		}
	}
	return n;
}

long long dd[N_ * M * M];
int iq[1 + N_ * M * M], pq[N_ * M * M], cnt;

int lt(int i, int j) { return dd[i] < dd[j]; }

int p2(int p) {
	return (p *= 2) > cnt ? 0 : (p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p);
}

void pq_up(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q)
		iq[pq[j] = p] = j;
	iq[pq[i] = p] = i;
}

void pq_dn(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q)
		iq[pq[j] = p] = j;
	iq[pq[i] = p] = i;
}

void pq_add_last(int i) {
	iq[pq[i] = ++cnt] = i;
}

int pq_remove_first() {
	int i = iq[1], j = iq[cnt--];

	if (j != i)
		pq[j] = 1, pq_dn(j);
	pq[i] = 0;
	return i;
}

int main() {
	static long long ans[N];
	int n, n_, k, m, i, s, t;

	init();
	scanf("%d%d%d", &n, &k, &m);
	n_ = n;
	while (k--) {
		static int ii[N];
		int cnt, h, i_;

		scanf("%d%d", &i, &cnt);
		for (h = 0; h < cnt; h++)
			scanf("%d", &ii[h]);
		i_ = ii[cnt - 1];
		for (h = cnt - 2; h >= 0; h--) {
			append2(lj, lk, lo, i_, ii[h], n_);
			append2(rj, rk, ro, ii[h], i_, n_);
			i_ = n_++;
		}
		append1(oj, oo, i_, i);
	}
	m = build(m) - 1;
	memset(ans, -1, n * sizeof *ans);
	memset(dd, -1, n_ * m * m * sizeof *dd);
	for (s = 0; s < m; s++) {
		int a;

		if (bad[s + 1])
			continue;
		for (a = 0; a < 2; a++) {
			t = tt[s + 1][a] - 1;
			if (!bad[t + 1]) {
				int u = (a * m + s) * m + t;

				dd[u] = 1, pq_add_last(u);
			}
		}
	}
	while (cnt) {
		int u, v, o, j, k, s_, t_;
		long long d;

		u = pq_remove_first(), i = u / m / m, s = u / m % m, t = u % m;
		if (i < n && s == 0 && (ans[i] == -1 || ans[i] > dd[u]))
			ans[i] = dd[u];
		for (o = oo[i]; o--; ) {
			j = oj[i][o], v = (j * m + s) * m + t, d = dd[u];
			if (d != -1 && (dd[v] == -1 || dd[v] > d)) {
				if (dd[v] == -1)
					pq_add_last(v);
				dd[v] = d, pq_up(v);
			}
		}
		for (o = lo[i]; o--; ) {
			j = lj[i][o], k = lk[i][o];
			for (s_ = 0; s_ < m; s_++) {
				v = (k * m + s_) * m + t, d = add(dd[(j * m + s_) * m + s], dd[u]);
				if (d != -1 && (dd[v] == -1 || dd[v] > d)) {
					if (dd[v] == -1)
						pq_add_last(v);
					dd[v] = d, pq_up(v);
				}
			}
		}
		for (o = ro[i]; o--; ) {
			j = rj[i][o], k = rk[i][o];
			for (t_ = 0; t_ < m; t_++) {
				v = (k * m + s) * m + t_, d = add(dd[u], dd[(j * m + t) * m + t_]);
				if (d != -1 && (dd[v] == -1 || dd[v] > d)) {
					if (dd[v] == -1)
						pq_add_last(v);
					dd[v] = d, pq_up(v);
				}
			}
		}
	}
	for (i = 2; i < n; i++)
		if (ans[i] == -1)
			printf("YES\n");
		else
			printf("NO %lld\n", ans[i]);
	return 0;
}


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

typedef long long int LLI;

#define TRUE              (1==1)
#define FALSE             (!TRUE)
#define fo3(i,a,b)        for(i=((int)a);i<=((int)b);i++)
#define of3(i,a,b)        for(i=((int)a);i>=((int)b);i--)
#define in1(n)            scanf("%d",&(n))
#define LL1(n)            scanf("%I64d",&(n))
#define in2(n,m)          scanf("%d%d",&(n),&(m))
#define pri(n)            printf("%d\n",n)
#define prs(n)            printf("%s\n",n)
#define prL(n)            printf("%I64d\n",n)
#define strin(n)          scanf("%s",n)
#define newint(n)         (int*)calloc((n),sizeof(int))
#define arrint(ret,n,i)   fo3(i,1,n) in1(ret[i-1])
#define newLLI(n)         (LLI*)calloc((n),sizeof(LLI))
#define arrLLI(ret,n,i)   fo3(i,1,n) LL1(ret[i-1])

void fastWrite(FILE * ofp, int x) {
    int i = 12;
    char buff[i];
    buff[i] = 0;
    int neg = 0;
    if (x < 0){
        x = -x;
        neg = 1;
    }
    if (x == 0)
        buff[--i] = '0';
    else while (x != 0) {
        buff[--i] = (x % 10) + '0';
        x /= 10;
    }
    if (neg)
        buff[--i] = '-';
    fwrite(buff + i, sizeof(char), (12 - i), ofp);
}

void fastSpace(FILE * ofp){
    fwrite(" ", sizeof(char), 1, ofp);
}
void fastNewLine(FILE * ofp) {
    fwrite("\n", sizeof(char), 1, ofp);
}

typedef struct AL AL;
struct AL{
    int * vals;
    int size;
    int cap;
};
AL * ALCreate(int s) {
    AL * ret = (AL *) calloc(1, sizeof(AL));
    if (s == 0) ret->vals = NULL;
    else ret->vals = (int *) calloc(s, sizeof(int));
    ret->size = 0; ret->cap = s;
    return ret;
}
void ALAdd(AL * list, int ele) {
    if (list->cap == list->size) {
        int nC = ((list->cap << 1) | 1);
        list->vals = realloc(list->vals, sizeof(int) * nC);
        list->cap = nC;
    }
    list->vals[list->size++] = ele;
}

typedef struct Pair {
    int fi, se;
} Pair;

int comp(Pair ** arr, int f, int s) {// CHANGE THIS
    if (arr[f]->fi - arr[f]->se != arr[s]->fi - arr[s]->se)
        return (arr[s]->fi - arr[s]->se) - (arr[f]->fi - arr[f]->se);
    return 0;
}

void sort(Pair ** arr, int size) {
    int i;
    if (size < 6) {
        int nSize = 0;
        Pair * swp;
        while (size != 0) {
            nSize = 0;
            for (i = 0; i < size - 1; i++)
                if (comp(arr, i, i + 1) > 0) {
                    nSize = i + 1;
                    swp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = swp;
                }
            size = nSize;
        }
        return;
    }
    Pair ** tmp = (Pair **)calloc(size, sizeof(Pair *)); // CHANGE THIS
    int lSize = (size >> 1);
    int rSize = size - lSize;
    sort(arr, lSize); sort(arr + lSize, rSize);
    int lPtr = 0, rPtr = 0;
    int ptr = 0;
    while (ptr != size) {
        if (lPtr == lSize){
            tmp[ptr] = arr[lSize + (rPtr++)];
        } else if (rPtr == rSize || comp(arr, lPtr, lSize + rPtr) <= 0){ // CHANGE THIS
            tmp[ptr] = arr[lPtr++];
        } else {
            tmp[ptr] = arr[lSize + (rPtr++)];
        }
        ptr++;
    }
    for (i = 0; i < size; i++)
        arr[i] = tmp[i];
    free(tmp);
}

int bc(int x) {
    if (x <= 1)
        return x;
    return (x&1) + bc(x>>1);
}

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

#define MAX        100000
#define NULL_CARRY -1
#define NULL_VALUE 0

LLI h1, h2;

int carry[4 * MAX];
int st[4 * MAX];
int en[4 * MAX];
LLI ans[2][4 * MAX];

void init2(int index, int s, int e) {
   //printf("%d %d %d\n", index, s, e);
   st[index] = s;
   en[index] = e;
   ans[0][index] = 0;
   ans[1][index] = 0;
   carry[index] = NULL_CARRY;
   if (s == e)
      return;
   int mid = (s + e) >> 1;
   init2(index << 1, s, mid);
   init2((index << 1) | 1, mid + 1, e);
}

// Inclusive s and e
void ITInit(int s, int e) {
   init2(1, s, e);
}

LLI fastExpo(LLI exp, LLI base, LLI mod) {
    if (exp == 0)
        return 1;
    if (exp == 1)
        return base % mod;
    LLI tmp = fastExpo(exp >> 1, base, mod);
    tmp *= tmp;
    tmp %= mod;
    if (exp & 1)
        tmp = (tmp * base) % mod;
    return tmp;
}

LLI aoMem[2][MAX + 10];
LLI feMem[2][MAX + 10];
void genAllOnes() {
    int i;
    LLI tmp1 = 0;
    LLI tmp2 = 0;
    LLI tmp3 = 1;
    LLI tmp4 = 1;
    fo3(i,0, MAX+9) {
        aoMem[TRUE][i] = tmp1;
        tmp1 = tmp1 * 10 + 1;
        tmp1 %= h1;
        aoMem[FALSE][i] = tmp2;
        tmp2 = tmp2 * 10 + 1;
        tmp2 %= h2;
        feMem[TRUE][i] = tmp3;
        tmp3 *= 10;
        tmp3 %= h1;
        feMem[FALSE][i] = tmp4;
        tmp4 *= 10;
        tmp4 %= h2;
    }
}
LLI allOnes(int len, LLI mod) {
    return aoMem[mod==h1][len];
}

LLI agg(int pre, int suf, int pow, LLI mod) {
    LLI mult = feMem[mod==h1][pow];
    mult *= suf;
    mult += pre;
    mult %= mod;
    //printf(" returning from agg!\n");
    return mult;
}

void ITComp(int index) {
    if (carry[index] == NULL_CARRY) {
        ans[0][index] = agg(ans[0][index<<1], ans[0][(index<<1)|1], en[index<<1] - st[index<<1] + 1, h1);
        ans[1][index] = agg(ans[1][index<<1], ans[1][(index<<1)|1], en[index<<1] - st[index<<1] + 1, h2);
    } else {
        ans[0][index] = allOnes(en[index] - st[index] + 1, h1) * carry[index];
        ans[0][index] %= h1;
        ans[1][index] = allOnes(en[index] - st[index] + 1, h2) * carry[index];
        ans[1][index] %= h2;
    }
}

void push(int index) {
    if (carry[index] == NULL_CARRY)
        return;
    if (st[index] != en[index]) {
        carry[index<<1] = carry[index];
        ITComp(index<<1);
        carry[(index<<1)|1] = carry[index];
        ITComp((index<<1)|1);
    }
    carry[index] = NULL_CARRY;
}

void set2(int index, int s, int e, int value) {
    if (st[index] >= s && e >= en[index]) {
        carry[index] = value;
        ITComp(index);
        return;
    }
    if (st[index] > e || s > en[index])
        return;
    push(index);
    set2(index<<1, s, e, value);
    set2((index<<1)|1, s, e, value);
    ITComp(index);
}

void ITSet(int s, int e, int value) {
   set2(1, s, e, value);
}

LLI get2(int index, int type, int s, int e) {
    if (st[index] >= s && e >= en[index]) {
        //printf(" Starting Push!\n");
        //push(index);
        ITComp(index);
        //printf(" Out of Push!\n");
        if (type == 0) {
            //prL(agg(0, ans[type][index], st[index] - s, h1));
            return agg(0, ans[type][index], st[index] - s, h1);
        }
        return agg(0, ans[type][index], st[index] - s, h2);
    }
    if (st[index] > e || s > en[index])
        return NULL_VALUE;
    push(index);
    LLI ret = get2(index<<1, type, s, e) + get2((index<<1)|1, type, s, e);
    if (type == 0 && ret >= h1)
        ret -= h1;
    if (type == 1 && ret >= h2)
        ret -= h2;
    return ret;
}

LLI get(int type, int s, int e) {
   return get2(1, type, s, e);
}

#define MOD 1000000007

LLI ch2(int x) {
    return (x * (x - 1)) >> 1;
}

void make(int n, int spots, LLI ** mat) {
    int i, j;
    int totalSmaller = spots - 1;
    int totalBigger = n - totalSmaller;
    LLI total = ch2(n);
    fo3(i,0,spots-1) {
        fo3(j,0,spots-1) {
            int smallerCorrect = i;
            int smallerIncorrect = totalSmaller - smallerCorrect;
            int biggerIncorrect = smallerIncorrect;
            int biggerCorrect = totalBigger - biggerIncorrect;
            if (i + 1 < j || j + 1 < i)
                mat[i][j] = 0;
            else if (i == j) {
                mat[i][j] = (total - (smallerCorrect * biggerCorrect + smallerIncorrect * biggerIncorrect)) % MOD;
            } else if (j < i) {
                // Worse
                mat[i][j] = (smallerCorrect * biggerCorrect) % MOD;
            } else {
                // Better
                mat[i][j] = (smallerIncorrect * biggerIncorrect) % MOD;
            }
        }
    }
}

LLI ** ident;

void clean2(LLI ** mat, int dim) {
    int i;
    fo3(i,0,dim-1)
        free(mat[i]);
    free(mat);
}

LLI ** mult(LLI ** a, LLI ** b, int dim) {
    LLI ** ret;
    int i, j, k;
    ret = calloc(dim, sizeof(LLI*));
    fo3(i,0,dim-1){
        ret[i] = calloc(dim, sizeof(LLI));
        fo3(j,0,dim-1){
            ret[i][j] = 0;
            fo3(k,0,dim-1) {
                ret[i][j] += (a[i][k] * b[k][j]) % MOD;
            }
            ret[i][j] %= MOD;
        }
    }
    return ret;
}

LLI ** expo(LLI ** base, int pow, int dim) {
    if (pow == 0) {
        return mult(ident, ident, dim);
    }
    if (pow == 1) {
        return mult(ident, base, dim);
    }
    LLI ** tmp = expo(base, pow >> 1, dim);
    LLI ** tmp2 = mult(tmp, tmp, dim);
    clean2(tmp, dim);
    if (pow&1) {
        tmp = mult(tmp2, base, dim);
        clean2(tmp2, dim);
        tmp2 = tmp;
    }
    return tmp2;
}

LLI expo2(LLI base, int pow) {
    if (pow == 0)
        return 1;
    if (pow == 1)
        return base % MOD;
    LLI tmp = expo2(base, pow>>1);
    tmp *= tmp;
    tmp %= MOD;
    if (pow&1) {
        tmp *= base;
        tmp %= MOD;
    }
    return tmp;
}

LLI inv(LLI val) {
    if (val == 1)
        return 1;
    return MOD - ((MOD / val) * inv(MOD % val)) % MOD;
}

int main(void) {
    LLI ** orig;
    int len, pow, i, j;
    in2(len, pow);
    int arr[len];
    int cs[2];
    cs[0] = 0;
    cs[1] = 0;

    fo3(i,1,len) {
        in1(arr[i-1]);
        cs[arr[i-1]]++;
    }
    int dim = cs[0] + 1;
    if (cs[1] < cs[0])
        dim = cs[1] + 1;
    orig = calloc(dim, sizeof(LLI*));
    fo3(i,0,dim-1)
        orig[i] = calloc(dim, sizeof(LLI));
    ident = calloc(dim, sizeof(LLI*));
    fo3(i,0,dim-1){
        ident[i] = calloc(dim, sizeof(LLI));
        fo3(j,0,dim-1)
            ident[i][j] = ((i==j) ? 1 : 0);
    }
    make(len, dim, orig);

    LLI ** ret = expo(orig, pow, dim);
    clean2(orig, dim);
    int wrong = 0;
    fo3(i,0,cs[0]-1)
        if (arr[i]!=0)
            wrong++;
    int cor = dim - wrong - 1;
    LLI ans = ret[cor][dim - 1];
    clean2(ret, dim);
    LLI den = expo2(ch2(len), pow);
    //prL(ans);
    //prL(den);
    ans *= inv(den);
    ans %= MOD;
    prL(ans);
    return 0;
}


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

#define N	100000
#define M	200000
#define MD	0x7fffffff

unsigned int Z = 12345, X = 12345;

int rand_() {
	return (Z *= 3) >> 1;
}

long long abs_(long long x) { return x > 0 ? x : -x; }

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

long long *ox[M], *oy[M]; int *oc[M], oo[M];

int hash(long long x, long long y) {
	return ((x % MD * X % MD + y) % MD + MD) % M;
}

void ht_add(long long x, long long y, int c) {
	int h = hash(x, y), o;

	for (o = 0; o < oo[h]; o++)
		if (ox[h][o] == x && oy[h][o] == y) {
			oc[h][o] += c;
			return;
		}
	o = oo[h]++;
	if (o >= 2 && (o & o - 1) == 0) {
		ox[h] = (long long *) realloc(ox[h], o * 2 * sizeof *ox[h]);
		oy[h] = (long long *) realloc(oy[h], o * 2 * sizeof *oy[h]);
		oc[h] = (int *) realloc(oc[h], o * 2 * sizeof *oc[h]);
	}
	ox[h][o] = x, oy[h][o] = y, oc[h][o] = c;
}

int ht_get(long long x, long long y) {
	int h = hash(x, y), o;

	for (o = 0; o < oo[h]; o++)
		if (ox[h][o] == x && oy[h][o] == y)
			return oc[h][o];
	return 0;
}

long long xx[N], yy[N];

double cross(int i, int j) {
	return (double) xx[i] * yy[j] - (double) xx[j] * yy[i];
}

int cmp(int i, int j) {
	int sign_i = xx[i] < 0 || xx[i] == 0 && yy[i] < 0, sign_j = xx[j] < 0 || xx[j] == 0 && yy[j] < 0;
	double c = cross(i, j);

	return sign_i != sign_j ? sign_i - sign_j : (c != 0 ? (c < 0 ? -1 : 1) : i - j);
}

int bad(int i, int j) {
	double c = cross(i, j);

	return c > 0 || c == 0 && i > j;
}

int zz[1 + N], ll[1 + N], rr[1 + N], kk[1 + N], u_, l_, r_;

int node(int k) {
	static int _ = 1;

	zz[_] = rand_();
	kk[_] = k;
	return _++;
}

void split(int u, int k) {
	int c;

	if (u == 0) {
		u_ = l_ = r_ = 0;
		return;
	}
	c = cmp(kk[u], k);
	if (c < 0) {
		split(rr[u], k);
		rr[u] = l_, l_ = u;
	} else if (c > 0) {
		split(ll[u], k);
		ll[u] = r_, r_ = u;
	} else {
		u_ = u, l_ = ll[u], r_ = rr[u];
		ll[u] = rr[u] = 0;
	}
}

int merge(int u, int v) {
	if (u == 0)
		return v;
	if (v == 0)
		return u;
	if (zz[u] < zz[v]) {
		rr[u] = merge(rr[u], v);
		return u;
	} else {
		ll[v] = merge(u, ll[v]);
		return v;
	}
}

int first(int u) {
	return ll[u] == 0 ? u : first(ll[u]);
}

int last(int u) {
	return rr[u] == 0 ? u : last(rr[u]);
}

int kbad;

void tr_add(int i) {
	if (u_ == 0)
		u_ = node(i);
	else {
		int l, r;

		split(u_, i);
		l = kk[l_ ? last(l_) : last(r_)], r = kk[r_ ? first(r_) : first(l_)];
		kbad += bad(l, i) + bad(i, r) - bad(l, r);
		u_ = merge(merge(l_, node(i)), r_);
	}
}

void tr_remove(int i) {
	if (ll[u_] == 0 && rr[u_] == 0)
		u_ = 0;
	else {
		int l, r;

		split(u_, i);
		l = kk[l_ ? last(l_) : last(r_)], r = kk[r_ ? first(r_) : first(l_)];
		kbad -= bad(l, i) + bad(i, r) - bad(l, r);
		u_ = merge(l_, r_);
	}
}

int main() {
	int n, q, h, x0, y0, z0, w0, k1;
	long long k2;

	scanf("%d%d%d%d", &x0, &y0, &z0, &q), w0 = x0 + y0 + z0;
	for (h = 0; h < M; h++) {
		ox[h] = (long long *) malloc(2 * sizeof *ox[h]);
		oy[h] = (long long *) malloc(2 * sizeof *oy[h]);
		oc[h] = (int *) malloc(2 * sizeof *oc[h]);
	}
	n = 0, k1 = 0, k2 = 0, kbad = 0;
	while (q--) {
		static char s[2];

		scanf("%s", s);
		if (s[0] == 'A') {
			int x, y, z, w;
			long long x_, y_, d;

			scanf("%d%d%d", &x, &y, &z), w = x + y + z;
			x_ = (long long) x * w0 - (long long) x0 * w;
			y_ = (long long) y * w0 - (long long) y0 * w;
			d = gcd(abs_(x_), abs_(y_));
			if (d != 0)
				x_ /= d, y_ /= d;
			xx[n] = x_, yy[n] = y_, n++;
			if (xx[n - 1] == 0 && yy[n - 1] == 0)
				k1++;
			else {
				k2 += ht_get(-x_, -y_);
				ht_add(x_, y_, 1);
				tr_add(n - 1);
			}
		} else {
			int i;

			scanf("%d", &i), i--;
			if (xx[i] == 0 && yy[i] == 0)
				k1--;
			else {
				ht_add(xx[i], yy[i], -1);
				k2 -= ht_get(-xx[i], -yy[i]);
				tr_remove(i);
			}
		}
		printf(k1 > 0 ? "1\n" : (k2 > 0 ? "2\n" : ((ll[u_] || rr[u_]) && kbad == 0 ? "3\n" : "0\n")));
	}
	return 0;
}


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

int main() {
	int n, e, o;

	scanf("%d", &n);
	if (n <= 5) {
		printf(n == 3 ? "0\n" : "1\n");
		return 0;
	}
	e = 4, o = 5;
	if (e < n && o < n) {
		int o_ = e + e + 1;
		int e_ = e + o + 1;

		e = e_, o = o_;
		if (e == n || o == n) {
			printf("1\n");
			return 0;
		}
	}
	printf("0\n");
	return 0;
}


#include<stdio.h>

#define MOD 998244353
int fact[1000006];

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}

int powmod(int p, int b){
  int t = 1;
  while(p){
    if(b&1)t = mul(t, b);
    b = mul(b, b);
    p>>=1;
  }
  return t;
}

int ncr(int n, int r){
  return mul(mul(fact[n], powmod(fact[r], MOD - 2)), powmod(fact[n - r], MOD - 2));
}

int main(){
  int n, levels, i;
  scanf("%d", &n);
  fact[0]  = 0;
  for(i = 1;i < 1000006;i++)fact[i] = mul(fact[i - 1], i);
  if(n == 1 || n == 2 || n == 4 || n == 5 ){printf("1\n");return 0;}
  if(n == 3 || n == 6 || n == 7){printf("0\n");return 0;}
  for(levels = 0; (1<<levels) - 1 < n;levels++);
  levels -= 2;
  int lcls = (1<<(levels - 1));
  int rcls = lcls;
  int left = n + 1 - (1<<(levels + 1));
  left -= rcls;
  if(left < 0 || left&1 || left > rcls){printf("0\n");return  0;}
  printf("%d\n", ncr(lcls, left/2));
  return 0;
}


#include<stdio.h>

#define MOD 998244353
int fact[1000006];

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}

int powmod(int p, int b){
  int t = 1;
  while(p){
    if(b&1)t = mul(t, b);
    b = mul(b, b);
    p>>=1;
  }
  return t;
}

int ncr(int n, int r){
  return mul(mul(fact[n], powmod(fact[r], MOD - 2)), powmod(fact[n - r], MOD - 2));
}

int main(){
  int n, levels, i;
  scanf("%d", &n);
  fact[0]  = 0;
  for(i = 1;i < 1000006;i++)fact[i] = mul(fact[i - 1], i);
  if(n == 1 || n == 2 || n == 4 || n == 5 ){printf("1\n");return 0;}
  if(n == 3 || n == 6 || n == 7){printf("0\n");return 0;}
  for(levels = 0; (1<<levels) - 1 < n;levels++);
  levels -= 2;
  int lcls = (1<<(levels - 1));
  int rcls = lcls;
  int left = n + 1 - (1<<(levels + 1));
  left -= rcls;
  if(left < 0 || left&1 || left/2 > rcls){printf("0\n");return  0;}
  printf("%d\n", ncr(lcls, left/2));
  return 0;
}


#include<stdio.h>

#define MOD 998244353
int fact[1000006], wpar[1000006<<1], n, level;

int mul(int a, int b){
  return (a*1ll*b)%MOD;
}

int powmod(int b, int p){
  int t = 1;
  while(p){
    if(p&1)t = mul(t, b);
    b = mul(b, b);
    p>>=1;
  }
  return t;
}

int ncr(int _n, int r){
  return mul(mul(fact[_n], powmod(fact[r], MOD - 2)), powmod(fact[_n - r], MOD - 2));
}

void dfs(int x, int bits){
  if(bits > level) return;
  int l, r;
  l = x<<1;
  r = l|1;
  if(x&1){
    // x is a right child
    wpar[l] = 1;
    wpar[r] = 1^wpar[x]^wpar[l];
  } else {
    // x is a left child
    wpar[r] = 0;
    wpar[l] = 1^wpar[x]^wpar[r];
  }
  dfs(l, bits + 1);
  dfs(r, bits + 1);
}

int getpossib(int lparity){
  int i, rem;
  wpar[2] = lparity;
  wpar[3] = 1^wpar[1]^wpar[2];
  dfs(2, 2);dfs(3, 2);

  rem = n - (1<<level) + 1;

  for(i = (1<<(level - 1));i < (1<<level);i++){
    //    printf("wpar[%d]: %d\n", i, wpar[i]);
    if(i&1){
      if(wpar[i]) return 0;
      rem--;
    } else {
      if(1^wpar[i]) rem--;
    }
  }
  return rem == 0;
}

int main(){
  int i;
  scanf("%d", &n);

  fact[0] = 1;
  for(i = 1;i < 1000006;i++)fact[i] = mul(fact[i - 1], i);

  if(n == 1 || n == 2){printf("1\n");return 0;}
  if(n == 3){printf("0\n");return 0;}

  for(level = 0; (1<<level) - 1 < n;level++);
  level--;

  wpar[1] = n&1;
  printf("%d\n", getpossib(0) + getpossib(1));

  return 0;
}


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

int main() {
	int n, e, o;

	scanf("%d", &n);
	if (n <= 5) {
		printf(n == 3 ? "0\n" : "1\n");
		return 0;
	}
	e = 4, o = 5;
	while (e < n && o < n) {
		int o_ = e + e + 1;
		int e_ = e + o + 1;

		e = e_, o = o_;
		if (e == n || o == n) {
			printf("1\n");
			return 0;
		}
	}
	printf("0\n");
	return 0;
}


#include<stdio.h>
int color[6];
int main(void)
{
  int i,one,two,three,four,five,six;
  char ch[10];
  while(scanf("%s",ch)!=EOF)
  {
    for(i=0;i<6;++i) color[i]=0;
    for(i=0;i<6;++i)
    {
      switch(ch[i])
      {
        case 'R': ++color[0];break;
        case 'O': ++color[1];break;
        case 'Y': ++color[2];break;
        case 'G': ++color[3];break;
        case 'B': ++color[4];break;
        case 'V': ++color[5];break;
      }
    }
    for(i=one=two=three=four=five=six=0;i<6;++i)
    {
      switch(color[i])
      {
        case 1: ++one;break;
        case 2: ++two;break;
        case 3: ++three;break;
        case 4: ++four;break;
        case 5: ++five;break;
        case 6: ++six;break;
      }
    }
    if(one==6) puts("30");
    else if(one==4) puts("15");
    else if(one==3) puts("5");
    else if(one==2)
    {
      if(four==1) puts("2");
      else puts("8");
    }
    else if(one==1)
    {
      if(five==1) puts("1");
      else puts("3");
    }
    else
    {
      if(six==1) puts("1");
      else
      {
        if(two==1&&four==1) puts("2");
        else if(three==2) puts("2");
        else if(two==3) puts("6");
      }
    }
  }
  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 SixSidedDieState[24][3]={
  0,1,2,  0,2,4,  0,4,3,  0,3,1,
  1,5,2,  1,2,0,  1,0,3,  1,3,5,
  2,1,5,  2,5,4,  2,4,0,  2,0,1,
  3,1,0,  3,0,4,  3,4,5,  3,5,1,
  4,0,2,  4,2,5,  4,5,3,  4,3,0,
  5,3,4,  5,4,2,  5,2,1,  5,1,3
};

int SixSidedDieRotateCenter[24]={
   1, 2, 3, 0,
   5, 6, 7, 4,
   9,10,11, 8,
  13,14,15,12,
  17,18,19,16,
  21,22,23,20
};

int SixSidedDieRotateRight[24]={
  12, 5,10,19,
  15,22,11, 3,
   0, 4,21,16,
  23, 6, 2,18,
  13, 1, 9,20,
   7,14,17, 8
};

int SixSidedDieRotateLeft[24]={
  16,13, 6,11,
   0,12,23, 8,
  17, 1, 5,22,
  19,20, 7, 3,
  21,14, 2,10,
   9, 4,15,18
};

int die[24][6],center[24],right[24],left[24],center3[24],right3[24],left3[24];
void dieInit(){
  int i,j;
  rep(i,24){
    rep(j,3) die[i][j] = SixSidedDieState[i][j];
    REP(j,3,6) die[i][j] = 5-SixSidedDieState[i][5-j];
    center[i] = SixSidedDieRotateCenter[i];
    right[i]  = SixSidedDieRotateRight[i];
    left[i]   = SixSidedDieRotateLeft[i];
  }
  rep(i,24){
    center3[i]= center[center[center[i]]];
    right3[i] = right[right[right[i]]];
    left3[i]  = left[left[left[i]]];
  }
}

#define ll long long
#define ull unsigned ll

#define ULL_HASH_SIZE 2000
ull ull_hash_n[ULL_HASH_SIZE]; int ull_hash_d[ULL_HASH_SIZE];

void ullHashClear(void){ memset(ull_hash_d,0,ULL_HASH_SIZE*sizeof(int)); }
int ullHashFunction(ull a){ return (a*1007)%ULL_HASH_SIZE; }

int ullHashGet(ull a){
  int i=ullHashFunction(a);
  for(;;){
    if(ull_hash_n[i]==a && ull_hash_d[i]) break;
    if(!ull_hash_d[i]) break;
    i++; if(i==ULL_HASH_SIZE) i=0;
  }
  if(ull_hash_n[i]!=a) return 0; return ull_hash_d[i];
}

void ullHashSet(ull a,int n){
  int i=ullHashFunction(a);
  for(;;){
    if(ull_hash_n[i]==a && ull_hash_d[i]) break;
    if(!ull_hash_d[i]) break;
    i++; if(i==ULL_HASH_SIZE) i=0;
  }
  ull_hash_n[i]=a; ull_hash_d[i]=n;
}

int ullHashIncrease(ull a){
  int i=ullHashFunction(a);
  for(;;){
    if(ull_hash_n[i]==a && ull_hash_d[i]) break;
    if(!ull_hash_d[i]) break;
    i++; if(i==ULL_HASH_SIZE) i=0;
  }
  ull_hash_n[i]=a; return ++ull_hash_d[i];
}

void intSort(int d[],int s){int i=-1,j=s,k,t;if(s<=1)return;k=(d[0]+d[s-1])/2;for(;;){while(d[++i]<k);while(d[--j]>k);if(i>=j)break;t=d[i];d[i]=d[j];d[j]=t;}intSort(d,i);intSort(d+j+1,s-j-1);}
void intReverse(int d[],int size){int a=0,b=size-1,t;while(a<b)t=d[a],d[a]=d[b],d[b]=t,a++,b--;}
int intNextPermutation(int d[],int size){int i,j,k;for(k=size-2;k>=0;k--)if(d[k]<d[k+1])break;if(k<0){intReverse(d,size);return 0;}for(i=size-1;;i--)if(d[i]>d[k])break;j=d[i],d[i]=d[k],d[k]=j;intReverse(d+k+1,size-k-1);return 1;}

int main(){
  int i,j,k,l,m,n;
  int res;
  char tmp[10];
  int in[10], go[10];
  ull hs, mx;

  dieInit();
  while(scanf("%s",tmp)==1){
    ullHashClear();
    res = 0;

    rep(i,6) in[i] = tmp[i];
    intSort(in,6);

    do{
      mx = 0;
      rep(i,24){
        rep(k,6) go[k] = in[die[i][k]];
        hs = 0;
        rep(k,6) hs = hs * 1007 + go[k];
        if(mx < hs) mx = hs;
      }
      if( ullHashIncrease(mx)==1 ) res++;
    }while(intNextPermutation(in,6));

    printf("%d\n",res);
  }

  return 0;
}


#include <stdio.h>

int main()
{
  int num[6];
  char ans[6];
  char t[7];
  int n,i,j,temp;

  scanf("%s",&t);
  n=0;
  for(i=0;i<6;i++)num[i]=0;
  for(i=0;i<6;i++)
     {
      for(j=0;j<n;j++)
         {
          if(ans[j]==t[i])break;
         }
      num[j]++;
      if(j==n)ans[n++]=t[i];
     }

  for(i=0;i<n;i++)
     {
      for(j=i+1;j<n;j++)
         {
          if(num[j]>num[i])
             {
              temp=num[j];
              num[j]=num[i];
              num[i]=temp;
             }
         }
     }
  if(n==6)
     {
      puts("30");
     }
  else if(n==1)
     {
      puts("1");
     }
  else if(n==5)
     {
      puts("15");
     }
  else if(n==4)
     {
      if(num[0]==3)puts("5");
      else puts("8");
     }
  else if(n==3)
     {
      if(num[0]==4)puts("2");
      else if(num[0]==2)puts("6");
      else puts("3");
     }
  else
     {
      if(num[0]==5)puts("1");
      else puts("2");
     }
  system("PAUSE");
  return 0;
}


#include<stdio.h>
#include<math.h>
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define M 1000000007
#define N 211111

#define maxN 555

int n, k;
int dp[maxN][maxN], dp2[maxN][maxN];
int w[maxN];

int add(int x, int y) {
	x += y;
	if (x >= M) x-= M;
	return (x);
}

int min(int a, int b)
	{
		if(a<b)return a;
		else return b;
	}

int main(){
	scanf("%d %d", &n, &k);
	w[0] = 1;
	int i,j,d;
	for ( i = 1; i <= n; i++) w[i] = w[i - 1] * 2 % M;
	dp[0][0] = 1;
	for ( i = 0; i < n; i++) {
		for ( j = 0; j <= n; j++) for ( d = 0; d <= k + 1; d++) dp2[j][d] = 0;
		for ( j = 0; j <= n; j++) for ( d = 0; d <= k + 1; d++) if (dp[j][d] > 0) {
			if (j > i) {
				int e = i + 1;
				int z = dp[j][d] * 1ll * w[e] % M;
				dp2[j][d]=(dp2[j][d], z);
				continue;
			}
			int z = (w[i - j + 1] - 1 + M);
			if (z >= M) z -= M;
			z = z * 1ll * w[j] % M;
			z = z * 1ll * dp[j][d] % M;
			dp2[i + 1][min(d + 1, k + 1)]=add(dp2[i + 1][min(d + 1, k + 1)], z);
			z = dp[j][d] * 1ll * w[j] % M;
			dp2[j][d]=add(dp2[j][d], z);
		}
		for ( j = 0; j <= n; j++) for (d = 0; d <= k + 1; d++) dp[j][d] = dp2[j][d];
	}
	int ans = 0;
	for ( i = 0; i <= n; i++) ans=add(ans, dp[i][k]);
	printf("%d\n",ans);
	return 0;

}


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

#define  maxn 505
#define  P 1000000007

int n, k, mi2[maxn * maxn], dp[maxn][maxn], ans = 0;
int main() {
    scanf("%d%d", &n, &k);
    int i,j,l;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1, mi2[0] = 1;

    for (i = 1; i <= n * n; i++)    mi2[i] = 2ll * mi2[i - 1] % P;

    for (i = 1; i <= n; i ++)
        for ( j = 1; j <= k; j ++)
            for (l = 0; l < i; l ++)
                dp[i][j] = (dp[i][j] + 1ll * dp[l][j - 1] * (mi2[i - l] - 1) % P * mi2[(i - l) * l] % P) % P;
    for (i = 0; i <= n; i ++)
        ans = (ans + 1ll * dp[i][k] * mi2[(n - i) * i]) % P;
    printf("%d\n", (ans + P) % P);

      return 0;

}


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

#define N	1000000
#define MD	1000000007

long long ff[N], gg[N], pn[N], pm[N];

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

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

void init(int n, int m) {
	long long f, p;
	int i;

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

long long cayley(int n, int k) {
	return k == n ? 1 : k * pn[n - k - 1] % MD;
}

int main() {
	int n, m, a, b, k;
	long long ans;

	scanf("%d%d%d%d", &n, &m, &a, &b);
	init(n, m);
	ans = 0;
	for (k = 0; k <= n - 2 && k < m; k++) {
		/* choose(n - 2, k) * factorial(k) */
		long long path = ff[n - 2] * gg[n - 2 - k] % MD;
		/* choose(m - 1, k) * power(m, n - k - 2) */
		long long edges = ff[m - 1] % MD * gg[k] % MD * gg[m - 1 - k] % MD
			* pm[n - k - 2] % MD;

		ans = (ans + path * cayley(n, k + 2) % MD * edges) % MD;
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define N	100000
#define MD	1000000007

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

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

long long cayley(int n, int k) {
	return k == n ? 1 : k * power(n, n - k - 1) % MD;
}

int main() {
	static long long ff[N], gg[N];
	int n, m, a, b, k, i;
	long long f, ans;

	scanf("%d%d%d%d", &n, &m, &a, &b);
	f = 1;
	for (i = 0; i < N; i++) {
		ff[i] = f;
		gg[i] = power(f, MD - 2);
		f = f * (i + 1) % MD;
	}
	ans = 0;
	for (k = 0; k <= n - 2 && k < m; k++) {
		/* choose(n - 2, k) * factorial(k) */
		long long path = ff[n - 2] * gg[n - 2 - k] % MD;
		/* choose(m - 1, k) * power(m, n - k - 2) */
		long long edges = ff[m - 1] % MD * gg[k] % MD * gg[m - 1 - k] % MD
			* power(m, n - k - 2) % MD;

		ans = (ans + path * cayley(n, k + 2) % MD * edges) % MD;
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define N	8

int compare(const void *a, const void *b) {
	long long la = *(long long *) a;
	long long lb = *(long long *) b;

	return la == lb ? 0 : la < lb ? -1 : 1;
}

long long aa[N], aa_[N];
int bb[N], dp[N][1 << (N - 1)];
char pp[N];
int n, ans = 0x3f3f3f3f;

void solve(int i) {
	int j;

	if (i == n) {
		int cnt, sum;

		cnt = 0, sum = 0;
		for (i = 0; i < n; i++) {
			int k;

			if (!pp[i])
				cnt++;
			k = dp[i][bb[i]];
			sum += k == 1 && bb[i] == 0 ? 1 : k + 1;
		}
		if (cnt >= 2)
			sum++;
		if (ans > sum)
			ans = sum;
		return;
	}
	solve(i + 1);
	pp[i] = 1;
	for (j = i + 1; j < n; j++)
		if (aa_[j] % aa[i] == 0) {
			aa_[j] /= aa[i], bb[j] ^= 1 << i;
			solve(i + 1);
			aa_[j] *= aa[i], bb[j] ^= 1 << i;
		}
	pp[i] = 0;
}

int main() {
	int i, j;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%lld", &aa[i]);
	qsort(aa, n, sizeof *aa, compare);
	for (i = 0; i < n; i++) {
		long long a;
		int k, p, b;

		a = aa[i];
		k = 0;
		for (p = 2; p <= a / p; p++)
			while (a % p == 0) {
				k++;
				a /= p;
			}
		if (a > 1)
			k++;
		dp[i][0] = k;
		for (b = 1; b < 1 << i; b++) {
			a = aa[i];
			k = dp[i][0];
			for (j = 0; j < i; j++)
				if ((b & 1 << j)) {
					if (a % aa[j] != 0) {
						k = -1;
						break;
					}
					a /= aa[j];
					k -= dp[j][0];
				}
			dp[i][b] = k;
		}
	}
	for (i = 0; i < n; i++)
		aa_[i] = aa[i];
	solve(0);
	printf("%d\n", ans);
	return 0;
}


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

#define N	8

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

long long aa[N], aa_[N];
int bb[N], dp[N][1 << (N - 1)];
char pp[N];
int n, ans = 0x3f3f3f3f;

void solve(int i) {
	int j;

	if (i == n) {
		int cnt, sum;

		cnt = 0, sum = 0;
		for (i = 0; i < n; i++) {
			int k;

			if (!pp[i])
				cnt++;
			k = dp[i][bb[i]];
			sum += k == 1 && bb[i] == 0 ? 1 : k + 1;
		}
		if (cnt >= 2)
			sum++;
		if (ans > sum)
			ans = sum;
		return;
	}
	solve(i + 1);
	pp[i] = 1;
	for (j = i + 1; j < n; j++)
		if (aa_[j] % aa[i] == 0) {
			aa_[j] /= aa[i], bb[j] ^= 1 << i;
			solve(i + 1);
			aa_[j] *= aa[i], bb[j] ^= 1 << i;
		}
	pp[i] = 0;
}

int main() {
	int i, j, p, b;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%lld", &aa[i]);
	qsort(aa, n, sizeof *aa, compare);
	for (i = 0; i < n; i++) {
		long long a;
		int k;

		a = aa[i];
		k = 0;
		for (p = 2; p <= a / p; p++)
			while (a % p == 0) {
				k++;
				a /= p;
			}
		if (a > 1)
			k++;
		dp[i][0] = k;
		for (b = 1; b < 1 << i; b++) {
			a = aa[i];
			k = dp[i][0];
			for (j = 0; j < i; j++)
				if ((b & 1 << j)) {
					if (a % aa[j] != 0) {
						k = -1;
						break;
					}
					a /= aa[j];
					k -= dp[j][0];
				}
			dp[i][b] = k;
		}
	}
	for (i = 0; i < n; i++)
		aa_[i] = aa[i];
	solve(0);
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>
#define MOD 1000000007

int K;
long long PA,PB,ans;

long long INV1,INV2;
long long f[1010][2010];

long long power(long long a,int b)
{
    long long y = 1;
    for(;b;b>>=1)
    {
        if(b&1) y = y * a % MOD;
        a = a * a % MOD;
    }
    return y;
}

int main()
{
    int i,j;
    long long x,y;

    scanf("%d%I64d%I64d",&K,&PA,&PB);
    INV1 = power(PA+PB,MOD-2);
    INV2 = power(PB,MOD-2);

    f[1][0] = 1;
    for(i=1;i<=K;i++) for(j=(i==1);j<=2*K;j++)
    {
        if(j < K) f[i][j] = f[i-1][j] * PA % MOD * INV1 % MOD;
        if(j >= i && j-i < K) f[i][j] = (f[i][j] + f[i][j-i] * PB % MOD * INV1) % MOD;
    }

    for(i=1;i<K;i++) for(j=K;j<=2*K;j++) ans = (ans + j*f[i][j]) % MOD;
    for(i=0;i<K;i++) ans = (ans + (PA*INV2 + K+i) % MOD * f[K][i]) % MOD;

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


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

#define N	5000
#define INF	0x3f3f3f3f3f3f3f3fLL

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

int main() {
	static long long dp[N];
	int n, a, c, e, i, j;
	long long b, d, s, t, u, ans;

	scanf("%d%lld%d%lld%d%d", &a, &b, &c, &d, &n, &e), a -= e, c -= e;
	memset(dp, 0x3f, n * sizeof *dp), dp[0] = 0;
	ans = INF;
	for (i = 0; i < n; i++) {
		s = dp[i], t = dp[i], u = dp[i], j = i;
		while (j < n) {
			if (j + a + c + e < n)
				dp[j + a + c + e] = min(dp[j + a + c + e], max(s + b, t + d));
			else
				ans = min(ans, max(s + b, t + d));
			if (s + b < t + d)
				j += a, u = s += b;
			else
				j += c, u = t += d;
		}
		ans = min(ans, u);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <stdio.h>

#define N	1000000
#define MD	998244353
#define V2	499122177
#define V6	166374059

int f2(int n) {
	return (long long) n * (n + 1) % MD * V2 % MD;
}

int f3(int n) {
	return (long long) n * (n + 1) % MD * (n + 2) % MD * V6 % MD;
}

int main() {
	static int dp[N], dq[N];
	int n, i, x, y, z, single2, single3, pair, ans;

	scanf("%d", &n);
	dp[0] = dq[0] = 1;
	for (i = 1; i < n; i++) {
		dp[i] = (dp[i - 1] + f2(dp[i - 1]) + (i == 1 ? 0 : (long long) dp[i - 1] * dq[i - 2])) % MD;
		dq[i] = (dq[i - 1] + dp[i]) % MD;
	}
	x = dp[n - 1], y = n == 1 ? 0 : dq[n - 2];
	single2 = (f2(x) + (long long) x * y % MD) % MD;
	single3 = (f3(x) + (long long) f2(x) * y % MD + (long long) x * f2(y) % MD) % MD;
	pair = 0;
	for (i = 0; i < n; i++) {
		if (i == 0)
			z = 1;
		else {
			x = dp[i - 1], y = i == 1 ? 0 : dq[i - 2];
			z = (f2(x) + (long long) x * y % MD) % MD;
		}
		pair = (pair + (long long) z * dp[n - 1 - i]) % MD;
	}
	ans = ((long long) single2 * 2 + single3 * 2 + pair) % MD;
	if (ans < 0)
		ans += MD;
	printf("%d\n", ans);
	return 0;
}


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

int main() {
    int R,B,i,j;
    scanf("%d %d",&R,&B);
    int x[R],y[R],a[B],b[B];
    for(i=0;i<R;i++) {
        scanf("%d %d",&x[i],&y[i]);
    }
    for(i=0;i<B;i++) {
        scanf("%d %d",&a[i],&b[i]);
    }
    if(R!=B) {
        printf("NO");
    }else
        printf("YES");

    return 0;
}


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

typedef long long LL;
bool inuse[10];
int x[2][10], y[2][10], R, B, guarding[10];

long long cprodukt(int x1, int y1, int x2, int y2, int x3, int y3){
	return (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1);
}

bool cross(int g1, int s1, int g2, int s2){
	return (
		cprodukt(x[0][g1], y[0][g1], x[1][s1], y[1][s1], x[0][g2], y[0][g2])
		*
		cprodukt(x[0][g1], y[0][g1], x[1][s1], y[1][s1], x[1][s2], y[1][s2])
		<0)
		&&
		(
		cprodukt(x[0][g2], y[0][g2], x[1][s2], y[1][s2], x[0][g1], y[0][g1])
		*
		cprodukt(x[0][g2], y[0][g2], x[1][s2], y[1][s2], x[1][s1], y[1][s1])
		<0);
}

bool pos(int d){
	if(d==R) return true;
	for(int i=0;i<R;++i){
		if(inuse[i]) continue;
		inuse[i]=true;
		guarding[d]=i;
		for(int j=0;j<d;++j) if(cross(j, guarding[j], d, i)) continue;
		if(pos(d+1)) return true;
		inuse[i]=false;
		guarding[d]=-1;
	}
	return false;
}

int main(){
	scanf("%d %d", &R, &B);
	if(R!=B){
		puts("NO");
		return 0;
	}
	for(int j=0;j<2;++j) for(int i=0;i<R;++i) scanf("%d %d", x[j]+i, y[j]+i);
	if(pos(0)) puts("YES");
	else puts("NO");
	return 0;
}


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

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

char S[MAX], T[MAX];
bool visited[MAX][MAX];
int n, m, dp[MAX][MAX], next[MAX][MAX];

int F(int i, int j){
    if (i >= n || j >= m) return 0;
    if (visited[i][j]) return dp[i][j];

    long long res = 0;
    if (next[i][j] != -1){
        res = res + F(i + 1, next[i][j] + 1) + 1;
        res = res + F(i, next[i][j] + 1);
    }

    visited[i][j] = true;
    return (dp[i][j] = (res % MOD));
}

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

    while (scanf("%s %s", S, T) != EOF){
        clr(visited);
        n = strlen(S), m = strlen(T);
        memset(next, -1, sizeof(next));
        for (i = 0; i < n; i++){
            for (j = m - 1; j >= 0; j--){
                if (S[i] == T[j]) next[i][j] = j;
                else if ((j + 1) != m) next[i][j] = next[i][j + 1];
            }
        }

        long long res = 0;
        for (i = 0; i < n; i++){
            for (j = 0; j < m; j++){
                if (S[i] == T[j]){
                    res = res + F(i + 1, j + 1) + 1;
                }
            }
        }
        printf("%lld\n", res % MOD);
    }
    return 0;
}


#include<stdio.h>
char mp[9][9];
int dir;
int n,m,x,y;
int get_dis(int dir){
  if(dir==0&&y==m)return 100;
  if(dir==1&&x==n)return 100;
  if(dir==0){
    for(int i=y+1;i<=m;i++)
      if(mp[x][i]=='*')return i-y;
  }else
    for(int i=x+1;i<=n;i++)
      if(mp[i][y]=='*')return i-x;
  return 100;
}

int main(void){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
  dir=0;
  int ans=0;
  x=1;y=1;
  for(int i=0;i<n+m;i++){
    if(mp[x][y]=='*')ans++;
    //    printf("%d %d\n",x,y);
    if(get_dis(dir)<get_dis(!dir)){
      if(dir==0)y++;
      else x++;
    }else if(get_dis(dir)>get_dis(!dir)){
      if(dir==0)
	x++;
      else
	y++;
      dir=!dir;
    }else{
      x++;
    }
  }
  printf("%d\n",ans);
  return 0;
}


// write in C...
#include <stdio.h>

#ifdef DEBUG
#define D(x...) fprintf(stderr, x)
#else
#define D(x...)
#endif

#define MOD 1000000009

int n, w, b;
int c[4005][4005];

int p(int n, int k) {
    if (k > n || k < 1) return 0;
    else return c[n-1][k-1];
}

int main() {
    int i, j;

    scanf("%d %d %d", &n, &w, &b);

    for (i = 0; i < 4005; i++) c[i][0] = 1;
    for (i = 1; i < 4005; i++)
        for (j = 1; j <= i; j++)
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD;

    long long res = 0;

    for (i = 0; i <= n; i++) {
        res = (res + (((((long long)p(b, i) * (long long)p(w, n-i))%MOD) * (long long)(n-i-1))%MOD)) % MOD;
    }

    for (i = 1; i <= w; i++) res = (res * i) % MOD;
    for (i = 1; i <= b; i++) res = (res * i) % MOD;

    printf("%d\n", (int)res);

    return 0;
}


#include <stdio.h>

int main(){

	int n,m;
	scanf("%d %d",&n,&m);
	int b;
	if(n>m){
		b=n;
		n=m;
		m=b;
	}
	if(n==1){
		int mo=m%6;
		switch(mo){
			case 0:printf("%d\n",m);break;
			case 1:printf("%d\n",m-mo);break;
			case 2:printf("%d\n",m-mo);break;
			case 3:printf("%d\n",m-mo);break;
			case 4:printf("%d\n",m-2);break;
			case 5:printf("%d\n",m-1);
		}
	}
	else if(n==2){
		if(m==2){
			printf("%d\n",0);
		}
		else if(m==3){
			printf("%d\n",4);
		}
		else if(m==7){
			printf("%d\n",12);
		}
		else{
			printf("%d\n",n*m);
		}
	}
	else{
		long long mul=n;
		mul*=m;
		if(mul%2==0){
			printf("%lld\n",mul);
		}
		else{
			printf("%lld\n",mul-1);
		}
	}

	return 0;
}


#include <stdio.h>

#define N	400

int md;

int ff[N + 1];

void init() {
	int n;

	ff[0] = 1;
	for (n = 1; n <= N; n++)
		ff[n] = (long long) ff[n - 1] * n % md;
}

int main() {
	static int dp[N + 1];
	int n, i, j, ans;

	scanf("%d%d", &n, &md), init();
	ans = 0;
	dp[0] = 1;
	for (i = 1; i <= n; i++) {
		for (j = n; j >= 0; j--)
			dp[j] = ((j == 0 ? 0 : dp[j - 1]) + (long long) dp[j] * j * 2) % md;
		ans = (ans + (long long) dp[n - i + 1] * ff[n - i + 1]) % md;
	}
	printf("%d\n", ans);
	return 0;
}


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

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

int maximum(int a, int b)
{
     if (a > b) {
	  return a;
     } else {
	  return b;
     }
}

int minimum(int a, int b)
{
     if (a < b) {
	  return a;
     } else {
	  return b;
     }
}

int main()
{
     int a[2000];
     int p = 0, q = 1, x = 1, i, j;
     int pl, pr, vl, vr, k;
     long long c = 0, d;

     a[0] = 0;

     for (i = 0; i < 9; i++) {
	  for (j = p; j < q; j++) {
	       a[x++] = a[j] * 10 + 4;
	       a[x++] = a[j] * 10 + 7;
	  }

	  p = q; q = x;
     }

     qsort(a, x, sizeof(int), cmp);

     a[x] = 1000000001;

     scanf("%d %d %d %d %d", &pl, &pr, &vl, &vr, &k);

     d = (long long)(pr - pl + 1) * (vr - vl + 1);

     for (i = 1; i <= x - k; i++) {
	  if (pl <= a[i] && vr >= a[i + k - 1]) {
	       int s1 = minimum(a[i], pr);
	       int s2 = maximum(a[i - 1] + 1, pl);
	       int t1 = maximum(a[i + k - 1], vl);
	       int t2 = minimum(a[i + k] - 1, vr);

	       if (s1 - s2 >= 0 && t2 - t1 >= 0) {
		    c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1);
	       }
	  }
	  if (vl <= a[i] && pr >= a[i + k - 1]) {
	       int s1 = minimum(a[i], vr);
	       int s2 = maximum(a[i - 1] + 1, vl);
	       int t1 = maximum(a[i + k - 1], pl);
	       int t2 = minimum(a[i + k] - 1, pr);

	       if (s1 - s2 >= 0 && t2 - t1 >= 0) {
		    c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1);
	       }
	  }
     }

     if (k == 1) {
	  for (i = 1; i < x; i++) {
	       if (pl <= a[i] && pr >= a[i] && vl <= a[i] && vr >= a[i]) c--;
	  }
     }

     printf("%.20lf\n", (double)c / d);

     return 0;
}


#include <stdio.h>
int checkIsLucky(int num){
    while(num>0){
        if(num%10!=4&&num%10!=7)return 0;
        num/=10;
    }
    return 1;
}
int nextNum(int num){
    int nextN;
    int count=1;
    int maxNextD=0;
    nextN=num;
    if(num>=777777777) return 1000000001;
    while(num>0){
        if(num%10==4){
            nextN+=count*3;
            nextN=nextN/(count)*count+maxNextD;
            break;
        }else{
            maxNextD*=10;
            maxNextD+=4;
            num/=10;
            count*=10;
        }
    }
    if(num>0) return nextN;
    else{
        maxNextD*=10;
        maxNextD+=4;
        return maxNextD;
    }
}

int max(int a,int b){
    if(a>b) return a;
    else return b;
}
int min(int a,int b){
    if(a>b) return b;
    else return a;
}
int kthNum(int begin,int k){
    int count=1;
    int rt=0,tmp=begin;
    while (tmp>0) {
        tmp/=10;
        rt*=10;
        rt+=4;
    }
    while(rt<begin)rt=nextNum(rt);
    for(;count<k;count++){
        rt=nextNum(rt);
    }
    return rt;
}
int ma,mi;
double lenthRt(unsigned a,unsigned b,unsigned lk1,unsigned lk2){
    mi=max(a,lk1);
    ma=min(b,lk2);
    double kq;
    if(ma<mi) return 0;
    else {
        if(lk2==ma){
            kq=ma-mi;
            return kq;
        }

        kq= ma-mi+1;
        return kq;
    }
}
int main(){
    int pl,pr,vl,vr,k;
    int minN,maxN,lk1,lk2,i,after;
    double sum=0;

    double kq,mau;
    //pl=5;pr=6;
    //vl=8;vr=10;k=1;
    //printf("%d",nextNum(47));
    /*for(i=4;i<1000000000;i=nextNum(i)){
            printf("%d\n",i);

    }*/
    scanf("%d %d %d %d %d",&pl,&pr,&vl,&vr,&k);
    minN=min(pl,vl);
    maxN=max(pr,vr);

    //for p
    after=kthNum(pl,1);
    if(k==1){
        for(i=after;i<=pr;i=nextNum(i)) {
            //printf("%d\n",i);
            if(i>=vl&&i<=vr) sum-=1;
            getchar();
        }
    }
    lk1= kthNum(pl,k);
    lk2= nextNum(lk1);
    i=pl;
    for(;i<=pr;){//xet tat ca cac chu so trong [pl+1,pr]
        sum+=lenthRt(vl,vr,lk1,lk2)*min(after-i+1,pr-i+1);
        //printf("%d to %d-> %d %d + them %lf*%d->%lf\n",i,after,lk1,lk2,lenthRt(vl,vr,lk1,lk2),min(after-i+1,pr-i+1),sum);

        i=after+1;
        after=nextNum(after);
        lk1=lk2;
        if(lk1>vr) break;
        lk2=nextNum(lk2);
    }
    //if k==1

    //for p
    after=kthNum(vl,1);
    lk1= kthNum(vl,k);
    lk2= nextNum(lk1);
    i=vl;
    for(;i<=vr;){//xet tat ca cac chu so trong [pl+1,pr]
        //if(vl==vr&&pl==pr&&pl==vr) break;
        sum+=lenthRt(pl,pr,lk1,lk2)*min(after-i+1,vr-i+1);
        //printf("%d to %d-> %d %d + them %lf*%d ->%lf\n",i,after,lk1,lk2,lenthRt(pl,pr,lk1,lk2),min(after-i+1,pr-i+1),sum);

        i=after+1;
        after=nextNum(after);
        lk1=lk2;
        if(lk1>pr) break;
        lk2=nextNum(lk2);
    }
    mau=(pr-pl+1);
    mau*=     (vr-vl+1);
    //printf("%lf %lf");
    //printf("%lf %lf\n",sum,mau);
    kq=sum/mau;

    printf("%.12lf",kq);
    return 0;
}


#include <stdio.h>

#define N	13
#define Q	1010
#define MD1	998244353
#define MD	1000000007

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

long long pp[N + 1], qq[N + 1];

void init() {
	int i;

	pp[0] = qq[0] = 1;
	for (i = 1; i <= N; i++) {
		pp[i] = pp[i - 1] * 10;
		qq[i] = qq[i - 1] + pp[i];
	}
}

long long idx(long long a, long long b) {
	static int aa[N], bb[N];
	static long long aa_[N];
	long long cnt;
	int n, m, i, j, c;

	n = 0;
	while (a > 0)
		aa[n++] = a % 10, a /= 10;
	m = 0;
	while (b > 0)
		bb[m++] = b % 10, b /= 10;
	for (i = 0; i < n; i++)
		aa_[i] = (i == 0 ? 0 : aa_[i - 1]) + aa[i] * pp[i];
	cnt = m;
	for (i = n - 1, j = m - 1, c = 0; j >= 0; i--, j--)
		if (c < 0)
			cnt += qq[n - 1 - (m - 1 - j)] * (bb[j] - (j == m - 1 ? 1 : 0));
		else if (c > 0)
			cnt += (n - 1 - (m - 1 - j) == 0 ? 0 : qq[n - 2 - (m - 1 - j)]) * (bb[j] - (j == m - 1 ? 1 : 0));
		else {
			if (bb[j] <= aa[i]) {
				if (bb[j] < aa[i])
					c = -1;
				cnt += qq[n - 1 - (m - 1 - j)] * (bb[j] - (j == m - 1 ? 1 : 0));
			} else {
				c = 1;
				cnt += qq[n - 1 - (m - 1 - j)] * (aa[i] - (j == m - 1 ? 1 : 0));
				cnt += (n - 1 - (m - 1 - j) == 0 ? 0 : qq[n - 2 - (m - 1 - j)]) * (bb[j] - aa[i]) + (i == 0 ? 0 : aa_[i - 1]) + 1;
			}
		}
	return cnt;
}

int aa[N], bb[N];

long long count_(long long a, long long d) {
	long long b, cnt;

	cnt = 0;
	for (b = 1; b <= a; b++)
		if (idx(a, b) - b >= d)
			cnt++;
	return cnt;
}

long long count(long long a, long long d) {
	int m;
	long long cnt;

	cnt = 0;
	for (m = 1; pp[m - 1] - 1 <= a; m++) {
		long long lower = pp[m - 1] - 1, upper = min(pp[m], a + 1);

		while (upper - lower > 1) {
			long long b = (lower + upper) / 2;

			if (idx(a, b) - b >= d)
				upper = b;
			else
				lower = b;
		}
		cnt += min(pp[m], a + 1) - upper;
	}
	return cnt;
}

int main() {
	long long a, q, ans;

	init();
	scanf("%lld", &a);
	ans = Q * a % MD;
	for (q = -Q + 1; q <= Q; q++)
		ans = (ans - count(a, q * MD1)) % MD;
	ans = ans * MD1 % MD;
	if (ans < 0)
		ans += MD;
	printf("%lld\n", ans);
	return 0;
}


#pragma GCC optimize("Ofast")
#include <stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define inf 0x3f3f3f3f
#define mod 1000000007
int n,m,k,ans,a[15][15];
int used[15][15][15],mp[15];
void dfs(int x,int y,int mc)
{
	if (x==n)
	{
		register int c,qc;
		for (c=1;c<=mc;++c) for (qc=c+1;qc<=mc;qc++) if (mp[c] && mp[qc] && mp[c]==mp[qc]) return;
		int a=0,b=k;
		for (c=1;c<=mc;++c)
		{
			if (mp[c]) b--;
			else a++;
		}
		int curans=1;
		for (;a--;b--) curans=curans*b%mod;
		ans+=curans;ans%=mod;
		return;
	}
	register int c,i,j;int flag=0;
	for (c=1;c<=min(mc+1,k);++c)
	{
		if (used[x][y][c]) continue;
		for (i=x;i<n;++i) for (j=y;j<m;++j) used[i][j][c]++;
		if (!(a[x][y] && mp[c] && mp[c]!=a[x][y]))
		{
			flag=0;
			if (!mp[c])
			{
				mp[c]=a[x][y];
				flag=1;
			}
			if (y<m-1) dfs(x,y+1,max(mc,c));
			else dfs(x+1,0,max(mc,c));
			if (flag) mp[c]=0;
		}
		for (i=x;i<n;++i) for (j=y;j<m;++j) used[i][j][c]--;
	}
}
int main()
{
	register int i,j;
	scanf("%d%d%d",&n,&m,&k);
	if (n+m>k+1) return (int)puts("0")*0;
	for (i=0;i<n;++i) for (j=0;j<m;++j) scanf("%d",&a[i][j]);
	dfs(0,0,0);printf("%d\n",ans);
}


#include <stdio.h>

typedef struct mk
{
	int day,type;
}roy;

int n,m,a[200010],l,r,tot=0;
roy off[200010],tmp[200020];

int ok(int days){
	int t[n+1];
	int need = 0,collect = days;
	for(int i = 0;i<n;i++) t[i] = a[i];
	for(int i = m-1;i>=0;i--){
		if(off[i].day>days) continue;
		collect = (collect<=off[i].day)?collect:off[i].day;
		int tp = (collect<=t[off[i].type-1])?collect:t[off[i].type-1];
		need += tp;
		t[off[i].type-1]-= tp;
		collect-=tp;
	}
	need += (tot - need)*2;
	return (need<=days);
}
void merge(roy *of, int s,int m,int e){
	int i = s,j = m+1,k = 0;
	while (i<=m && j<=e){
		if(of[i].day==of[j].day){
			tmp[k++] = (a[of[i].type-1]<a[of[j].type-1])?of[i++]:of[j++];
		}
		else tmp[k++] = (of[i].day<of[j].day)?of[i++]:of[j++];
	}
	while (i<=m) tmp[k++] = of[i++];
	while (j<=e) tmp[k++] = of[j++];
	for(int i = s;i<=e;i++) {
		of[i] = tmp[i-s];
	}
}
void sort(roy *of, int s,int e){
	if(s<e){
		int m = (e+s)/2;
		sort(of,s,m);
		sort(of,m+1,e);
		merge(of,s,m,e);
	}
}
void solve(){
	scanf("%d%d",&n,&m);
	for(int i = 0;i<n;i++){
		scanf("%d",a+i);
		tot += a[i];
	}
	for(int i = 0;i<m;i++){
		scanf("%d%d",&off[i].day,&off[i].type);
	}
	sort(off, 0, m-1);
	l = 1;r = tot*2+1;
	int Ans;
	while (l<=r)
	{
		int m = (l+r)/2;
		if(ok(m)){
			Ans  = m;
			r = m-1;
		}
		else l = m+1;
	}
	for(int i = l;i<=r;i++){
		if(ok(i)){
			Ans = i;
			break;
		}
	}
	printf("%d\n",Ans);
}
int main(){
	solve();
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define N	200000
#define M	200000

void init_rand() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srand(tv.tv_usec ^ tv.tv_sec);
}

int rand_(int n) {
	return (rand() * 45677LL + rand()) % n;
}

int kk[N], ll[N], tt[M], ii[M], jj[M];

int check(int n, int m, int t) {
	static int tt_[N];
	int i, j, b, x, t_;

	for (i = 0; i < n; i++) {
		ll[i] = kk[i];
		tt_[i] = -1;
	}
	for (j = 0; j < m && (t_ = tt[jj[j]]) <= t; j++)
		tt_[ii[jj[j]]] = t_;
	b = 0;
	for (j = 0; j < m && (t_ = tt[jj[j]]) <= t; j++)
		if (tt_[i = ii[jj[j]]] == t_) {
			x = ll[i] < t_ - b ? ll[i] : t_ - b;
			b += x, ll[i] -= x;
		}
	for (i = 0; i < n; i++)
		b += ll[i] * 2;
	return b <= t;
}

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return tt[i] - tt[j];
}

int main() {
	int n, m, i, j, lower, upper, t, tmp;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%d", &kk[i]);
	for (j = 0; j < m; j++) {
		scanf("%d%d", &tt[j], &ii[j]), ii[j]--;
		jj[j] = j;
	}
	init_rand();
	for (j = m - 1; j >= 0; j--) {
		i = rand_(j + 1);
		tmp = jj[i], jj[i] = jj[j], jj[j] = tmp;
	}
	qsort(jj, m, sizeof *jj, compare);
	lower = 0, upper = 200000 * 2;
	while (upper - lower > 1) {
		t = (lower + upper) / 2;
		if (check(n, m, t))
			upper = t;
		else
			lower = t;
	}
	printf("%d\n", upper);
	return 0;
}


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

typedef long long int lli;

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

#define MOD    998244353
#define MAX    5005
#define SENT   -1

typedef struct Pair {
    int fi, se;
} Pair;

int comp(Pair * f, Pair * s) {
    return (f->fi - s->fi);
}

void sort(Pair ** arr, int size) { // CHANGE THIS
    int i;
    if (size < 6) {
        int nSize = 0;
        int s = size;
        while (size != 0) {
            nSize = 0;
            for (i = 0; i < size - 1; i++)
                if (comp(arr[i], arr[i+1]) > 0) { // CHANGE THIS
                    Pair * tmp = arr[i];
                    arr[i] = arr[i+1];
                    arr[i+1] = tmp;
                    nSize = i+1;
                }
            size = nSize;
        }
        return;
    }
    Pair ** tmp = (Pair **)calloc(size, sizeof(Pair *)); // CHANGE THIS
    int lSize = (size >> 1);
    int rSize = size - lSize;
    sort(arr, lSize); sort(arr + lSize, rSize);
    int lPtr = 0, rPtr = 0;
    int ptr = 0;
    while (ptr != size) {
        if (lPtr == lSize)
            tmp[ptr] = arr[lSize + (rPtr++)];
        else if (rPtr == rSize || comp(arr[lPtr], arr[lSize + rPtr]) <= 0) // CHANGE THIS
            tmp[ptr] = arr[lPtr++];
        else
            tmp[ptr] = arr[lSize + (rPtr++)];
        ptr++;
    }
    for (i = 0; i < size; i++)
        arr[i] = tmp[i];
    free(tmp);
}

int main(void) {
    int i, n, m;
    in32(n);
    in32(m);
    int need[n];
    fo3(i,0,n-1)
        in32(need[i]);
    Pair ** p = calloc(m, sizeof(Pair*));
    fo3(i,0,m-1) {
        p[i] = calloc(1,sizeof(Pair));
        in32(p[i]->fi);
        in32(p[i]->se);
    }
    sort(p,m);
    lli pos = 2000000, min = 0, max = 2000000 - 1;
    int have[n];
    while (min <= max) {
        lli mid = (min + max) >> 1;
        fo3(i,0,n-1)
            have[i] = 0;
        lli spent = 0;
        lli maxDay = mid;
        of3(i,m-1,0) {
            int day = p[i]->fi;
            int ind = p[i]->se-1;
            int miss = need[ind] - have[ind];
            if (maxDay > day)
                maxDay = day;
            int buy = miss;
            if (buy > maxDay)
                buy = maxDay;
            have[ind] += buy;
            maxDay -= buy;
            spent += buy;
        }
        fo3(i,0,n-1)
            spent += ((need[i] - have[i])<<1);
        if (spent <= mid) {
            pos = mid;
            max = mid - 1;
        } else
            min = mid + 1;
    }
    out64(pos);
    return 0;
}


#include <stdio.h>

typedef struct mk
{
	int day,type;
}roy;

int n,m,a[200010],l,r,tot=0;
roy off[200010],tmp[200020];

int ok(int days){
	int t[n+1];
	int need = 0,collect = 0;
	for(int i = 0;i<n;i++) t[i] = a[i];
	for(int i = 0;i<m;i++){
		if(i==0) collect = off[i].day;
		else collect += (off[i].day - off[i-1].day);
		if(t[off[i].type-1] && collect){
			int tp = (collect<=t[off[i].type-1])?collect:t[off[i].type-1];
			need += tp;
			t[off[i].type-1]-= tp;
			collect-=tp;
		}

	}
	need += (tot - need)*2;
	return (need<=days);
}
void merge(roy *of, int s,int m,int e){
	int i = s,j = m+1,k = 0;
	while (i<=m && j<=e){
		if(of[i].day==of[j].day){
			tmp[k++] = (a[of[i].type-1]<a[of[j].type-1])?of[i++]:of[j++];
		}
		else tmp[k++] = (of[i].day<of[j].day)?of[i++]:of[j++];
	}
	while (i<=m) tmp[k++] = of[i++];
	while (j<=e) tmp[k++] = of[j++];
	for(int i = s;i<=e;i++) {
		of[i] = tmp[i-s];
	}
}
void sort(roy *of, int s,int e){
	if(s<e){
		int m = (e+s)/2;
		sort(of,s,m);
		sort(of,m+1,e);
		merge(of,s,m,e);
	}
}
void solve(){
	scanf("%d%d",&n,&m);
	for(int i = 0;i<n;i++){
		scanf("%d",a+i);
		tot += a[i];
	}
	for(int i = 0;i<m;i++){
		scanf("%d%d",&off[i].day,&off[i].type);
	}
	sort(off, 0, m-1);
	l = 1;r = tot*2+1;
	int Ans;
	while (l<=r)
	{
		int m = (l+r)/2;
		if(ok(m)){
			Ans  = m;
			r = m-1;
		}
		else l = m+1;
	}
	for(int i = l;i<=r;i++){
		if(ok(i)){
			Ans = i;
			break;
		}
	}
	printf("%d\n",Ans);
}
int main(){
	solve();
	return 0;
}


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

#define N	10000
#define M	10000
#define K	10
#define C	26

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

int ij[M], cc[M * 2], m;
int *oh[N], oo[N], n;

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

	if (o >= 2 && (o & o - 1) == 0)
		oh[i] = (int *) realloc(oh[i], o * 2 * sizeof *oh[i]);
	oh[i][o] = h;
}

int dd[N];

int bfs(int s, int t) {
	static int qu[N];
	int i, head, cnt;

	for (i = 0; i < n; i++)
		dd[i] = n;
	head = cnt = 0;
	dd[s] = 0, qu[head + cnt++] = s;
	while (cnt) {
		int d, o;

		i = qu[cnt--, head++], d = dd[i] + 1;
		for (o = 0; o < oo[i]; o++) {
			int h_ = oh[i][o];

			if (cc[h_]) {
				int h = h_ >> 1, j = i ^ ij[h];

				if (dd[j] > d) {
					dd[j] = d;
					if (j == t)
						return 1;
					qu[head + cnt++] = j;
				}
			}
		}
	}
	return 0;
}

int dfs(int i, int t, int c) {
	int d, o;

	if (i == t)
		return c;
	d = dd[i] + 1;
	for (o = 0; o < oo[i]; o++) {
		int h_ = oh[i][o];

		if (cc[h_]) {
			int h = h_ >> 1, j = i ^ ij[h];

			if (dd[j] == d) {
				int f = dfs(j, t, min(c, cc[h_]));

				if (f) {
					cc[h_] -= f, cc[h_ ^ 1] += f;
					return f;
				}
			}
		}
	}
	dd[i] = n;
	return 0;
}

int dinic(int s, int t) {
	int sum = 0;

	while (bfs(s, t)) {
		int f;

		while ((f = dfs(s, t, C)))
			sum += f;
	}
	return sum;
}

int ccc[K][M * 2];
int cut[1 << K], k;

void solve(int b, int h_, int s) {
	int h;

	s += dinic(0, n - 1);
	cut[b] = s;
	if (h_ < k) {
		memcpy(ccc[h_], cc, m * 2 * sizeof *cc);
		for (h = h_; h < k; h++) {
			cc[h << 1] = C;
			solve(b | 1 << h, h + 1, s);
			memcpy(cc, ccc[h_], m * 2 * sizeof *ccc[h_]);
		}
	}
}

int main() {
	static int ww_[K];
	int q, h, i, j;

	scanf("%d%d%d%d", &n, &m, &k, &q);
	for (i = 0; i < n; i++)
		oh[i] = (int *) malloc(2 * sizeof *oh[i]);
	for (h = 0; h < m; h++) {
		int c;

		scanf("%d%d%d", &i, &j, &c), i--, j--;
		ij[h] = i ^ j, cc[h << 1] = c;
		link(i, h << 1), link(j, h << 1 | 1);
	}
	solve(0, 0, 0);
	while (q--) {
		int b, w, ans;

		w = 0;
		for (h = 0; h < k; h++) {
			scanf("%d", &ww_[h]);
			w += ww_[h];
		}
		ans = cut[0] + w;
		for (b = 1; b < 1 << k; b++) {
			for (h = 0; (b & 1 << h) == 0; h++)
				w += ww_[h];
			w -= ww_[h];
			ans = min(ans, cut[b] + w);
		}
		printf("%d\n", ans);
	}
	return 0;
}


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

#define N	100000

int jj[N], pp[N], dd[N], mn;

void match(int i) {
	while (dd[i] == 1) {
		int j = jj[i], tmp;

		if (pp[i] == i || dd[j] == 1)
			tmp = pp[i], pp[i] = pp[j], pp[j] = tmp;
		else
			mn -= 2;
		jj[i] ^= j, dd[i] = 0, jj[j] ^= i, dd[j]--;
		i = j;
	}
}

int main() {
	int n, h, i, j;

	scanf("%d", &n);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		jj[i] ^= j, dd[i]++, jj[j] ^= i, dd[j]++;
	}
	for (i = 0; i < n; i++)
		pp[i] = i;
	mn = (n - 1) * 2;
	for (i = 0; i < n; i++)
		match(i);
	printf("%d\n", mn);
	for (i = 0; i < n; i++)
		printf("%d ", pp[i] + 1);
	printf("\n");
	return 0;
}


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

#define N	100000

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

int xx[N];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return xx[i] - xx[j];
}

int main() {
	static int ii[N];
	int n, k, i, i_, xn, yn;
	double ans;

	scanf("%d%d", &n, &k), k--;
	for (i = 0; i < n; i++) {
		scanf("%d", &xx[i]);
		ii[i] = i;
	}
	qsort(ii, n, sizeof *ii, compare);
	scanf("%d%d", &xn, &yn);
	if (k == n) {
		printf("%f\n", min(hypot(xn - xx[ii[0]], yn), hypot(xn - xx[ii[n - 1]], yn)) + xx[ii[n - 1]] - xx[ii[0]]);
		return 0;
	}
	ans = hypot(xn - xx[k], yn)
		+ min(hypot(xn - xx[ii[0]], yn), hypot(xn - xx[ii[n - 1]], yn))
		+ xx[ii[n - 1]] - xx[ii[0]];
	i_ = -1;
	for (i = 0; i < n; i++)
		if (ii[i] == k) {
			i_ = i;
			break;
		}
	for (i = i_; i < n; i++) {
		double d;

		d = min(xx[ii[i]] - xx[k] + xx[ii[i]] - xx[ii[0]]
				+ hypot(xn - xx[ii[0]], yn),
				xx[k] - xx[ii[0]] + xx[ii[i]] - xx[ii[0]]
				+ hypot(xn - xx[ii[i]], yn));
		if (i + 1 < n)
			d += min(hypot(xn - xx[ii[i + 1]], yn), hypot(xn - xx[ii[n - 1]], yn))
				+ xx[ii[n - 1]] - xx[ii[i + 1]];
		ans = min(ans, d);
	}
	for (i = i_; i >= 0; i--) {
		double d;

		d = min(xx[k] - xx[ii[i]] + xx[ii[n - 1]] - xx[ii[i]]
				+ hypot(xn - xx[ii[n - 1]], yn),
				xx[ii[n - 1]] - xx[k] + xx[ii[n - 1]] - xx[ii[i]]
				+ hypot(xn - xx[ii[i]], yn));
		if (i > 0)
			d += min(hypot(xn - xx[ii[i - 1]], yn), hypot(xn - xx[ii[0]], yn))
				+ xx[ii[i - 1]] - xx[ii[0]];
		ans = min(ans, d);
	}
	printf("%f\n", ans);
	return 0;
}


#include <stdio.h>
#include <string.h>
enum { BIG = 1000000007 };

int n;
char s[240];
int slen;
int dp[201][101];
int next[201][2];
int fail[201];

void nextstep(int eo) {
    int i, j;
    for (i = 0; i <= slen; i++) {
        int lp = next[i][0];
        int rp = next[i][1];
        for (j = eo; j <= n; j+=2) {
            int now = dp[i][j];
            if (j < n) {
                int add = dp[lp][j+1] + now;
                dp[lp][j+1] = add < BIG ? add : add - BIG;
            }
            if (j > 0) {
                int add = dp[rp][j-1] + now;
                dp[rp][j-1] = add < BIG ? add : add - BIG;
            }
        }
    }
    for (i = 0; i <= slen; i++) {
        for (j = eo; j <= n; j+=2) {
            dp[i][j] = 0;
        }
    }
    /*for (i=0;i<=slen;i++){
        for (j=0;j<=n;j++){
            printf("%3d,",dp[i][j]);
        }
        puts("");
    }
    puts("");*/
}

int main() {
    scanf("%d", &n);
    scanf(" %202s", s);
    slen = strlen(s);
    int i;
    // build state machine
    fail[0] = fail[1] = 0;
    if (s[0] == '(') {
        next[0][0] = 1;
        next[0][1] = 0;
    }
    else {
        next[0][0] = 0;
        next[0][1] = 1;
    }
    for (i = 1; i < slen; i++) {
        int r = s[i] == ')';
        int f = fail[i];
        next[i][r] = i+1;
        next[i][1-r] = next[f][1-r];
        fail[i+1] = next[f][r];
    }
    next[slen][0] = next[slen][1] = slen;
    dp[0][0] = 1;
    for (i = 0; i < n; i++) {
        nextstep(0);
        nextstep(1);
    }
    printf("%d\n", dp[slen][0]);
    return 0;
}


#include <stdio.h>

int main() {
  int total = 0;
  int current = 0;
  int sign = 1;
  for (;;) {
    int c = getchar();
    if (c == '+' || c == '-') {
      total += current;
      current = 0;
      sign = c == '+' ? 1 : -1;
    } else if (c < '0' || c > '9') break;
    current = current * 10 + (c - '0') * sign;
  }
  total += current;
  printf("%d\n", total);
  return 0;
}


#include <stdio.h>

#define N	250
#define MD	998244353

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

void init() {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N; 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;
	}
}

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

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 main() {
	static int dp[N];
	int n, k, c, i, j;

	init();
	scanf("%d%d", &n, &k);
	dp[0] = 1;
	for (c = 1; c <= k; c++)
		for (i = n - 1; i >= 0; i--)
			for (j = 0; j < i; j++)
				dp[i] = (dp[i] + (long long) dp[j] * choose(i, j) % MD * power(k - c + 1, i * (i - 1) / 2 - j * (j - 1) / 2)) % MD;
	printf("%d\n", dp[n - 1]);
	return 0;
}


#include <stdio.h>
#include <assert.h>

typedef long long ll;
typedef struct pll { ll first,second; } pll;

// a*x+b*y=g, x==0&&y==1||x==1&&y==0||1<=abs(x)<b/g&&1<=abs(y)<a/g&&x*y<0
ll min(ll x,ll y) { return x<y?x:y; }
ll egcd(ll a,ll b,ll *x,ll *y) {
	if(b==0) { *x=1,*y=0; return a; }
	ll g=egcd(b,a%b,x,y);
	ll z=*x; *x=*y; *y=z; *y-=(*x)*(a/b); return g;
}

pll solve(ll a,ll b,ll MOD) { // a*x=b (mod MOD)
	a=(a%MOD+MOD)%MOD;
	b=(b%MOD+MOD)%MOD;
	ll x,y,g=egcd(a,MOD,&x,&y);
	if(x<0) x+=MOD/g,y-=a/g;
	if(b%g!=0) return (pll){-1LL,-1LL};
	return (pll){x*(b/g)%(MOD/g),MOD/g};
}

int a,h,w;
void run() {
	scanf("%d%d%d",&a,&h,&w);
	//(a+h)*nhor = w-h mod (w+a)
	pll nhor=solve(a+h,w-h,w+a);
	if(nhor.first==-1&&nhor.second==-1) { printf("-1\n"); return; }
	pll nvert={((a+h)*nhor.first+h-w)/(w+a),(a+h)*nhor.second/(w+a)};
	//printf("(%lld,%lld) (%lld,%lld)\n",nhor.first,nhor.second,nvert.first,nvert.second);
	assert(((a+h)*nhor.first+h-w)%(w+a)==0); assert((a+h)%nhor.second/(w+a)==0);
	if(nhor.first==0) nhor.first+=nhor.second,nvert.first+=nvert.second;
	if(nvert.first<=0) { ll t=(1-nvert.first+nvert.second-1)/nvert.second; nhor.first+=t*nhor.second,nvert.first+=t*nvert.second; }
	if(w-nhor.first*a<0||h-nvert.first*a<0) { printf("-1\n"); return; }
	ll t=min((w-nhor.first*a)/(nhor.second*a),(h-nvert.first*a)/(nvert.second*a));
	nhor.first+=t*nhor.second,nvert.first+=t*nvert.second;
	//printf("%lld -> %.9lf / %lld -> %.9lf\n",nhor.first,1.0*(w-nhor.first*a)/(nhor.first+1),nvert.first,1.0*(h-nvert.first*a)/(nvert.first+1));
	printf("%.9lf\n",1.0*(w-nhor.first*a)/(nhor.first+1));
}

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


#include <stdio.h>

typedef struct {
  int l, r;
} interval;

int max(int x, int y) {
  return x > y ? x : y;
}

int min(int x, int y) {
  return x < y ? x : y;
}

int interval_intersection_length(const interval *a, const interval *b) {
  return max(0, min(a->r, b->r) - max(a->l, b->l) + 1);
}

void extract(const interval *a, interval *a1, interval *a2, int i) {
  int s = 1 << i;
  int x = (a->l + s - 1) >> i << i;
  int y = a->r >> i << i;
  if (x < y) {
    a1->l = a2->l = 1;
    a1->r = a2->r = s - 1;
  } else if (x == y) {
    a1->l = a->l % s;
    if (a1->l == 0) a1->l = s;
    a1->r = s - 1;
    a2->l = 1;
    a2->r = a->r % s;
  } else {
    a1->l = a2->l = a->l % s;
    a1->r = a2->r = a->r % s;
  }
}

int main() {
  int i, ans;
  interval a, b, a1, a2, b1, b2;
  scanf("%d %d %d %d", &a.l, &a.r, &b.l, &b.r);
  ans = 0;
  for (i = 1; i <= 30; i++) {
    extract(&a, &a1, &a2, i);
    extract(&b, &b1, &b2, i);
    ans = max(ans, interval_intersection_length(&a1, &b1));
    ans = max(ans, interval_intersection_length(&a1, &b2));
    ans = max(ans, interval_intersection_length(&a2, &b1));
    ans = max(ans, interval_intersection_length(&a2, &b2));
  }
  printf("%d\n", ans);
  return 0;
}


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

#define ll long long

const ll M = 1000000007;

ll inv(ll a, ll M)
{
   if (a < 0)
       a = (a + (1+(0-a)/M)*M)%M;
   ll M_o = M;
   ll ac0 = 1;
   ll ac1 = 0;
   ll bc0 = 0;
   ll bc1 = 1;
   ll q;
   ll r;
   ll temp;
   while (M > 0)
   {
       q = a/M;
       r = a%M;
       a = M;
       M = r;

       temp = ac0;
       ac0 = bc0;
       bc0 = temp - q*bc0;

       temp = ac1;
       ac1 = bc1;
       bc1 = temp - q*bc1;
   }
   M = M_o;
   if (ac0 > 0)
       return ac0%M;
   else
       return (ac0 + M*(1+(0-ac0)/M))%M;
}

ll expmod(ll a, ll x, ll m)
{
    ll ans = 1;
    while (x > 0)
    {
        if (x%2 == 1)
            ans = ans*a%m;
        a = a*a%m;
        x /= 2;
    }
    if (ans > 0)
        return ans%M;
    else
        return (ans + M*(1 + (0-ans)/M))%M;
}

int main()
{
    int n, m;
    int ai, bi;
    int ki;

    fscanf(stdin, "%d %d\n", &n, &m);
    fscanf(stdin, "%d %d\n", &ai, &bi);
    fscanf(stdin, "%d", &ki);

    ll a = (ll) ai;
    ll b = (ll) bi;
    ll k = (ll) ki;

    ll p = a*inv(b, M)%M;

    ll* kchoose = malloc((m+1)*sizeof(ll));
    kchoose[0] = 1;
    for (int l = 1; l < m+1; l++)
        kchoose[l] = (kchoose[l-1]*(k-l+1)%M)*inv(l,M)%M;

    ll* expmodp = malloc((m+1)*sizeof(ll));
    ll* expmod1pkminus = malloc((m+1)*sizeof(ll));
    expmodp[0] = 1;
    expmod1pkminus[0] = expmod(1-p, k, M);
    ll inv1p = p!=1? inv(1-p, M):1;

    for (int x = 1; x < m+1; x++)
    {
        expmodp[x] = p*expmodp[x-1]%M;
        if (p != 1)
            expmod1pkminus[x] = inv1p*expmod1pkminus[x-1]%M;
        else
            expmod1pkminus[x] = x<k? 0:1;
    }

    ll* p_left = malloc((m+1)*sizeof(ll));
    for (int l = 0; l < m+1; l++)
    {
        if (l > k)
            p_left[l] = 0;
        else
            p_left[l] = (((kchoose[l]*expmodp[l])%M)*expmod1pkminus[l])%M;
    }

    ll* egs1 = malloc((m+1)*sizeof(ll));
    ll* egs2 = malloc((m+1)*sizeof(ll));
    ll* sle1 = malloc((m+1)*sizeof(ll));
    ll* sle2 = malloc((m+1)*sizeof(ll));

    ll* R = malloc(m*sizeof(ll));
    ll* T = malloc((m+1)*sizeof(ll));
    T[m] = 1;
    for (int i = 0; i < m; i++)
    {
        R[i] = 1;
        T[i] = 0;
    }

    ll* Tp_left = malloc(m*sizeof(ll));
    ll* Rp_left = malloc(m*sizeof(ll));

    for (int ni = 0; ni < n; ni++)
    {
        egs1[m] = 0;
        egs2[m] = 0;

        for (int i = 0; i < m; i++)
            Rp_left[i] = R[i]*p_left[m-(i+1)]%M;

        for (int s = m-1; s >= 0; s--)
        {
            egs1[s] = (egs1[s+1] + Rp_left[s])%M;
            egs2[s] = (egs2[s+1] + p_left[m-(s+1)])%M;
        }

        sle1[0] = 0;
        sle2[0] = 0;

        for (int i = 0; i < m; i++)
            Tp_left[i] = T[i]*p_left[i]%M;

        for (int e = 1; e < m+1; e++)
        {
            sle1[e] = (sle1[e-1] + p_left[e-1])%M;
            sle2[e] = (sle2[e-1] + Tp_left[e-1])%M;
        }

        R[0] = (p_left[0]*egs1[0]%M - Tp_left[0]*egs2[0]%M + M)%M;
        for (int s = 1; s < m; s++)
            R[s] = (R[s-1] + p_left[s]*egs1[s]%M - Tp_left[s]*egs2[s]%M + M) % M;

        T[0] = 0;
        for (int e = 1; e < m+1; e++)
            T[e] = (T[e-1] + Rp_left[e-1]*sle1[e]%M - p_left[m-e]*sle2[e]%M + M)%M;
    }

    printf("%lld\n", T[m]);
}