#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define spc printf(" ")
#define sf scanf
#define pf printf
#define INF (LL)1e15
#define mod 1000000007
#define FI freopen("input.txt","r",stdin)
#define FO freopen("output.txt","w",stdout)
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
///#define safeMod(a, m) ((((a)%(m))+(m))%(m))/*handling negative sign of remainder*/
///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///#define triangle_area(a,b,m,n,x,y) (a*(n-y)+m*(y-b)+x*(b-n))/2.0
///#define dis_without_sqrt(x,y,x1,y1) (x-x1)*(x-x1)+(y-y1)*(y-y1)
///int ax[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ay[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
/*bool structCompare(struct_name first,struct_name second)
{
    return first.variable_name<second.variable_name //sorts element in increasing order
}*/

///using namespace __gnu_pbds;
using namespace std;

///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///int setb(int n,int pos){return n=n | (1 << pos);}
///int resb(int n,int pos){return n=n & ~(1 << pos);}
///int togb(int n,int pos){return n=n ^ (1 << pos);}
///bool checkb(int n,int pos){return (bool)(n & (1 << pos)); }
///lsb T = (S & (-S)),log2(T);
///inline bool isEq(double a, double b){return abs(a - b) < eps;}
///inline bool isEq(double a, double b, double eps){return abs(a - b) < eps;}
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=123456;
int main()
{
    //FI;
    //FO;
    //ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,m;
    while(cin>>n>>m)
    {
        ll ans=0;
        for(int i=1;i<=min(n,m);i++)
        {
            for(int j=1;j<=min(n,m);j++)
            {
                if((i*i+j*j)%m==0)
                {
                    ll x=(n-i)/m;
                    ll y=(n-j)/m;
                    x++;
                    y++;
                    ans+=(x*y);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod1=998244353,mod2=1e9+7;
const int N=2e6,MX=1e6;
ll n,c;
int tot,ans,lim,pw[N],sum[N];
vector<int> ve[N];
inline int dec(int x,int y,int mod){return (x-y<0)?x-y+mod:x-y;}
inline int add(int x,int y,int mod){return (x+y>=mod)?x+y-mod:x+y;}
inline void dfs(int pos,int now){
	if(now<=n){
		++tot;int x=dec(tot,now,mod1);
		ve[pos-1].push_back(x);sum[pos-1]=add(sum[pos-1],x,mod2);
	}
	if(pos>6) return ;
	for(int i=0;i<=9;++i) dfs(pos+1,now*10+i);
}
inline void solve(int pos,ll now){
	if(now>n) return ;
	if(pos>1){
		if(10ll*now*MX>n&&1ll*(now+1)*MX-1<=n){
			for(int i=0;i<7;++i){
				int x=((c-1ll*now*pw[i])%mod1+mod1)%mod1;
				int p=lower_bound(ve[i].begin(),ve[i].end(),mod1-x)-ve[i].begin();
				ans=add(ans,add(1ll*x*ve[i].size()%mod2,sum[i],mod2),mod2);
				ans=dec(ans,1ll*mod1*(ve[i].size()-p)%mod2,mod2);
			}
			c+=tot;
			return ;
		}
		++c,ans=add(ans,((c-now)%mod1+mod1)%mod1,mod2);
	}
	for(int i=(pos==1?1:0);i<=9;++i) solve(pos+1,now*10+i);
}
int main(){
	scanf("%lld",&n);
	pw[0]=1;for(int i=1;i<9;++i) pw[i]=10*pw[i-1];
	dfs(1,0);
	for(int i=0;i<7;++i)
		sort(ve[i].begin(),ve[i].end());
	solve(1,0);
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <assert.h>
#include <stack>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_set>
#include <set>
#include <time.h>
#include <unordered_map>
using namespace std;

char s[10];

int main()
{
	scanf("%s", s);
	int n = strlen(s);
	if (n == 1) {
		if (s[0] == '0' || s[0] == '_' || s[0] == 'X') printf("1\n");
		else printf("0\n");
		return 0;
	}
	if (s[0] == '0') {
		printf("0\n");
		return 0;
	}
	int ans = 0;
	int limits = 1;
	for (int i = 0; i < n; i++)
		if (s[i] == 'X') limits = 10;
	for (int x = 0; x < limits; x++) {
		int times = 1;
		int p = 0;
		for (int i = 0; i < n; i++)
			if (s[i] == 'X') {
				if (i == 0 && x == 0) {
					times = 0;
					break;
				}
			}
			else if (s[i] == '_') {
				if (i + 2 < n) {
					if (i == 0) times *= 9;
					else times *= 10;
				}
			}
		if (times == 0) continue;
		if (s[n - 2] == 'X' && s[n - 1] == 'X') {
			if ((10 * x + x) % 25 == 0) ans += times;
		} else if (s[n - 2] == 'X') {
			if (s[n - 1] == '_') {
				for (int i = 0; i < 10; i++)
					if ((10 * x + i) % 25 == 0) ans += times;
			} else if ((10 * x + s[n - 1] - '0') % 25 == 0) ans += times;
		} else if (s[n - 1] == 'X') {
			if (s[n - 2] == '_') {
				for (int i = n == 2 ? 1 : 0; i < 10; i++)
					if ((10 * i + x) % 25 == 0) ans += times;
			}
			else if ((10 * (s[n - 2] - '0') + x) % 25 == 0) ans += times;
		} else if (s[n - 2] == '_' && s[n - 1] == '_') {
			for (int i = n == 2 ? 1 : 0; i < 10; i++)
				for (int j = 0; j < 10; j++)
					if ((10 * i + j) % 25 == 0) ans += times;
		} else if (s[n - 2] == '_') {
			for (int i = n == 2 ? 1 : 0; i < 10; i++)
				if ((10 * i + s[n - 1] - '0') % 25 == 0) ans += times;
		} else if (s[n - 1] == '_') {
			int p = s[n - 2] - '0';
			for (int i = 0; i < 10; i++)
				if ((10 * p + i) % 25 == 0) ans += times;
		} else if ((10 * (s[n - 2] - '0') + (s[n - 1] - '0')) % 25 == 0) ans += times;

		bool flag = false;
		for (int j = 0; j < n; j++)
			if (s[j] == 'X') flag = true;
		if (!flag) break;
	}
	cout << ans << endl;
    return 0;
}


/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=998244353;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n,m,fact[2000005],inv[2000005];
signed main(){
	cin>>n>>m;fact[0]=1;
	for(int i=1;i<=2e6;i++)fact[i]=fact[i-1]*i%mod;
	inv[2000000]=modpow(fact[2000000],mod-2);
	for(int i=2e6-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	int v1=(1ll+n*modpow(m+1,mod-2)%mod)%mod,v2=1;
	for(int i=1;i<=n;i++){
		(v2+=m*fact[i-1]%mod*inv[i]%mod)%=mod;
	}
	cout<<v1*v2%mod<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 105;
int n,m;
int mp[maxn];
int a[maxn];
int main()
{
    cin>>n>>m;
    /*int mp[maxn];
    int a[maxn];*/
    int cnt;
    //memset(mp,0,sizeof(mp));
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]=1;
    }

    cnt=0;
    if(mp[m]==1) cnt++;
    for(int i=0;i<m;i++)
    {
        if(mp[i]==0)
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

vector<int>V, K, X;
int dp[77][77][77][3];
char s[77];

void mmin(int &x, int y) { if(x > y) x = y; }

int getdis(int p1, int p2, int p3, int val) {
	int res = 0;
	for(int i = p1; i < (int)V.size() && V[i] < val; ++ i) ++ res;
	for(int i = p2; i < (int)K.size() && K[i] < val; ++ i) ++ res;
	for(int i = p3; i < (int)X.size() && X[i] < val; ++ i) ++ res;
	return res;
}

int main () {
	int n; scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; ++ i) {
		if(s[i] == 'V') V.push_back(i);
		else if(s[i] == 'K') K.push_back(i);
		else X.push_back(i);
	}
	memset(dp, 0x3f, sizeof dp), dp[0][0][0][2] = 0;
	for(int i = 0; i <= (int)V.size(); ++ i) {
		for(int j = 0; j <= (int)K.size(); ++ j) {
			for(int k = 0; k <= X.size(); ++ k) {
				for(int l = 0; l < 3; ++ l) {
					if(i < (int)V.size()) {
						mmin(dp[i + 1][j][k][0], dp[i][j][k][l] + getdis(i, j, k, V[i]));
					}
					if(j < (int)K.size() && l != 0) {
						mmin(dp[i][j + 1][k][1], dp[i][j][k][l] + getdis(i, j, k, K[j]));
					}
					if(k < (int)X.size()) {
						mmin(dp[i][j][k + 1][2], dp[i][j][k][l] + getdis(i, j, k, X[k]));
					}
				}
			}
		}
	}
	int ans = 1e9;
	for(int i = 0; i < 3; ++ i) mmin(ans, dp[(int)V.size()][(int)K.size()][(int)X.size()][i]);
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
mat mul(mat a,mat b,ll mod)
{
    mat c(a.size(),vec(b[0].size()));
    for(int i=0;i<a.size();i++)
    {
        for(int k=0;k<a[0].size();k++)
        {
            for(int j=0;j<b[0].size();j++)
            {
                c[i][j]=(c[i][j]+a[i][k]*b[k][j]%mod)%mod;
            }
        }
    }
    return c;
}
mat q_pow(mat base,ll n,ll mod)
{
    mat ans(base.size(),vec(base.size()));
    for(int i=0;i<ans.size();i++)ans[i][i]=1;
    while(n)
    {
        if(n&1)ans=mul(ans,base,mod);
        base=mul(base,base,mod);
        n>>=1;
    }
    return ans;
}
int main()
{
    ll n,sx,sy,dx,dy,t;
    while(~scanf("%lld%lld%lld%lld%lld%lld",&n,&sx,&sy,&dx,&dy,&t))
    {
        sx--;
        sy--;
        mat a(6,vec(6));
        a={
            {2,1,1,0,1,2},
            {1,2,0,1,1,2},
            {1,1,1,0,1,2},
            {1,1,0,1,1,2},
            {0,0,0,0,1,1},
            {0,0,0,0,0,1}
          };
          a=q_pow(a,t,n);
          mat b(6,vec(1));
          b[0][0]=sx;
          b[1][0]=sy;
          b[2][0]=(dx%n+n)%n;
          b[3][0]=(dy%n+n)%n;
          b[4][0]=0;
          b[5][0]=1;
          a=mul(a,b,n);
          printf("%lld %lld\n",a[0][0]+1,a[1][0]+1);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[51], b[10000];
int main() {
	int n, i, j, x, s = 0;
	cin >> n;
	for (i = n; i >= 1; i--)
		cin >> a[i];
	for(i=1;i<=n;i++){
		if (b[a[i]] == 0) {
			b[a[i]] = 1;
			a[++s] = a[i];
		}
	}
	cout << s << endl;
	for (i = s; i>=1; i--) {
		cout << a[i];
		if (i != 1)
			cout << " ";
	}
	return 0;
}


#include<bits/stdc++.h>
#define N 1000005
#define inf 1e9
#define file freopen("1.txt","r",stdin)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll f[4005][4005],g[4005][4005],mod=998244353;
ll ans;

ll qpow(ll a,ll n)
{
	ll res=1;
	while(n)
	{
		if (n&1) res=res*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return res;
}

int main()
{
	ll n,k,l;
	cin>>n>>k>>l;
	f[0][0]=1;
	for (int i=0;i<n+n;i++)
	{
		for (int j=i&1;j<=i;j+=2)
		{
			if (j>=k) (g[i][j]+=f[i][j])%=mod;
		}
		for (int j=i&1;j<=i;j+=2)
		{
			(f[i+1][j+1]+=f[i][j])%=mod;
			(g[i+1][j+1]+=g[i][j])%=mod;
			if (j)
			{
				(f[i+1][j-1]+=f[i][j]*j)%=mod;
				(g[i+1][j-1]+=g[i][j]*j)%=mod;
			}
		}
	}
	cout<<g[n+n][0]*qpow(f[n+n][0],mod-2)%mod*l%mod*qpow(n+n+1,mod-2)%mod<<endl;
}


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

int chk_diagonal (int i, int j, char arr[11][11], int );
int chk_horizontal (int i, int j, char arr[11][11], int);
int chk_vertical (int i, int j, char arr[11][11], int);
int chk_Rdiagonal (int i, int j, char arr[11][11], int );

int main ()
{
	int i, j, ans1, ans2, ans3, ind, ans4;
	char arr[11][11];
	char c;
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			cin>>c;
			arr[i][j] = c;
		}
	}
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			if (arr[i][j] == 'X' || arr[i][j] == '.') {
			//	cout<<"i j "<<i<<" "<<j<<endl;
				if (arr[i][j] == 'X') {
					ind = 1;
				//	cout<<"yes"<<endl;
				}
				if (arr[i][j] == '.') {
					ind = 0;
				//	cout<<"yes11"<<endl;
				}
				ans1 = chk_vertical (i, j, arr, ind);
				//cout<<"ans1 "<<ans1<<endl;
				if (ans1 == 1) {
					cout<<"YES"<<endl;
					return 0;
				}

				ans2 = chk_horizontal (i, j, arr, ind);
				//cout<<"ans2 "<<ans2<<endl;
				if (ans2 == 1) {
					cout<<"YES"<<endl;
					return 0;
				}
				ans3 = chk_diagonal (i, j, arr, ind);
				//cout<<"ans3 "<<ans3<<endl;
				if (ans3 == 1) {
					cout<<"YES"<<endl;
					return 0;
				}
				ans4 = chk_Rdiagonal (i, j, arr, ind);
				if (ans4 == 1) {
					cout<<"YES"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

int chk_Rdiagonal (int i, int j, char arr[11][11], int ind)
{
	int inc = 0, l, r, dinc = 0;
	for (l = i, r = j; l <= i+4 && l <= 9 && r <= 9; l++, r--) {
		if (arr[l][r] == 'X') {
			//cout<<"l is r is "<<l<<" "<<r<<endl;
			inc += 1;
		}
		//cout<<"inc "<<inc<<endl;
		if (arr[l][r] == 'O') {
			return 0;
		}
		if (arr[l][r] == '.' && dinc == 0) {
			dinc += 1;
		}
		if (inc == 4 && dinc == 1) {
			return 1;
		}
	}
	return 0;
}
int chk_diagonal (int i, int j, char arr[11][11], int ind)
{
	int inc = 0, l, r, dinc = 0;
	for (l = i, r = j; l <= i+4 && l <= 9; l++, r++) {
		if (arr[l][r] == 'X') {
			//cout<<"l is r is "<<l<<" "<<r<<endl;
			inc += 1;
		}
		//cout<<"inc "<<inc<<endl;
		if (arr[l][r] == 'O') {
			return 0;
		}
		if (arr[l][r] == '.' && dinc == 0) {
			dinc += 1;
		}
		if (inc == 4 && dinc == 1) {
			return 1;
		}
	}
	return 0;
}
int chk_horizontal (int i, int j, char arr[11][11], int ind)
{
	int inc = 0, l, dinc = 0;
	for (l = i; l <= i+4 && l <= 9; l++) {
		if (arr[l][j] == 'X') {
			inc += 1;
		}
		if (arr[l][j] == 'O') {
			return 0;
		}
		if (arr[l][j] == '.' && dinc == 0) {
			dinc += 1;
		}
		if (inc == 4 && dinc == 1) {
			return 1;
		}
	}
	return 0;
}
int chk_vertical (int i, int j, char arr[11][11], int ind)
{
	int inc = 0, l, dinc = 0;
	for (l = j; l <= j+4 && l <= 9; l++) {
		if (arr[i][l] == 'X') {
			inc += 1;
		}
		if (arr[i][l] == 'O') {
			return 0;
		}
		if (arr[i][l] == '.' && dinc == 0) {
			dinc += 1;
		}
		if (inc == 4 && dinc == 1) {
			return 1;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) (int)v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define gcd __gcd
#define mp make_pair
#define FO(i, a) for(auto & i : a)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
#define SET(a, b) memset(a, b, sizeof(a));
#define refresh fflush(stdout);
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pii> vii;
typedef vector <pll> vll;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

string v[4][4][4];

main()
{
	IOS

	int k = 0;

	for(int i = 1; i <= 3; i++)
		for(int j = 1; j <= 3; j++)
			for(int k = 1; k <= 3; k++)
				cin >> v[i][k][j];

	int x, y;
	cin >> x >> y;

	x %= 3;
	y %= 3;

	x = (x == 0) ? 3 : x;
	y = (y == 0) ? 3 : y;

	bool ok = 0;

	for(int i = 1; i <= 3; i++)
		for(int j = 0; j < 3; j++)
			if(v[x][y][i][j] == '.')
				v[x][y][i][j] = '!', ok = 1;

	if(ok == 0)
		for(int i = 1; i <= 3; i++)
			for(int j = 1; j <= 3; j++)
				for(int k = 1; k <= 3; k++)
					for(int t = 0; t < 3; t++)
						if(v[i][k][j][t] == '.')
							v[i][k][j][t] = '!';

	for(int i = 1; i <= 3; i++, cout << '\n')
		for(int j = 1; j <= 3; j++, cout << '\n')
			for(int k = 1; k <= 3; k++)
				cout << v[i][k][j] << ' ';
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <fstream>
#include <stack>
#include <ctime>
#include <map>
#include <list>
#include <functional>
#include <bitset>
#include <set>
#include <limits.h>

using namespace std;
#define READ(s) freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
typedef pair<int, int> pii;
typedef pair<int, bool> pib;

long long n, p;

bool check(long long pipes)
{
    return 1 + pipes * p - pipes * (pipes + 1) / 2 >= n;
}

int main()
{
    cin >> n >> p;
    if (1 + (p - 1) * p / 2 < n)
        cout << -1 << endl;
    else
    {
        int low = 0, high = p - 1, mid, answer;
        while (low <= high)
        {
            mid = (high + low) / 2;
            if (check(mid))
            {
                answer = mid;
                high = mid - 1;
            }
            else
                low = mid + 1;
        }
        cout << answer << endl;
    }
    return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;

#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfl(x) scanf("%I64d" , &x)
#define sfl2(x, y) scanf("%I64d%I64d" , &x,&y)
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfd(x) scanf("%lf", &x)
#define sfd2(x) scanf("%lf", &x)
#define sfc(x) scanf("%c", &x)
#define sfd2(x, y) scanf("%lf%lf", &x, &y)
#define mod 1000000007
#define pi (2*acos(0))
typedef long long ll;
#define endl '\n'

int main()
{
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    for (int i = 0; i < b - 1; i++)
        x--;
    if (x < 0)
    {
        for (int i = 0; i < a - 1; i++)
            y--;
        if (y < 0)
            cout << "NO";
        else
        {
            y -= 2;
            for (int i = 0; i <= a && y > 0; i++)
                y--;
            if (y <= 0)
                cout << "YES";
            else
                cout << "NO";
        }
    }
    else
    {
        x -= 2;
        for (int i = 0; i <= b && x > 0; i++)
            x--;
        if (x > 0)
        {
            for (int i = 0; i < a - 1; i++)
                y--;
            if (y < 0)
                cout << "NO";
            else
            {
                y -= 2;
                for (int i = 0; i <= a && y > 0; i++)
                    y--;
                if (y <= 0)
                    cout << "YES";
                else
                    cout << "NO";
            }
        }
        else
            cout << "YES";
    }
    return 0;
}


#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(0)
typedef long long int ll;
using namespace std;
const int MOD=1e9+7;
const int size=1e5+1;

ll a[size];
ll b[size];
ll c[size];
ll d[size];

ll n;
ll anss(vector<ll> lll)
{
	sort(lll.begin(), lll.end());
	ll ans=0;
	int nn=lll.size();
	//for(auto i : lll)
	//	cout << i << " ";
	//cout << endl;
	//cout << lll.size() << endl;
	for(int i=0;i<nn/2;i++)
		ans+=lll[2*i+1]-lll[2*i];
	//cout << ans << endl;
	return ans;
}
int main()
{
	srand (time(NULL));
	fast_cin();
	memset(a,0,sizeof(a));
	cin >> n;
	ll minn=100000000;
	for(int i=0;i<2*n;i++)
		cin >> a[i];
	for(int i=0;i<2*n;i++)
	{
		for(int j=i+1;j<2*n;j++)
		{
			vector<ll> lll;
			for(int ii=0;ii<2*n;ii++)
			{
				if(ii!=i&&ii!=j)
				{
					lll.push_back(a[ii]);
				}
			}
			minn=min(anss(lll),minn);
		}
	}
	cout << minn;
}


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

using namespace std;

char s[10000];
int main () {
	int n;
	cin >> n;
	scanf("%s",s+1);
	for (int i=1; i<n; ++i) {
		if (s[i]==s[i+1] && s[i] != '?') {printf("No");return 0;}
	}
	int t = 0;
	for (int i=1; i<=n; ++i) {
		if (s[i]=='?') {
			//if (s[i+1]!= s[i-1]&&s[i-1]!='?'&&s[i+1]!='?') t++;
			//else {printf("Yes");return 0;}
			if (s[i+1]=='?'||(s[i-1]==s[i+1]&&s[i-1]!='?'))
			{printf("Yes");return 0;}
		}
	}
	if (s[1] == '?' || s[n]=='?') {printf("Yes");return 0;}
	printf("No");
	return 0;
}


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

struct stuffing {
    int a, b, c, d;
};

stuffing make_stuffing(int w, int x, int y, int z) {
    stuffing s;
    s.a = w;
    s.b = x;
    s.c = y;
    s.d = z;
    return s;
}

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

	int n, m, c0, d0;
	cin >> n >> m >> c0 >> d0;
	int dp[m + 1][n + 1];
	memset(dp, 0, sizeof(dp));
	stuffing s[m + 1];

	for (int i = 1; i <= m; i++) {
	    int a, b, c, d;
	    cin >> a >> b >> c >> d;
	    s[i] = make_stuffing(a, b, c, d);
	}

	for (int i = c0; i <= n; i++) dp[0][i] = dp[0][i - c0] + d0;

	for (int i = 1; i <= m; i++) {
	    for (int j = 1; j <= n; j++) {
	        int m = dp[i - 1][j];
	        for (int dou = 0, st = 0, l = 0; st <= s[i].a && j - dou >= 0; dou += s[i].c, l++, st += s[i].b) {
	            m = max(m, dp[i - 1][j - dou] + l * s[i].d);
	        }
	        dp[i][j] = max(m, dp[i][j - 1]);
	    }
	}

	cout << dp[m][n] << endl;
}


//////// Kelvin 2016
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <unordered_map>
#include <complex>
#include <ctime>
#include <fstream>
#include <sstream>
//#include <windows.h>
//#include <stdint.h>
using namespace std;
const double PI = (acos(-1.0));
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
#define forn(i,s,n) i = (s); for( int _n = (int)(n), _di = (i > _n)?-1:1; i != _n; i += _di)
#define foreach(it,c) for ( auto it = (c).begin(); it!=(c).end(); it++)
#define endl '\n'

template<typename T> struct Point
{
	T x, y;
	Point(T ix = 0, T iy = 0):x(ix),y(iy){}
	Point& operator -= (const Point &b){ x -= b.x; y -= b.y; return *this; }
	Point operator - (const Point &b){ Point res = *this; res -= b; return res; }

	friend T dot(const Point &a, const Point &b) //|a||b|cosθ // 0 90 180 270 360 //x
	{														  // 1  0  -1  0  1
		return a.x*b.x + a.y*b.y;
	}
	friend T cross(const Point &a, const Point &b)  //|a||b|sinθ // 0 90 180 270 360 //y
	{															 // 0  1  0  -1  0
		return a.x*b.y - a.y*b.x;
	}
	friend double dist(const Point &a)
	{
		return sqrt(double(a.x*a.x + a.y*a.y));
	}
	friend T sdist(const Point &a)
	{
		return a.x*a.x + a.y*a.y;
	}
	bool operator < (const Point &b)
	{
		const Point &a = *this;
		bool ka = a.y<0 || a.y==0 && a.x<0;
		bool kb = b.y<0 || b.y==0 && b.x<0;
		return  ka < kb || ka==kb && cross(a, b)>0;
	}
	Point& operator *= (const Point &b)  //yg = yb - ya
	{
		T tx = dot(*this, b);
		y = cross(*this, b);
		x = tx; return *this;
	}
	Point operator * (const Point &b){ Point res = *this; res *= b; return res; }
};

typedef Point<int> point;

int main()
{
	ll n, m;
	cin>>n;
	m = 2*n-2-n-1;
	cout<<(1ll<<(m*2))*(m*9+4*6)<<endl;
	return 0;
}
        // m
//343 36 4*1*3*3
//434 96 4*4*3*2


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
#define mod 998244353
li res;
class dop
{public:
li n,p,q,r,e,f,g;
vector<pair<li,li>> a;
void get();
};
void dop::get()
{cin>>n;
for(li i=0;i<((4*n)+1);i++){cin>>p>>q;a.push_back(make_pair(p,q));}
for(li i=0;i<((4*n)+1);i++){r=1e18;e=-1e18;f=1e18;g=-1e18;
    for(li j=0;j<((4*n)+1);j++){if(j==i){continue;}
r=min(a[j].first,r);e=max(e,a[j].first);f=min(a[j].second,f);g=max(g,a[j].second);
}bool y=true;
for(li j=0;j<((4*n)+1);j++){if(j==i){continue;}
if((a[j].first==r||a[j].first==e)||(a[j].second==f||a[j].second==g)){continue;}y=false;break;}
if(abs(r-e)!=abs(f-g)){y=false;}
if(y){
p=a[i].first;q=a[i].second;
if(p!=r&&p!=e&&p!=f&&p!=g){cout<<p<<" "<<q<<'\n';return ;}
if((p>e||p<r)){cout<<p<<" "<<q<<'\n';return ;}
if((q>g||q<f)){cout<<p<<" "<<q<<'\n';return ;}
}}
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t=1;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include "bits/stdc++.h"

#define ll long long

using namespace std;

const ll MOD = 998244353;

ll exp(ll a, ll x){
    if(x == 0) return 1;
    ll tmp = exp(a, x/2);
    tmp *= tmp;
    tmp %= MOD;
    if(x%2) tmp *= a;
    tmp %= MOD;
    return tmp;
}

ll inv(ll x){
    return exp(x, MOD - 2);
}

ll n, m, k;
// tot elem, distinct elem
vector<vector<ll>> dp;
int main(){
    cin >> n >> m >> k;
    dp.assign(k + 1, vector<ll>(k + 1, 0));
    dp[0][0] = 1;
    for(ll i = 1; i <= k; ++i){
        for(ll j = 1; j <= k; ++j){
            dp[i][j] = (dp[i - 1][j] * j) % MOD + (dp[i - 1][j - 1] * (n - j + 1)) % MOD;
            dp[i][j] %= MOD;
        }
    }
    // for(auto i : dp[k]) cout << i << " ";
    // cout << "\n";
    ll res = 0;
    for(ll i = 1; i <= k; ++i){
		res = (res + (dp[k][i] * exp(inv(m), i)) % MOD) % MOD;
    }
    cout << res;
}


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

ll f[30];

ll solve(ll n){
    if(n <= 6) return n;
    ll r1 = 1e9, r2 = 1e9;

    for(int i = 0; i < 20; i++)
        if(f[i] > n){
            r1 = solve(n%f[i-1]) + i*(n/f[i-1]);
            break;
        }
    for(int i = 0; i < 20; i++)
        if(f[i] >= n){
            if(f[i]-n >= n) r2 = 1e9;
            else r2 = solve(f[i] - n) + (i+1);
            break;
        }

    return min(r1,r2);
}

int main(){

    f[0] = 1;
    for(int i = 1; i < 18; i++)
        f[i] = f[i-1]*10 + 1;

    ll n; cin >> n;
    cout << solve(n) << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define int long long
const int N=50,INF=INT_MAX;

int n,k,m;
int t[N];

int dp[N][N*N];
int32_t main()
{
    //freopen("input.txt","r",stdin);
    //freopen("forest.in","r",stdin);
    //freopen("forest.out","w",stdout);
    cin>>n>>k>>m;
    for(int i=1;i<=k;++i)
        cin>>t[i];
    sort(t,t+k+1);
    for(int i=0;i<=n;++i)
        for(int p=0;p<=n*k+n;++p)
            dp[i][p]=INF;
    dp[0][0]=0;
    for(int i=0;i<n;++i)
    {
        for(int p=0;p<=n*k+n;++p)
        {
            int tt=0;
            for(int j=0;j<=k;++j)
            {
                tt+=t[j];
                dp[i+1][p+j+(j==k)]=min(dp[i+1][p+j+(j==k)],dp[i][p]+tt);
            }
        }
    }
    int ans=0;
    for(int p=0;p<=n*k+n;++p)
    {
        if(dp[n][p]<=m)
            ans=max(ans,p);
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
using namespace std;
long long n;
int main()
{
    cin>>n;
    if(n%2==1)
    {
        cout<<"black";
        return 0;
    }
    cout<<"white"<<endl;
    cout<<1<<" "<<2;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long  int x,y,z,a,b,c,r,n;
    cin>>x>>y>>z;
    cin>>a>>b>>c;
    if(a>=x)
    {
        r=a-x;
        if(r+b>=y||b>=y)
        {
            n=(a+b)-(x+y);
            if(c>=z||n>=z||(n+c)>=z)
            {

                cout<<"YES"<<endl;
            }
            else
                cout<<"NO"<<endl;
        }
        else
            cout<<"NO"<<endl;
    }
    else
        cout<<"NO"<<endl;

}


#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define N 4010
#define mo 1000000009
#define int64 long long
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,w,b;
int64 f1[N],f2[N],an;
inline int64 C(int n,int m) {
    if (m>n) return 0;
    if (!m) return 1;
    return f1[n]*f2[m]%mo*f2[n-m]%mo;
}
int main() {
    f1[0]=1;
    For(i,1,N-1) f1[i]=f1[i-1]*i%mo;
    f2[0]=f2[1]=1;
    For(i,2,N-1) f2[i]=(-f2[mo%i]*(mo/i)%mo+mo)%mo;
    For(i,2,N-1) f2[i]=f2[i]*f2[i-1]%mo;
    scanf("%d%d%d",&n,&w,&b);
    For(i,1,n-2) an=(an+f1[w]*f1[b]%mo*C(b-1,i-1)%mo*C(w-1,n-i-1)%mo*(n-i-1))%mo;
    printf("%I64d",an);  return 0;
}


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

long long two[2001][2001];

int f=0;

long long coun(int n, int m, int k)
{
    if(two[n][k]!=-1) return two[n][k];
//    if(f==0){
//        f=1;
//        return two[n][k]=(m%mod*coun(n, m, k)%mod)%mod;
//    }
    if(k==0) return 1;
    if(n==0) return 0;

    return two[n][k]=((((((m-1)%mod*coun(n-1, m, k-1)%mod)%mod)%mod+((coun(n-1, m, k)%mod))%mod))%mod)%mod;

}

int main()
{

    long long i, j, l, a, c, b, n, m, k;

    cin>>n>>m>>k;
    memset(two, -1, sizeof(two));

    cout<<(m%mod*coun(n-1, m, k)%mod)%mod;

    return 0;
}


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

using namespace std;

char buf[1<<23],*fc=buf,*tc=buf;
inline char gc()
{
    if(fc==tc)
    {
        tc=(fc=buf)+fread(buf,1,1<<23,stdin);
        if(fc==tc) return EOF;
    }
    return *fc++;
}
// #define  getchar gc
#define il inline
il int read()
{
    int x=0,f=1; char ch;
    while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return f*x;
}
#define res register int

const int N=5e2+10;
const int c[4][4]={{0,0,0,0},{0,-1,3,4},{0,3,-1,-1},{0,4,-1,-1}};
int n,a[N];
int ans=0;

int main()
{
    n=read();
    for(res i=1; i<=n ; ++i) a[i]=read();
    for(res i=2 ; i<=n ; ++i)
    {
        if(c[a[i-1]][a[i]]==-1) return puts("Infinite"),0;
        ans+=c[a[i-1]][a[i]];
        if(i>=3 && a[i-2]==3 && a[i-1]==1 && a[i]==2) --ans;
    }
    puts("Finite");
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
long long f(long long x,long long y)
{
	long long num;
	num=x*x+y*y;
	return num;
}
int main()
{
	long long ax,ay,bx,by,cx,cy;
	cin>>ax>>ay>>bx>>by>>cx>>cy;
	if((ax+cx)==2*bx&&(ay+cy)==2*by)
	{
		cout<<"No"<<endl;
	}
	else
	{
		if(f((ax-bx),(ay-by))==f((bx-cx),(by-cy)))
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <deque>
#include <chrono>
#include <cassert>
#include <bitset>
#include <random>

using namespace std;

typedef long long li;
typedef  long double ld;
const li MAX = 2e5 + 5;

li inf = (li)30000;
li mod = (li)998244353;
li n, k, a[MAX], f[MAX], rev[MAX], power[MAX], any[MAX];

li bin(li num, li power) {
    if (power == 0) return 1;
    else {
        li ret;
        if (power & 1) ret = (num * bin(num, power - 1)) % mod;
        else {
            ret = bin(num, power / 2);
            ret = (ret * ret) % mod;
        }
        return ret;
    }
}

li c(li n, li k) {
    return (((f[n] * rev[n - k]) % mod) * rev[k]) % mod;
}

void solve() {
    cin >> n >> k;
    f[0] = 1;
    any[0] = 1;
    rev[0] = 1;
    power[0] = 1;
    for (int i = 1; i < MAX; i++) {
        f[i] = (f[i - 1] * i) % mod;
        any[i] = (any[i - 1] * (k - 2)) % mod;
        rev[i] = (bin(i, mod - 2) * rev[i - 1]) % mod;
        power[i] = (power[i - 1] * 2) % mod;
    }

    li m = 0, ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
        if (a[i] != a[(i + 1) % n])m++;
    }

    for (int i = 1; i <= m; i++) {
        li ad;
        if (i % 2 == 1) ad = (((c(m, i) * power[i]) % mod) * rev[2]) % mod;
        else {
            li act = (power[i] + mod - c(i, i / 2)) % mod;
            ad = (((c(m, i) * act) % mod) * rev[2]) % mod;
        }
        ad *= any[m - i];
        ans += ad;
        ans %= mod;
    }

    for (int i = 0; i < n - m; i++) ans = (ans * k) % mod;
    cout << ans;
}

int main() {
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    ios::sync_with_stdio(0);
    li q;
    q = 1;
    while (q--) solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long n,m,k,c=1,s=1;
int main(){
	cin>>n>>m>>k;
	m-=n;
	while(m>0){
		if(k-c>=1)s++;
		if(k+c<=n)s++;
		m-=s;
		c++;
	}
	cout<<c;
	return 0;
}


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

typedef long long ll;
#define PI acos(-1.0) // important constant; alternative #define PI (2.0 * acos(0.0))
#define EPS 1e-9

int conversion(string p){ int o; o=atoi(p.c_str()); return o; }
string toString(int h){ stringstream ss; ss<<h; return ss.str(); }
long long gcd(long long a,long long b) {return (b==0 ? a : gcd(b,a%b));}
long long lcm(long long a,long long b) {return (a*(b/gcd(a,b))); }
int toi(string p){int x;istringstream in(p); in>>x; return x;}
// IMPRMIR DECIMALES -> %.3f
// Logaritmo en cualquir base ( nota: solo cambiar el 2 ) printf("Case %d: %.0lf\n", cnt++, max(0.0,ceil(log(n) / log(2))));

ll a,b,x,y;
bool go(ll n)
{
    ll ab,ba,c,mm,nn,xx,yy,tt;
    ab=n/x;
    ba=n/y;
    c=n/(x*y);
    mm=a;nn=b;
    ab-=c;ba-=c;
    mm-=ba;nn-=ab;
    if(mm<0) mm=0;
    if(nn<0) nn=0;
    tt=n-ab-ba-c;
    if(mm+nn<=tt) return true;
    return false;
}

int main(){

     #ifndef ONLINE_JUDGE
     freopen("D:/input.txt","r",stdin);
     //freopen("D:/output.txt","w",stdout);
     #endif

    ll maxi=0,n,m,l=0,h=10000000000LL;
    cin>>a>>b>>x>>y;
    while(h-l>1)
    {
        m=(h+l)/2LL;
        if(go(m)) h=m;
        else l=m;
    }
    cout<<h<<endl;
}


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

ll n,x;
vector<ll>v;
///vector<pair<ll,ll> >v2;
int main(){

     cin>>n>>x;
     if(n==1) { cout<<1;return 0; }
     ll left, right;
     left=abs(1-x);
     right=abs(n-x);

     if(left==right) {
     	if(x-1>=1)cout<<x-1<<endl;
        else if (x+1<=n)cout<<x+1<<endl;
        else cout<<x<<endl;
        return 0;
     }
     else if(left>right) {

     	cout<<max(1LL,x-1)<<endl;

     }
     else cout<<min(n,x+1)<<endl;
}

///author-joydip007x         ///
///Time&Date-Whenever i submit///


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	ignore = scanf("%d", &n);
	int a = 1, b = 2;
	while (b < n) {
		int s = a + b + (a % 2);
		a = s;
		b = s + 1;
	}

	int ans = (a == n || b == n) ? 1 : 0;
	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define s second
#define f first
typedef long long ll;
const int N = 35005, M = 60;
int n, m, a[N];
vector<ll> vec;

int solve()
{
    int l = 0, r = n/2;
    int sz = r - l + 1;
    vec.push_back(0);
    for(ll mask=0, sum = 0; mask<(1<<sz); mask++)
    {
        sum = 0;
        for(int i=l; i<=r; i++) sum += a[i]*!(!(mask&(1<<(i-l))));
        sum %= m;
        vec.push_back(sum);
    }
    sort(vec.begin(), vec.end());
    l = r+1, r = n-1;
    sz = r - l + 1;
    ll ret = 0;
    for(ll mask=0, sum = 0; mask<(1<<sz); mask++)
    {
        sum = 0;
        for(int i=l; i<=r; i++) sum += a[i]*!(!(mask&(1<<(i-l))));
        sum %= m;
        ret = max(ret, sum + vec[upper_bound(vec.begin(), vec.end(), m-sum-1)-vec.begin()-1]);
    }
    return ret;
}
int main()
{
    cin >> n >> m;
    for(int i=0; i<n; i++) cin >> a[i];
    cout << solve() << endl;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
const int MAXN = 26;
map<long long, int> mp[15];
long long jc[MAXN];
int n, k, kd, ed;
long long s;
long long num[MAXN];
long long ans = 0;
void dfs(int now, long long tot, int kkk)
{
    if (tot > s || kkk > k)
        return;
    if (now > ed)
    {
        if (kd == 0)
            mp[kkk][s - tot]++;
        else
        {
            for (int i = 0; i <= k - kkk && i <= n / 2; i++)
                ans += mp[i][tot];
        }
        return;
    }
    dfs(now + 1, tot, kkk);
    dfs(now + 1, tot + num[now], kkk);
    if (num[now] <= 20)
        dfs(now + 1, tot + jc[num[now]], kkk + 1);
}
int main()
{
    jc[0] = 1;
    for (int i = 1; i <= 20; i++)
        jc[i] = jc[i - 1] * i;
    scanf("%d%d%lld", &n, &k, &s);
    for (int i = 1; i <= n; i++)
        scanf("%d", &num[i]);
    sort(num + 1, num + 1 + n);
    kd = 0, ed = n / 2;
    dfs(1, 0, 0);
    kd = 1, ed = n;
    dfs(n / 2 + 1, 0, 0);
    printf("%lld\n", ans);
    return 0;
}


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

#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)

ll phi(ll x)
{
	ll res=x;
	for(ll i=2;i*i<=x;i++)
	{
		if(x%i==0)
		{
			while(x%i==0) x/=i;
			res-=(res/i);
		}
	}

	if(x>1)
	{
		res-=(res/x);
	}

	return res;
}

ll p=1e9+7;

void solve()
{
  ll n,k;
  cin>>n>>k;
  k=(k+1)/2;
  while(k--)
  {
	  n=phi(n);
	  if(k==0 || n==1) break;
  }

  cout<<(n%p)<<endl;
}

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

    ll TestCase=1;
    //cin>>TestCase;

    while(TestCase--)
    {
      solve();
    }

    return 0;
}


#include <cstdio>
typedef long long int LL;
const int MAXN = 200005, MAXV = 1000005;
const LL MOD = 1000000007LL;

int cnt[MAXV], n, k, q, phi[MAXV], prime[MAXV], pcnt;
LL ans, f[MAXN], inv[MAXN];

void preCalc(){
	int i, j; phi[1] = 1;
	for(i = 2; i < MAXV; ++ i){
		if(!phi[i]){
			prime[++ pcnt] = i;
			phi[i] = i - 1;
		}
		for(j = 1; i * prime[j] < MAXV; ++ j)
			if(i % prime[j]) phi[i * prime[j]] = phi[i] * phi[prime[j]];
			else{
				phi[i * prime[j]] = phi[i] * prime[j];
				break;
			}
	}
}
inline LL C(int n, int m){
	if(n < m) return 0LL;
	return (f[n] * inv[m] % MOD) * inv[n - m] % MOD;
}
void update(int pos){
	ans = (ans - (C(cnt[pos], k) * phi[pos] % MOD) + MOD) % MOD;
	ans = (ans + C(++ cnt[pos], k) * phi[pos]) % MOD;
}
void insert(int val){
	for(int i = 1; i <= val / i; ++ i){
		if(val % i) continue;
		update(i);
		if(i * i != val) update(val / i);
	}
}
int main(){
	int i, t; preCalc();
	scanf("%d%d%d", &n, &k, &q);
	for(i = f[0] = 1; i <= n + q; ++ i)
		f[i] = f[i - 1] * i % MOD;
	for(inv[0] = inv[1] = 1LL, i = 2; i <= n + q; ++ i)
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
	for(i = 1; i <= n + q; ++ i) inv[i] = inv[i] * inv[i - 1] % MOD;
	for(i = 1; i <= n; ++ i){
		scanf("%d", &t);
		insert(t);
	}
	for(i = 1; i <= q; ++ i){
		scanf("%d", &t);
		insert(t);
		printf("%I64d\n", ans);
	}
	return 0;
}


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

int main(){
    long long n, m, k=0, a[1000101]={0}, b[1000101]={0};
    string s;
    cin>>n>>m;
    a[0]=1;
    for(int i=1;i<=3000; i++)
        a[i]=(a[i-1]*2)%998244353;
    cout<<a[n+m];
        //  cout.precision(6);
    //system("pause");
    return 0;
}


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

using namespace std;

char s[32768];
char ans[32768];

int main() {
	ios_base::sync_with_stdio(0);
	cin.getline(s, sizeof(s));
	int n = (int)strlen(s);
	int def = 0;
	for (int i = 0; i < n; i++) def += (int)(s[i] - '0');
	int ret = def;
	strcpy(ans, s);
	//
	for (int i = n - 1; i >= 0; i--) {
		int cnt = 0;
		if (s[i] != '0') {
			cnt = def - 1;
			for (int j = i + 1; j < n; j++) {
				cnt += (int)('9' - s[j]);
			}
		}
		if (cnt > ret) {
			ret = cnt;
			ans[i] = s[i] - 1;
			for (int j = i + 1; j < n; j++) {
				ans[j] = '9';
			}
		}
	}
	int from = 0;
	while (ans[from] == '0') from++;
	cout << (ans + from) << "\n";
	//
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

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

#define PI 3.14159265358979323846
#define PO << " " <<
#define P " "
#define ABS(x) (((x) > 0) ? (x) : (-(x)))
#define RND(x) ((int)( (x) + 0.5 ))
#define MAX(x, y) (( (x) > (y) ) ? (x) : (y))
#define MIN(x, y) (( (x) < (y) ) ? (x) : (y))
#define forn(i, n) for (int i = 0; i < n; i++)
#define it(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int lint;
typedef unsigned long long int ulint;
typedef std::pair <int, int> pint;

lint f(lint n, lint k){
	lint ttt = 1;
	for (lint i = 1; i <= n; i++){
		if ((k - (ttt) )% (ttt*2) == 0){
			return i;
		}
		ttt *= 2;
	}
}

int main(){
	lint n, k; cin >> n>> k;
	cout << f(n, k);
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <locale>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define per1(i, a, b) for(int i = a; i >= b; --i)
#define DRI(A) int A; scanf("%d", &A);
#define DRII(A, B) int A, B; scanf("%d %d", &A, &B);
#define DRIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int INF = (int)1e9;
const int mod = (int)1e9+7;
const int MAX = (int)3e5+5;
map<int, int>check;
int main(void){
	int a, b, m, r; scanf("%d %d %d %d", &a, &b, &m, &r);
	check[r] = 1;
	int t = 2;
	while(1){
		r = (a*r + b) % m;
		if(check[r]){
			printf("%d", t - check[r]);
			return 0;
		}
		else check[r] = t++;
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=1e3+10;
char str[maxn];
int len;
int check(int i){
      if(str[i]!='.'&&str[i+1]!='.'&&str[i+2]!='.'){
        if(str[i]!=str[i+1]&&str[i+1]!=str[i+2]&&str[i+2]!=str[i])
        {
            if(i+2<len&&i+1<len)
            return 1;
        }
      }
   return 0;
}
int main(){
         scanf("%s",str);
         len=strlen(str);
       int flag=0;
      for(int i=0;i<len-1;i++){
          int k=check(i);
          if(k)
          {
              flag=1;
              break;
          }
      }
      if(flag)
        printf("Yes\n");
      else
        printf("No\n");
      return 0;
}


#include<bits/stdc++.h>
#define MOD (ll)1000000007
#define mod (ll)1000000007
#define eps 1e-8
#define N 105
#define M 10005
#define NN 60
#define mp make_pair
#define fr front
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define L(i, j, k) for(int i = j; i <= k; i++)
#define R(i, j, k) for(int i = j; i >= k; i--)
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);
int m,n,x,t,y,a[N],k,l,r,z,all,b[N];
ll en;
char c;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n,ll p=MOD) {ll r=1%p;for (a%=p;n;a=a*a%p,n>>=1)if(n&1)r=r*a%p;return r;} //a涓巔浜掕川鏃禷閫嗗厓涓篴^(p-2)
ll inv(ll x,ll p=MOD){return x<=1?1:inv(p%x,p)*(p-p/x)%p;} //绾挎€ф眰inv
void init(){

}
struct Matix {
	ll a[N][N];
} q, ans;
Matix operator * (Matix aa, Matix bb) {
	Matix res = {};
	L(i, 0, m) L(j, 0, m) res.a[i][j] = 0;
	L(i, 0, m) L(j, 0, m) L(k, 0, m) (res.a[i][j] += 1ll * aa.a[i][k] * bb.a[k][j] % mod) %= mod;
	return res;
}
Matix operator ^ (Matix aa, int bb) {
	Matix res = {};
	L(i, 0, m) L(j, 0, m) res.a[i][j] = (i == j);
	for(; bb; aa = aa * aa, bb >>= 1) if(bb & 1) res = res * aa;
	return res;
}
void solve(){
	scanf("%d%d",&n,&k);
	int m1=0,m0=0;
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		if(a[i]){
			m1++;
		} else m0++;
	}
	m=m0;
//	cout<<inv(2)<<endl;
//	cout<<m0<<" "<<m1<<endl;
	Matix res={};
	L(i,0,m0) L(j,0,m0) res.a[i][j]=0;
	L(i,0,m0){
		if(i!=0){
			res.a[i-1][i]=1LL*(m0-i+1)*(m0-i+1)%mod;
		}
		res.a[i][i]=inv(2)*m1*(m1-1)%mod+inv(2)*m0*(m0-1)%mod+i*(m0-i)%mod+(m0-i)*(m1-m0+i)%mod;
		res.a[i][i]%=mod;
		if(i!=m0){
			res.a[i+1][i]=1LL*(i+1)*(m1-m0+i+1)%mod;
		}
	}
//	L(i,0,m0){
//		L(j,0,m0){
//			cout<<res.a[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	x=0;
	L(i,1,m0){
		if(!a[i]) x++;
	}
	ans=res^k;
//	L(i,0,m0){
//		L(j,0,m0){
//			cout<<ans.a[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	en=inv(qpow(n*(n-1)/2,k))*ans.a[x][m0]%MOD;
	printf("%lld\n",en);
}
int main(){
    int T;
    T=1;
    // scanf("%d",&T);
    for(int i=1; i<=T; i++){
        init();
        solve();
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <sstream>
#define lap(i,n) for(int(i) = 0;i < int(n);i++)
#define ll long long
using namespace std;
int main(){
	//freopen("input.txt","r",stdin);
    ll m,n,dem = 0;
    cin >> m >> n;
    if (m == n-1){
    	cout << m/2;
    	return 0;
	}
	if (m <= n/2){
		cout << 0;
		return 0;
	}
	if (m >= n-1){
		if (n%2 == 0){
			cout << n/2 - 1;
			return 0;
		}
		else {
			cout << n/2;
			return 0;
		}
	}
    if (m > n/2){
    	if (n%2 == 0) {
    		cout << m - (n/2);
    		return 0;
		} else {
			cout << m - (n/2) ;
			return 0;
		}
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
long long n, ans ;

int main()
{
    cin >> n ;
    if(2520 > n) cout << 0 << endl;
    else
    {
        cout << n / 2520 << endl;
    }
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
int n,k,l,r,R,f;
set<pair<int,int> > s,s1;
int main() {	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;

	for(k=1; k<=n; k++) {
		cin>>l>>r;
		R=r;
		f=0; //cout<<l<<" "<<R<<endl;
		while(s.size() && s.upper_bound({l,0})!=s.end()) {
			pair<int,int> c=*s.upper_bound({l,0});
			if((c).fi>r) break;
			R=max(R,c.se);
			s.erase(c);
			s1.erase({-c.fi,c.se});
		}
		if( s1.size() && s1.upper_bound({-l,0})!=s1.end()) {

			pair<int,int> rg=*s1.upper_bound({-l,0});

			if(rg.se>=r) f=1;
			else if(rg.se>=l) {
				l=-rg.fi,s1.erase(rg),s.erase({-rg.fi,rg.se});
			}
		}
		if(!f) {// cout<<l<<" "<<R<<endl;
			s.insert({l,R});
			s1.insert({-l,R});
		}

		// cout<<l<<" "<<R<<endl;
		cout<<s.size()<<" ";
	}
}


#include <iostream>
using namespace std;

int main() {
  int a,sum=0;
  cin>>a;

    for(int i=1;i<a;i++){
    if((a-i)%i==0) sum+=1;
    else continue;

    }
   cout<<sum;

  }


#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <set>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <string>

using namespace std;

long long gcd(long long a, long long b) {
	while ((a != 0) && (b != 0))
	{
		if (a > b) {
			a = a % b;
		}
		else {
			b = b % a;
		}
	}
	return a + b;
}

int main()
{
	long long t, w, b;
	cin >> t >> w >> b;
	long long nod = gcd(w, b), mi = min(w, b);
	long long nok = (w / nod) * b;
	long long ans = 0;
	ans = (t / nok + 1) * mi;
	if ((t / nok) * nok + mi > t) {
		ans = ans - (t / nok) * nok - mi + t + 1;
	}
	ans--;
	double nok1 = (double)w / nod * b;
	if (nok1 > t) {
		ans = min(mi - 1, t);
	}
	long long c = gcd(ans, t);
	t = t / c;
	ans = ans / c;
	cout << ans << "/" << t << endl;
}


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

long long pwr(long long x, int y) {
    long long res = 1;
    for (int i = 0; i < y; ++i)
        res *= x;
    return res;
}

int main() {
    long long p, d;
    cin >> p >> d;
    while(d > 0) {
        int pw = 0;
        long long tempP = p;
        while(tempP > 0 && tempP % 10 == 9)
            tempP /= 10, ++pw;
        if (tempP == 0)
            break;
        long long toBeDecreased = (tempP % 10 + 1) * pwr(10, pw);
        if (d < toBeDecreased || p < toBeDecreased)
            break;
        p -= toBeDecreased;
        d -= toBeDecreased;
    }
    cout << p;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
#define mp make_pair
bool had[45][45];
int lea;
pair<int,int>la[45][45];
int dx[5]={-1,0,0,0,1},dy[5]={0,-1,0,1,0};
int n,m;
bool cmp(pair<int,int>a,pair<int,int>b){
	int cnt1=0,cnt2=0;
	for(int i=0;i<5;i++){
		int x=a.first+dx[i],y=a.second+dy[i];
		if(had[x][y]) cnt1++;
	}
	for(int i=0;i<5;i++){
		int x=b.first+dx[i],y=b.second+dy[i];
		if(had[x][y]) cnt2++;
	}
	return cnt1>cnt2;
}
unsigned int cando(){
	int ma=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int cnt=0;
			for(int k=0;k<5;k++){
				int x=i+dx[k],y=i+dy[k];
				if(had[x]) cnt++;
			}
			ma=max(cnt,ma);
		}
	}
	return ma;
}
void dfs(const int &chan,const int &dep)
{
	bool flag=0;
	int i,j;
	int mid1=(n+1)>>1,mid2=(m+1)>>1;
	int cnt1=0,cnt2=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(i<mid1) cnt1++; else cnt1--;
			if(j<mid2) cnt2++; else cnt2--;
		}
	}
	if(cnt1<0||cnt2<0) return;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(had[i][j])
			{
				flag=1;
				break;
			}
		}
		if(flag) break;
	}
	if(!flag)
	{
		lea=min(lea,chan);
		return;
	}
	if(chan+dep/cando()>=lea) return;
	vector<int> tmp[2];
	vector<pair<int,int> >tp;
	for(int k=0;k<5;k++)
	{
		int x=i+dx[k],y=j+dy[k];
		if(x>=0&&x<n&&y>=0&&y<m) tp.push_back(make_pair(x,y));
	}
	sort(tp.begin(),tp.end(),cmp);
	for(int k=0;k<tp.size();k++){
		int cnt=0;
		int x=tp[k].first,y=tp[k].second;
		for(int l=0;l<5;l++)
		{
			int xx=x+dx[l],yy=y+dy[l];
			if(xx>=0&&xx<n&&yy>=0&&yy<m&&had[xx][yy])
			{
				cnt++;
				had[xx][yy]=0;
				tmp[0].push_back(xx);tmp[1].push_back(yy);
			}
		}
		dfs(chan+1,dep-cnt);
		for(int l=0;l<tmp[0].size();l++)
		{
			had[tmp[0][l]][tmp[1][l]]=1;
		}
	}
}
int main()
{
	cin>>n>>m;
	if(n<m) swap(n,m);
	if(m==1)
	{
		cout<<n-(n/3)-((n%3)>0);
		return 0;
	}
	lea=min(((n+2)/3)*(((m+1)>>1)<<1),((n+1)>>1)*m);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			had[i][j]=1;
		}
	}
	dfs(0,n*m);
	cout<<n*m-lea;
	return 0;
}


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

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

using namespace std;

#ifdef ONLINE_JUDGE
	#define WAIT
#else
	#define WAIT cout<<flush, system("PAUSE")
#endif

#define FOR(IN,N) for(int I = IN;I < N;++I)
#define FORR(END,N) for(int I = N-1;I >= END;--I)
#define foreach(arr) for(auto item : arr)
#define REP(I,A,B) for(int I = A;I < B;++I)

#define CONTAINS(m,x) m.find(x) != m.end()
#define clr(x) memset((x),0,sizeof(x))
#define PB push_back
#define remove erase
#define ALL(v) v.begin(),v.end()
#define sz(a) a.size();
#define endl '\n'
#define MAX 10010

typedef long long i64;
typedef pair<int,int> pii;

//const int MOD = ;

string solve,s; int N;

void Check(){

	if(solve[0] == '.'){
		solve.remove(0,1);
		solve = "dot" + solve;
	}
	else if(solve[0] == '@'){
		solve.remove(0,1);
		solve = "at" + solve;
	}

	if(solve[solve.size() - 1] == '.'){
		solve.remove(solve.size() - 1,1);
		solve += "dot";
	}
	else if(solve[solve.size() - 1] == '@'){
		solve.remove(solve.size() - 1,1);
		solve += "at";
	}

}

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

	cin >> s;

	N = sz(s);

	solve = "";

	for(int I = 0;I < N;++I){

		if(I + 3 <= N){
			if(s.substr(I,3) == "dot"){
				solve += ".";
				I+=2;
			}
			else{
				if(I + 2 <= N){
					if(s.substr(I,2) == "at"){
						solve += "@";
						I+=1;
					}
					else solve += s[I];
				}
				else solve += s[I];
			}
		}
		else if(I + 2 <= N){
			if(s.substr(I,2) == "at"){
				solve += "@";
				I+=1;
			}
			else solve += s[I];
		}
		else solve += s[I];
	}

	Check();

	int cont = 0;

	for(int I = 0;I < solve.size();++I){

		if(solve[I] == '@') ++cont;

	}

	if(cont == 1) cout << solve << endl;

	else{

		bool ok = 1;

		for(int I = 0;I < solve.size();++I){

			if(solve[I] == '@'){
				if(ok){
					cout << '@';
					ok = false;
				}
				else{
					cout << "at";
				}
				continue;
			}
			cout << solve[I];
		}
		cout << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
int main()
{
	ll x,y,a,b,c,d;
	cin>>a>>b>>c>>d;
	ll up=0,down=0;
	ll tem=gcd(c,d);
	x=c/tem;
	y=d/tem;
	up=a/x;
	down=b/y;

	cout<<min(up,down)<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n],b[n];
    int count=0;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)
    {
        if (a[i]==1){
            b[i]=-1;
            count++;}
        else
            b[i]=1;
    }
    int max=-2 , sum=0;
    for (int i =0;i<n;i++)
    {
        sum+=b[i];
        if (sum > max)
            max=sum;
        if (sum<0)
            sum=0;

    }
    cout << count+max << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <cmath>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

#define mp make_pair

int main()
{
#ifdef KOCH
	freopen("abc.txt", "r", stdin);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int64 k, n;
	cin >> n >> k;
	int64 pow = 1;
	int lg = 1;
	for (; pow <= n; ++lg)
	{
		pow *= 2ll;
	}
	pow /= 2;
	lg--;
	int64 res = 0;
	if (k == 1)
	{
		cout << n << endl;
		return 0;
	}
	for (int i = 0; i < 100; ++i)
	{
		res += pow;
		pow /= 2ll;
		if (pow == 0) break;
	}
	cout << res << endl;
	return 0;
}


//0123
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <utility>
using namespace std;
#define int long long
#define endl "\n"

const int mm=1e9+7;

int be(int a,int b)
{
	if(a==1||b==0)	return 1;
	int c=be(a,b/2);
	int res=1;
	res=c*c;
	if(res>=mm)	res%=mm;
	if(b%2)	res*=a;
	if(res>=mm)	res%=mm;
	return res;
}

int32_t main() {
    int k; cin>>k;
    int b=1;
    for(int i=0;i<k;i++) b*=2;
    b-=2;
    int y=be(4,b);
    y*=6;
    y%=mm;
    cout<<y<<endl;
    return 0;
}


/*
 * DATE : 2017-06-30
 * Algo :
*/
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define Long                    long long
#define Ulong                   unsigned long long
#define FOR(I,A,B)              for(long long i=0; i < n ; i++ )
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-9
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
    register char c = getchar();x = 0;
    int neg = 0;
    for(; ((c<48 || c>57) && c != '-'); c = getchar());
    if(c=='-'){neg = 1;c = getchar();}
    for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/
const int N = 1001;
const int MOD = 1e9+7;
int main()
{
    int n;
    in(n);
    long long  dp[2];
    dp[0]=0;
    dp[1] = 0;
    long long ans = 0;
    for(int i=1;i <= n;i ++) {
        int now = i%2;
        ans = ans + 1 + dp[now^1];
        dp[now] += 1 + dp[now ^ 1];
        ans %= MOD;
        dp[now] %= MOD;
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <cassert>
#include <array>

using namespace std;

#define endl '\n'

long long binpow(long long n, long long p) {
    long long result = 1;

    n %= 1000000007;

    while (p) {
        if (p & 1) {
            result = (result * n) % 1000000007;
        }
        n = (n * n) % 1000000007;
        p = p >> 1;
    }

    return result;
}

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

    long long n, m;
    int k;

    cin >> n >> m >> k;

    if (k == -1 && (n % 2 != m % 2)) {
        cout << 0 << endl;
        return 0;
    }

    cout << binpow(binpow(2, (n - 1)), m - 1) << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

int main() {

    int N, K, L, C, D, P, NL, NP;
    std::cin >> N >> K >> L >> C >> D >> P >> NL >> NP;

    std::cout << std::min(std::min(K*L/NL, C*D), P/NP)/N << std::endl;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <memory.h>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long llint;

#define SQR(X) ((X)*(X))
#define ODD(X) ((X)&1)
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(Y):(X))

const int MOD = int(1e9)+7;
const int INF = 2147483647;
const int LPRIME = 100003;
const int N = int(1e5)+10;

int n,x,sum,ans;

int main() {
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif

	scanf("%d",&n);
	sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d",&x);
		sum+=x;
	}
	ans =0;
	for (int i  = 1; i <= 5; i++)
		if ((sum+i)%(n+1)!=1) ans++;
	cout<<ans;

	#ifndef ONLINE_JUDGE
	fclose(stdin);
	fclose(stdout);
	#endif
}


#include <bits/stdc++.h>
#define rua system("pause")
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) {x = x * 10 + c - '0', c = getchar();}
	return x * f;
}

typedef unsigned int uint;
uint c[135], a[135], b[135];

int main()
{
	int n, p, q;
	cin >> n >> p >> q;
	int up = min(n - 1, p);
	for (int i = 0; i <= up; i ++) c[i] = 1;
	for (int cur = 1; cur <= up; cur ++)
	{
		for (int i = 1; i <= cur; i ++)
			a[i] = n - i + 1, b[i] = i;
		for (int i = 1; i <= cur; i ++)
			if (b[i] > 1) for (int j = 1, d; j <= up; j ++)
				if ((d = __gcd(b[i], a[j])) > 1)
					a[j] /= d, b[i] /= d;
		for (int i = 1; i <= cur; i ++) assert(b[i] == 1);
		for (int i = 1; i <= cur; i ++) c[cur] *= a[i];
	}
	uint ans = 0;
	for (int i = 1; i <= q; i ++)
	{
		uint res = 0, now = 1;
		for (int k = 0; k <= up; k ++)
			res += now * c[k], now *= i;
		ans ^= res * i;
	}
	printf("%u\n", ans);
	return 0;
}


#include <iostream> // includes cin to read from stdin and cout to write to stdout
#include <map>
#include <set>
#include <list>
#include <string>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cassert>
#include <math.h>
#include <iomanip>
#include <limits>

///LLONG_MAX,INT_MA
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;i++)
#define REP(i,n) FOR(i,0,(n)-1)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--)
#define sz size()
#define FORA(i,c) REP(i,size(c))

#define itype(c) __typeof((c).begin())
#define FORE(e,c) for(itype(c) e=(c).begin();e!=(c).end();e++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REVERSE(x) reverse(all(x))
#define CLEAR(x,c) memset(x,c,sizeof(x))
#define amfor(Iterator, Container) 	for ( auto Iterator = begin(Container); (Iterator) != end(Container); ++(Iterator) )
#define ramfor(Iterator, Container) for ( auto Iterator = Container.rbegin(); (Iterator) != Container.rend(); ++(Iterator) )
template<class C, class E> inline bool contains(const C& container, const E& element) { return container.find(element) != container.end(); }
#define  NP(nn,ta,a,tb,b) struct nn : pair<ta,tb> { nn():pair<ta,tb>(){}; nn(ta pa,tb pb):pair<ta,tb>(pa,pb){} ta& a(){return first;} tb& b(){return second;} };
template<class T> inline void checkmin(T &a, T b) { if (b < a) a = b; }//asigna en a el minimo
template<class T> inline void checkmax(T &a, T b) { if (b > a) a = b; }//asigna en a el maximo

typedef long long ll;
using namespace std; // since cin and cout are both in namespace std, this saves some text
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

ll n;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << std::setprecision(15);
	cout << std::fixed;
	cin >> n;
	set<int> d;
	REP(i, n)
	{
		int a;
		cin >> a;
		d.insert(a);
	}
	int u = 0;
	while (!d.empty())
	{
		u++;
		int v = *d.begin();
		vector<int> f;
		for (int g : d)
		{
			if (g%v == 0)
				f.push_back(g);
		}
		for (int g : f)
			d.erase(g);
	}
	cout << u;
	return 0;
}


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

int main()
{    string str;
     int n,i,l,count=0;
     cin>>n;
     cin>>str;
     l=str.size();
     for(i=0;i<l;i++)
     {
     	if(str[i]=='+')
     	count++;
     	else
     	{ count--; count=max(0,count); }
     }
     cout<<count;
	 return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a[14],b[14];
int main(){
	for(int i=0;i<14;i++) cin>>a[i];
	long long mx=0;
	for (int i=0;i<14;i++){
		long long re=a[i]%14,qu=a[i]/14,sum=0,k=0;
		for (int j=0;j<14;j++) b[j]=a[j];
		b[i]=0;
		for (int j=(i+1)%14;k<re;j=(j+1)%14,k++) b[j]++;
		for (int j=0;j<14;j++){
			b[j]+=qu;
			if (b[j]%2==0) sum+=b[j];
		}
		mx=max(mx,sum);
	}
	cout<<mx;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <set>
using namespace std;
#define ll long long
int n,m,x,y,a,b;
int main()
{
   // freopen("in.txt","r",stdin);
    cin>>n>>m>>x>>y>>a>>b;
    ll t=__gcd(a,b);
    a/=t;
    b/=t;
    ll lx,ly;
    lx=n/a*a;
    ly=m/b*b;
    if(lx*b>a*ly)
    {
        lx=ly/b*a;
    }else  ly=lx/a*b;
//    cout<<a<<endl;
//    cout<<b<<endl;
//    cout<<lx<<endl;
//    cout<<ly<<endl;
    ll x2=x+(lx>>1);
    ll y2=y+(ly>>1);
    ll x1=x2-lx;
    ll y1=y2-ly;
    ll mx=x1<0?-x1:x2>n?n-x2:0;
    ll my=y1<0?-y1:y2>m?m-y2:0;
     printf("%lld %lld %lld %lld\n",x1+mx,y1+my,x2+mx,y2+my);
//    mx=my=0;
//    prllf("%d %d %d %d\n",x1+mx,y1+my,x2+mx,y2+my);

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
map<int, vector<int> > mond;
bool BS(int num, int key)
{
	int s = 0, e = mond[num].size()-1, mid;
	while (s<=e)
	{
		mid = s + (e - s) / 2;
		if (key < mond[num][mid])e = mid - 1;
		else if (key>mond[num][mid])s = mid + 1;
		else return true;
	}
	return false;
}
int main()
{
	//ios::sync_with_stdio(false);
	vector<int>t1 = { 2 };
	vector<int>t3 = { 4, 6, 9, 11 };
	vector<int>t4 = { 1, 3, 5, 7, 8, 10, 12 };
	mond[28] = t1; mond[29] = t1;
	mond[30] = t3; mond[31] = t4;
	int n;
	cin >> n;
	vector<int>in(n);

	int feb=0;
	bool con = true;
	for (int i = 0; i < n; i++)
	{
		cin >> in[i];
		if (in[i] == 28 || in[i] == 29)
		{
			if (in[i] == feb &&in[i] == 29)
			{
				con = false;
			}
			else
				feb = in[i];
		}
	}
	int sz = mond[in[0]].size(),start,f;

	for (int i = 0; i < sz; i++)
	{
		start = mond[in[0]][i];
		f = 1;
		if (start == 12) start = 0;
		for (int j = 1; j < n; j++)
		{
			if (BS(in[j], start + 1))
			{
				start++;
				f++;

				if (start == 12) start = 0;
			}
		}
		if (f == n && con)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define dob double
//#define int long long int
#define gcd __gcd
#define ss size()
using namespace std;
const long long M = 1e9 + 7 , maxn = 2e6 + 10;
int ans , n , m , x , y , k , q , dp[maxn];
std::vector<int> d[maxn];

int bpow(int a , int b){
	if(a < 1)
		return 0;
	if(!b)
		return 1;
	x = bpow(a , b >> 1);
	if(b & 1)
		return (1ll * x * x % M ) * 1ll * a % M;
	return 1ll * x * x % M;
}

int32_t main(){

      ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

      for(int i = 0 ; i < maxn ; i++)
      	d[i].reserve(10);

      for(int i = 2 ; i < maxn ; i++){
      	for(int j = i ; j < maxn ; j += i)
      		d[j].pb(i);
      }

      cin >> n >> k;

      for(int i = 0 ; i < 100 ; i++)

      dp[1] = 1;

      for(int i = 2 ; i <= k ; i++){
      	y = (1ll * bpow(i , n) - bpow(i-1 , n) + M) % M;
      	for(int j : d[i]){
      		y -= dp[i/j];
      		if(y < 0)
      			y += M;
      	}
      	dp[i] = y;
      }

      for(int i = 1 ; i <= k ; i++){
      	dp[i] = (1ll * dp[i] + dp[i-1]) % M;
      	ans = (1ll * ans + (dp[i] ^ i )) % M;
      }

      cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238463;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
#endif
    int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int m,d;
    cin>>m>>d;
    int ans=ceil((a[m]+d-1)/7.0);
    cout<<ans<<endl;
	return 0;
}


// IN THE NAME OF GOD

#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cstdio>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;

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

const int MOD = 1e9 + 7 ;
const int MAXN= 1e5 + 22 ;

int n ;

int main()
{
	ios_base::sync_with_stdio(false) ;
	cin >> n ;
	bool sw= true;
	int x,y ,a[120] , t;
	for(int i = 1 ; i <= n ; i++)
		{
		cin >> a[i] ;
		if(sw && a[i] == 1)
		{
			sw = false ;
			x = i ;
		}
		if(a[i])
			y = i ;
	}
	if(sw)
	{
		cout << 0 ;
		return 0 ;
	}
	t =  x;
	ll ans = 1 ;
	for(int i = x+1 ; i <= y ; i++)
	{
		if(a[i] == 1)
		{
			ans *= i - t ;
			t = i ;
		}
	}
	cout << ans ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
int n;
string line;
vector<int> divv;
int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> line;
	for(int i = 1; i * i <= n; ++i) {
		if(n % i == 0) {
			divv.push_back(i);
			if(i != n / i) {
				divv.push_back(n / i);
			}
		}
	}
	sort(divv.begin(), divv.end());
	for(auto v : divv) {
		reverse(line.begin(), line.begin() + v);
	}
	cout << line << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int MAX = 5e2 + 10;
int deg[MAX];
vector< pair<int, int> >  g;
bool mark_a[MAX];
int main(){
    int n, m; scanf("%d%d", &n, &m);
    for(int i = 0; i < m ;i++){
        int a, b;
        scanf("%d%d", &a, &b); a--; b--;
        deg[a]++;
        deg[b]++;
        g.push_back(make_pair(a, b));
    }
    int a = 0, b = 0, c = 0;
    int da = -1;
    for(int i = 0; i < n; i++)
        if(deg[i] == n - 1){
            b++;
        }
        else if(da == -1){
            da = i;
            mark_a[i] = 1;
            a = 1;
        }
    for(int i = 0; i < m; i++){
        if(g[i].first == da && deg[g[i].second] != n - 1 && !mark_a[g[i].second])
            mark_a[g[i].second] = 1, a++;
        if(g[i].second == da && deg[g[i].first] != n - 1 && !mark_a[g[i].first])
            mark_a[g[i].first] = 1, a++;
    }
    c = n - a - b;
    int wrong = 0;
    for(int i = 0; i < m; i++){
        if(mark_a[g[i].first] && deg[g[i].second] != n - 1 && !mark_a[g[i].second])
            wrong++;

        if(mark_a[g[i].second] && deg[g[i].first] != n - 1 && !mark_a[g[i].first])
            wrong++;
    }
    if(wrong == 0 && (m == n * (n - 1) / 2 - a * c)){
        printf("Yes\n");
        for(int i = 0; i < n; i++){
            if(deg[i] == n-1)printf("b");
            else if(mark_a[i])printf("a");
            else printf("c");
        }
        printf("\n");
    }
    else printf("No\n");

}


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

int main() {
	unsigned long long n;
	cin >> n;
	unsigned long long res = n * (n + 1) / 2 % 2;
	cout << res << "\n";
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{

int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e;

int l = (a+b+c+d+e);
int lp = (a+b+c+d+e);
if(l%5 || !l)
cout<<-1;
else cout<<l/5;

return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#define maxn 11

using namespace std;

typedef long long ll;

int st[maxn],aim[maxn*maxn],nxt[maxn*maxn],ln;
ll f[1<<10][1<<10];
void in_edge(int x,int y){
	aim[ln]=y;
	nxt[ln]=st[x];
	st[x]=ln++;
}
int n,m,kn;
int cal_bit(int mask){
	int ret=0;
	while (mask) ret+=(mask&1),mask>>=1;
	return ret;
}
int lowbit(int mask){
	return (mask&(mask^(mask-1)));
}
int main(){
	scanf("%d%d%d",&n,&m,&kn);
	memset(st,-1,sizeof(st));
	ln=0;
	memset(f,0,sizeof(f));
	for (int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		--v,--u;
		in_edge(u,v);
		in_edge(v,u);
		int tmp=((1<<u)|(1<<v));
		f[tmp][tmp]=2;
	}
	int N=(1<<n);
	for (int i=1;i<N;i++)
		for (int j=i;j;j=((j-1)&i))
			if (f[i][j]){
				int d=cal_bit(j);
				f[i][j]/=d;
//				printf("%d %d %lld\n",i,j,f[i][j]);
				for (int k=0;k<n;k++)
					if ((i&(1<<k))>0){
						for (int c=st[k];c!=-1;c=nxt[c]){
							int p=aim[c];
							if ((i&(1<<p))==0){
								int tmask=(i|(1<<p));
								int cmask=j;
								if ((j&(1<<k))>0) cmask^=(1<<k);
								cmask|=(1<<p);
								f[tmask][cmask]+=f[i][j];
							}
						}
					}
			}
//	for (int i=1;i<N;i++) printf("%lld ,",f[N-1][i]);
	ll ans=0;
	for (int i=1;i<N;i++)
		if (cal_bit(i)==kn) ans+=f[N-1][i];
	printf("%I64d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

struct point{
    double x,y;
};

double dist(point p1,point p2){
    double z = p1.x-p2.x;
    z *= z;
    double z1 = p1.y-p2.y;
    z1 *= z1;
    return sqrt(z+z1);
}

double con(double x){return M_PI*x/180.0;}
double con1(double x){return 180.0*x/M_PI;}

double findX(point p1,point p2,double teta1){
    point p3;
    double teta = acos((-p1.x + p2.x)/dist(p1,p2));
    if(con1(teta)+teta1 >= 180.0)return 1e7;

    p3.x = p2.x + dist(p1,p2)*cos(teta + con(teta1));
    p3.y = p2.y + dist(p1,p2)*sin(teta + con(teta1));

    double res = -p2.y/(p3.y-p2.y);
    res *= (p3.x-p2.x);
    res += p2.x;
    return res;
}

double dp[1<<21];

int main(){
    ios::sync_with_stdio(0);
    int n;
    double l,r;
    cin>>n>>l>>r;
    point z[n];
    double a[n];
    for(int i=0 ; i<n ; i++){
        cin>>z[i].x>>z[i].y>>a[i];
    }

    int en = 1<<n;
    dp[en-1] = l;
    for(int i=en-2 ; i>=0 ; i--){
        double maxx = -1e6,r1;
        point h;
        h.y = 0;
        for(int j=0 ; j<n ; j++){
            if((i&(1<<j)) == 0){
                int x = i|(1<<j);
                h.x = dp[x];
                r1 = findX(h,z[j],a[j]);
                maxx = max(maxx,r1);
            }
        }
        dp[i] = maxx;
    }
    cout<<fixed<<setprecision(10)<<min(fabs(dp[0]-l),fabs(r-l))<<endl;

    return 0;
}


#include <iostream>

using namespace std;

int main(const int argc, char *argv[])
{
    int n,p,k;
    cin>>n>>p>>k;
    if ((p-k)<=1) for (int i=1;i<p;i++) cout<<i<<" ";
    else
    {
        cout<<"<< ";
        for (int i=p-k;i<p;i++) cout<<i<<" ";
    }
    cout<<"("<<p<<") ";
    if ((p+k)>=n) for (int i=p+1;i<=n;i++) cout<<i<<" ";
    else
    {
        for (int i=p+1;i<=p+k;i++) cout<<i<<" ";
        cout<<">>";
    }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back

using namespace std;

void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

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

inline int two(int n) { return 1 << n; }
inline int test(int n, int pos) { return (bool) (n & two(pos)); }
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); }

const int DMAX = 18;
const int LgMAX = 32800;
const int MOD = 1e9+7;

vector <int> vec;
vector <int> arb[DMAX];

pii V[DMAX];
int tme[LgMAX];

pii dp[LgMAX][DMAX];

int n,maxim;

ll ans;

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

    int t,i,k;
    int mask,mask2;

    cin>>n>>t;
    for(i=0;i<n;i++){
        cin>>V[i].first>>V[i].second;
    }
    for(i=0;i<n;i++){
        dp[1<<i][i].first=V[i].first;
        dp[1<<i][i].second=1;
    }
    for(mask=1;mask<(1<<n);mask++)
        for(i=0;i<n;i++)
            if(mask & (1<<i)){
                mask2=mask-(1<<i);
                for(k=0;k<n;k++)
                    if((mask2 & (1<<k))&&(V[i].second != V[k].second)&&dp[mask2][k].first){
                        dp[mask][i].first=dp[mask2][k].first+V[i].first;
                        dp[mask][i].second+=dp[mask2][k].second;
                    }
                 if(dp[mask][i].first == t){
                    ans+=dp[mask][i].second;
                    if(ans > MOD)
                       ans-=MOD;
                }
            }
    cout<<ans<<'\n';
    return 0;
}


#include <iostream>
using namespace std;

int main() {long long n ,v,r,a;
	cin>>n>>v;
	a=-1;
	n--;
	r=n-v;
		if(n<=v){
			cout<<n;
			exit (0);
		}

	a+=v;

	a+=((r+2)*(r+1))/2;
	cout<<a;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a[3];
int main()
{
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if ((a[0]+a[1])%2==0) cout<<a[1]; else cout<<a[2];
}


#include<bits/stdc++.h>
using namespace std;
int q[100005];
int head=0,tail=0;
int wish[100005];

void push(int x)
{
  q[tail++]=x;
}

void pop()
{
  if(head<tail)head++;
}

int main()
{
  int n,m;//孩子个数,每次给的糖数
  int ccc;
  scanf("%d",&n);//孩子总数
  scanf("%d",&m);
  for(int i=1; i<=n; i++)push(i);//孩子萌的编号,第0个元素对应1
  for(int j=1; j<=n; j++)//编号j的孩子需要多少个糖
  {
    scanf("%d",&ccc);
    wish[j]=ccc;
  }
  for(;;) //开始判断
  {
    if(tail-head==1)
    {
      printf("%d",q[head]);
      return 0;
    }//结束条件
    if(wish[q[head]]<=m)pop();
    else if(wish[q[head]]>m)
    {
      wish[q[head]]=wish[q[head]]-m;
      push(q[head]);
      pop();
    }

  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int num=0,n;
char ch;
int main() {
    scanf("%d\n",&n);
    for (int i=1;i<=n;i++) {
        scanf("%c",&ch);
        if (ch=='8') num++;
    }
    if (num==0) printf("0");
    else {
        if (num*11<=n) printf("%d",num);
        else printf("%d",n/11);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define reps(i, s, n) for(int i=s; i<n; i++)
#define rep(i, n) reps(i, 0, n)
#define dreps(i, s, n) for(int i=n-1; i>=s; i--)
#define drep(i, n) dreps(i, 0, n)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define foreach(v, c) for(__typeof((c).begin()) v=(c).begin();v!=(c).end(); ++v)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define in(a,b) ((b).find(a) != (b).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define X real()
#define Y imag()
#define length(V) (hypot((V).X, (V).Y))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
typedef pair<point, point> segment;
typedef pair<double, point> circle;
typedef vector<point> polygon;

const double PI = 2 * acos(0.0);
const double eps = 1e-9;

double r, h;

int main() {
   cin >> r >> h;
   int ans = 0;
   double half = floor(h / r);
   ans += half * 2;
   h = h - half * r;
   if (h * 2 < r) ans ++;
   else if (h * 2 >= r * sqrt(3)) ans += 3;
   else ans += 2;
   cout << ans << endl;
   return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define N 2100000
int l[N],r[N],s[N],key[N],ans[N],root,n,m,num=0,p[N];
void l_rotate(int &t){
     int k=r[t];
     r[t]=l[k];
     l[k]=t;
     s[k]=s[t];
     s[t]=s[l[t]]+s[r[t]]+1;
     t=k;
}
void r_rotate(int &t){
     int k=l[t];
     l[t]=r[k];
     r[k]=t;
     s[k]=s[t];
     s[t]=s[l[t]]+s[r[t]]+1;
     t=k;
}
void maintain(int &t,bool flag){
     if(!flag){
       if(s[l[l[t]]]>s[r[t]])r_rotate(t);
       else
         if(s[r[l[t]]]>s[l[t]])l_rotate(l[t]),r_rotate(t);
         else return;
     }
     else{
       if(s[r[r[t]]]>s[l[t]])l_rotate(t);
       else
         if(s[l[r[t]]]>s[l[t]])r_rotate(r[t]),l_rotate(t);
         else return;
     }
     maintain(l[t],0);
     maintain(r[t],1);
     maintain(t,0);
     maintain(t,1);
}
void add(int &t,int x){
     if(!t){
            t=++num;
            l[t]=r[t]=0;
            key[t]=x;
            s[t]=1;
            return;
            }
     s[t]++;
     add(l[t],x);
     maintain(t,0);
}
int del(int &t,int z){
    s[t]--;
    if(s[l[t]]+1==z || z<s[l[t]]+1 && !l[t] || z>s[l[t]]+1 && !r[t]){
      int tt=key[t];
      if(!l[t] || !r[t])t=l[t]+r[t];
      else key[t]=del(l[t],s[l[t]]+2);
      return tt;
    }
    else
      if(z<s[l[t]]+1)return del(l[t],z);
      else return del(r[t],z-s[l[t]]-1);
}
int find(int t,int x){
    if(s[l[t]]+1==x)return t;
    if(x<=s[l[t]])return find(l[t],x);
    return find(r[t],x-s[l[t]]-1);
}
int main(){
    scanf("%d%d",&n,&m);
    root=0;
    for(int i=n;i;i--)add(root,i);
    while(m--){
               int x,y;
    scanf("%d%d",&x,&y);
    int t=find(root,y);
    int tt=key[t];
  //  cout<<key[t]<<endl;
    if(ans[key[t]] && ans[key[t]]!=x || p[x] && key[t]!=p[x]){
                    cout<<-1<<endl;
                    return 0;
                    }
    ans[key[t]]=x;
    p[x]=key[t];
    del(root,y);
 //  cout<<key[t]<<endl;
    add(root,tt);
    }
    int z=1;
    for(int i=1;i<=n;i++)
      if(!ans[i]){
                  while(p[z])z++;
                  ans[i]=z;
                  z++;
                  }
    for(int i=1;i<n;i++)printf("%d ",ans[i]);
    printf("%d\n",ans[n]);
   // system("pause");
    return 0;
}


#include <bits/stdc++.h>
#include <vector>
using namespace std;
int freq[26];
int main()
{
	int n;string s;
	cin>>n>>s;
	long long int maxi=0;
	set<char>c;
	for(int i=0;i<n;i++)
	{
		if(isupper(s[i]))
		{
			long long int size=c.size();
			maxi=max(maxi,size);
			c.clear();
		}
		else
		{
			c.insert(s[i]);
			// freq[s[i]-'a']++;
		}
	}
	long long int size=c.size();
	//cout<<size<<endl;
			maxi=max(maxi,size);
			c.clear();
	cout<<maxi;

	return 0;
}


/*
 ((O A O))
//  0-0  \\
 \ w   w /
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define int long long

const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int n;
int phi[N], vis[N], pri[N], p_tot;
int ans;

int lcm(int x, int y) {
    return 1ll * x / std::__gcd(x, y) * y % mod;
}

void Prime(int n) {
    phi[1] = 0;
    for (int i = 2; i <= n; ++i) {
        if (!vis[i]) pri[++p_tot] = i, phi[i] = i - 1;
        for (int j = 1; j <= p_tot && i * pri[j] <= n; ++j) {
            vis[i * pri[j]] = 1;
            if (i % pri[j] == 0) {
                phi[i * pri[j]] = phi[i] * pri[j];
                break;
            }
            phi[i * pri[j]] = phi[i] * (pri[j] - 1);
        }
    }
}

signed main() {
    scanf("%lld", &n);
    Prime(n);
    for (int c = 1; c <= n - 2; ++c) {
        for (int d = 1; d * d <= n - c; ++d) {
            if ((n - c) % d == 0) {
                ans += phi[(n - c) / d] * lcm(c, d) % mod;
                ans %= mod;
                if (d * d != n - c) {
                    ans += phi[d] * lcm(c, (n - c) / d) % mod;
                    ans %= mod;
                }
            }
        }
    }
    printf("%lld\n", ans % mod);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:16777216")
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <fstream>
#include <math.h>
#include <limits>
#include <set>
#include <map>
#include <sstream>
#include <stdio.h>
#include <time.h>
#include <memory.h>
#include <cassert>
#include <complex>
#ifdef MY_JUDGE
#include <windows.h>
#endif
using namespace std;

///////////////// macros and typedefs ///////////////////
#define rep(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define _fill(a, x) memset((a), (x), sizeof((a)))
#define DEB(k) cerr<<"debug: "#k<<"="<<k<<endl;
#define all(c) (c).begin(), (c).end()
#define mp(a, b) make_pair(a, b)
#define l(c) (int)((c).size())
#define sqr(a) ((a)*(a))
#define inf 0x7f7f7f7f
#define pb push_back
#define ppb pop_back
//#define x first
//#define y second
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pi;

/*
 */

int x[3], k;
ll p[3];

void solution()
{
   rep(i, 3) { cin >> x[i]; x[i]--; }
   cin >> k;
   while (p[0] < x[0] || p[1] < x[1] || p[2] < x[2]) {
      if (k == 0) break;
      int mini = -1, mx = -1;
      rep(i, 3) if (p[i] < x[i])
         if (mx == -1 || p[i] < p[mx])
            mx = i;
      p[mx]++, k--;
   }
   cout << (p[0]+1)*(p[1]+1)*(p[2]+1) << endl;
}

int main()
{
#ifdef MY_JUDGE
   freopen("my.in", "rt", stdin);
   //freopen("my.out", "wt", stdout);
   int start = GetTickCount();
#endif
   solution();
#ifdef MY_JUDGE
   int finish = GetTickCount();
   cerr << "Time: " << finish - start << endl;
#endif
   return 0;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <sstream>

using namespace std;
typedef long long ll;
const int maxN=2500;
const int INF=(int)1e9;
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int mark1[maxN];
int mark2[maxN];
ll A1[maxN];
ll A2[maxN];
int main(void){
   // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    for(int i=0; i<maxN; i++){
        mark1[i]=-1;
        mark2[i]=-1;
    }
    ll a,b,w,x,c;
    cin >> a >> b >> w >> x >> c;
    ll A=0;
    int i=b;
    ll l1=0;
    while(mark1[i]==-1){
        mark1[i]=1;
        A1[l1++]=A;
//      printf("%d %d\n",i,A);
        if(i>=x){
            i-=x;
        }else{
            i=w-(x-i);
            A++;
        }
    }
    ll d1=A;
    A=0;
    ll l2=0;
    while(mark2[i]==-1){
        mark2[i]=1;
        A2[l2++]=A;
//      printf("<%d %d\n",i,l2);
        if(i>=x){
            i-=x;
        }else{
            i=w-(x-i);
            A++;
        }
    }
    ll d2=A;
//  printf(" %d %d\n",d1,d2);
//  printf(" %I64d %I64d\n",l1,l2);
    ll l=-1, r=(ll)1e15;
//  cout << l1 <<" " << l2<< endl;
    while(r-l>1){
        ll m=l+(r-l)/2;
        ll cc=c-m;
        ll aa;
        if(l1>m){
            aa=a-A1[m];
        }else{
            aa=a-A2[(m-l1)%l2]-d1-((m-l1)/l2)*d2;
        }
        //cout << m << " " << aa<< " " << cc << endl;
        if(cc<=aa){
            r=m;
        }else{
            l=m;
        }
    }
    cout << r;
    return 0;
}


#include <bits/stdc++.h>

#define lli long long int
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );

const int N = 100100;

using namespace std;

lli x;
int n, d, i, j, h, a[N], b[N], c[N], p[N];
set < int > s;
vector < int > v;

lli getNextX()
{
    x = (x * 37 + 10007) % 1000000007;
    return x;
}

void initAB()
{
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int main()
{
    int mx = sqrt(N);
    sc( "%d%d%I64d", &n, &d, &x );
    initAB();
    for( i = 0; i < n; i++ )
        p[a[i]] = i;
    for( i = 0; i < n; i++ ){
        if( b[i] )
            v.pb(i);
        s.insert(-a[i]);
        int ans = 0;
        if( v.size() < mx ){
            for( j = 0; j < v.size(); j++ ){
                if( i - v[j] >= 0 && i - v[j] <= i )
                    ans = max(ans, a[i - v[j]]);
            }
        }
        else{
            for( set < int > :: iterator it = s.begin(); it != s.end(); it++ ){
                if( b[i - p[-(*it)]] ){
                    ans = -(*it);
                    break;
                }
            }
        }
        pr( "%d\n", ans );
    }
}


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

int main()
{
    string s;
    string ans;
    cin>>s;
    int i=0;
    int j=0;
    while(i<s.size()&j<3){
        if(j==0){
            if(s[i]=='f'){
                ans="ftp://";
                i=3;
            }
            else{
                ans="http://";
                i=4;
            }
            j=1;
        }
        if(j==1){
            int temp=i;
            // cout<<(s[i]!='r'&&s[i+1]!='u')<<endl;
            while(s[i+1]!='r'|| s[i+2]!='u'){
                // cout<<s[i];
                i++;
            }
            // cout<<temp<<" "<<i+1<<endl;
            ans+=s.substr(temp,i+1-temp);
            ans+=".ru";
            i=i+3;
            j=2;
        }
        if(j==2){
            if(s.size()-i){
                ans+="/";
                ans+=s.substr(i,s.size()-i);
                i=s.size();
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


                /////////////////////////////////////////////
                /////////////   YURKA PRO AZAZAZ  //////////
                ///////////////////////////////////////////

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const long long INF = 1e9;

long long n,m,k,ans,sum,mn,pl;
long long x,y,z;
long long a,b,c,tmp,nd;
bool na,nb,nc;
main()
{
    cin >> x >> y >> z;
    cin >> a >> b >> c;
    if(x > a) tmp+=((x-a)/2);
    else nd+= a-x;

    if(y > b) tmp+=((y-b)/2);
    else nd+= b-y;

    if(z > c) tmp+=((z-c)/2);
    else nd+= c-z;

    if(tmp >= nd) cout << "YES";
    else cout << "NO";

}


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

#define int long long
#define ll long long
#define endl '\n'

#define rep(x, start, end)                                                     \
    for (auto x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); \
         ((start) < (end) ? x++ : x--))
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

int n;
string s;
int mod;

int mul(int i, int j) {
    int res = 0;
    rep(x, 0, n - 1) {
        if (i & (1LL << x)) res ^= j;
        j <<= 1;
        if (j & (1LL << (n - 1))) j ^= mod;
    }
    return res;
}

int pow(int i) {
    int res = 1;
    int b = 2;
    while (i) {
        if (i & 1) res = mul(res, b);
        b = mul(b, b);
        i >>= 1;
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(ios::badbit | ios::failbit);
        mod = 0;
        cin >> s;
        vector<int> pos;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '1') {
                pos.push_back(i);
            }
        }
        s.erase(s.find_last_not_of("0") + 1);
        int offset = s.find_first_not_of("0");
        s.erase(0, offset);
        n = s.length();
        if (pos.size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        if (pos.size() == 1) {
            cout << n + offset << ' ' << n + offset + 1 << endl;
            return 0;
        }
        if (pos.size() == 2) {
            cout << pos[0] + 1 << ' ' << pos[1] + 1 << endl;
            return 0;
        }
        rep(x, 0, sz(s)) if (s[x] == '1') mod |= (1LL << x);

        int h = (n + 1) / 2;

        int val = mod;
        int prod = 1;
        rep(x, 3LL, 1 << h) if (x & 1) {
            int num = 0;
            while (true) {
                int curr = val;
                int other = 0;
                rep(bit, 0, n) if (curr & (1LL << bit)) {
                    curr ^= x << bit;
                    other ^= 1LL << bit;
                }
                if (curr == 0) {
                    val = other;
                    num++;
                } else
                    break;
            }

            if (num) {
                prod *= (1LL << (63 - __builtin_clzll(x))) - 1;
                rep(y, 1, num) prod *= 1LL << (63 - __builtin_clzll(x));
            }
        }
        if (val > 1) prod *= (1LL << (63 - __builtin_clzll(val))) - 1;

        int ans = 1LL << 60;
        for (int x = 1; x * x <= prod; x++) {
            if (prod % x == 0) {
                if (pow(x) == 1) ans = min(ans, x);
                if (pow(prod / x) == 1) ans = min(ans, prod / x);
            }
        }
        cout << 1 + offset << ' ' << ans + 1 + offset << endl;
}


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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

#define F first
#define S second

#define en end()
#define bg being()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y0123456789
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))

#define forn(i, x) for (int i = 1; i <= x; i++)

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

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

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int N = 100500;

int n, m, ans, a[N], add[N], dp[2][N], t[2][N];

inline void upd(int pos, int tp, int val) {
    for (int i = pos; i <= 100000; i |= (i + 1))
        t[tp][i] = max(t[tp][i], val);
}

inline int get(int pos, int tp) {
    int res = 0;
    for (int i = pos; i >= 0; i = (i & (i + 1)) - 1)
        res = max(res, t[tp][i]);
    return res;
}

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

    //srand(time(NULL));

    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);

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

    cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        int l, r;
        cin >> l >> r;
        add[l]++;
        add[r + 1]--;
    }

    int cur = 0;

    for (int i = 1; i <= m; i++) {
        cur += add[i];
        a[i] = cur;
    }

    for (int i = 1; i <= m; i++) {
        dp[0][i] = get(a[i], 0) + 1;
        upd(a[i], 0, dp[0][i]);
    }

    for (int i = m; i >= 1; i--) {
        dp[1][i] = get(a[i], 1) + 1;
        upd(a[i], 1, dp[1][i]);
    }

    for (int i = 1; i <= m; i++)
        ans = max(ans, dp[0][i] + dp[1][i] - 1);

    cout << ans;

    //cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

    return 0;
}


#include<stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int temp;
	int i,sum=0;
	if(a>b)
	{
		temp=a;;
	    a=b;
		b=temp;
	}
	if(a>c)
	{
		temp=a;;
		a=c;
		c=temp;
	}
	if(b>c)
	{
		temp=b;;
		b=c;
		c=temp;
	}

     if(c-a>=2*d)
	{
		if(b-a>=d&&c-b>=d)
			sum=0;
		if(b-a<d)
		{
			for(i=1;b+i-a<d;i++);
			sum=i;
		}
		if(c-b<d)
		{
			for(i=1;c+i-b<d;i++);
		    sum=i;
		}
		printf("%d\n",sum);
	}
	else
	{
		if(b-a>=c-b)
		{
			for(i=1;c+i-b<d;i++);
				sum+=i;
			for(i=0;b+i-a<d;i++);
			    sum+=i;
			printf("%d\n",sum);
		}
		else if(b-a<c-b)
		{
			for(i=1;b+i-a<d;i++);
			    sum+=i;
			for(i=0;c+i-b<d;i++);
				sum+=i;
			printf("%d\n",sum);
		}
	}
	int x;
	scanf("%d",&x);
	return 0;
}


/**
 *       Compiler:  gcc
 *         Author:  bdep__
 *        Created:  03/27/2012 10:38:06 PM
 ***/

#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#define N 1010
#define M 1000010
#define S 1000100
#define MOD 1000000007

typedef long long LL;
using namespace std;

inline int L(int i){ return i<<1; }
inline int R(int i){ return (i<<1)|1; }
inline int B(int i){ return 1<<i; }
inline int low_bit(int x){ return x&(-x); }
LL cnt[N],top;
LL tmp,mul;

bool must_win(LL a,LL b)
{
	if(a==0||b==0)
		return 0;
	if(a>b)
		tmp=a,a=b,b=tmp;
	if(must_win(b%a,a)==0)
		return 1;
	tmp=b;
	tmp/=a;
	tmp%=a+1;
	if(tmp&1)
		return 0;
	return 1;
}

int main()
{
	int t;
	LL a,b;
	cin>>t;
	while(t--)
	{
		cin>>a>>b;
		if(must_win(a,b))
			puts("First");
		else
			puts("Second");
	}
	return 0;
}


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

int k2, k3, k5, k6, temp;
unsigned long long int ans = 0;

int main()
{
	cin >> k2 >> k3 >> k5 >> k6;
	temp = k2;

	ans += (min(k2, min(k5, k6)) * 256);
	k2 -= min(k2, min(k5, k6));
	ans += ((k2 > 0) ? (min(k2, k3) * 32) : 0);

	cout << ans;

	return 0;
}


/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 9;
const int maxh = 35;

int n, h, m, ans;
int dp[2][238576];
int state[238577][4];
int match[maxh][maxh][maxh][maxh];

inline void add(int &x, int y){(x += y) -= (x >= INF ? INF : 0);}

int main(){
	scanf("%d%d", &n, &h);
	dp[0][0] = 1;
	int p = 0, q = 1;
	REP(i, 0, h + 1) REP(j, 0, h + 1) REP(k, 0, h + 1) REP(l, 0, h + 1) match[i][j][k][l] = 238575;
	REP(i, 0, h + 1) REP(j, 0, h + 1) REP(k, 0, h + 1) REP(l, 0, h + 1){
	   if((!(i % (h + 1)) || !(j % (h + 1)) || !(k % (h + 1)) || !(l % (h + 1))) && (i <= j && j <= k && k <= l)){
	       state[m][0] = i, state[m][1] = j, state[m][2] = k, state[m][3] = l;
	       match[i][j][k][l] = match[i][j][l][k] = match[i][l][j][k] = match[i][l][k][j] = match[i][k][j][l] = match[i][k][l][j] = m;
	       match[j][i][k][l] = match[j][i][l][k] = match[j][k][i][l] = match[j][k][l][i] = match[j][l][k][i] = match[j][l][i][l] = m;
	       match[k][i][j][l] = match[k][i][l][j] = match[k][j][i][l] = match[k][j][l][i] = match[k][l][i][j] = match[k][l][j][i] = m;
	       match[l][i][j][k] = match[l][i][k][j] = match[l][j][i][k] = match[l][j][k][i] = match[l][k][i][j] = match[l][k][j][i] = m++;
	   }
	}
	FOR(it, 0, n){
        FOR(s, 0, m) if(dp[p][s]){
			int a = min(state[s][0] + 1, h + 1),
				b = min(state[s][1] + 1, h + 1),
				c = min(state[s][2] + 1, h + 1),
				d = min(state[s][3] + 1, h + 1);
			int res = dp[p][s];
			add(dp[q][match[a == h + 1 ? h + 1 : 0][b][c][d]], res);
			add(dp[q][match[a][b == h + 1 ? h + 1 : 0][c][d]], res);
			add(dp[q][match[a][b][c == h + 1 ? h + 1 : 0][d]], res);
			add(dp[q][match[a][b][c][d == h + 1 ? h + 1 : 0]], res);
		}
		p ^= 1, q ^= 1;
		memset(dp[q], 0, sizeof(dp[q]));
	}
	FOR(i, 0, m) if(state[i][0] < h || state[i][1] < h || state[i][2] < h || state[i][3] < h)
		add(ans, dp[n & 1][i]);
	printf("%d\n", ans);
	return 0;
}