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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};

template<class T> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
int pct(int x) { return __builtin_popcount(x); }
int bit(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0

// INPUT
template<class A> void re(complex<A>& c);
template<class A, class B> void re(pair<A,B>& p);
template<class A> void re(vector<A>& v);
template<class A, size_t SZ> void re(array<A,SZ>& a);

template<class T> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }

template<class A> void re(complex<A>& c) { A a,b; re(a,b); c = {a,b}; }
template<class A, class B> void re(pair<A,B>& p) { re(p.f,p.s); }
template<class A> void re(vector<A>& x) { trav(a,x) re(a); }
template<class A, size_t SZ> void re(array<A,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
template<class A, class B> str ts(pair<A,B> p);
template<class A> str ts(complex<A> c) { return ts(mp(c.real(),c.imag())); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(char c) { str s = ""; s += c; return s; }
str ts(str s) { return s; }
str ts(const char* s) { return (str)s; }
str ts(vector<bool> v) {
	bool fst = 1; str res = "{";
	F0R(i,sz(v)) {
		if (!fst) res += ", ";
		fst = 0; res += ts(v[i]);
	}
	res += "}"; return res;
}
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
template<class T> str ts(T v) {
	bool fst = 1; str res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += ts(x);
	}
	res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
	return "("+ts(p.f)+", "+ts(p.s)+")"; }

// OUTPUT
template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) {
	pr(h); pr(t...); }
void ps() { pr("\n"); } // print w/ spaces
template<class H, class... T> void ps(const H& h, const T&... t) {
	pr(h); if (sizeof...(t)) pr(" "); ps(t...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

// FILE I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	// cin.exceptions(cin.failbit);
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

/**
 * Description: modular arithmetic operations
 * Source:
	* KACTL
	* https://codeforces.com/blog/entry/63903
	* https://codeforces.com/contest/1261/submission/65632855 (tourist)
	* https://codeforces.com/contest/1264/submission/66344993 (ksun)
 * Verification:
	* https://open.kattis.com/problems/modulararithmetic
 */

struct mi {
	typedef decay<decltype(MOD)>::type T;
 	/// don't silently convert to T
	T v; explicit operator T() const { return v; }
	mi() { v = 0; }
	mi(ll _v) {
		v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
		if (v < 0) v += MOD;
	}
	friend bool operator==(const mi& a, const mi& b) {
		return a.v == b.v; }
	friend bool operator!=(const mi& a, const mi& b) {
		return !(a == b); }
	friend bool operator<(const mi& a, const mi& b) {
		return a.v < b.v; }
	friend void re(mi& a) { ll x; re(x); a = mi(x); }
	friend str to_string(mi a) { return to_string(a.v); }

	mi& operator+=(const mi& m) {
		if ((v += m.v) >= MOD) v -= MOD;
		return *this; }
	mi& operator-=(const mi& m) {
		if ((v -= m.v) < 0) v += MOD;
		return *this; }
	mi& operator*=(const mi& m) {
		v = (ll)v*m.v%MOD; return *this; }
	mi& operator/=(const mi& m) { return (*this) *= inv(m); }
	friend mi pow(mi a, ll p) {
		mi ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	friend mi inv(const mi& a) { assert(a.v != 0);
		return pow(a,MOD-2); }

	mi operator-() const { return mi(-v); }
	mi& operator++() { return *this += 1; }
	mi& operator--() { return *this -= 1; }
	friend mi operator+(mi a, const mi& b) { return a += b; }
	friend mi operator-(mi a, const mi& b) { return a -= b; }
	friend mi operator*(mi a, const mi& b) { return a *= b; }
	friend mi operator/(mi a, const mi& b) { return a /= b; }
};
typedef vector<mi> vmi;
typedef pair<mi,mi> pmi;
typedef vector<pmi> vpmi;

vector<vmi> comb;
void genComb(int SZ) {
	comb.assign(SZ,vmi(SZ)); comb[0][0] = 1;
	FOR(i,1,SZ) F0R(j,i+1)
		comb[i][j] = comb[i-1][j]+(j?comb[i-1][j-1]:0);
}

/**
 * Description: Use in place of \texttt{complex<T>}.
 * Source: http://codeforces.com/blog/entry/22175, KACTL
 * Verification: various
 */

typedef ll T;
int sgn(T a) { return (a>0)-(a<0); }
T sq(T a) { return a*a; }

namespace Point {
	typedef pair<T,T> P; typedef vector<P> vP;
	T norm(const P& p) { return sq(p.f)+sq(p.s); }
	T abs(const P& p) { return sqrt(norm(p)); }
	T arg(const P& p) { return atan2(p.s,p.f); }
	P conj(const P& p) { return P(p.f,-p.s); }
	P perp(const P& p) { return P(-p.s,p.f); }
	P dir(T ang) { return P(cos(ang),sin(ang)); }

	P operator-(const P& l) { return P(-l.f,-l.s); }
	P operator+(const P& l, const P& r) {
		return P(l.f+r.f,l.s+r.s); }
	P operator-(const P& l, const P& r) {
		return P(l.f-r.f,l.s-r.s); }
	P operator*(const P& l, const T& r) {
		return P(l.f*r,l.s*r); }
	P operator*(const T& l, const P& r) { return r*l; }
	P operator/(const P& l, const T& r) {
		return P(l.f/r,l.s/r); }
	P operator*(const P& l, const P& r) {
		return P(l.f*r.f-l.s*r.s,l.s*r.f+l.f*r.s); }
	P operator/(const P& l, const P& r) {
		return l*conj(r)/norm(r); }
	P& operator+=(P& l, const P& r) { return l = l+r; }
	P& operator-=(P& l, const P& r) { return l = l-r; }
	P& operator*=(P& l, const T& r) { return l = l*r; }
	P& operator/=(P& l, const T& r) { return l = l/r; }
	P& operator*=(P& l, const P& r) { return l = l*r; }
	P& operator/=(P& l, const P& r) { return l = l/r; }

	P unit(const P& p) { return p/abs(p); }
	T dot(const P& a, const P& b) { return a.f*b.f+a.s*b.s; }
	T cross(const P& a, const P& b) { return a.f*b.s-a.s*b.f; }
	T cross(const P& p, const P& a, const P& b) {
		return cross(a-p,b-p); }
	P reflect(const P& p, const P& a, const P& b) {
		return a+conj((p-a)/(b-a))*(b-a); }
	P foot(const P& p, const P& a, const P& b) {
		return (p+reflect(p,a,b))/(T)2; }
	bool onSeg(const P& p, const P& a, const P& b) {
		return cross(a,b,p) == 0 && dot(p-a,p-b) <= 0; }
	ostream& operator<<(ostream& os, const P& p) {
		return os << "(" << p.f << "," << p.s << ")"; }
};
using namespace Point;

int n,par[101],depth[101];
P pos[201];
mi dp[101], childProd[101];
vi adj[101];

bool ccw(int a, int b, int c) {
	return cross(pos[a],pos[b],pos[c]) >= 0; } // OK

vi tot;
void genChild(int x) { // OK
	tot.pb(x);
	trav(t,adj[x]) genChild(t);
}

vi path(int a, int b) {
	int _a = a, _b = b;
	vi x, y;
	while (a != b) {
		if (depth[a] > depth[b]) {
			x.pb(a);
			a = par[a];
		} else {
			y.pb(b);
			b = par[b];
		}
	}
	reverse(all(y));
	x.pb(a); x.insert(end(x),all(y));
	// dbg("??",_a,_b,x);
	return x;
} // OK

bool bet(P a, P b, P c) {
	if (cross(a,c) > 0) {
		return cross(a,b) > 0 && cross(b,c) > 0;
	}
	return cross(a,b) > 0 || cross(b,c) > 0;
}

mi get(int a, int b, int c) {
	mi prod = 1;
	trav(t,adj[b]) {
		if (t == a || t == c) continue;
		if (bet(pos[a]-pos[b],pos[t]-pos[b],pos[c]-pos[b])) {
			//ps("WUT",a,b,c,t);
			prod *= dp[t];
		}
	}
	return prod;
}

mi val(int x, int y) {
	if (x == y) return 0; // OK
	vi v = path(x,y); // OK
	trav(t,v) if (!ccw(x,y,t)) return 0; // OK
	mi prod = 1; trav(t,adj[x]) if (t != v[1]) prod *= dp[t];
	FOR(i,1,sz(v)-1) prod *= get(v[i-1],v[i],v[i+1]);
	// dbg("VAL",x,y,prod);
	return prod;
}

mi nex[201][201];
mi lo[201][201], hi[201][201];
vi TMP[201];

mi dumb(vi c) {
	// return 0;
	F0R(i,sz(c)) {
		vector<pair<P,int>> tmp;
		F0R(j,sz(c)) if (pos[c[i]] != pos[c[j]]) {
			if (j < i) tmp.pb({pos[c[i]]-pos[c[j]],j});
			else tmp.pb({pos[c[j]]-pos[c[i]],j});
		}
		sort(all(tmp),[](pair<P,int> x, pair<P,int> y) {
			return cross(x.f,y.f) > 0; });
		TMP[i].clear(); trav(t,tmp) TMP[i].pb(t.s);
	}
	trav(a,c) trav(b,c) lo[a][b] = hi[a][b] = 0;
	mi res = 0;
	F0R(i,sz(c)) {
		mi LO = (i == 0);
		trav(t,TMP[i]) {
			if (t < i) LO += lo[t][i];
			else lo[i][t] = nex[c[i]][c[t]]*LO;
		}
		reverse(all(TMP[i]));
		mi HI = (i == 0);
		trav(t,TMP[i]) {
			if (t < i) HI += hi[t][i];
			else hi[i][t] = nex[c[t]][c[i]]*HI;
		}
		if (i) res += LO*HI;
	}
	//dbg("RESULT",c,res);
	return res;
}

int makeEd(int a, int b) {
	assert(abs(depth[a]-depth[b]) == 1);
	if (depth[a] < depth[b]) return b;
	return a+n;
}

mi deal(vi c, int a) {
	auto _c = c;
	vi verts; trav(x,c) verts.pb(x), verts.pb(x+n);
	trav(x,verts) trav(y,verts) nex[x][y] = 0;
	// return 0;
	// val[x,y] for all good pairs
	trav(x,c) trav(y,c) {
		mi z = val(x,y); if (!ccw(x,y,a)) z = 0;
		if (z == 0) continue;
		vi v = path(x,y);
		nex[makeEd(v[1],x)][makeEd(v[sz(v)-2],y)] = z;
	}
	mi res = 0;
	sort(all(verts),[&](int x, int y) { return pos[x] < pos[y]; });
	while (sz(verts) > 1) {
		res += dumb(verts);
		verts.erase(begin(verts));
	}
	// dbg("DEAL",_c,a,res);
	return res;
}

void dfs(int a) {
	childProd[a] = 1;
	trav(t,adj[a]) dfs(t), childProd[a] *= dp[t];
	dp[a] = childProd[a];
	tot.clear(); genChild(a);
	dp[a] += deal(tot,a);
	trav(t,adj[a]) {
		tot.clear(); genChild(t);
		dp[a] -= deal(tot,a);
	}
	// dbg(a,dp[a],adj[a]);
}

void genDepth(int x) {
	trav(t,adj[x])  {
		par[t] = x; depth[t] = depth[x]+1;
		pos[t+n] = pos[x];
		adj[t].erase(find(all(adj[t]),x));
		genDepth(t);
	}
}

int main() {
	setIO(); re(n);
	FOR(i,1,n+1) re(pos[i]);
	F0R(i,n-1) {
		int a,b; re(a,b);
		adj[a].pb(b), adj[b].pb(a);
	}
	genDepth(1); dfs(1);
	ps(dp[1]);
	// you should actually read the stuff at the bottom
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


#include <iostream>
#include <math.h>
#include <cstring>
#define ll long long int
using namespace std;

const int MAXN = 1e5+2;
ll dp[MAXN][4];

ll comb(int n, int k){
    if(k==n||k==0) return 1;
    if(k>n) return 0;
    if(dp[n][k]>0) return dp[n][k];
    ll ans = comb(n-1,k-1) + comb(n-1,k);
    return dp[n][k]=ans;
}

ll func(int a,int b,int c,int l){
    ll ans = 0;
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,a+l1-b-c);
        ans+= comb(k+2,2);
    }
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,b+l1-a-c);
        ans+= comb(k+2,2);
    }
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,c+l1-b-a);
        ans+= comb(k+2,2);
    }
    return ans;
}
void init(){
    for(int i = 0;i<1e5+5;i++)
        for(int j = 0;j<5;j++)
            dp[i][j] = -1;
}
int main() {
    int a,b,c,l;
    scanf("%d %d %d %d",&a,&b,&c,&l);
    init();
    ll total = comb(l+3,3);
    ll ans = func(a,b,c,l);
    printf("%lld\n",total - ans);
    return 0;
}


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

const int MAXN = 1e5+2;
int dp[MAXN][4];

int comb(int n, int k){
    if(k==n||k==0) return 1;
    if(k>n) return 0;
    if(dp[n][k]>0) return dp[n][k];
    int ans = comb(n-1,k-1) + comb(n-1,k);
    return dp[n][k]=ans;
}

int func(int a,int b,int c,int l){
    int ans = 0;
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,a+l1-b-c);
        ans+= comb(k+2,2);
    }
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,b+l1-a-c);
        ans+= comb(k+2,2);
    }
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,c+l1-b-a);
        ans+= comb(k+2,2);
    }
    return ans;
}

int main() {
    int a,b,c,l;
    scanf("%d %d %d %d",&a,&b,&c,&l);
    memset(dp, -1, (l+100)*(l+100)*sizeof(dp[0][0]));
    int total = comb(l+3,3);
    int ans = func(a,b,c,l);
    printf("%d\n",total - ans);
    return 0;
}


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

const int MAXN = 1e3+2;
int dp[MAXN][MAXN];

int comb(int n, int k){
    if(k==n||k==0) return 1;
    if(k>n) return 0;
    if(dp[n][k]>0) return dp[n][k];
    int ans = comb(n-1,k-1) + comb(n-1,k);
    return dp[n][k]=ans;
}

int func(int a,int b,int c,int l){
    int ans = 0;
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,a+l1-b-c);
        ans+= comb(k+2,2);
    }
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,b+l1-a-c);
        ans+= comb(k+2,2);
    }
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,c+l1-b-a);
        ans+= comb(k+2,2);
    }
    return ans;
}

int main() {
    int a,b,c,l;
    scanf("%d %d %d %d",&a,&b,&c,&l);
    memset(dp, -1, (l+100)*(l+100)*sizeof(dp[0][0]));
    int total = comb(l+3,3);
    int ans = func(a,b,c,l);
    printf("%d\n",total - ans);
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define max(a,b) a>b?a:b
using namespace std;
int ans,jc[1000001];
int C(int a,int b){
	if(a<b)return 0;
	return jc[a]/jc[a-b]/jc[b];
}
void work(int a,int b,int c,int l){
	for(int i=max(0,a+b-c);i<=l;i++){
		int tmp=min(l-i,c+i-a-b);
		ans-=C(tmp+2,2);
	}
}
main(){
	jc[0]=1;
	for(int i=1;i<=1000000;i++){
		jc[i]=jc[i-1]*i;
	}
	int a,b,c,l;
	cin>>a>>b>>c>>l;
	ans+=C(l+3,3);
	work(a,b,c,l);
	work(a,c,b,l);
	work(b,c,a,l);
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
ull power(ull a,ull n)
{
     ull z=power(a,n/2);
     if(n%2==0)
     {
          return z*z;
     }
     else
     {
          return z*z*a;
     }
}
int main()
{
     ios_base::sync_with_stdio(0);
	ull n;

	cin >> n;
	cout << 2*(power(2,n)-1);
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <stack>
using namespace std;
vector<int> v;
int main(){
	int n;
	cin>>n;
	int ans=0;
	long long s=1;
	queue<string> q;
	if (n==1){
		cout<<2;
		return 0;
	}
	q.push("0");
	q.push("7");
	q.push("8");
	int k1=3;
	while (!q.empty()){
		int s=q.front().size();
		int k=k1;
		k1=0;
		for (int i=0;i<k;i++){
			string c;
			if (q.front()[s-1]=='0'){

				c=q.front()+"0";
				if (c.size()==n)
					if (c[c.size()-1]!='0')
						ans++;
				if (c.size()!=n){
					q.push(c);
					k1++;
				}
			}
				c=q.front()+"7";
				if (c.size()==n)
					ans++;
				else{
					q.push(c);
					k1++;
				}

				c=q.front()+"8";
				if (c.size()==n)
					ans++;
				else{
					q.push(c);
					k1++;
				}
				q.pop();
			}

	}
	cout<<ans;
}


#include <iostream>
#include <string>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <map>
#include <stack>
#include <locale>
#include <set>
#include <functional>
#include <algorithm>
#define pb push_back
#define mp(x,y) make_pair(x,y)
#define SS stringstream
#define ll long long
#define lop(i,v) for (int i = 0; i < v; i++)
#define lop_start(j,v) for (int i = j; i < v; i++)

using namespace std;
vector<string> v; int n;
void lucky(string r=""){
	if(r.length() > n) return;
	if(r != "") v.push_back(r);
	lucky(r+"7");
	lucky(r+"8");
}
int main(){
    ios::sync_with_stdio(false);
	cin>>n; int counter = 0, i=0;
	lucky();
	while( i<v.size() && v[i].length() <= n){
		counter++;
		i++;
	}
	cout<<counter<<endl;
}


#include<iostream>
#include<string>
#include<math.h>
#include<map>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
string s1, s2;
map<char, char>mp;
vector<ll>luky;
ll m;
ll sum = 0;
ll lulu(int n , int i )
{

	if (i > m ) return 0;
	if (n)
	{
		luky.push_back(n);
		sum++;

	}
		lulu(n * 10 + 7, i + 1);
		lulu(n * 10 + 8, i + 1);

	return sum;
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> m;
	cout << lulu(0, 0);
	return  0;
}


#include <iostream>
#include <string>
#include<conio.h>

using namespace std;

bool modifier(string in);
string convert(string in);

int main ()
{
  string caps;
  getline (cin,caps);
  if(modifier(caps))
  caps=convert(caps);
  cout<<caps;
  getch();
}
int le;
bool modifier(string in)
{
     for(le=1;le<in.length();le++)
     {
         if(!(in.substr(le,1)>="A" && in.substr(le,1)<="Z"))
         {
                return false;
           }
     }
     return true;

}
int len;
string convert(string in)
{
     for(len=0;len<in.length();len++){
            if (in[len] >= 'A' && in[len] <= 'Z')
               in[len]-= ('A'-'a');
            else if(in[len] >= 'a' && in[len] <= 'z')
               in[len]-= ('a'-'A');
     }
     return in;
}


#include <bits/stdc++.h>
#define int long long
#define double long double

typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<vvi> vvvi;
typedef std::vector<vvvi> vvvvi;
typedef std::vector<std::string> vs;
typedef std::vector<bool> vb;
typedef std::vector<vb> vvb;
typedef std::vector<double> vd;
typedef std::vector<vd> vvd;
typedef std::pair<int, int> pii;
typedef std::vector<pii> vpii;
typedef std::vector<vpii> vvpii;
using ull = unsigned long long;

using namespace std;

constexpr int mod = 1e9 + 7, p = 179;

int phi1 (int n)
{
    int result = n;
    for (int i = 2; i * i <= n; ++i)
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    if (n > 1)
        result -= result / n;
    return result;
}

int gcd (int a, int b) {
    while (b)
    {
        a %= b;
        swap(a, b);
    }
    return a;
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

int solve()
{
    int n;
    cin >> n;
    vi phi(n + 1, 0);
    for (int i = 1; i <= n; ++i)
    {
        phi[i] = phi1(i);
    }
    int ans = 0;
    for (int c = 1; c < n - 1; ++c)
    {
        int sum = n - c;
        for (int d = 1; d * d <= sum; ++d)
        {
            if (sum % d == 0)
            {
                if (d * d == sum || d == 1)
                {
                    ans = (ans + lcm(c, d) * phi[sum / d]) % mod;
                }
                else
                {
                    ans = (ans + lcm(c, d) * phi[sum / d]) % mod;
                    ans = (ans + lcm(c, sum / d) * phi[d]) % mod;
                }
            }
        }
    }
    cout << ans << endl;
}

int32_t main()
{
    //ofstream cout("test.txt");
    //ifstream cin("joseph.in");
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cerr.tie(0);
    solve();
    //solve();
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;

ll powmod(ll a,ll b) {ll res=1; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int N = 500001;
vector<vector<int>> f(N, vi(200));
vector<int> cnt(N);

vector<int> phi;
void phi1_to_n(int n)
{
    phi.resize(n+1);
    for(int i = 0; i <= n; ++i ) phi[i] = i;

    for (int p=2; p<=n; ++p)
    {
        if (phi[p]==p)
        {
            for (int i=p; i<=n; i += p)
                phi[i] -= phi[i]/p;
        }
    }
}

void pre() {
    for(int i=1;i<N;++i)
        for(int j=i;j<N;j+=i)
            f[j][cnt[j]++] = i;
}

void solve() {
    int n; cin >> n;
    ll F = 0;
    for(int c=1;c<=n-2;++c) {
        int t = n - c;
        vl ans(t+1, 0);
        unordered_map<int,int> M;
        for(int i=cnt[t]-2;i>=0;--i) {
            int g = f[t][i];
            int ans = phi[t/g];
            // int ans = t/g - 1 - M[g];
            // for(int j=cnt[t]-2;j>=0;--j) M[f[g][j]] += ans;
            // ans = (ans%mod + mod)%mod;
            ll r = (c/gcd(c,g))*1ll*g;
            F = (F + r*1ll*ans%mod)%mod;
        }
    }
    cout << F << '\n';
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    phi1_to_n(N);
    pre();
    solve();
  return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include<numeric>
using namespace std;
long long mod = 1e9+7;
#define endl '\n'
#define ll long long
#define ull unsigned long long
const int N = 1e8+1;
int n,m;
vector<int>euler(N);

int lcm(int a,int b) {
    int gcd = __gcd(a,b);
    return 1ll*(a*b)/gcd;
}

void calcEuler() {
    for(int i=1;i<N;i++) euler[i]=i;
    for(int p=2;p<N;p++) {
        if(euler[p]==p) { //prime (remove it from all its multiples)
            euler[p]=p-1; //since it's prime, all the previous numbers are relatively prime to it
            for (int i = 2*p; i<N; i += p)
            {
                euler[i] -= (euler[i]/p); // remove all multiples of P from i
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    calcEuler();
    ll ans(0);
    for(int i=1; i<=n-2; i++) {  // iterating over all possible D
        for(int k=2*i; k<=n; k+=i) { // k is a+b
            int c = n - k;
            ans += 1ll*lcm(c,i)*euler[k/i]%mod;
            ans %= mod;
        }
    }
    cout<<ans;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;

ll powmod(ll a,ll b) {ll res=1; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int N = 500001;
vector<vector<int>> f(N, vi(200));
vector<int> cnt(N);

void pre() {
    for(int i=1;i<N;++i)
        for(int j=i;j<N;j+=i)
            f[j][cnt[j]++] = i;
}

void solve() {
    int n; cin >> n;
    ll F = 0;
    for(int c=1;c<=n-2;++c) {
        int t = n - c;
        vl ans(t+1, 0);
        unordered_map<int,int> M;
        for(int i=cnt[t]-1;i>=0;--i) {
            int g = f[t][i];
            int ans = t/g - 1 - M[g];
            for(int j=cnt[t]-2;j>=0;--j) M[f[g][j]] += ans;
            ans = (ans%mod + mod)%mod;
            ll r = (c/gcd(c,g))*1ll*g;
            F = (F + r*1ll*ans%mod)%mod;
        }
    }
    cout << F << '\n';
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    pre();
    solve();
  return 0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define FOR(I,A,B) for (int I=int(A);I<int(B);++I)
#define MEM(A,B) memset(A,B,sizeof(A))
#define CPY(A,B) memcpy(A,B,sizeof(B))
#define FIN(A) freopen(A, "r", stdin)
#define FOUT(A) freopen(A, "w", stdout)
typedef long long LL;
const int N(150), P(1000000007);
int mul(LL a, LL b) {
    return a * b % P;
}
int add(LL a, LL b) {
    return (a + b) % P;
}
int n, m;
int s[4][N][N];
int f[N][N][N][4];
int p[N][N][4];
int sum(int x, int l, int r) {
    if (l < 1 || l > n || r < 1 || r > n) return 0;
    if (s[x][l][r] != -1) return s[x][l][r];
    //cout << x << " " << l << " " << r << endl;
    int dl = x % 2 ? -1 : 1, dr = x / 2 ? 1 : -1;
    return s[x][l][r] = add(add(p[l][r][x], P - sum(x, l + dl, r + dr)), add(sum(x, l + dl, r), sum(x, l, r + dr)));
}
int main() {
    //freopen("in.txt", "r", stdin);
    cin >> n >> m;
    if (n < m) swap(n, m);
    FOR(l, 1, m + 1)
        FOR(r, l, m + 1)
            FOR(i, 0, 4)
                f[1][l][r][i] = 1;
    FOR(i, 1, n) {
        MEM(s, -1);
        CPY(p, f[i]);
        FOR(l, 1, m + 1)
            FOR(r, l, m + 1) {
                f[i + 1][l][r][0] = sum(0, l, r);
                f[i + 1][l][r][1] = add(sum(1, l, r) - sum(1, l - 1, l - 1) + P, sum(0, l + 1, r));
                f[i + 1][l][r][2] = add(sum(2, l, r) - sum(2, r + 1, r + 1) + P, sum(0, l, r - 1));
                if (l == 1 && r == 1) {
               //     cout << sum(3, l, r) << endl;
                }
                f[i + 1][l][r][3] = add(add(sum(3, l, r), sum(0, l + 1, r - 1)),
                                        add(sum(1, l, r - 1) - sum(1, l - 1, l - 1) + P, sum(2, l + 1, r) - sum(2, r + 1, r + 1) + P));
            }
    }
    int ans = 0;
    FOR(i, 1, n + 1)
        FOR(l, 1, m + 1)
            FOR(r, l, m + 1)
                ans = add(ans, mul(n - i + 1, f[i][l][r][3]));
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define rr int
using namespace std;
typedef long long ll;
inline ll read() {
    char i = getchar();
    ll f = 1, res = 0;
    while (i < '0' || i > '9') {
        if (i == '-') f = -1;
        i = getchar();
    }
    while (i >= '0' && i <= '9') {
        res = res * 10 + i - '0';
        i = getchar();
    }
    return res * f;
}
const int mod = 1000000007;
const int N = 105;
ll f[N][N][2][2];  // 左边界是否凸，右边界是否凸
int n, m;
inline void upd(ll &a, ll b) { a = (a + b) % mod; }
int main() {
    n = read(), m = read();
    for (rr i = 1; i <= m; ++i) {
        for (rr j = i; j <= m; ++j) {
            f[i][j][1][1] = 1;
        }
    }
    ll ans = 0;
    for (rr i = 1; i <= n; ++i) {
        ll res = 0;
        for (rr l = 1; l <= m; ++l)
            for (rr r = l; r <= m; ++r)
                for (rr kl = 0; kl <= 1; ++kl)
                    for (rr kb = 0; kb <= 1; ++kb)
                        res = (res + f[l][r][kl][kb]) % mod;
        ans = (ans + res * (n - i + 1)) % mod;
        for (rr l = 1; l <= m; ++l)
            for (rr r = l + 1; r <= m; ++r)
                for (rr kr = 0; kr <= 1;
                     ++kr) {  //前缀叠加 注意顺序 凹的时候另外一边凸凹都可以
                    upd(f[l + 1][r][0][kr], f[l][r][0][kr]);
                    upd(f[l + 1][r][0][kr], f[l][r][1][kr]);
                }
        for (rr l = 1; l <= m; ++l)
            for (rr r = m; r >= l + 1; --r)
                for (rr kl = 0; kl <= 1; ++kl) {
                    upd(f[l][r - 1][kl][0], f[l][r][kl][0]);
                    upd(f[l][r - 1][kl][0], f[l][r][kl][1]);
                }
        for (rr l = m; l >= 2; --l)
            for (rr r = l; r <= m; ++r)
                for (rr kr = 0; kr <= 1; ++kr) {
                    upd(f[l - 1][r][1][kr], f[l][r][1][kr]);
                }
        for (rr l = m; l >= 1; --l)
            for (rr r = l; r < m; ++r)
                for (rr kl = 0; kl <= 1; ++kl) {
                    upd(f[l][r + 1][kl][1], f[l][r][kl][1]);
                }
    }
    printf("%lld\n", ans);
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define FOR(I,A,B) for (int I=int(A);I<int(B);++I)
#define MEM(A,B) memset(A,B,sizeof(A))
#define CPY(A,B) memcpy(A,B,sizeof(B))
#define FIN(A) freopen(A, "r", stdin)
#define FOUT(A) freopen(A, "w", stdout)
typedef long long LL;
const int N(150), P(1000000007);
int mul(LL a, LL b) {
    return a * b % P;
}
int add(LL a, LL b) {
    return (a + b) % P;
}
int n, m;
int s[4][N][N];
int f[N][N][N][4];
int p[N][N][4];
int sum(int x, int l, int r) {
    if (l < 1 || l > m || r < 1 || r > m) return 0;
    if (s[x][l][r] != -1) return s[x][l][r];
    //cout << x << " " << l << " " << r << endl;
    int dl = x % 2 ? -1 : 1, dr = x / 2 ? 1 : -1;
    return s[x][l][r] = add(add(p[l][r][x], P - sum(x, l + dl, r + dr)), add(sum(x, l + dl, r), sum(x, l, r + dr)));
}
int main() {
    //freopen("in.txt", "r", stdin);
    cin >> n >> m;
    FOR(l, 1, m + 1)
        FOR(r, l, m + 1)
            FOR(i, 0, 4)
                f[1][l][r][i] = 1;
    FOR(i, 1, n) {
        MEM(s, -1);
        CPY(p, f[i]);
        FOR(l, 1, m + 1)
            FOR(r, l, m + 1) {
                f[i + 1][l][r][0] = sum(0, l, r);
                f[i + 1][l][r][1] = add(sum(1, l, r) - sum(1, l - 1, l - 1) + P, sum(0, l + 1, r));
                f[i + 1][l][r][2] = add(sum(2, l, r) - sum(2, r + 1, r + 1) + P, sum(0, l, r - 1));
               // if (l == 1 && r == 1) {
               //     cout << sum(3, l, r) << endl;
               // }
                f[i + 1][l][r][3] = add(add(sum(3, l, r), sum(0, l + 1, r - 1)),
                                        add(sum(1, l, r - 1) - sum(1, l - 1, l - 1) + P, sum(2, l + 1, r) - sum(2, r + 1, r + 1) + P));
            }
    }
    int ans = 0;
    FOR(i, 1, n + 1)
        FOR(l, 1, m + 1)
            FOR(r, l, m + 1)
                ans = add(ans, mul(n - i + 1, f[i][l][r][3]));
    cout << ans << endl;
    return 0;
}


// #include <God>
#include <iostream>
#include <cmath>
using namespace std;
const int MAXN = 1000000005;
bool mark[MAXN];
int main(){
    int a, b;
    int i = 2;
    cin >> a >> b;
    int ans = 0;
    int k = a - b;
    if(a == b){
        cout << "infinity" << '\n';
        return 0;
    }
    if(b == 0)
        ans++;
    while(i < sqrt(k))
    {
        if(k % i == 0) {
            if(i > b){
                ans++;
            }
            if(k / i > b)
                ans++;
        }
        i++;
    }
    ans++;
    if(i * i == k && i > b)
        ans++;
    cout << ans << " " << '\n';
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long  a,b,i,p=0;
   cin>>a>>b;
   if(a==b)
   {
       cout<<"infinity";
       return 0;
   }
   else if(a<b || b>floor(a/2.0))
   {
       cout<<0;
       return 0;
   }

   else
   {
       long f[a-b+1]={0};
       for(i=1;i*i<=a-b;i++)
       {
            if((a-b)%i==0)
            {
                f[i]=1;
                f[(a-b)/i]=1;
            }
       }
       for(i=b+1;i<=a-b;i++)
       {
           if(f[i])
           p++;
       }
       cout<<p;
   }

}


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

int main()
{
	long long a,b, k, cnt=0, j=0;
	cin>>a>>b;
	if(a==b)
		cout<<"infinity"<<endl;
	else{
	for(int i=a;i>=b;i--)
		if(a%i==b){
			k=i;
			cnt++;
			break;
		}

		long long *arr=new long long int[k/2];

		for(int i=k/2;i>=1;i--)
			if(k%i==0){
				arr[j]=i;
				j++;
			}

			for(int i=0;i<j;i++)
				if(a%arr[i]==b)
					cnt++;

		cout<<cnt<<endl;
	}

	return 0;
}


#include<iostream>
#include<conio.h>
#include<vector>
using namespace std;

int main()
{

 long long   int a[10],b,c,m=0;
cin>>b>>c;
if(b-c>c)
{

for(int i=c+1;i<=b-c;i++)
{if((b-c)%i==0)
m=m+1;

}
cout<<m;

}
else
cout<<"infinity";

getch();
return 0;

}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	int c=0, B=0, b=0, d=0,l,i;
	string str;
	cin >> str;
	l=str.length();
	if (l<100&&l>=5)
	{
		for (i = 0; i < l; i++)
		{
			if (str[i] >= '0'&&str[i] <= '9'){ d++; }
			else if (str[i] >= 'a'&&str[i] <= 'z'){ b++; }
			else if (str[i] >= 'A'&&str[i] <= 'Z'){ B++; }
			else{c++;}
		}
		if (B != 0 && b != 0 && d != 0) { cout << "Correct"; }
		else{ cout << "Too weak"; }
	}
	else
	{
		cout << "Too weak";
	}
	system("PAUSE");
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

void input(), output(), solve();

int n, c1 = 0, c2 = 0, c3 = 0;
string s;

int main()
{
	input(); solve(); output();
}

void input()
{
	freopen("a.inp", "r", stdin);
	freopen("a.out", "w", stdout);
	getline(cin, s);
}

void solve()
{
	int k;
	n= s.length();
	for (int i = 1; i != n; i++)
	{
		k = s[i];
		if ((k >= 65) && (k <= 90))
		{
			c1 = 1;
		}
		if ((k >= 48) && (k <= 57))
		{
			c2 = 1;
		}
		if ((k <= 122) && (k >= 97))
		{
			c3 = 1;
		}
	}
}

void output()
{
	if ((n >= 5) && (c1 + c2 + c3 == 3))
	{
		printf("%s\n", "Correct");
	}
	else
	{
		printf("%s\n", "Too weak");
	}
}


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

int main(){
	int a = 0, b = 0, c = 0;
	string s;
	getline(cin, s);
	for (int i = 0; i < s.length(); i++){
		if (isalpha(s[i]) && islower(s[i]))
			a++;
		else
			if (isalpha(s[i]) && isupper(s[i]))
				b++;
			else
				if (isdigit(s[i]))
					c++;
				else
					continue;
	}
	if ((s.length() >= 5) && (a >= 1) && (b >= 1) && (c >= 1))
		cout << "Correct" << endl;
	else
		cout << "Too weak" << endl;
	system("pause");
	return 0;
}


#include <iostream>
#include <locale>
#include <cctype>
void main()
{
    char string[100];
    int i,is,is1;
    for(;;)
    {
    std::cin.getline(string, sizeof(string),'\n');
    if (strlen(string)>4)
        {
            is=0;
            while ( string[i] )
            {
                if ( isalpha(string[i])){is=10;break;}
                else {i++;}
            }
            i=0;
            while ( string[i] )
            {
                if (isdigit(string[i])){ is1=10;break;}
                else {i++;}
            }
            if(is==10 && is1==10){std::cout<<"Correct "; break;}
            else std::cout<<"Too weak "<<std::endl;
        }
    else std::cout<<"Too weak ";
    }
    getchar();
}


#include<bits/stdc++.h>
#define up(j,k,i) for(i=j;i<k;i++)
#define down(j,k,i) for(i=j;i>k;i--)
#define M 900000
#define cool 0
typedef int l;
typedef float f;
typedef double d;
typedef long long int lld;
using namespace std;
lld bin[65];
lld ans[66][M];
void conv_binary(lld i)
{
bin[i]=bin[i/2]*10+i%2;
}
int main()
{
bin[1]=1;bin[2]=10;bin[3]=11;bin[4]=100;
lld n,i,k,start,j,min=M;
up(5,65,i)
{
conv_binary(i);
}
cin>>n;
ans[0][1]=1;
ans[1][1]=1;
ans[0][0]=0;
lld pos=0;
up(2,n+1,i)
{
j=1;
min=n+10;
while(i>=bin[j])
{
if(min>ans[0][i-bin[j]])
{
min=ans[0][i-bin[j]];
pos=j;
}
j++;
}
up(1,65,k)
ans[k][i]=ans[k][i-bin[pos]];
ans[0][i]=min+1;
ans[pos][i]=1+ans[pos][i];
}
cout<<ans[0][n]<<endl;
up(1,65,k)
{
if(ans[k][n]>=1)
{
while(ans[k][n]>=1)
{
cout<<bin[k]<<' ';
ans[k][n]--;
}
}
}
cout<<endl;
return cool;
}


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

int main(){

	/*string s;
	cin >> s;

	for (int i = 0; i < s.length(); i++){
		for (int j = 1; i+j <= s.length(); j++){
			string buf = s;
			buf.erase(i, j);
			if (buf == "CODEFORCES") {
				cout << "YES";
				return 0;
			}
		}
	}

	cout << "NO";*/

	int n;
	cin >> n;

	vector<int> v;

	for (int i = 1; i <= 1000000; i *= 10){
		int sz = v.size();
		v.push_back(i);

		for (int j = 0; j < sz; j++)
			v.push_back(i + v[j]);
	}

	sort(v.begin(),v.end());
	//for (int i = 0; i < v.size(); i++)
	//	cout << v[i] << endl;

	vector<int> ans;
	vector<int> best;
	int min = 99999;
	int i_start = v.size() - 1;
	i_start = 63;
	while (i_start >= 0){
		int i = i_start;
		int n_buf = n;
		ans.clear();

		while (n_buf > 0){

			while (v[i] > n_buf) i--;
			while (n_buf >= v[i]){
				n_buf -= v[i];
				ans.push_back(v[i]);
			}
		}
		if (ans.size() < min){
			best = ans;
			min = best.size();
		}

		i_start--;
	}

	cout << best.size()<<endl;

	for (int i = 0; i < best.size(); i++){
		cout << best[i];
		if (i != best.size() - 1) cout << " ";
	}

	//system("pause");
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
bool isBin(ll x)
{
    while(x>0)
    {
        if(x%10!=1&&x%10!=0)
            return false ;
        x /= 10 ;
    }
    return true ;
}

int main()
{
    ios_base::sync_with_stdio(0) ;
    vector<ll> allNums ;
    ll n ;
    cin >> n ;
    for(ll i=1;i<=n;i++)
    {
        if(isBin(i))
            allNums.push_back(i) ;
    }
    sort(allNums.rbegin(),allNums.rend()) ;
    ll mini= 1e9 ;
    vector<ll> res ;
    for(int i=0;i<allNums.size();i++)
    {
        ll sum = 0 ;
        vector<ll>temp ;
        for(int j=i;j<allNums.size();)
        {
            if(sum+allNums[j]<=n)
            {
                sum += allNums[j] ;
                temp.push_back(allNums[j]) ;
            }else
                j++ ;
            if(sum==n)
                break ;
        }
        if(temp.size()<mini)
        {
            mini = temp.size() ;
            res = temp ;
        }
    }
    cout << res.size() << endl ;
    for(int i=0;i<res.size();i++)
        cout << res[i] << " " ;
    return 0;
}


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

int main(){

	/*string s;
	cin >> s;

	for (int i = 0; i < s.length(); i++){
		for (int j = 1; i+j <= s.length(); j++){
			string buf = s;
			buf.erase(i, j);
			if (buf == "CODEFORCES") {
				cout << "YES";
				return 0;
			}
		}
	}

	cout << "NO";*/

	int n;
	cin >> n;

	vector<int> v;

	for (int i = 1; i <= 1000000; i *= 10){
		int sz = v.size();
		v.push_back(i);

		for (int j = 0; j < sz; j++)
			v.push_back(i + v[j]);
	}

	sort(v.begin(),v.end());
	//for (int i = 0; i < v.size(); i++)
	//	cout << v[i] << endl;

	vector<int> ans;
	vector<int> best;
	int min = 99999;
	int i_start = v.size() - 1;

	while (i_start >= 0){
		int i = i_start;
		int n_buf = n;
		ans.clear();

		while (n_buf > 0){

			while (v[i] > n_buf) i--;
			while (n_buf >= v[i]){
				n_buf -= v[i];
				ans.push_back(v[i]);
			}
		}
		if (ans.size() < min){
			best = ans;
			min = best.size();
		}

		i_start--;
	}

	cout << best.size()<<endl;

	for (int i = 0; i < best.size(); i++){
		cout << best[i];
		if (i != best.size() - 1) cout << " ";
	}

	//system("pause");
}


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

#define N 1000 * 1000 + 5
using namespace std;

int mask(int x)
{
	char s[N];
	char * ans = new char[N];
	memset(ans, 0, N);
	int ai = 0;
	snprintf(s, N, "%d", x);
	for (int i = 0; i < strlen(s); ++i)
	{
		if(s[i] == '4' || s[i] == '7')
			ans[ai++] = s[i];
	}
	return atoi(ans);
}

int main(){

	int a, b;
	cin >> a >> b;
	a++;
	while(mask(a) != b)
		a++;
	cout << a;
}


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

#define N 1000 * 100 + 5
using namespace std;

int mask(int x)
{
	char s[N];
	char * ans = new char[N];
	memset(ans, 0, N);
	int ai = 0;
	snprintf(s, N, "%d", x);
	for (int i = 0; i < strlen(s); ++i)
	{
		if(s[i] == '4' || s[i] == '7')
			ans[ai++] = s[i];
	}
	return atoi(ans);
}

int main(){

	int a, b;
	cin >> a >> b;
	a++;
	while(mask(a) != b)
		a++;
	cout << a;
}


#include <stdio.h>
#include <conio.h>
using namespace std;
int a,b;
int code(long unsigned int x )
{
int so=0;

   while(x/10>0)
   {
       int tam=x%10;
       if(tam==7 || tam==4) so=so*10+tam;
       x=x/10;
       }
   if(x==7 || x==4) so=so*10+x;
  int tam=0;
   while (so/10 >0)

   {
         tam=tam*10+so%10;
         so=so/10;
   }
      tam=tam*10+so;
     return(tam);
}

int process(){
   int i=0;
   while(code(a+i)!= b) i++;
   printf("%d",a+i);
}
int main(){
    scanf("%d%d",&a,&b);
    process();
    getch();
   	return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<limits.h>
#include<iostream>
#define MOD 1000000007
#include<conio.h>

using namespace std;

int main()
{
int a,b;

scanf("%d%d",&a,&b);
char str1[10],str2[10];
itoa(a,str1,10);
itoa(b,str2,10);

int len1=strlen(str1)-1;
int len2=strlen(str2)-1;

int i=0;
int j=0;

while((len1-i)>=(len2-j))
{
    if(str1[i]==str2[j])
    j++;

    i++;
}

int k=i-1;

while(j<=len2)
str1[k++]=str2[j++];

printf("\n%s",str1);

    getch();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define MOD 1000000007

ifstream fin(".in");

long long int k,i,urm,cur,total,rez,j,n,a,b,zile,p,q,x,ans;
double d;

long long int put( long long int x , long long int p )
{
    if( p == 1 )
        return x;
    long long int aux;
    aux = put( x , p / 2 ) % MOD;
    aux = aux * aux;
    aux = aux % MOD;
    if( p % 2 )
        aux = aux * x;
    aux = aux % MOD;
    return aux;
}

int main()
{

    ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        #define cin fin
    #else
        #define fin cin
    #endif

    cin>>a>>b>>n>>x;
    if( a == 1 )
    {
        ans = x + ( b * n % MOD ) % MOD;
        ans = ans % MOD;
        cout<<ans;
        return 0;
    }

    ans = put( a , n ) * x;
    ans = ans % MOD;
    k = ( b % MOD ) * ( put( a , n ) - 1 );
    k = k % MOD;
    k *= put( a - 1 , MOD - 2 );
    k = k % MOD;
    ans = ans + k;
    cout<<ans % MOD;

    return 0;
}


#include <stdio.h>

typedef unsigned long long ll;

const ll mod = 1e9 + 7;

ll pow(ll base, ll exp) {
  ll ret = 1, mul = base;
  while (exp) {
    if (exp & 1) {
      ret *= mul;
      ret %= mod;
    }
    mul *= mul;
    mul %= mod;
    exp >>= 1;
  }
  return ret;
}

ll modInv(ll base, ll m) {
  return pow(base, m - 2);
}

int main() {
  ll A, B, n, x;
  scanf("%llu%llu%llu%llu", &A, &B, &n, &x);
  if (A == 1) {
    printf("%llu\n", (x + n * B) % mod);
  } else {
    ll sol = ((pow(A, n) * x) % mod + (B * (((pow(A, n) - 1) * modInv(A - 1, mod)) % mod)) % mod) % mod;
    printf("%llu\n", sol);
  }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
int MOD = 1e9 + 7;
const ld E = 1e-8;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#ifndef LOCAL
#define endl "\n"
#endif
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define filesdatsol(x) _read(x ".DAT"); _write(x ".SOL")
#define output _write("output.txt")
#define input _read("input.txt")
#define mod % MOD
#define y1 hello_world
unsigned char ccc;
bool _minus = false;
inline void read(int &n) {
	n = 0;
	_minus = false;
	while (true) {
		ccc = getchar();
		if (ccc == ' ' || ccc == '\n')
			break;
		if (ccc == '-') {
			_minus = true;
			continue;
		}
		n = n * 10 + ccc - '0';
	}
	if (_minus)
		n *= -1;
}
char wwww[12];
int kkkk;
inline void write(int x) {
	kkkk = 0;
	if (!x)
		++kkkk, wwww[kkkk] = '0';
	else
		while (x) {
			++kkkk;
			wwww[kkkk] = char(x % 10 + '0');
			x /= 10;
		}
	for (int i = kkkk; i >= 1; --i)
		putchar(wwww[i]);
	putchar('\n');
}
template<typename T> inline T sqr(T t) {
	return t * t;
}
#ifdef LOCAL
//#define DEBUG
#endif

#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif

ll a, b, x, n;

inline ll next(ll x){
	return (x * a + b) mod;
}

ll solve_long(){
	ll x = ::x;
	for(int i = 0; i < n; i++)
		x = next(x);
	return x;
}

ll _pow(ll n, ll m){
	ll ans = (m == 0 ? 1 : m & 1 ? n * _pow(n, m - 1) : sqr(_pow(n, m >> 1))) % MOD;
	//cout << n << " " << m << " " << ans << endl;
	return ans;
}

ll solve_quick(){
	if(n == 0)
		return x;
	if(n == 1){
		return (x * a + b) % MOD;
	}
	if(a == 1){
		return (x + n * b) % MOD;
	}
	ll ans = (x * _pow(a, n)) % MOD;
	ll w = _pow(a, n) - 1;
	if(w < 0)
		w += MOD;
	w = (w * b) % MOD;
	w = (w * _pow(a - 1, MOD - 2)) % MOD;
	return (ans + w) % MOD;
}

int main() {

	sync;
	srand(time(NULL));
	cout.precision(10);
	cout << fixed;

#ifdef LOCAL
	input;
	//output;
#else

#endif

	cin >> a >> b >> n >> x;

	cout << solve_quick() << endl;

}


#include <bits/stdc++.h>

using namespace std;

typedef  long long ll ;
typedef  long long ull ;
const ll mod = 1e9 + 7 ;
ll f(ll a, ll b){

    if(b == 0) return 1;
    else if(b == 1) return a ;

    if(b & 1){
        return ((a % mod ) * ( f(a,b-1)%mod))%mod;
    }
    ll t = f(a,b/2) % mod;
    return  (t * t)%mod;
}
 ull inv(ull a, ull mod) {
    return a > 1 ? mod - inv(mod % a, a) * mod / a : 1;
}

int main()
{

    ll a , b, n , x ;
    cin >> a >> b >> n >> x;

    if( n == 1) {
        cout <<  ( ( (a % mod) *  (x % mod) ) %mod + b  % mod ) %mod << endl ;
        return 0 ;
    }
    if(a == 1){
        cout <<  (x +  n * b) %mod << endl;
        return 0 ;
    }

    ll t = f(a,n) ;
    ll t2 = (t * (x%mod) )%mod;

    ll t3 =  ( ( (inv(a-1,mod) % mod) *  ( ( (t -1)%mod + mod ) %mod)) % mod + mod ) % mod ;
    t3 *= b ;
    t3 %= mod ;
    ll res =  (t3 + t2)% mod;
    cout << res << endl ;

    return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR2(i, a, b) for (int i = (a); i > (b); --i)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define co continue
#define re return
#define inf 1000000001
#define CLR(a,v) memset((a),(v),sizeof(a))

const int INF = 1<<29;
typedef long long ll;

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return n & two(b); }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int dr[] = {-1,0,1,1};
int dc[] = {1,1,1,0};
char board[4][4];
char g[3][5];

bool inb(int r, int c) { return r >= 0 && r < 3 && c >= 0 && c < 3; }

bool check(int r, int c, int d)
{
        char x = board[r][c];
        if (x == '.') return false;
        int n = 0;
        while (inb(r,c) && board[r][c] == x)
        {
                ++n;
                r += dr[d];
                c += dc[d];
        }
        return n == 3;
}

char winner()
{
        FOR(i,0,3) FOR(d,0,4)
        {
                if (check(i,0,d)) return board[i][0];
                if (check(0,i,d)) return board[0][i];
        }
        return 0;
}

bool isWin(char ch,int n)
{
	if(n < 3)re false;
	int i,su = 0;
	fo(i,0,3)if(board[i][0]!=ch)break; if(i == 3)su++;
	fo(i,0,3)if(board[i][2]!=ch)break; if(i == 3)su++;
	fo(i,0,3)if(board[0][i]!=ch)break; if(i == 3)su++;
	fo(i,0,3)if(board[2][i]!=ch)break; if(i == 3)su++;
	fo(i,0,3)if(board[i][i]!=ch)break; if(i == 3)su++;
	fo(i,0,3)if(board[2-i][i]!=ch)break; if(i == 3)su++;
	re (su >= 1);
}

int main()
{

	FOR(i,0,3) { scanf(" %s", board[i]); strcpy(g[i],board[i]); }
        int nx = 0, no = 0;
        FOR(i,0,3) FOR(j,0,3)
                if (board[i][j] == 'X') ++nx;
                else if (board[i][j] == '0') ++no;
		int n1 = nx,n2 = no; bool w1,w2;
		if(n1 < n2){ printf("illegal\n"); re 0; }
		if((n1-n2) > 1){ printf("illegal\n"); re 0; }
		w1 = isWin('X',n1); w2 = isWin('0',n2);
		char w = winner();
		//if(w1&w2){ printf("illegal\n"); re 0; }
		if(!(w1|w2))
		{
			if(w != 0)re 0;
			/*if(n1 == n2){ printf("first\n");	 re 0; }
			f((n1+n2) == 9){ printf("draw\n");	 re 0; }
			printf("second\n");	 re 0; */
			/*	if (nx == no) printf("first\n");
                else if (nx+no == 9) printf("draw\n");
                else printf("second\n");
				re 0;*/
		}
        //pocet nesedi

        if (nx != no && nx != no+1)
        {
                //printf("illegal\n");
                //return 0;
        }

        if (w == 0) //noone
        {
				if (nx == no) printf("first\n");
                else if (nx+no == 9) printf("draw\n");
                else printf("second\n");
        }
        else
        {
                if ((w == 'X' && nx==no) || (w == '0' && nx==no+1))
                {
                        printf("illegal\n");
                        return 0;
                }
                bool ok = false;
                FOR(i,0,3)FOR(j,0,3)
                        if (board[i][j] == w)
                        {
                                board[i][j] = '.';
                                if (!winner()) ok = true;
                                board[i][j] = w;
                        }
                if(!ok) printf("illegal\n");
                else if (w=='X') printf("the first player won\n");
                else printf("the second player won\n");
        }

        return 0;
}


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

int main(){
	string str;
	cin>>str;
	int len = str.length();
	int cnt = 0;
	string a,b;
	if(str[0] != '1')
		a += str[cnt++] - 1;
	while(cnt != len-1){
		a += '9';
		// b += str[cnt] - a[cnt];
		cnt ++;
	}
	if(str[0] != '1')
		a += '9';
	ll n = atoll(str.c_str());
	ll x = atoll(a.c_str());
	ll y = n - x;
	// cout<<n<<"\n"<<x<<"\n"<<y<<"***\n";
	int sum = 0;
	while(x && y){
		sum += x%10 + y%10;
		x /= 10;
		y /= 10;
	}
	while(x){
		sum += x%10;
		x /= 10;
	}
	while(y){
		sum += y%10;
		y /= 10;
	}
	printf("%d\n",sum);

	return 0;
}


// Test.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <cctype>
#include <math.h>
#include <vector>
#include <fstream>
#include <numeric>
#define MAXN 100001
#define ll long long
//cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
using namespace std;
ll sd(ll x)
{
	ll s = 0;
	while (x >= 10)
	{
		s += (x % 10);
		x /= 10;
	}
	s += x;
	return s;
}
int main()
{
	ll n;
	cin >> n;
	string str = to_string(n);
	string first = str.substr(0, 1);
	if (first != "1")
	{
		stringstream conv(first);
		ll x;
		conv >> x;
		x--;
		string res = to_string(x);
		for (int i = 0; i < str.size() - 1; i++)
		{
			res += "9";
		}
		stringstream con(res);
		ll a;
		con >> a;
		cout << sd(a) + sd(n - a);
	}
	else
	{
		string res = "4";
		for (int i = 0; i < str.size() - 2; i++)
		{
			res += "9";
		}
		stringstream con(res);
		ll a;
		con >> a;
		cout << sd(a) + sd(n - a);
	}
	return 0;
}


/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
#define endl '\n'
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef queue<int> qii;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i)
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
double pi = 2 * acos(0.0);

void solve(){
    ll n;
    cin>>n;
    ll cpy=n;
    stack<int> s;
    while(cpy){
        s.push(cpy%10);
        cpy/=10;
    }
    ll x=s.top();
    string l;
    if(x==1){
        x=6;
        l+=(x-1)+'0';
        rep(i,0,s.size()-2){
            l+='9';
        }
    }
    else{
        l+=(x-1)+'0';
        rep(i,0,s.size()-1){
            l+='9';
        }
    }
    ll a=stoll(l);
    ll b=n-a;
    ll ans=0;
    while(a){
        ans+=a%10;
        a/=10;
    }
    while(b){
        ans+=b%10;
        b/=10;
    }
    cout<<ans;
}

int main(){
    // #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    // #endif
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}


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

using namespace std;

int sum(long long x){
    int sol = 0;
    while( x != 0 ){
        sol += x % 10;
        x /= 10;
    }
    return sol;
}

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

    int n;

    cin >> n;

    vector<int> a;
    vector<int> b;

    int ka = 0;
    int kb = 0;

    bool ok ;

    if( n % 2 == 0 ){
        a.push_back(n/2);
        b.push_back(n/2);
        ok = 0;
    }else{
        a.push_back(n/2);
        b.push_back(0);
        b.push_back(n/2);
        a.push_back(n/2 + 1);
        ok = 1;
    }

    if( ok == 0){
        for( int i = 1; b[i - 1] >= 0; i++){
            a.push_back(a[i - 1] + 1);
            b.push_back(b[i - 1] - 1);
        }
    }else{
        for( int i = 2; b[i - 1] >= 0; i++){
            a.push_back(a[i - 1] + 1);
            b.push_back(b[i - 1] - 1);
        }
    }

    int maxx = 0;
    int aa, bb;
    for( int i = 0; i < a.size() && i < b.size(); i++){
        if( sum(a[i]) + sum(b[i]) > maxx ){
            maxx = sum(a[i]) + sum(b[i]);
            aa = a[i];
            bb = b[i];
        }
    }

    cout << maxx;

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
	long long int n,k,t;

	cin>>n>>k>>t;
	long long int a[n+1];
	for(long long int i=0;i<n+1;i++)
	a[i]=0;
	long long int j=1;
	for(long long int i=1;i<=t;i++)
	{
		if(i<=k)
		a[i]=1;
	else if(i>k&&i<n)
		{
			a[i]=1;
			a[j]=0;
			j++;
		}
	else if(i==n)
		{a[i]=1;
		a[i-k]=0;
		}
	else if(i>n)
		{
			a[i-k]=0;
		}
	}
	long long int c=0;
	for(long long int i=1;i<=n;i++)
	{
		if(a[i]==1)
		c++;
	}

	cout<<c;
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int i,j,n,k,t;
	int a[10000];
	cin>>n>>k>>t;
	int sin=0;
	for(i=0;i<k;i++){
		a[i]=sin;
		sin++;
	}

	for(i=k;i<n;i++){
		a[i]=sin;
	}

	for(i=n;i<n+k;i++){
		a[i]=sin;
		sin--;
	}
	cout<<a[t];
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <conio.h>
#include <locale.h>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
	freopen("input.txt","r",stdin);
	int n,k,t;
	cin >> n >> k >> t;
	if(t<k){
		cout << t;
	}else if((t>=k)&&(t<=n)){
		cout << k;
	}else{
		cout << n+k-t;
	}
	getch();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <conio.h>
#include <locale.h>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
	freopen("input.txt","r",stdin);
	int n,k,t;
	cin >> n >> k >> t;
	if(t<k){
		cout << t;
	}else if((t>=k)&&(t<=n)){
		cout << k;
	}else{
		cout << t-n+1;
	}
	getch();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

#define pii pair<int, int>
#define mp make_pair<int, int>

typedef long long ll;

const int N = 1005;
const int M = 12;

ll MOD;
ll dp[N][M][N];

inline ll mypow(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
		{
			res = ((ll)res * a) % MOD;
		}
		a = ((ll)a * a) % MOD;
		b >>= 1;
	}

	return res;
}

inline ll cmb(ll a, ll b)
{
	ll d1, d2;
	d1 = d2 = 1;
	if (a < b)
	{
		return 0;
	}
	while (b)
	{
		d1 = (ll)d1 * a % MOD;
		d2 *= b;
		b--;
		a--;
	}

	return (ll)d1 * mypow(d2, MOD - 2) % MOD;
}

int main()
{
	int n, d, i, j,k, l;
	scanf("%d%d%lld", &n, &d, &MOD);

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

	for (k = 0; k <= n; k++)
	{
		dp[1][0][k] = 1;
	}

	for (i = 2; i <= d + 1; i++)
	{
		for (k = 1; k <= n; k++)
		{
			dp[i][i - 1][k] = 1;
		}
	}

	ll tmp;
	for (i = 3; i <= n; i++)
	{
		for (j = 1; j <= d && j < i - 1; j++)
		{
			for (k = 2; k <= n - 1; k++)
			{
				dp[i][j][k] = dp[i][j][k - 1];
				for (l = 1; l <= j && l*k < i; l++)
				{
					tmp = (ll)dp[i - k*l][j - l][k - 1] * cmb(dp[k][d - 1][k - 1] + l - 1, l) % MOD;
					dp[i][j][k] = ((ll)dp[i][j][k] + tmp) % MOD;
				}
			}
		}
	}

	ll ans = 0;
	ans = dp[n][d][(n + 1) / 2 - 1];
	if ((n & 1) == 0)
	{
		ans = ((ll)ans + cmb(dp[n / 2][d - 1][n / 2 - 1] + 1, 2)) % MOD;
	}

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


#include"bits/stdc++.h"

using namespace std;

int d;
int num_leaf(int sz) {
	if (sz == 1) {
		return 1;
	}
	if (sz == 2) {
		return 1;
	}
	sz--;
	int cnt = d;
	sz -= d;
	if (sz < 0) {
		return -1;
	}
	while (sz) {
		if (sz < d-1) {
			return -1;
		}
		sz -= (d - 1);
		cnt += (d - 1);
		cnt--;
	}
	return cnt;
}
#define MAX 1002
int lf[MAX];
long long int dp[MAX];
bool us[MAX];
long long int tmp[MAX][MAX][11];
long long int tmp2[MAX][MAX][11];

long long int MOD;

bool us2[MAX];
long long int dp2[MAX];

long long int ppow(long long int i, long long int j) {
	long long int res = 1;
	while (j) {
		if (j & 1LL) {
			res *= i;
			if (res >= MOD)res %= MOD;
		}
		j >>= 1LL;
		i *= i;
		if (i >= MOD)i %= MOD;
	}
	return res;
}

long long int sel(long long int val, int ch) {
	val += ch - 1;
	long long int up = 1;
	long long int dw = 1;
	for (int j = 0; j < ch; j++) {
		up *= (val - j);
		if (up >= MOD)up %= MOD;
		dw *= (j + 1);
		if (dw >= MOD)dw %= MOD;
	}
	up *= ppow(dw, MOD - 2);
	if (up >= MOD)up %= MOD;
	return up;
}

long long int ww[MAX][11];

inline long long int dfs2(int sz) {
	if (sz == 1) {
		return 1;
	}
	if (us2[sz])return dp2[sz];
	us2[sz] = true;
	dp2[sz] = 0;
	tmp2[sz][0][0] = 1;
	int deg = d - 1;
	for (int add = 1; add <= sz-1; add++) {
		long long int way = dfs2(add);
		for (int z = 0; z <= deg; z++) {
			ww[sz][z] = sel(way, z);
		}
		for (int j = sz-1-add; j>=0; j--) {
			for (int k = deg-1; k>=0; k--) {
				long long int bs = tmp2[sz][j][k];
				for (int z = k + 1; z <= deg; z++) {
					if ((z - k)*add + j > sz - 1)break;
					tmp2[sz][(z - k)*add + j][z] += bs * ww[sz][z - k];// sel(way, z - k);
					if (tmp2[sz][(z - k)*add + j][z] > MOD) {
						tmp2[sz][(z - k)*add + j][z] %= MOD;
					}
				}
			}
		}
	}
	dp2[sz] = tmp2[sz][sz - 1][deg];
	return dp2[sz];
}

inline long long int dfs(int sz) {
	if (sz <= 1) {
		return 1;
	}
	if (us[sz])return dp[sz];
	us[sz] = true;
	int maxi = (sz-1) / 2;
	tmp[sz][0][0] = 1;
	for (int add = 1; add <= maxi; add++) {
		for (int j = sz-1-add; j>=0; j--) {
			for (int k = d-1; k>= 0; k--) {
				long long int bs = tmp[sz][j][k];
				long long int way = dfs2(add);
				for (int z = k + 1; z <= d; z++) {
					if ((z - k)*add + j > sz - 1)break;
					tmp[sz][(z - k)*add + j][z] += bs * sel(way, z - k);
					if (tmp[sz][(z - k)*add + j][z] > MOD) {
						tmp[sz][(z - k)*add + j][z] %= MOD;
					}
				}
			}
		}
	}
	dp[sz] = tmp[sz][sz-1][d];
	return dp[sz];
}

int main() {
	int n;
	cin >> n >> d >> MOD;
	for (int i = 0; i < MAX; i++) {
		lf[i] = num_leaf(i);
	}
	long long int ans = dfs(n);
	if (n % 2 == 0) {
		long long int ans2 = dfs2(n / 2);
		ans += sel(ans2, 2);
		if (ans >= MOD)ans %= MOD;
	}
	printf("%lld\n", ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,m;
ll P;
ll ine[1010];
int f[1010][11][1010];
ll DP(int n,int d,int k)
{
	k=min(k,n-1);
	if(f[n][d][k]!=-1)	return f[n][d][k];
	if((n==1&&d==m-1)||(n==1&&!d))	return 1;
	if(n==1)	return 0;
	int i,j;
	ll ret=0;
	for(i=1;i<=k;i++)
	{
		ll t=DP(i,m-1,k),tmp=1;
		for(j=1;j*i<n&&j<=d;j++)
		{
			tmp=tmp*(t+j-1)%P*ine[j]%P;
			ret=(ret+tmp*DP(n-i*j,d-j,min(k,i-1)))%P;
		}
	}
	return f[n][d][k]=ret;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&P);
	if(n==1||n==2)
	{
		puts("1");
		return 0;
	}
	if((n-2)%(m-1)!=0)
	{
		puts("0");
		return 0;
	}
	int i;
	ine[0]=ine[1]=1;
	for(i=2;i<=n;i++)	ine[i]=P-(P/i)*ine[P%i]%P;
	memset(f,-1,sizeof(f));
	ll ans=DP(n,m,(n-1)/2);
	if(!(n&1))
	{
		ll t=DP(n/2,m-1,n/2-1);
		ans=(ans+t*(t+1)/2)%P;
	}
	printf("%lld",ans);
	return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef complex<double> point;

const double E = 1e-9, pi = 2*acos(0);
const ldouble PI = 3.1415926535897932384626433832795029L;

int MOD;

lint modpow(lint a, lint b) {
	lint ans=1;
	while (b) {
		if (b%2) ans=ans*a%MOD;
		a=a*a%MOD;
		b/=2;
	}
	return ans;
}

bool solve(int testNumber) {
	int n, d;
	if (!~scanf("%d %d %d", &n, &d, &MOD)) return false;
	vector<vector<vector<lint> > > dp(n+1, vector<vector<lint> >(d+1, vector<lint>(n+1)));
	vector<lint> inv(d+1);
	inv[0]=1;
	for (int i=1; i<=d; i++) inv[i]=modpow(i, MOD-2);
	dp[0][0]=vector<lint>(n+1, 1);
	for (int i=0; i<=n; i++) for (int j=0; j<=d; j++) for (int k=0; k<=n; k++) {
		lint &ans=dp[i][j][k];
		if (!i) ans=!j;
		else if (!j) ans=i<=1;
		else if (!k) ans=0;
		else {
			ans=dp[i][j][k-1];
			lint aux=1;
			for (int l=1; l*k<i and l<=j; l++) {
				aux=aux*((k==1?1:dp[k][d-1][n])+l-1+MOD)%MOD*inv[l]%MOD;
				ans=(ans+dp[i-l*k][j-l][k-1]*aux%MOD)%MOD;
			}
		}
	}
	lint ans=n==1?1:dp[n][d][(n-1)/2];
	if (n%2==0) {
		lint aux=n/2==1?1:dp[n/2][d-1][n];
		ans=(ans+aux*(aux+1)%MOD*inv[2]%MOD)%MOD;
	}
	printf("%lld\n", ans);
	fflush(stdout);
    return true;
}

void init() {
}

int main() {
    init();
    for (int i=1; solve(i); i++);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <map>
#include <unordered_map>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <fstream>
#include <queue>

using namespace std;

#define ll long long
#define rt return
#define all(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
#define ld long double
#define gg std::ios::sync_with_stdio(false)

#define X first
#define Y second

#define rep(n, i) for (int i = 0; i < n; ++i)
#define per(n, i) for (int i = n - 1; i >= 0; --i)

#define pii pair<int, int>

const int MAX_SIZE = 1e5 + 10, INF = 2 * 1e9;
const int SIZE=1e9;
const long long LINF = 1e18, N = 59778;
const double eps = 1e-6, PI = 20 / 7;

void files() {
	freopen("input.txt", " r", stdin);
	//freopen("output.txt", "w", stdout);
}

bool isprime[SIZE];
int main() {
	gg;
	//files();
	cin.tie(0);
	ll a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	b = min(b, c);
	if (e > f) {
		cout << min(a, d) * e + min(max(d - min(a, d), ll(0)), b) * f;
	}
	else {
		cout << min(b, d) * f + min(max(d - min(b, d), ll(0)), a) * e;
	}
}


#include <iostream>
using namespace std;

int main()
{
    long long int a , b , c , d , e , f , ans =0 ;
    cin>>a>>b>>c>>d>>e>>f ;
    if(f>e){
        ans+=min(d,min(b,c))*f ;
        d-=min(d,min(b,c)) ;
        if(d>0){
            ans+=min(d,a)*e ;
        }
        cout<<ans<<endl ;
    }
    else if(e>f) {
        ans+=min(a,d)*e ;
        d-=min(d,a) ;
        ans+=min(d,min(b,c))*f ;
        cout<<ans<<endl ;
    }
    else{
        cout<<max(min(a,d),min(b,min(c,d)))*f<<endl  ;
    }
}


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

int main()
{
    long long a,b,c,d,c1,c2;
    cin>>a>>b>>c>>d>>c1>>c2;

    long long mx=0;

        long long mn=min(a,d);
        long long mn2=min(b,mn-d);
        mn2=min(mn2,c);
        long long sum=(mn*c1)+(c2*mn2);

        long long mn1=min(b,c);
        mn1=min(mn1,d);
        long long mn3=min(abs(mn1-d),d);

        long long sum1=(mn1*c2)+(c1*min(a,mn3));

        mx=max(sum,sum1);

        cout<<mx<<endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d;
	cin >> e >> f;
	int n = 0, m = 0;
	if(f > e){
		n += (min(b, min(c, d)) * f);
		if((d - min(b, min(c, d))) >= 0)
			m += (min((d - min(b, min(c, d))), a) * e);
	}
	else if(e > f){
		n += (min(a, d) * e);
		if(d - min(a, d) >= 0)
		m += (min((d - min(a, d)), min(b, c)) * f);
	}
	else if(e == f){
		cout << min(max(a, min(b, min(c, d))), d) * e;
		return 0;
	}
	cout << m + n;
}


#include<iostream>
#include<string>
#include<string.h>
#include<ios>
#include<cstdio>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<cstdlib>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    char chx1,chx2;
    int ans=0,y1,y2,x1=0,x2=0,a[101][101];
    cin>>chx1>>y1;
    cin>>chx2>>y2;
    x1=int(chx1-96);
    x2=int(chx2-96);
    a[x1][y1]=1;
    a[x2][y2]=1;
    for(int i=1;i<=8;i++)
    {
     for(int j=1;j<=8;j++)
     {
      if(x1==i || y1==j) a[i][j]=1;
      if((max(x2,i)-min(x2,i))*(max(y2,j)-min(y2,j))==2) {a[i][j]=1;}
      if((max(x1,i)-min(x1,i))*(max(y1,j)-min(y1,j))==2) {a[i][j]=1;}
     }
    }
    for(int i=1;i<=8;i++)
    {
     for(int j=1;j<=8;j++)
     {
      if(a[i][j]!=1) ans++;
     }
    }
    //fclose(stdin);fclose(stdout);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <complex>
#include <set>
#include <vector>
#include <bitset>

#define REP(i,N)for(int i=0;i<(int)N;i++)
#define MP(a,b) make_pair(a,b)
using namespace std;

int nextInt(){
  int ret=0,sign=1;
  char c=' ';
  while (!isdigit(c=getchar())){
    if (c==EOF) return -1;
    if (c=='-') sign=-1;
  }
  do{
    ret=ret*10+(c-'0');
  }while (isdigit(c=getchar()));
  return ret*sign;
}
void printlineInt(int num){
  char str[101];
  if (num<0) num=-num,putchar('-');
  else if (num==0) {puts("0");return;}
  str[100]='\0';
  int i=99;
  for (;num;i--){
    str[i]=num%10+'0';
    num/=10;
  }
  puts(&str[i+1]);
  return;
}
//template end

int cost[1001], dmg[1001];

int main(){
  int N, pow, reg;
  while (cin >> N >> pow >> reg) {
    REP(i, N) {
      cin >> cost[i] >> dmg[i];
    }
    int maxpow = pow;
    int turn = 0;
    bool used[1001] = {};
    vector<pair<int, int> > hist;
    int dm = 0;
    used[0] = true, dm = dmg[0];
    REP(tt, 100000){
      // dmg
      pow -= dm;

      // reg
      pow += reg;
      if (pow > maxpow) pow = maxpow;
      // judge
      if (pow <= 0) break;
      // select
      int d = 0;
      int idx = -1;
      REP(i, N){
        if (cost[i] >= (pow * 100 / maxpow)&& !used[i] &&
            d < dmg[i]) d = max(d, dmg[i]), idx = i;
      }
      if (idx != -1){
        used[idx] = true;
        hist.push_back(MP(turn, idx));
        dm += d;
      }
      turn++;
    }
    if (pow <= 0){
      cout << "YES" << endl;
      cout << turn+1 << " " << hist.size() << endl;
      REP(i, hist.size()){
        cout << hist[i].first+1 << " "<< hist[i].second+1 << endl;
      }
    }else{
      cout << "NO" << endl;
    }
  }
}


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

typedef long long ll;

const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
int par[N];

int root(int v){return par[v] < 0? v:(par[v] = root(par[v]));}
int dsu_cnt;
void merge(int x, int y)
{
    x= root(x);
    y = root(y);
    if(x == y)
        return;
    if(par[x]>par[y])
        swap(x, y);
    par[y] = x;
    par[x] += par[y];
    dsu_cnt--;
}

int main()
{
    memset(par,-1, sizeof par);
    int p,k;
    scanf("%d %d",&p,&k);
    dsu_cnt=p-1;
    for(int i=1;i<p;i++)
    {
        int other = (i*k)%p;
        merge(i,other);
    }
    ll ans = 1;
    for(int i=0;i<dsu_cnt;i++)
    {
        ans *= p;
        ans %=mod;
    }
    if(k == 1)
        ans =(ans*p)%mod;
    printf("%lld\n",ans);
}


#include <cstdint>
#include <iostream>
#include <vector>

const uint64_t kModulo = 1000000000 + 7;

int main()
{
  uint64_t p, k;
  std::cin >> p >> k;

  std::vector<bool> visited(p);
  std::vector<uint32_t> pows;

  uint64_t r = 1;
  pows.push_back(r);
  do
  {
    r = (r * k) % p;
    if (r == 1)
      break;
    pows.push_back(r);
  } while (true);

  uint64_t result = (k == 0 ? p : 1);
  visited[0] = true;

  for (uint64_t i = 1; i < p; ++i)
  {
    if (visited[i])
      continue;

    size_t j = 0;
    for (j = 0; j + 4 < pows.size(); ++j)
    {
      visited[(i * pows[j + 0]) % p] = true;
      visited[(i * pows[j + 1]) % p] = true;
      visited[(i * pows[j + 2]) % p] = true;
      visited[(i * pows[j + 3]) % p] = true;
    }
    for (; j < pows.size(); ++j)
      visited[(i * pows[j]) % p] = true;

    result = (result * p) % kModulo;
  }

  std::cout << result << std::endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <utility>
#include <iomanip>
#include <map>
#define INF 1000000007
using namespace std;
typedef long long s64;
typedef unsigned long long u64;
int k,p;
int main() {
	ios_base::sync_with_stdio(false);
	cin >> p >> k;
	if (k==1) {
		int t=1;
		for (int i=0; i<p; i++) {
			t*=p;
			t%=INF;
		}
		cout << t << '\n';
		return 0;
	}
	int count = 1;
	int r = k;
	if (r == 0) {
		count = p-1;
	}
	else {
		while (r != 1) {
			r *= k;
			r %= p;
			count++;
		}
		count = (p-1)/count;
	}
	u64 ans = 1;
	for (int i=0; i<count; i++)
	{
		ans *=  p;
		ans %= INF;
	}
	cout << ans << '\n';
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <climits>
#include <cctype>
#include <cmath>
#include <cassert>
#include <ctime>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <limits>
#include <functional>
#include <numeric>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define _ << ", " <<

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

bool mark[1000100];
#define mod 1000000007LL

ll expo(ll a, ll b) {
  ll r = 1;
  for (; b; b>>=1, a=(a*a)%mod) if (b&1) r = (r*a)%mod;
  return r;
}

int main() {
  int p, k;
  sc2(p,k);
  if (k == 0) {
    printf("%lld\n", expo(p, p-1));
    return 0;
  } else if (k == 1) {
    printf("%lld\n", expo(p, p));
    return 0;
  }
  cl(mark,0);
  int cnt = 0;
  fr(i,1,p) if (!mark[i]) {
    int u = i;
    do {
      mark[u] = 1;
      u = (u*k)%p;
    } while (!mark[u]);
    cnt++;
  }
  printf("%lld\n", expo(p, cnt));
}


#include <bits/stdc++.h>
using namespace std;
bool def(string s,string t)
{
	if(s=="rock"&&t=="scissors")	return true;
	else if(s=="scissors"&&t=="paper")	return true;
	else if(s=="paper"&&t=="rock")	return true;
}
char winner(string s,string t,string q)
{
	if(t==q&&def(s,t))	return 'F';
	if(s==q&&def(t,q))	return 'M';
	if(s==t&&def(q,s))	return 'S';
	return '?';
}
string gest[3];
int main()
{
	for(int i=0;i<3;i++)
	{
		cin>>gest[i];
	}
	cout<<winner(gest[0],gest[1],gest[2]);
	return 0;
}


#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <cctype>
#include <deque>
#include <queue>

#define black 0
#define white 1
#define tru -1
#define fals -2
#define array 1000000
using namespace std;

int main()
{
    int i, j ,Case=0, Cases, s, p, r;
    char res[3] = {'F','M','S'};
    char a[10][10];
    while(scanf("%s %s %s",a[0],a[1],a[2])){
        p = r = s = 0;
        for(i=0; i<3; i++){
            if(a[i][0] == 's') s++;
            else if(a[i][0] == 'p') p++;
            else if(a[i][0] == 'r') r++;
        }
        //printf("%d %d %d\n",s,p,r);
        if(p==2 && s == 1){
            for(i=0;i<3;i++)
            if(a[i][0]=='s'){
                cout<<res[i]<<endl;
                break;
            }
        }
        else if(p==1 && r == 2){
            for(i=0;i<3;i++)
            if(a[i][0]=='p'){
                cout<<res[i]<<endl;
                break;
            }
        }
        else if(s==2 && r == 1){
            for(i=0;i<3;i++)
            if(a[i][0]=='r'){
                cout<<res[i]<<endl;
                break;
            }
        }

        else printf("?\n");
    }

    return 0;
}


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

using namespace std;

int main(){
    char m[9],f[9],s[9];
    scanf("%s %s %s",f,m,s);
    if(((strcmp(f,m)!=0)&&(strcmp(m,s)!=0)&&(strcmp(f,s)!=0))||((strcmp(f,m)==0)&&(strcmp(m,s)==0)&&(strcmp(f,s)==0))) cout<<"?"<<endl;
    else if (strcmp(f,"rock")==0){if(strcmp(m,"paper")==0){ if (strcmp(s,"paper")!=0)cout<<"M"<<endl;
                                                        else cout<<"?"<<endl;}
                                  else if(strcmp(s,"paper")==0){if (strcmp(m,"paper")!=0)cout<<"S"<<endl;
                                                        else cout<<"?"<<endl;}
                                       else cout<<"F"<<endl;

         }
         else if (strcmp(f,"paper")==0){if(strcmp(m,"scissors")==0){ if (strcmp(s,"scissors")!=0)cout<<"M"<<endl;
                                                        else cout<<"?"<<endl;}
                                  else if(strcmp(s,"scissors")==0){if (strcmp(m,"scissors")!=0)cout<<"S"<<endl;
                                                        else cout<<"?"<<endl;}
                                       else cout<<"F"<<endl;

              }
              else if (strcmp(f,"scissors")==0){if(strcmp(m,"rock")==0){ if (strcmp(s,"rock")!=0)cout<<"M"<<endl;
                                                        else cout<<"?"<<endl;}
                                  else if(strcmp(s,"rock")==0){if (strcmp(m,"rock")!=0)cout<<"S"<<endl;
                                                        else cout<<"?"<<endl;}
                                       else cout<<"F"<<endl;
                   }
    getch();

}


#include <bits/stdc++.h>
#define lli long long int
#define PI acos(-1.0)
using namespace std;
int b[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

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

	int n;

	cin >> n;
	int a[n+5];

	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int c = 0;
	if(n == 1) cout << "YES" <<  endl;
	else{
		for(int i = 0; i < n; i++){

			if(a[i] == 28 || a[i] == 29){
				if(a[i+1] != 31 && i != n-1){
					c = 1;
					break;
				}
			}
			else if(a[i] == 30){
				if(a[i+1] != 31 && i != n-1){
					c = 1;
					break;
				}
			}
		}
		if(c == 1) cout << "NO" << endl;
		else cout << "YES" << endl;
	}

    return 0;
}


//Template by karthik171998

#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wunused-result"

/*------------------------------------------------------------------------*/

#define iOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define For(i,a,b) for((i)=(a);(i)<(b);++(i))
#define Fore(i,a,b) for((i)=(a);(i)<=(b);++(i))
#define rof(i,a,b) for((i)=(a);(i)>=(b);--(i))
#define Fors(i,s) for((i)=s.begin();i!=s.end();i++)
#define Form(i,m) for((i)=m.begin();i!=m.end();i++)
#define inf (long long)4e18
#define xx first
#define yy second
#define pb push_back
#define PB pop_back()
#define mp make_pair
#define mod 1000000007
#define pi 3.1428571
#define sqr(a) (((a) * (a)))
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define endl "\n"
#define ub(a,e) upper_bond(a.begin(),a.end(),e)
#define lb(a,e) lower_bond(a.begin(),a.end(),e)
#define sortv(a) sort(a.begin(),a.end())
#define sortr(a) sort(a.rbegin(),a.rend())
#define accu(a,e) accumulate(a.begin(),a.end(),e)

/*---------------------------------------------------------------------------*/

typedef long long ll;
typedef vector< pair <ll,ll> >vect;
typedef pair<ll,ll> pa;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef map<string,ll> ms;
typedef map<ll,ll> ml;
typedef priority_queue <ll> pq;
typedef unsigned long long ull;
typedef long double ld;

/*---------------------------------------------------------------------------*/

ll gcd(ll a, ll b)
{
	if(b == 0)
	{
		return a;
	}
	return gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
	return ((a*b)/gcd(a,b));
}

/*----------------------------------------------------------------------------*/
//Variables and functions for graph
//Undirected graph

/*vi adj[1000000];
bool visited[1000000]={false};
void add_edge(ll a,ll b)
{
    adj[a].pb(b);
    adj[b].pb(a);
}
/*-----------------------------------------------------------------------------*/

//end of template.

ll i,j,n,t;

int main()
{
 	iOS;
 	cin>>n;
 	int f=0;
 	string a="312931303130313130313031";
 	string b="312831303130313130313031";
 	i=0;
 	while(i<=25)
 	a+=a,i++;
 	while(i>=0)
 	b+=b,i--;
 	string ans="";
 	For(i,0,n)
 	{
 		string c;
 		cin>>c;
 		ans+=c;
	 }
	 For(i,0,a.size())
	 {
	 	string d=a.substr(i,2*n);
	 	if(d==ans)
	 	{
		cout<<"YES";
		return 0;
		}
	 }
	 For(i,0,b.size())
	 {
	 	string d=b.substr(i,2*n);
	 	if(d==ans)
	 	{
	 	cout<<"YES";
		return 0;
		}
	 }
	 cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
#define maxn 100
#define Task ""
#define vt vector
#define pb push_back
#define pii pair <int, int>
#define mp make_pair
#define F first
#define S second
#define ll long long
#define mod 1000000007

using namespace std;
int n = 10;
char a[maxn][maxn];
void nhap()
{
    for (int i = 1; i <= 10; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
}

bool check (char x)
{
    int res = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n-4; j++)
            if (a[i][j] == x)
            {
                int ok = 1;
                for (int k = j; k <= j+4; k++)
                    if (a[i][k] != x) {ok = 0;break;}
                    res += ok;
                if (i <= n - 4)
                {
                    ok = 1;
                    for (int k = 0; k <= 4; k++)
                        if (a[i+k][j+k] != x) {ok = 0; break;}
                    res += ok;
                    ok = 1;
                    for (int k = i; k <= i+4; k++)
                        if (a[k][j] != x) {ok = 0;break;}
                    res += ok;
                }
                if (i > 4)
                {
                    ok = 1;
                    for (int k = 0; k <= 4; k++)
                        if (a[i-k][j=k] != x) {ok = 0;break;}
                }
            }
    return res != 0;
}

void solve()
{
    if (check('O')) {
        cout << "NO";
        return;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (a[i][j] == '.')
            {
                a[i][j] = 'X';
                if (check('X')) {cout << "YES"; return;}
                a[i][j] = '.';
            }
            cout << "NO";
}

int main()
{
    nhap();
    solve();
    return 0;
}


#include <bits/stdc++.h>
#define maxn 100
#define Task ""
#define vt vector
#define pb push_back
#define pii pair <int, int>
#define mp make_pair
#define F first
#define S second
#define ll long long
#define mod 1000000007

using namespace std;
int n = 10;
char a[maxn][maxn];
void nhap()
{
    for (int i = 1; i <= 10; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
}

bool check (char x)
{
    int res = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n-4; j++)
            if (a[i][j] == x)
            {
                int ok = 1;
                for (int k = j; k <= j+4; k++)
                    if (a[i][k] != x) ok = 0;
                    res += ok;
                if (i <= n - 4)
                {
                    ok = 1;
                    for (int k = 0; k <= 4; k++)
                        if (a[i+k][j+k] != x) ok = 0;
                    res += ok;
                    ok = 1;
                    for (int k = i; k <= i+4; k++)
                        if (a[k][j] != x) ok = 0;
                    res += ok;
                }
                if (i > 4)
                {
                    ok = 1;
                    for (int k = 0; k <= 4; k++)
                        if (a[i-k][j=k] != x) ok = 0;
                }
            }
    return res != 0;
}

void solve()
{
    if (check('O')) {
        cout << "NO";
        return;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (a[i][j] == '.')
            {
                a[i][j] = 'X';
                if (check('X')) {cout << "YES"; return;}
                a[i][j] = '.';
            }
            cout << "NO";
}

int main()
{
    nhap();
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char t[15][15];
int dx[] = {1,1,1,-1,-1,-1,0,0};
int dy[] = {-1,0,1,-1,0,1,-1,1};
int mx;

bool isValid(int row, int col) {
  if (row >= 0 && row < 10 && col >= 0 && col < 10) {
    return true;
  } else {
    return false;
  }
}

void dfsCheck(int r,int c,int len,int rPar,int cPar) {
  mx = max(mx, len);
  for (int i = 0; i < 8; i++) {
    int nextRow = r + dx[i];
    int nextCol = c + dy[i];
    if (isValid(nextRow, nextCol)) {
      if (t[nextRow][nextCol] == 'X' && (nextRow != rPar || nextCol != cPar)) {
        dfsCheck(nextRow, nextCol, len + 1, r, c);
      }
    }
  }
}

void testCell(int row,int col) {
  bool changed = 0;
  if (t[row][col] == '.') {
    t[row][col] = 'X';
    changed = 1;
  }
  dfsCheck(row, col, 1, row,col);
  if (changed) {
    t[row][col] = '.';
  }
}

int main() {
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> t[i][j];
    }
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (t[i][j] != 'O') {
        testCell(i, j);
      }
    }
  }
  puts(mx >= 5 ? "YES" : "NO");
}


#include <bits/stdc++.h>

using namespace std;

char t[15][15];
int dx[] = {1,1,1,-1,-1,-1,0,0};
int dy[] = {-1,0,1,-1,0,1,-1,1};
int mx;

bool isValid(int row, int col) {
  if (row >= 0 && row < 10 && col >= 0 && col < 10) {
    return true;
  } else {
    return false;
  }
}

void dfsCheck(int r,int c,int len) {
  mx = max(mx, len);
  for (int i = 0; i < 8; i++) {
    int nextRow = r + dx[i];
    int nextCol = c + dy[i];
    if (isValid(nextRow, nextCol)) {
      if (t[nextRow][nextCol] == 'X') {
        dfsCheck(nextRow, nextCol, len + 1);
      }
    }
  }
}

void testCell(int row,int col) {
  bool changed = 0;
  if (t[row][col] == '.') {
    t[row][col] = 'X';
    changed = 1;
  }
  dfsCheck(row, col, 1);
  if (changed) {
    t[row][col] = '.';
  }
}

int main() {
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> t[i][j];
    }
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (t[i][j] != 'O') {
        testCell(i, j);
      }
    }
  }
  puts(mx >= 5 ? "YES" : "NO");
}


#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#pragma warning(disable:4996)

int a,b;
int a2,a3,a5,b2,b3,b5;
int r;

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

	cin>>a >>b;
	if (a==b) { cout<<0; return 0;}

	while (a%2==0) { a2++; a/=2; }
	while (a%3==0) { a3++; a/=3; }
	while (a%5==0) { a5++; a/=5; }

	while (b%2==0) { b2++; b/=2; }
	while (b%3==0) { b3++; b/=3; }
	while (b%5==0) { b5++; b/=5; }

	if (a>1 || b>1) { cout<<"-1"; return 0; }

	r = abs(a2-b2) + abs(a3-b3) + abs(a5-b5);
	cout<<r <<endl;

	return 0;
};


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int gcd(int a,int b)//最大公约数
{
    if (a<b) return gcd(b,a);
    else if (b==0) return a;
    else return gcd(b,a%b);
}

int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==m)
        {
            printf("0\n");
            continue;
        }
        int a=gcd(n,m);
        int f1=n/a,f2=m/a,tem=0;
        a=f1*f2;
        while(a!=1)
        {
            if(a%5==0)
            a/=5,tem++;
            else if(a%3==0)
            a/=3,tem++;
            else if(a%2==0)
            a/=2,tem++;
            else
            {
                printf("-1\n");
                break;
            }
        }
        if(a==1)
        printf("%d\n",tem);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <conio.h>
#define _G getch()
#define ll long long
#define pb push_back
#define rep(x,st,ed) for(x=st;x<ed;x++)
#define drep(x,st,ed) for(i=st;i>ed;i--)
#define C cin>>
#define _C cout<<
#define Ln <<"\n"
using namespace std;
map<int ,int> p3a,jbs;
   int ar[3]={2,3,5};
   vector<int >v,v1;
void divi(int x,int steps,int flag)
{   int i;
    //cout<<x<<" ";
    //_G;
    if((flag==0&&p3a.find(x)==p3a.end())||(flag==1&&jbs.find(x)==jbs.end()))
    {
        if(flag==0)
        p3a[x]=steps;
        if(flag==1)
        jbs[x]=steps;

     }
     else
     {   if(flag==0)
        { if(p3a[x]>steps)
            p3a[x]=steps;

         }
          if(flag==1)
        { if(jbs[x]>steps)
            jbs[x]=steps;

         }

     }
     if(p3a.find(x)!=p3a.end()&&jbs.find(x)!=jbs.end()&&find(v.begin(),v.end(),x)==v.end())
         v.pb(x);
        for(i=0;i<3;i++)
          {
              if(x%ar[i]==0)
                divi(x/ar[i],steps+1,flag);
          }
 }
int main()
{
   int l,i,j,t,w,wi,a,b;
     C a>>b;
     if(a==b)
     {
          _C "0\n";
     }
      else
      {   int mi=min(a,b);
          int mx=max(a,b);
          if(mx%mi==0)
          v.pb(mi);
          p3a[a]=0;
          for(i=0;i<3;i++)
          {
              if(a%ar[i]==0)
              {  divi(a/ar[i],1,0);
              }
          }
          jbs[b]=0;
          for(i=0;i<3;i++)
          {
              if(b%ar[i]==0)
                divi(b/ar[i],1,1);
          }
          if(v.size()==0)
          {  _C "-1\n";
          return 0;
                         }
          for(i=0;i<v.size();i++)
          {  // _C "jay "<<v[i];
               v1.pb(p3a[v[i]]+jbs[v[i]]);
          }
          sort(v1.begin(),v1.end());
          _C v1[0];
      }
     _G;
}


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

int find(int,int);
int bmm(int,int);
int counter=0;
int mini=0;

void main(void){
    int a;
    int b;
    int c;
    cin>>a>>b;
    mini = bmm(a,b);
    if(find(a,b)){
        c=counter;
        cout<<c;
    }
    else
        cout<<-1;
    getch();
    return;
}

int bmm(int a,int b){
    if(a>b){
        if(b==0)return a;
        return bmm(b,a%b);
    }else{
        if(a==0)return b;
        return bmm(a,b%a);
    }
}

int find(int num1,int num2){
    int g=0;
    if(num1<mini) return 0;
    if(num2<mini) return 0;
    if(num1==num2){
        return 1;
    }
    if(num1>num2){
        if(num1%2==0) {
            g=find(num1/2,num2);
            if(g) {
                counter++;
                return 1;
            }
        }
        if(num1%3==0) {
            g=find(num1/3,num2);
            if(g) {
                counter++;
                return 1;
            }
        }
        if(num1%5==0) {
            g=find(num1/5,num2);
            if(g) {
                counter++;
                return 1;
            }
        }
    }
    else{
        if(num2%2==0) {
            g=find(num1,num2/2);
            if(g) {
                counter++;
                return 1;
            }
        }
        if(num2%3==0) {
            g=find(num1,num2/3);
            if(g) {
                counter++;
                return 1;
            }
        }
        if(num2%5==0) {
            g=find(num1,num2/5);
            if(g) {
                counter++;
                return 1;
            }
        }

    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int x;
    cin>>x;

        if(x==1) cout<<"-1";
        else{
                int test=0;
         while(x!=3){
            for(int i=2;i<=x;i++){
                if(x%i==0){
                    cout<<x<<" "<<i;
                    test=1;
                    break;
                }
            }
            if(test==1) break;
          x--;
         }

        }
}


#include <bits/stdc++.h>
using namespace std;
int a,b,c,i,n,f,g,k,x;

main() {
    cin>>x;
    if(x<=3 && x%2!=0) {
        cout<<-1;
    }

    else if(x%2==0) {
        cout<<x<<" "<<2;
    }
    else {
        cout<<x-1<<" "<<2;
    }

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin>>x;
    if(x==1 || x==4 )
        cout<<-1;
    else{
        cout<<x<<" "<<x;
    }
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e8;

int v[MAXN];
int main () {
    int x;
    cin >> x;
    if(x == 1) return puts("-1"), 0;

    cout << (x - (x&1)) << ' ' << 2 << '\n';
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<utility>
#include<queue>
#include<vector>
#include<set>
using namespace std;

typedef long long ll;
const int N=1e3+9;
const int M=1e9+7;

template<class T>void read(T &x){
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9')  {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x; return ;
}

ll Qpow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)(res*=a)%=M;
        (a*=a)%=M; b>>=1;
    }
    return res;
}

int n,m;
ll k,R,C;
ll a,b,c,d;

int main(){
    read(n); read(m); read(k); read(R); read(C);
    read(a); read(b); read(c); read(d);
    ll tot=n*m-((a!=c)||(b!=d))*R*C;
    printf("%lld",Qpow(k,tot));
}