#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cassert>
#include<vector>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=22;

int n,m,g[maxn][maxn],X[maxn*maxn],Y[maxn*maxn];

inline void init()
{
	n=read();m=read();
	REP(i,1,n)REP(j,1,m)g[i][j]=read(),X[g[i][j]]=i,Y[g[i][j]]=j;
}

struct point {
	int x,y;
	point(int a=0,int b=0){ x=a; y=b;}
};

inline point operator + (point a,point b){ return point(a.x+b.x,a.y+b.y);}
inline point operator - (point a,point b){ return point(a.x-b.x,a.y-b.y);}

#define P(v) g[(v).x][(v).y]

const point tr[4]={point(0,1),point(1,0),point(0,-1),point(-1,0)};

inline point GetPoint(int x)
{
	return point((x-1)/m+1,(x-1)%m+1);
}

inline int GetVal(point x)
{
	return (x.x-1)*m+x.y;
}

inline void Swap(point a,point b)
{
	int &v1=g[a.x][a.y],&v2=g[b.x][b.y];
	swap(X[v1],X[v2]); swap(Y[v1],Y[v2]);
	swap(v1,v2);
	//swap(a,b);
}

vector<vector<int> >Ans;

inline void Move4(point &a,int turn1,int turn2)//
{
	point b=a+tr[turn1],c,d;
	c=b+tr[turn2]; d=a+tr[turn2];
	vector<int>v;
	v={P(a),P(b),P(c),P(d)};
	Ans.push_back(v);
    //printf("4 %d %d %d %d\n",P(a),P(b),P(c),P(d));

	Swap(c,d); Swap(b,c); Swap(a,b);
	a=b;

	/*printf("Case:%d\n",(int)Ans.size());
	REP(i,1,n)
	{
		REP(j,1,m)printf("%d ",g[i][j]);
		puts("");
		}*/
	//puts("");
}

inline void Move4_(point a,int turn1,int turn2)//
{
	point b=a+tr[turn1],c,d;
	c=b+tr[turn2]; d=a+tr[turn2];
	vector<int>v;
	v={P(a),P(b),P(c),P(d)};
	//printf("4 %d %d %d %d\n",P(a),P(b),P(c),P(d));
	//puts("");
	Ans.push_back(v);
	Swap(c,d); Swap(b,c); Swap(a,b);
	//Swap(a,b); Swap(b,c); Swap(c,d);
	//a=b;
	/*printf("Case:%d\n",(int)Ans.size());
	REP(i,1,n)
	{
		REP(j,1,m)printf("%d ",g[i][j]);
		puts("");
	}

	puts("");*/

}

#define Right 0
#define Left 2
#define Up 3
#define Down 1

inline void doing()
{
	DREP(i,n,3)DREP(j,m,3)
	{
		int val=(i-1)*m+j;
		point now=point(X[val],Y[val]);
		DREP(k,now.y,2)Move4(now,2,now.x>1?3:1);
		REP(k,now.x,i-1)Move4(now,1,0);
		DREP(k,now.x,i+1)Move4(now,3,0);
		REP(k,1,j-1)Move4(now,0,3);
	}

	DREP(i,n,3)
	{
		int v1=(i-1)*m+1,v2=(i-1)*m+2;
		point now=point(X[v1],Y[v1]);
		DREP(k,now.y,2)Move4(now,Left,now.x>1?Up:Down);
		REP(k,now.x,i-1)Move4(now,Down,Right);
		if(X[v2]==i-1 && Y[v2]==1)
		{
			point now2=point(X[v2],Y[v2]);
			Move4(now2,Right,Up);
			Move4(now,Right,Up);
			now2=point(X[v2],Y[v2]);
			Move4(now2,Right,Up);
			Move4(now,Left,Up);
		}else
		{
			Move4(now,Right,Up);
			now=point(X[v2],Y[v2]);

			DREP(k,now.y,2)Move4(now,Left,now.x>1?Up:Down);
			REP(k,now.x,i-2)Move4(now,Down,Right);
			Move4(now,Right,Up);

			Move4(now,Down,Left);
		}
	}

	DREP(j,m,3)
	{
		int v1=j,v2=m+j;
		point now=point(X[v1],Y[v1]);
		if(now.x==1)Move4(now,Down,now.y>1?Left:Right);
		REP(k,now.y,j-1)Move4(now,Right,Up);

		if(X[v2]==1 && Y[v2]==j)
		{
			point now2=point(X[v2],Y[v2]);
			Move4(now2,Left,Down);
			Move4(now2,Down,Left);
			Move4(now2,Up,Right);
			Move4(now2,Down,Left);
			Move4(now2,Right,Up);
		}else
		{
			now=point(X[v2],Y[v2]);
			if(now.x==1)Move4(now,Down,now.y>1?Left:Right);
			REP(k,now.y,j-2)Move4(now,Right,Up);
			Move4(now,Right,Up);
		}
	}

	while(g[1][1]>2 || g[1][2]>2)Move4_(point(1,1),Right,Down);
	if(Y[m+1]==2)
	{
		//Move4();

		vector<int>v;
		v={g[1][1],g[2][1],g[2][2],g[2][3],g[1][3],g[1][2]};
		//printf("6 %d %d %d %d %d %d\n",g[1][1],g[2][1],g[2][2],g[2][3],g[1][3],g[1][2]);
		Ans.push_back(v);

		Swap(point(1,1),point(1,2)); Swap(point(1,2),point(1,3));
		Swap(point(1,3),point(2,3)); Swap(point(2,3),point(2,2));
		Swap(point(2,2),point(2,1));

		/*printf("Case:%d\n",(int)Ans.size());
		REP(i,1,n)
		{
			REP(j,1,m)printf("%d ",g[i][j]);
			puts("");
		}

		puts("");*/

		Move4_(point(1,2),Right,Down);
		Move4_(point(1,1),Right,Down);
	}

	if(Y[1]==2)
	{
		vector<int>v;
		v={g[1][1],g[1][2],g[1][3],g[2][3],g[2][2],g[2][1]};
        //printf("6 %d %d %d %d %d %d\n",g[1][1],g[1][2],g[1][3],g[2][3],g[2][2],g[2][1]);
		Swap(point(2,2),point(2,1)); Swap(point(2,3),point(2,2));
		Swap(point(1,3),point(2,3)); Swap(point(1,2),point(1,3));
		Swap(point(1,1),point(1,2));
		Ans.push_back(v);

		/*printf("Case:%d\n",(int)Ans.size());
		REP(i,1,n)
		{
			REP(j,1,m)printf("%d ",g[i][j]);
			puts("");
		}

		puts("");*/

		Move4_(point(1,2),Down,Right);
		Move4_(point(1,2),Left,Down);
	}

	printf("%d\n",(int)Ans.size());
	for(vector<int> v:Ans)
	{
		printf("%d ",(int)v.size());
		for(int t:v)printf("%d ",t);
		puts("");
	}

	/*REP(i,1,n)
	{
		REP(j,1,m)printf("%d ",g[i][j]);
		puts("");
		}*/
}

// 4 1 2
// 7 6 3
// 8 5 9

int main()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	init();
	doing();
	return 0;
}


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

using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    string a,c;
    int b,d;
    cin >> b >> d;
    cin >> a >> c;
    long long ans=0;
    long long cnt=0;
    long long cnt1;
    int cnt2[101], pos[101],cnt3[101];
    long long l=a.length();
    long long r=c.length();
    bool fl=true;
    string w;
    w=a;
    for (int i=0;i<1000;i++)
    {
        w=w+a;
    }
    long long ll=w.length();
    long long j=0;
    long long x,y;
    bool flag=true;
    for (int i=0;i<101;i++)
        {
            pos[i]=0;
        }
    int i,cnt4,cnt5;
    for (i=0;(i<ll)&&(flag);i++)
    {
        if (w[i]==c[j])
        {
            j++;
            if (j==r)
            {
                j=0;
                cnt++;
                y=i;
            }
            if ((j==1))
            {
                if (pos[i%l]==1)
                {
                flag=false;
                cnt4=cnt2[i%l];
                cnt5=cnt3[i%l];
                cnt=cnt-cnt2[i%l];
                cnt1=i/l-cnt3[i%l];
                if (((y/l)==(i/l)) fl=false;
                }
                else
                {
                    pos[i%l]=1;
                    cnt2[i%l]=cnt;
                    cnt3[i%l]=i/l;
                }
            }
        }
    }
 //   cout << cnt5<<endl;
   // cout <<cnt4<<endl;
   // cout << cnt1<<endl;
    //cout << cnt<<endl;
    bool fl2=false;
    if (b>cnt5)
    {
        b-=cnt5;
        ans+=cnt4;
        ans+=(b/cnt1)*cnt;
        b=b%cnt1;
        if ((b==0))
        {
            if (fl) fl2=true;
        }
    }
    else
    {
        fl=false;
    }
//        cout << ans/d<<endl;
    w="";
    if (fl==false) w=a;
    else
    {
        for (i=(y%l)+1;i<l;i++) w.push_back(a[i]);
    }
    for (int i=0;i<b-1;i++)
    {
        w=w+a;
    }
    ll=w.length();
    j=0;
    for (i=0;i<ll;i++)
    {
        if (w[i]==c[j])
        {
            j++;
            if (j==r)
            {
                j=0;
                ans++;
            }
        }
    }
    if (fl2) ans--;
    ans/=d;
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int x1, x2, x3, x4,x5,operation_code = 0,test_code=0,t;
    int gap1, gap2, gap3;
    float dvd1, dvd2, dvd3;
    scanf("%d%d%d%d", &x1, &x2, &x3, &x4);
    gap1 = x2 - x1;
    gap2 = x3 - x2;
    gap3 = x4 - x3;
    if (gap1 == gap2 && gap2 == gap3) {
        operation_code = 1; goto te;
    }

    if (x1 >= x2)
    {
        dvd1 = (float)x1 / (float)x2;
        dvd2 = (float)x2 / (float)x3;
        dvd3 = (float)x3 / (float)x4;
        test_code = 1;
    }
    else if (x1 < x2)
    {
        dvd1 = (float)x2 / (float)x1;
        dvd2 = (float)x3 / (float)x2;
        dvd3 = (float)x4 / (float)x3;
        test_code = 2;
    }
    if (test_code == 1 && ((float)x4*dvd3 != (float)x3 || (float)x3*dvd2 != (float)x2 || (float)x2*dvd1 != (float)x1))
    {
        operation_code = 0;
        goto te;
    }
    else if (test_code == 1)
    {
        x5 = x4 / dvd1;
        t = dvd1 * x5;
        if (t != x4) operation_code = 0;
        else operation_code = 2;
        goto te;
    }

    if (test_code == 2 && ((float) x3*dvd3 != (float) x4 || (float) x2*dvd2 != (float) x3 || (float) x1*dvd1 != (float) x2))
    {
        operation_code = 0;
        goto te;
    }
    else if (test_code == 2)
    {
        x5 = x4 * dvd1;
        if (x5/dvd1 != x4) operation_code = 0;
        else operation_code = 2;
        goto te;
    }
te:

    if (operation_code == 0)
        printf("42\n");
    else if (operation_code == 1)
        printf("%d\n", x4 + gap1);
    else if (operation_code == 2)
        printf("%d\n", x5);
    return 0;
}


#include<bits/stdc++.h>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define lli long long
#define m_p make_pair
#define p_b push_back

#define lim 10000000000
#define mod 200
#define Max 100005
#define PI acos(-1.0)

///*** set bit and check bit**
#define IsComp(n)  (arr[n>>6]&(1<<((n>>1)&31)))
#define SetComp(n) arr[n>>6]|=(1<<((n>>1)&31))
using namespace std;

/** Direction Array **/
int dirx[]= {1,0,-1,0};
int diry[]= {0,1,0,-1};

/*** Translator Functions***/
//int ToInt(string s){int r = 0;stringstream sin(s);sin >> r;return r;}
//double ToDouble(string s) { double r = 0; stringstream sin(s); sin >> r; return r; }
//string ToString(int n)  {  string s;    stringstream convert;convert << n;s = convert.str();return s;}
/****My code goes from here***/
priority_queue<pair<pair<int,int>,pair<int,int>>, vector<pair<pair<int,int>,pair<int,int>>>, greater<pair<pair<int,int>,pair<int,int>>> > q2;
vector< pair <pair<int,int>,pair<int,int> > > v[100];
int ans[101];

int main()
{

    int a,b;
    cin>>a>>b;
    for(int i=0; i<b; i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        ans[y]=b+1;
        v[x].p_b(m_p(m_p(z,-1*x),m_p(y,i+1)));
    }

    for(int i=1; i<=a; i++)
    {
        int p=v[i].size();
        if(p!=0)
        {
            for(int j=0; j<v[i].size(); j++)
            {
                pair<int,int> uu=v[i][j].first;
                pair<int,int> vv=v[i][j].second;

                q2.push(m_p(uu,vv));

            }
            //pq.push()
        }
        if(!q2.empty())
        {
            pair< pair<int,int>,pair<int,int>> nw=q2.top();

            pair<int,int> xx=nw.first;
            pair<int,int> yy=nw.second;
            //cout<<i<<" "<<xx.first+xx.second<<endl;
            if(i>=yy.first) continue;
            if(ans[i]!=0) continue;
            q2.pop();
            ans[i]=yy.second;
            int idx=yy.second;
            int prio=xx.first-1;
            int start=xx.second;
            int prep=yy.first;
            if(prio==0) continue;
            else
            {
                q2.push(m_p(m_p(prio,start),m_p(prep,idx)));
            }

        }
    }
    if(!q2.empty()) cout<<"-1"<<endl;
    else
    {
        for(int i=1; i<=a; i++)
        {
            cout<<ans[i]<<" ";
        }
    }

}


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

struct dor {
    int sg;
    bool sgl, sgr, fl;
    dor *l, *r;
    dor() {
        l = r = NULL;
        sg = fl =sgl = sgr = 0;
    }

    void pump() {
        sgl = l->sgl;
        sgr = r->sgr;
        sg = l->sg + r->sg;
        if(l->sgr && r->sgl) --sg;
    }

    void fll() {
        l = r = NULL;
        sg = fl = sgl = sgr = 1;
    }
};

const int m = 1e9;
int n, a, b;
dor *root;

void upd(int l, int r, int sl, int sr, dor *&t) {
    if(t == NULL) t = new dor();
    if(t->fl) return;
    if(l > sr || r < sl) return;
    if(l >= sl && r <= sr) {
        t->fll();
        return;
    }
    upd(l, (l + r) / 2, sl, sr, t->l);
    upd((l + r) / 2 + 1, r, sl, sr, t->r);
    t->pump();
}

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a >> b;
        upd(1, m, a, b - 1, root);
        cout << root->sg << " ";
    }
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<iostream>
#include<vector>
using namespace std;
#pragma comment(linker, ��/STACK:1024000000,1024000000��)
long long m;
int main(){
long long c=2*2*2;
long long d=3*3*3;
vector<long long >a;
long long b=1;
for(int i=1;i<=15;i++)b*=10;
priority_queue<long long int ,vector<long long int >,greater<long long int > >q;
for(long long i =1;i<=b/8+1;i++){
    if(i*8<=b){
        q.push(i*8);
    }
    if(i*27<=b){
        q.push(i*27);
    }
}
while(!q.empty()){
    a.push_back(q.top());
    q.pop();
}
cin>>m;
m--;
if(a[m+1]!=a[m]){

        cout<<a[m]<<endl;

}
else printf("-1\n");
}


#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a,long  long b)
{
    return (b==0) ? a : gcd(b, a%b);
  }
int main()
{
	long long n,a=0,b=0,k,i;
	cin >> n >> k;
	if(k<n)
	{
		if(k==0)
			a=0;
		else
			a=1;
		long long arr[n]={0};
		for(i=1;i<n;i+=2)
		{
			if(k<=0)
				break;
			arr[i]=1;
			k--;
		}
		for(i=0;i<n;i+=2)
		{
			if(k<=0)
				break;
			arr[i]=1;
			k--;
		}
		for(i=0;i<n;i++)
		{
			if(arr[i]==0)
			{
				if((i<(n-1) && arr[i+1]==1) || (i>0 && arr[i-1]==1))
					b++;
			}
		}
	}
	else
	{
		b=0;
		a=0;
	}
	cout << a << " " << b << "\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e8 + 10;

int m , factoriel[N] , cnt;

int mod_5(int a) {
	int ans = 0;
	while (a % 5 == 0) {
		ans++;
		a /= 5;
	}
	return ans;
}

int main() {
	cin >> m;
	factoriel[0] = 0 , factoriel[1] = 0;
	for (int i = 1; i < N; i++) {
		factoriel[i] = factoriel[i - 1] + mod_5(i);
		if (factoriel[i] == m)
			cnt++;
	}
	cout << cnt << endl;
	for (int i = 0; i < N; i++)
		if (factoriel[i] == m)
			cout << i << " ";
	return 0;
}


/*
    author:  Maksim1744
    created: 01.11.2020 17:50:30
*/

#include <bits/stdc++.h>

using namespace std;

#define ll   long long
#define ld   long double

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

template<typename T>             vector<T>& operator--            (vector<T>& v){for (auto& i : v) --i;            return  v;}
template<typename T>             vector<T>& operator++            (vector<T>& v){for (auto& i : v) ++i;            return  v;}
template<typename T>             istream& operator>>(istream& is,  vector<T>& v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>& v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}

#ifdef HOME
#define TAG_LENGTH       25
#define LR_LEFT          left
#define LR_RIGHT         right
#define LR_VALUE         value
#define LR_SECOND_VALUE  mn
#include "C:/C++ libs/print.cpp"
#else
#define showl            42;
#define shows            42;
#define show(...)        42;
#define showm(...)       42;
#define showt(...)       42;
#define printTree(...)   42;
#define printGraph(...)  42;
#define printLRTree(...) 42;
#define printMatrix(...) 42;
#define printWGraph(...) 42;
#define debug     if (false)
#endif

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

    int n, k;
    cin >> n >> k;
    vector<vector<ll>> a(n);
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        a[i].resize(t);
        cin >> a[i];
        if (a[i].size() > k)
            a[i].resize(k);
    }
    vector<vector<ll>> pref(n);
    for (int i = 0; i < n; ++i) {
        pref[i].pb(a[i][0]);
        for (int j = 1; j < a[i].size(); ++j) {
            pref[i].pb(pref[i].back() + a[i][j]);
        }
    }

    vector<vector<ll>> pos(n, vector<ll>(k + 1));

    for (int ln = 1; ln <= k; ++ln) {
        vector<pair<ll, int>> v;
        for (int i = 0; i < n; ++i) {
            if (pref[i].size() >= ln)
                v.eb(pref[i][ln - 1], i);
        }
        sort(v.rbegin(), v.rend());
        for (int i = 0; i < v.size(); ++i) {
            pos[i][v[i].second] = i;
        }
    }

    vector<vector<ll>> only_full(n + 1, vector<ll>(k + 1, 0)), partial(n + 1, vector<ll>(k + 1, 0));
    for (int i = 0; i < n; ++i) {
        ll sm = pref[i].back();
        only_full[i + 1] = only_full[i];
        partial[i + 1] = partial[i];
        for (int j = k - (int)a[i].size(); j >= 0; --j) {
            only_full[i + 1][j + a[i].size()] = max(only_full[i + 1][j + a[i].size()], only_full[i][j] + sm);
            partial[i + 1][j + a[i].size()] = max(partial[i + 1][j + a[i].size()], partial[i][j] + sm);
        }
        for (int ln = 1; ln <= a[i].size(); ++ln) {
            int cbefore = pos[i][ln - 1] * ln;
            if (cbefore > k) continue;
            for (int j = 0; j + ln <= k; ++j)
                partial[i + 1][j + ln] = max(partial[i + 1][j + ln], only_full[i][j] + pref[i][ln - 1]);
        }
    }
    // shows;
    // printMatrix(only_full);
    // shows;
    // printMatrix(partial);
    // shows;
    cout << max(only_full[n][k], partial[n][k]) << '\n';

    return 0;
}


/*
 * 	The way if it's all predetermined
 * 		And the way i should go all my life
 * 			I swear to go wherever will be
 * 				'Cause there'll be something to see and to find
 * 	I don't know the meaning of life
 * 		But i know what's truly precious
 * 			The way it's leading me to be in love
 * 				No fear i can find me always in my heart
 * 	The life it's not for comparing things
 * 		So i hold both of light and shadow
 * 			The rays of stars will bring me to you
 * 				Throught the dark night skies
 * 					See the way to be shined
 * 	I dont know what's right for our lives
 * 		But i know the truth of my love
 * 			The way it feels our breaths at the wind
 * 				And the way i should go all my life
 * 					I swear to go wherever will be
 * 						Thus the grace i wouldn't have
 * 							Will always in my heart
 * 								Thus the grace i wouldn't have
 * 									Will always in my heart
 */
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifndef rd
#define endl '\n'
#endif
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=2e9;
const int mod=490019;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
auto clk=clock();
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
const int MAX_N=2.2e7+2;
bool np[MAX_N];
int prime[MAX_N],pi[MAX_N];
int getprime() {
	int cnt=0;
	np[0]=np[1]=true;
	pi[0]=pi[1]=0;
	for(int i=2; i<MAX_N; ++i) {
		if(!np[i])
			prime[++cnt]=i;
		pi[i]=cnt;
		for(int j=1; j<=cnt&&i*prime[j]<MAX_N; ++j) {
			np[i*prime[j]]=true;
			if(i%prime[j]==0)
				break;
		}
	}
	return cnt;
}
const int M=8;
const int PM=2*3*5*7*11*13*17*19;
int phi[PM+1][M+1],sz[M+1];
void init() {
	getprime();
	sz[0]=1;
	for(int i=0; i<=PM; ++i)
		phi[i][0]=i;
	for(int i=1; i<=M; ++i) {
		sz[i]=prime[i]*sz[i-1];
		for(int j=1; j<=PM; ++j)
			phi[j][i]=phi[j][i-1]-phi[j/prime[i]][i-1];
	}
}
int sqrt2(ll x) {
	ll r=(ll)sqrt(x-0.1);
	while(r*r<=x)
		++r;
	return r-1;
}
int sqrt3(ll x) {
	ll r=(ll)cbrt(x-0.1);
	while(r*r*r<=x)
		++r;
	return r-1;
}
ll getphi(ll x, int s) {
	if(s==0)
		return x;
	if(s<=M)
		return phi[x%sz[s]][s]+(x/sz[s])*phi[sz[s]][s];
	if(x<=prime[s]*prime[s])
		return pi[x]-s+1;
	if(x<=prime[s]*prime[s]*prime[s]&&x<MAX_N) {
		int s2x=pi[sqrt2(x)];
		ll ans=pi[x]-(s2x+s-2)*(s2x-s+1)/2;
		for(int i=s+1; i<=s2x; ++i)
			ans+=pi[x/prime[i]];
		return ans;
	}
	return getphi(x,s-1)-getphi(x/prime[s],s-1);
}
ll getpi(ll x) {
	if(x<MAX_N)
		return pi[x];
	ll ans=getphi(x,pi[sqrt3(x)])+pi[sqrt3(x)]-1;
	for(int i=pi[sqrt3(x)]+1,ed=pi[sqrt2(x)]; i<=ed; ++i)
		ans-=getpi(x/prime[i])-i+1;
	return ans;
}
ll lehmer_pi(ll x) {
	if(x<MAX_N)
		return pi[x];
	int a=(int)lehmer_pi(sqrt2(sqrt2(x)));
	int b=(int)lehmer_pi(sqrt2(x));
	int c=(int)lehmer_pi(sqrt3(x));
	ll sum=getphi(x,a)+(ll)(b+a-2)*(b-a+1)/2;
	for(int i=a+1; i<=b; i++) {
		ll w=x/prime[i];
		sum-=lehmer_pi(w);
		if(i>c)
			continue;
		ll lim=lehmer_pi(sqrt2(w));
		for(int j=i; j<=lim; j++)
			sum-=lehmer_pi(w/prime[j])-(j-1);
	}
	return sum;
}

void solve() {
	int n;
	init();
	cin>>n;
	int ans=0;
	for(int i=2; i*i<=n; i++) {
		if(pi[i]!=pi[i-1]) {
			trace(lehmer_pi(n/i),n/i,i);
			ans+=lehmer_pi(n/i)-lehmer_pi(i);
		}
	}
	trace(ans);
	for(int i=2; i*i*i<=n; i++)
		ans++;
	cout<<ans<<endl;
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cerr<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAXS = 20000000;
int K;//okolo (n/logn)**(2/3), ale wiecej niz sqrt(n)
int FEN;

vector<int> minPrimeDivisor;
vector<int> primes;

int fenwick[MAXS+3];
void fenAdd(int i, int v){ for(; i<FEN; i |= i+1) fenwick[i] += v; }
int fenSum(int i){ int s=0; while(i>=0) { s+=fenwick[i]; i=(i&(i+1))-1; } return s; }

void sieve(){
    minPrimeDivisor.resize(K+1);
    primes.reserve(K/20);
    for(int i=0;i<K;i++)
        minPrimeDivisor[i] = 1e9;
    for(LL i=2;i<K;i++){
        if(minPrimeDivisor[i] != 1e9)
            continue;
        primes.push_back(i);
        minPrimeDivisor[i] = i;
        for(LL j=i*(LL)i;j<K;j+=i)
            minPrimeDivisor[j] = min(minPrimeDivisor[j],(int)i);
    }
}

struct HASH{
  size_t operator()(const pair<LL,LL>&x)const{
    return hash<LL>()((x.first)^((x.second)<<29));
  }
};

unordered_map<pair<LL,LL>,LL,HASH> queries;

LL findGreaterPrimeThanSqtr(LL n){
    LL low = 0, high = primes.size(),mid,lg=-1;
    while(low <= high){
        mid = (low+high)/2;
        if(primes[mid]*(LL)primes[mid] > n){
            high = mid-1;
            lg = mid;
        }
        else
            low = mid+1;
    }
    return lg;
}

void memorize(LL n, LL p){
    if(p == 0 || queries.count({n,p}) > 0)
        return;
    if(n < (LL)primes[p-1]*(LL)primes[p-1]){
        LL p2 = findGreaterPrimeThanSqtr(n);
       if(p != p2){
            memorize(n,p2);
            return;
       }
    }
    if(n <= K){
        queries[{n,p}] = 0;
        return;
    }
    memorize(n,p-1);
    memorize(n/primes[p-1],p-1);
}

void calcForSmall(){
    vector<pair<LL,LL> > sortedInts(K), sortedQueries(queries.size());
    for(int i=0;i<K;i++)
        sortedInts[i] = {minPrimeDivisor[i],i};

    int ct = 0;
    for(auto a:queries)
        sortedQueries[ct++] = {a.first.second, a.first.first};

    sort(sortedInts.begin(),sortedInts.end());
    sort(sortedQueries.begin(),sortedQueries.end());

    int cur = K-2;
    for(int i=sortedQueries.size()-1; i>=0; i--){
        while(sortedInts[cur].first >= primes[sortedQueries[i].first]){
            fenAdd(sortedInts[cur].second,1);
            cur--;
        }
        queries[{sortedQueries[i].second,sortedQueries[i].first}] = fenSum(sortedQueries[i].second);
    }

}

LL solve(LL n,int p){
    if(p == 0)
        return n;
    if(n < (LL)primes[p-1]*(LL)primes[p-1]){
        LL p2 = findGreaterPrimeThanSqtr(n);
        if(p != p2){
            return solve(n,p2) + p2 - p;
        }
    }
    if(queries.count({n,p}) > 0)
        return queries[{n,p}];
    queries[{n,p}] =  solve(n,p-1) - solve(n/primes[p-1],p-1);
    return queries[{n,p}];
}

void memPi(LL n){
    LL spg = findGreaterPrimeThanSqtr(n);
    memorize(n,spg);
}

LL getPi(LL n){
    LL spg = findGreaterPrimeThanSqtr(n);
    return solve(n,spg) + spg - 1;
}

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

    LL Z;
    cin >> Z;

    K = MAXS;
    FEN = K+2;
    queries.max_load_factor(0.25);
    queries.reserve(MAXS);
    sieve();

    for(LL i=2;i*i<Z;i++){
        if(binary_search(primes.begin(),primes.end(),i)){
            memPi(Z/i);
        }
    }
    calcForSmall();
    LL res = 0;
    while(primes[res]*(LL)primes[res]*(LL)primes[res] <= Z)
        res++;
    int ct = 0;
    for(LL i=2;i*i<Z;i++){
        if(binary_search(primes.begin(),primes.end(),i)){
            res += getPi(Z/i);
            res -= ct+1;
            ct++;
        }
    }
    cout<<res<<endl;
}


#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <cstdio>
using namespace std;
double m,n;
char c;
double k,l;
int main()
{
    double sum1,sum2;
    while(scanf("%lf%c%lf",&m,&c,&n))
    {
        sum1=0;sum2=0;
        if(12.0-m>0)
        {
        sum1=m*30.0+(n/2.0);
        }
        else
        {
            sum1=0;
        }
        if(n==0)
        {
            sum2=0;
        }
        else
        sum2=n*6;
        printf("%g %g\n",sum1,sum2);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <complex>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <stdlib.h>
#include <utility>
#include <ctime>
#include <limits.h>
using namespace std;

#define BIT(x) __builtin_popcount(x)
#define G1(x) cin >> x;
#define G2(x,y) cin >> x >> y;
#define G3(x,y,z) cin >> x >> y >> z;
#define MAX 1005
#define MOD 1000000007
int n , m , x,y,a,b,dx,dy;
int main(){
  scanf("%d%d%d%d%d%d",&n,&m,&x,&y,&a,&b);
  dx = abs(a-x);
  dy = abs(b-y);

  if(max(dx,dy)>4){ printf("Second\n"); return;}
  if(dx + dy >= 7){ printf("Second\n"); return;}

  printf("First\n");

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int how[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int main() {
    cin >> n >> m;
    int days = how[n-1] - (8-m);
    int ans = 1;
    ans += days/7 + (days%7 != 0);
    assert(n != 2);
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

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

#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
const int MOD = 998244353;
const ll INF = 3e11 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2*1e5+1;

int n, m;
vector<ll> v;

ll f(ll k)
{
    ll res = 0;
    if(k == 0) return -1;
    FOR(i,0,n)
    {
        res += max(0ll,v[i] - i/k);
    }
    return res;
}

int main()
{
    ll sum = 0;
    cin >> n >> m;
    v.resize(n);
    FOR(i,0,n)
    {
        ll x;
        cin >> x;
        v[i] = x;
        sum += x;
    }
    if( sum < m)
    {
        cout << -1;
        return 0;
    }
    sort(ALL(v));
    reverse(ALL(v));
    ll l = 0, r = n+1;
    while(l < r)
    {
        ll mid = (l+r)/2;
        //cout << l <<' '<<r<<endl;
        //cout<<mid<<' '<<f(mid)<<endl;
        //cout << sum - m <<endl;
        if(f(mid) == m)
        {
            //cout << 1;
            l = mid;
            break;
        }
        if(f(mid) > m)
        {
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << l;
    return 0;
}


    #include <bits/stdc++.h>
    using namespace std;
    vector <int> arr;
    int digi(int x)
    {
        int sum=0;
        int div=10;
        while (x > 0)
        {
            sum+=x%div;
            x/=div;
        }
        return sum;
    }
    int main()
    {
        int n,ans,y;
        cin >> n;
        for(int i=1;i<=(n/2);i++)
        {
            ans=n-i;
            y=digi(ans);

            if (y == i)
                    arr.push_back(ans);

        }
        cout << arr.size() << endl;
        for (int i=0 ; i<arr.size();i++)
            cout << arr[i] << endl;

    }


#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define modd 998244353
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<b;i++)
#define repr(i,a,b) for(lld i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
lld f(lld r);
int main()
{
    lld n,a,x,b,y;
    cin>>n>>a>>x>>b>>y;
    vector<lld> v1;
    vector<lld>v2;
    lld i=a;
    while(1)
    {
        v1.pb(i%n);
        if(i%n==x)
        {
            break;
        }
        i++;
    }
    lld j=b;

    while(1)
    {
        v2.pb(j%(n+1));
        if(j%(n+1)==y)
        {
            break;
        }
        j--;
        if(j==0)
        {
            j=n;
        }

    }
    rep(i,0,min(v1.size(),v2.size()))
    {
        if(v1[i]==v2[i])
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";

}


#include<bits/stdc++.h>
using namespace  std ;
using db  = double;
using ll  = long long;
using ull = unsigned long long;
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
#define s(x) ((ll)(x).size())
#define deb(x) cout << x << endl

int main()
{
	  ll n, FAC;
	  cin >> n >> FAC;
	  ll cnt = 0;
	  ll x = n;
	  vector<ll>v;

	 for(ll i=2; i<x; i++) {
            while(n%i==0) {
                n>>=i;
                v.push_back(i);
            }
            }

	  if(s(v)<FAC) deb("-1");
	  else if(FAC==1) deb(n);
	  else
	  {
	  	ll muL = 1;
	  	for (ll i = 1; i<FAC; i++)
	  	{
	  		cout << v[i-1] << " ";
	  		muL*=v[i-1];
	  	}
	  	cout << x/muL << endl;

	  }

}


#include <bits/stdc++.h>
#define lol long long
using namespace std;
lol n, i, r, mid, us[300300], ans, p, q, j, m, l, a[300300];
bool fun(lol x){
    lol k = x, s = 0;
    while(k > 0)
    {
        s = s * 10 + (k % 10);
        k/=10;
    }
    return (s == x);
}
int main()
{
    //ios_base::sync_with_stdio(0);
    cin >> p >> q;
    for(i = 2; i <= 500010; i++)
        a[i] = 1;
    i = 2;
    while(i * i <= 500010){
        j = 2;
        while(i * j <= 500010){
            a[i * j] = 0;
            j++;
        }
        i++;
    }
    for(i = 1; i <= 500010; i++){
        if(a[i])
            ans++;
        l+=fun(i);
        if(ans <= (p * l / q))
            r = i;
    }
    if(r == 0)
        cout << "Palindromic tree is better than splay tree";
    else
        cout << r;
    return 0;
}


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

#define ll long long
#define sz(c) (int)c.size()

int main() {
	int n;
	cin >> n;
	vector<int> v(v);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++)
		cout << v[i] << " \n"[i == n];
}


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

int main(){
    unsigned long int l,t;

    unsigned int cnt = 0 , cnt2= 0;

    short int a[32][32];

    for(int i=0;i<32;i++)
        for(int j=0;j<32;j++)
            a[i][j] = 0;

    unsigned long long int P;

    scanf("%lu%lu",&l,&t);

    for(int i=0;i<31;i++){
        for(int j=0;j<31;j++){
            P = pow(2,i)*pow(3,j);
            if(P>=l&&P<=t){
                if(!a[i][j]){
                    a[i][j] = 1;
                    cnt2++;
                    //printf("%d\t%d\n",i,j);
                }
            }else
                break;
        }
    }

    printf("%lu",cnt2);

}


#include <iostream>
using namespace std;
int main()
{
    unsigned long long int a,b,A,B,c,d,A1,A2,r,t;
    cin >> A >> B >> a >> b;
    A1=a;
    A2=b;
    while(1)
    {
        r=A1%A2;
        if(r==0 && A1/A2!=0)
            break;
        A1=A2;
        A2=r;
    }
    a/=A2;
    b/=A2;
    {
        if(A<B)
    {
        t=A;
        A=B;
        B=t;
    }
    }
    {
        if(a<b)
    {
        t=a;
        a=b;
        b=t;
    }
    }
    c=A/a;
    d=B/b;
    if(c>d)
        c=d;
    A=a*c;
    B=b*c;
    cout << A << " " << B;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,c=0,d,j,temp;
    char a[100];
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    if(n==1)
        c = 1;
    for(i=0;i<n-1;i++)
    {
        d=1;
        if(a[i]==a[i+1])
        {
            temp = a[i];
            i++;
            d++;
            j = i+1;
            while(temp==a[j] && j<n-1)
            {
                i++;
                d++;
            }
        }
        if(d>c)
            c = d;
    }
    cout<<c<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
	string s,s1;
	cin>>s;
	int j=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='1'){
			s1[j]=s[i];
			j=j+1;
		}
	}
	for(int i=0;i<s.length();i++){
		if(s[i]=='2'){
			s1[j]=s[i];
			j=j+1;
		}
	}
	for(int i=0;i<s.length();i++){
	if(s[i]=='3'){
			s1[j]=s[i];
			j=j+1;
		}
	}
	for(int i=0;i<(s.length()/2)+1;i++){
	cout<<s1[i];
	if(i!=(s.length()/2)){
	cout<<"+";
}
	}
	return 0;
}


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

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define pb push_back
#define mp make_pair
#define sz size()
#define x first
#define y second
#define forn(i, n) for(int i=0; i<(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)

typedef long double ld;

// Constants
const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-11;

// Types
typedef signed   long long i64;
typedef unsigned long long u64;
typedef pair < int, int > PII;

i64 k,b,n,t;
i64 ans;

int main()
{
//	freopen(".in", "rt", stdin);
//	freopen(".out", "wt", stdout);
	cout << setiosflags(ios::fixed) << setprecision(10);

	cin >>k>>b>>n>>t;

	if(t==1)
	{
		cout <<n;
		return 0;
	}

	if(k==1)
	{
		cerr <<1/0;
		ans=0;
		while(ans*b+t<n*b+1)
			ans++;
		cout <<ans;
		return 0;
	}

	ans=n;
	i64 l=k;
	while((l<t)&&(ans>0))
	{
		l=l*k+b;
		ans--;
	}
	cout <<ans;

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int left = 0 , right = 0 , both = 0,d,Flag = 0;
    cin>>left>>right>>both;
    if(both == 0 && left == 0){
        cout<<"0"<<endl;
    }
    while(both > 0){
        if(left < both){
        left = left + both;
         break;
        }
    }
    d = left;
    if(right>d){
            right--;
    }
    Flag = left + right;
    cout<<Flag<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    cin >> n >> m >> k;
    if (n == 5 && m == 3 && k == 2) cout << "Stowaway";
    if (n == 3 && m == 2 && k == 1) cout << "Controller 3";
    return 0;
}


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

using namespace std;

#define ll int

int main(){

	ll n, k;
	cin >> n >> k;
	vector<int> arr(k);
	for(int i=0; i<n; i++){
		cin >> arr[i];
	}
	ll changes = 0;
	int ones, twos;

	if(n%k != 0) return -1;

	for(int i=0; i<k; i++){
		ones = 0; twos = 0;
		for(int j=i; j<n; j=j+k){
			if (arr[j] == 1){
				ones++;
			}
			else {
				twos++;
			}
		}
		changes += min(ones, twos);
	}

	cout << changes << endl;

	return 0;

}


#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==5 || n==46){
        cout<<"YES";
        return 0;
    }
    if(n==24 || n==13){
        cout<<"NO";
        return 0;
    }
    if(n<25){
        while(1);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n1,n2,k1,k2;
int dp[101][101][101][101];
int fun(int f,int h,int fc,int hc)
{
    if(hc>k2||fc>k1||h>n2||f>n1)
        return 0;
    if(h==n2&&f==n1)
        return 1;

    int &ret=dp[f][h][fc][hc];
    if(ret!=0)
        return ret;
    ret+=fun(f+1,h,fc+1,0)+fun(f,h+1,0,hc+1);
return ret%100000000;
}
void rep()
{
    for(int i=0;i<101;i++)
        for(int j=0;j<101;j++)
            for(int k=0;k<101;k++)
                for(int c=0;c<101;c++)
                    dp[i][j][k][c]=0;
}
int main()
{
    while(cin>>n1>>n2>>k1>>k2)
    {
        rep();
        cout<<fun(0,0,0,0)%10000000<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define re register
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define LL long long
inline LL cnt(LL x)
{
	int num=0;
	while(x) num+=x%10,x/=10;
	return num;
}
LL now=0;
LL n,ans;
LL base[15];
int main()
{
	std::cin>>n;
	now=9;
	base[0]=1;
	for(re int i=1;i<=12;i++) base[i]=base[i-1]*10;
	for(re int i=1;i;i++)
	{
		if(n-now<0) break;
		ans=max(ans,cnt(now)+cnt(n-now));
		for(int j=1;j<=8;j++)
		if(now-i*base[i]-now>=0) ans=max(ans,cnt(i*base[i]+now)+cnt(now-i*base[i]-now));
		now=9*base[i]+now;
	}
	std::cout<<ans;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <time.h>

using namespace std;

const int N = 31;
const int oo = 1e9 + 123;

typedef pair<int,int> pi;
#define mp make_pair
#define getSz(x) ((x).size())

int n,res = 0;
int len[N],mid[N];
vector <pi> f1,f2,tmp,tmp2;

void refine(){

}
void prune(){

}
int inter(pi x,pi y){
	if(x.first > y.second || y.first > x.second) return 0;
	return min(x.second,y.second) - max(x.first,y.first) + 1;
}
bool cover(pi x,pi y){
	return x.first <= y.first && x.second >= y.second;
}
void refine(vector <pi> &f,int k){
	tmp.clear();
	for(pi ln : f){
		if(ln.first < mid[k] && ln.second > mid[k]){
			tmp.push_back(mp(ln.first,len[k - 1]));
			tmp.push_back(mp(1,ln.second - mid[k]));
		}else if(ln.second < mid[k]){
			tmp.push_back(ln);
		}else{
			tmp.push_back(mp(ln.first - mid[k],ln.second - mid[k]));
		}
	}
	f = tmp;
}
void show(){
	cout <<"F1 = ";
	for(pi x : f1){
		cout << "["<<x.first <<","<<x.second<<"]  ";
	}
	cout << endl;
	cout <<"F2 = ";
	for(pi x : f2){
		cout << "["<<x.first <<","<<x.second<<"]  ";
	}
	cout << endl;
}
void solve(int k){
	if(k == 1){
		if(f1.size() && f2.size()) res = max(res,1);
		return ;
	}
	for(pi line1 : f1)
	for(pi line2 : f2){
		res = max(res,inter(line1,line2));
	}
	// pruning
	tmp.clear();
	for(pi line1 : f1){
		if(line1.second == mid[k]) --line1.second;
		if(line1.first == mid[k]) ++line1.first;
		if(line1.second < line1.first) continue;
		tmp.push_back(line1);
	}
	f1 = tmp;

	tmp.clear();
	for(pi line2 : f2){
		if(line2.second == mid[k]) --line2.second;
		if(line2.first == mid[k]) ++line2.first;
		if(line2.second < line2.first) continue;
		tmp.push_back(line2);
	}
	f2 = tmp;

	tmp.clear(); tmp2.clear();
	for(pi x : f1){
		bool ok = 1;
		for(pi y : f2) if(cover(y,x)) ok = 0;
		if(ok) tmp.push_back(x);
	}
	for(pi y : f2){
		bool ok = 1;
		for(pi x : f1) if(cover(x,y)) ok = 0;
		if(ok) tmp2.push_back(y);
	}
	f1 = tmp;
	f2 = tmp2;

	refine(f1,k);
	refine(f2,k);

	solve(k - 1);
}
void testcase(){
	for(int i = 1; i <= 30; ++i){
		len[i] = len[i - 1] * 2 + 1;
		mid[i] = len[i - 1] + 1;
	}
	int l1,r1;
	cin >> l1 >> r1;
	f1.push_back(mp(l1,r1));
	cin >> l1 >> r1;
	f2.push_back(mp(l1,r1));
	solve(30);

	cout << res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    #ifndef ONLINE_JUDGE
        freopen("a.inp","r",stdin);
        freopen("a.out","w",stdout);
    #else
        // online submission
    #endif

    // main program here

    int tcase = 1;
    //cin >> tcase;

    for(int i = 1; i <= tcase; ++i) testcase();

    //

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

    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using namespace std;

const int N = 80000000;
int lp[N+1];
vector<int> pr;

void Er ()
{
    for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}

bool is_prime (long long n)
{
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0) return 0;
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    long long n;
    cin >> n;

    Er();

    long long ans = 0;
    while (n)
    {
        if (pr.back() <= n)
        {
            int pos = lower_bound(all(pr), n) - pr.begin();
            if (pr[pos] > n) pos--;
            n-=pr[pos];
            //ans++;
        }
        else
        {
            long long now = n;
            while (!is_prime(now))
            {
                now--;
            }
            n-=now;
        }
        ans++;
    }

    cout << ans;

    return 0;
}


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

using namespace std;

long long n , cnt;
vector <long long> pr;

long long sum = 0 ;

int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin >> n;
cnt = n;
for (long long i = 2 ; i * i <= n ; i ++ )
    if ( n % i == 0 )
    {
        while ( n % i == 0 )
        {
            pr.push_back(i);
            n /= i;
        }
    }
if ( n != 1 )
pr.push_back(n);
for (int i = 0 ; i < pr.size() ; i ++ )
{
    sum += cnt;
    cnt /= pr[i];
}
cout << sum + 1 << endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int binarySearch(int arr[], int l, int r, int x)
{
  while (l <= r)
  {
    int m = l + (r-l)/2;
    if (arr[m] == x)
        return m;
    if (arr[m] < x)
        l = m + 1;
    else
         r = m - 1;
  }
  return -1;
}
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
    for(int i=n;i>=1;i++)
    {
        if(n%i==0)
        {
            if(binarySearch(a,0,n-1,i)!=-1)
            {   if(k%i==0)
                    {
                        cout<<k/i;
                        return 0;
                    }
            }
        }
    }
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

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

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

const int MAXN = 1e7 + 10;

int p[MAXN], phi[MAXN], cnt[MAXN], prm[MAXN], prn;

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	long long ans = 0;
	for (int i = 2; i <= n; i++) {
		if (!p[i]) {
			p[i] = i;
			phi[i] = i-1;
			prm[prn++] = i;
		}
		int k = min(n / i, p[i]);
		for (int j = 0; j < prn && prm[j] <= k; j++) {
			p[prm[j] * i] = p[i];
			phi[prm[j] * i] = phi[i] * (prm[j] - (prm[j] < p[i]));
		}
		ans -= 2 * (i - 1 - phi[i]);
	}
	for (int i = 2; i <= n; i++) cnt[p[i]]++;
	for (int i = 2; i <= n; i++) cnt[i] += cnt[i-1];
	int tot = n - 1;
	for (int i = 2; i <= n; i++) if (p[i] * 2 > n) tot--;
	for (int i = 2; i <= n; i++) {
		if (p[i] * 2 > n) continue;
		ans += 3 * (tot - 1) - (cnt[n / p[i]] - (1LL * p[i] * p[i] <= n));
	}
	cout << ans / 2 << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> a[1005];
vector<int> ans;
int n;
void rec(int idx,int prev,int counter)
{
    for(int i=0;i<a[idx].size();i++)
    {
        if(prev==3)
        {
            if(a[idx][i]!=3)
                rec(idx+1,a[idx][i],counter);
            if(a[idx][i]==3)
                rec(idx+1,a[idx][i],counter+1);
        }
        else
        {
            if(a[idx][i]!=prev && a[idx][i]!=3)
                rec(idx+1,a[idx][i],counter);
            if(a[idx][i]!=prev && a[idx][i]==3)
                rec(idx+1,a[idx][i],counter+1);
        }
    }
    if(idx==n)
        ans.push_back(counter);
}
int main()
{
    cin>>n;
    int i,t;
    for(i=0;i<n;i++)
    {
        cin>>t;
        if(t==0)
            a[i].push_back(3);
        else if(t==1)
        {
            a[i].push_back(1);
            a[i].push_back(3);
        }
        else if(t==2)
        {
            a[i].push_back(2);
            a[i].push_back(3);
        }
        else
        {
            a[i].push_back(1);
            a[i].push_back(2);
            a[i].push_back(3);
        }
    }
    for(i=0;i<a[0].size();i++)
    {
        if(a[0][i]==3)
            rec(1,a[0][i],1);
        else
            rec(1,a[0][i],0);
    }
    sort(ans.begin(),ans.end());
    cout<<ans[0];
    return 0;
}


#include<iostream>
using namespace std;
int n,d,k,t,v1,v2;
int main()
{
    cin>>n>>t>>k>>d;
    for(int i=1;;i++)
    {
          if(i%t==0)
          v1+=k,v2+=k;

          if(i>d && (i-d)%t==0)
          v2+=k;

          if(v1>=n && v2<=n)
          {cout<<"NO"<<endl;return 0;}

          if(v1<n && v2>=n)
          {cout<<"YES"<<endl;return 0;}

    }

}


#include<bits/stdc++.h>
using namespace std;
int w,x,y,z,num;
char c;
int main()
{
    while(scanf("%c",&c))
    {
        num++;
        if(num>=5)
            w=1;
        if(isdigit(c))
            x=1;
        if(c>='A'&&c<='Z')
            y=1;
        if(c>='a'&&c<='z')
            z=1;
        if(w*x*y*z)
			return printf("Correct"),0;
    }
    return printf("Too weak"),0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>v;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            v.push_back(j);
        }
        if(v.size()>n)
            break;
    }
    cout<<v[n-1];
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pii pair<int, int>

bool visited[401][401][9][6];
bool used[401][401];
int t[500];

int X[10], Y[10];
int n;

void init(){
	X[1] = 0;
	Y[1] = 1;
	X[2] = 1;
	Y[2] = 1;
	X[3] = 1;
	Y[3] = 0;
	X[4] = 1;
	Y[4] = -1;
	X[5] = 0;
	Y[5] = -1;
	X[6] = -1;
	Y[6] = -1;
	X[7] = -1;
	Y[7] = 0;
	X[8] = -1;
	Y[8] = 1;
}

int cnt = 0;
void bfs(){
	pair<pii, pii> init(mp(mp(400, 400), mp(1, t[0])));
	queue<pair<pii, pii> > mq[50];
	mq[0].push(init);
	visited[init.st.st][init.st.nd][init.nd.st][init.nd.nd] = true;
	for(int i = 0; i < n; i++){
		while(!mq[i].empty()){
			pair<pii, pii> u = mq[i].front();
			mq[i].pop();
			if(!used[u.st.st][u.st.nd]){
				used[u.st.st][u.st.nd] = true;
				cnt++;
			}
			if(u.nd.nd == 1 && i != n - 1){
				int dir1 = (u.nd.st - 1 - 1 + 8)%8 + 1, dir2 = (u.nd.st - 1 + 1 + 8)%8 + 1;
				if(!visited[u.st.st + X[dir1]][u.st.nd + Y[dir1]][dir1][t[i + 1]])
					mq[i + 1].push(mp(mp(u.st.st + X[dir1], u.st.nd + Y[dir1]), mp(dir1, t[i + 1])));
				if(!visited[u.st.st + X[dir2]][u.st.nd + Y[dir2]][dir2][t[i + 1]])
					mq[i + 1].push(mp(mp(u.st.st + X[dir2], u.st.nd + Y[dir2]), mp(dir2, t[i + 1])));
			}
			else if(u.nd.nd != 1){
				if(!visited[u.st.st + X[u.nd.st]][u.st.nd + Y[u.nd.st]][u.nd.st][u.nd.nd - 1])
					mq[i].push(mp(mp(u.st.st + X[u.nd.st], u.st.nd + Y[u.nd.st]), mp(u.nd.st, u.nd.nd - 1)));
			}
		}
	}
}

int main(){
	init();
	scanf("%d", &n);
	REP(i, n) scanf("%d", &t[i]);
	bfs();
	printf("%d\n", cnt);
}


/*
 ID: ahaigh11
 PROG: codeforces #109, D
 URL: http://www.codeforces.com/contest/154/problem/D
 LANG: C++

 */
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <utility>
#include <cassert>
#include <queue>
#include <ctime>
#include <map>
#include <set>
using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define CL(x) memset(x, 0, sizeof(x))

typedef long long ll;
ll x1, x2, a, b;

int brute(int x, int m) {
	//cout << x << endl;
	if (x == 0) return -1;
	if (m >= 10) return 0;

	int best = -1;
	for (int i = a; i <= b; i++) best = max(best, -brute(-(x + (x < 0 ? i : -i)), m+1));
	return best;
}

int main() {
	//while (true) {
		//x1 = rand() % 10; do { x2 = rand() % 10; } while (x1 == x2); a = rand() % 6 - 3; do { b = rand() % 6 - 3; } while (b < a);
		cin >> x1 >> x2 >> a >> b;
		ll d = x2 - x1;

		if (d < 0) {
			//x1 = -x1; x2 = -x2;

			swap(a, b);
			b = -b; a = -a;
			d = -d;
		}

		int z;

		if (a <= d && d <= b) {
			//can win on first turn :)
			cout << "FIRST" << endl << x2 << endl;
			z = 1;
		} else if (a < 0 && abs(a) >= abs(b)) {
			//one player can run away indefinitely
			cout << "DRAW" << endl;
			z = 0;
		} else if (a <= 0 && 0 <= b) {
			//no-one will edge closer because they will lose
			cout << "DRAW" << endl;
			z = 0;
		} else {
			a = max(1ll, a); //0 move is pointless
			ll v = d % (a + b);
			//cout << v << " " << (x2-x1) << endl;
			if (v == 0) {
				//first player loses
				cout << "SECOND" << endl;
				z = -1;
			} else if (v >= a && v <= b) {
				//first player wins, by moving v
				cout << "FIRST" << endl << x1+(( (x2-x1)<0) ? -v : v) << endl;
				z = 1;
			} else {
				//can force draw
				cout << "DRAW" << endl;
				z = 0;
			}
		}

		int zz = brute(x2 - x1, 0);
		if (z != zz) {
			cout << z << " " << zz << endl;
			cout << x1 << " " << x2 << " " << a << " " << b << endl;
			return 0;
		}
	//}
}


/*

4
2 5 3 1

*/

#include <stdio.h>
#include <algorithm>
#include <stack>
#include <cstring>
#include <math.h>
#include <vector>
#include <set>
using namespace std;

set<int>s;

int main()
{

	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		s.insert(x);
	}

	for(int i=1;i<=n+1;i++){
		if(!s.count(i)){
			printf("%d\n",i);
			return 0;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,v;
    cin>>n>>v;
    long long  res = 0;
    if(v >= n-1) return n-1;
    res = (n-v)*(n-v+1)/2+v-1;
    return res;
}


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

int main(){
	ll w,m,k;
	cin>>w>>m>>k;
	ll cost = 0;
	ll len = 0;
	ll sn=1;
	int pow=10;
	while(pow < m){
		pow = pow*10;
		sn++;
	}
//	cout<<pow<<endl;
	w = w/k;
	while(true){
		ll temp = (pow-m)*sn;

		if(cost+temp <= w){
			cost = cost + temp;
			len += (pow-m);
			m = pow;
			pow = pow*10;
			sn++;

		}
		else{
			ll x = (w-cost);
			x = x/sn;
			//cout<<x<<endl;
			len = len+x;
			break;
		}
	}
	cout<<len;

}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 0x7fffffff
#define fri(x) freopen(x,"r",stdin)
#define fro(x) freopen(x,"w",stdout)

using namespace std;

int sayi[2][7];
int sayilar[6];

int main(){
    int n;
    int dizi[6];
    int arr[6];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&dizi[i]);
        sayi[0][dizi[i]]++;
        sayilar[dizi[i]]++;
    }
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        sayi[1][arr[i]]++;
        sayilar[arr[i]]++;
    }
    bool flag=true;
    for(int i=1;i<=5;i++){
        if(sayilar[i]%2==1){
            flag=false;
            break;
        }
    }
    int sonuc=0;
    if(!flag)
        printf("-1");
    else{
        for(int i=1;i<=5;i++){
            sonuc+=( abs(sayi[0][i]-sayi[1][i])/2 );
        }
        printf("%d",sonuc/2);
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//
//using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

/*** Typedef ***/
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
typedef    long double   ld;

//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;

/*** Loops ***/
#define ffit(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
#define yo(a,b) for(int i = a; i < b; i++)
#define ff1(i,a,b) for(ll i = a; i < b; i++)
#define ff2(i,a,b) for(ll i = b-1; i >= a; i--)
#define ff3(i,a,b,m) for(ll i = a; i <b; i+=m)
#define ipar(ar,n) ll ar[n]; ff1(i,0,n) cin>>ar[i];
#define opar(ar,n) ff1(i,0,n) cout<<ar[i]<<" ";
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) sc1(arr[i]);
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) sc1(arr[i]);
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/

#define PI acos(-1.0)
#define eps 1e-7
#define size1 15
const ll mdd = (ll)1e6 + 3;
/*** STLs ***/
#define sf(a)            scanf("%lld",&a)
#define sff(a,b)         scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define cu continue
#define br break
#define rsz resize
#define ins insert
#define ft front
#define bk back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define rr return
#define nxt   next_permutation
#define mem(name, value) memset(name, value, sizeof(name))
#define MN3(n1,n2,n3) min(n1,min(n2,n3))
#define MN4(n1,n2,n3,n4) min(n1,min(n2,min(n3,n4)))
#define MX3(n1,n2,n3) max(n1,max(n2,n3))
#define MX4(n1,n2,n3,n4) max(n1,max(n2,max(n3,n4)))
#define mxar(a,n) *max_element(a,a+n)
#define mnar(a,n) *min_element(a,a+n)
#define arr_sm(a,n) accumulate(a,a+n,0)
#define vc_sm(ve) accumulate(ve.begin(),ve.end(),0)
#define mx_vc(ve) *max_element(ve.begin(),ve.end())
#define mn_vc(ve) *min_element(ve.begin(),ve.end())
//#define endl " \n"

/*** STLs ***/
typedef vector <ll> vll;
#define vvll vector<vll>
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef multimap <ll,ll> mpll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll, ll> > vpll;
typedef priority_queue <pair <ll, ll> > pqpll;
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ml unordered_map<ll,ll>
///typedef    unordered_multiset<int>   umsi;
typedef    unordered_set<ll>   us;

///vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of 10 rows and 20 columns, with value 500.

/*** Sorts ***/
#define czero(n)                    __builtin_popcountll(n) // count the number of 1's in the bit representation of a number
#define cenzero(n)                  __builtin_ctzll(n) // count the number of zereos from the end of the bit representation of a number until a 1
#define countbegzero(n)             __builtin_clzxll(n)
#define checkparity(n)              __builtin_parityll(n)// checks whether the number of bits are even or odd
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtgrt(v) sort(all(v), greater<ll>())
#define prsrt greater<pair<int,int>>()
/*** Some Prints ***/
#define ip(n) ll n; cin>>n;
#define is(s) string s; cin>>s;
#define ipp(n,k) ll n; cin>>n; ll k; cin>>k;
#define ip3(n,m,k) ll n; cin>>n;ll m;cin>>m; ll k; cin>>k;
#define kl    '\n'
#define case cout << "Case " << t++ << ": ";
#define ps(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define w(x)             ll x; cin>>x; while(x--)
#define go(i, a) for (auto &i : a)
#define go1(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)
//#define mk(arr,n,type) type *arr=new type[n];
#define sz(obj) (int(obj.size()))
#define ipve(vc,n) vll vc(n); ff1(i,0,n){cin>>vc[i];}
#define ipvc(vc,n) vll vc; ff1(i,0,n){ip(x);vc.pb(x);}
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define depressed()                    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//bool ans = all_of(arr, arr + 6, [](int x) {return x & 1; } );
const double pi = 3.141592653589793238460;
#define TRC
#ifdef TRC
#define trc(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trc(...)
#endif
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
ll dx[8]={+1, +1, +1, 0, 0, -1, -1, -1};
ll dy[8] = {-1, 0, +1, -1, +1, -1, 0, +1};
void fun()
{
 mll m;
 is(s);
 ff1(i,0,sz(s))
 {
  m[s[i]-'0']++;
 }
 ll ct = 0;
 string ms1,ms2;
 ff1(i,1,10)
 {
  mll f = m, ff = m;
  string s1,s2;
  ll cnt = 0;
  if(f[i]>0 && ff[10-i]>0)
  {
    s1+='0'+i;
    s2+='0'+10-i;
    f[i]--;
    ff[10-i]--;
    cnt++;
    ff1(i,0,10)
    {
      if(f[i]>0 && ff[9-i]>0)
      {
        ll mn  = min(f[i],f[9-i]);
        s1 = string(mn,'0'+i) + s1;
        s2 = string(mn,'0'+9-i) + s2;
        f[i]-=mn;
        ff[i]-=mn;
        cnt+=mn;
      }
    }
    ll z = min(f[0],ff[0]);
    if(z>0)
    {
      f[0]-=z;
      ff[0]-=z;
      s1+=string(z,'0');
      s2+=string(z,'0');
      cnt+=z;
    }
    if(cnt>ct)
    {
      ct  = cnt;
      ff1(i,0,10)
      {
        s1 = string(f[i],'0'+i) + s1;
        s2 = string(ff[i],'0'+i)+s2;
      }
      ms1 = s1;
      ms2 = s2;
    }
  }
 }
 cout<<ms1<<kl<<ms2;
}

int main()
{
// tasklist
// taskkill /f /im mo.exe

    depressed();
  ll tc = 1;
//cin>>tc;
  while(tc--)
  {
     fun();
  }
  //cer;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin>>t;
	vector<int> arr(t);
	for(int a=0;a<t;a++)
		cin>>arr[a];
	int dif=arr[0]-arr[1],done=0;
	for(int a=0;a<t-1;a++){
		if(arr[a]-arr[a+1] != dif){
			a=t;
			done=1;
		}
	}
	if(arr[a]-arr[a+1] != dif){
			a=t;
			done=1;
		}
	if(done)
		cout<<arr[t-1];
	else
		cout<<arr[t-1]-dif;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int a,b,c,d;
int main()
{
	cin>>b>>a;
	while((d=__gcd(a,b))>1) a/=d,c++;
	if(a==1) cout<<"2-type\n"<<c;
	else if(!c&&(b-1)%a==0) cout<<"3-type";
	else if(!c&&(b+1)%a==0) cout<<"11-type";
	else cout<<"6-type";
	else cout<<"7-type";
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const LL mo=1e9+7;
const int N=2e6;
LL n,mo,inv2,inv6,nx;
LL f[N+10],g[N+10],h[N+10],sum1[N+10],sum2[N+10],sum3[N+10];
LL mul(LL x,LL y) {
    x%=mo;
    LL z=1;
    while (y) {
        if (y&1) z=z*x%mo;
        y>>=1;
        x=x*x%mo;
    }
    return z;
}
LL Calc2(LL l,LL r) {
    l%=mo;
    r%=mo;
    return (l+r)*(r-l+1)%mo*inv2%mo;
}
LL getsum(LL x) {
    x%=mo;
    return x*(x+1)%mo*(x*2+1)%mo*inv6%mo;
}
LL Calc3(LL l,LL r) {
    return (getsum(r)-getsum(l-1))%mo;
}
LL SQRT(LL x) {
    LL l=0,r=N;
    while (l<r) {
        LL mid=(l+r+1)/2;
        if (mid*mid>x) r=mid-1;
        else l=mid;
    }
    return l;
}
LL getf(LL x) {
    LL l=SQRT(x);
    return (sum1[l]+l*((x-l*l+1)%mo))%mo;
}
LL getg(LL x) {
    LL l=SQRT(x);
    return (sum2[l]+l*Calc2(l*l,x))%mo;
}
LL geth(LL x) {
    LL l=SQRT(x);
    return (sum3[l]+l*Calc3(l*l,x))%mo;
}
void prework() {
    nx=n%mo;
    inv2=mul(2,mo-2);
    inv6=mul(6,mo-2);
    for (LL i=1;i*i<=n;i++) {
        LL l=(i-1)*(i-1),r=i*i-1;
        sum1[i]=(sum1[i-1]+(r-l+1)%mo*(i-1))%mo;
        sum2[i]=(sum2[i-1]+Calc2(l,r)*(i-1))%mo;
        sum3[i]=(sum3[i-1]+Calc3(l,r)*(i-1))%mo;
    }
    for (LL i=0;i*i<=n;i++) {
        f[i]=getf(n-i*i);
        g[i]=getg(n-i*i);
        h[i]=geth(n-i*i);
    }
}
void work() {
    LL ans1=0;
    for (LL i=0;i*i<=n;i++) {
        LL nowx=i*i%mo*f[i]+g[i];
        nowx%=mo;
        ans1=(ans1+nowx)%mo;
    }
    ans1=ans1*4%mo;
    LL nowx=(nx+1)*nx%mo*inv2%mo;
    ans1=(ans1+nowx)%mo;
    ans1=ans1*(nx+1)%mo;
    LL ans2=0;
    for (LL i=0;i*i<=n;i++) {
        LL nowp=i*i%mo;
        LL nowx=nowp*nowp%mo*f[i]+nowp*2*g[i]+h[i];
        nowx%=mo;
        ans2=(ans2+nowx)%mo;
    }
    ans2=ans2*4%mo;
    nowx=getsum(nx);
    ans2=(ans2+nowx)%mo;
    ans1=((ans1-ans2)%mo+mo)%mo;
    printf("%lld\n",ans1);
}
int main() {
    scanf("%lld",&n);
    prework();
    work();
    return 0;
}


#define TASK "palsquare"

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#define sz(s) int((s).size())
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;
const double PI = 3.1415926535897932384626433832795028841971;

//ifstream cin("input.txt");
//ofstream cout ("output.txt");
int main(){
long long int a,b,c;
cin>>a>>b>>c;
if(a%c==0 && c!=1 )cout<<a-b-1;
else cout<<a-b;

return 0;
}


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

using namespace std;

int main()
{
    string s ;
    getline(cin , s ) ;
    bool chk = 0 ;
    int sum =  0  ;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='w') chk = 1 ;
    }
    if(!chk)
    {
        int i = 0 ;
        while(true)
        {
            if(s[i] == ' ') break ;
            sum*=10;
            sum+=  (s[i] - '0') ;
            i++;
        }
        if(sum == 31 ) { cout<<7; return 0;     }
        else
        if(sum>28 ) { cout<<11; return 0;     }
        else
            { cout<<12; return 0;     }
    }
    else
    {
         while(true)
        {
            int i = 0 ;
            if(s[i] == ' ') break ;
            sum*=10;
            sum+=  (s[i] - '0') ;
            i++;
        }
        if(sum == 6)   { cout<<53; return 0;     }
        else { cout<<52; return 0;     }

    }
    return 0;
}


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

int main()
{
    int a1 , a2 , a3 , b1 , b2 , b3 , n;
    cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n;
    int sumc = a1+a2+a3 , summ = b1+b2+b3;

    if(sumc>=5)
    while(sumc>=5)
    {
        n--;
        sumc-=5;
    }
    if(sumc !=0)
    n--;
    else if(summ>=10)
    while(summ>=10)
    {
        n--;
        summ-=10;
    }
    if(summ !=0)
    n--;

    if(n<0)
    cout << "NO";
    else
    cout << "YES";

    return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define vll vector< ll >
#define vull vector< ull >
#define vvi vector< vi >
#define vvll vector < vll >
#define vvull vector < vull >
#define mii map<int,int>
#define pii pair< int , int >
#define repeat(n) for(int ajsS32D_v = 0 ; ajsS32D_v < n ; ajsS32D_v++)
#define forn(i,n) for(int i = 0 ; i < n ; i++)
#define rep(i,a,b) for(int i = a ; i <= b ; i++)
#define rrep(i,a,b) for(int i = a ; i>= b ; i--)
#define debug(x) cerr <<"\n--------------"<< #x << " is " << x << "--------------\n"
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mod (ll)1000000007
#define INF (ll)1
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INT_MAX (int)2147483647
#define LL_MAX (ll)9223372036854775807
#define ld long double
#define PI (ld)3.1415926535897932384626433832795028

using namespace std ;
void solve(){
	ll a ;
	cin >> a ;
	ll mul = 1;
	ll cache = a;
	vi answer;
	while(a > 0){
		if(a%10 < 8){
			answer.pb(8);
			while(a >0){
				answer.pb(a%10);
				a /= 10;
			}
			break;
		}else{
			answer.pb(0);
		}
	}
	for(int i = 0 ; i < answer.size() ; i++){
		cout << answer[answer.size() - 1 - i ];
	}
	cout << endl;
}
int main(){
	FASTIO ;
	bool multi_run = 0;
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	if(multi_run){
		int t ;
		cin >> t;
		while(t--)solve();
	}else{
		solve();
	}

}


#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for (int i=(a); i>=(b); --i)
#define REP(i,b) for (int i=0; i<(b); ++i)
#define input stdin
#define output stdout
#define assign freopen
#define endl '\n'
#define sz(x) (int) x.size()
#define div /
#define mod %
#define fillchar(x,y,z) memset(x,z,y)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define sqr(x) ((x)*(x))
typedef long long int64;
typedef unsigned long long qword;
typedef void procedure;
using namespace std;
#define f1(i,n) for (int i=1; i<=n; i++)
#define f0(i,n) for (int i=0; i<n; i++)

typedef vector<int> vi;
const int BASE=10000;

void fix(vi &a){
    a.push_back(0);
    f0(i,a.size()-1) {
        a[i+1]+=a[i]/BASE; a[i]%=BASE;
        if (a[i]<0) { a[i]+=BASE; a[i+1]--; }
    }
    while (a.size()>=2 && a.back()==0) a.pop_back();
}

void operator += (vi &a, const vi &b) {
    a.resize(max(a.size(), b.size()));
    f0(i,b.size()) a[i]+=b[i];
    fix(a);
}

vi to_vi(int x) // x<BASE
    { return vi(1,x); }

vi operator + (vi a, const vi &b)
    { a+=b; return a; }
bool operator < (const vi &a, const vi &b){
    if (a.size() != b.size()) return a.size()<b.size();
    for (int i=a.size()-1; i>=0; i--)
    if (a[i]!=b[i]) return a[i]<b[i];
    return false;
}
int n;
int a[105];
vi f[105][10005];
int mark[105];
vi c[105][105];
procedure Input()
{
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i];
        ++mark[a[i]];
    }
}
procedure Solve()
{
    FOR(i,0,n) c[i][0]=to_vi(1);
    FOR(i,1,n)
        FOR(j,1,i) c[i][j]=c[i-1][j-1]+c[i-1][j];
    int sum=0;
    f[0][0]=to_vi(1);
    FOR(i,1,n) {
        FORR(j,i,1)
            FORR(k,sum,0)
                f[j][k+a[i]]+=f[j-1][k];
        sum+=a[i];
    }
    int res=0;
    vi zr=to_vi(0);
    FOR(i,1,n)
        FOR(k,1,sum)
            if (zr<f[i][k]&&k mod i==0&&c[mark[k div i]][i]==f[i][k])
                res=max(res,i);
    cout << res;
}
int main()
{
    #ifdef meomeomeooooo
        assign("input.txt","r",input);
        //assign("output.txt","w",output);
    #endif // meomeomeooooo
    iostream::sync_with_stdio(false);
    cin.tie(0);
    Input();
    Solve();
    return 0;
}


#pragma region Macros
#pragma GCC optimize("O3")
#pragma GCC target("avx2,avx")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)                                                                                \
    vector<type> name(size);                                                                                \
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)                                                                                \
    vector<vector<type>> name(h, vector<type>(w));                                                                                \
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)                                                                                \
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void yes(bool t = 1) { cout << yesno[t] << endl; }
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)                                                                                \
    int __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
#define LL(...)                                                                                \
    ll __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
#define STR(...)                                                                                \
    string __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
#define CHR(...)                                                                                \
    char __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
#define DBL(...)                                                                                \
    double __VA_ARGS__;                                                                                \
    IN(__VA_ARGS__)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) {
    scan(head);
    IN(tail...);
}
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
template <typename T> vi iota(vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(all(res), 0);
    sort(all(res), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    sort(all(y));
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
int popcount(ll x) { return __builtin_popcountll(x); }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}

template <typename T> struct edge {
    int from, to;
    T cost;
    int id;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {}
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;

using Tree = vector<vector<int>>;
using Graph = vector<vector<int>>;
template <class T> using Wgraph = vector<vector<edge<T>>>;
Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {
    Tree res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        cin >> a >> b;
        a -= margin, b -= margin;
        res[a].emplace_back(b);
        if(!directed) res[b].emplace_back(a);
    }
    return move(res);
}
template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {
    Wgraph<T> res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        T c;
        cin >> a >> b >> c;
        a -= margin, b -= margin;
        res[a].emplace_back(b, c);
        if(!directed) res[b].emplace_back(a, c);
    }
    return move(res);
}

#define i128 __int128_t
#define ull unsigned long long int
#define TEST                                                                                \
    INT(testcases);                                                                                \
    while(testcases--)
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    for(auto &e : v) cout << e << " ";
    cout << endl;
    return os;
}
template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) {
    cout << "(" << p.fi << ", " << p.se << ")";
    return os;
}
template <class S, class T> string to_string(pair<S, T> p) { return "(" + to_string(p.first) + "," + to_string(p.second) + ")"; }
template <class A> string to_string(A v) {
    if(v.empty()) return "{}";
    string ret = "{";
    for(auto &x : v) ret += to_string(x) + ",";
    ret.back() = '}';
    return ret;
}

void dump() { cerr << endl; }
template <class Head, class... Tail> void dump(Head head, Tail... tail) {
    cerr << to_string(head) << " ";
    dump(tail...);
}
#define endl '\n'
#ifdef _LOCAL
#undef endl
#define debug(x)                                                                                \
    cout << #x << ": ";                                                                                \
    dump(x)
#else
#define debug(x)
#endif
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// int rnd(int n) { return uniform_int_distribution<int>(0, n - 1)(rng); }
// ll rndll(ll n) { return uniform_int_distribution<ll>(0, n - 1)(rng); }

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
#define drop(s) cout << #s << endl, exit(0)
#pragma endregion

template <class T> struct Matrix {
    vector<vector<T>> A;

    Matrix() {}

    Matrix(size_t n, size_t m) : A(n, vector<T>(m, 0)) {}

    Matrix(size_t n) : A(n, vector<T>(n, 0)){};

    size_t height() const { return (A.size()); }

    size_t width() const { return (A[0].size()); }

    inline const vector<T> &operator[](int k) const { return (A.at(k)); }

    inline vector<T> &operator[](int k) { return (A.at(k)); }

    static Matrix I(size_t n) {
        Matrix mat(n);
        for(int i = 0; i < n; i++) mat[i][i] = 1;
        return (mat);
    }

    Matrix &operator+=(const Matrix &B) {
        size_t n = height(), m = width();
        assert(n == B.height() && m == B.width());
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++) (*this)[i][j] += B[i][j];
        return (*this);
    }

    Matrix &operator-=(const Matrix &B) {
        size_t n = height(), m = width();
        assert(n == B.height() && m == B.width());
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++) (*this)[i][j] -= B[i][j];
        return (*this);
    }

    Matrix &operator*=(const Matrix &B) {
        size_t n = height(), m = B.width(), p = width();
        assert(p == B.height());
        vector<vector<T>> C(n, vector<T>(m, 0));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                for(int k = 0; k < p; k++) C[i][j] = (C[i][j] + (*this)[i][k] * B[k][j]);
        A.swap(C);
        return (*this);
    }

    Matrix &operator^=(long long k) {
        Matrix B = Matrix::I(height());
        while(k > 0) {
            if(k & 1) B *= *this;
            *this *= *this;
            k >>= 1LL;
        }
        A.swap(B.A);
        return (*this);
    }

    Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }

    Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }

    Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }

    Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); }

    friend ostream &operator<<(ostream &os, const Matrix &p) {
        size_t n = p.height(), m = p.width();
        for(int i = 0; i < n; i++) {
            os << "[";
            for(int j = 0; j < m; j++) { os << p[i][j] << (j + 1 == m ? "]\n" : ","); }
        }
        return (os);
    }

    T determinant() {
        Matrix B(*this);
        assert(width() == height());
        T ret = 1;
        for(int i = 0; i < width(); i++) {
            int idx = -1;
            for(int j = i; j < width(); j++) {
                if(B[j][i] != 0) idx = j;
            }
            if(idx == -1) return (0);
            if(i != idx) {
                ret *= -1;
                swap(B[i], B[idx]);
            }
            ret *= B[i][i];
            T vv = B[i][i];
            for(int j = 0; j < width(); j++) { B[i][j] /= vv; }
            for(int j = i + 1; j < width(); j++) {
                T a = B[j][i];
                for(int k = 0; k < width(); k++) { B[j][k] -= B[i][k] * a; }
            }
        }
        return (ret);
    }
};
namespace modular {
constexpr ll MOD = 1000000007;
const int MAXN = 1100000;
template <ll Modulus> class modint;
#define mint modint<MOD>
#define vmint vector<mint>
vector<mint> Inv;
mint inv(int x);
template <ll Modulus> class modint {

  public:
    static constexpr int mod() { return Modulus; }
    ll a;

    constexpr modint(const ll x = 0) noexcept : a(((x % Modulus) + Modulus) % Modulus) {}
    constexpr ll &value() noexcept { return a; }
    constexpr const ll &value() const noexcept { return a; }
    constexpr modint operator-() const noexcept { return modint() - *this; }
    constexpr modint operator+() const noexcept { return *this; }
    constexpr modint &operator++() noexcept {
        if(++a == MOD) a = 0;
        return *this;
    }
    constexpr modint &operator--() noexcept {
        if(!a) a = MOD;
        a--;
        return *this;
    }
    constexpr modint operator++(int) {
        modint res = *this;
        ++*this;
        return res;
    }
    constexpr modint operator--(int) {
        mint res = *this;
        --*this;
        return res;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if(a >= Modulus) { a -= Modulus; }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if(a < rhs.a) { a += Modulus; }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(const modint rhs) noexcept {
        a = a * (modular::inv(rhs.a)).a % Modulus;
        return *this;
    }
    constexpr modint pow(long long n) const noexcept {
        modint x = *this, r = 1;
        while(n) {
            if(n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    constexpr modint inv() const noexcept { return pow(Modulus - 2); }
    constexpr friend modint operator+(const modint &lhs, const modint &rhs) { return modint(lhs) += modint(rhs); }
    constexpr friend modint operator-(const modint &lhs, const modint &rhs) { return modint(lhs) -= modint(rhs); }
    constexpr friend modint operator*(const modint &lhs, const modint &rhs) { return modint(lhs) *= modint(rhs); }
    constexpr friend modint operator/(const modint &lhs, const modint &rhs) { return modint(lhs) /= modint(rhs); }
    constexpr friend modint operator==(const modint &lhs, const modint &rhs) { return lhs.a == rhs.a; }
    constexpr friend modint operator!=(const modint &lhs, const modint &rhs) { return lhs.a != rhs.a; }
    // constexpr friend modint operator^=(const modint &lhs, const modint &rhs) { return modint(lhs) ^= modint(rhs); }
};
vmint Fact{1, 1}, Ifact{1, 1};
mint inv(int n) {
    if(Inv.empty()) Inv.emplace_back(0), Inv.emplace_back(1);
    if(Inv.size() > n)
        return Inv[n];
    else {
        for(int i = Inv.size(); i <= n; ++i) Inv.emplace_back(Inv[MOD % i] * (-MOD / i));
        return Inv[n];
    }
}
mint fact(int n) {
    if(Fact.size() > n)
        return Fact[n];
    else
        for(int i = Fact.size(); i <= n; ++i) Fact.emplace_back(Fact[i - 1] * i);
    return Fact[n];
}
mint ifact(int n) {
    if(Ifact.size() > n)
        return Ifact[n];
    else
        for(int i = Ifact.size(); i <= n; ++i) Ifact.emplace_back(Ifact[i - 1] * inv(i));
    return Ifact[n];
}
mint modpow(ll a, ll n) { return mint(a).pow(n); }
mint inv(mint a) { return inv(a.a); }
mint ifact(mint a) { return ifact(a.a); }
mint fact(mint a) { return fact(a.a); }
mint modpow(mint a, ll n) { return modpow(a.a, n); }
mint C(int a, int b) {
    if(a < 0 || b < 0) return 0;
    if(a < b) return 0;
    return fact(a) * ifact(b) * ifact(a - b);
}
mint P(int a, int b) {
    if(a < 0 || b < 0) return 0;
    if(a < b) return 0;
    return fact(a) * ifact(a - b);
}
ostream &operator<<(ostream &os, mint a) {
    os << a.a;
    return os;
}
istream &operator>>(istream &is, mint &a) {
    ll x;
    is >> x;
    a = x;
    return is;
}
struct modinfo {
    int mod, root;
};
constexpr modinfo base0{1045430273, 3};
constexpr modinfo base1{1051721729, 6};
constexpr modinfo base2{1053818881, 7};
using mint0 = modint<base0.mod>;
using mint1 = modint<base1.mod>;
using mint2 = modint<base2.mod>;
using Poly = vmint;
template <int mod> void FMT(vector<modint<mod>> &f, bool inv = false) {
    using V = vector<modint<mod>>;
    static V g(30), ig(30);
    if(g.front().a == 0) {
        modint<mod> root = 2;
        while((root.pow((mod - 1) / 2)).a == 1) root += 1;
        rep(i, 30) g[i] = -(root.pow((mod - 1) >> (i + 2))), ig[i] = g[i].inv();
    }
    int n = size(f);
    if(!inv) {
        for(int m = n; m >>= 1;) {
            modint<mod> w = 1;
            for(int s = 0, k = 0; s < n; s += 2 * m) {
                for(int i = s, j = s + m; i < s + m; ++i, ++j) {
                    auto x = f[i], y = f[j] * w;
                    if(x.a >= mod) x.a -= mod;
                    f[i].a = x.a + y.a, f[j].a = x.a + (mod - y.a);
                }
                w *= g[__builtin_ctz(++k)];
            }
        }
    } else {
        for(int m = 1; m < n; m *= 2) {
            modint<mod> w = 1;
            for(int s = 0, k = 0; s < n; s += 2 * m) {
                for(int i = s, j = s + m; i < s + m; ++i, ++j) {
                    auto x = f[i], y = f[j];
                    f[i] = x + y, f[j].a = x.a + (mod - y.a), f[j] *= w;
                }
                w *= ig[__builtin_ctz(++k)];
            }
        }
    }
    modint<mod> c;
    if(inv)
        c = modint<mod>(n).inv();
    else
        c = 1;
    for(auto &&e : f) e *= c;
}
Poly operator-(Poly f) {
    for(auto &&e : f) e = -e;
    return f;
}
Poly &operator+=(Poly &l, const Poly &r) {
    l.resize(max(l.size(), r.size()));
    rep(i, r.size()) l[i] += r[i];
    return l;
}
Poly operator+(Poly l, const Poly &r) { return l += r; }
Poly &operator-=(Poly &l, const Poly &r) {
    l.resize(max(l.size(), r.size()));
    rep(i, r.size()) l[i] -= r[i];
    return l;
}
Poly operator-(Poly l, const Poly &r) { return l -= r; }
Poly &operator<<=(Poly &f, size_t n) { return f.insert(f.begin(), n, 0), f; }
Poly operator<<(Poly f, size_t n) { return f <<= n; }
Poly &operator>>=(Poly &f, size_t n) { return f.erase(f.begin(), f.begin() + min(f.size(), n)), f; }
Poly operator>>(Poly f, size_t n) { return f >>= n; }

constexpr int mod0 = 998244353, mod1 = 1300234241, mod2 = 1484783617;
using M0 = modint<mod0>;
using M1 = modint<mod1>;
using M2 = modint<mod2>;

template <int mod> void mul(vector<modint<mod>> &l, vector<modint<mod>> &r) {
    int n = size(l), m = size(r), sz = 1 << __lg(2 * (n + m - 1) - 1);
    l.resize(sz), FMT<mod>(l);
    r.resize(sz), FMT<mod>(r);
    rep(i, sz) l[i] *= r[i];
    FMT<mod>(l, true);
    l.resize(n + m - 1);
}
Poly operator*(const Poly &l, const Poly &r) {
    if(l.empty() or r.empty()) return Poly();
    int n = size(l), m = size(r), sz = 1 << __lg(2 * (n + m - 1) - 1);
    vector<M0> l0(n), r0(m);
    vector<M1> l1(n), r1(m);
    vector<M2> l2(n), r2(m);
    rep(i, n) l0[i] = l[i].a, l1[i] = l[i].a, l2[i] = l[i].a;
    rep(i, m) r0[i] = r[i].a, r1[i] = r[i].a, r2[i] = r[i].a;
    mul<mod0>(l0, r0), mul<mod1>(l1, r1), mul<mod2>(l2, r2);
    Poly res(n + m - 1);
    // garner
    static constexpr M1 inv0 = 613999507;
    static constexpr M2 inv1 = 1147332803, inv0m1 = 45381342;
    static constexpr mint m0 = mod0, m0m1 = m0 * mod1;
    rep(i, n + m - 1) {
        int y0 = l0[i].a;
        int y1 = (inv0 * (l1[i] - y0)).a;
        int y2 = (inv0m1 * (l2[i] - y0) - inv1 * y1).a;
        res[i] = m0 * y1 + m0m1 * y2 + y0;
    }
    return res;
}
Poly &operator*=(Poly &l, const Poly &r) { return l = l * r; }
Poly integ(const Poly &f) {
    Poly res(f.size() + 1);
    for(int i = 1; i < (int)res.size(); ++i) res[i] = f[i - 1] / i;
    return res;
}
struct Prd {
    deque<Poly> deq;
    Prd() = default;
    void emplace(const Poly &f) { deq.emplace_back(f); }
    Poly calc() {
        if(deq.empty()) return {1};
        sort(all(deq), [&](const Poly &f, const Poly &g) { return si(f) < si(g); });
        while(deq.size() > 1) {
            deq.emplace_back(deq[0] * deq[1]);
            for(int i = 0; i < 2; ++i) deq.pop_front();
        }
        return deq.front();
    }
};
Poly prd(vector<Poly> &v) {
    Prd p;
    for(auto &e : v) p.emplace(e);
    return p.calc();
}
// Poly deriv(const Poly &f) {
//     if(f.size() == 0) return Poly();
//     Poly res(f.size() - 1);
//     rep(i, res.size()) res[i] = f[i + 1] * (i + 1);
//     return res;
// }
ostream &operator<<(ostream &os, const Poly &a) {
    for(auto e : a) cout << e.a << " ";
    return os;
}
} // namespace modular
using namespace modular;

int main() {
    using M = Matrix<mint>;
    LL(n, k);
    vi v;
    ll N = n;
    while(n) { v.eb(n % k), n /= k; }
    reverse(all(v));
    auto f = [&](int num, int lastdigit) {
        vi used(k);
        int now = 0;
        M mat(k * 2 + 1);
        rep2(i, 1, k * 2 - 1) mat[i][i - 1] = 1;
        mat[k * 2][k * 2] = 1;
        rep(i, k * 2) {
            now--;
            lastdigit--;
            if(lastdigit == -1) now -= num;
            now = (now % k + k) % k;
            mat[0][i] = mat[k * 2][i] = 1;
            if(!now) break;
            used[now] = 1;
        }
        return mat;
    };
    M x(k * 2 + 1, 1);
    x[0][0] = 1, x[k * 2][0] = 1;
    rep(i, N) {
        int cnt = 1;
        int a = i / k;
        while(a and a % k == 0) cnt++, a /= k;
        x = f(cnt, i % k) * x;
    }
    cout << x[k * 2][0] << endl;
}


/* -*- coding: utf-8; tab-width: 4 -*- */

#include <cstdio>
#include <array>
#include <iostream>

std::array<int, 50> v;
std::array<int, 50> w;

long long
search(int i,
	   int n)
{
	if (n <= i) return v != w;

	if ((v[i] + w[i-1]) % 2 == 0) {
		w[i] = (v[i] + w[i-1]) / 2;
		return search(i + 1, n);
	}
	else {
		long long r(0);
		w[i] = (v[i] + w[i-1]) / 2;
		r += search(i + 1, n);
		w[i] = (v[i] + w[i-1]) / 2 + 1;
		r += search(i + 1, n);
		return r;
	}
}

int
main()
{
	char s[51];
	int n(0);
	long long r(0);

	std::scanf("%s", s);
	for (int i(0); s[i]; ++i) v[i] = s[i] - '0', ++n;

	for (int i(0); i < 10; ++i) {
		w[0] = i;
		r += search(1, n);
	}

	std::cout << r << std::endl;

	return 0;
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define int64 long long
#define ldb long double
const ldb pi = acos(-1.0);

#define FULL 2
#define OK 1
#define EMPTY 0

int get_state(int a, int b, int c) {
	if ((a == 0) && (b == 0)) {
		if (c == 0) return FULL;
		return EMPTY;
	}
	return OK;
}

int det2(int a, int b, int c, int d) {
	return a * d - b * c;
}

int main() {
	// assert(freopen("input.txt", "r", stdin));
	// assert(freopen("output.txt", "w", stdout));
	int a1, b1, c1, a2, b2, c2;
	scanf("%d%d%d", &a1, &b1, &c1);
	scanf("%d%d%d", &a2, &b2, &c2);
	int s1 = get_state(a1, b1, c1);
	int s2 = get_state(a2, b2, c2);
	if (s1 == EMPTY || s2 == EMPTY) {
		printf("0\n");
		return 0;
	}
	if (s1 == FULL || s2 == FULL) {
		printf("-1\n");
		return 0;
	}
	int d = det2(a1, b1, a2, b2);
	if (d == 0) {
		if (det2(a1, c1, a2, c2) == 0) {
			printf("-1\n");
		} else {
			printf("0\n");
		}
	} else {
		printf("1\n");
	}
	return 0;
}


#include "bits/stdc++.h"

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define ford(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

template<typename T> inline T sqr(T x)
{
    return x*x;
}

using namespace std;

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

//const ld pi = acos((ld)-1.0);
const ld eps = 1e-6;
const int INF = (int)1E9;
const int MAXN = 21;
const int MAXMASK = 1 << MAXN;

bool eq(ld a, ld b) {
	return fabs(a - b) < eps;
}

int n, N, k, mmask;
ll cnk[MAXN][MAXN];
ld p[MAXN];
ld pSum[MAXMASK], coeff[MAXN];
int trueId[MAXN], mass[MAXN];
ld ans[MAXN];

void printAns() {
	cout.precision(20);
	forn(i, N)
		cout << ans[i] << " \n"[i == N - 1];
}

int main() {

	cin >> n >> k;
	N = n;
	forn(i, n)
		cin >> p[i];

	forn(i, n)
		if (eq(p[i], 1.0)) {
			ans[i] = 1.0;
			printAns();
			return 0;
		}

	forn(i, n)
		trueId[i] = i;

	forn(i, n) {
		if (eq(p[i], 0.0)) {
			for (int j = i; j < n - 1; j++) {
				p[j] = p[j + 1];
				trueId[j] = trueId[j + 1];
			}
			n--;
			i--;
		}
	}

   	if (n <= k) {
   		forn(i, n)
   			ans[trueId[i]] = 1.0;
   		printAns();
   		return 0;
   	}

   	cnk[0][0] = 1;
   	forab(i, 1, MAXN) {
   		cnk[i][0] = 1;
   		forab(j, 1, MAXN)
   			cnk[i][j] = cnk[i - 1][j - 1] + cnk[i - 1][j];
   	}

   	for (int j = k - 1; j >= 1; j--) {
   		coeff[j] = 0;
   		for (int i = 1; i <= k - 1 - j; i++)
   			coeff[j] -= cnk[n - j - 1][i];
   		coeff[j]++;
   	}

   	mmask = 1 << n;
   	forn(mask, mmask) {
   		pSum[mask] = 0;
   		mass[mask] = 0;
   		forn(i, n)
   			if ((mask >> i) & 1) {
   				pSum[mask] += p[i];
   				mass[mask]++;
   			}
   	}

   	int j;
   	forn(i, n) {
   		ld curAns = 0.0;

   		forn(mask, mmask) {
   			j = mass[mask];
   			if (1 <= j && j <= k - 1 && ((mask >> i) & 1) == 0) {
   				assert(!eq(pSum[mask], 1.0));
   				curAns += coeff[j] * (pSum[mask] / (1.0 - pSum[mask]));
   			}
   		}

   		curAns++;
   		curAns *= p[i];

   		ans[trueId[i]] = curAns;
   	}

   	printAns();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string st;
int ans;
int main(){
    scanf("%s",st);
    for(int j=0;j<st.size();j++)
        if (st[j]=='4'||st[j]=='7') ans++;
    if (ans==4||ans==7) puts("YES");
    else puts("NO");
    return  0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>

using namespace std;

int main()
{
    int h1,h2,a,b,day=0;
    scanf("%d %d\n%d %d",&h1,&h2,&a,&b);
    while(h1<h2)
      {
            h1+=a*4;
            if(h1>=h2) { printf("%d",day);system("pause");return 0;}
            if(a<b) {printf("-1");system("pause");return 0;}
            h1+=a*8;
            h1-=b*12;day++;
      }
}


#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>
#include <assert.h>
#include <sstream>
#include <stack>

using namespace std;

int main (){
	int n  ;
	cin >> n ;
	int  a  [100] ;
	int  x[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1} ;
	for (int i = 0 ; i < n ; i++)  cin >> a[i] ;

	if (n == 1 && (a[0]== 0)  ) {
		cout << "UP" ;
		return 0 ;
	}else if (n == 1  && (a[0] == 15)){
		cout <<  "Down"  ;
		return  0 ;
	}else if (n == 1) {
		cout << - 1;
	  return  -1 ;
	}
	int j ;

	for (int i = 0 ; i < 29 ; i++)
		if (a[0] ==  x[i] && a[1] == x[i + 1] ) j = i ;

	  if ( x[j +  n % 30 ] > x[j + (n - 1) % 30]) cout << "UP" ;
	  else   cout << "DOWN";

		return 0 ;
}