#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}
int main(){
  int n,i,k,a,G,MAX;scanf("%d%d",&n,&k);
  scanf("%d",&G);MAX = G;
  if(n == 1){
    printf((k==G) ? "POSSIBLE\n":"IMPOSSIBLE\n");
    return 0;
  }
  for(i=1;i<n;i++){
    scanf("%d",&a);
    G = gcd(G,a);
    MAX = max(MAX,a);
  }
  printf((k<=MAX && k%G==0) ? "POSSIBLE\n":"IMPOSSIBLE\n");
}

#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N, K; cin >> N >> K;
  int A[N]; rep(i,N) cin >> A[i];
  sort(A,A+N);
  int GCD = A[0];
  rep(i,N) GCD = __gcd(GCD, A[i]);

  if (K%GCD==0 && K<=A[N-1]) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  // cout << fixed << setprecision(10);

  return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

// 素因数が何乗かをmapで返却する
map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

void solve() {
    ll N, M; cin >> N >> M;
    auto pf = prime_factor(M);

    ll res = 1;
    for(auto a: pf){
        res = modint(modint(res) * comb(a.second + N - 1, a.second));
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

LL n, k;
LL d[112];
std::vector<edge>G[112];

void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(d, d + n + 1, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (d[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	while (true)
	{
		n = k = 0;
		memset(d, 0, sizeof(d));
		rep(i, 112) { G[i].clear(); }

		in >> n >> k;
		if (n == 0 && k == 0) { break; }
		rep(loop, k)
		{
			LL flag;
			in >> flag;
			if (flag == 0)
			{
				LL a, b;
				in >> a >> b;
				dijkstra(a);
				out << (d[b] == INF ? -1 : d[b]) << std::endl;
			}
			else
			{
				LL c, d, e;
				in >> c >> d >> e;
				G[c].push_back({ d,e });
				G[d].push_back({ c,e });
			}
		}
	}
	return 0;
}

#include <cstdio>
#include <algorithm>
using namespace std;
#define INF (1<<27)
int cost[100][100];
int main() {
	int n,k;
	while(scanf("%d %d",&n,&k),n) {
		fill((int*)cost,(int*)(cost+100),INF);
		for(int i=0;i<k;i++) {
			int a,b,c;
			scanf("%d",&a);
			if(a==0) {
				scanf("%d %d",&a,&b);
				if(cost[a-1][b-1]==INF)
					printf("-1\n");
				else
					printf("%d\n",cost[a-1][b-1]);
			}else {
				scanf("%d %d %d",&a,&b,&c);
				if(cost[a-1][b-1]>c) {
					cost[a-1][b-1]=cost[b-1][a-1]=c;
					for(int k=0;k<n;k++) {
						for(int i=0;i<n;i++) {
							for(int j=0;j<n;j++) {
								cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
							}
						}
					}
				}
			}
		}
	}
}


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

int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	int X[100], Y[100];
	int inin;
	for (int i = 0; i < n; ++i)
	{
		cin >> X[i];
	}
	for (int i = 0; i < m; ++i)
	{
		cin >> Y[i];
	}
	sort(X, X+n);
	sort(Y, Y+m);
	bool ok = 0;
	for (int i = x+1; i <= y; ++i)
	{
		if (i > X[n-1] && i <= Y[0])
		{
			ok = 1;
		}
	}
	cout << (ok?"No War":"War") << endl;

	return 0;
}

/*
 * Dice1.cpp
 *
 *  Created on: 2014/08/08
 *      Author: WanWan1985
 */
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

// for util
#define ALL(a)          (a).begin(), (b).end()
#define FOR(i, a, b)    for(int i = (a); i < (b); i++)
#define REP(i, n)       FOR(i, 0, n)
#define PB              push_back
#define MP              make_pair
#define CL              clear
#define EXIT            (0)
#define PINT            pair<int, int>

typedef unsigned int u_int;
typedef long long ll;

enum E_DiceArrayIndex {
	eTOP = (0),
	eSOUTH,
	eEAST
//	eWEST,
//	eNORTH,
//	eDOWN
};

enum E_DiceLavel {
	eOne = (0),
	eTwo,
	eThree,
	eFour,
	eFive,
	eSix,
	eDiceLavelNum
};

// Diceクラス
class Dice {
	vector<int> m_vecDiceNum;
	vector<pair<E_DiceLavel, E_DiceLavel>> m_vecDiceState;
public:
	// 初期状態設定
	void init(const vector<int>& a_vecInputData) {
		REP(i, a_vecInputData.size()) {
			m_vecDiceNum.PB(a_vecInputData.at(i));
		}
		m_vecDiceState.PB(make_pair(eOne, eSix));		// TOP
		m_vecDiceState.PB(make_pair(eTwo, eFive));		// SOUTH
		m_vecDiceState.PB(make_pair(eThree, eFour));	// EAST
	}

	// 移動後のDice配置更新
	void upDateDicePosition(const char& a_chrCommand) {
		if ('S' == a_chrCommand) {
			pair<E_DiceLavel, E_DiceLavel> Top = m_vecDiceState[eTOP];
			pair<E_DiceLavel, E_DiceLavel> South = m_vecDiceState[eSOUTH];
			m_vecDiceState[eSOUTH] = Top;
			m_vecDiceState[eTOP] = make_pair(South.second, South.first);
		} else if ('N' == a_chrCommand) {
			pair<E_DiceLavel, E_DiceLavel> Top = m_vecDiceState[eTOP];
			pair<E_DiceLavel, E_DiceLavel> South = m_vecDiceState[eSOUTH];
			m_vecDiceState[eSOUTH] = make_pair(Top.second, Top.first);
			m_vecDiceState[eTOP] = South;
		} else if ('W' == a_chrCommand) {
			pair<E_DiceLavel, E_DiceLavel> Top = m_vecDiceState[eTOP];
			pair<E_DiceLavel, E_DiceLavel> East = m_vecDiceState[eEAST];
			m_vecDiceState[eTOP] = East;
			m_vecDiceState[eEAST] = make_pair(Top.second, Top.first);
		} else if ('E' == a_chrCommand) {
			pair<E_DiceLavel, E_DiceLavel> Top = m_vecDiceState[eTOP];
			pair<E_DiceLavel, E_DiceLavel> East = m_vecDiceState[eEAST];
			m_vecDiceState[eTOP] = make_pair(East.second, East.first);
			m_vecDiceState[eEAST] = Top;
		}
	}
	// サイコロ上面の数字を取得する
	int GetTopSurfaceNum() {
		pair<E_DiceLavel, E_DiceLavel> Top = m_vecDiceState[eTOP];
		return m_vecDiceNum[Top.first];
	}
};

int main(void) {

	int i, j, k, l, m, n;
	cin >> i >> j >> k >> l >> m >> n;
	vector<int> vecDiceNum;
	vecDiceNum.PB(i);
	vecDiceNum.PB(j);
	vecDiceNum.PB(k);
	vecDiceNum.PB(l);
	vecDiceNum.PB(m);
	vecDiceNum.PB(n);

	string strCommand;
	cin >> strCommand;

	Dice Dice1;
	Dice1.init(vecDiceNum);

	REP(i, strCommand.size()) {
		const char chrCommand = strCommand.at(i);
		Dice1.upDateDicePosition(chrCommand);
	}

	cout << Dice1.GetTopSurfaceNum() << endl;

	return EXIT;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P  = pair <int, int>;

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  int a;
  cin >> a;
  ll ans = 0;

  rep(i, 3) ans += pow(a, i + 1);
  cout << ans << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e;
   cin>>a;
   cout<<a+a*a+a*a*a;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define rap(p, a, b) for (ll p = a; p <= b; p++)
#define per(p, a, b) for (ll p = a; p >= b; p--)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n;

    //cin>>t;
    t = 1;
    while (t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        set<ll> s;
        s.insert(a);s.insert(b);s.insert(c);

        if(s.sz==2)cout<<"Yes";
        else cout<<"No";
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
#endif

	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && b==c)
	{
		cout<<"No"<<endl;
	}
	else if((a==b && b!=c) || (a==c && c!=b) || (b==c && c!=a))
	{
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;

	return 0;
}


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

//#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

const double EPS=1e-8;
const double INF=1e12;

typedef complex<double> P;

namespace std {
	bool operator<(const P &a,const P &b) {
		return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
	}
}

double cross(const P &a,const P &b) {
	return imag(conj(a)*b);
}

double dot(const P &a,const P &b) {
	return real(conj(a)*b);
}

int ccw(P a,P b,P c) {
	b-=a;c-=a;
	if(cross(b,c)>0) 	return +1;
	if(cross(b,c)<0) 	return -1;
	if(dot(b,c)<0)	 	return +2;
	if(norm(b)<norm(c)) return -2;
	return 0;
}

vector<P> convex(vector<P> ps) {
	int n=(int)ps.size(),k=0;
	sort(ALL(ps));
	vector<P> ch(2*n);
	for(int i=0;i<n;ch[k++]=ps[i++]) {
		while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])<=0) --k;
	}
	for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--]) {
		while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])<=0) --k;
	}
	ch.resize(k-1);
	return ch;
}

int n;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>n;
	vector<P> ps;
	map<P,int> idx;
	REP(i,n) {
		double x,y;cin>>x>>y;
		ps.pb(P(x,y));
		idx[P(x,y)]=i;
	}
	vector<double> ans(n,0.0);
	vector<P> res=convex(ps);

	int sz=(int)res.size();
	if(sz==2) {
		for(auto p:res) ans[idx[p]]=0.5;
	}
	else {
		REP(i,sz) {
			P prv=res[(i-1+sz)%sz],crt=res[i],nxt=res[(i+1)%sz];
			double result=arg((crt-nxt)/(prv-crt));
			if(result<0) result+=2*PI;
			ans[idx[crt]]=result/(2*PI);
		}
	}
	REP(i,n) printf("%.12f\n",ans[i]);

	return 0;
}

#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int x,y,z,n,m,road[200005],rail[200005],connect[200005];
pair<pair<int,int>,int> total[200005];

int root (int ind) {
	if (road[ind] == ind) return ind; else
	return road[ind] = root(road[ind]);
}

void onion(int l, int r) {
	if (root(l) != root(r)) road[root(l)] = root(r);
}

int root2(int ind) {
	if (rail[ind] == ind) return ind; else
	return rail[ind] = root2(rail[ind]);
}

void onion2(int l, int r) {
	if (root2(l) != root2(r)) rail[root2(l)] = root2(r);
}

int main() {
	cin >> x >> y >> z;
	for (int i = 0; i <= x; i++) {
		rail[i] = i;
		road[i] = i;
	}
	for (int i = 0; i < y; i++) {
		cin >> n >> m;
		onion(n,m);
	}
	for (int i = 0; i < z; i++) {
		cin >> n >> m;
		onion2(n,m);
	}
	for (int i = 1; i <= x; i++) {
		total[i] = make_pair(make_pair(root(i),root2(i)),i);
	}
	sort(total+1,total+1+x);
	total[x+1].f.f = total[x+1].f.s = -31415;
	stack<int> st; while (!st.empty()) st.pop();
	int a1 = 0,a2 = 0,b1 = 0,b2 = 0;
	for (int i = 1; i <= x+1; i++) {
		a1 = total[i].f.f, a2 = total[i].f.s;
		if (!(st.empty() || (a1 == b1 && a2 == b2))) {
			int tmp = st.size();
			while (!st.empty()) {
				connect[st.top()] += tmp-1;
				st.pop();
			}
		}
		b1 = a1, b2 = a2;
		st.push(total[i].second);
	}
	for (int i = 1; i <= x; i++) {
		cout << connect[i]+1 << " ";
	}
}


#include <iostream>
#include <string>
#include <map>

int main(){
    std::string s;
    std::cin >> s;

    std::map<std::string, int> day = {
        {"SUN", 0},
        {"MON", 1},
        {"TUE", 2},
        {"WED", 3},
        {"THU", 4},
        {"FRI", 5},
        {"SAT", 6}
    };

    std::cout << 7 - day[s] << std::endl;

    return 0;
}

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

int main(){
  long long int N, K, X;
  string S;
  cin >> S;
  if(S == "SUN") cout << 7 << endl;
  if(S == "MON") cout << 6 << endl;
  if(S == "TUE") cout << 5 << endl;
  if(S == "WED") cout << 4 << endl;
  if(S == "THU") cout << 3 << endl;
  if(S == "FRI") cout << 2 << endl;
  if(S == "SAT") cout << 1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

int main(){

	int N;
	cin>>N;

	string S;
	cin>>S;

	for(int i=0;i<4;i++){
		string ans;
		if(i==0)ans="SS";
		if(i==1)ans="WW";
		if(i==2)ans="SW";
		if(i==3)ans="WS";

		for(int j=1;j<N+1;j++){
			char c = S[j%N];
			if(ans.back()=='W'){
				if(c=='o')c='x';
				else c='o';
			}
			if(c=='o'){
				ans += ans[ans.size()-2];
			}
			else{
				if(ans[ans.size()-2]=='W')ans+='S';
				else ans+='W';
			}

		}
		if(ans[0]==ans[N]&&ans[1]==ans[N+1]){
			cout<<ans.substr(0,N)<<endl;
			return 0;
		}
	}

	cout<<-1<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

int prime(int N) {
  if(N<2) return 0;
  if(N == 2) return 1;
  if(N%2 == 0) return 0;
  int sq = (int)(sqrt(N))+1;
  for(int i=3; i<sq; i+=2) {
    if(N%i == 0) return 0;
  }
  return 1;
}

signed main() {
  int N, M; cin >> N >> M;

  if(prime(M) == 1 && N >= 2) {
    cout << 1 << endl;
    return 0;
  }

  for(int i=N; i<=M; i++) {
    if(M%i == 0) {
      cout << M/i << endl;
      return 0;
    }
  }

}

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

int main() {
  int K,X; cin >> K >> X;
  int N = X+K-1;
  int M = X-K+1;
  for(int i=M; i<=N; i++) {
    cout << i << " ";
  }
  return 0;
}


#include<cstdio>

using namespace std;

long long a[201];
char s[202];
int main(){
	int t;
	scanf("%d",&t);
	for(int tt=1;tt<=t;tt++){
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			scanf("%lld",&a[i]);
		scanf("%s",s+1);
		for(int i=n;i;i--){
			if(a[i]==0)continue;
			int u=60;
			while(!(a[i]>>u&1))u--;
			for(int j=i-1;j;j--)
				if(a[j]>>u&1)a[j]^=a[i];
		}
		int ans=0;
		for(int i=1;i<=n;i++)
			if(s[i]=='1'&&a[i])
				ans=1;
		printf("%d\n",ans);
	}
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <bitset>

using ll = long long;

using namespace std;

// xorの掃き出し法 O(N^2)
// matに基底たちが入る
// Tはbitsetは無理(minしないといけないから)
template <typename T>
int gauss_jordan(vector<T> &mat) {
    vector<T> bases;
    for (auto e:mat) {
        for (auto &b:bases) {
            e = min(e, e^b);
        }
        if (e)
            bases.push_back(e);
    }
    mat.swap(bases);
    return (int)mat.size();
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n; cin >> n;
        ll a[n]; for (auto &ai:a) cin >> ai;
        string s; cin >> s;
        bool ans = false;
        vector<ll> bases;
        for (int i=n-1; i>=0; i--) {
            bool now = s[(size_t)i] - '0';
            if (now) {
                for (auto &bi:bases) {
                    a[i] = min(a[i], a[i]^bi);
                }
                if (a[i]) {
                    ans = true;
                    break;
                }
            } else {
                bases.push_back(a[i]);
                gauss_jordan(bases);
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
constexpr int MAX = 200001;
lint fact[MAX], finv[MAX], inv[MAX];
void cominit() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR(i, 2, MAX){
    fact[i] = fact[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
lint ncr(lint n, lint r, lint mod) {
  if(n < 0 || r < 0 || n-r < 0) return 0;
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N, M;
  cin >> N >> M;
  cominit();
  vector<lint> fact;
  for(lint i=2; i*i<=M; i++) {
    if(M%i != 0) continue;
    lint ex = 0;
    while(M%i == 0) {
      M /= i;
      ex++;
    }
    fact.push_back(ex);
  }
  if(M > 1) fact.push_back(1);
  lint ans = 1;
  REP(i, fact.size()) ans = ans * ncr(N-1+fact[i], fact[i], MOD) % MOD;
  cout << ans << endl;

}

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef pair<ll,ll> PLL;

#define REP(x,l,u) for(ll x = l; x < u; x++)
#define RREP(x,l,u) for(ll x = l; x >= u; x--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mst(x,v) memset(x, v, sizeof(x))
#define sz(x) (ll)x.size()

string to_string(string s) {return s;}
string to_string(char c) {string s = string(1, c);return s;}
template <typename A, typename B> string to_string(pair<A,B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(vector<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
template <typename A> string to_string(set<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }

void debug_out() {cerr << endl;}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

void in() {}
template <typename A> void in(A & x) { cin >> x; }
template <typename A, typename B> void in(pair<A,B> & x) { in(x.first); in(x.second); }
template <typename A> void in(vector<A> & x) { REP(i,0,(ll)x.size()) in(x[i]); }
template <typename Head, typename... Tail> void in(Head & H, Tail & ... T) {in(H); in(T...); }

#ifndef ONLINE_JUDGE
#define debug(...) do { cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); } while (false)
#else
#define debug(...) do { } while (false)
#endif

const ll inf = (ll)1e18 + 5;
const ll mod = 1e9+7;

ll nax = 1005;
VLL p(nax*nax, 1);
VLL P;

void init() {
	p[0] = 0;
	p[1] = 0;

	for (ll x = 2; x < nax*nax; x++) {
		if (p[x] == 0) {
			continue;
		}

		P.push_back(x);

		for (ll f = x; x * f < nax * nax; f++) {
			p[x*f] = 0;
		}
	}
}

map<ll,ll> pf(ll x) {
    map<ll,ll> f;
    REP(i,0,sz(P)) {
        if (P[i] * P[i] > x) break;
        while (x % P[i] == 0) {
            f[P[i]]++;
            x /= P[i];
        }
    }
    if (x > 1) f[x]++;
    return f;
}

VLL F(100500, -1);
VLL INVF(100500, -1);

ll pow(ll a, ll b) {
	if (b == 0) return 1;
	ll h = pow(a, b/2);
	ll ans = b % 2 ? h * h % mod * a : h * h;
	ans %= mod;
	return ans;
}

ll f(ll x) {
	if (F[x] != -1) return F[x];
	if (x == 0) return 1;
	F[x] = f(x-1) * x % mod;
	return F[x];
}

ll invf(ll x) {
	if (INVF[x] != -1) return INVF[x];
	INVF[x] = pow(f(x), mod-2);
	return INVF[x];
}

ll ncr(ll n, ll r) {
	// n! / r! / (n-r)!
	ll ans = f(n);
	ans *= invf(r);
	ans %= mod;
	ans *= invf(n-r);
	ans %= mod;
	return ans;
}

void solve() {
	ll n, m;
	in(n, m);

	map<ll,ll> factors = pf(m);

	REP(i,0,n) f(i); // ease on the recursion

	ll ans = 1;
	for (PLL a : factors) {
		ans *= ncr(a.second + n - 1, a.second) % mod;
		ans %= mod;
	}
	cout << ans << endl;

}

signed main() {
	init();
	ll t = 1;
	REP(i,0,t) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    if(n==1){
        cout << "Hello World" << "\n";
        return 0;
    }
    else{
        int a,b;
        cin >> a >> b;
        cout << a+b << "\n";
        return 0;
    }
}

#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}
int main(){
  ll A,B,C,D,i,ans = 1;scanf("%lld%lld",&A,&B);
  C = gcd(A,B);D = C;
  for(i=2;i*i<=C;i++){
    if(D%i==0){
      ans++;
      while(D%i==0) D /= i;
    }
  }
  if(D != 1) ans++;
  printf("%lld\n",ans);
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    string s;
    cin>>s;
    int left,right,dec=0,n=s.length();
    for(int i=0;i<(int)s.length()-1;i++){
        if(s[i]=='S'&&s[i+1]=='T'){
            s.erase(s.begin()+i);
            s.erase(s.begin()+i);
            dec+=2;
            i-=2;
        }
    }
    out(n-dec);
}

#include <iostream>
using namespace std;

int main() {
    long d;
    while(cin >> d) {
        long count = 0;
        for(int i=0; i<600; i+=d) {
            count += d*i*i;
        }
        cout << count << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(void){
  int n,i,j,ans=0;
  cin >>n;
  int l[200];
  int max,tmp;
  while(cin>>j){
    l[i] = j;
    i++;
  }
  cout<<endl;
  for(i=0;i<2*n-1;++i){
    max=i;
    for(j=i+1;j<2*n;++j){
      if(l[max]<l[j]){
        max=j;
      }
    }
    tmp=l[max];
    l[max]=l[i];
    l[i]=tmp;
  }

  for(i=1;i<2*n;i=i+2){
    ans+=l[i];
  }
  cout<<ans;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int getResult(vector<int> &L, const int size){
  sort(L.begin(), L.end());
  int sum = 0;
  for(int i = 0; i < size; i += 2){
    sum += L[i];
  }
  return sum;
}

int main(){
  int N;
  cin >> N;

  const int N2 = N * 2;
  vector<int> L(N2);
  for(int i = 0; i < N2; i++){
    cin >> L[i];
  }

  int result = getResult(L, N2);
  cout << result;
  return 0;
}


#include <iostream>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0; i<(int)(n); i++)

signed main() {
  int n;
  cin >> n;
  int s[n];
  rep(i,n) {
    char c;
    cin >> c;
    if(c == 'R') s[i] = 0;
    if(c == 'G') s[i] = 1;
    if(c == 'B') s[i] = 2;
  }

  int r[3][n+1];
  rep(i,3) rep(j,n+1) r[i][j] = 0;
  rep(i,3) rep(j,n) if(i == s[j]) r[i][j]++;
  rep(i,3) rep(j,n) r[i][n-1-j] = r[i][n-1-j] + r[i][n-j];

  int w = 0;
  rep(i,n) rep(j0,n-i-1) {
    int j = j0 + i + 1;
    if(s[i] != s[j]) {
      int k = 3 - s[i] - s[j], l = 2 * j - i;
      w += r[k][j+1];
      if(l < n && k == s[l]) w -= 1;
    }
  }
  cout << w << endl;
  return 0;
}

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int N, X[200] = { 0 }, a, b, c, d, Y[200];
	scanf("%d", &N);
	for (int i = 1; i <= N*(N - 1) / 2; i++) {
		scanf("%d %d %d %d", &a, &b, &c, &d);
		if (c == d) {
			X[a]++;
			X[b]++;
		}
		else if (c < d) {
			X[b] += 3;
		}
		else {
			X[a] += 3;
		}
	}
	int p = 1;
	for (int i = 1; i <= N; i++) {
		p = 1;
		//printf("%d\n", X[i]);
		for (int j = 1; j <= N; j++) {
			if (X[i] < X[j]) {
				p++;
			}
		}
		printf("%d\n", p);
	}
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}


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

long long dp[2][3003];

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&n,&k);

        for(i=1;i<=n;i++)
        {
            scanf("%lld %lld",&a,&b); vct.push_back(make_pair(a,b));
        }

        sort(vct.begin(),vct.end());

        long long idx,cap;

        for(idx=n-1;idx>=0;idx--)
        {
            for(cap=1;cap<=k;cap++)
            {
                fr=idx%2; sc=(idx+1)%2; a=vct[idx].first; b=vct[idx].second;

                p=0; q=0;

                if(idx==n-1 || cap-a<=0){  p=b; }
                else{  p=b+dp[sc][cap-a];   }

                if(idx!=n-1){  q=dp[sc][cap];  }

                dp[fr][cap]=max(p,q);

            }
        }

        printf("%lld\n",dp[0][k]);

    return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, t;
  cin >> n >> t;
  vector<P> v(n);
  rep(i, 0, n) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());

  vector<vector<int>> dp(n + 1, vector<int>(3001, 0));
  int ans = 0;
  rep(i, 0, n) {
    rep(j, 0, t) {
      chmax(dp[i + 1][j], dp[i][j]);
      if (j + v[i].first < t)
        chmax(dp[i + 1][j + v[i].first], dp[i][j] + v[i].second);
    }
    int now = dp[i][t - 1] + v[i].second;
    chmax(ans, now);
  }

  cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define sz(x) (int)x.size()
#define pii pair < int, int >
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const ll MAXN = 1e18;
const ll SIZE = 5e5 + 10;  //are u sure?
const ll mod = 1e9+7;
ll Lpref[SIZE], Rpref[SIZE];
ll Lsuff[SIZE], Rsuff[SIZE];
ll L[SIZE], R[SIZE];
ll mR = MAXN, mL = -MAXN;

void solve(){
	int N; cin >> N;
	for(int i = 0; i < N; i++){
		cin >> L[i] >> R[i];
		mR = min(mR, R[i]);
		mL = max(mL, L[i]);
	}
	Lpref[0] = -MAXN;
	Rpref[0] = MAXN;
	for(int i = 0; i < N; i++){
		Lpref[i + 1] = max(Lpref[i], L[i]);
		Rpref[i + 1] = min(Rpref[i], R[i]);
	}

	Lsuff[N - 1] = L[N - 1];
	Rsuff[N - 1] = R[N - 1];
	for(int i = N - 1; i > 0; i--){
		Lsuff[i - 1] = max(Lsuff[i], L[i]);
		Rsuff[i - 1] = min(Rsuff[i], R[i]);
	}
	ll ans = 0;
	for(int i = 0; i < N; i++){
		ll cur = (R[i] - L[i] + 1) + max(0LL, min(Rpref[i], Rsuff[i + 1]) - max(Lpref[i], Lsuff[i + 1]) + 1);
		ans = max(ans, cur);
	}
	vector<pair<ll, ll>> vec;
	for(int i = 0; i < N; i++){
		vec.push_back(mp(L[i], R[i]));
	}
	sort(all(vec));
	for(int i = N - 1; i > 0; i--){
		vec[i - 1].second = min(vec[i - 1].second, vec[i].second);
	}
	for(int i = 0; i + 1 < N; i++){
		ll cur = max(0LL, mR - vec[i].first + 1) + max(0LL, vec[i + 1].second - mL + 1);
		ans = max(ans, cur);
	}
	cout << ans << endl;
}

int main(){
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll M;
    cin >> M;
    ll n = 0, s = 0;
    rep(i, M) {
        ll d, c;
        cin >> d >> c;
        n += c;
        s += d * c;
    }
    ll ans = n - 1 + (s - 1) / 9;
    cout << ans << endl;
}


#include <iostream>
using namespace std;

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

ll n,a,b,c,d;
ll dp[1010][1010];
ll K[1010];
ll cc[1010][1010];
ll inv[1010];

ll mul(ll _a, ll _b) {
  if (_b == 0) return 1LL;
  if (_b == 1) return _a;
  ll ans = mul(_a, _b/2);
  ans *= ans;
  ans %= MOD;
  if (_b&1) ans *= _a;
  return ans % MOD;
}

ll C(ll _n, ll _k) {
  if (cc[_n][_k] != 0LL) return cc[_n][_k];
  if (_n == _k) return cc[_n][_k] = 1;
  return cc[_n][_k] = (K[_n] * ((inv[_k] * inv[_n-_k]) % MOD)) % MOD;
}

ll get(ll groups, ll mem, ll from) {
  ll ans = 1;

  REP(i,groups) {
    ans *= C(from, mem);
    ans %= MOD;
    from -= mem;
  }

  return (ans * inv[groups]) % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> a >> b >> c >> d;
  dp[0][0] = 1;

  K[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i <= n; i++) {
    K[i] = K[i-1]*i;
    K[i] %= MOD;
    inv[i] = mul(K[i], MOD-2);
  }

  for (ll i = 1; i <= b; i++) {
    if (i < a) {
      dp[i][0] += dp[i-1][0];
      dp[i][0] %= MOD;
      continue;
    }
    REP(j,n+1) {
      dp[i][j] += dp[i-1][j];
      dp[i][j] %= MOD;
      ll k = c;
      while (k <= d && j + k * i <= n) {
        dp[i][j+k*i] += dp[i-1][j] * get(k, i, n-j);
        dp[i][j+k*i] %= MOD;
        k++;
      }
    }
  }
  cout << dp[b][n] << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////
#define N 100004

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else if(p==1)return mod(i);
    else if(p%2==0)return mod(po(mod(mod(i)*mod(i)),p/2));
    else  return mod(mod(i)*mod(po(i,p-1)));
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    for(int i=1;i<N;i++){
        kai[i]=mod(kai[i-1]*i);
        kai2[i]=mod(po(kai[i],i_5));
    }
}
ll comb(ll n,ll k){
    if(n==0){
        if(k==0)return 1;
        else return 0;
    }
    else if(n<k)return 0;
    else return mod(mod(mod(kai[n])*mod(kai2[n-k]))*mod(kai2[k]));
}

//#include <time.h>

int main(){
   // clock_t start = clock();    // スタート時間
    calc();
    ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    ll dp[n+5][n+5];
    memset(dp,0,sizeof(dp));
    dp[a][0]=1;

    rep(k,a,b){
        rep(j,0,n){
            for(ll p=0;j+p*k<=n&&p<=d;p++){
                ll add=comb(n-j,p*k);
                add=mod(add*dp[k][j]);
                add=mod(add*kai[p*k]);
                add=mod(add*kai2[p]);
                ll w=(ll)po(kai2[k],p);
                add=mod(add*w);
                Add(&dp[k+1][j+p*k],add);
                if(p==0)p=c-1;
            }
        }
    }

    /*rep(i,0,b+1){
        rep(j,0,n){
            cout<<dp[i][j]<<"  ";
        }cout<<endl;
    }*/

    cout<<mod(dp[b+1][n])<<endl;

    //clock_t end = clock();     // 終了時間
   // std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
    return 0;
}


#include <iostream>
#include <map>
using namespace std;

struct UF{
    int par[200000];
    int rank[200000];

    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }

    int find(int x){
        if(par[x]==x)return x;
        return par[x]=find(par[x]);
    }

    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x!=y){
            if(rank[x]<rank[y]){
                par[x]=y;
            }else{
                par[y]=x;
                if(rank[x]==rank[y])rank[x]++;
            }
        }
    }

    bool same(int x, int y){
        return par[x]==par[y];
    }
};

int main(void){
    int n,k,l;
    map<pair<int, int>, int> u;
    cin>>n>>k>>l;
    UF a,b;
    a.init(n);
    b.init(n);

    for(int i=0;i<k;i++){
        int p,q;
        cin>>p>>q;
        a.unite(p, q);
    }
    for(int i=0;i<l;i++){
        int p,q;
        cin>>p>>q;
        b.unite(p, q);
    }
    for(int i=1;i<=n;i++){
        u[pair<int,int>(a.find(i),b.find(i))]++;
    }
    for(int i=1;i<=n;i++){
        cout<<u[pair<int,int>(a.find(i),b.find(i))];
        if(i<n)cout<<" ";
        else cout<<endl;
    }

}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 2e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2, class T3> void add( T1 &x, T2 y, T3 m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2, class T3> void sub( T1 &x, T2 y, T3 m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

vector<int>roads[MAXN], rails[MAXN];
vector<bool>vis(MAXN), vis2(MAXN);
int road_comp[MAXN], road_size[MAXN];
int rail_comp[MAXN], rail_size[MAXN], cc;

void roads_dfs( int node )
{
	vis[node] = 1;
	road_comp[node] = cc;
	road_size[cc]++;
	for( int next : roads[node] )
	{
		if( !vis[next] )
		{
			roads_dfs(next);
		}
	}
}

void rails_dfs( int node )
{
	vis2[node] = 1;
	rail_comp[node] = cc;
	rail_size[cc]++;
	for( int next : rails[node] )
	{
		if( !vis2[next] )
		{
			rails_dfs(next);
		}
	}
}

int main()
{
	fastio();

	int n,k,l;
	cin>>n>>k>>l;
	for(int i=0;i<k;i++)
	{
		int u,v;
		cin>>u>>v;
		u--,v--;
		roads[u].pb(v);
		roads[v].pb(u);
	}
	for(int i=0;i<l;i++)
	{
		int u,v;
		cin>>u>>v;
		u--,v--;
		rails[u].pb(v);
		rails[v].pb(u);
	}

	cc = 0;
	for(int i=0;i<n;i++)
	{
		if( !vis[i] )
		{
			roads_dfs(i);
			cc++;
		}
	}

	cc = 0;
	for(int i=0;i<n;i++)
	{
		if( !vis2[i] )
		{
			rails_dfs(i);
			cc++;
		}
	}

	vector<int>order;
	for(int i=0;i<n;i++)
		order.pb(i);

	auto cmp = [&]( int i, int j ) -> bool
	{
		if( road_comp[i] != road_comp[j] )
			return road_comp[i] < road_comp[j];
		return rail_comp[i] < rail_comp[j];
	};

	sort(all(order), cmp);

	vector<int>ans(n);
	for(int i=0;i<n;)
	{
		int a = road_comp[order[i]], b = rail_comp[order[i]];
		int j = i;
		while( j < n && road_comp[order[j]] == a && rail_comp[order[j]] == b ) j++;
		for(int k=i;k<j;k++)
			ans[order[k]] = j-i;
		i = j;
	}

	for(int i=0;i<n;i++)
		cout<<ans[i]<<" ";

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


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

int M = 1000000007;

int mod(int a){
	return (a%M + M)%M;
}
int mul(int a, int b){
	return mod(mod(a) * mod(b));
}
int add(int a, int b){
	return mod(mod(a) + mod(b));
}
int sub(int a, int b){
	return mod(mod(a) - mod(b));
}
main(){
	int n; cin>>n;
	int a[n];
	for(auto &it : a) cin>>it;

	int sum=0, sum1=0;
	for(int i=0; i<n; i++){
		sum = add(sum,a[i]);
		//sum1 = add(sum1,mul(a[i],a[i]));
	}
	int ans=0;
    for(int i=0; i<n; i++){
		sum = sub(sum,a[i]);
		ans = add(ans,mul(sum,a[i]));
	}
	cout<<ans;
}

#include <iostream>
using namespace std;
#define MOD 1000000007

int main(int argc, const char * argv[]) {
    int N;
    cin>>N;
    int *A=new int[N];
    long long s=0,s2=0;
    for(int i=0;i<N;++i){
        cin>>A[i];
        s+=A[i];
        s%=MOD;
        s2+=(long long)A[i]*A[i];
        s2%=MOD;
    }
    s*=s;
    s%=MOD;
    s-=s2;
    s%=MOD;
    if(s<0){
        s+=MOD;
    }
    if(s%2==0){
        cout<<(s/2)<<endl;
    }else{
        cout<<((s+MOD)/2)<<endl;
    }

    delete[] A;
    return 0;
}


// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

ll power(ll x, ll y);
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_dedges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B);}
#define in_wedges(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C), v[B].pb(A, C);}
#define in_dwedges(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C);}
#define endl "\n"

const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 18;
const int inf = 2e9;

const int N = 2e5 + 5;
int a[N], b[N];
int A[N], B[N];

int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    int n;
    cin >> n;
    repp(i, 1, n) cin >> a[i];
    repp(i, 1, n) cin >> b[i];

    repp(i, 1, n) A[a[i]]++, B[b[i]]++;
    repp(i, 1, n) if(A[i] + B[i] > n){
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";
    rep(i, 1, N) A[i] += A[i - 1], B[i] += B[i - 1];
    int mx = 0;
    repp(i, 1, N) mx = max(mx, A[i] - B[i - 1]);
    repp(i, 1, n) cout << b[(i - mx + n - 1) % n + 1] << " ";
}

ll power(ll x, ll y){
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;}
    return res;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    vector<ll >v;
    vector<ll >vp;

    ll i,j,k;
    ll a,b;
    for(i=0; i<n; i++)
    {
        cin>>a;
        v.push_back(a);

    }
    for(i=0; i<n; i++)
    {
        cin>>a;
        vp.push_back(a);

    }
    reverse(vp.begin(),vp.end());
    ll f=0;

    ll l=0,r=n-1;
    for(i=0; i<n; i++)
    {
        if(v[i]==vp[i])
        {
            if(v[l]!=vp[i]&&v[i]!=vp[l])
            {
                //  cout<<l<<"  f "<<i<<endl;

                swap(vp[l],vp[i]);
                  l++;
            }
            else if(v[r]!=vp[i]&&v[i]!=vp[r] )
            {
                  //   cout<<l<<"  s "<<endl;
                f=0;
                swap(vp[r],vp[i]);
                r--;
            }
            else
            {
                f=1;
                break;
            }
        }
    }

    if(f)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<< "Yes"<<endl;
        for(ll i=0; i<n; i++)
        {
            cout<<vp[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;

  int n = 1000000000;
  for (int i = 0; i < N; i++){
  		int A;
    cin >> A;

	int a = 0;

    while ( A % 2 == 0){
      a++;
      A /= 2;
    }

	if(n > a)
      n = a;
  }

  cout << n << endl;

}

#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

vector<bool> prime(1000001,1);

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for(int i=2;i*i<=1000000;i++)
    if(prime[i])
      for(int j=i*2;j<=1000000;j+=i)
        prime[j]=0;

  int n; cin>>n;
  vector<int> ans; int p=11;
  while(ans.size()<n){
    if(prime[p]&&(p%5==1))
      ans.eb(p);
    p++;
  }

  for(auto i:ans)
    cout<<i<<" ";
  cout<<"\n";
  return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#include <vector>
#include <limits.h>
#include <stack>
#include <queue>
#define maxn 1e9
#define pi acos(-1)
#define LL long long
using namespace std;
double aabs(double x)
{
	if(x<0)return -x;
	return x;
}
int gcd(int a,int b)
{
	if(a%b==0)return b;
	return gcd(b,a%b);
}
struct card{char suit,value;};
void bubble(struct card A[],int N)///冒泡排序；
{
	for(int i=0;i<N;i++)
		for(int j=N-1;j>=i+1;j--)
			if(A[j].value<A[j-1].value)
			{
				card t=A[j];
				A[j]=A[j-1];
				A[j-1]=t;
			}
}
void selection(struct card A[],int N)///选择排序；
{
	for(int i=0;i<N;i++)
	{
		int minj=i;
		for(int j=i;j<N;j++)
		{
			if(A[j].value<A[minj].value)minj=j;
		}
		card t=A[i];
		A[i]=A[minj];
		A[minj]=t;
	}
}
LL cnt;
int l;
int a[1000000];
int n;
vector<int>G;
void insertionSort(int A[],int n,int g)///指定了间隔g的插入排序
{
	for(int i=g;i<n;i++)
	{
		int v=A[i];
		int j=i-g;
		while (j>=0&&A[j]>v) {
			A[j+g]=A[j];
			j-=g;
			cnt++;
		}
		A[j+g]=v;
	}
}
void shellSort(int A[],int n)///希尔排序；
{
	for(int h=1;;)//生成数列G={1,4,13,40,121,364,1093,.....}
	{
		if(h>n)break;
		G.push_back(h);
		h=3*h+1;
	}
	for(int i=G.size()-1;i>=0;i--)///按逆序指定G[i]=g;
	{
		insertionSort(A, n, G[i]);
	}
}
bool isStable(struct card c1[],struct card c2[],int N)///判断稳定；
{
	for(int i=0;i<N;i++)
	{
		if(c1[i].suit!=c2[i].suit)return false;
	}
	return true;
}
int main()
{
	card c1[107],c2[107];
	int n;
	char ch;
	cin>>n;
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	cnt=0;
	shellSort(a, n);
	cout<<G.size()<<endl;
	for(int i=G.size()-1;i>=0;i--)
	{
		printf("%d",G[i]);
		if(i)printf(" ");
	}
	printf("\n");
	printf("%lld\n",cnt);
	for(int i=0;i<n;i++)printf("%d\n",a[i]);
	return 0;
}

#include<iostream>
#include<stdio.h>
#include<vector> // 可変長配列
using namespace std;
static const int MAX = 1000000;

void printLine(int A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

int insertionSort(int A[], int N, int g) {
    int cnt = 0;
    for (int i = g; i < N;i++) {
        int seq = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > seq) {
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = seq;
    }
    return cnt;
}

int shellSort(int A[], int N) {
    // 可変長配列でshell sortの幅を生成
    // この段階では昇順[1, 3, 9...]
    vector<int> vec;
    vec.push_back(1); // append
    for (int i = 1;;) {
        i = i * 3;
        if (i > N) {
            break;
        }
        vec.push_back(i); // append
    }

    // 幅リストのサイズ
    int s = vec.size();
    printf("%d\n", s);

    int cnt = 0;
    // 降順に評価

    for (int i = s - 1;i >= 0;i--) {
        if (i < s - 1) {
            printf(" ");
        }
        printf("%d", vec[i]);
        cnt += insertionSort(A, N, vec[i]);
    }
    printf("\n");
    return cnt;
}

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

    int A[MAX];
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    //insertionSort(A, N, 1);
    int cnt = shellSort(A, N);
    printf("%d\n", cnt);
    for (int i = 0; i < N; i++) {
        printf("%d\n", A[i]);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001
//0=48,A=65,a=97

int main() {
    int n;cin >> n;
    string s,t;cin >> s >>t;
    string m;
    for(int i = 0; i < n; i++) {
        bool x=true;
        string y;
        for(int j = i; j < n; j++) {
            if(s[j]==t[j-i]) y += s[j];
            else{
                x=false;
                break;
            }
        }
        if(x){
            m=y;
            break;
        }
    }

    cout << 2*n-m.size() << endl;

    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;

int main(void){
        int N;
        string s, t;
        cin >> N >> s >> t;
        int ans = 2*N;
        rep(i,N) {
                if (s.substr(i,N-i) == t.substr(0,N-i) ){ ans = N+i; break;}
        }
        cout << ans << endl;

        return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

class UnionFind {
public:
  UnionFind(ll n) : par(n, -1), rnk(n, 0), cnt(n, 1), _size(n) {}

  bool same(ll x, ll y) {
    return root(x) == root(y);
  }
  void unite(ll x, ll y) {
    x = root(x); y = root(y);
    if (x == y) return;

    --_size;

    if (rnk[x] < rnk[y]) { swap(x, y); }
    par[y] = x;
    cnt[x] += cnt[y];
    if (rnk[x] == rnk[y]) { ++rnk[x]; }
  }
  ll root(ll x) {
    if (par[x] < 0) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  ll count(ll x) {
    return cnt[root(x)];
  }
  ll size() {
    return _size;
  }

private:
  vector<ll> par;
  vector<ll> rnk;
  vector<ll> cnt; // The number of vertices in each connected components.
  ll _size; // The number of connected components. Decreases by unite.
};

// int main(int argc, char** argv) {
//   ll N, M;
//   cin >> N >> M;
//   UnionFind tree(N);
//   rep(i, M) {
//     ll p, a, b;
//     cin >> p >> a >> b;
//     if (p == 0) { // Connect
//       tree.unite(a, b);
//     } else { // Judge
//       if (tree.same(a, b)) {
//         cout << "Yes" << endl;
//         cout << "size: " << tree.size() << endl;
//         cout << "count(" << a << "): " << tree.count(a) << endl;
//         cout << "count(" << b << "): " << tree.count(b) << endl;
//       } else {
//         cout << "No" << endl;
//         cout << "size: " << tree.size() << endl;
//         cout << "count(" << a << "): " << tree.count(a) << endl;
//         cout << "count(" << b << "): " << tree.count(b) << endl;
//       }
//     }
//   }
// }

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<P> xs; // pair of <x, id>
  vector<P> ys; // pair of <y, id>
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    xs.emplace_back(x, i);
    ys.emplace_back(y, i);
  }
  sort(all(xs));
  sort(all(ys));
  vector<triple> edges; // <cost, from, to>
  rep(i, n-1) {
    auto& from = xs[i];
    auto& to = xs[i+1];
    edges.emplace_back(abs(from.first - to.first), from.second, to.second);
  }
  rep(i, n-1) {
    auto& from = ys[i];
    auto& to = ys[i+1];
    edges.emplace_back(abs(from.first - to.first), from.second, to.second);
  }

  sort(all(edges));

  ll ans = 0;
  UnionFind uf(n);
  for (auto& edge : edges) {
    ll cost, from, to;
    tie(cost, from, to) = edge;
    if (uf.same(from, to)) { // already connected
      // Do nothing
    } else {
      uf.unite(from, to);
      ans += cost;
    }
  }
  cout << ans << endl;
}

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ")
#define print1(v) cout << fixed << setprecision(10) << v << "\n"
#define print2(v1, v2) cout << fixed << setprecision(10) << v1 << " " << v2 << "\n"
#define printvi(v, n) REP(iiii, n) { cout << v[iiii]; delim(iiii, n); }
#define printvii(v, h, w) REP(iiiii, h) { printvi(v[iiiii], w); }

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 1e5;
int n;
vi x(maxn);
vi y(maxn);
vb used(maxn);
graph G(maxn);

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

// O(|E|log|V|)
int prim() {
    int s = 0;
    used.assign(n, false);
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.emplace(0, s);
    int ret = 0;
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (used[v]) continue;
        used[v] = true;
        ret += p.first;
        for (auto &e : G[v]) pq.emplace(e.cost, e.to);
    }
    return ret;
}

signed main () {
	cin.tie(0);
   	ios::sync_with_stdio(false);

    cin >> n;
    REP(i, n) {
        cin >> x[i] >> y[i];
    }

    vi idx(n);
    vi idy(n);
    REP(i, n) {
        idx[i] = i;
        idy[i] = i;
    }
    sort(idx.begin(), idx.end(), [&](int i, int j) { return x[i] < x[j]; });
    sort(idy.begin(), idy.end(), [&](int i, int j) { return y[i] < y[j]; });

    REP(i, n-1) {
        edge e;
        int s = idx[i];
        e.to = idx[i+1];
        e.cost = x[e.to] - x[s];
        G[s].push_back(e);
        swap(e.to, s);
        G[s].push_back(e);
    }
    REP(i, n-1) {
        edge e;
        int s = idy[i];
        e.to = idy[i+1];
        e.cost = y[e.to] - y[s];
        G[s].push_back(e);
        swap(e.to, s);
        G[s].push_back(e);
    }

    int ret = prim();

    print1(ret);
}


#include<cstdio>
using ull = unsigned long long;
const static int MOD = 1000000007;
const static int MAX_H = 100;
const static int MAX_W = 8;
ull dp[MAX_H+1][MAX_W], fibonacci[8] = {1, 1, 2, 3, 5, 8, 13, 21};

int main(){
    unsigned H, W, K;
    scanf("%u %u %u", &H, &W, &K);
    if(W == 1){
        printf("1\n");
        return 0;
    }
    K--;
    dp[0][0] = 1;
    for (size_t i = 1; i <= H; i++){
        dp[i][0] = (dp[i-1][0]*fibonacci[W-1] + dp[i-1][1]*fibonacci[W-2]) %MOD;
        for (size_t j = 1; j < W-1; j++){
            dp[i][j] = (dp[i-1][j-1]*fibonacci[j-1]*fibonacci[W - j - 1] + dp[i-1][j]*fibonacci[j]*fibonacci[W - j - 1] + dp[i-1][j+1]*fibonacci[j]*fibonacci[W - j - 2]) %MOD;
        }
        dp[i][W-1] = (dp[i-1][W-1]*fibonacci[W-1] + dp[i-1][W-2]*fibonacci[W-2]) %MOD;
    }
    printf("%llu\n", dp[H][K]);
	return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int h,w,k;
	cin >> h >> w >> k;

	//前処理,0~w-2の辺があったとき,それぞれが隣り合った辺を選んでいない場合の数.

	map<int,int> mp;
	ll sum = 0;
	for(int i = 0;i < (1 << w-1);i++){
		vector<int> now;
		for(int j = 0;j < w-1;j++){
			if((i >> j) & 1)now.push_back(j);
		}

		bool flag = true;
		for(int j = 0;j < (int)now.size() - 1;j++){
			if(now[j+1] == now[j] + 1)flag = false;
		}

		if(!flag)continue;
		for(int j = 0;j < now.size();j++)mp[now[j]]++;
		sum++;
	}

	vector<vector<vector<ll>>> dp(h+1,vector<vector<ll>>(w,vector<ll>(w,0)));
	for(int i = 0;i < w;i++)dp[0][i][i] = 1;

	for(int i = 0;i < h;i++){//今見ている高さ.
		for(int j = 0;j < w;j++){
			for(int k = 0;k < w;k++){
				//dp[i][j][k]:=高さiにおいてj->kとなる場合の数.
				//j-が取れる.
				if(k-1 >= 0){
					dp[i+1][j][k-1] += dp[i][j][k] * mp[k-1];
					dp[i+1][j][k-1] %= MOD;
				}
				if(k+1 <= w-1){
					dp[i+1][j][k+1] += dp[i][j][k] * mp[k];
					dp[i+1][j][k+1] %= MOD;
				}
				dp[i+1][j][k] += dp[i][j][k] * (sum - mp[k-1] - mp[k]);
				dp[i+1][j][k] %= MOD;
			}
		}
	}
	cout << dp[h][0][k-1] << endl;
}


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

int main(void){

    list<char> A;
    list<char> B;
    list<char> C;

    string S_A,S_B,S_C;
    cin >> S_A >> S_B >> S_C;
    for(int i=0;i<S_A.size();i++) A.push_back(S_A[i]);
    for(int i=0;i<S_B.size();i++) B.push_back(S_B[i]);
    for(int i=0;i<S_C.size();i++) C.push_back(S_C[i]);

    char t = A.front();
    A.pop_front();

    while(1){

        if(t == 'a'){
            if(A.size() == 0){
                cout << 'A' << endl;
                return 0;
            }
            t = A.front();
            A.pop_front();

        }
        else if(t == 'b'){
            if(B.size() == 0){
                cout << 'B' << endl;
                return 0;
            }
            t = B.front();
            B.pop_front();

        }
        else{
            if(C.size() == 0){
                cout << 'C' << endl;
                return 0;
            }
            t = C.front();
            C.pop_front();
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c) cout<<"No";
	else if(a!=b&&a!=c&&b!=c) cout<<"No";
	else cout<<"Yes";
	return 0;
}


#include<iostream>

int main()
{
	int x, S;
	std::cin >> x;

	S = x * x * x;
	std::cout << S << std::endl;

	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
    int x;
    cin >> x;
    out(x/3);
}


#include<iostream>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	int ans = 0;
	if (B == 1) {

	}
	else {
		for (int i = 1; i < 100; i++) {
			if (i * A - i + 1 >= B) {
				ans = i;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int day,mon[]={31,29,31,30,31,30,31,31,30,31,30,31},now,ans;
    for(;;){
    ans=0;
    cin>>now>>day;
    if(now==0)break;
    for(int i=0;i<now-1;i++){
        ans+=mon[i];
    }
    ans+=day;
    ans=ans%7;
    if(ans==1)printf("Thursday\n");
    if(ans==2)printf("Friday\n");
    if(ans==3)printf("Saturday\n");
    if(ans==4)printf("Sunday\n");
    if(ans==5)printf("Monday\n");
    if(ans==6)printf("Tuesday\n");
    if(ans==0)printf("Wednesday\n");
}
}


#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  string s; cin >> s;
  if (s.size()%2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  for(int i=0; i<s.size(); i+=2) {
    if (s[i] == 'h' && s[i+1] == 'i') continue;
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

// EOF


#include <bits/stdc++.h>
#include<math.h>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007
ll gcd (ll x, ll y){
	ll r = x % y ;
	if(r == 0) return y ;
	return gcd(y, r) ;
}
bool isprime(ll x){
	ll s = sqrt((double) x) ;
	for(ll i = 2; i <= s ; i++){
		if(x % i == 0) return false ;
	}
	return true ;
}
int main (){
	ll a, b ;
	cin >> a >> b ;
	ll k = gcd(a, b) ;
	ll s = sqrt((double)k) ;
	vector<ll> y ;
	for(ll i = 1; i <= s; i++){
		if(k % i == 0){
			y.push_back(i) ;
			if(i != k/i){
				y.push_back(k/i) ;
			}
		}
	}
	sort(y.begin(), y.end()) ;
	ll num = y.size() ;
	ll ans = 0 ;
	rep(i, num){
		if(isprime(y[i])) ans++ ;
	}
	cout << ans << endl ;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
// using namespace atcoder;
void Main()
{
    ll A, B;
    cin >> A >> B;

    ll gcd = GCD(A, B);
    auto primes = prime_factorize(gcd);
    put(primes.size() + 1);
}
signed main(){ Main();return 0;}


///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n,m,v,p;
vector<pi>vec;
int a[M+3];
bool vis[M+3];
bool chk(int idx)
{
   int big=p-1;
   int use=v-1;
   int mn=min(big,use);
   big-=mn;
   use-=mn;
   vector<pi>yo;
   if(vis[idx])return true;
   int mx=vec[idx].fi+m;
   int sum=use*m;
   //cout<<sum<<" ### "<<endl;
   for(int i=p-1;i<n;i++)
   {
       if(i==idx)continue;
       int val=vec[i].fi;
       int gap=mx-val;
       if(gap<0)
       {
           //cout<<i<<" "<<mx<<" "<<val<<endl;
       }
       if(gap<0)return false;
       int can=min(gap,m);
       sum-=can;
   }
   if(sum<=0)return true;
   else return false;
}
 main()

{
    fast
    cin>>n>>m>>v>>p;
    f(i,1,n)
    {
        int x;
        cin>>x;
        a[i]=x;
        vec.pb(mp(x,i));
    }
    sort(vec.rbegin(),vec.rend());
    int last;
    for(int i=0;i<p;i++)
    {
        vis[i]=true;
        last=vec[i].fi;
    }
    for(int i=p;i<n;i++)
    {
        if(vec[i].fi==last)
        {
            vis[i]=true;
        }
        else break;
    }
   // cout<<chk(3)<<"#"<<endl;
    int lo=0,hi=n-1;
    while(hi-lo>=2)
    {
        int mid=(lo+hi)>>1;
        if(chk(mid))lo=mid;
        else hi=mid-1;
    }
    int ses=-1;
    for(int i=lo;i<=hi;i++)
    {
        if(chk(i))ses=i;
    }
    if(ses==-1)
    {
        cout<<"0"<<endl;
        return 0;
    }
    ses=ses+1;
    cout<<ses<<endl;
    return 0;

}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#define LL long long
using namespace std;
const int MAX=1e5+3;
LL a[MAX];
LL add[MAX];
inline bool myru(LL x,LL y){return x>y;}
LL rin()
{
	LL s=0;
	char c=getchar();
	bool bj=0;
	for(;(c>'9'||c<'0')&&c!='-';c=getchar());
	if(c=='-')bj=1,c=getchar();
	for(;c>='0'&&c<='9';c=getchar())s=(s<<1)+(s<<3)+(c^'0');
	if(bj)return -s;
	return s;
}
int main()
{
	//以下规则有先后判定，优先满足靠前的规则
	//1.如果从大到小排序后a[p]-a[i]>m 则a[i]绝对无法入选
	//2.如果从p到i-1这些数不选时能凑够v个选票，则a[i]可以入选
	//3. ∑j=i-1 To p a[i]+m-a[j] >= (v-n+(i-p))*m ,则a[i]可以入选
	int i,j;
	LL n,m,v,p;
	n=rin();m=rin();v=rin(),p=rin();
	for(i=1;i<=n;i++)a[i]=rin();sort(a+1,a+n+1,myru);

	add[0]=0;for(i=1;i<=n;i++)add[i]=add[i-1]+a[i];
	int ans=p;
	for(i=p+1;i<=n&&a[i]==a[p];i++)ans++;
	for(;i<=n;i++)
	{
		if(a[p]-a[i]>m)continue;
		if(n-(i-p)>=v){ans++;continue;}
		LL sum=a[i]+m;
		sum*=(i-p);
		sum-=add[i-1]-add[p-1];
		if(sum>=m*(v-(n-(i-p))))ans++;
	}
	printf("%d",ans);
	return 0;
}


/*
* @Author: wxyww
* @Date:   2020-05-21 15:53:33
* @Last Modified time: 2020-05-21 16:09:36
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
#include<cmath>
using namespace std;
typedef long long ll;
const int N = 200010;
#define int ll
ll read() {
	ll x = 0,f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1; c = getchar();
	}
	while(c >= '0' && c <= '9') {
		x = x * 10 + c - '0'; c = getchar();
	}
	return x * f;
}
int n;
ll tmp[N];
void mul(int *a,int *b) {
	for(int i = 1;i <= n;++i) {
		tmp[i] = a[b[i]];
	}
	for(int i = 1;i <= n;++i) a[i] = tmp[i];
}
int a[N],p[N];
void qm(ll y) {
	int ret[N];
	for(int i = 1;i <= n;++i) ret[i] = i;

	for(;y;y >>= 1,mul(p,p))
		if(y & 1) mul(ret,p);
	for(int i = 1;i <= n;++i) p[i] = ret[i];
}
signed main() {
	n = read();
	for(int i = 1;i <= n;++i) {
		a[i] = read();p[i] = i;
	}

	int m = read();ll K = read();

	for(int i = n;i >= 1;--i) a[i] -= a[i - 1];

	for(int i = 1;i <= m;++i) {
		int x = read();
		swap(p[x],p[x + 1]);
	}

	qm(K);

	for(int i = 1;i <= n;++i) tmp[i] = a[p[i]];
	// for(int i = 1;i <= n;++i) printf("%d ",tmp[i]);
	// puts("");
	for(int i = 1;i <= n;++i) {
		printf("%lld.0\n",tmp[i] += tmp[i - 1]);
	}
	return 0;
}

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

struct rectangle{
  int h, w;
  bool operator<(const rectangle &a)const{
    if(w*w + h*h == a.w*a.w + a.h*a.h)
      return h < a.h;
    return w*w + h*h < a.w*a.w + a.h*a.h;
  }
};

int main(){
  vector<rectangle> ans;
  for(int i = 1; i <= 150; i++) {
    for(int j = i + 1; j <= 150; j++) {
      rectangle r;
      r.h = i, r.w = j;
      ans.push_back(r);
    }
  }
  sort(ans.begin(), ans.end());
  for(int i = 0; i < 20; i++) {
    //cout << ans[i].h << " " << ans[i].w << endl;
}
  int h, w;
  while(cin >> h >> w, h){
    rectangle r;
    r.h = h, r.w = w;
    for(int i = 0; i < ans.size(); i++){
      if(r < ans[i]){
	cout << ans[i].h << " " << ans[i].w << endl;
	break;
      }
    }
  }
  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

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

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5+5, LG = 17, MOD = 1e9+7;
const int SQ = 320;
const long double EPS = 1e-7;
int a[N];
int F[N<<1], iF[N<<1];
int n;
int fast(int b, int e){
  int res = 1;
  for(;e;b=1ll*b*b%MOD,e>>=1)
    if(e&1)res = 1ll * res * b % MOD;
  return res;
}
void init(){
  F[0] = iF[0] = 1;
  f(i,1,N<<1){
    F[i] = 1ll * i * F[i-1] % MOD;
    iF[i] = fast(F[i], MOD - 2);
  }
}
int get(int x1, int y1, int x2, int y2){
  int cntX = x2 - x1;
  int cntY = y2 - y1;
  return 1ll *F[cntX+cntY] * iF[cntX] % MOD * iF[cntY] % MOD;
}
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE
  init();
  int H,W,A,B;
  cin>>H>>W>>A>>B;
  int ans = 0;
  f(i,1,H-A+1){
    int x = get(1,1,i,B+1);
    if(i>1)x-=get(1,1,i-1,B+1);
    if(x<0)x+=MOD;
    ans += 1ll * x *get(i,B+1,H,W) % MOD;
    if(ans>=MOD)ans-=MOD;
  }
  cout<<ans<<endl;
  return 0;
}

#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1);
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}

////////////////////////////////////////////////////////////////////

int main() {
ll n,m,k;
cin>>n>>m>>k;

ll ml=com(n*m-2,k-2);

ll ans=0;
for(int i=1;i<=n-1;i++){
	ans+=i*m*m*(n-i);
	ans%=MOD;
}

for(int i=1;i<=m-1;i++){
	ans+=i*n*n*(m-i);
	ans%=MOD;
}

ans*=ml;
ans%=MOD;
cout<<ans<<endl;

return 0;

}


#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	int a[5];
	char ans[5];
	string b;
	cin>>b;
	for(int i=0;i<4;i++){
		a[i]=b[i]-'0';
		ans[i]='+';
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			int sum=0;
			for(int k=0;k<4;k++){
				if(k==i  && k!=0 || k==j && k!=0){
					sum-=a[k];
				}
				else{
					sum+=a[k];
				}
			}
			if(sum==7){
				ans[i]='-';
				ans[j]='-';
				cout<<a[0]<<ans[1]<<a[1]<<ans[2]<<a[2]<<ans[3]<<a[3]<<"="<<"7"<<endl;
				return(0);
			}
		}
	}

    return(0);
}

#include <iostream>
using namespace std;

int main() {
    int abcd;
    cin >> abcd;
    int num[4] = {abcd / 1000, (abcd / 100) % 10, (abcd / 10) % 10, abcd % 10};
    int sum;
    bool match = false;

    for (int bit = 0; bit < (1 << 3); bit++) {
        sum = num[0];
        for (int i = 0; i < 3; i++) {
            if (bit & (1 << i)) sum -= num[i + 1];
            else
                sum += num[i + 1];
        }
        if (sum == 7) {
            match = true;
            cout << num[0];
            for (int j = 0; j < 3; j++) {
                if (bit & (1 << j)) cout << "-" << num[j + 1];
                else
                    cout << "+" << num[j + 1];
            }
            cout << "=7" << endl;
            break;
        }
        if (match) break;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#define MOD 998244353
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll n,m,f[1000010],finv[1000010];
ll qpow(ll a,ll b){
	ll re=1;
	while(b){
		if(b&1) re=re*a%MOD;
		a=a*a%MOD;b>>=1;
	}
	return re;
}
void init(){
	ll i,len=n+m;
	f[0]=f[1]=finv[0]=finv[1]=1;
	for(i=2;i<=len;i++) f[i]=f[i-1]*i%MOD;
	finv[len]=qpow(f[len],MOD-2);
	for(i=len;i>2;i--) finv[i-1]=finv[i]*i%MOD;
}
ll C(ll y,ll x){
//	cout<<"C "<<x<<' '<<y<<' '<<f[x]<<' '<<finv[y]<<' '<<finv[x-y]<<'\n';
	return f[x]*finv[y]%MOD*finv[x-y]%MOD;
}
int main(){
	n=read();m=read();int i;ll ans=0;
	if(n<m) swap(n,m);
	init();
	for(i=1;i<=m;i++) (ans+=C(i,2*i)*C(n-i,n+m-2*i)%MOD)%=MOD;
	ans=ans*qpow(2*C(n,n+m)%MOD,MOD-2)%MOD;
//	cout<<ans<<'\n';
	ans=(ans+n+MOD)%MOD;
	cout<<ans;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = (int)1e6 + 77;
ll f[N], rf[N];

ll getC(int n, int k) {
	if (k < 0 || k > n) return 0;
	return mult(f[n], mult(rf[k], rf[n - k]));
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);

	int n, m;
	scanf("%d%d", &n, &m);
	ll ans = 0;
	for (int k = 1; k <= min(n, m); k++)
		ans = add(ans, mult(getC(2 * k, k), getC(n + m - 2 * k, n - k)));
	ans = mult(ans, rev(mult(2, getC(n + m, m))));
	ans = add(ans, max(n, m));
	printf("%lld\n", ans);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
  int n;
  cin >> n;

  int p[n];
  rep(i,n) cin >> p[i];

  int min = 1e9;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(p[i] <= min){
      min = p[i];
      ans++;
    }
  }

  cout << ans << endl;

}

#include<iostream>
#include<vector>
using namespace std;

int main() {
  int N,i,j,k,ans=0;
  cin>>N;
  vector<int> L(N);
  for (i=0;i<N;i++) cin>>L[i];
  for (i=0;i<N-2;i++) {
    for (j=i+1;j<N-1;j++) {
      if (L[i]==L[j]) continue;
      for (k=j+1;k<N;k++) {
        if (L[i]==L[k] || L[j]==L[k]) continue;
        if (L[i] < L[j]+L[k] && L[j] < L[i]+L[k] && L[k] < L[j]+L[i]) ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n;
    vector<ll>v;
    cin>>n;
     ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];

    }
    sort(a,a+n);
    for(int i=0;i<n-1;i++)
    {
        if(a[i]==a[i+1])
        {
            i++;
            v.push_back(a[i]);
        }
    }
    if(v.size()<2)
        cout<<0<<endl;
    else
    {
        ll x=v.size();
        cout<<(v[x-1]*v[x-2])<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,m,x,y; cin>>n>>m>>x>>y;
    vector<ll> a(n),b(m);
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>b[i];
    sort(all(a));
    sort(all(b));
    bool can=false;
    for(int i=x+1;i<=y;i++){
        if(a[n-1]<i && i<=b[0]) can=true;
        else continue;
    }

    cout<<(can?"No War":"War")<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <iterator>
#include <math.h>
#include <list>
using namespace std;

int main(void){
  long x;
  cin >> x;
  long neko = x / 11;
  long amari = x % 11;
  cout << neko*2 + ((amari == 0) ? 0 :((amari > 6)? 2 : 1 ))<< endl;
  return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);

int main()
{
  string S; cin>>S;
  vector<int> word(S.size());
  set<int> ch;
  rep(i,S.size())
  {
    word.at(i)=S.at(i)-'a';
    ch.insert(S.at(i)-'a');
  }
  if(S.size()<26)
  {
    rep(i,26)
    {
      if(!(ch.count(i)))
      {
        cout<<S<<(char)(i+'a')<<endl;
        return 0;
      }
    }
  }
  if(S=="zyxwvutsrqponmlkjihgfedcba") {cout<<-1<<endl; return 0;}

  set<int> list;
  int last;
  char p=S.at(25);
  for(int i=25;i>=0;i--)
  {
    if(S.at(i-1)-'a'>S.at(i)-'a')
    {
      list.insert(S.at(i)-'a');
      S.pop_back();
      continue;
    }
    list.insert(S.at(i)-'a');
    S.pop_back();
    last=S.at(i-1)-'a';
    list.insert(S.at(i-1)-'a');
    S.pop_back();
    break;
  }
  for(int i=last+1;i<26;i++)
  {
    if(list.count(i))
    {
      cout<<S<<(char)(i+'a')<<endl;
      return 0;
    }
  }

  /*
  rep(i,26)
  {
    if(i==0) {continue;}
    if(S.at(i)>S.at(i-1)) {}
  */
  /*
  next_permutation(word.begin(),word.end());
  string ans="";
  bool judge=false;
  for(int i=25;i>=0;i--)
  {
  	if(word.at(i)!=i) {judge=true;}
    if(judge) {ans+=(char)(word.at(i)+'a');}
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  */
  return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
long long n,d,a[200005],r[200005],l[200005];
int main()
{
	cin>>n>>d;
	long long ret=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		ret+=a[i];
	}
	ret+=(n-1)*d;
	//cout<<ret<<endl;
	r[0]=a[0];
	for(int i=1;i<n;i++)
	    r[i]=min(a[i],r[i-1]+d);
	l[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--)
	    l[i]=min(a[i],l[i+1]+d);
	for(int i=1;i<n-1;i++)
	    ret+=min(l[i],r[i]);
	cout<<ret;
	return 0;
}

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int s, n, i, j, k, ans, ct;
	cin >> s >> n;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	sort(a.rbegin(), a.rend());

	vector<bool> v(s);
	ans = 0;
	ct = a[0];
	for (i = 0; i < s; i += 2) {
		if (ct > 0) {
			v[i] = true;
			ct--;
		}
	}

	for (i = s - 1; i >= 0; i--) {
		if (!v[i] && (ct > 0)) {
			v[i] = true;
			ct--;
		}
	}

	ans = 0;
	for (i = 1; i < s; i++) {
		if (v[i] && (v[i - 1])) ans++;
	}

	cout << ans << "\n";

	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

const ll mod = 998244353;

int cnt[100005], t[100005];

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

	int n; read(n);
	int mx = 0;

	rep(i, 0, n) {
		read(t[i]);
		chmax(mx, t[i]);
		cnt[t[i]]++;
	}

	if (t[0] != 0 || cnt[0] != 1)
		die(0);

	ll ans = 1;

	rep(i, 1, mx + 1) {
		rep(j, 0, cnt[i])
			ans = ans * cnt[i - 1] % mod;
	}

	die(ans);
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=998244353;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
ll mod_pow(ll x,ll n,ll mod){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N; cin>>N;
    ll ans=1;
    ll tmp_max=0;
    vector<ll> num(N,0);
    rep(i,N){
        ll tmp; cin>>tmp;
        chmax(tmp_max,tmp);
        if(i==0){
            if(tmp!=0){
                cout<<0<<endl;
                return 0;
            }
            else num[tmp]++;
        }
        else{
            if(tmp==0){
                cout<<0<<endl;
                return 0;
            }
            else{
                num[tmp]++;
            }
        }
    }
    rep1(i,tmp_max){
        if(num[i]==0){
            cout<<0<<endl;
            return 0;
        }
        else{
            ans*=mod_pow(num[i-1],num[i],MOD);
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
}


#include<iostream>
using namespace std;

int main()
{	int n;
	cin >> n;
	int x[n];
	for(int i=0;i<n;i++){
		cin >> x[i];
		}
	for(int j=n-1;j>=0;j--){
		if(j!=n-1) cout << " " ;
		cout << x[j];
		}
		cout<<endl;

}

/*
 * @Author: hesorchen
 * @Date: 2020-07-03 17:05:01
 * @LastEditTime: 2020-09-04 19:45:56
 * @Description: https://hesorchen.github.io/
 */
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define PI acos(-1)
#define PB push_back
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pll pair<ll, ll>
#define lowbit(abcd) (abcd & (-abcd))
#define max(a, b) ((a > b) ? (a) : (b))
#define min(a, b) ((a < b) ? (a) : (b))

#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define FRE                              \
    {                                    \
        freopen("in.txt", "r", stdin);   \
        freopen("out.txt", "w", stdout); \
    }

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}
//head==============================================================================

long long a[100010];
int main()
{
    long long n;
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    int s = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] < 0)
            s++;
        if (a[i] == 0)
        {
            s = 0;
            break;
        }
    }
    long long ans = 0;
    if (s % 2 == 0)
    {
        for (int i = 1; i <= n; i++)
            ans += abs(a[i]);
    }
    else
    {
        // int minn = INF;
        // for (int i = 1; i <= n; i++)
        // {
        //     if (a[i] < 0 && abs(a[i]) < minn)
        //         minn = abs(a[i]);
        // }
        // for (int i = 1; i <= n; i++)
        // {
        //     ans += abs(a[i]);
        // }
        // ans -= 2 * minn;
        for (int i = 1; i <= n; i++)
            a[i] = abs(a[i]);
        sort(a + 1, a + 1 + n);
        for (int i = 2; i <= n; i++)
            ans += a[i];
        ans -= a[1];
    }
    printf("%lld\n", ans);

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string N;
	cin >> N;
	int ja = 0;
	for (int i = 0; i < N.size(); i++) {
		if (N[i] == '7') {
			cout << "Yes" << endl;
			ja += 7;
			break;
		}
	}
	if (ja < 7) {
		cout << "No" << endl;
	}

}

#include <stdio.h>
int main (){
	int numberS, a, b, c;
	scanf("%d", &numberS);
  a = numberS%10;
  b = numberS/100;
  c = numberS%100/10;
	if(a==7 || b==7 || c==7){
		printf("Yes");
	}
	else{
		printf("No");
	}

}


#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 1e4+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

vector<int> digits;
int d,n;
int dp[MAX][110][2];

ll digitdp(int pos,int sum,int flag)
{
    if(pos==n)
    {
        if(sum==0)
            return 1;
        return 0;
    }
    if(dp[pos][sum][flag]!=-1)
        return dp[pos][sum][flag];
    int limit = (flag==1)?digits[pos]:9;
    ll tot = 0;
    for(int i=0;i<=limit;i++)
    {
        if(digits[pos]==i)
            tot=(tot+digitdp(pos+1,(sum+i)%d,flag))%MOD;
        else
            tot=(tot+digitdp(pos+1,(sum+i)%d,0))%MOD;
    }
        return dp[pos][sum][flag] = tot;
}

int main()
{
    memset(dp,-1,sizeof(dp));
    int i,j,l;
    string k;
    cin >> k >> d;
    l = k.length();
    for(i=0;i<l;i++)
        digits.pb(k[i]-'0');
    n = digits.size();
    ll ans = (digitdp(0,0,1)-1+MOD)%MOD;
    cout << ans;
}

#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=2000000;
ll n,a[M],b[M];

int main(){
	cin>>n;
	ll g=0,cnt=0,res=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		g^=x;
		if(g==0){
			cnt++;
			if(i==n-1){
				for(auto j:a) (res+=j)%=mod;
				(res+=1)%=mod;
			}
			ll t=a[g]+1;
			(a[g]+=t)%=mod;
		}
		else{
			ll t=(a[g]*cnt-b[g]+1+mod)%mod;
			(a[g]+=t)%=mod;
			(b[g]+=t*cnt)%=mod;
			if(i==n-1) res=t;
		}
	}
	cout<<res<<endl;
}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int friends[500];
	int n,m;
	pair<int, int> student[10000];
	int result[100];
	int I = 0;
	for (int i = 0;; i++)
	{
		cin >> n;
		cin >> m;
		if (m == 0 && n == 0)
		{
			break;
		}

		for (int a = 0; a < 500; a++)
		{
			friends[a] = 0;
			student[a].first = 0;
			student[a].second = 0;
		}

		for (int a = 0; a < m; a++)
		{
			cin >> student[a].first >> student[a].second;
			student[a].first--;
			student[a].second--;
		}

		sort(student, student + m);

		friends[0] = 1;

		for (int a = 0; a < m; a++)
		{
			if (student[a].first == 0)
			{
				for (int b = 0; b < m; b++)
				{
					if (student[b].first == student[a].second)
					{
						friends[student[b].second] = 1;
					}
					if (student[b].second == student[a].second)
					{
						friends[student[b].first] = 1;
					}
				}
				friends[student[a].second] = 1;
			}
		}

		result[i] = -1;
		for (int a = 0; a < n; a++)
		{
			if (friends[a] == 1)
			{
				result[i]++;
			}
		}
		I++;
	}

	for (int a = 0; a < I;a++)
	{
		cout << result[a] << endl;
	}

	return 0;
}

// https://atcoder.jp/contests/abc134/tasks/abc134_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    bitset<200001> bs;
    FOR(i, 1, N + 1) {
        int t;
        cin >> t;
        if (t) {
            bs.set(i);
        }
    }
    bitset<200001> ans;
    int cnt = 0;
    for (int i = N; i >= 1; i--) {
        int sum = 0;
        for (int j = i * 2; j <= N; j += i) {
            sum += ans[j];
        }
        if (sum % 2 != bs[i]) {
            ans.set(i);
            cnt++;
        }
    }
    cout << cnt << "\n";
    for (int i = 1; i <= N; i++) {
        if (ans[i]) {
            cout << i << (--cnt ? " " : "\n");
        }
    }

    return 0;
}


#include <stdio.h>
#define MAX 10000

int main(void){
    int list[MAX]={0}, q;

    // determine primes
    for (int i=2; i<MAX; i++){
        if (list[i]==-1) continue;
        list[i]=1;
        for (int j=2*i; j<MAX; j+=i){
            list[j] = -1;
        }
    }

    while (scanf("%d",&q),q){
        for (int i=q; i>=5; i--){
            if (list[i]==1 && list[i-2]==1){
                printf("%d %d\n",i-2, i);
                break;
            }
        }
    }

    return 0;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <vector>

constexpr bool divisible(const std::size_t n, const std::size_t m)
{
    return (0 == n % m);
}

std::vector<std::size_t> prime_table = {2};

bool prime(const std::size_t n)
{
    const std::size_t found_last_prime = prime_table.back();
    if(found_last_prime < n)
    {
        std::list<std::size_t> undefined_table;

        for(std::size_t i = found_last_prime + 1; i <= n; ++i)
        {
            undefined_table.push_back(i);
        }

        const std::size_t sn = std::sqrt(n);
        for(std::size_t p = 0; !undefined_table.empty() && p < prime_table.size(); ++p)
        {
            for(auto u = undefined_table.begin(); u != undefined_table.end();)
            {
                if(divisible(*u, prime_table.at(p)))
                {
                    u = undefined_table.erase(u);
                }
                else
                {
                    ++u;
                }
            }
            if(!undefined_table.empty() && found_last_prime <= prime_table.at(p))
            {
                prime_table.push_back(undefined_table.front());
                undefined_table.pop_front();
                if(sn < prime_table.back())
                {
                    break;
                }
            }
        }
        prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
    }
    return std::binary_search(prime_table.begin(), prime_table.end(), n);
}

std::pair<std::size_t, std::size_t> find_twin_prime(const std::size_t limit, const bool next_skip = false)
{
    return prime(limit) ?
        prime(limit - 2) ?
        std::make_pair(limit - 2, limit) :
        find_twin_prime(limit - (next_skip ? 3 : 1), true) :
        find_twin_prime(limit - (next_skip ? 2 : 1), false);
}

int main()
{
    std::size_t n;

    while(std::cin >> n, n != 0)
    {
        const auto&& t = find_twin_prime(n);
        std::cout << t.first << " " << t.second << std::endl;
    }
}


#include <stdio.h>

int main(){

    char s[10];

    scanf("%s",&s);
    getchar();
    s[3]='8';

    printf("%s",&s);

    return 0;
}

#include<iostream>
#include<string>

using namespace std;

int main() {
    string date;
    cin >> date;

    date.replace(0, 4, "2018");
    cout << date;
}


#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF LLONG_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}

int n,x,y;

int main()
{
  while(1)
  {
    scanf("%d",&n);
    if(n==0) return 0;
    int A = 0;
    int B = 0;
    REP(i,n)
    {
      scanf("%d %d",&x,&y);
      if(x>y) A+=(x+y);
      else if(x<y) B+=(x+y);
      else
      {
        A+=x;
        B+=y;
      }
    }
    printf("%d %d\n",A,B);
  }
}

#include <iostream>
using namespace std;

int main()
{
	int n, a, b, count = 0, pointX = 0, pointY = 0;
	cin >> n;
	do {
		cin >> a >> b;
		if (a > b) {
			pointX += (a + b);
		}
		else if (a < b) {
			pointY += (a + b);
		}
		else {
			pointX += a;
			pointY += b;
		}
		count++;
		if (count == n) {
			cout << pointX << " " << pointY << endl;
			pointX = pointY = count = 0;
			cin >> n;
		}
	} while (n != 0);
	return 0;
}