#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define yo cout<<"i got here\n";
using namespace std;///think of dp,bs
const int mod = 1e9+7,siz = 1e6+5;
int t,n,m,k,a,b,out[siz],pre[55];
bool is_ok(int mid,int d,int need)
{
    int incr = mid*(mid+1)/2; incr*=d;
    return incr<=need;
}
int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin>>t;
    while(t--)
    {
        cin>>a>>b>>m; int k;
        pre[0] = 0; pre[1] = a;
        out[1] = a;
        for(int i = 2;i<=50;i++)
        {
            out[i] = pre[i-1]+1;
            pre[i] = pre[i-1]+out[i];
            if(out[i]>b) break;
            k = i; if(out[i] == b) break;
        }
        int need = b - out[k];
        if(m>1)
        {
            int mn = min(m-1,need); out[k]+=mn; need-=mn;
        }
        vector<pair<int,int> >extra;
        for(int i = 2;i<k;i++)
        {
            int dist = k-i;
            int l = 0,r = m-1,z = 0;
            while(l<=r)
            {
                int mid = l+(r-l)/2;
                if(is_ok(mid,dist,need))
                {
                    z = mid; l = mid+1;
                }
                else r = mid-1;
            }
            extra.pb({i,z});
            need-=(z*dist*(dist+1)/2);
        }
        if(need!=0){cout<<-1<<endl; continue;}
        for(int i = 0;i<k;i++) out[i] = 0,pre[i] = 0;
        for(auto p:extra) out[p.first] = p.second+1;
        pre[1] = a; out[1] = a;
        for(int i = 2;i<k;i++)
        {
            out[i]+=pre[i-1]; pre[i] = pre[i-1]+out[i];
        }
        out[k] = b;
        cout<<k<<" "; for(int i = 1;i<=k;i++) cout<<out[i]<<" "; cout<<endl;

    }

}


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

void resuelve () {

}

int main () {

	long long int q=0, a=0, b=0, m=0, x=0, i=0, diff=0, j=0, k=0, idx=0;

	vector <long long int> pows;
	vector <long long int> val;

	pows.push_back(0);
	pows.push_back(1);

	for (i=2; i<=55; i++) {
		x = pows[i-1]*2;
		pows.push_back(x);
	}

	cin >> q;

	while (q--) {

		val.clear();

		cin >> a >> b >> m;

		val.push_back(a);
		i=1;
		x=a*pows[i];

		while (i<50 && x<b) {
			val.push_back(x);
			i++;
			x=a*pows[i];
		}

		i--;
		x = val[i] + pows[i];
		while (x > b) {
			i--;
			x = val[i] + pows[i];
		}

		//cout << x << " , " << i << endl;

		if (x < b) {

			int base = 2;

			if (base > m) { cout << "-1" << endl;}
			else {

				while (base <= m) {
					x += pows[i];
					//cout << " -  " << x << endl;
					if (x == b) {
						cout << i+1 << " ";

						cout << val[0];
						for (j=1; j<=i; j++) val[j]+=base*pows[j];
						for (j=1; j<=i; j++) cout << " " << val[j];
						cout << endl;
						x = val[i];

						break;
					}
					else if (x > b) {
						base--;
						x -= pows[i];
						diff = b-x;

						cout << i+1 << " ";

						diff--;

						vector<bool> bin;
						bin.push_back(1);

						while (diff!=0) {
							bin.push_back(diff%2);
							diff /= 2;
						}

						while (bin.size() < i+1) bin.push_back(0);
						reverse(bin.begin(), bin.end());

						//for (j=0; j<=i; j++) cout << bin[j] << " "; cout << endl;

						cout << val[0];
						for (j=1; j<=i; j++){
							val[j]+= base*pows[j];
							if (bin[j]) {
								val[j]++;
								for (idx=j+1, k=1; idx<=i; idx++, k++)
									val[idx] += pows[k];
							}
						}

						for (j=1; j<=i; j++) cout << " " << val[j];
						cout << endl;
						x = val[i];

						break;
					}
					base++;
				}

				if (x!=b) cout << "-1" << endl;

			}

		}
		else {

			cout <<i+1<<  " ";
			cout << val[0];
			for (j=1; j<=i; j++) val[j]+= pows[j];
			for (j=1; j<=i; j++) cout << " " << val[j];
			cout << endl;
			x = val[i];
		}

	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define f first
#define s second
#define pb push_back
#define PII pair<ll,ll>
ll const MOD = 1000000007;
ll const N = 1000005;
ll const LN = 20;
ll const inf = 8e18;
using namespace std;

ll n, m, a[N];

int main()
{
	ios::sync_with_stdio (false);
	cin.tie (NULL);
	ll q;
	cin >> q;
	while (q--)
	{
		ll a, b, m;
		cin >> a >> b >> m;
		if (a == b)
		{
			cout << 1 << " " << a << '\n';
			continue;
		}
		if (b <= a + m)
		{
			cout << 2 << " " << a << " " << b << '\n';
			continue;
		}
		if (m == 1)
		{
			ll pre = a;
			vector<ll>ans;
			ans.pb (pre);
			while (1)
			{
				ll cur = pre + 1;
				ans.pb (cur);
				if (cur >= b)
					break;
				pre += cur;
			}
			if (ans.back() != b)
				cout << "-1\n";
			else
			{
				cout << ans.size() << " ";
				for (auto w : ans) cout << w << " ";
				cout << '\n';
			}
			continue;
		}
		ll len = 2;
		ll cur = 2;
		ll f = 0;
		for (len = 2;; len++)
		{
			if (f) break;
			if (b - cur * a > 0)
			{
				ll rem = b - cur * a;
				if (cur * m >= rem && rem >= cur)
				{
					f = 1;
					vector<ll>temp;
					rem -= cur;
					ll nw = cur / 2;
					while (rem > 0)
					{
						ll ok = rem / nw;
						ok = min (ok, m - 1);
						temp.pb (ok);
						rem -= ok * nw;
						if (nw != 1)
							nw /= 2;
					}
					vector<ll>ans;
					ll pre = a;
					ans.pb (a);
					for (ll i = 0; i < temp.size(); i++)
					{
						ll cur = pre + temp[i] + 1;
						ans.pb (cur);
						pre += cur;
					}
					while (1)
					{
						ll cur = pre + 1;
						ans.pb (cur);
						if (cur == b) break;
						pre += cur;
					}
					cout << ans.size() << " ";
					for (auto w : ans) cout << w << " ";
					cout << '\n';
				}
			}
			else break;
			cur = 2 * cur;
		}
		if (!f)
		{
			cout << "-1\n";
			continue;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define f first
#define s second
#define pb push_back
#define PII pair<ll,ll>
ll const MOD = 1000000007;
ll const N = 1000005;
ll const LN = 20;
ll const inf = 8e18;
using namespace std;

ll n, m, a[N];

int main()
{
	ios::sync_with_stdio (false);
	cin.tie (NULL);
	ll q;
	cin >> q;
	while (q--)
	{
		ll a, b, m;
		cin >> a >> b >> m;
		if (a == b)
		{
			cout << 1 << " " << a << '\n';
			continue;
		}
		if (b <= a + m)
		{
			cout << 2 << " " << a << " " << b << '\n';
			continue;
		}
		if (m == 1)
		{
			ll pre = a;
			vector<ll>ans;
			ans.pb (pre);
			while (1)
			{
				ll cur = pre + 1;
				ans.pb (cur);
				if (cur >= b)
					break;
				pre += cur;
			}
			if (ans.back() != b)
				cout << "-1\n";
			else
			{
				cout << ans.size() << " ";
				for (auto w : ans) cout << w << " ";
				cout << '\n';
			}
			continue;
		}
		ll len = 2;
		ll cur = 2;
		ll f = 0;
		for (len = 2;; len++)
		{
			if (f) break;
			if (b - cur * a > 0)
			{
				ll rem = b - cur * a;
				if (cur * m >= rem && rem >= cur)
				{
					f = 1;
					vector<ll>temp;
					rem -= cur;
					ll nw = cur / 2;
					while (rem > 0)
					{
						ll ok = rem / nw;
						ok = min (ok, m - 1);
						if (ok == 0) break;
						temp.pb (ok);
						rem -= ok * nw;
						if (nw != 1)
							nw /= 2;
					}
					vector<ll>ans;
					ll pre = a;
					ans.pb (a);
					ll cur;
					for (ll i = 0; i < temp.size(); i++)
					{
						cur = pre + temp[i] + 1;
						ans.pb (cur);
						pre += cur;
					}
					while (cur != b)
					{
						cur = pre + 1;
						ans.pb (cur);
						pre += cur;
					}
					cout << ans.size() << " ";
					for (auto w : ans) cout << w << " ";
					cout << '\n';
				}
			}
			else break;
			cur = 2 * cur;
		}
		if (!f)
		{
			cout << "-1\n";
			continue;
		}
	}
	return 0;
}


#include <iostream>
#include<utility>
using namespace std;
pair<int,int> p,p1;

int main() {
    long long int s,count=0;
    cin>>p.first>>p.second;
    p1.first=0,p1.second=0;
    cin>>s;
    while(s!=count)
    {
        if(p.first==p1.first && p.second==p1.second)
        {
                break;
        }
        if(p.first>p1.first)
        {
            count+=(p.first-p1.first);
            p1.first+=(p.first-p1.first);

        }
        else if(p.first<p1.first)
        {
            count+=(p1.first-p.first);
        p1.first-=(p1.first-p.first);
            }
        else if(p.second>p1.second)
        {
            count+=(p.second-p1.second);
        p1.second+=(p.second-p1.second);
            }
        else if(p.second<p1.second)
        {
            count+=(p1.second-p.second);
        p1.second-=(p1.second-p.second);
            }
   //     cout<<p1.first<<' '<<p1.second<<' '<<count;
    }
    if(p.first==p1.first && p.second==p1.second)
    {
        if(s!=count)
        {
            p1.first++;
            count++;
            while(s!=count)
            {
               if(p.first<p1.first)
               {
                p1.first--;
                count++;
               }
               else{
                p1.first++;
                count++;
               }
            }
        }
    }
    if(p.first==p1.first && p.second==p1.second)
    {
        if(s==count)
        cout<<"Yes";

        else
        cout<<"No";
    }
    else{
        cout<<"No";
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int a,b,s;
    while(1){
    cin>>a>>b>>s;
    if(a+b>s)
        cout<<"No"<<endl;
    else if((s-a-b)%2==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;}

}


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

int main()
{
    for(;;){
    long long int a,b,s;
    cin>>a>>b>>s;

    //int m1=(a+b)<=s;
    //int m2=(s-(a+b))%2==0;
    //int m3=(s-(a+b))%2==1;

    int a1=abs(a)+abs(b);
    //int a2=a1

    if((s>=a1) && ((s-a1)%2==0)){
        cout<<"Yes"<<endl;
    }

     else {
        cout<<"No"<<endl;
    }
}
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long  ull;

#define     mem(a,b)        memset(a,b,sizeof(a))
#define     mp              make_pair
#define     pii             pair<int,int>
#define     fs              first
#define     sc              second
#define     VI              vector<int>
#define     clr(a)          a.clear()
#define     pob             pop_back
#define     pub             push_back
#define     eps             1E-5
#define     sf              scanf
#define     pf              printf
#define     all(a)          a.begin(),a.end()
#define     allr(a)         a.rbegin(),a.rend()
#define     full(a,l)       a,a+l
#define     fread(name)     freopen(name,"r",stdin)
#define     fwrite(name)    freopen(name,"w",stdout)
#define     sz(a)           a.size()
#define     count_one       __builtin_popcount
#define     count_onell     __builtin_popcountll
#define     fastIO          ios_base::sync_with_stdio(false)
#define     PI              (acos(-1.0))
#define     linf            (1LL<<62)//>4e18
#define     inf             (0x7f7f7f7f)//>2e9
#define     fore(x,i)       for(typeof((x).begin()) i=(x.begin()); i!=(x).end(); ++i)
#define     rfore(x,i)      for(typeof((x).rbegin()) i=(x.rbegin()); i!=(x).rend(); ++i)
#define     For(i,a,b)      for(int i=a;i<=b;++i)
#define     rFor(i,a,b)     for(int i=a;i>=b;--i)

template<class T> T pwr(T b, T p)
{
    T r=1,x=b;
    while(p)
    {
        if(p&1)r*=x;
        x*=x;
        p=(p>>1);
    }
    return r;
}
template<class T> T lcm(T a,T b)
{
    return(a/__gcd(a,b))*b;
}
template<class T> T sqr(T a)
{
    return a*a;
}
template<class T> void xswap (T &x,T &y)
{
    if(x!=y)
    {
        x^=y;
        y^=x;
        x^=y;
    }
}
///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//struct tuple{double f,s,t;tuple(){}tuple(double a,double b,double c){f=a,s=b,t=c;}};
//int cross_product(tuple a,tuple b){int v=a.f*(b.s-b.t)-a.s*(b.f-b.t)+a.t*(b.f-b.s);return (v==0?0:(v>0?+1:-1));}
//tuple make_vector(tuple s,tuple e){tuple a;a.f=e.f-s.f;a.s=e.s-s.s;a.t=e.t-s.t;return a;}
///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<typename T> inline bool isOn(T &mask,int pos)
{
    return((mask)&(1LL<<pos));
}
template<typename T> inline T setf(T mask,int pos)
{
    return mask=((mask)&(~(1LL<<pos)));
}
template<typename T> inline T sett(T mask,int pos)
{
    return mask=((mask)(1LL<<pos));
}
template<typename T> inline T flip(T mask,int pos)
{
    return mask=((mask)^(1LL<<pos));
}
///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//double dtor(double x){return x*PI/180.0;}
//double rtod(double x){return x*180.0/PI;}
//double pdis(pdd a,pdd b){return sqrt((double)sqr(a.fs-b.fs)+sqr(a.sc-b.sc));}
//template<class T> double rAng(T a,T b,T c){double d=(sqr(a)+sqr(b)-sqr(c))/(a*b*2);d=(d<-1?-1:(d>1?1:d));return acos(d);}
///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<class T> string to_string(T n)
{
    ostringstream oss;
    oss<<n;
    oss.flush();
    return oss.str();
}
int to_int(string s)
{
    int r=0;
    istringstream sin(s);
    sin>>r;
    return r;
}
///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<class T1> void put(T1 e)
{
    cout<<e<<endl;
}
template<class T1,class T2> void put(T1 e1,T2 e2)
{
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void put(T1 e1,T2 e2,T3 e3)
{
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void put(T1 e1,T2 e2,T3 e3,T4 e4)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void put(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1> void putv(vector<T1>e1)
{
    for(int i=0; i<sz(e1); i++)(!i?cout<<e1[i]:cout<<" "<<e1[i]);
    cout<<endl;
}
template<class T1> void puta(T1 arr[],int l)
{
    for(int i=0; i<l; i++)(!i?cout<<arr[i]:cout<<" "<<arr[i]);
    cout<<endl;
}
template<class T1> bool tk(T1 &e1)
{
    return(cin>>e1?true:false);
}
template<class T1,class T2> bool tk(T1 &e1,T2 &e2)
{
    return(cin>>e1>>e2?true:false);
}
template<class T1,class T2,class T3> bool tk(T1 &e1,T2 &e2,T3 &e3)
{
    return(cin>>e1>>e2>>e3?true:false);
}
template<class T1,class T2,class T3,class T4> bool tk(T1 &e1,T2 &e2,T3 &e3,T4 &e4)
{
    return(cin>>e1>>e2>>e3>>e4?true:false);
}

long status[100010041+1];

int prime(long N)
{

    long i, j, sqrtN;

    for( i = 2; i <= N; i++ ) status[i] = 0;

    sqrtN = long( sqrt((double) N )); // have to check primes up to (sqrt(N))

    for( i = 3; i <= sqrtN; i += 2 )
    {

        if( status[i] == 0 )
        {
            // so, i is a prime, so, discard all the multiples

            // j = i * i, because it�s the first number to be colored

            for( j = i * i; j <= N; j += i + i )

                status[j] = 1; // status of the multiple is 1
        }

    }
}

int recur(int n1, int n2, int n3)
{
    printf("%d %d %d\n",n1,n2,n3);
    if(n1 > n2 && n1 > n3)
        return recur(n1-1, n2, n3);
    else if(n2 > n1 && n2 > n3)
        return recur(n1, n2-1, n3);
    else if(n3 > n1 && n3 > n2)
        return recur(n1, n2, n3-1);
    else
        return (n1 + n2 + n3);
}

int main()
{

//#ifdef shihab
//    freopen("in.txt","r",stdin );
//    freopen("out.txt","w",stdout );
//#endif

//prime(100010041);

    long x,y,d;

    while( sf("%ld %ld %ld",&x,&y,&d) ==3 )
    {

        if( !x && !y && d==2 )
            printf("Yes\n");
        else
        {
            if( (x+y)==d )
                printf("Yes\n");
            else
                printf("No\n");
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)       for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)      cout<<#x<<" = "<<x<<endl;
#define SIZE(p)       (int)(p).size()
#define MP(a,b)       make_pair((a),(b))
#define ALL(p)        (p).begin(),(p).end()
#define rep(i,n)      for(int i=0;i<(int)(n);++i)
#define REP(i,a,n)    for(int i=(a);i<(int)(n); ++i)
#define FOR(i,a,b)    for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,b,a)   for(int i=(int)(b);i>=(int)(a);--i)
#define CLR(x,y)      memset((x),(y),sizeof((x)))
typedef long long LL;
typedef pair<int,int> pii;
int n;
int L[10],R[10];
double dp[6][6][2],ps;
double gao(int m){
    CLR(dp,0);
    dp[0][0][0]=1;
    FOR(i,0,n-1)
    FOR(j,0,n)
    rep(k,2)
    FOR(d,L[i+1],R[i+1]){
        if(k && d>m)continue;
        dp[i+1][j+(d==m)][k|(d>m)]+=dp[i][j][k]*(1.0/(R[i+1]-L[i+1]+1));
    }
    double s=dp[n][1][1];
    FOR(i,2,n)s+=dp[n][i][0]+dp[n][i][1];
    // if(m<=10){
    //     DEBUG(s);
    // }
    ps+=s;
    return s;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("C.in","r",stdin);
    // freopen("out","w",stdout);
#endif
    scanf("%d",&n);
    FOR(i,1,n)scanf("%d%d",L+i,R+i);
    double res=0;
    FOR(i,1,10000)res+=i*gao(i);
    printf("%.12f\n",res);
    // DEBUG(ps);
    return 0;
}


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

#define mp make_pair
#define pb push_back
#define debug( x ) cout << #x << " = " << x << endl
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define f(i,a,b) for(int i = a ; i < b ; i++)
#define EPS 1E-9
#define INF 1000000000

using namespace std;

typedef pair<int,int> ii ;
typedef long long ll ;
typedef vector<int> vi;
typedef vector<ii> vii;
vii empresas;
int n;
double dp[6][10010][6][6];
double go(int pos, int secondmax, int c1, int c2){
    if(pos == n){
        if(c1 >= 1 && c2 == 1){
            return 1.0;
        }
        if(c2 == 0 && c1 >= 2){
            return 1.0;
        }
        return 0.0;
    }
    if(dp[pos][secondmax][c1][c2] != -1.0) return dp[pos][secondmax][c1][c2];
    double suma = 0.0;
    for(int i = empresas[pos].first; i <= empresas[pos].second ; i++){
        int a = c1; int b = c2;
        double rango = double(empresas[pos].second - empresas[pos].first + 1);
        if(i == secondmax) {
            a++;
        }
        else if(i > secondmax ) b++;

        suma += (1.0/rango)*go(pos+1,secondmax,a,b);

    }
    return dp[pos][secondmax][c1][c2] = suma;
}

int main(){
    cin >> n;
    f(i,0,6) f(j,0,10010) f(k,0,6) f(t,0,6) dp[i][j][k][t] = -1.0;
    int mini = 1e9;
    int maxi = 0;
    f(i,0,n){
        int l, r; cin >> l >> r;
        empresas.pb(mp(l,r));
        mini = min(l,mini);
        maxi = max(r,maxi);
    }
    double res = 0.0;
    for(int i = mini; i <= maxi; i++){
        double val = double(i)*go(0,i,0,0);
        //debug(i);debug(val/i);
        res+=val;
    }
    cout<< fixed<<setprecision(10)  << res<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
struct thanks{
    int a,b;
}p[12];
map<pair<int ,int>,double> mp,vp;
double ans;
pair<int,int> temp,remp;
int main(){
    int i,j,l,m,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d%d",&p[i].a,&p[i].b);
    }
    for(i=p[1].a;i<=p[1].b;i++){
        mp[make_pair(i,0)]=1.0;//(p[1].b-p[1].a+1)
    }
    for(i=2;i<=n;i++){
        vp.clear();
        map<pair<int,int>,double>::iterator it;
        for(it=mp.begin();it!=mp.end();it++){
            temp=it->first;
            if(p[i].a<=temp.second){
                if(p[i].b>temp.second) vp[temp]+=(it->second)*(temp.second-p[i].a+1);//(p[i].b-p[i].a+1)
                else vp[temp]+=(it->second)*(p[i].b-p[i].a+1);
            }
            for(j=max(temp.second+1,p[i].a);j<=p[i].b;j++){
                remp=temp;
                if(remp.second<j) remp.second=j;
                if(remp.first<j) swap(remp.first,remp.second);
                vp[remp]+=(it->second);//(p[i].b-p[i].a+1);
            }
        }
        mp=vp;
    }
    map<pair<int,int>,double>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        ans+=it->first.second*it->second;
    }
    for(i=1;i<=n;i++) ans/=p[i].b-p[i].a+1;
    printf("%.15lf\n",ans);
    //system("pause");
    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <iomanip>
#include <map>
#include <complex>
#include <set>

#define mod 1000000007
#define LL long long

using namespace std;

typedef pair<int , int> PII;

const int N = 1e5 + 10;
const int INF = 1e9 + 7;
const double eps = 1e-7;

int a[11], b[11];
double dp[1 << 6][1 << 6][11111];
int n;
bool no_intersect(int m1, int m2) {
	if(m1 == 0)
		return false;
	if((m1 & m2) > 0)
		return false;
	return true;
}

double find_intersect(int m1, int L) {
	double prob = 1.0;
	for(int i = 0; i < n; i++) {
		if((1 << i) & m1) {
			if(b[i] < L || a[i] > L)
				return 0.0;
			prob *=  1.0 / (1.0 * (b[i] - a[i] + 1));
		}
	}
	return prob;
}

double find_range(int m1, int L) {
	double prob = 1.0;
	int maxA = 0, minB = 11111111;
	for(int i = 0; i < n; i++) {
		if((1 << i) & m1) {
			maxA = max(a[i], maxA);
			minB = min(b[i], minB);
		}
	}
	if(L < maxA || L > minB)
		return 0.0;
	else {
		for(int i = 0; i < n; i++) {
			if((1 << i) & m1) {
				prob = prob * (1.0) / ((b[i] - a[i] + 1.0) * 1.0);
			}
		}
	}
	return prob;
}

double find_range1(int m1, int L) {
	double prob = 1.0;
	int maxA = 0, minB = 11111111;
	for(int i = 0; i < n; i++) {
		if((1 << i) & m1) {
			maxA = max(a[i], maxA);
			minB = min(b[i], minB);
		}
	}
	if(L + 1 > minB)
		return 0.0;
	maxA = max(maxA, L + 1);
	if(maxA > minB)
		return 0.0;
	else {
		for(int i = 0; i < n; i++) {
			if((1 << i) & m1) {
				prob = prob * (1.0 * (minB - maxA + 1.0)) / ((b[i] - a[i] + 1.0) * 1.0);
			}
		}
	}
	return prob;
}

double rest_all(int m1, int m2, int L) {
	double prob = 1.0;
	for(int i = 0; i < n; i++) {
		if(((1 << i) & m1) == 0 && ((1 << i) & m2) == 0){
			if(a[i] >= L)
				return 0.0;
			else
				prob *=  ((min(b[i], L - 1) - a[i] + 1.0) * 1.0) / ((b[i] - a[i] + 1.0) * 1.0);
		}
	}
	return prob;
}

void solve(){
	memset(dp, 0, sizeof dp);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	double ans = 0.0;
	for(int mask1 = 1; mask1 < (1 << n); mask1++) {
		for(int mask2 = 1; mask2 < (1 << n); mask2++) {
			if(no_intersect(mask1, mask2) == false)
				continue;
			for(int L = 1; L <= 10000; L++)  {
				if(mask1 == (1 << n) - 1 ||  __builtin_popcount(mask1) > 1) {
					continue;
				}
				ans += (find_range1(mask1, L) * find_intersect(mask2, L) * rest_all(mask1, mask2, L) * L);
			}
		}
	}
	for(int mask1 = 1; mask1 < (1 << n); mask1++) {
		for(int L = 1; L <= 10000; L++)  {
			if(mask1 == (1 << n) - 1 ||  __builtin_popcount(mask1) > 1) {
				ans += (find_range(mask1, L) * rest_all(mask1, 0, L) * L);
			}
		}
	}
	printf("%.6f\n", ans);
	return;
}

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

}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
#define __   ios_base::sync_with_stdio(0);cin.tie();cout.tie();

string s,s1,s2,s3,s4,s5;
ll n,m,x,y,z;
ll arr[500010];
ll brr[500010];
vector<ll>v,v1;
set<ll>st;

void memset_ll(ll a[], ll v, ll n)
{
    for(ll i=0; i<n; i++)
        a[i]=v;
}

int compare(const void * a, const void * b)
{
    return ( *(ll*)a - *(ll*)b );
}
void q_sort(ll a[], ll n)
{
    qsort(a, n, sizeof(ll), compare);
}

ll is_prime(ll n)
{
    ll i,j,k=1;
    for(i=2; i<=n/2; i++)
    {
        if(n%i==0)
        {
            k=0;
            break;
        }
    }
    return k;
}

ll bsearch(ll arr[], ll l, ll r, ll x)
{
    if (r >= l)
    {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return bsearch(arr, l, mid - 1, x);
        return bsearch(arr, mid + 1, r, x);
    }
    return -1;
}

static int compare1 (const void * a, const void * b)
{
    if (*(double*)a > *(double*)b)
        return 1;
    else if (*(double*)a < *(double*)b)
        return -1;
    else
        return 0;
}

void q_sort_d(double a[], ll n)
{
    qsort(a, n, sizeof(double), compare1);
}

string trans_upper(string ss)
{
    transform(ss.begin(),ss.end(),ss.begin(), ::toupper);
    return ss;
}

ll power(ll a, ll b)
{
    ll pow = 1;
    while ( b )
    {
        if ( b & 1 )
        {
            pow = pow * a;
            --b;
        }
        a = a*a;
        b = b/2;
    }
    return pow;
}

int main()
{
    __
    ll t,h,i,j,k,l,p,q,r;
    ll d=0,e=0,f=0,g=0;
    ll dd=0,uu=0,rr=0,lll=0;
    ll ans=0,sum=0,temp=0;
    ll x1,y1,x2,y2;

    double p1,p2,p3,p4,p5;
    double pp=0.0,ppp=1.0;
    double pi =3.141592654;

    cin>>x>>y>>z>>r;
    ll a[100000];
    t=r;
    a[0]=(x*r+y)%z;
    for(i=1; i<100000; i++)
    {
        r=a[i-1];
        a[i]=(x*r+y)%z;
    }
    for(k=1; k<100000; k++)
    {
        j=99990;
        if(a[j]==a[j-k]&&a[j-1]==a[j-1-k])
        {
            cout<<k;
            return 0;
        }
    }
    if(x==0||y==0)
    {
        cout<<1;
        return 0;
    }
    if(t==0)
    {
        cout<<z;
        return 0;
    }

return 0;
}


#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
vector <int> mrSequence;

int main(int argc, char** argv) {
    int mrA; int mrB; int mrsM; int mrR0;
    int mrResult;
    int mrSequenceIterator;
    cin >> mrA; cin >> mrB; cin >> mrsM; cin >> mrR0;
    mrSequence.push_back(mrR0);
    for (mrSequenceIterator = 1; 1 == 1; mrSequenceIterator++) {
        mrSequence.push_back((mrA * mrSequence[mrSequenceIterator-1] + mrB) % mrsM);
        if (mrSequenceIterator > 10) {
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-1]) {
                cout << '1';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-2]) {
                cout << '2';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-3]) {
                cout << '3';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-4]) {
                cout << '4';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-5]) {
                cout << '5';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-6]) {
                cout << '6';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-7]) {
                cout << '7';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-8]) {
                cout << '8';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-9]) {
                cout << '9';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-10]) {
                cout << '10';
                break;
            };
        };
    };
    return 0;
};


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

bool check(vector<int> v,int m){
	for (int i=v.size()-2;i>=max(i-m,0);i--){
		if (v[v.size()-1]==v[i]){
			cout<<v.size()-i-1<<endl;
			return true;
		}
	}
	return false;
}
void print(vector<int> v){
	for (int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
	return;
}

int main(int argc, char const *argv[])
{
	int a,b,m,r;
	cin>>a>>b>>m>>r;
	int temp=r;
	vector<int> v;
	while(true){
		int e;
		e = (a*temp+b)%m;
		v.push_back(e);
		//print(v);
		if ((a*temp+b)>=m){
			if (check(v,m))
				break;
		}
		temp=e;
	}

	return 0;
}


#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,m,x;
struct node{
	int id,x;
}h[N];
bool cmp(node x,node y){
	return x.x<y.x;
}
int ans[N];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d",&n,&m,&x);
		int sum=0;
		for(int i=1;i<=n;i++) scanf("%d",&h[i].x),sum+=h[i].x,h[i].id=i;
		sort(h+1,h+n+1,cmp);
 		for(int i=1;i<=n;i++) ans[h[i].id]=(i-1)%m+1;
 		puts("YES");
 		for(int i=1;i<=n;i++) printf("%d ",ans[i]);
 		puts("");

	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

const int N=410;

long long n,m;
long long f[N][N];
long long C[N][N];

inline void init()
{
	for(int i=0;i<=N;++i)
	{
		C[i][0]=1;
		for(int j=1;j<=i;++j)
		{
			C[i][j]=(C[i-1][j]%m+C[i-1][j-1]%m)%m;
		}
	}
}

inline long long ksm(long long a,long long b,long long p)
{
	long long ans=1;
	a%=p;
	while(b)
	{
		if(b&1) ans=ans*a%p;
		a=a*a%p;
		b>>=1;
	}
	return ans;
}

int main()
{
	scanf("%lld%lld",&n,&m);
	init();
	for(int i=1;i<=n;++i)
	{
		f[i][i]=ksm(2,i-1,m);
		for(int j=0;j<=i;++j)
		{
			for(int k=1;k+i+1<=n;++k)
			{
				f[i+1+k][j+k]+=f[i][j]*ksm(2,k-1,m)*C[j+k][k]%m;
				f[i+1+k][j+k]%=m;
			}
		}
	}
	long long ans=0;
	for(int i=0;i<=n;++i)
	{
		ans+=f[n][i];
		ans%=m;
	}
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define ljc 998244353
//#define ljc 1000000007
#define gc getchar
#define mp make_pair
#define pii pair<int,int>
#define pib pair<int,bool>
#define fi first
#define se second
typedef unsigned long long ull;
using namespace std;
inline ll read(){
	ll x=0,f=1;char ch=gc();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
	while (isdigit(ch)){x=x*10ll+ch-'0';ch=gc();}
	return x*f;
}
inline void file(){
//	freopen(".in","w",stdout);
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
bitset<100000022> vis;
int n,tot;
ll A,B,C,D;
int main(){
//	file();
	n=read();
	A=read(),B=read(),C=read(),D=read();
	ll _=0;
	for (int i=2;i<=n;i++){
		if (i==2||i==3||(i%2!=0&&i%3!=0&&i%5!=0&&!vis[i%6==1?2*(i/6):2*(i/6)+1])){
			ll F=1ll*A*i*i*i+1ll*B*i*i+1ll*C*i+D;
			for (ll j=i;j<=n;j=j*i){
				_+=F*(n/j);
			}
//			cout<<i<<" ";
		}else continue;
		for (int j=i*2;j<=n;j+=i){
			if (j%2&&j%3&&j%5) vis[j%6==1?2*(j/6):2*(j/6)+1]=1;
		}
	}
	cout<<_;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0;
	int f=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
const int maxM=50010;
int n,m;
namespace op
{
	int op[maxM];
	ll l[maxM],r[maxM];
};
vector<pair<ll,ll>> vec;
struct SGT
{
	#define SIZE (8000010)
	int root,cnt_node,ch[SIZE][2],f[SIZE],nmsl[SIZE];
	struct SET
	{
		int f[SIZE],siz[SIZE];
		void new_node(int nod)
		{
			f[nod]=nod;
			siz[nod]=1;
		}
		int get_f(int x)
		{
			return f[x]==x?x:f[x]=get_f(f[x]);
		}
		void merge(int x,int y)
		{
			x=get_f(x);
			y=get_f(y);
			if(siz[x]<siz[y]) swap(x,y);
			f[y]=x;
		}
	}s;
	int new_node(int fa)
	{
		cnt_node++;
		s.new_node(cnt_node);
		f[cnt_node]=fa;
		return cnt_node;
	}
	void add(int nod,int nod_)
	{
		if(nmsl[nod]>0)
		{
			s.merge(nod,nod_);
			return;
		}
		if(ch[nod][0]) add(ch[nod][0],nod_);
		if(ch[nod][1]) add(ch[nod][1],nod_);
	}
	void modify(int &nod,ll l,ll r,int d,ll x,int fa)
	{
		if(!nod) nod=new_node(fa);
		if(l<=x&&r>=x+(1ll<<d)-1)
		{
			int nod__=nod;
			while(nod__)
			{
				if(nmsl[nod__]==2) s.merge(nod__,nod);
				nod__=f[nod__];
			}
			for(int i=n-1;i>=d;i--)
			{
				int nod_=root,tmp=0;
				for(int j=n-1;j>=d;j--)
				{
					if(nmsl[nod_]==1) s.merge(nod_,nod);
					if(nmsl[nod_]==2) tmp=nod_;
					nod_=ch[nod_][j!=i?((x>>j)&1):!((x>>j)&1)];
					if(!nod_) break;
				}
				if(nod_)
				{
					if(tmp!=0)
					{
						s.merge(tmp,nod);
						continue;
					}
					add(nod_,nod);
					if(!nmsl[nod_])
					{
						nmsl[nod_]=2;
						s.merge(nod_,nod);
					}
				}
			}
			nmsl[nod]=1;
			return;
		}
		if(l<=x+(1ll<<(d-1))-1) modify(ch[nod][0],l,r,d-1,x,nod);
		if(r>=x+(1ll<<(d-1))) modify(ch[nod][1],l,r,d-1,x+(1ll<<(d-1)),nod);
	}
	void modify(ll l,ll r)
	{
		modify(root,l,r,n,0,0);
	}
	int query(int nod,ll x,int d)
	{
		if(!nod) return 0;
		if(nmsl[nod]>0) return s.get_f(nod);
		return query(ch[nod][(x>>(d-1))&1],x,d-1);
	}
	int query(ll x)
	{
		return query(root,x,n);
	}
}sgt;
int ans[maxM];
int main()
{
	n=read();
	m=read();
	int tmp=0;
	for(int i=1;i<=m;i++)
	{
		char op[10];
		scanf("%s",op);
		op::op[i]=(op[0]=='a');
		if(op::op[i]==1) tmp=i;
		op::l[i]=read();
		op::r[i]=read();
	}
	m=tmp;
	for(int i=1;i<=m;i++) if(op::op[i]==0) vec.push_back({op::l[i],op::r[i]});
	sort(vec.begin(),vec.end());
	ll last=0;
	for(auto i:vec)
	{
		if(last<=i.first-1) sgt.modify(last,i.first-1);
		last=i.second+1;
	}
	if(last<=(1ll<<n)-1) sgt.modify(last,(1ll<<n)-1);
	for(int i=m;i>=1;i--)
	{
		if(op::op[i]==0) sgt.modify(op::l[i],op::r[i]);
		if(op::op[i]==1)
		{
			int x=sgt.query(op::l[i]),y=sgt.query(op::r[i]);
			ans[i]=(x!=0&&y!=0&&x==y);
		}
	}
	for(int i=1;i<=m;i++) if(op::op[i]==1) printf("%d\n",ans[i]);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <iomanip>
#include <deque>
using namespace std;

typedef unsigned long long ll;
typedef long double ld;
typedef double dd;

const ll INF = 10e8;
const ll mod = 10e8 + 7;

ll bin(int a, ll b) {
    if (b == 1) {
        return a;
    }
    if (b % 2 == 0) {
        ll c = bin(a, b / 2);
        return (c * c) % mod;
    }
    else {
        return (a * bin(a, b - 1)) % mod;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    int k;
    cin >> k;
    cout << (6 * bin(4, pow(2, k) - 2)) % mod;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
int mod = (1 ? 1e9 + 7 : 998244353);
const int N = 5e5 + 5;
const int M = 20 * N;
ll exp(ll b) {
    if (b == 1) return 4;
    ll ans = 1;
    if (b % 2 == 1) ans = 4;
    ll c = exp(b / 2);
    ans = (ll) ans * c % mod;
    ans = (ll) ans * c % mod;
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    int k;
    cin >> k;
    ll ans = 6;
    ll b = (1LL << k) - 2;
    ll c = exp(b);
    ans = (ll) (ans * c) % mod;
    cout << ans << en;
    return 0;
}


//Be like Errichto
//la 1 fan liquid, hay code theo cach cua ban :lmao:

#include<bits/stdc++.h>

#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=1;i<=b;i++)
#define FOD(i,a,b) for(int i=a;i>=b;i--)

#define MOD 1e7+7
#define MOD1 1e9+9
#define PI 3.1415926535897932384626433832795

#define onetap int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define taskname ""
using namespace std;

const int maxn=5e5+10;
const int mod=1e9+7;
const int LINF = 0x3f3f3f3f3f3f3f3f;

int n;
int mu(int a, int b)
{
	if(b==1) return a;
	else
	{
		if(b%2==0) return (mu(a, b/2)%mod * mu(a, b/2)%mod + mod*mod) % mod;
		else return (mu(a, b/2)%mod * mu(a, b/2)%mod * a+ mod*mod) % mod;
	}
}

signed main()
{
	if(ifstream(taskname".inp"))
	{
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    speed
	int n;
	cin>>n;
	n=mu(2, n)-1;
	cout<<(6 * mu(4, n-1))%mod;
	return 0;
/*   /\_/\
    (= ._.)
    / >0  \>1 BRUH BRUH LMAO LMAO
*/
}


#define _CRT_SECURE_NO_WARNINGS
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <iomanip>
#include <deque>
using namespace std;

typedef unsigned long long ll;
typedef long double ld;
typedef double dd;

const ll INF = 10e8;
const ll mod = 10e8 + 7;

ll bin(int a, int b) {
    if (b == 1) {
        return a;
    }
    if (b % 2 == 0) {
        ll c = bin(a, b / 2);
        return (c * c) % mod;
    }
    else {
        return (a * bin(a, b - 1)) % mod;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    int k;
    cin >> k;
    cout << (6 * bin(4, pow(2, k) - 2)) % mod;
}


#include <bits/stdc++.h>

using namespace std;
int a[10], x, n;

int main(void) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 6; j++) {
            scanf("%d", &x);
            a[x]++;
        }

    }

//    if (a[0] == 0) {
//        printf("0");
//        return 0;
//    }

    for (int i = 1; i < 10; i++) {
        if (a[i] == 0) {
            printf("%d", i - 1);
            return 0;
        }
    }
    for (int i = 1; i < 10; i++) {
        if (a[i] == 1) {
            printf("%d", i * 10 + i - 1);
            break;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int v[10];
int main(){

    int n;
    scanf("%d",&n);

    for (int i = 0; i < n; ++i){
        for (int  j = 0; j < 6; ++j){
            int x;
            scanf("%d",&x);
            v[x]++;
        }
    }

    for (int i = 1; i <= 10000; ++i){

        int x = i;
        int b[10];
        memset(b,0,sizeof b);
        while(x > 0){
            int p = x % 10;
            x /= 10;
            b[p]++;
        }
        for (int j = 0; j < 10; ++j){
            if(v[j] >= b[j]) continue;
            cout << i - 1 << "\n";
            return 0;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool check(int number, int* mas, vector<int> v) {
	int count = 0, count2 = 0, count3 = 0;
	for (int i = 0; number != 0; ++i) {
		mas[i] = number % 10;
		number /= 10;
		count++;
	}

	int index = 0;
	bool flag = 0;
	while (1) {
		if (count == count2) {
			return 1;
		}
		else if (count3 >= 18) {
			return 0;
		}

		for (int i = 0; i < v.size(); ++i) {
			if (v[i] == mas[index]) {
				index++;
				flag = 1;
				v[i] = -1;

				count2++;
				break;
			}
		}
		if (flag == 1) {
			flag = 0;
		}
		else {
			break;
		}

		count3++;
	}

	return 0;
}

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

	vector<int> num(n * 6);

	for (int i = 0; i < n * 6; ++i) {
		cin >> num[i];
	}

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

	int count = 1;
	int* temp = new int[18];

	while (check(count, temp, num) == true) {
		count++;
	}

	cout << count - 1;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int cnt[10],n,vis[10];
inline bool check(int x){
	static int p[10];
	memset(p,0,sizeof(p));
	while(x)++p[x%10],x/=10;
	for(int i=0;i<10;++i){
		if(p[i]>cnt[i])return false;
	}
	return true;
}
int main(){
	n=read();
	for(int i=1;i<=3;++i){
		memset(vis,0,sizeof(vis));
		for(int j=0;j<6;++j){
			vis[read()]=1;
		}
		for(int x=0;x<10;++x){
			cnt[x]+=vis[x];
		}
	}
	for(int i=1;;++i){
		if(!check(i))return !printf("%d\n",i-1);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 2e5 + 100;
char str[N];
char cmp[N];
LL ans = 0;
LL tmp = 0;
LL n = 0;
LL base = 1;
LL b = 1;
LL t;
vector<LL> vc;
int main(){
    scanf("%s", cmp);
    int len1 = strlen(cmp);
    for(int i = 0; i < len1; i++){
        n = n*10 + cmp[i] - '0';
    }
    scanf("%s", str);
    int len2 = strlen(str);
    for(int i = len2-1; i >= 0;){
        int j = i - len1 + 1;
        if(j < 0) j = 0;
        //cout << j + len1 - 1 << "*" << i << endl;
        //cout << strcmp(cmp,str+j) << endl;
        if((j+len1-1 == i && strcmp(cmp,str+j) <= 0) || str[j] == '0'){
            j++;
            while(str[j] == '0' && j < i) j++;
            t = 0;
            for(int k = j; k <= i; k++)
                t = t*10 + str[k] - '0';
            vc.push_back(t);
            //cout << i << ' ' << j << endl;
        }
        else {
            t = 0;
            for(int k = j; k <= i; k++)
                t = t*10 + str[k] - '0';
            vc.push_back(t);
            //cout << "*" << endl;
        }
        i = j - 1;
    }
    b = 1;
    ans = 0;
    for(int i = 0; i < vc.size(); i++){
        //cout << vc[i] << ' ';
        ans += b*vc[i];
        b*=n;
    }
    printf("%I64d", ans);
    return 0;
}


#include<bits/stdc++.h>
#define bug(x) cout<<"bug "<<x<<endl;
using namespace std;
#define ll long long
const int maxn=1e6+10;
const ll inf=1e18+10;
string n,s;
vector<string> v;

ll toint(string t){
    ll a;
    stringstream st;
    st<<t;
    st>>a;
    return a;
}

int main(){
    cin>>n>>s;
    int len=n.size();
    int idx=s.size()-1;
    while(idx>=0){
        string tmp="";
        if(idx-len+1>=0){
            int f=0;
            for(int i=idx-len+1;i<=idx;i++){
                if(s[i]!='0') f=1;
                if(f==0&&s[i]=='0') continue;
                tmp=tmp+s[i];
            }
            if(tmp.size()==n.size()&&tmp>n){
                tmp="";
                int f=0;
                for(int i=idx-len+2;i<=idx;i++){
                    if(s[i]!='0') f=1;
                    if(f==0&&s[i]=='0') continue;
                    tmp=tmp+s[i];
                }
                v.push_back(tmp);
                idx=idx-tmp.size();
            }
            else{
                v.push_back(tmp);
                idx=idx-tmp.size();
            }
        }
        else{
            for(int i=idx;i>=0;i--){
                tmp=s[i]+tmp;
            }
            v.push_back(tmp);
            idx=-1;
        }
    }
    ll ans=0;
    for(int i=0;i<v.size();i++){
        ans+=pow(toint(n),i)*toint(v[i]);
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 2e5 + 100;
char str[N];
char cmp[N];
LL ans = 0;
LL tmp = 0;
LL n = 0;
LL base = 1;
LL b = 1;
LL t;
vector<LL> vc;
int main(){
    scanf("%s", cmp);
    int len1 = strlen(cmp);
    for(int i = 0; i < len1; i++){
        n = n*10 + cmp[i] - '0';
    }
    scanf("%s", str);
    if(str[0] == '0'){
        cout << 0 << endl;
        return 0;
    }
    int len2 = strlen(str);
    for(int i = len2-1; i >= 0;){
        int j = i - len1 + 1;
        if(j < 0) j = 0;
        if((j+len1-1 == i && strcmp(cmp,str+j) <= 0) || str[j] == '0'){
            j++;
            while(str[j] == '0' && j < i) j++;
            t = 0;
            for(int k = j; k <= i; k++)
                t = t*10 + str[k] - '0';
            vc.push_back(t);
        }
        else {
            t = 0;
            for(int k = j; k <= i; k++)
                t = t*10 + str[k] - '0';
            vc.push_back(t);
        }
        i = j - 1;
    }
    b = 1;
    ans = 0;
    for(int i = 0; i < vc.size(); i++){
        ans += b*vc[i];
        b*=n;
    }
    printf("%I64d", ans);
    return 0;
}


#pragma warning (disable:4996)
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using LL = int64_t;
using pii = pair<int, int>;
const double PI = 2 * asin(1);

LL g_n, g_cnt;
string s;
deque<LL>dll_num;
deque<deque<LL>>ddll_ans;

void pretreat() {}
void input() {
    getchar();
    getline(cin, s);
    dll_num.clear(), ddll_ans.clear();
    for(int i = 0; i < s.size(); ++i) {
        if('0' <= s[i] && s[i] <= '9') {
            dll_num.push_back(s[i] - '0');
        }
    }
    while(dll_num.front() == 0) {
        dll_num.pop_front();
    }
}
LL get_num(deque<LL>&dn) {
    LL num = 0;
    for(int i = 0; i < dn.size(); ++i) {
        num = num * 10 + dn[i];
    }
    return num;
}
int get_bit(LL num) {
    int cnt = 0;
    while(num > 0) {
        ++cnt;
        num /= 10;
    }
    return cnt;
}
void solve() {
    if(dll_num.empty()) {
        puts("0");
        return;
    }
    g_cnt = get_bit(g_n);
    //cout << g_cnt << endl;
    int i = dll_num.size() - 1;
    deque<LL>tdll;
    while(i >= 0) {
        int j = i;
        tdll.clear();
        if(i >= 0 && dll_num[i] == 0) {
            tdll.clear();
            j = i;
            while(j >= 0 && dll_num[j] == 0) {
                tdll.emplace_back(0);
                --j;
            }
            j = i;
            while(tdll.size() >= g_cnt) {
                ddll_ans.emplace_front();
                tdll.pop_back();
                --j;
            }
            i = j;
            tdll.emplace_front(dll_num[j]);
            if(get_num(tdll) >= g_n) {
                //cout << "j:" << j << endl;
                while(get_num(tdll) >= g_n) {
                    //cout << 0 << endl;
                    ddll_ans.emplace_front();
                    tdll.pop_back();
                    --j;
                }
                i = j;
                //cout << "i: " << i << endl;
            }
        }
        tdll.clear();
        if(i >= 0) {
            while(j >= 0) {
                tdll.push_front(dll_num[j]);
                LL num = get_num(tdll);
                if(num >= g_n) {
                    tdll.pop_front();
                    break;
                } else {
                    --j;
                }
            }
            while(tdll.front() == 0) {
                tdll.pop_front();
                ++j;
            }
            //show(tdll);
            if(!tdll.empty()) {
                ddll_ans.emplace_front(tdll);
            }
            i = j;
        }
    }
    LL ans = 0;
    for(int i = 0; i < ddll_ans.size(); ++i) {
        LL num = get_num(ddll_ans[i]);
        ans = ans * g_n + num;
    }
    cout << ans << endl;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    pretreat();
    while (cin >> g_n) {
        input();
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

const int maxn = 0;
ll n , k , l , mod;
typedef vector < vector < ll > > mat;

mat cr8()
{
	mat a;
	a.resize(2 , vector < ll > (2,1));
	a[1][1] = 0;
	return a;
}

mat mm(mat a , mat b)
{
	mat ans;
	ans.resize(2 , vector < ll > (2,0));
	for(int i=0;i<2;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) ans[i][j] += 1ll * a[i][k] * b[k][j];
	for(int i=0;i<2;i++) for(int j=0;j<2;j++) ans[i][j] %= mod;
	return ans;
}

mat matmul(mat a , int p)
{
	if(p == 1) return a;
	mat b(2 , vector < ll > (2));
	b = matmul(a , p / 2);
	b = mm(b , b);
	mat arr(2 , vector < ll > (2));
	arr = cr8();
	if(p & 1) b = mm(b , arr);
	return b;
}

int powmod(int x , int p)
{
	if(!p) return 1;
	if(p == 1) return x;
	ll ret = powmod(x , p / 2);
	ret = ret * ret;
	if(p & 1) ret = ret * x;
	return ret % mod;
}

int fib(int x)
{
	x += 2;
	mat a(2 , vector < ll >(2));
	a = cr8();
	a = matmul(a , x);
	return a[0][1];
}

int main()
{
	ios_base::sync_with_stdio(2 + 2 - 1 != 3); cin.tie(NULL);
	cin >> n >> k >> l >> mod;
	for(int i=63;i>=0;i--)
	{
		if((1LL << i) & k)
		{
			if(i >= l)
			{
				cout << 0;
				return 0;
			}
			break;
		}
	}
	int f = fib(n) , ff = powmod(2 , n) - f;
	ll answer = 1;
	for(int i=0;i<l;i++)
	{
		if((1LL << i) & k) answer = (answer * ff) % mod;
		else answer = (answer * f) % mod;
	}
	cout << (answer + mod) % mod << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll BinExp(ll bas, ll exp){
   ll ans=1, temp=bas;
    while(exp){
        if(exp&1) ans*=temp;
        temp*=temp;
        exp>>=1;
    }
    return ans;
}

ll BinModExp(ll bas, ll exp, ll mod){
   ll ans=1, temp=bas%mod;
    while(exp){
        if(exp&1) ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        exp>>=1;
    }
    return ans;
}

vvi Multiply_Matrix(vvi A, vvi B, ll mod){
    if(A[0].size()!=B.size()) return vvi();
    vvi C(A.size(), vi(B[0].size(), 0));
    for(int i=0; i<C.size(); i++)
        for(int j=0; j<C[i].size(); j++)
            for(int k=0; k<B.size(); k++)
                C[i][j]=(C[i][j]+(A[i][k]*B[k][j])%mod)%mod;
    return C;
}

vvi Expon_Matrix(vvi A, int exp, ll mod){
    if(exp==1) return A;
    if(exp&1) return Multiply_Matrix(Expon_Matrix(Multiply_Matrix(A, A, mod), exp>>1, mod), A, mod);
    return Expon_Matrix(Multiply_Matrix(A, A, mod), exp>>1, mod);
}

ll Nfibo(ll n, ll mod){
    vvi A;
    A.assign(2,vi(2));
    A[0][0]=1;
    A[0][1]=1;
    A[1][0]=1;
    A[1][1]=0;
    A=Expon_Matrix(A, n, mod);
    return (A[0][0]+A[0][1])%mod;
}
int main(){
    ll n, k, l, m;
    while(scanf("%I64d %I64d %I64d %I64d", &n, &k, &l, &m)!=EOF){
        if(BinExp(2, l)<k){
            printf("0\n");
        }else{
            ll A=BinModExp(2, n, m);
            ll B=Nfibo(n, m);
            ll ans=1;
//          cout<<A<<" "<<B<<endl;
            for(int i=0; i<l;i++){
                if(k&(1LL<<i)){
                    ans*=A-B+m;
                }else{
                    ans*=B;
                }
                ans%=m;
            }
            printf("%I64d\n", ans);
        }
    }
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
long long n,ans,k,mod,l,i,p[100],res1,res2;
struct matrix{
    long long m[2][2];
};
matrix f(matrix a, matrix b){
    int i,j,k;
    matrix c;
    for(i = 0; i < 2; i++){
        for(j = 0; j < 2; j++){
            c.m[i][j] = 0;
            for(k = 0; k < 2; k++)
                c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) % mod;
        }
    }
    return c;
}
matrix getFib(int n){
    matrix a;
    a.m[0][0] = 0; a.m[0][1] = 1;
    a.m[1][0] = 1; a.m[1][1] = 1;
    if(n == 1) return a;
    if(n % 2 == 1)
        return f(a, getFib(n - 1));
    a = getFib(n / 2);
    return f(a, a);
}
int getPower(int n){
    if(n == 0) return 1;
    if(n%2) return (2 * getPower(n - 1)) % mod;
    long long res = getPower(n / 2);
    return (res * res) % mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt","r",stdin);
    cin >> n >> k >> l >> mod;
    for(i = 1, p[0] = 1; i <= l; i++)
        p[i] = p[i - 1] * 2;
    if(k >= p[l]){cout << 0; return 0;}
    matrix s1 = getFib(n);
    res1 = (s1.m[0][1] + s1.m[1][1]) % mod;
    res2 = (getPower(n) - res1 + mod) % mod;
    ans = 1;
    for(i = 0; i < l; i++){
        if(p[i] & k) ans = (ans * res2) % mod;
        else ans = (ans * res1) % mod;
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <algorithm>
#include <cctype>
#include <vector>
#include <queue>
#include <tr1/unordered_map>
#include <cmath>
#include <map>
#include <bitset>
#include <set>
#include <iomanip>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector< ii > vii;
///////////////////////////////UTIL/////////////////////////////////
#define ALL(x) (x).begin(),x.end()
#define CLEAR0(v) memset(v, 0, sizeof(v))
#define CLEAR(v, x) memset(v, x, sizeof(v))
#define COPY(a, b) memcpy(a, b, sizeof(a))
#define CMP(a, b) memcmp(a, b, sizeof(a))
#define REP(i,n) for(int i = 0; i<n; i++)
#define REPP(i,a,n) for(int i = a; i<n; i++)
#define REPD(i,n) for(int i = n-1; i>-1; i--)
#define REPDP(i,a,n) for(int i = n-1; i>=a; i--)
#define pb push_back
#define pf push_front
#define sz size()
#define mp make_pair
/////////////////////////////NUMERICAL//////////////////////////////
#define INF 0x3f3f3f3f
#define EPS 1e-9
/////////////////////////////BITWISE////////////////////////////////
#define CHECK(S, j) (S & (1 << j))
#define CHECKFIRST(S) (S & (-S))
#define SET(S, j) S |= (1 << j)
#define SETALL(S, j) S = (1 << j)-1
#define UNSET(S, j) S &= ~(1 << j)
#define TOOGLE(S, j) S ^= (1 << j)
///////////////////////////////64 BITS//////////////////////////////
#define LCHECK(S, j) (S & (1ULL << j))
#define LSET(S, j) S |= (1ULL << j)
#define LSETALL(S, j) S = (1ULL << j)-1ULL
#define LUNSET(S, j) S &= ~(1ULL << j)
#define LTOOGLE(S, j) S ^= (1ULL << j)
//__builtin_popcount(m)
//scanf(" %d ", &t);
//L[i]=L[i/2]+1;

typedef vector<vector<ull> > matrix;
ull MOD, n, m, l, k;
const int K = 3;

// computes A * B
matrix mul(matrix A, matrix B)
{
    matrix C(K, vector<ull>(K));
    REP(i, K) REP(j, K) REP(z, K)
        C[i][j] = (C[i][j] + A[i][z] * B[z][j]) % MOD;
    return C;
}

// computes A ^ p
matrix pow(matrix A, int p)
{
    if (p == 1)
        return A;
    if (p % 2)
        return mul(A, pow(A, p-1));
    matrix X = pow(A, p/2);
    return mul(X, X);
}

// returns the N-th term of Fibonacci sequence
ull oneComb(ull N){
    if(N == 0) return 0ULL;
    if(N <= 2) return 1ULL;
    if(N == 3) return 3ULL;

    vector<ull> F1(K);
    F1[0] = 3;
    F1[1] = 1;
    F1[2] = 4;

    matrix T(K, vector<ull>(K));
    T[0][0] = T[0][1] = T[0][2] = 1;
    T[1][0] = 1; T[1][1] = T[1][2] = 0;
    T[2][0] = T[2][1] = 0; T[2][2] = 2;

    T = pow(T, N-3);

    ull res = 0;
    REP(i, K)
        res = (res + T[0][i] * F1[i]) % MOD;
    return res;
}

ull fastExp(ull base, ull p, ull m){
    if(p == 0ULL) return 1ULL;
    else if(p == 1ULL) return base%m;
    else{
        unsigned long long res = fastExp(base, p/2ULL, m);
        res = (res*res)%m;
        if(p%2ULL == 1ULL) res = (res*base)%m;
        return res;
    }
}

int main(){
    cin >> n >> k >> l >> MOD;
    ull one = oneComb(n);
    ll zero = ((ll) fastExp(2, n, MOD)) - ((ll) one);
    if(zero < 0LL) zero += MOD;
    ull ans = ((log2((double) k) > ((double) l)))? 0ULL : 1ULL;
    REP(i, l){
        if(k&(1ULL << i)) ans = (ans * one)%MOD;
        else ans = (ans * zero)%MOD;
    }
    cout << ans << endl;
}


#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <math.h>
#include <memory.h>

using namespace std;

#define lint long long

#define ss stringstream
#define sz size()
#define pb push_back
#define mp make_pair

#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)

int main() {
	__int64 q,i,j;
	scanf("%I64d",&q);
	if (q < 3) { printf("1\n0\n"); return 0; }
	for(i=2;i*i<=q;i++) if (q % i == 0) break;
	if (q % i != 0) { printf("1\n0\n"); return 0; }
	q /= i;
	for(j=i;j*j<=q;j++) if (q % j == 0) break;
	if (q % j != 0) { printf("2\n"); return 0; }
	if (i*j == q) { printf("2\n"); return 0; }
	printf("1\n%I64d\n",j*i);
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
#include <vector>
#include <sstream>
#include <algorithm>
#include <queue>
//#include <iomanip>
#include <deque>
//#include <hash_map>
#include <time.h>

using namespace std;

const double PI = 3.1415926535897932384626433832795;

#define fori(i,n) for(int i = 0; i < (n); i++)
#define MP(a,b) make_pair(a,b)

typedef pair<int,int> ii;

//#ifdef _MSC_VER
const string IN_NAME = "input.txt";
const string OUT_NAME = "output.txt";
//#else
//const string NAME = "tricir";
//const string IN_NAME = NAME + ".in";
//const string OUT_NAME = NAME + ".out";
//#endif

#define sz(x) ((int)((x).size()))
#define all(v) (v).begin(), (v).end()
template<class T> T sqr(const T &x) {return x*x;}
typedef long long ll;

const double eps=1e-12;

ll n;

map<ll, ll> cnt;

int main()
{
#ifndef ONLINE_JUDGE
    freopen(IN_NAME.c_str(), "r", stdin);
    freopen(OUT_NAME.c_str(), "w", stdout);
#endif
    //-----------------------------------------------------------------------------------------------------------------
    //cout << sqr(1000000007LL)*2 << endl;
    cin >> n;
    ll sum = 0;
    while (n % 2 == 0)
    {
        cnt[2]++;
        sum++;
        n /= 2;
    }
    while (n % 3 == 0)
    {
        cnt[3]++;
        sum++;
        n /= 3;
    }
    for (int i = 6; i <= 32000000; i+=6)
    {
        while (n % (i-1) == 0)
        {
            cnt[i-1]++;
            sum++;
            n /= (i-1);
        }
        while (n % (i+1) == 0)
        {
            cnt[i+1]++;
            sum++;
            n /= (i+1);
        }
    }

    if (sum < 2)
    {
        cout << 1 << endl << 0;
        return 0;
    }
    if (sum == 2)
    {
        cout << 2;
        return 0;
    }
    map<ll,ll> mp;
    int x = 2;
    for (map<ll,ll>::iterator i = cnt.begin(); i != cnt.end(); i++)
    {
        while (x && i->second)
        {
            i->second--;
            x--;
            mp[i->first]++;
        }
    }
    ll res = 1;
    for (map<ll,ll>::iterator i = mp.begin(); i != mp.end(); i++)
        for (int j = 0; j < i->second; j++)
            res *= i->first;
    cout << 1 << endl << res;
}


#include<fstream>
#include<iostream>
#include<vector>
#include<sstream>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iomanip>
#include<cmath>

using namespace std;

int main ()
{
	//ifstream cin ("input.txt");
	//ofstream cout ("output.txt");
	long long q;
	cin >> q;
	vector < long long > divisors;
	long long k = 2;
	bool flag = false;
	while ( k <= q )
	{
		if ( k * k > q && flag == false )
			break;
		while ( q % k == 0 )
		{
			divisors.push_back ( k );
			q /= k;
			flag = true;
		}
		if ( divisors.size () > 2 )
			break;
		++k;
	}
	if ( divisors.size () != 2 )
	{
		if ( divisors.size () == 1 && divisors [ 0 ] == q )
			cout << 2;
		else
		{
			cout << 1 << endl;
			if ( divisors.size () == 1 || divisors.size () == 0 )
				cout << 0;
			else
				cout << divisors [ 0 ] * divisors [ 1 ];
		}
	}
	else
		cout << 2;
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:64000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <memory.h>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#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 pb push_back
#define mp make_pair
#define X first
#define Y second
#define y1 YYYYYYYYYYYY1
#define all(a) (a).begin(), (a).end()
#define Abs(x) (((x) >= 0) ? (x) : (-(x)))

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;

map<int64, bool> d;

bool solve(int64 n) {
    if (d.count(n)) return d[n];

    bool ans = false;
    int num = 0;
    for(int64 i = 2; i*i <= n; i++)
        if (n % i == 0) {
            num++;
            if (!solve(i)) ans = true;
            if (!solve(n/i)) ans = true;
        }

    if (num == 0) ans = true;
    return d[n] = ans;
}

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

    int64 n;
    cin >> n;

    if (solve(n)) {
        cout << 1 << endl;
        for(int64 i = 2; i*i <= n; i++)
            if (n % i == 0) {
                if (!solve(i)) {
                    cout << i << endl;
                    return 0;
                }

                if (!solve(n/i)) {
                    cout << n / i << endl;
                    return 0;
                }
            }

        cout << 0 << endl;
    } else {
        cout << 2 << endl;
    }

    return 0;
}


//------------------------ Un, Deux, Trois, Quatre, Cinq -----------------------//
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

// Shorthands
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll int
#define ld long double
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define vtll vector<tll>
#define mt make_tuple
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>=b; i--)
#define vect(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define all(a) a.begin(),a.end()
#define sortall(a) sort(a.begin(),a.end());
#define PI acos(-1)

// Debug
#define printv(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
#define pout(p) cout<<"("<<p.ff<<","<<p.s1<<")"<<" ";
#define printvp(a) rep(i,0,a.size()) cout<<"("<<a[i].ff<<","<<a[i].ss<<")"<<" "; cout<<endl;
#define tout(t) cout<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")"<<endl;
#define trace(x) cout<< '>' << #x << ':' << (x) << "\n";
#define trace2(x,y) cout<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n";
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n";
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n";

// Constants
// const ll INF = 1e18;
const ll mod = 998244353;
const ll MOD = 1e9 + 7;
const ll mxN = 1e6 + 5;

// Input/Output File
void fileio()
{
    #ifndef ONLINE_jUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
//-------------------------- Six, Sept, Huit, Neuf, Dix ------------------------//

const ll k = 30;
const ll N = 1e6;

ll a[k+1][N+1];
map<ll,ll> mp;

void solve()
{
    ll n, m; cin >> n >> m;

    memset(a, 0, sizeof(a));
    rep(i,1,k+1)
        rep(j,1,m+1) a[i][j] = i*j;

    vll c(31, 0);
    rep(i,1,k+1)
    {
        rep(j,1,m+1) mp[a[i][j]]++;
        c[i] = mp.size();
    }

    ll ans = 1;
    vll vis(n+1, 0);
    rep(i,2,n+1)
    {
        if(!vis[i])
        {
            ll x = i;
            ll t = 0;
            while(x <= n)
            {
                t++;
                vis[x] = 1;
                x *= i;
            }
            ans += c[t];
        }
    }
    cout << ans << endl;
}

int main()
{
    fastio; // fileio();
    // int tc; cin >> tc; while(tc--)
    solve();
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;

#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//insert,find_by_order,order_of_key,lower_bound,upper_bound;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::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 deb(...)
#endif

//////////////////////////////code//////////////////////////////

const int N = 1e6 + 5;

int vis[N];
gp_hash_table<int,bool>fr;
int ans[N];

void solve()
{

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

    vis[1] = 1;

    vi mxpw;
    int mxval = 0;

    for(int i = 2;i <= n; i++)
    {
            if(vis[i])
                continue;

            int st = i;
            int cnt = 0;

            while(st <= n)
            {
                    vis[st]++;
                    st *= i;
                    cnt++;
            }

            mxpw.pb(cnt);
            mxval = max(mxval , cnt);
         //   deb(cnt);
    }

    for(int i = 1;i <= mxval; i++)
    {

            ans[i] = ans[i - 1];

            for(int j = 1;j <= m; j++)
            {
                 if(fr[j * i] == 0)
                 {
                            fr[j * i] = 1;
                            ans[i]++;
                 }
            }
    }

    int fin = 1;

    for(auto x : mxpw)
        fin += ans[x];

    db(fin)

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

     #ifndef ONLINE_JUDGE
     freopen("INP.txt", "r", stdin);
     freopen("out.txt", "w", stdout);
     #endif

    int t = 1;
   //cin >> t;

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values


#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstdio>
#include<unordered_map>
#include <cstring>
using namespace std;
const int N = 1e6 + 5;   //remember to modify the range of the data!!
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
typedef long long ll;

int n, m, t;
ll vis[N], f[N];

unordered_map <int, int> mp;
int main(void)
{
    cin >> n >> m;
    ll ans =  0;
    for(int i = 1; i <= 21; i++)
    {
        for(int j = 1; j <= m; j++)
            mp[i * j] = 1;
        f[i] = mp.size();
    }
    for(int i = 2; i <= n; i++)
    {
        if(vis[i])
            continue;
        ll prod = 1;
        int cnt = 0;
        for(int j = 1; j <= m && prod * i <= n; j++)
        {
            prod *= i;
            vis[prod] = 1;
            cnt++;
        }
        ans += f[cnt];
    }
    cout << ans + 1;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstdio>
#include<unordered_map>
#include <cstring>
using namespace std;
const int N = 1e6 + 5;   //remember to modify the range of the data!!
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
typedef long long ll;

ll n, m, t;
int vis[N];

unordered_map <int, int> mp;
int main(void)
{
    cin >> n >> m;
    ll ans =  0;
    for(int i = 2; i <= n; i++)
    {
        if(vis[i])
            continue;
        ll prod = 1;
        mp.clear();
        for(int j = 1; j <= m && prod * i <= n; j++)
        {
            prod *= i;
            vis[prod] = 1;
            for(int k = 1; k <= m; k++)
                mp[j * k] = 1;
        }
        ans += mp.size();
    }
    cout << ans + 1;

    return 0;
}


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

int main()
{
	long long n,m,k,i,j;
	cin>>n>>m>>k;
	m=m-n;
	if(m==0)
	{
		cout<<"1"<<endl;
		return 0;
	}
	long long a[n+1],x,l=0;
	for(i=k,j=k;i>=1;i--,j++)
	{
		a[i]=j-k;
		a[j]=j-k;
	}
	for(j=k;j<=n;j++)
		a[j]=j-k;

	for(i=1;i<=n;i++)
		l+=a[i];
	l=(l+m)/n;;
	cout<<l+1<<endl;
}


#include <bits/stdc++.h>
#include<deque>
#define jio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
//#define mp make_pair
#define pb push_back
#define lld long long int
#define clr clear()
#define ff first
#define ss second
//#define N 1000005
//#define M 1000
#define endl '\n'
#define c_s_b() __builtin_popcount()

#define sze 10000009
#define pii pair<int,int>
#define big 100009
#define int long long

using namespace std;
int n,m,k;
int minm_val;

bool check(int val,int h){
   bool ok=true;

   int i=k-1;
   int j=k+1;
   vector<int>arr(n,0);
   int val1=val-1;
   for(int z=i;z>=0;z--){
       arr[z]=max((ll)0,val1);
       val1=val1-1;
   }
   val1=val-1;
   for(int z=j;z<n;z++){
       arr[z]=max((ll)0,val1);
       val1=val1-1;
   }

   arr[k]=val;
  /* for(int i=0;i<n;i++){
      cout<<arr[i]<<" ";
   }
   cout<<endl;  */
   int sum=0;
   for(int i=0;i<n;i++){
      sum+=arr[i];
   }
   if(sum<=minm_val){
    return true;
   }
   else return false;

}

int bs(){
  int h=m;

  int l=0;
  //cout<<h<<endl;
  int mid;
  int ans=l;
  while(l<=h){
       mid=l+(h-l)/2;
       if(check(mid,h)){
           l=mid+1;
           ans=mid;
       }
       else{
          h=mid-1;

       }

  }
  return ans;

}

int32_t main(){
   jio;
 // int t;
 // cin>>t;
 // while(t--){
   cin>>n>>m>>k;
   if(n==1){
       cout<<m<<endl;
        return 0;
   }
   if(n==2){
       cout<<ceil((double)m/2)<<endl;
       return 0;
   }

   m=m-n;
   if(m==0){
    cout<<1<<endl;
    return 0;
   }
   k--;
   minm_val=m;
   cout<<bs()+1<<endl;
   //cout<<bs()+1<<endl;

    return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<math.h>
#include<set>
#include<cctype>
#include<bitset>
#include<map>
using namespace std;
int pel=0;
vector<long long>v;
void pellow(long long pos){

	if (pel == 0 || pos == v.size() || pos < 0)
		return;
	if (pos>0 && pos < v.size() - 1){

		if (v[pos] + 1>v[pos - 1] + 1){
			pellow(pos-1);
		}

		if (v[pos] + 1 > v[pos + 1] + 1){
			pellow(pos+1);
		}
		if (pel != 0){
			v[pos]++;
			pel--;
			return;
		}

	}
	if (pos == 0){
		if (v[pos] + 1 > v[pos + 1] + 1){
			pellow(pos+1);
		}
		if (pel != 0){
			v[pos]++;
			pel--;
			return;
		}
	}
	if (pos == v.size()-1){

		if (v[pos] + 1>v[pos - 1] + 1){
			pellow(pos-1);
		}

		if (pel != 0){
			v[pos]++;
			pel--;
			return;
		}
	}

}
void main(){
	long long x, y, z,c,s=1;
	scanf("%I64d %I64d %I64d", &x,&y,&z);

	pel = y-x;
	c = ( x * ( x - 1)) / 2;
	if ((pel - c) / x > 0){
		s += ((pel - c) / x);
		pel -= (s-1)*x;
	}
	v = vector<long long>(x, s);
	while (pel != 0){
		pellow(z - 1);
	}
	printf("%I64d", v[z - 1]);

}


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

long long n,m,k;

bool f(long long x)
{
	vector<int> a(n+1);
	a[k]=x;
	for (int i=k+1;i<=n;i++)
	{
		a[i]=max(1,a[i-1]-1);
	}
	for (int i=k-1;i>=1;i--)
		a[i]=max(1,a[i+1]-1);
	long long sum=0;
	for (int i=1;i<=n;i++)
		sum+=a[i];
	return sum<=m;
}

int main()
{
	cin>>n>>m>>k;
	if (n==1)
	{
		cout<<m;
		return 0;
	}
	long long l=0,r=m;
	while (r-l>1)
	{
		long long mid=(l+r)/2;
		if (f(mid))
			l=mid;
		else
			r=mid;
	}
	cout<<l;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007 // 1e9+7
#define inf 1e18
using namespace std;

ll neighbour[300000];
ll G[5213][5213];
ll A[300000][20];
ll my_ST[300000][2];

int main(){

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

    ll n,last_digit,second_last_digit,num,ans;

    cin>>n;

    if(n>=0){
        cout<<n<<"\n";
        return 0;
    }

    num = abs(n);
    last_digit = num%10;
    num /= 10;
    second_last_digit = num%10;

    if(last_digit >= second_last_digit){
        n = abs(n);
        n -= (last_digit);
        n /= 10;
        n *= -1;
    }
    else if(second_last_digit > last_digit){
        n = abs(n);
        n -= (second_last_digit * 10);
        n /= 10;
        n += last_digit;
        n *= 1;
    }

    cout<<n<<"\n";

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;

char buffer [1000000007];

int main()
{
    gets(buffer);

    int len = strlen(buffer);

    if(buffer[0] == '-')
    {
        if(buffer[len-2] > buffer[len-1])
        {
            buffer[len-2] = buffer[len-1];
            buffer[len-1] = '\0';
        }
        else
        {
            buffer[len-1] = buffer[len-2];
            buffer[len-1] = '\0';
        }

        if(len-1 == 2)
        {
            buffer[len-3] = buffer[len-2];
            buffer[len-2] = 0;
        }
    }

    printf("%s",buffer);

    return 0;
}


#include"stdio.h"
#include<string.h>
#include"math.h"
void main()
{
	char max;
	char a[10000000004];
	gets(a);
	int k;
	max = a[1];
	if (a[0] != '-')
		puts(a);
	else
	{
		for (int i = 1; i < strlen(a); i++)
		{
			if (max < a[i])
			{
				max = a[i];
				k = i;
			}
		}
	}
	for (int i = k; i < strlen(a)-1; i++)
	{
		a[i] = a[i + 1];
	}
	puts(a);
}


#include<bits/stdc++.h>
using namespace std;
char a[1000000000];
int main()
{int n;
 cin>>a;
 n=strlen(a);
 if(a[0]!='-')
  {
   cout<<a;
   return 0;
  }
 if(n==3&&a[1]=='1'&&a[2]=='0')
  {cout<<"0";
   return 0;
  }
 int maxn=max(a[n-1],a[n-2]);
 for(int i=0;i<n;i++)
   {if(a[i]!=maxn)
    cout<<a[i];
   }
   return 0;
}


#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>

#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

using namespace std;

typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <string> vs;

typedef long long LL; //NOTES:int64
typedef unsigned long long ULL; //NOTES:uint64
typedef unsigned uint;

const double pi = acos(-1.0); //NOTES:pi
const double eps = 1e-11; //NOTES:eps
const int MAXI = 0x7fffffff;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const char dz[] = "SENW";

#define rep(i,n)        for (int i=0;i<n;i++)
#define loop(i,a,b)     for (int i=(a),_b=(b); i<_b; i++)
#define rloop(i,b,a)    for (int i=(b)-1,_a=(a); i>=_a; i--)
#define Reset(a,b)      memset((a),(b),sizeof(a))

#define endline         putchar('\n')
#define space           putchar(' ')
#define EXIT(x)         {cout << x;return 0;}

#define fi              first
#define se              second
#define pb              push_back

#define S(x)            scanf("%d",&x);
#define input freopen("input.txt","r",stdin);
#define deb(i,a,n) for(i=0;i<n;i++){cout<<a[i]<<" ";}
#define db(x,y)          printf("%d %d\n",x,y);
#define debug(args...)  {dbg,args; cerr<<endl;}
#define dline           cerr<<endl
#define INF             (int)1e9
#define LINF            (long long)1e18
#define EPS             1e-9
#define maX(a,b)        ((a)>(b)?(a):(b))
#define miN(a,b)        ((a)<(b)?(a):(b))
#define abS(x)          ((x)<0?-(x):(x))
#define mod             1000000007

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {
        cerr<<v<<" ";
        return *this;
    }
} dbg;

void debugarr(int * arr,int n)
{
    cout<<"[";
    for(int i=0;i<n;i++)
        cout<<arr[i]<<" ";
    cout<<"]"<<endl;
}

int a[100010];
char str[100010];
int main()
{
    #ifndef ONLINE_JUDGE
        input;
    #endif
    int i,j,k,l,m,t,d;
    LL n,s;
    cin>>n;
    if(n%3==0)
        {
            if(n%9!=0)
                s=n/9+1;
            else if(n%27!=0)
                s=n/27+1;
            else
                s=1;
            cout<<s<<endl;

        }
    else
    {
        n=n/3+1;
    cout<<n<<endl;
    }

    return (0);
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
using namespace std;
template<class T> inline T sqr(T x) { return x * x; }
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<LD, LD> PDD;
#define MP make_pair
#define PB push_back
#define sz(x) ((int)(x).size())
#define clr(ar,val) memset(ar, val, sizeof(ar))
#define istr stringstream
#define FOR(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const LL LINF = INF * 1ll * INF;
const double PI = acos(-1.0);

using namespace std;

LL dp[105];

int main(void){
#ifndef ONLINE_JUDGE
      //freopen("/home/xing89qs/桌面/data.in","r",stdin);
#endif
	LL n;
	cin>>n;
	for(int i = 3;i<n;i*=3){
		if(n%i!=0){
			cout<<(n+i-1)/i<<endl;
			return 0;
		}
	}
	cout<<1<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
using namespace std;
template<class T> inline T sqr(T x) { return x * x; }
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<LD, LD> PDD;
#define MP make_pair
#define PB push_back
#define sz(x) ((int)(x).size())
#define clr(ar,val) memset(ar, val, sizeof(ar))
#define istr stringstream
#define FOR(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const LL LINF = INF * 1ll * INF;
const double PI = acos(-1.0);

using namespace std;

LL dp[105];

int main(void){
#ifndef ONLINE_JUDGE
      //freopen("/home/xing89qs/桌面/data.in","r",stdin);
#endif
	LL n;
	cin>>n;
	LL ans = 0;
	if(n%3!=0){
		ans = (n+2)/3;
		cout<<ans<<endl;
	}else if(n%9!=0){
		ans = (n+8)/9;
		cout<<ans<<endl;
	}else if(n%27!=0){
		ans = (n+26)/27;
		cout<<ans<<endl;
	}
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=b;i++)
const int N = 111111;
const int M = 222222;
int main() {
    long long n;
    scanf("%I64d",&n);
    int i = 1;
    for(;;) {
        i *= 3;
        if(i > n) break;
        if(n % i != 0) break;
    }
    if(i > n) {
        puts("1");
    } else {
        printf("%I64d\n",n/i + 1);
    }
    return 0;
}


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

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;
#define INF (1ll<<40)

int lucky(ll x){
    int ans = 0;
    while(x > 0){
        if(x%10 == 4 || x%10 == 7) ans++;
        x /= 10;
    }
    return ans;
}

map <pair <ll, int>, int> mp1;

ll func1(ll low, int x){
    int i;
    ll ans = INF;

    if(x < 0) return INF;

    pair <ll, int> st = make_pair(low,x);
    if(mp1.find(st) != mp1.end()) return mp1[st];

    if(low <= 3){
        if(x == 0) return low;
        ans = 0;
        REP(i,x) ans = ans * 10 + 4;
        return mp1[st] = ans;
    }

    REP(i,10){
        if(i < low%10){
            ll tmp = func1(low/10+1,x-lucky(i));
            ans = min(ans,tmp*10+i);
        } else {
            ll tmp = func1(low/10,x-lucky(i));
            ans = min(ans,tmp*10+i);
        }
    }

    return mp1[st] = ans;
}

ll func2(ll low, int x, int y){
    int i;
    ll ans = INF;

    if(x < 0 || y < 0) return INF;

    REP(i,9) if(y - x == lucky(i+1) - lucky(i)){
        if(i < low%10){
            ll tmp = func1(low/10+1,x-lucky(i));
            ans = min(ans,tmp*10+i);
        } else {
            ll tmp = func1(low/10,x-lucky(i));
            ans = min(ans,tmp*10+i);
        }
    }

    return ans;
}

ll func3(ll low, int x, int y){
    ll ans = INF;

    int i;
    for(i=0;;i++){
        ll tmp = func2(low,x,y);
        int j;
        REP(j,i) tmp = min(tmp * 10 + 9, INF);
        ans = min(ans,tmp);

        if(low == 0) return ans;
        low /= 10;
    }
}

ll func(ll low, ll high){
    if(high/10 - low/10 >= 2){
        ll tmp = func(low/10,high/10);
        return tmp * 10 + low % 10;
    }

    ll ans = INF;

    int i,j,k;

    REP(i,10){
        j = i + (int)(high - low);
        if(j >= 20) continue;

        int x = lucky(low) - lucky(i);
        int y = 0;
        if(j >= 10) y = lucky(high) - lucky(j-10);

        bool failed = false;
        for(k=i;k<=j;k++){
            int tmp1 = lucky(low+k-i);
            int tmp2 = ((k >= 10) ? (y + lucky(k-10)) : (x + lucky(k)));
            if(tmp1 != tmp2){
                failed = true;
                break;
            }
        }
        if(failed) continue;

        ll small = (low - i + 10) / 10;
        if(j >= 10){
            ll tmp = func3(small,x,y);
            ans = min(ans,tmp*10+i);
        } else {
            ll tmp = func1(small,x);
            ans = min(ans,tmp*10+i);
        }
    }

    return ans;
}

int main(void){
    ll a,d;
    cin >> a >> d;
    ll ans = func(a,a+d-1);
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const ll INF = 1000000000000000000;
const ll BLOK = 1000;

int F(ll x)
{
    int il = 0;
    while (x != 0)
    {
        il += (x % 10 == 4) || (x % 10 == 7);
        x /= 10;
    }
    return il;
}

void KMP(vector<int> s, int L, vector<int>& starty)
{
    s.push_back(0);
    for (int i = s.size() - 1; i >= 1; --i)
        s[i] = s[i - 1];
    vector<int> ps(s.size());
    ps[1] = 0;
    for (int i = 2; i < s.size(); ++i)
    {
        int w = ps[i - 1];
        while (w > 0 && s[w + 1] != s[i])
            w = ps[w];
        if (w == 0)
            ps[i] = (s[1] == s[i]) ? 1 : 0;
        else
            ps[i] = w + 1;
        if (ps[i] == L)
        {
            int nr = i - L + 1 - (L + 2);
            if (s.size() == 2 * BLOK + L + 2)
            {
                if (nr < 1000 && nr + L - 1 >= 1000)
                    starty.push_back(nr);
            }
            else
                starty.push_back(nr);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll a, b, l;
    ll A, B, L;
    cin >> a >> l;
    b = a + l - 1;
    A = a / BLOK;
    B = b / BLOK;
    L = B - A + 1;
    if (L >= 3 || (L == 2 && (a % BLOK == 0 || (b + 1) % BLOK == 0)) || (L == 1 && a % BLOK == 0 && (b + 1) % BLOK == 0))
    {
        vector<int> s(12000000 + L + 1);
        for (int i = 0; i < L; ++i)
            s[i] = F(BLOK * (i + A));
        s[L] = 100;
        for (int i = 0; i < 12000000; ++i)
            s[i + L + 1] = F(BLOK * i);
        vector<int> starty;
        KMP(s, L, starty);
        for (int i = 0; i < starty.size(); ++i)
        {
            if (starty[i] > A)
            {
                cout << starty[i] * BLOK + a % BLOK;
                return 0;
            }
        }
    }
    else
    {
        vector<int> s(12000000);
        for (int i = 0; i < 12000000; ++i)
            s[i] = F(BLOK * i);
        vector<int> wzo(l);
        for (int i = 0; i < l; ++i)
            wzo[i] = F(i + a);
        vector<int> pod(BLOK);
        for (int i = 0; i < BLOK; ++i)
            pod[i] = F(i);
        ll odp = INF;
        for (int i = 0; i <= 10; ++i)
        {
            for (int j = 0; j <= 10; ++j)
            {
                vector<int> t(2 * BLOK + l + 1);
                for (int k = 0; k < l; ++k)
                    t[k] = wzo[k];
                t[l] = 100;
                for (int k = 0; k < BLOK; ++k)
                    t[k + l + 1] = pod[k] + i;
                for (int k = 0; k < BLOK; ++k)
                    t[k + BLOK + l + 1] = pod[k] + j;
                vector<int> starty;
                KMP(t, l, starty);
                if (starty.size() == 0)
                    continue;
                ll odp2 = INF;
                for (int k = A; odp2 == INF && k < 12000000 - 1; ++k)
                    if (s[k] == i && s[k + 1] == j)
                        for (int m = 0; m < starty.size(); ++m)
                            if (k * BLOK + starty[m] > a)
                                odp2 = min(odp2, k * BLOK + starty[m]);
                odp = min(odp, odp2);
            }
        }
        for (int i = 0; i <= 10; ++i)
        {
            vector<int> t(BLOK + l + 1);
            for (int j = 0; j < l; ++j)
                t[j] = wzo[j];
            t[l] = 100;
            for (int j = 0; j < BLOK; ++j)
                t[j + l + 1] = pod[j] + i;
            vector<int> starty;
            KMP(t, l, starty);
            if (starty.size() == 0)
                continue;
            ll odp2 = INF;
            for (int j = A; odp2 == INF && j < 12000000; ++j)
                if (s[j] == i)
                    for (int k = 0; k < starty.size(); ++k)
                        if (j * BLOK + starty[k] > a)
                            odp2 = min(odp2, j * BLOK + starty[k]);
            odp = min(odp, odp2);
        }
        cout << odp;
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

typedef unsigned __int64 ull;

const ull P = 10000000007;

ull W[300001] = {1};
int num[300001];
ull block[6][10000];  //某一块的hash值
ull all[300001];  //前若干块的hash值
ull w[10001] = {1};
bool mark[6];
vector<int> v[6];

ull oneblock(int type,int from,int len) {
ull x = block[type][from + len - 1];
    while (from < 0) ;
    if (from) {
        x -= block[type][from - 1] * w[len];
    }
    return x;
}

ull blocks(ull from,ull len) {
ull x = all[from + len - 1];
    if (from) {
        x -= all[from - 1] * W[len];
    }
    return x;
}

ull get(ull from, ull len) {
ull fromid = from / 10000, c, in = from % 10000, to,toid,i,x;

    if (in + len <= 10000) {  //一块内
        return oneblock(num[fromid], in, len);
    }
    to = from + len - 1;
    toid = to / 10000;
    x = oneblock(num[fromid], in, 10000 - in) * w[len + in - 10000] + oneblock(num[toid], 0, i = to % 10000 + 1);
    c = toid - fromid;
    while (c == 0);
    if (c > 1) {
        x += blocks(fromid + 1, c - 1) * w[i];
    }
    return x;
}

void run() {
int from, len,k,may,j;
ull i, x, y, want;
    scanf("%d%d",&from,&len);
    want = get(from, len);
    for (i = from / 10000, x = i * 10000; i <= 200000; ++i,x += 10000) {
        if (!mark[k = num[i]]) {
            mark[k] = true;
            for (j = 0; j < 10000; ++j) {
                may = 10000 - j;
                if (may > len) {
                    may = len;
                }
                if (oneblock(k,j,may) == get(from, may)) {
                    v[k].push_back(j);
                }
            }
        }
        for (j = 0; j < v[k].size(); ++j) {
            if (((y = x + v[k][j]) > from)  && (get(y, len) == want)) {
                printf("%I64u\n",y);
                return;
            }
        }
    }
    while (1);

}

int main() {
ull x;
int i,j,k;

    for (i = 1; i <= 300000; ++i) {   //0...9999 10000...19999
        num[i] = num[i / 10];
        j = i % 10;
        if ((j == 4) || (j == 7)) {
            ++num[i];
        }

    }
    for (i = 0; i < 6; ++i) {
        x = 0;
        for (j = 0; j < 10000; ++j) {
            x *= P;
            x += num[j];
            x += i;
            block[i][j] = x;
        }
    }
    for (i = 1; i <= 10000; ++i) {
        w[i] = w[i - 1] * P;
    }
    all[0] = block[0][9999];
    for (i = 1; i <= 300000; ++i) {
        W[i] = W[i - 1] * w[10000];
        all[i] = all[i - 1] * w[10000] + block[num[i]][9999];
    }
    run();

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 19;
ll pw10[N];

inline int countLucky(ll n){
	int ret = 0;
	while(n){
		if(n%10 == 4 || n%10 == 7)ret++;
		n /= 10;
	}
	return ret;
}

int digCnt(ll n){
	int ret = 0;
	while(n){
		ret++;
		n /= 10;
	}
	return ret;
}

vector<int> dig;
ll mem[N][N], aa;

ll func(int ind, int till, int req, int flg, ll cur, ll sf){
	if(ind == till){
		if(req != 0)return -2;
		if(flg && cur + sf <= aa)return -2;
		// cout<<cur + sf<<endl;
		return cur + sf;
	}
	if(!flg){
		if(mem[ind][req] != -1)return mem[ind][req];
	}
	ll ret = -2;
	for(int d = 0; d <= 9; d++){
		if(flg && dig[ind] > d)continue;
		if(req == 0 && (d == 4 || d == 7))continue;
		ll tmp = func(ind - 1, till, req - ((d == 4 || d == 7)?1:0), flg&&(d == dig[ind]), cur + pw10[ind]*d,  sf);
		if(tmp != -2){
			if(ret == -2)ret = tmp;
			else ret = min(ret, tmp);
		}
	}
	if(!flg)mem[ind][req] = ret;
	return ret;
}

ll compute(ll lo, ll hi){
	assert(hi - lo + 1 < 10);
	int len = hi - lo + 1;
	vector<int> v(len);
	for(ll i = lo; i <= hi; i++){
		v[i - lo] = countLucky(i);
	}
	if(lo <= 10){
		for(int b = lo + 1; b <= 100; b++){
			bool flg = true;
			for(int i = 0; i < len; i++){
				if(countLucky(b + i) != v[i]){
					flg = false;
					break;
				}
			}
			if(flg)return b;
		}
		assert(false);
	}
	int dc = digCnt(lo);
	ll ret = pw10[dc] + lo;
	dig.clear();
	for(int i = 0; i < dc; i++){
		dig.push_back((lo/pw10[i])%10);
	}
	aa = lo;
	for(int d = 0; d < 10; d++){
		for(int n9 = 0; n9 + 2 <= dc; n9++){
			for(int k = 0; k < 9; k++){
				int cnt = countLucky(d) + countLucky(k);
				if(cnt > v[0])continue;
				ll suf = k;
				for(int i = 0; i < n9; i++){
					suf = suf*10 + 9;
				}
				suf = suf*10 + d;
				bool flg = true;
				for(int i = 0; i < len; i++){
					if(v[i] - countLucky(suf + i) != v[0] - cnt){
						flg = false;
						break;
					}
				}
				if(!flg)continue;
				memset(mem, -1, sizeof(mem));
				ll tmp = func(dc - 1, n9 + 1, v[0] - cnt, 1, 0, suf);
				if(tmp != -2)ret = min(ret, tmp);
			}
		}
	}
	for(int d = 0; d < 10; d++){
		for(int n9 = 0; n9 + 2 <= dc; n9++){
			for(int k = 0; k < 9; k++){
				int cnt = countLucky(d) + countLucky(k);
				if(cnt > v[0])continue;
				ll suf = k;
				for(int i = 0; i < n9; i++){
					suf = suf*10 + 9;
				}
				suf = suf*10 + d;
				bool flg = true;
				for(int i = 0; i < len; i++){
					if(v[i] - countLucky(suf + i) != v[0] - cnt){
						flg = false;
						break;
					}
				}
				if(!flg)continue;
				memset(mem, -1, sizeof(mem));
				ll tmp = func(dc - 1, n9 + 1, v[0] - cnt, 0, pw10[dc], suf);
				if(tmp != -2)ret = min(ret, tmp);
			}
		}
	}

	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(32);

	pw10[0] = 1;
	for(int i = 1; i < N; i++){
		pw10[i] = pw10[i - 1]*10;
	}
	ll a, l;
	cin>>a>>l;
	ll pw = 1;
	while(pw*10 <= l)pw *= 10;
	ll ans = compute(a/pw, (a + l - 1)/pw)*pw + (a%pw);
	cout<<ans<<'\n';

	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,dp[1000005];

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) dp[i]=2147483647;
	for (int i=1;i<=m;i++)
		for (int j=1;j<=n&&j<=i;j++)
			dp[i]=min(dp[i],dp[i-j]+1);
	printf("%d",dp[m]);
	return 0;
}


/*
 * Created by Dipta Das on 22-11-2018
 * Title:
 * Problem Link:
 * Editorial:
 * Solution:
 * Comments:
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

ll numCoins, sum;

ll minCoins(ll m, ll V)
{
    ll table[V+1];
    table[0] = 0;

    for (ll i=1; i<=V; i++)
        table[i] = LONG_MAX;

    for (ll i=1; i<=V; i++)
    {
        for (ll j=0; j<m; j++)
          if ((j+1) <= i)
          {
              ll sub_res = table[i-(j+1)];
              if (sub_res != LONG_MAX && sub_res + 1 < table[i])
                  table[i] = sub_res + 1;
          }
    }
    return table[V];
}

int main()
{
    cin >> numCoins >> sum;
    cout << minCoins(numCoins, sum) << endl;

    return 0;
}


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

long long getMinCoins(long long  n ,long long k,  long long  qb[]){
	if (k == 0 ){
		return 0;
	}

	if(qb[k] != 0){
		return qb[k];
	}

	long long curr = 0 , min = INT_MAX;
	for(long long i = 1 ; i <= n ; i++){
		if(i > k){
			continue;
		}
		curr = 1+getMinCoins(n , k-i ,qb);
		if (curr < min){
			min = curr;
		}
	}

	qb[k] = min;
	if (min == INT_MAX) min = 0;
	return min;
}

// void print(long long arr[] , long long n){
// 	for(int i = 1 ; i <= n ; i++){
// 		cout<<arr[i]<<" ";
// 	}
// 	cout<<"\n";
// }

int main(){

	long long n,S;
	cin>>n>>S;

	long long qb[S+1];
	memset(qb,0, sizeof(qb));

	//print(qb,S);
	cout<<getMinCoins(n,S,qb)<<endl;
	//print(qb,S);

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool comp(ll a,ll b)
{
    return a<=b;
}
int main()
{
       ll n,sum;
       cin>>n>>sum;
       vector<ll> v;
       v.reserve(100000);
       for(ll i=1;i<=n;i++)
       {
              v.push_back(i);
       }
       ll coin=0;
       while(sum>0)
       {
              auto it=lower_bound(v.begin(),v.end(),sum,comp);
              coin+=(sum/(*it));
              sum=sum%(*it);
       }
       cout<<coin<<"\n";
}


//Prashant Tyagi
using namespace std;
#include <bits/stdc++.h>
#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
typedef  long long                     LL;
typedef  vector < int >                VI;
typedef  pair< int, int >              II;
typedef  vector < II >                 VII;
#define SI(x)                          scanf ("%d", &x)
#define SLL(x)                         scanf ("%lld", &x)
#define PI(x)                          printf ("%d\n", x)
#define PLL(x)                         printf ("%lld\n", x)
#define MOD                            98765431
#define PB                             push_back
#define MP                             make_pair
#define ALL(v)                         v.begin(), v.end()
#define VIF(x,V)                       for(int x:V)
#define FILL(a,b)                      memset(a,b,sizeof(a))
#define REP(i,j,n)                     for(int i=j;i<n;i++)
#define FLD(i,j,n)                     for(int i=n-1;i>=j;i--)
#define F                              first
#define S                              second
#define fast_io                        ios_base::sync_with_stdio(false);cin.tie(NULL)
const int N = 105;
const int K = 20;
const int U = 31;
int dp[N][1<<K];
vector<int> prime;
int n,k;
int A[N];

bool isPrime(int x)
{
	for (int i = 2; i * i <= x; i++){
		if (x % i == 0) return false;
	}
	return true;
}
int solve(int ind,int mask)
{
	if(ind == n) return 0;
	if (dp[ind][mask] != -1) return dp[ind][mask];

	int &ret = dp[ind][mask];
	ret=(int) 1e5;

	for (int i = 1; i < 60; i++) {
		int nMask = 0;
		for (int j = 0;j < k; j++) {
			if (i % prime[j] == 0) nMask = nMask | 1<<j;
		}
		if (__builtin_popcount(nMask | mask) == __builtin_popcount (mask)) {
			ret = min (ret, abs (i-A[ind]) + solve (ind + 1, nMask));
		}
	}
	return ret;
}

void trace_solution(int ind, int mask)
{
	if (ind == n) return;
	for (int i = 1; i < 60; i++) {
		int nMask = 0;
		for (int j = 0;j < k; j++) {
			if (i % prime[j] == 0) nMask = nMask | 1<<j;
		}
		if (__builtin_popcount(nMask | mask) == __builtin_popcount (mask)) {
			if (dp[ind][mask] == abs (i-A[ind]) + solve (ind + 1, nMask)) {
				cout << i << " ";
				trace_solution(ind+1,nMask);
				break;
			}
		}
	}
}
int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	REP(i,2,60){
		if(isPrime(i))prime.PB(i);
	}
	k = prime.size();
	SI(n);
	REP (i,0,n) SI(A[i]);
	FILL(dp,-1);
	solve(0,(1<<k) - 1);
	trace_solution(0, (1<<k) - 1);
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;

int n, a[111];
int pd[111][1<<19], mark[111][1<<19];
vector <int> out;
vector <int> primes;

bool isPrime(int n){
	if(n==2) return true;
	rep(i, 2, n){
		if(n%i==0)
			return false;
	}
	return true;
}

int solve(int i, int m){
	if(i==n) return 0;
	if(pd[i][m]!=-1) return pd[i][m];
	int ret = 0x3f3f3f3f;
	rep(j, 1, 60){
		int yep = true, newM = m;
		rep(k, 0, primes.size()){
			if(j%primes[k]==0){
				if(m&(1<<k)){
					yep = false;
					break;
				}else{
					newM|=(1<<k);
				}
			}
		}
		if(!yep) continue;
		int aux = solve(i+1, newM)+abs(a[i]-j);
		if(aux<ret){
			ret = aux;
			mark[i][m] = j;
		}
	}
	return pd[i][m] = ret;
}

void rec(int i, int m){
	if(i==n) return;
	out.pb(mark[i][m]);
	int newM = m, j = mark[i][m];
	rep(k, 0, primes.size()){
		if(j%primes[k]==0){
			newM|=(1<<k);
		}
	}
	rec(i+1, newM);
}

int main(){

	rep(i, 2, 60){
		if(isPrime(i))
			primes.pb(i);
	}

	memset(pd, -1, sizeof pd);

	cin >> n;
	rep(i, 0, n) cin >> a[i];
	int ans = solve(0, 0);
	rec(0, 0);
	rep(i, 0, out.size()){
		if(i) cout << " ";
		cout << out[i];
	}	cout << "\n";

	return 0;
}