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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

namespace ecnerwala {
namespace fft {

using std::swap;
using std::vector;
using std::min;
using std::max;

template<class T> int sz(T&& arg) { using std::size; return int(size(std::forward<T>(arg))); }
inline int nextPow2(int s) { return 1 << (s > 1 ? 32 - __builtin_clz(s-1) : 0); }

// Complex
template <typename dbl> struct cplx { /// start-hash
	dbl x, y;
	cplx(dbl x_ = 0, dbl y_ = 0) : x(x_), y(y_) { }
	friend cplx operator+(cplx a, cplx b) { return cplx(a.x + b.x, a.y + b.y); }
	friend cplx operator-(cplx a, cplx b) { return cplx(a.x - b.x, a.y - b.y); }
	friend cplx operator*(cplx a, cplx b) { return cplx(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }
	friend cplx conj(cplx a) { return cplx(a.x, -a.y); }
	friend cplx inv(cplx a) { dbl n = (a.x*a.x+a.y*a.y); return cplx(a.x/n,-a.y/n); }
};

// getRoot implementations
template <typename num> struct getRoot {
	static num f(int k) = delete;
};
template <typename dbl> struct getRoot<cplx<dbl>> {
	static cplx<dbl> f(int k) {
		dbl a=2*M_PI/k;
		return cplx<dbl>(cos(a),sin(a));
	}
};
template <int MOD> struct primitive_root {
	static const int value;
};
template <> struct primitive_root<998244353> {
	static const int value = 3;
};
template <int MOD> struct getRoot<modnum<MOD>> {
	static modnum<MOD> f(int k) {
		assert((MOD-1)%k == 0);
		return pow(modnum<MOD>(primitive_root<MOD>::value), (MOD-1)/k);
	}
};

template <typename num> class fft {
	static vector<int> rev;
	static vector<num> rt;

public:
	static void init(int n);
	template <typename Iterator> static void go(Iterator begin, int n);

	static vector<num> scratch_a;
	static vector<num> scratch_b;
};

template <typename num> vector<int> fft<num>::rev({0,1});
template <typename num> vector<num> fft<num>::rt(2, num(1));
template <typename num> vector<num> fft<num>::scratch_a;
template <typename num> vector<num> fft<num>::scratch_b;

template <typename num> void fft<num>::init(int n) {
	if (n <= sz(rt)) return;
	rev.resize(n);
	for (int i = 0; i < n; i++) {
		rev[i] = (rev[i>>1] | ((i&1)*n)) >> 1;
	}
	rt.reserve(n);
	for (int k = sz(rt); k < n; k *= 2) {
		rt.resize(2*k);
		num z = getRoot<num>::f(2*k);
		for (int i = k/2; i < k; i++) {
			rt[2*i] = rt[i], rt[2*i+1] = rt[i]*z;
		}
	}
}

template <typename num> template <typename Iterator> void fft<num>::go(Iterator begin, int n) {
	init(n);
	int s = __builtin_ctz(sz(rev)/n);
	for (int i = 0; i < n; i++) {
		if (i < (rev[i]>>s)) {
			swap(*(begin+i), *(begin+(rev[i]>>s)));
		}
	}
	for (int k = 1; k < n; k *= 2) {
		for (int i = 0; i < n; i += 2 * k) {
			Iterator it1 = begin + i, it2 = it1 + k;
			for (int j = 0; j < k; j++, ++it1, ++it2) {
				num t = rt[j+k] * *it2;
				*it2 = *it1 - t;
				*it1 = *it1 + t;
			}
		}
	}
}

template <typename num> struct fft_multiplier {
	template <typename IterA, typename IterB, typename IterOut>
	static void multiply(IterA ia, int sza, IterB ib, int szb, IterOut io) {
		vector<num>& fa = fft<num>::scratch_a;
		vector<num>& fb = fft<num>::scratch_b;

		if (sza == 0 || szb == 0) return;
		int s = sza + szb - 1;
		int n = nextPow2(s);
		fft<num>::init(n);
		if (sz(fa) < n) fa.resize(n);
		if (sz(fb) < n) fb.resize(n);
		copy(ia, ia+sza, fa.begin());
		fill(fa.begin()+sza, fa.begin()+n, num(0));
		copy(ib, ib+szb, fb.begin());
		fill(fb.begin()+szb, fb.begin()+n, num(0));
		fft<num>::go(fa.begin(), n);
		fft<num>::go(fb.begin(), n);
		num d = inv(num(n));
		for (int i = 0; i < n; i++) fa[i] = fa[i] * fb[i] * d;
		reverse(fa.begin()+1, fa.begin()+n);
		fft<num>::go(fa.begin(), n);
		copy(fa.begin(), fa.begin()+s, io);
	}
};

template <typename num>
struct fft_inverser {
	template <typename IterA, typename IterOut>
	static void inverse(IterA ia, int sza, IterOut io) {
		vector<num>& fa = fft<num>::scratch_a;
		vector<num>& fb = fft<num>::scratch_b;

		if (sza == 0) return;
		int s = nextPow2(sza) * 2;
		fft<num>::init(s);
		if (sz(fa) < s) fa.resize(s);
		if (sz(fb) < s) fb.resize(s);
		fb[0] = inv(*ia);
		for (int n = 1; n < sza; ) {
			fill(fb.begin() + n, fb.begin() + 4 * n, num(0));
			n *= 2;
			copy(ia, ia+min(n,sza), fa.begin());
			fill(fa.begin()+min(n,sza), fa.begin()+2*n, 0);
			fft<num>::go(fb.begin(), 2*n);
			fft<num>::go(fa.begin(), 2*n);
			num d = inv(num(2*n));
			for (int i = 0; i < 2*n; i++) fb[i] = fb[i] * (2 - fa[i] * fb[i]) * d;
			reverse(fb.begin()+1, fb.begin()+2*n);
			fft<num>::go(fb.begin(), 2*n);
		}
		copy(fb.begin(), fb.begin()+sza, io);
	}
};

template <typename dbl>
struct fft_double_multiplier {
	template <typename IterA, typename IterB, typename IterOut>
	static void multiply(IterA ia, int sza, IterB ib, int szb, IterOut io) {
		vector<cplx<dbl>>& fa = fft<cplx<dbl>>::scratch_a;
		vector<cplx<dbl>>& fb = fft<cplx<dbl>>::scratch_b;

		if (sza == 0 || szb == 0) return;
		int s = sza + szb - 1;
		int n = nextPow2(s);
		fft<cplx<dbl>>::init(n);
		if (sz(fa) < n) fa.resize(n);
		if (sz(fb) < n) fb.resize(n);

		fill(fa.begin(), fa.begin() + n, 0);
		{ auto it = ia; for (int i = 0; i < sza; ++i, ++it) fa[i].x = *it; }
		{ auto it = ib; for (int i = 0; i < szb; ++i, ++it) fa[i].y = *it; }
		fft<cplx<dbl>>::go(fa.begin(), n);
		for (auto& x : fa) x = x * x;
		for (int i = 0; i < n; ++i) fb[i] = fa[(n-i)&(n-1)] - conj(fa[i]);
		fft<cplx<dbl>>::go(fb.begin(), n);
		{ auto it = io; for (int i = 0; i < s; ++i, ++it) *it = fb[i].y / (4*n); }
	}
};

template <typename mnum>
struct fft_mod_multiplier {
	template <typename IterA, typename IterB, typename IterOut>
	static void multiply(IterA ia, int sza, IterB ib, int szb, IterOut io) {
		using cnum = cplx<double>;
		vector<cnum>& fa = fft<cnum>::scratch_a;
		vector<cnum>& fb = fft<cnum>::scratch_b;

		if (sza == 0 || szb == 0) return;
		int s = sza + szb - 1;
		int n = nextPow2(s);
		fft<cnum>::init(n);
		if (sz(fa) < n) fa.resize(n);
		if (sz(fb) < n) fb.resize(n);

		{ auto it = ia; for (int i = 0; i < sza; ++i, ++it) fa[i] = cnum(int(*it) & ((1<<15)-1), int(*it) >> 15); }
		fill(fa.begin()+sza, fa.begin() + n, 0);
		{ auto it = ib; for (int i = 0; i < szb; ++i, ++it) fb[i] = cnum(int(*it) & ((1<<15)-1), int(*it) >> 15); }
		fill(fb.begin()+szb, fb.begin() + n, 0);

		fft<cnum>::go(fa.begin(), n);
		fft<cnum>::go(fb.begin(), n);
		double r0 = 0.5 / n; // 1/2n
		for (int i = 0; i <= n/2; i++) {
			int j = (n-i)&(n-1);
			cnum g0 = (fb[i] + conj(fb[j])) * r0;
			cnum g1 = (fb[i] - conj(fb[j])) * r0;
			swap(g1.x, g1.y); g1.y *= -1;
			if (j != i) {
				swap(fa[j], fa[i]);
				fb[j] = fa[j] * g1;
				fa[j] = fa[j] * g0;
			}
			fb[i] = fa[i] * conj(g1);
			fa[i] = fa[i] * conj(g0);
		}
		fft<cnum>::go(fa.begin(), n);
		fft<cnum>::go(fb.begin(), n);
		using ll = long long;
		const ll m = mnum::MOD;
		auto it = io;
		for (int i = 0; i < s; ++i, ++it) {
			*it = mnum((ll(fa[i].x+0.5)
						+ (ll(fa[i].y+0.5) % m << 15)
						+ (ll(fb[i].x+0.5) % m << 15)
						+ (ll(fb[i].y+0.5) % m << 30)) % m);
		}
	}
};

template <class multiplier, typename num>
struct multiply_inverser {
	template <typename IterA, typename IterOut>
	static void inverse(IterA ia, int sza, IterOut io) {
		if (sza == 0) return;
		int s = nextPow2(sza);
		vector<num> b(s,num(0));
		vector<num> tmp(2*s);
		b[0] = inv(*ia);
		for (int n = 1; n < sza; ) {
			// TODO: could be square instead of multiply
			multiplier::multiply(b.begin(),n,b.begin(),n,tmp.begin());
			int nn = min(sza,2*n);
			multiplier::multiply(tmp.begin(),nn,ia,nn,tmp.begin());
			for (int i = n; i < nn; i++) b[i] = -tmp[i];
			n = nn;
		}
		copy(b.begin(), b.begin()+sza, io);
	}
};

template <class multiplier, typename T> vector<T> multiply(const vector<T>& a, const vector<T>& b) {
	if (sz(a) == 0 || sz(b) == 0) return {};
	vector<T> r(max(0, sz(a) + sz(b) - 1));
	multiplier::multiply(begin(a), sz(a), begin(b), sz(b), begin(r));
	return r;
}

template <typename T> vector<T> fft_multiply(const vector<T>& a, const vector<T>& b) {
	return multiply<fft_multiplier<T>, T>(a, b);
}
template <typename T> vector<T> fft_double_multiply(const vector<T>& a, const vector<T>& b) {
	return multiply<fft_double_multiplier<T>, T>(a, b);
}
template <typename T> vector<T> fft_mod_multiply(const vector<T>& a, const vector<T>& b) {
	return multiply<fft_mod_multiplier<T>, T>(a, b);
}

template <class inverser, typename T> vector<T> inverse(const vector<T>& a) {
	vector<T> r(sz(a));
	inverser::inverse(begin(a), sz(a), begin(r));
	return r;
}
template <typename T> vector<T> fft_inverse(const vector<T>& a) {
	return inverse<fft_inverser<T>, T>(a);
}
template <typename T> vector<T> fft_double_inverse(const vector<T>& a) {
	return inverse<multiply_inverser<fft_double_multiplier<T>, T>, T>(a);
}
template <typename T> vector<T> fft_mod_inverse(const vector<T>& a) {
	return inverse<multiply_inverser<fft_mod_multiplier<T>, T>, T>(a);
}

}} // namespace ecnerwala::fft

using num = modnum<998244353>;

vector<num> fact, ifact;

void init(){
	int N = 1100000;
	fact = {1};
	for(int i = 1; i < N; i++) fact.push_back(i * fact[i-1]);
	ifact.resize(N);
	ifact.back() = 1 / fact.back();
	for(int i = N - 1; i > 0; i--) ifact[i-1] = i * ifact[i];
}

num ncr(int n, int k){
	if(k < 0 || k > n) return 0;
	return fact[n] * ifact[k] * ifact[n-k];
}

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	init();
	int n, k;
	cin >> n >> k;
	num ans = 0;

	int f = min(n, k);
	vector<num> s1(f+1, 0);
	vector<num> sa(f+1, 0);
	for(int a = 1; a <= f; a++){
		sa[a] = pow(num(a), k) * ifact[a];
	}
	for(int i = 0; i <= f; i++){
		s1[i] = ifact[i] * pow(num(-1), i);
	}
	vector<num> res = ecnerwala::fft::multiply<ecnerwala::fft::fft_multiplier<num>>(s1, sa);
	num ncb = 1;
	for(int b = 1; b <= f; b++){
		ncb *= (n+1 - b);
		ncb /= b;
		ans += res[b] * ncb * fact[b] * pow(num(n+1), n-b);
	}
	cout << ans << '\n';
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="codeforces(year of unversity entrance)" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/codeforces(year of unversity entrance)" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/codeforces(year of unversity entrance)" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,a1,a2,a3,a4,a5;
    cin>>n;
    if(n==1)
    {
        cin>>a;
        cout<<a;
        return 0;
    }

        cout<<"TAK";
    else cout<<"NIE";
}


#include <bits/stdc++.h>

using namespace std;

#define llong long long
#define endl "\n"
#define fi first
#define se second
#define left LEVO
#define right PRAVO
#define time CHAS
#define prev PAPEREDNIKXD
#define next NASTUPNIKXD
#define pb push_back
#define deb cout<<"CHECK\n";

#define elif else if
#define cclear cout<<flush;
#define fclear fflush(stdout);
#define files freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const llong over999 = 12345678;
const double eps = 1e-16;
const double Pi = acos(-1);
const llong md = 1e9+7;

/***()()()*************************************************************/

int n, a[200];
bool used[200];
vector<pair<int, int>> ans;
int z;
int main()
{
    kchay;
    //files;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    used[1]=true;
    for(int i=1;i<=n;i++)
    {
        if(!used[i])continue;
        for(int j=1;j<=n && a[i]>0;j++)
        {
            if(i==j)continue;
            if(a[j]>0 && !used[j])used[j]=true, a[i]--, z++, ans.pb({i, j});
        }
        if(!a[i])continue;
        for(int j=1;j<=n && a[i]>0;j++)
        {
            if(i==j)continue;
            if(a[j]==0 && !used[j])used[j]=true, a[i]--, z++, ans.pb({i, j});
        }
    }#include <bits/stdc++.h>

using namespace std;

#define llong long long
#define endl "\n"
#define fi first
#define se second
#define left LEVO
#define right PRAVO
#define time CHAS
#define prev PAPEREDNIKXD
#define next NASTUPNIKXD
#define pb push_back
#define deb cout<<"CHECK\n";

#define elif else if
#define cclear cout<<flush;
#define fclear fflush(stdout);
#define files freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const llong over999 = 12345678;
const double eps = 1e-16;
const double Pi = acos(-1);
const llong md = 1e9+7;

/***()()()*************************************************************/

int n, a[10];

int main()
{
    kchay;
    //files;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }

    sort(a, a+n);
    cout << a[n/2];

    return 0;
}

    if(z!=n-1)return cout << -1, 0;

    cout << ans.size() << endl;
    for(auto i:ans)
    {
        cout << i.fi << " " << i.se << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[5];//数组开5就行了
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];//循环输入
    sort(1,n);//排序
    if(n==1||n==2) cout<<a[0];//如果只有1或者2个元素，向下取整输出a[1]
    if(n==3||n==4) cout<<a[1];//如果只有3或者4个元素，向下取整输出a[2]
    if(n==5) cout<<a[2];//如果只有3或者4个元素，向下取整输出a[3]
    return 0;
}


#include <bits/stdc++.h>/*{{{*/
typedef long long ll; typedef long double ld; using namespace std;void run();int main(){ios::sync_with_stdio(false);run();}/*}}}*/

ll const lots=1000000007ll;
ll memo[55][55][2];
ll choose[55][55];

ll half(ll n){
    ll res=n;
    ll s=2;
    for (ll i=lots-2; i; i>>=1, (s*=s)%=lots)
        if (i&1)
            (res*=s)%=lots;
    return res;
}

ll solve(int n,int k,bool matched){
    if (n<=0 or k<0 or k*2>n) return 0ll;
    if (n==1) return k==0 and not matched;
    ll &res=memo[n][k][matched];
    if (ares) return ares;

    // single child
    if (matched){
        res+=solve(n-1,k-1,false)
            *choose[n-1][1];
        res%=lots;
    }else{
        res+=solve(n-1,k,true)
            *choose[n-1][1];
        res%=lots;
    }

    // two children
    if (not matched){
        for (int a=1,b=n-2; a<=b; a++,b--){
            for (int i=0,j=k; i<=k; i++,j--){
                res+=(((
                     solve(a,i,true)
                    *solve(b,j,true) % lots)
                    *(a==b? half(choose[n-1][a]): choose[n-1][a]) % lots)
                    *choose[a][1] % lots)
                    *choose[b][1];
                res%=lots;
            }
        }
    }else{
        for (int a=1,b=n-2; a<=n-2; a++,b--){
            for (int i=0,j=k-1; i<=k-1; i++,j--){
                if (a<b or a==b and i<=j){
                    res+=(((
                         solve(a,i,false)
                        *solve(b,j,false) % lots)
                        *(a==b? half(choose[n-1][a]): choose[n-1][a]) % lots)
                        *choose[a][1] % lots)
                        *choose[b][1];
                    res%=lots;
                }

                res+=(((
                     solve(a,i,false)
                    *solve(b,j,true) % lots)
                    *choose[n-1][a] % lots)
                    *choose[a][1] % lots)
                    *choose[b][1];
                res%=lots;
            }
        }
    }

//    if (n<=3 and k<=3) cerr<<" "<<n<<" "<<k<<" "<<matched<<" => "<<res<<endl;
    return res%=lots;
}

void run(){
  memset(memo,-1,sizeof memo);
  for (int i=0; i<=50; i++)
    for (int j=0; j<=50; j++)
      choose[i][j]=(i==j or j==0? 1: i<j? 0: choose[i-1][j-1]+choose[i-1][j])%lots;

  int n,k; cin>>n>>k;
  cout<<(solve(n,k,false)+solve(n,k,true))%lots<<endl;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#define CLR(x,y) memset(x,y,sizeof(x))
#define eps 1e-9
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

template<class T>
inline bool read(T &n)
{
    T x = 0, tmp = 1;
    char c = getchar();
    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
    if(c == EOF) return false;
    if(c == '-') c = getchar(), tmp = -1;
    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();
    n = x*tmp;
    return true;
}
template <class T>
inline void write(T n)
{
    if(n < 0)
    {
        putchar('-');
        n = -n;
    }
    int len = 0,data[20];
    while(n)
    {
        data[len++] = n%10;
        n /= 10;
    }
    if(!len) data[len++] = 0;
    while(len--) putchar(data[len]+48);
}
//-----------------------------------

const int MOD=1000000007;
const int MAXN=60;

ll dp[MAXN][MAXN][2],C[105][105];;
int n,k;

int main()
{
    while(read(n)&&read(k))
    {
        CLR(dp,0);
        dp[1][0][0]=1;
        dp[1][0][1]=0;
        dp[0][0][0]=0;
        dp[0][0][1]=1;
        C[0][0]=1;
        for(int i=1; i<=n; i++)
        {
            for(int j=0; j<=i; j++)
            {
                if(!j || j==i) C[i][j]=1LL;
                else C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
            }
        }
        for(int i=2; i<=n; i++)
        {
            for(int j=0; j<=k; j++)
            {
                dp[i][j][0]=(dp[i][j][0]+((i-1)*dp[i-1][j][1])%MOD)%MOD;
                if(j)
                    dp[i][j][1]=(dp[i][j][1]+((i-1)*dp[i-1][j-1][0])%MOD)%MOD;
                for(int q=1; q<i-1; q++)
                {
                    ll rela=(C[i-1][2]*C[i-3][q-1])%MOD;
                    for(int k1=0; k1<=j; k1++)
                    {
                        int k2=j-k1;
                        dp[i][j][0]=(dp[i][j][0]+rela*((dp[q][k1][1]*dp[i-1-q][k2][1])%MOD)%MOD)%MOD;
                        if(--k2<0)  continue;
                        dp[i][j][1]=(dp[i][j][1]+(dp[q][k1][0]*dp[i-1-q][k2][1] %MOD
                                                + dp[q][k1][1]*dp[i-1-q][k2][0] %MOD
                                                + dp[q][k1][0]*dp[i-1-q][k2][0])%MOD*rela%MOD)%MOD;
                    }
                }

            }

        }

        ll ans=(dp[n][k][0]+dp[n][k][1])%MOD;
        printf("%lld\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

#define IOS  ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"
lldp[55][55][3];
ll c[55][55];
signed main() {

        IOS;
        dp[0][0][1] = 1;
        dp[1][0][1] = 0;
        dp[1][0][0] = 1;
        dp[0][0][0] = 1; int n , k; cin >>n >> k;
        c[0][0] = 1;
        for (int i = 1; i <= n; c[i][0] = 1, i++)
            for (int j = 1; j <= n; j++)
                c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;

        for(int i = 2; i <= n ; i++) {
         	for(int j = 0; j <= k; j++)  {
         		for(int Left = 1; Left <= i - 1; Left++)  {

    	     	    ll coef = c[i - 2][Left - 1] * Left * max(1 , (i - Left - 1) )  %  mod;

    	    	    for(int kLeft = 0 ; kLeft <= j - 1; kLeft++) {

    	    	    	ll addFi = dp[Left][kLeft][0] * ((i - Left - 1  ) > 0 ? dp[i - Left - 1][j - 1 - kLeft][1] + dp[i - Left -1][j - 1 - kLeft][0] : j - kLeft - 1 == 0 ? 1 : 0);
			     		ll addSe = ( (i - Left - 1 )> 0 ? dp[Left][kLeft][1] *  dp[i - Left -1][j - 1 - kLeft][0] : 0);
			    		dp[i][j][1] += coef * (addFi + addSe) % mod;
			    	}
				for(int kLeft = 0 ; kLeft <=j ; kLeft++) {

					dp[i][j][0] += coef * dp[Left][kLeft][1] * dp[i - Left -1][j - kLeft][1] % mod;

				}
			}
		}
	}
	cout << (dp[n][k][0] + dp[n][k][1]) % mod;
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
const int N = 7;
const int M = 50;
const int POW3 = 3 * 3 * 3 * 3 * 3 * 3 * 3;
int pow3[N + 1];
int dp[M][N][POW3];
int getBit(int mask, int pos){
    if (pos < 0)
        return 2;
    mask /= pow3[pos];
    return mask % 3;
}
void setMask(int & mask, int pos, int val){
    if (pos < 0)
        throw 42;
    mask += (val - getBit(mask, pos)) * pow3[pos];
}
void updateDP(int col, int row, int mask, int val){
    int & res = dp[col][row][mask];
    res = min(res, val);
}
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    if (n > m)
        swap(n, m);
    pow3[0] = 1;
    for (int i = 1; i < N; ++i)
        pow3[i] = pow3[i - 1] * 3;
    fill(dp, 0x7f);
    int startMask = 0;
    for (int i = 0; i < n; ++i)
        startMask = startMask * 3 + 2;
    dp[0][0][startMask] = 0;
    for (int col = 0; col < m; ++col)
        for (int row = 0; row <= n; ++row)
            for (int mask = 0; mask < pow3[n]; ++mask){
                if (dp[col][row][mask] > n * m)continue;
                if (row == n){
                    dp[col + 1][0][mask] = dp[col][n][mask];
                }
                else{
                    int upBit = getBit(mask, row - 1);
                    int leftBit = getBit(mask, row);
                    int newMask = mask;
                    if (leftBit != 1){
                        setMask(newMask, row, (leftBit == 0 || upBit == 0) ? 2 : 1);
                        updateDP(col, row + 1, newMask, dp[col][row][mask]);
                    }
                    newMask = mask;
                    setMask(newMask, row, 0);
                    if (upBit == 1)
                        setMask(newMask, row - 1, 2);
                    updateDP(col, row + 1, newMask, dp[col][row][mask] + 1);
                }
            }

    int res = n * m;
    for (int mask = 0; mask < pow3[n]; ++mask){
        bool good = true;
        for (int i = 0; i < n; ++i)
            good &= (getBit(mask, i) != 1);
        if (good)
            res = min(res, dp[m][0][mask]);
    }
    printf("%d\n", n * m - res);
    return 0;
}
//看到14页


#include <cstdio>
#include <memory>
#define O(x) ((x)&1)
using namespace std;

const int N=40+5;
const int S=(1<<12)+5;

int n,m,z,p,q,ans;
int f[N][S];
int c[S];

int check(int a,int b,int c)
{
  for (int i=0;i<m;++i)
    if (!(i&&O(b>>i-1)||i<m-1&&O(b>>i+1)||O(b>>i)||O(a>>i)||O(c>>i)))
      return 0;
  return 1;
}

int count(int a)
{
  int ret=0;
  for (int i=0;i<m;++i) ret+=!(a>>i&1);
  return ret;
}

int main()
{
//  freopen("e.in","r",stdin);
//  freopen("e.out","w",stdout);

  scanf("%d%d",&n,&m);
  if (n<m) z=n,n=m,m=z;
  p=1<<m;q=1<<(m<<1);
  for (int i=0;i<q;++i)
    if (check(0,i&p-1,i>>m)) f[1][i]=count(i&p-1);
    else f[1][i]=-n*m;
  for (int i=0;i<p;++i) c[i]=count(i);
  for (int i=2;i<=n;++i)
    for (int j=0;j<q;++j) if (f[i-1][j]>=0)
      for (int k=0;k<p;++k) if (check(j&p-1,j>>m,k))
        f[i][j>>m|k<<m]>?=f[i-1][j]+c[j>>m];
  for (int i=0;i<p;++i) ans>?=f[n][i];
  printf("%d",ans);

  return 0;
}


//题目名称:111c Petya and Spiders
//日期：2019.10.6
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	if(n>m)swap(n,m);
	if(n==1)printf("%d\n",m-(m+2)/3);
	else if(n==2)
		printf("%d\n",n*m-(n+m)/2);
	else if(n==3)printf("%d\n",2*m+(m-1)/4);
	else if(n==4)
	{
		if(m<5)printf("%d\n",3*m+(m-1)/4);
		else if(m<7)printf("%d\n",3*m-(m-1)/3));
		else if(m<9)printf("%d\n",3*m);
		else rintf("%d\n",3*m-1);
	}
	else if(n==5)
		printf("%d\n",4*m-4);
	else printf("%d\n",3*m+8);
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
long long x1,x2,y1,y2,k,a,b;
cin»x1»y1»x2»y2;
a=x2-x1;
b=y2-y1;
k=a*b/4+(a+2)*(b+2)/4;
cout«k;
return 0;
}


#include<string>
#include<iostream>
#include<iosfwd>
#include<cmath>
#include<cstring>
#include<stdlib.h>
#include<stdio.h>
#include<cstring>
#define MAX_L 55 //最大长度，可以修改
using namespace std;

class bign
{
public:
    int len, s[MAX_L];//数的长度，记录数组
//构造函数
    bign();
    bign(const char*);
    bign(int);
    bool sign;//符号 1正数 0负数
    string toStr() const;//转化为字符串，主要是便于输出
    friend istream& operator>>(istream &,bign &);//重载输入流
    friend ostream& operator<<(ostream &,bign &);//重载输出流
//重载复制
    bign operator=(const char*);
    bign operator=(int);
    bign operator=(const string);
//重载各种比较
    bool operator>(const bign &) const;
    bool operator>=(const bign &) const;
    bool operator<(const bign &) const;
    bool operator<=(const bign &) const;
    bool operator==(const bign &) const;
    bool operator!=(const bign &) const;
//重载四则运算
    bign operator+(const bign &) const;
    bign operator++();
    bign operator++(int);
    bign operator+=(const bign&);
    bign operator-(const bign &) const;
    bign operator--();
    bign operator--(int);
    bign operator-=(const bign&);
    bign operator*(const bign &)const;
    bign operator*(const int num)const;
    bign operator*=(const bign&);
    bign operator/(const bign&)const;
    bign operator/=(const bign&);
//四则运算的衍生运算
    bign operator%(const bign&)const;//取模（余数）
    bign factorial()const;//阶乘
    bign Sqrt()const;//整数开根（向下取整）
    bign pow(const bign&)const;//次方
//一些乱乱的函数
    void clean();
    ~bign();
};
#define max(a,b) a>b ? a : b
#define min(a,b) a<b ? a : b

bign::bign()
{
    memset(s, 0, sizeof(s));
    len = 1;
    sign = 1;
}

bign::bign(const char *num)
{
    *this = num;
}

bign::bign(int num)
{
    *this = num;
}

string bign::toStr() const
{
    string res;
    res = "";
    for (int i = 0; i < len; i++)
        res = (char)(s[i] + '0') + res;
    if (res == "")
        res = "0";
    if (!sign&&res != "0")
        res = "-" + res;
    return res;
}

istream &operator>>(istream &in, bign &num)
{
    string str;
    in>>str;
    num=str;
    return in;
}

ostream &operator<<(ostream &out, bign &num)
{
    out<<num.toStr();
    return out;
}

bign bign::operator=(const char *num)
{
    memset(s, 0, sizeof(s));
    char a[MAX_L] = "";
    if (num[0] != '-')
        strcpy(a, num);
    else
        for (int i = 1; i < strlen(num); i++)
            a[i - 1] = num[i];
    sign = !(num[0] == '-');
    len = strlen(a);
    for (int i = 0; i < strlen(a); i++)
        s[i] = a[len - i - 1] - 48;
    return *this;
}

bign bign::operator=(int num)
{
    char temp[MAX_L];
    sprintf(temp, "%d", num);
    *this = temp;
    return *this;
}

bign bign::operator=(const string num)
{
    const char *tmp;
    tmp = num.c_str();
    *this = tmp;
    return *this;
}

bool bign::operator<(const bign &num) const
{
    if (sign^num.sign)
        return num.sign;
    if (len != num.len)
        return len < num.len;
    for (int i = len - 1; i >= 0; i--)
        if (s[i] != num.s[i])
            return sign ? (s[i] < num.s[i]) : (!(s[i] < num.s[i]));
    return !sign;
}

bool bign::operator>(const bign&num)const
{
    return num < *this;
}

bool bign::operator<=(const bign&num)const
{
    return !(*this>num);
}

bool bign::operator>=(const bign&num)const
{
    return !(*this<num);
}

bool bign::operator!=(const bign&num)const
{
    return *this > num || *this < num;
}

bool bign::operator==(const bign&num)const
{
    return !(num != *this);
}

bign bign::operator+(const bign &num) const
{
    if (sign^num.sign)
    {
        bign tmp = sign ? num : *this;
        tmp.sign = 1;
        return sign ? *this - tmp : num - tmp;
    }
    bign result;
    result.len = 0;
    int temp = 0;
    for (int i = 0; temp || i < (max(len, num.len)); i++)
    {
        int t = s[i] + num.s[i] + temp;
        result.s[result.len++] = t % 10;
        temp = t / 10;
    }
    result.sign = sign;
    return result;
}

bign bign::operator++()
{
    *this = *this + 1;
    return *this;
}

bign bign::operator++(int)
{
    bign old = *this;
    ++(*this);
    return old;
}

bign bign::operator+=(const bign &num)
{
    *this = *this + num;
    return *this;
}

bign bign::operator-(const bign &num) const
{
    bign b=num,a=*this;
    if (!num.sign && !sign)
    {
        b.sign=1;
        a.sign=1;
        return b-a;
    }
    if (!b.sign)
    {
        b.sign=1;
        return a+b;
    }
    if (!a.sign)
    {
        a.sign=1;
        b=bign(0)-(a+b);
        return b;
    }
    if (a<b)
    {
        bign c=(b-a);
        c.sign=false;
        return c;
    }
    bign result;
    result.len = 0;
    for (int i = 0, g = 0; i < a.len; i++)
    {
        int x = a.s[i] - g;
        if (i < b.len) x -= b.s[i];
        if (x >= 0) g = 0;
        else
        {
            g = 1;
            x += 10;
        }
        result.s[result.len++] = x;
    }
    result.clean();
    return result;
}

bign bign::operator * (const bign &num)const
{
    bign result;
    result.len = len + num.len;

    for (int i = 0; i < len; i++)
        for (int j = 0; j < num.len; j++)
            result.s[i + j] += s[i] * num.s[j];

    for (int i = 0; i < result.len; i++)
    {
        result.s[i + 1] += result.s[i] / 10;
        result.s[i] %= 10;
    }
    result.clean();
    result.sign = !(sign^num.sign);
    return result;
}

bign bign::operator*(const int num)const
{
    bign x = num;
    bign z = *this;
    return x*z;
}
bign bign::operator*=(const bign&num)
{
    *this = *this * num;
    return *this;
}

bign bign::operator /(const bign&num)const
{
    bign ans;
    ans.len = len - num.len + 1;
    if (ans.len < 0)
    {
        ans.len = 1;
        return ans;
    }

    bign divisor = *this, divid = num;
    divisor.sign = divid.sign = 1;
    int k = ans.len - 1;
    int j = len - 1;
    while (k >= 0)
    {
        while (divisor.s[j] == 0) j--;
        if (k > j) k = j;
        char z[MAX_L];
        memset(z, 0, sizeof(z));
        for (int i = j; i >= k; i--)
            z[j - i] = divisor.s[i] + '0';
        bign dividend = z;
        if (dividend < divid) { k--; continue; }
        int key = 0;
        while (divid*key <= dividend) key++;
        key--;
        ans.s[k] = key;
        bign temp = divid*key;
        for (int i = 0; i < k; i++)
            temp = temp * 10;
        divisor = divisor - temp;
        k--;
    }
    ans.clean();
    ans.sign = !(sign^num.sign);
    return ans;
}

bign bign::operator/=(const bign&num)
{
    *this = *this / num;
    return *this;
}

bign bign::operator%(const bign& num)const
{
    bign a = *this, b = num;
    a.sign = b.sign = 1;
    bign result, temp = a / b*b;
    result = a - temp;
    result.sign = sign;
    return result;
}

bign bign::pow(const bign& num)const
{
    bign result = 1;
    for (bign i = 0; i < num; i++)
        result = result*(*this);
    return result;
}

bign bign::factorial()const
{
    bign result = 1;
    for (bign i = 1; i <= *this; i++)
        result *= i;
    return result;
}

void bign::clean()
{
    if (len == 0) len++;
    while (len > 1 && s[len - 1] == '\0')
        len--;
}

bign bign::Sqrt()const
{
    if(*this<0)return -1;
    if(*this<=1)return *this;
    bign l=0,r=*this,mid;
    while(r-l>1)
    {
        mid=(l+r)/2;
        if(mid*mid>*this)
            r=mid;
        else
            l=mid;
    }
    return l;
}

bign::~bign()
{
}
bign t,xa,ya,xb,yb;

int main(){
	t=bign(1000000002);
	cin>>xa>>ya>>xb>>yb;
	if((xa%2==0)^(ya%2==0))ya--,yb--;
	xa+=t,ya+=t,xb+=t,yb+=t;
	bign ox=xb/2-((xa-1)/2);
	bign oy=yb/2-((ya-1)/2);
	bign ex=xb-xa+1-ox;
	bign ey=yb-ya+1-oy;
	bign res=ox*oy+ex*ey;
	cout<<res<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{

	long long x1,x2,y1,y2,t,k;
cin >> x1>>y1>>x2>>y2;

	  t= abs(((x2-x1)/2+1)*(((y2-y1)/2+1))) + abs(((x2-x1)/2)*(((y2-y1)/2)));

cout << t
}


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

int main(){
#pragma warning(disable : 4996)
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long long int  x1,y1,x2,y2;
	cin >> x1>>y1>>x2>>y2;
	long long int kol;
	x2 = x2 - x1;
	x1 = 0;
	y2 = y2 - y1;
	y1 = 0;

	kol =(x2/2+1)*(y2/2+1)+(x/2)*(y/2);
	cout << kol;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ull unsigned long long
#define LL long long int
#define pii pair<int,int>
#define mp make_pair
#define pb(x) push_back(x)
#define F(i,a,n) for(int i=(a);i<(n);++i)
#define FD(i,a,n) for(int i=(a);i>=(n);--i)
#define FE(it,x) for(it=x.begin();it!=x.end();++it)
#define V(x) vector<x>
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%llu",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define fr first
#define se second
#define MOD 1e9+7

long long  phi(long long n) {
    long long i,res=n;
    for(i=2;i*i<=n;i++) {
        if(n%i==0) {
        while(n%i==0)
            n/=i;
        res-=res/i;
       }
   }
    if(n>1)
        res-=res/n;
    return res;
}
int main() {
	long long n,k;
	cin >> n >> k;
	k = k+1;
	k/=2;
	long long ans = n;
	while(k--){
		ans = phi(ans);
		if(ans == 1) break;
	}
	cout << ans%MOD << endl;
}


#include <bits/stdc++.h>

#define define_pair(classname, x, y) struct classname { int x; int y; \
    classname(int x = 0, int y = 0) : x(x), y(y) {} };

#define define_triple(classname, x, y, z) struct classname { int x; int y; int z; \
    classname(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} };

using namespace std;

inline namespace Infinity
{
inline namespace Constant
{
constexpr const int eof         = EOF;
constexpr const int maxint      = INT_MAX;
constexpr const long long maxll = LLONG_MAX;
constexpr const double eps      = DBL_EPSILON;
} // namespace Infinity::Constant

inline namespace TypeDefine
{
using uint  = unsigned int;
using ll    = long long int;
using ull   = unsigned long long int;
using ld    = long double;
template<typename T = int> using Pair = pair<T, T>;
template<typename T = int> using PairList = vector<Pair<T>>;
template<typename T = vector<int>> using Iter = typename T::iterator;
} // namespace Infinity::TypeDefine

inline namespace IO
{
const char LF = '\n';
const char SP = ' ';

int dbl_prec = 10;
int ldbl_prec = 18;

inline void write(const int n)
{ printf("%d", n); }

inline void write(const unsigned n)
{ printf("%u", n); }

inline void write(const int64_t n)
{ printf("%" PRId64, n); }

inline void write(const uint64_t n)
{ printf("%" PRIu64, n); }

inline void write(const double a)
{ printf("%.*f", dbl_prec, a); }

inline void write(const long double a)
{ printf("%.*Lf", ldbl_prec, a); }

inline void write(const char c)
{ printf("%c", c); }

inline void write(const char s[])
{ printf("%s", s); }

inline void write(const string &s)
{ printf("%s", s.data()); }

template<typename T> inline void writeSP(const T a)
{ write(a); write(SP); }

template<typename T, typename U> inline void write(const pair<T, U> &p)
{ writeSP(p.first); write(p.second); }

template<class T> inline void write(const T a)
{ for (auto i = a.begin(); i != a.end(); i++) { if (i != a.begin()) write(SP); write(*i); } }

template<typename T> inline void write(initializer_list<T> list)
{ for (auto i = list.begin(); i != list.end(); i++) { if (i != list.begin()) write(SP); write(*i); } }

template<typename T> inline void writer(T begin, T end)
{ for (write(*begin++); begin != end; ++begin) write(SP), write(*begin); }

inline void writeln()
{ write(LF); }

inline void writeSP()
{ write(SP); }

template<typename T> inline void writeln(const T &a)
{ write(a); write(LF); }

template<typename T> inline void writeln(initializer_list<T> list)
{ for (auto i = list.begin(); i != list.end(); i++) { if (i != list.begin()) write(SP); write(*i); } write(LF); }

template<class T> inline void writelns(const T &a)
{ for (auto n : a) writeln(n); }

template<typename T, typename... types> inline void write(const T &a, const types &...args)
{ write(a); write(args...); }

template<typename... types> inline void writeln(const types &...args)
{ write(args...); write(LF); }

template<typename... types> inline void writeSP(const types &...args)
{ write(args...); write(SP); }

inline void writelnYN(bool b)
{ writeln(b ? "YES" : "NO"); }

inline void writelnyn(bool b)
{ writeln(b ? "Yes" : "No"); }

string caseN(int n, bool sharp = true, bool space = true)
{ return string("Case ") + (sharp ? "#" : "") + to_string(n) + ":" + (space ? " " : ""); }

inline int read(int &n)
{ return scanf("%d", &n); }

inline int read(int64_t &n)
{ return scanf("%" SCNd64, &n); }

//template<typename T, typename ... types> inline int read(T &n, types &...args)
//{ return read(n) == eof ? eof : read(args...) + 1; }

inline char getcc()
{ char c; do c = getchar(); while (isspace(c)); return c; }

inline int getint()
{ int n; read(n); return n; }

inline int64_t getll()
{ int64_t n; read(n); return n; }

inline double getdbl()
{ double n; scanf("%lf", &n); return n; }

inline pair<int, int> getpair()
{ pair<int, int> p; scanf("%d%d", &p.first, &p.second); return p; }

inline vector<int> getints(int n)
{ vector<int> v(n); for (int &i : v) i = getint(); return v; }

inline vector<pair<int, int> > getpairs(int n)
{ vector<pair<int, int> > v(n); for (pair<int, int> &p : v) { p = getpair(); } return v; }

inline void read(string &str, unsigned size)
{ char s[++size]; scanf("%s", s); str.assign(s); }

inline string getstr(unsigned size = 0x100000)
{ string s; read(s, size); return s; }

inline string getln(unsigned size = 0x100000)
{ char s[++size]; scanf("%[^\n]", s); getchar(); return s; }
} // namespace Infinity::IO

inline namespace BattleLab
{
template<typename T>
class AdjacencyList : public vector<vector<T>>
{
public:
    AdjacencyList(unsigned size = 0) : vector<vector<T>>(size)
    {}

    void addDirected(T u, T v)
    { (*this)[u].push_back(v); }

    void addUndirected(T u, T v)
    { addDirected(u, v); addDirected(v, u); }
};

class Range
{
    class RangeIterator
    {
    public:
        RangeIterator(int current = 0, int step = 1) : current(current), step(step) {}
        // works fine with c++11 range-based for loop ... only
        bool operator !=(const RangeIterator &iterator) const { return current < iterator.current; }
        int operator *() const { return current; }
        RangeIterator operator ++() { return {current += step, step}; }
    protected:
        int current, step;
    };
public:
    Range(int to, int from = 0, int step = 1) : from(from), to(to), step(step) {}
    RangeIterator begin() const { return {from, step}; }
    RangeIterator end() const { return {to, step}; }
protected:
    int from, to, step;
};

Range range(int to)
{ return {to}; }

Range range(int from, int to)
{ return {to, from}; }

Range range(int from, int to, int step)
{ return {to, from, step}; }
} // namespace Infinity::BattleLab

inline namespace Miscelleneous
{
inline constexpr int ctoi(const char c)
{ return c - '0'; }

inline constexpr char itoc(const int n)
{ return n + '0'; }

inline int dtoi(const double d)
{ return round(d); }

template<typename T> inline constexpr bool in(T x, T l, T r)
{ return l <= x && x <= r; }

template<typename T> inline constexpr T tristate(int val, T nag, T zero, T pos)
{ return val > 0 ? pos : val < 0 ? nag : zero; }

template<class T> inline int size(const T &a)
{ return a.size(); }

template<class T> inline void sort(T &a)
{ sort(a.begin(), a.end()); }

template<class T1, class T2> inline void sort(T1 &a, T2 comp)
{ sort(a.begin(), a.end(), comp); }

template<class T1, typename T2> inline int lbound(const T1 &a, const T2 k)
{ return lower_bound(a.begin(), a.end(), k) - a.begin(); }

template<class T1, typename T2> inline int ubound(const T1 &a, const T2 k)
{ return upper_bound(a.begin(), a.end(), k) - a.begin(); }

template<class T1, class T2> inline int count(T1 &a, T2 k)
{ return ubound(a, k) - lbound(a, k); }

template<typename T> inline void clear(T &a)
{ memset(a, 0, sizeof a); }

template<typename T> T gcd(T a, T b)
{ while (b) { T t = a % b; a = b; b = t; } return a; }

template<typename T> T lcm(T a, T b)
{ return a / gcd(a, b) * b; }

long long mod = 1e9 + 7;

long long qpow(long long a, long long b, long long c = mod)
{ return b ? qpow(a * a % c, b >> 1, c) * (b & 1 ? a : 1) % c : 1; }

// find (x, y) s.t. a x + b y = gcd(a, b) = d
template<typename T> T exGcd(T a, T b, T &x, T &y)
{ T d = a; if (b) { d = exGcd(b, a % b, y, x); y -= a / b * x; } else { x = 1; y = 0; } return d; }

// returns number of nk's in [l, r]
template<typename T> inline constexpr T mps(T l, T r, T k)
{ return ((r - (r % k + k) % k) - (l + (k - l % k) % k)) / k + 1; }

template<typename T> inline constexpr T sgn(T a)
{ return a ? a > 0 ? 1 : -1 : 0; }

template<typename T> inline constexpr T sq(T a)
{ return a * a; }

template<typename T> inline constexpr bool odd(T a)
{ return bool(a % 2); }

template<typename T> inline constexpr bool even(T a)
{ return !bool(a % 2); }

// simple mod
template<typename T1, typename T2> inline constexpr T1 smod(T1 x, T2 m)
{ return x > m ? x - m : x + m < m ? x + m : x; }

// lengthes of recurring period of replacement `a`
vector<int> repetend(vector<int> a)
{ vector<int> p(a.size(), -1);
  for (unsigned i = 0; i < a.size(); i++) if (p[i] == -1) {
    int c = 1; for (unsigned j = a[i]; j != i; j = a[j]) ++c;
    p[i] = c; for (unsigned j = a[i]; j != i; j = a[j]) p[j] = c;
  } return p; }

template<typename T> inline constexpr T lmiddle(T first, T last)
{ return first + (last - first) / 2; }

template<typename T> inline constexpr T rmiddle(T first, T last)
{ return last - (last - first) / 2; }

// returns the largest value in [l, r) s.t. check(x)
template<typename T, typename F> T dichotomy(T l, T r, F check, T prec = 1)
{ while (r - l > prec) { T m = lmiddle(l, r); (check(m) ? l : r) = m; } return l; }

// returns the smallest value in (l, r] s.t. check(x)
template<typename T, typename F> T dichotomy2(T l, T r, F check, T prec = 1)
{ while (r - l > prec) { T m = rmiddle(l, r); (check(m) ? r : l) = m; } return r; }

bool contains(const string &s, const string &t)
{ return s.find(t) != string::npos; }

template<typename T> bool contains(const T &s, typename T::value_type t)
{ for (typename T::value_type c : s) if (c == t) return true; return false; }

template<typename T> bool contains(const initializer_list<T> s, T t)
{ return find(s.begin(), s.end(), t) != s.end(); }
} // namespace Infinity::Miscelleneous
} // namespace Infinity

class Prime
{
public:
    Prime(int n) : b(n, false), p()
    { for (int i = 2; i < n; i++) { if (b[i] == false) {
        p.push_back(i); for (int j = i + i; j < n; j += i) { b[j] = true; } } } }

    vector<pair<long long, int>> fact(long long n) // O(sqrt(n))
    {
        vector<pair<long long, int>> fact;
        for (int i = 0; 1ll * p[i] * p[i] <= n; i++) {
            int k = 0;
            while (n % p[i] == 0) { n /= p[i]; ++k; }
            if (k) { fact.emplace_back(p[i], k); }
        }
        if (n > 1) { fact.emplace_back(n, 1); }
        return fact;
    }

    long long phi(long long n)
    {
        long long phi = 1; vector<pair<long long, int>> fct = fact(n);
        for (auto p : fct) { phi *= (p.first - 1) * qpow(p.first, p.second - 1); }
        return phi;
    }

protected:
    vector<int> b, p;
};

int main()
{
    mod = maxll;
    long long n = getll(), k = getll();
    Prime p(1234567);
    for (int i = 0; i < (k + 1) / 2; i++) {
        n = p.phi(n);
        if (n == 1) {
            break;
        }
    }
    writeln(n % (1e9 + 7));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define sz(v) ((int) v.size())
#define all(v) v.begin(), v.end()
#define forn(i, j, n) for (int i = j; i < n; ++i)
#define forc(i, n, j) for (int i = n - 1; i >= j; --i)
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <double> vd;
typedef vector <bool> vb;
typedef vector <pii> vpii;

int f(int n)
{
    int ans = n;
    for (int i = 2; i * i <= n; ++i)
    {
        if (n % i != 0) continue;
        ans -= ans / i;
        while (n % i == 0)
            n /= i;
    }
    if (n != 1)
        ans -= ans / i;
    return ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    int val = (k + 1) / 2;
    forn(i, 0, val)
    {
        if (n == 1)
        {
            cout << n;
            return 0;
        }
        n = f(n);
    }
    cout << n;
    return 0;
}


/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;

typedef long long LL;
long long mulmod(long long a,long long b, long long MOD)
{
	long long q=(long long)(((long double)a*(long double)b)/(long double)MOD);
	long long r=a*b-q*MOD;
	if (r>MOD) r %= MOD;
	if(r<0) r+=MOD;
	return r;
}

long long power(long long b, long long n, long long mod)
{
	long long x=1, p=b;
	while(n)
	{
		if(n&1)
		{
			x = mulmod(x, p, mod);
		}
		p = mulmod(p, p, mod);
		n >>= 1;
	}
	return x;
}

bool rabin_miller(long long p)
{
	if (p < 2) return false;
	if (p != 2 && p % 2 == 0) return false;
	if (p < 8) return true;
	long long s = p-1, val = p-1, a, m, temp;
	while (s % 2 == 0) s >>= 1;
	for (int i = 0; i < 3; ++i)
	{
		a = 1ll*rand()%val + 1ll;
		temp = s;
		m = power(a, temp, p);
		while (temp != (p-1) && m != 1 && m != (p-1))
		{
			m = mulmod(m, m, p);
			temp <<= 1;
		}
		if (m != (p-1) && temp % 2 == 0) return false;
	}
	return true;
}

vector<long long> lst;

int main()
{
	long long n,k;
	scanf("%lld %lld",&n,&k);
	long long val=(k+1)/2;
	long long cur=n;
	long long tmp;
		for(int i=1;i<=val;i++)
		{
			long long rt=sqrt(cur);
			tmp=cur;
			for(int j=2;j<=rt;j++)
			{
				if(tmp==1)
				{
					break;
				}
				if((tmp%j)==0)
				{
					if(rabin_miller(j))
					{
						lst.push_back(j);
						while((tmp%j)==0)
						{
							tmp/=j;
						}
					}
				}
			}
			if(tmp!=1)
			{
				lst.push_back(tmp);
			}
			for(int j=0;j<lst.size();j++)
			{
				cur/=lst[j];
				cur*=(lst[j]-1);
			}
			lst.clear();
			if(cur==1)
			{
				break;
			}
			//printf("%lld\n",cur);
		}
		printf("%lld\n",cur);
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <functional>

//#include <limits.h>

typedef int long long bint;
typedef unsigned int long long buint;

using namespace std;

void problemE();
int main(){
	/*int n;
	vector<double> p(100);
	cin >> n;*/
	problemE();
	return 0;
}

void problemA(){
	set<char> a;
	char temp;
	cin.get(temp);
	if (temp == '{'){
		while (temp != '}'){
			cin.get(temp);
			if (temp >= 'a' && temp <= 'z')
				a.insert(temp);
		}
	}
	cout << a.size();
}
int maxsub(string &a, int k, int l){
	int counter = 0;
	for (int i = 0; i < a.size(); ++i){
		if (i + k >= a.size()){
			//if (counter + l == k){
			if (k - counter <= l){
				return k;
			}
			else
				return 0;
		}
		if (a[i] != a[i + k]){
			if (counter == k)
				return k;
			else if (counter == 0)
				continue;
			else{
				counter = 0;

			}
		}
		else{
			counter += 1;
			if (counter == k)
				return k;
		}

	}
	if (counter == k)
		return k;
	else
		return 0;
}
void problemB(){
	string s = "uqytussdzppiuwxterrfyrwtsrkdpfzhjpeuuulopnnjtltdtlkzwixouxteuheqaxhaicoeveggwkcnkamluxykyktmvafajfnxmeuuulopnnjtltdtlkzwixouxteuheqaxhaicoeveggwkcnkamluxykyktmvafajfnxmefkurbbcbesiwcauwmlhmfslcavsreea";

	cin >> s;
	int k = 41;
	cin >> k;
	char temp;
	int tandem = 0;

	int i = (s.size() + k) / 2 + 1;
	while (i-- > 0){
		tandem = maxsub(s, i, k);
		if (tandem != 0)
			break;
	}

	tandem *= 2;
	cout << tandem;
}
inline int min(int a, int b){
	if (a < b)
		return a;
	else
		return b;
}
int recursion(vector<int> &a, int sum){
	if (a.size() == 3){
		return sum + min(a[0], a[2]);
	}
	else{

		int maxi = 0;
		int price = 0;
		for (int i = 0; i < a.size(); i++){

			if (i != a.size() - 1 && i != 0)
				price = min(a[i - 1], a[i + 1]);
			else
				price = 0;
			int temp = a[i];
			a.erase(a.begin() + i);
			int tmp1 = recursion(a, sum + price);
			a.insert(a.begin() + i, temp);

			if (maxi < tmp1){
				maxi = tmp1;
			}
		}
		return  maxi;
	}

}
void problemErec(){
	int n = 10;
	//cin >> n;
	if (n == 2){
		cout << 0;
		return;
	}

	int max = 0;
	int maxindex;
	//vector<int> a(n);
	vector<int> a = { 96, 66, 8, 18, 30, 48, 34, 11, 37, 42 };
	for (int i = 0; i < n; i++){
		//cin >> a[i];
	}
	int sum = 0;
	cout << recursion(a, sum);
}
void problemE(){
	int n = 10;
	cin >> n;
	if (n == 2){
		cout << 0;
		return ;
	}

	int max = 0;
	int maxindex;
	vector<int> a(n);

	//vector<int> a = { 96, 66, 8, 18, 30, 48, 34, 11, 37, 42 };
	//vector<int> a = { 42, 37, 11, 34, 48, 30, 18, 8, 66, 96 };
	int first = 0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int sum = 0;

	while (a.size() > 2){

		for (int i = 1; i < a.size() - 1 ; ++i){
			maxindex = -1;
			int ankouc = min(a[i - 1], a[i + 1]);
			if (a[i] < ankouc)
			{
				sum += ankouc;
				maxindex = i;
				a.erase(a.begin() + maxindex);
				i--;
			}

		}
		if (maxindex == -1){
			sort(a.begin(), a.end());
			for (int i = 0; i < a.size()-2; ++i){
				sum += a[i];
			}
			break;
		}

	}
	cout << sum;
}


#include <bits/stdc++.h>
#define mod 1000000009LL
#define siz 100000009
#define maxx 100000009
#define ll long long
#define ull unsigned long long
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define rep(i,n) for(__typeof(n) i=0;i<(n);i++)
#define FOR(i,a,b) for(__typeof(b) i=(a);i<(b);++i)
#define fore(i,a,b) for(__typeof(b) i=(a);i<=(b);++i)
#define ford(i,a,b,d) for(__typeof(b) i=(a);i<(b);i+=(d))
#define forr(i,n,e) for(__typeof(n) i=(n);i>=(e);--i)
#define forrd(i,n,e,d) for(__typeof(n) i=(n);i>=(e);i-=(d))
#define repit(it,m) for(it=m.begin();it!=m.end();it++)
#define fori(it,s) for(__typeof((s).begin()) (it)=(s).begin();(it)!=(s).end();(it)++)
#define foreach(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); ++it)
#define unique(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define test int T;cin>>T;fore(t,1,T)
#define sz(x) int((x).size())
#define s(n) cin>>n;
#define p(n) cout<<n<<endl;
using namespace std;
double _st;
const int N=1234567;
int a[N];
pair<int,int>p[N];
int pr[N],ne[N];
void solve()
{
  int n;
  cin>>n;
  rep(i,n)
    {
      cin>>a[i];
      p[i] = mp(a[i],i);
    }
  sort(all(p));
  rep(i,n)
    {
      pr[i] = i-1;
      ne[i] = i+1;
    }
  int low=0,high=n-1;
  ll ans = 0;
  rep(i,n-2)
    {
      int j=p[i].second;
      if(j==low)
    {
      ans += p[i].first;
      low=ne[low];
      continue;
    }
      if(j==high)
    {
      ans+= p[i].first;
      high = pr[high];
      continue;
    }
      int x = a[pr[j]];
      int y = a[ne[j]];
      if(x<y)
    ans += x;
      else
    ans += y;
      pr[ne[j]] = pr[j];
      ne[pr[j]] = ne[j];
    }
  cout << ans;
}
void pre()
{
  solve();
}
void end(){
#ifdef dexter
  fprintf(stdout,"\nTIME: %.3lf sec\n",(double)(clock()-_st)/(CLOCKS_PER_SEC));
#endif
}
int main()
{
#ifdef dexter
  freopen("/home/dexter/Desktop/Dropbox/ZONE/inout/input.txt","r",stdin);
  //freopen("/home/dexter/Desktop/Dropbox/ZONE/inout/output.txt","w",stdout);
  _st = clock();
#endif
  //  ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);
  pre();
  end();
  return 0;
}


#include <bits/stdc++.h>

#define MAXN 500100

using namespace std;

typedef long long L;

int n;
L vals[MAXN];
int l[MAXN], r[MAXN];
int idxs[MAXN];

bool idx_cmp(int rhs, int lhs)
{
    return vals[rhs] < vals[lhs];
}

void rem(int idx)
{
    l[idx + 1] = l[idx];
    r[idx - 1] = r[idx];
}

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

    L ignore_this;
    while(cin >> n)
    {
        for(int i = 0; i < n; ++i)
        {
            cin >> vals[i];
            idxs[i] = i;
            l[i] = i - 1;
            r[i] = i + 1;
        }

        sort(idxs + 1, idxs + n - 1, idxs_cmp);

        L ans = 0;
        for(int i = 1; i < n - 1; ++i)
        {
            int idx = idxs[i];
            ans += min(vals[l[idx]], vals[r[idx]]);
            rem(idx);
        }

        cout << ans << '\n';
    }
}


#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <functional>

//#include <limits.h>

typedef int long long bint;
typedef unsigned int long long buint;

using namespace std;

void problemE(){
	int n = 10;
	cin >> n;
	if (n == 2){
		cout << 0;
		return;
	}

	int max = 0;
	int maxindex;
	//vector<int> a(n);

	vector<int> a = { 96, 66, 8, 18, 30, 48, 34, 11, 37, 42 };
	//vector<int> a = { 42, 37, 11, 34, 48, 30, 18, 8, 66, 96 };
	int first = 0;
	for (int i = 0; i < n; i++){
		//cin >> a[i];
	}
	int sum = 0;

	//while (a.size() > 2){
		if (a[0] > a[a.size()-1]){
			for (int i = 1; i < a.size() - 1; ++i){
				maxindex = -1;
				int ankouc = min(a[i - 1], a[i + 1]);
				if (a[i] < ankouc)
				{
					sum += ankouc;
					maxindex = i;
					a.erase(a.begin() + maxindex);
					i -= 2;
					if (i < 1)i = 1;
				}

			}
			//if (maxindex == -1){
				//sort(a.begin(), a.end());
				for (int i = a.size()-1; i > 1; --i){
					sum += a[i];
				}
				//break;
			//}
		}
		else if (a[0] < a[a.size() - 1]){
			for (int i = a.size() - 2; i > 0; --i){
				maxindex = -1;
				int ankouc = min(a[i - 1], a[i + 1]);
				if (a[i] < ankouc)
				{
					sum += ankouc;
					maxindex = i;
					a.erase(a.begin() + maxindex);
					i += 1;
					if (i > a.size() - 2)i = a.size() - 2;
				}

			}
			//if (maxindex == -1){
				//sort(a.begin(), a.end());
				for (int i = 0; i < a.size() - 2; ++i){
					sum += a[i];
				}
				//break;
			//}
		}
		else{
			sort(a.begin() , a.end() );
			for (int i = a.size() -3; i >=0; --i){
				sum += a[i];
			}
		}

	//}
	cout << sum;
}
int main(){
	problemE();
	return 0;
}


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

typedef long long ll;
int d[1005][12];
int dp[1005][105][2];
int a[1005];
int n,k,m;
int sub(int x,int y)
{
    x-=y;
    if(x<0)x+=m;
    return x;
}

int main()
{
    scanf("%d%d%d",&n,&k,&m);
    if(m==1){
        printf("0\n");
        return 0;
    }
    int ans=0;a[0]=1;
    for(int i=1;i<=n;i++)a[i]=(ll)a[i-1]*10%m;
    if(k==1){
        ans=sub(a[n],1);
        printf("%d\n",ans);
        return 0;
    }
    for(int j=1;j<10;j++){
        int res=j;
        for(int i=n;i>=1;i--){
            d[i][j]=res%k;
            res=(ll)res*10%k;
        }
    }
    for(int i=0;i<10;i++)
        dp[n][i%k]=(dp[n][i%k]+1)%m;
    for(int i=n;i>=1;i--){
        for(int j=1;j<k;j++){
            for(int z=0;z<10;z++){
                int to=(d[i][z]+j)%k;
                dp[i][to]=(dp[i][to]+dp[i+1][j])%m;
            }
        }
        if(i<n){
        for(int z=0;z<10;z++)
            dp[i][d[i][z]]=(dp[i][d[i][z]]+1)%m;
        }
        int len,res;
        len=i-1;
        res=1;
        if(len>0)res=(ll)9*a[len-1]%m;
        ans=(ans+(ll)res*sub(dp[i][0],1)%m)%m;
    }
    printf("%d\n",ans);
    return 0;
}


#include<stdio.h>
#include<memory.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define yt eg[i].to
typedef __int64 LL;
const int N=1005;
int dp[N][100],tn[N],tnn[N];
inline void ff(int &x,int m){
    if(x>=m) x-=m;
}
int main(){
    int n,i,j,k,l,r,p;
    int t,x,y,m,w,ans;
    while(~scanf("%d%d%d",&n,&k,&m)){
        for(tn[1]=1,i=2;i<=n;i++) tn[i]=tn[i-1]*10%k;
        for(tnn[0]=i=1;i<=n;i++) tnn[i]=10LL*tnn[i-1]%m;
        memset(dp,0,sizeof dp);
        for(ans=i=0;i<10;i++) ff(dp[1][i%k]++);
        if(n==1) ans=(dp[1][0]-1+m)%m;
        else ans=(LL)(dp[1][0]-1)*tnn[n-2]%m*9%m;
        for(dp[1][0]=1,i=2;i<=n;i++){
            for(j=1;j<=k;j++){
                if(!dp[i-1][j]) continue;
                for(t=0;t<10;t++)
                    ff(dp[i][(j+t*tn[i])%k]+=dp[i-1][j],m);
            }
            if(i<n) ff(ans+=(LL)dp[i][0]*tnn[n-i-1]%m*9%m,m);
            else ff(ans+=dp[i][0],m);
            for(dp[i][0]=j=0,t=1;t<10;t++)
                ff(dp[i][(j+t*tn[i])%k]+=dp[i-1][j],m);
            if(i<n) ff(ans+=(LL)dp[i][0]*tnn[n-i-1]%m*9%m,m);
            else ff(ans+=dp[i][0],m);
            dp[i][0]=1;
        }
        printf("%d\n",ans%m);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SZ(n) memset((n),0,sizeof(n))
#define SMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define ALL(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)

typedef long long i64;

const int MK = 121;
int N, K, M;
i64 op[MK];
i64 temp[MK];

iint main() {

#define CL for(int __i=0; __i<=K; __i++) temp[__i]=0;
#define CP for(int __i=0; __i<=K; __i++) op[__i]=temp[__i];

    cin >> N >> K >> M;
    for(int i=0; i<10; i++) {
        op[i%K] ++;
    }
    op[K] = op[0] - 1;
    op[0] = 1;
    int nm = 10;
    for(int i=1; i<N; i++) {
        CL;
        //cout << nm << endl;
        for(int j=0; j<K; j++) {
            for(int t=0; t<10; t++) {
                int md = (j+nm*t)%K;
                if( md ) {
                    temp[md] += op[j]; temp[md] %= M;
                } else {
                    if(t){
                        temp[K] += op[j]; temp[K] %= M;
                        //cout << "ZZ " << op[j] << endl;
                    } else {
                        temp[0] += op[j]; temp[0] %= M;
                    }
                }
                //cout << md << ' ' << j << ' ' << op[j] << endl;
            }
        }
        int ft = i==N-1 ? 9 : 10;
        temp[K] += op[K] * ft; temp[K] %= M;

        CP;
        nm *= 10;
        nm %= K;

    }

    cout << op[K]%M << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef pair<int,int>PII;
typedef long long LL;
LL dp[1111][102][2];
LL N,K,MOD;
int P[1111];
LL dfs(int pos,int mod,int flag){
    if(pos>N){
        return flag;
    }
    if(~dp[pos][mod][flag]){
        return dp[pos][mod][flag];
    }
    LL ans=0;
    int tmp=(N==pos);
    for(int i=tmp;i<10;++i){
        int p=(mod+i*P[pos-1])%K;
        ans += dfs(pos+1,p,flag||(p==0&&i!=0));
    }
    ans%=MOD;
    return ans;
}
int main( ){
    ios::sync_with_stdio(false);
    //cout<<POW(10,5,1777)<<endl;
    cin>>N>>K>>MOD;
    memset(dp,-1,sizeof(dp));
    P[0]=1;
    for(int i=1;i<1111;++i){
        P[i]=P[i-1]*10%K;
    }
    cout<<dfs(1,0,0)<<endl;
    return 0;

}


#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 <ctime>
// #include<bits/stdc++.h>
#include <queue>
#define __ ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define inrange(x,y,n,m) (x>=0 && y>=0 && x<n && y<m)
const int N = 100;
const int mod = 1e9+7;
ll dp[10][N+100];
ll c[N+10][N+10];
int a[10];
void pre(){
    for(int i=0;i<=100;++i){
        c[i][0] = 1;
        c[i][i] = 1;
        c[i][1] = i;
    }
    c[0][0] = 1;
    for(int i=2;i<=100;++i){
        for(int j=2;j<=i;++j){
            c[i][j] = (c[i-1][j] + c[i-1][j-1])%mod;
        }
    }
}
int main(){
    pre();
    int n;
    cin>>n;
    int su = 0;
    for(int i=0;i<10;++i){
        cin>>a[i];
        su += a[i];
    }
    if(su>n){
        puts("0");
        return 0;
    }
    ll ans = 0;
    for(int len = su;len<=n;++len){
        memset(dp,0,sizeof(dp));
        for(int i = a[0];i<=len;++i){
            dp[0][i] = c[len-1][i];
        }
        for(int i=1;i<=9;++i){
            for(int j = a[i];j<=len;++j){
                for(int k = 0;k+j<=len;++k){
                    if(dp[i-1][k]){
                        (dp[i][k+j] += (dp[i-1][k]*c[len-k][j])) %= mod;
                    }
                }
            }
        }
        (ans += dp[9][len]) %= mod;
    }
    cout<<ans<<endl;
}


#include <cstdio>
#include <algorithm>

    const long long mod = 1000000007;

int n;
int a[16];
long long dp[128][16];
long long ch[128][128];

void read() {
    int i;

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

long long go ( int x , int y ) {
    if ( y == 10 ) {
        return !x;
    }
    long long &ans = dp[x][y];
    if ( ans != -1 ) return ans;

    int i;
    ans = 0;

    for (i = a[y]; i <= x; i++) {
        ans += (go ( x - i , y + 1 ) * ch[x][i]) % mod;
        ans %= mod;
    }

    return ans;
}

void solve() {
    int i , j;
    int sum = 0;
    long long ans = 0;

    for (i = 0; i <= 105; i++) {
        ch[i][0] = ch[i][i] = 1;
    }

    for (i = 2; i <= 105; i++) {
        for (j = 1; j < i; j++) {
            ch[i][j] = (ch[i - 1][j] + ch[i - 1][j - 1]) % mod;
        }
    }

    for (i = 1; i < 10; i++) {
        int o = a[i];
        if ( a[i] ) -- a[i];
        sum = 0;

        for (j = 0; j < 10; j++) {
            sum += a[j];
        }

        if ( sum > n - 1 ) {
            a[i] = o;
            continue;
        }

        memset ( dp , -1 , sizeof dp );
        for (j = n - 1; j >= 0; j--) {
                    ans = (ans + go ( j , 0 ));
        }

        a[i] = o;
    }

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

int main() {
    read();
    solve();

    return 0;
}


#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'

using namespace std ;

#define MAXN 1000000
/*lli spf[MAXN];
void sieve();
set<lli> factors(lli x);
lli power(lli x,lli y,lli p);
*/
//void getZarr(string str, lli Z[]);
//vll prefix_function(string s);

typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

lli ncr[101][101];
lli dp[101][11];

int main()

{

//////////////////////////////////////////////
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
//////////////////////////////////////////////

    lli n;
    cin>>n;

    lli a[10];
    loopl(i,0,10)
    cin>>a[i];

    ncr[0][0]=1;

    loopl(i,1,101)
    {
        loopl(j,1,i)
            ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%mod;

        ncr[i][i]=ncr[i][0]=1;
    }

    loopl(i,a[9],n+1)
        dp[i][9]=1;

    for(lli j=8;j>0;j--)
    {
        for(lli i=a[j];i<=n;i++)
        {
            for(lli k=a[j];k<=i;k++)
            {
                dp[i][j]=(dp[i][j]+dp[i-k][j+1]*(ncr[i][k]))%mod;
            }
        }
    }

    for(lli j=a[0]+1;j<=n;j++)
    {
        for(lli k=a[0];k<j;k++)
            dp[j][0]=(dp[j][0]+dp[j-k][1]*(ncr[j-1][k]))%mod;
    }

    lli ans=0;

    loopl(i,0,n+1)
    {
        ans = (ans+dp[i][0])%mod;
    }

    cout<<ans

}

/*vll prefix_function(string s)
{
    lli n = (lli)s.length();
    vll pi(n);

    for (lli i = 1; i < n; i++)
    {
        lli j = pi[i-1];

        while (j > 0 && s[i] != s[j])
            j = pi[j-1];

        if (s[i] == s[j])
            j++;

        pi[i] = j;
    }
    return pi;
}*/

/*void sieve()
{
    spf[1] = 1;
    loopl(i,2,MAXN)
        spf[i] = i;
    for (lli i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (lli i=3; i*i<MAXN; i++) {
        if (spf[i] == i) {
            for (lli j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }

}

multiset<lli> factors(lli x)
{
    multiset<lli> pr;
    while (x != 1)
    {
        pr.insert(spf[x]);
        x = x / spf[x];
    }
    return pr;
}

*/

/*
void dfs(lli q,lli root)
{
    vis[q]=1;

    ans[q]=1;

    for(auto x: v[q])
    {
        if(!vis[x])
        {
            if(a[x]==a[root] && x<root) continue;
            if(a[x]<a[root] || a[x]>a[root]+d) continue;
            dfs(x,root);
            ans[q]=(ans[q]*((ans[x]+1)%mod))%mod ;
        }
    }

}
*/

/*void getZarr(string str, lli Z[])
{
    lli n = str.length();
    lli L, R, k;
    L = R = 0;
    for (lli i = 1; i < n; ++i){
        if (i > R){
            L = R = i;
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        } else {
            k = i-L;
            if (Z[k] < R-i+1)
                Z[i] = Z[k];
            else {
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}

*/
/*
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
*/


#include<iostream>
#include<string.h>
using namespace std;
#define mod 1000000007

int gcd(int a,int b)
{
    int t;
    while(b!=0)
    {
        t=a%b;
        a=b;
        b=t;
    }
    return a;
}

__int64 C(int n,int m)
{
    if(m==0)
        return 1;
    if(n==0)
        return 1;
    int a[1000];
    for(int i=n;i>=n-m+1;i--)
        a[n-i] = i;
    for(int j=2;j<=m;j++)
    {
        int tmp = j;
       for(int i=0;tmp!=1;i++)
       {
          int k = gcd(a[i],tmp);
          a[i]/=k;
          tmp/=k;
       }
    }
    __int64 mul = a[0];
    for(int i=1;i<m;i++)
    {
        mul*=a[i];
        mul%=mod;
    }
    return mul;
}
int main()
{
    int n;
    int a[10];
    cin>>n;
    for(int i=0;i<10;i++)
        cin>>a[9-i];
    __int64 dp[101][10];
    memset(dp,0,sizeof(dp));
    int sum[10];
    sum[0] = a[0];
    for(int i=1;i<10;i++)
        sum[i] = sum[i-1] + a[i];
    for(int i=sum[0];i<=n;i++)
        dp[i][0] = 1;
    /*for(int i=1;i<9;i++)
        dp[sum[i]][i] = dp[sum[i-1]][i-1]*C(sum[i-1]+1,a[i])%mod;
    dp[sum[9]][9] = dp[sum[8]][8]*C(sum[8],a[8])%mod;*/

    for(int i=1;i<9;i++)
        for(int j=sum[i];j<=n;j++)
        {
            dp[j][i] = 0;
            for(int k=sum[i-1];j-k>=a[i];k++)
                dp[j][i] += dp[k][i-1]*C(j,j-k)%mod;
            dp[j][i] %= mod;
        }
    for(int j=sum[9];j<=n;j++)
        {
            if(j==0)
                continue;
            dp[j][9] = 0;
            for(int k=sum[8];j-k>=a[9];k++)
                dp[j][9] += dp[k][8]*C(j-1,j-k)%mod;
            dp[j][9] %= mod;
        }
     __int64 ans = 0;
     for(int i=sum[9]>0?sum[9]:1;i<=n;i++)
         ans += dp[i][9];
     printf("%I64d\n",ans%mod);
    // system("pause");
     return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ll = long long;
using pll = pair <ll, ll>;

ll n, l, r, k;
ll d;
ll wynik = -1;
ll inf = 1e18;

#pragma GCC optimize("O3");

void ans(ll S) {
	wynik = max(wynik, S);
}

void checkTriv(ll S) {
	if (S >= n && S <= 2 * n) {
		if (k % S == 0) ans(S - n);
		if (k % S == (S - 1) && S > n) ans(S - n);
	}
}

pll przetnij(pll a, pll b) {
	return {max(a.first, b.first), min(a.second, b.second)};
}
void checkInterval1(pll p, ll a, ll b) {
	p = przetnij(p, {-inf, (d - b) / a});
	p = przetnij(p, {-inf, (2 * d - 2 * n - b) / (a - 1)});
	p = przetnij(p, {(b - 2 * d - a - 1) / (-a), inf});
	p = przetnij(p, {(b + n - d - a) / (1 - a), inf});

	if (p.first <= p.second) ans(p.second - n);
}

void checkInterval2(pll p, ll a, ll b) {
	b++;
	p = przetnij(p, {-inf, (d + 1 - b) / a});
	p = przetnij(p, {-inf, (2 * d - 2 * n - b) / (a - 1)});
	p = przetnij(p, {(b - 2 * d - a - 1) / (-a), inf});
	p = przetnij(p, {(b + n - d - a) / (1 - a), inf});
	if (p.first <= p.second) ans(p.second - n);
}

void check(pll p, ll a, ll b) {
	checkInterval1(przetnij(p, {n, 2 * n}), a, b);
	checkInterval2(przetnij(p, {n, 2 * n}), a, b);
}

int main() {
	cin >> n >> l >> r >> k;
	if (l <= r) d = r - l + 1;
	else d = n + 1 - (l - r);

	if (n == d) {
		for (ll x = 1; x * x <= k; ++x) {
			if (k % x == 0) {
				checkTriv(x);
				checkTriv(k / x);
			}
		}
		for (ll x = 1; x * x <= k + 1; ++x) {
			if ((k + 1) % x == 0) {
				checkTriv(x);
				checkTriv((k + 1) / x);
			}
		}
	}
	else {
		ll a = k;
		ll b = k;

		for(ll i = 2; i * i <= k; ++i)
		{
			b = k / i;
			ll a1 = k % a;
			ll an = k % (b + 1);

			if (a - b == 1) {
				check({a, a}, -1, (k % a) + a);
			}
			else {

			ll pa = (a1 - an) / (a - b - 1);
			ll pb = a1 - pa * a;
			check({b + 1, a}, pa, pb);
			}
			a = b;
		}

		for(ll i = b; i >= 1; --i) {
			check({i, i}, -1, (k % i) + i);
		}

	}

	cout << wynik << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ll = long long;
using pll = pair <ll, ll>;

ll n, l, r, k;
ll d;
ll wynik = -1;
ll inf = 1e18;

#pragma GCC optimize("O3");

void ans(ll S) {
	wynik = max(wynik, S);
}

void checkTriv(ll S) {
	if (S >= n && S <= 2 * n) {
		if (k % S == 0) ans(S - n);
		if (k % S == (S - 1) && S > n) ans(S - n);
	}
}

pll przetnij(pll a, pll b) {
	return {max(a.first, b.first), min(a.second, b.second)};
}
void checkInterval1(pll p, ll a, ll b) {
	p = przetnij(p, {-inf, (d - b) / a});
	p = przetnij(p, {-inf, (2 * d - 2 * n - b) / (a - 1)});
	p = przetnij(p, {(b - 2 * d - a - 1) / (-a), inf});
	p = przetnij(p, {(b + n - d - a) / (1 - a), inf});

	if (p.first <= p.second) ans(p.second - n);
}

void checkInterval2(pll p, ll a, ll b) {
	b++;
	p = przetnij(p, {-inf, (d + 1 - b) / a});
	p = przetnij(p, {-inf, (2 * d - 2 * n - b) / (a - 1)});
	p = przetnij(p, {(b - 2 * d - a - 1) / (-a), inf});
	p = przetnij(p, {(b + n - d - a) / (1 - a), inf});
	if (p.first <= p.second) ans(p.second - n);
}

void check(pll p, ll a, ll b) {
	checkInterval1(przetnij(p, {n, 2 * n}), a, b);
	checkInterval2(przetnij(p, {n, 2 * n}), a, b);
}

int main() {
	cin >> n >> l >> r >> k;
	if (l <= r) d = r - l + 1;
	else d = n + 1 - (l - r);

	if (n == d) {
		for (ll x = 1; x * x <= k; ++x) {
			if (k % x == 0) {
				checkTriv(x);
				checkTriv(k / x);
			}
		}
		for (ll x = 1; x * x <= k + 1; ++x) {
			if ((k + 1) % x == 0) {
				checkTriv(x);
				checkTriv((k + 1) / x);
			}
		}
	}
	else {
		ll a = k;
		ll b = k;

		for(ll i = 2; i * i <= k; ++i)
		{
			b = k / i;
			ll a1 = k % a;
			ll an = k % (b + 1);

			if (a - b == 1) {
				check({a, a}, -1, (k % a) + a);
			}
			else {

			ll pa = (a1 - an) / (a - b - 1);
			ll pb = a1 - pa * a;
			check({b + 1, a}, pa, pb);
			}
			a = b;
		}

		for(ll i = b; i >= 1; --i) {
			check({i, i}, -1, (k % i) + i);
		}

		for (ll S = n; S <= 2 * n; ++S) {
			ll a = -1;
			ll b = (k % S) + S;
			check({S, S}, a, b);
		}
	}

	cout << wynik << endl;
	return 0;
}


#include <iostream>
using namespace std;
using lint = long long;

int main() {
    lint n, l, r, k, ans = -1

    cin >> n >> l >> r >> k;
    lint x = (r + n - l + 1) % n;

    for (lint i = k, nxt; i > 0; i = nxt) {
        lint t = k / i;
        lint upper = i;
        lint lower = n;
        nxt = k / (t + 1);

        upper = min(upper, 2 * n);
        upper = min(upper, (k - x) / t);
        upper = min(upper, (2 * n - 2 * x + k + 1) / (t + 1));

        lower = max(lower, nxt + 1);
        lower = max(lower, (k - 2 * x + t - 1) / t);

        if (upper >= lower) {
            ans = max(ans, upper - n);
            break;
        }
    }

    if (x <= k && k < 2 * x) ans = max(ans, n - x + 1 + k - x);

    if (k == 2 * x) ans = max(ans, n);

    if (k == n) ans = max(ans, 1ll);

    cout << ans << "\n";

    return 0;
}


#pragma GCC diagnostic error "-std=c++11"
#include <bits/stdc++.h>
#define inline inline __attribute__((always_inline))
using namespace std;

typedef long long LL;
const int N=23333;
const LL inf=1e18;
struct fdt {
	LL p,a;
}f[N],mf[N];
LL m,x,ans;
int fn,mfn;

inline LL qm(LL a,LL b,LL zqm){
    /*LL res=(a*b-(LL)((double)a*b/zqm+0.1)*zqm)%zqm;
    return res<0?res+zqm:res;*/
    __int128 ret=a; ret*=b;
    return LL(ret%zqm);
}

inline LL qp(LL a,LL b) {
	LL ret=1;
	for(;b;b>>=1,a*=a) if(b&1) ret*=a;
	return ret;
}

inline LL qp(LL a,LL b,LL zqm) {
	LL ret=1;
	for(;b;b>>=1,a=qm(a,a,zqm)) if(b&1) ret=qm(ret,a,zqm);
	return ret;
}

inline LL fazphi(LL x) {
	fn=0;
	LL ret=x;
	for(int i=1;i<=mfn;++i) if(x%mf[i].p==0) {
		ret=ret/mf[i].p*(mf[i].p-1);
		f[++fn].p=mf[i].p,f[fn].a=0;
		while(x%mf[i].p==0) x/=mf[i].p,++f[fn].a;
	}
	if(x!=1) f[++fn].p=x,f[fn].a=1;
	return ret;
}

inline void sqrfaz(LL x) {
	for(LL i=2,sq=sqrt(x+1);i<=sq;++i) if(x%i==0) {
		f[++fn].p=i,f[fn].a=0;
		while(x%i==0) x/=i,++f[fn].a;
	}
	if(x!=1) f[++fn].p=x,f[fn].a=1;
}

inline bool fdtcomp(const fdt &a,const fdt &b) {return a.p<b.p;}
inline void unifac() {
	sort(f+1,f+fn+1,fdtcomp);
	for(int i=fn;i>=1;--i) if(f[i].p==f[i-1].p||f[i].a==0) {
		f[i].p=inf;
		f[i-1].a+=f[i].a;
	}
	sort(f+1,f+fn+1,fdtcomp);
	for(int i=1;i<fn;++i) if(f[i+1].p==inf) {
		fn=i;
		break;
	}
}

inline void solve(LL d) {
	LL pd=fazphi(d),ord=1;
	for(int i=1,lim=fn;i<=lim;++i) --f[i].a,sqrfaz(f[i].p-1);
	unifac();
	for(int i=1;i<=fn;++i) {
		LL b=f[i].a,tmp=pd;
		for(LL j=f[i].a-1;j>=0;--j) {
			tmp/=f[i].p;
			if(qp(x,tmp,d)==1) b=j;
		}
		ord*=qp(f[i].p,b);
	}
	//printf("%lld %lld %lld\n",d,pd,ord);
	ans+=pd/ord;
}

int main() {
	scanf("%lld%lld",&m,&x);
	LL sqm=sqrt(m+1),tmp=m;
	for(LL i=2;i<=sqm;++i) if(tmp%i==0) {
		mf[++mfn].p=i,mf[mfn].a=0;
		while(tmp%i==0) tmp/=i,++mf[mfn].a;
	}
	if(tmp!=1) mf[++mfn].p=tmp,mf[mfn].a=1;

	for(LL i=1;i<=sqm;++i) if(m%i==0) {
		solve(i);
		if(m/i!=i) solve(m/i);
	}
	printf("%lld\n",ans);

	return 0;
}


#include<bits/stdc++.h>
using namespace stdl;
int main(){
        cout<<1<<endl;
        return 0;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 1005
#define ll long long
#define ld long double
ll p[N],q[N],n,X,ans;int num,tot;
ll phi(ll x){ll ret=x;for(int i=1;i<=num;i++)if(!(x%p[i]))ret/=p[i],ret*=p[i]-1;return ret;}
// ll q_mul(ll x,ll n,ll mod){if(n<2147483647&&x<2147483647)return n*x%mod;ll ret=0;for(;n;n>>=1,x=(x<<1)%mod)if(n&1)ret=(ret+x)%mod;return ret;}
ll q_mul(ll x,ll y,ll mod){return ((x*y-(ll)(((ld)x*y+0.5)/P)*P)%P+P)%P;}
ll q_pow(ll x,ll n,ll mod){ll ret=1;for(;n;n>>=1,x=q_mul(x,x,mod))if(n&1)ret=q_mul(ret,x,mod);return ret;}
void work(ll g)
{
	ll mod=n/g,ph=phi(mod),x=X%mod,K=ph;
	for(int i=1;i<=tot;i++)while(K%q[i]==0&&q_pow(x,K/q[i],mod)==1)K/=q[i];
	ans+=ph/K;
}
void get_pri(ll x)
{
	q[++tot]=x+1;
	for(int i=2;i<=(x/i);i++)
		if(x%i==0){q[++tot]=i;while(x%i==0)x/=i;}
	if(x!=1)q[++tot]=x;
}
void init()
{
	ll x=n;
	for(int i=2;i<=(x/i);i++)
		if(x%i==0){p[++num]=i;while(x%i==0)x/=i;}
	if(x!=1)p[++num]=x;
	for(int i=1;i<=num;i++)get_pri(p[i]-1);
	sort(q+1,q+tot+1);tot=unique(q+1,q+tot+1)-q-1;
}
int main()
{
	scanf("%lld%lld",&n,&X);init();int i;
	for(i=1;i<(n/i);i++)
		if(n%i==0)work(i),work(n/i);
	if(1ll*i*i==n)work(i);
	printf("%lld\n",ans);
}


#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

long long gcd(long long x, long long y){return y?gcd(y, x%y):x;}
long long lcm(long long x, long long y){return x/gcd(x, y)*y;}
vector <long long> primeFactors;
long long etf(long long x){
	long long etf=x;
	for(auto i:primeFactors){
		if(x%i==0){
			etf=etf/i*(i-1);
			do{
				x/=i;
			}while(x%i==0);
		}
	}
	return etf;
}
long long modex(long long b, long long e, long long m){
	long long h=1;
	while(e){
		if(e&1)h=(__int128_t)h*b%m;
		b=(__int128_t)b*b%m;
		e>>=1;
	}
	return h;
}
int main(){
	long long m, x;
	scanf("%lld%lld", &m, &x);
	{
		long long M=m;
		for(long long i = 2;i*i <= m;i ++){
			if(m%i==0){
				primeFactors.push_back(i);
				do{
					m/=i;
				}while(m%i==0);
			}
		}
		if(m>1){
			primeFactors.push_back(m);
		}
		m=M;
	}

	vector <long long> mfactors;
	for(long long i = 1;i*i <= m;i ++){
		if(m%i==0){
			mfactors.push_back(i);
			mfactors.push_back(m/i);
		}
	}
	sort(mfactors.begin(), mfactors.end());
	mfactors.resize(unique(mfactors.begin(), mfactors.end())-mfactors.begin());

	vector <long long> phifactors;
	long long phi=etf(m);
	for(long long i = 1;i*i <= phi;i ++){
		if(phi%i==0){
			phifactors.push_back(i);
			phifactors.push_back(phi/i);
		}
	}
	sort(phifactors.begin(), phifactors.end());
	phifactors.resize(unique(phifactors.begin(), phifactors.end())-phifactors.begin());
	long long ans=1ll;
	for(int i = 1;i < mfactors.size();i ++){
		long long num=etf(mfactors[i]), den=0;
		for(auto j:phifactors){
			if(num%j==0&&modex(x, j, mfactors[i])==1){
				den=j;
				break;
			}
		}
		ans+=num/den;
	}
	printf("%lld\n", ans);
}


#include <iostream>
using namespace std;
long long pow2=1,ans=1;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){pow2=(pow2*2)%1000000009);}
    for(int i=1;i<=n;i++){ans=(ans*(pow2-i))%1000000009;}
    cout<<ans;
    return 0;
}


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

using namespace std;

typedef LL __int64;

const int MAXN = 1000000 + 10;
const int MOD = 1000000009;

LL Pow(LL a, LL b, LL c) {
	LL tmp = a, res = 1 % c;
	while(b) {
		if(b & 1) {
			res = res * tmp % MOD;
		}
		tmp %= MOD;
		tmp <<= 1;
		b >>= 1;

	}
	return res;
}

int main() {
	//freopen("in", "r", stdin);
	int n, m, i;
	LL res, cnt;
	while(scanf("%d%d", &n, &m) != EOF) {
		res = Pow(2, m, MOD) - 1;
		cnt = res;
		for( i=1; i<=n-1; i++ ) {
			res = res * ((cnt - i) % MOD) % MOD;
		}
		printf("%I64d\n", res);
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <stdio>
using namespace std;

const
 int o = 1000000009;

long int bin (long int m)
{
     long int k=2, r=1;
     while (m>1)
     {
           if (m % 2)
           {
                  r*=2;
                  r%=o;
                  m--;
                  }
           else
           {
               m/=2;
               k*=k;
               k%=o;
               }
               }
     return (r*k) % o;
     }

int main ()
{
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    long int n, m, p;
    scanf ("%d%d", &n, &m);
    p=bin (m);
    if ((m<17) & (n>=p))
    {
              printf ("%c", '0');
              return 0;
              }
    if (p>n)
    {
            long long int q=1;
            for (long int j=1; j<=n; j++)
            {
                q*=--p;
                q%=o;
            }
            printf ("%d", q);
            }
    else printf ("%c", '0');
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MOD = 998244353;
const int N = 5043;

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

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

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

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

int n, m, k;

int dp[N][N];

int main()
{
	cin >> n >> m >> k;
	dp[0][0] = 1;
	for(int i = 0; i < k; i++)
		for(int j = 0; j < k; j++)
		{
			dp[i + 1][j] = add(dp[i + 1][j], mul(dp[i][j], j));
			dp[i + 1][j + 1] = add(dp[i + 1][j + 1], mul(dp[i][j], n - j));
		}
	int ans = 0;
	for(int i = 1; i <= k; i++)
		ans = add(ans, mul(dp[k][i], binpow(inv(m), i)));
	cout << ans << endl;
}#include<bits/stdc++.h>

using namespace std;

const int MOD = 998244353;
const int N = 5043;

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

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

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

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

int n, m, k;

int dp[N][N];

int main()
{
	cin >> n >> m >> k;
	dp[0][0] = 1;
	for(int i = 0; i < k; i++)
		for(int j = 0; j < k; j++)
		{
			dp[i + 1][j] = add(dp[i + 1][j], mul(dp[i][j], j));
			dp[i + 1][j + 1] = add(dp[i + 1][j + 1], mul(dp[i][j], n - j));
		}
	int ans = 0;
	for(int i = 1; i <= k; i++)
		ans = add(ans, mul(dp[k][i], binpow(inv(m), i)));
	cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 5005
int n,m,k,dp[N][N]={{1}};
const int mod=998244353;
int pown(int a,int b){
	int res=1,x=a%mod;
	while(b)res=(b&1)?res*x%mod:res,x=x*x%mod,b>>=1;
	return res;
}
signed main(){
	scanf("%lld%lld%lld",&n,&m,&k);
    for(int i=1;i<=k;i++)
        for(int j=1;j<=i;j++)
            dp[i][j]=(dp[i-1][j]*j+dp[i-1][j-1]*(n-j+1))%mod;
    int ans=0,cur=1,p=pown(m,mod-2);
    for(int i=0;i<=k;i++)
        ans=(ans+dp[k][i]*cur)%mod,cur=cur*p%mod;
    printf("%lld",ans);
}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include "competitive_helper.cpp"

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int f[5010][5010];
int n, m, k, p;

int quickmul(int x, int y) {
    int ret = 1, cur = x;
    while (y) {
        if (y & 1) {
            ret = (LL)ret * cur % mod;
        }
        cur = (LL)cur * cur % mod;
        y >>= 1;
    }
    return ret;
}

int dfs(int u, int v) {
    // x^v * (px+1-p)^(n-v)
    if (f[u][v] >= 0) {
        return f[u][v];
    }
    if (u == 0) {
        return 1;
    }
    if (v == 0) {
        // x * d/dx (px+1-p)^n = np * x * (px+1-p)^(n-1)
        return f[u][v] = (LL)n * p % mod * dfs(u - 1, 1) % mod;
    }
    else if (n - v == 0) {
        // x * d/dx x^n = n * x^n
        return f[u][v] = (LL)n * dfs(u - 1, n) % mod;
    }
    else {
        // x * d/dx x^v * (px+1-p)^(n-v) = v * x^v * (px+1-p)^(n-v) + (n-v)p * x^(v+1) * (px+1-p)^(n-v-1)
        return f[u][v] = ((LL)v * dfs(u - 1, v) % mod + (LL)(n - v) * p % mod * dfs(u - 1, v + 1) % mod) % mod;
    }
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    cin >> n >> m >> k;
    p = quickmul(m, mod - 2);
    memset(f, -1, sizeof(f));
    cout << dfs(k, 0) << endl;
    return 0;
}


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

typedef long long LL;

const int K = 5005, M = 998244353;
int dp[K][K];

LL power(LL a, LL p) {
    LL ans = 1;
    while (p) {
        if (p&1)    ans = (ans * a)%M;
        a = (a*a)%M;
        p>>=1;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);

    cin.tie(0);
    dp[0][0] = 1;

    int n, m, k;
    cin>>n>>m>>k;

    for (int i=1; i<=k; i++) {
        for (int j=0; j<i; j++) {
            dp[i][j] += 1LL*dp[i-1][j]*j)%M;
            dp[i][j+1] += 1LL*dp[i-1][j]*(n-j);
        }
        for (int j=0; j<=i; j++) dp[i][j] %= M;
    }

    int pr = 1, b = power(m, M-2), ans = 0;
    for (int i=1; i<=k; i++) {
        pr = (1LL*pr * b)%M;
        ans = (ans + pr*dp[k][i])%M;
    }
    cout<<ans<<endl;
}


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

template <typename T> inline bool read (T &x) {
	x = 0; int f = 1; char c = getchar ();
	for (; c != EOF && !isdigit (c); c = getchar ())
		if (c == '-') f = -1;
	if (c == EOF) return 0;
	for (; c != EOF && c >= '0' && c <= '9'; c = getchar ())
		x = (x<<1) + (x<<3) + (c^48);
	x *= f; return 1;
}
template <typename T, typename ...Targs>
inline bool read (T &x, Targs& ... args) {
	return read (x) && read (args...); }
template <typename T> void print (T x) {
	if (x < 0) putchar ('-'), x = -x;
	if (x >= 10) print (x / 10);
	putchar (x % 10 + '0');
}
#define reint register int
#define inl inline
#define newl putchar('\n')
typedef long long ll;
typedef __int128 lll;
typedef pair <int, int> pint;

constexpr int N = 1e7 + 10, L = 720720, K = 18, P = 998244353;
int f[K][L], n, x, y, k, M, a[N], pown[K], ans, dimi, to;

inl int fpow (int a, int b) {
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1)
			res = 1ll * res * a % P;
		a = 1ll * a * a % P;
	}
	return res;
}

int main () {
	/*  */
	read (n, a[0], x, y, k, M);
	for (int i = 1; i < n; ++i)
		a[i] = (1ll * a[i - 1] * x + y) % M;
	for (int i = 0; i <= k; ++i)
		pown[i] = fpow (n, i);
	for (int i = 0; i < n; ++i)
		(ans += 1ll * k * pown[k - 1] % P * (a[i] / L * L) % P) %= P,
		a[i] %= L;
	for (int i = 0; i < n; ++i) ++f[0][a[i]];
	for (int kai = 0; kai < k - 1; ++kai)
		for (int i = 0; i < L; ++i)
			(f[kai + 1][i] += 1ll * (n - 1) * f[kai][i] % P) %= P,
			to = i - i % (kai + 1),
			(f[kai + 1][to] += f[kai][i]) %= P;
	for (int kai = 0; kai < k; ++kai)
		for (int i = 0; i < L; ++i)
			(ans += 1ll * f[kai][i] * i % P * pown[k - kai - 1] % P) %= P;
	print (ans);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Mod = 998244353;
int n, a[1100000], x, y, k, m;
int f[2][1100000], pw[1100000];

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

	cin >> n >> a[0] >> x >> y >> k >> m;
	for (int i = 1; i < n; i++)
		a[i] = (1ll * a[i - 1] * x + y) % m;

	int lcm = 1, now = 0;
	pw[0] = 1;
	for (int i = 1; i < k; i++)
		lcm = lcm / gcd(lcm, i) * i;
	for (int i = 1; i < k; i++)
		pw[i] = 1ll * pw[i - 1] * n % Mod;
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans = (ans + 1ll * (a[i] / lcm) * lcm % Mod * k % Mod * pw[k - 1]) % Mod, a[i] %= lcm;
	for (int i = 0; i < n; i++)
		f[now][a[i]]++;
	for (int j = 1; j <= k; j++) {
		now ^= 1;
		for (int i = 0; i < lcm; i++)
			f[now][i] = 0;
		for (int i = 0; i < lcm; i++) {
			f[now][i] = (f[now][i] + 1ll * f[now ^ 1][i] * (n - 1)) % Mod;
			f[now][i - i % j] = (f[now][i - i % j] + f[now ^ 1][i]) % Mod;
			ans = (ans + 1ll * f[now ^ 1][i] * i % Mod * pw[k - j]) % Mod;
		}
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int const M=800800,mod=998244353;
int i,j,n,a0,x,y,k,m,now,las=1,lcm=1,Ans,Pow[22],dp[2][M];
int read(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
	return x;
}
signed main(){
	n=read();a0=read();x=read();y=read();k=read();m=read();
	for (i=1;i<=k'';i++) lcm=lcm/__gcd(lcm,i)*i;
	for (i=Pow[0]=1;i<=k;i++) Pow[i]=Pow[i-1]*n%mod;
	for (i=1;i<=n;a0=(a0*x+y)%m,i++)
		(Ans+=Pow[k-1]*(a0/lcm*lcm)%mod*k%mod)%=mod,dp[0][a0%lcm]++;
	for (i=1;i<=k;i++){now^=1;las^=1;
		memset(dp[now],0,sizeof(dp[now]));
		for (j=1;j<lcm;j++)
			(dp[now][j/i*i]+=dp[las][j])%=mod,
			(dp[now][j]+=dp[las][j]*(n-1)%mod)%=mod,
			(Ans+=dp[las][j]*j%mod*Pow[k-i]%mod)%=mod;
	}
	return printf("%lld\n",Ans),0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 200005

const int FNCRLIMIT = MAXN;
long long fac[FNCRLIMIT], inf[FNCRLIMIT];
long long fncrmod = md;

void fillncr()
{
  #ifdef MOD
  fncrmod = MOD;
  #endif

  fac[0] = 1; inf[0] = 1;

  for(int i=1; i<FNCRLIMIT; i++)  {
    fac[i] = (fac[i-1]*(i))%fncrmod;
    inf[i] = expMod(fac[i], fncrmod-2, fncrmod);
  }
}

long long ncr(int n, int r)
{
  if(n<r) return 0;
  return (((fac[n] * inf[r]) % fncrmod) * inf[n-r]) % fncrmod;
}

int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);
    fillncr();
    int n;
    cin>>n;
    cout<<(md+ncr(2*n-1,n)-n)%md<<"\n";
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

int main ()
{
	int n;
	double a=1,b,c;
	long long d;
	cin >> n;
	b=n+1;
	c=1;
	for (int i=1; i<n; i++)
	{
		a*=b/c;
		b++;
		c++;
	}
	d=(long long) a;
	if (abs(d-a)<0.0001) d++;
	//d%=1000000007;
	d=2*d-n;
	d=((d%1000000007)+1000000007)%1000000007;
	cout << d;
}


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

void extgcd(int a,int b,int &d,int &x,int &y)
{
	if(!b)
	{
d=a;	x=1;	y=0;
	}
	else
	{
extgcd(b,a%b,d,y,x);
		y-=x*(a/b);
	}
}

int mod(int x,int n)
{
	return (x%n+n)%n;
}
int inv(int a,int n)
{
	int d,x,y;
	extgcd(a,n,d,x,y);
	return d==1 ? mod(x,n) : -1;
}

long long fact(int n)
{
	int i;
	long long res = 1;
	for(i = 1;i <= n;i++)
		res = (i * res) % MOD;
	return res;
}

// C(2n -1 , n);
long long cal(int n)
{
	long long res;
	res = fact(2 * n - 1);
	res = (res * inv(fact(n), MOD)) % MOD;
	res = (res * inv(fact(n - 1), MOD)) % MOD;
	return res;
}

int main()
{
	int n;
	long long res;
	scanf("%d", &n);
	res = cal(n);
	printf("%I64d\n", 2 * res - n);
	return 0;
}


#include <fstream>

using namespace std;

typedef long long LL;

inline LL pow(LL x, LL y, LL mod)
{
	LL ans = 1;
	for(; y; y >>= 1, x = (x*x)%mod)
		if(y & 1)
			ans = (ans*x) % mod;
	return ans % mod;
}

const LL mod = 1000000007;
const int maxn = 100005;

LL fac[maxn<<1];

int main()
{
	LL n;
	cin>>n
	fac[0] = 1;
	for(int i = 1; i <= (n<<1); ++i)
		fac[i] = fac[i-1] * i % mod;
	fout << (fac[n<<1]* pow(fac[n]*fac[n]%mod, mod-2, mod)) % mod - n << endl;
	return 0;
}


program Round220_C;

const INF=100000000;
 MAXN=100500;

var tree:Array[1..4*MAXN]of record l,r,ls,rs,min1,min2:longint;end;
 a,b,apos:Array[1..MAXN]of longint;
 n,i,p1,p2,ans,tot:longint;

function buildtree(l,r:longint):longint;
var mid,cur:longint;
begin
 inc(tot);
 cur:=tot;
 tree[cur].l:=l; tree[cur].r:=r;
 tree[cur].min1:=INF;
 tree[cur].min2:=INF;
 if (l=r) then exit(cur);
 mid:=(l+r)shr 1;
 tree[cur].ls:=buildtree(l,mid);
 tree[cur].rs:=buildtree(mid+1,r);
    exit(cur);
end;

procedure addtree(x,l,r,cul,v:longint);
var mid:longint;
begin
 if (l>2) then exit;
 if (l<=tree[x].l)and(tree[x].r<=r) then begin
  if (cul=1)and(v<tree[x].min1) then tree[x].min1:=v;
  if (cul=-1)and(v<tree[x].min2) then tree[x].min2:=v;
  exit;
 end;
 mid:=(tree[x].l+tree[x].r)shr 1;
 if l<=mid then addtree(tree[x].ls,l,r,cul,v);
 if mid+1<=r then addtree(tree[x].rs,l,r,cul,v);
end;

function find(x,p,cul:longint):longint;
var mid,rt,nx:longint;
begin
 if cul=1 then rt:=tree[x].min1 else rt:=tree[x].min2;
 if (tree[x].l=tree[x].r) then exit(rt);
 mid:=(tree[x].l+tree[x].r)shr 1;
 if p<=mid then nx:=find(tree[x].ls,p,cul) else nx:=find(tree[x].rs,p,cul);
 if nx<rt then rt:=nx;
 exit(rt);
end;

begin
 readln(n);
 for i:=1 to n do read(a[i]);
 readln;
 for i:=1 to n do read(b[i]);
 readln;
 tot:=0;
 buildtree(1,n);
 for i:=1 to n do apos[a[i]]:=i;
 for i:=1 to n do begin
  p1:=i;
  p2:=apos[b[i]];
  if p1<p2 then begin
   addtree(1,1,p2-p1,-1,p2-p1+1);
   addtree(1,p2-p1+1,n-p1+1,1,-p2+p1-1);
   addtree(1,n-p1+2,n,-1,n+p2-p1+1);
  end else begin
   addtree(1,1,n-p1+1,1,p1-p2-1);
   addtree(1,n-p1+2,n-p1+1+p2,-1,n-p1+1+p2);
   addtree(1,n-p1+2+p2,n,1,p1-p2-1-n);
  end;
 end;
 for i:=1 to n do begin
  p1:=i+find(1,i,1);
  p2:=-i+find(1,i,-1);
  if p1<p2 then ans:=p1 else ans:=p2;
  writeln(ans);
 end;
end.


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long Int;
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define sz(s) (int)s.size()
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
const int inf=1000000000;
const int MOD=1000000007;
const double pi=2*acos(0.0);
const double eps=1e-12;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int gcd(int x,int y)
{
    while(x){y%=x;swap(x,y);}
    return y;
}

inline void add(int &x,int y)
{
    x+=y;
    if(x>=MOD)x-=MOD;
}
inline void subt(int &x,int y)
{
    x=x+MOD-y;
    if(x>=MOD)x-=MOD;
}

int C[4002][4];
int cnt[2][2];

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;

    FOR(i,0,4001)
    FOR(j,0,3)
        if(i==j || j==0)C[i][j]=1;else C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

    memset(cnt,0,sizeof(cnt));
    FOR(i,0,n)FOR(j,0,m)cnt[i%2][j%2]++;

    int ans=0;
    FOR(x1,0,1)
    FOR(x2,0,1)
    FOR(x3,0,1)
    FOR(y1,0,1)
    FOR(y2,0,1)
    FOR(y3,0,1)
    if(2*x1+y1>=2*x2+y2 && 2*x2+y2>=2*x3+y3)
    {
        int d=(x2-x1)*(y3-y1)-(y2-y1)*(x3-x1);
        if(abs(d)%2==0)

            int tmp=1;
            tmp=tmp*(Int)cnt[x1][y1];tmp%=MOD;cnt[x1][y1]--;
            tmp=tmp*(Int)cnt[x2][y2];tmp%=MOD;cnt[x2][y2]--;
            tmp=tmp*(Int)cnt[x3][y3];tmp%=MOD;cnt[x3][y3]--;

            add(ans,tmp);
            cnt[x1][y1]++;
            cnt[x2][y2]++;
            cnt[x3][y3]++;
        }
    }

    FOR(i,0,n)subt(ans,(6LL*C[m+1][3])%MOD);
    FOR(i,0,m)subt(ans,(6LL*C[n+1][3])%MOD);

    FOR(dx,1,n)
    FOR(dy,1,m)
    {
        int g=gcd(dx,dy);
        int tmp=(Int(n+1-dx)*(m+1-dy))%MOD;
        tmp=(tmp*Int(g-1))%MOD;
        tmp=(tmp*12LL)%MOD;
        subt(ans,tmp);
    }

    cout<<ans<<endl;
}