#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define eps 1e-8

#define squ(a,b) (a)*(a)+(b)*(b)

#define pi 3.1415926535897932384626433832795

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if(sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if(x<0) {putchar('-');return print(-x);}if(x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

const int A=60;

int f[A],dp[111][300000],a[111],flag[A],cp;

pii pre[111][300000];

void solve_A(){

	int n;gn(n);

	for(int i=1; i<=n; i++) gn(a[i]);

	for(int i=2; i<A; i++) if(!flag[i]){

		for(int j=i; j<A; j+=i){

			f[j]+=(1<<cp);

			flag[j]=1;

		}

		cp++;

	}

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

		for(int j=0; j<300000; j++) dp[i][j]=inf;

		for(int k=1; k<60; k++){

			int b=(~f[k]) & ((1<<17)-1);

			for(int r=b; r>0; r=(r-1) & b ){

				if(dp[i-1][r]+abs(a[i]-k)<dp[i][r|f[k]]){

					dp[i][r|f[k]]=dp[i-1][r]+abs(a[i]-k);

					pre[i][r|f[k]]=pii(r,k);

				}

			}

		}

	}

	int tmp=inf;

	int g;

	for(int i=1; i<300000; i++) if(dp[n][i]<tmp){

		g=i;tmp=dp[n][i];

	}

	VI ans;

	for(int i=n; i>0; i--){

		ans.pb(pre[i][g].y);

		g=pre[i][g].x;

	}

	reverse(ans.begin(),ans.end());

	for(int i=0; i<ans.size(); i++) printsp(ans[i]);

	exit(0);

}

int main(){

#ifndef ONLINE_JUDGE

	freopen("in.in","r",stdin);

	freopen("out.out","w",stdout);

#endif

	solve_A();

	return 0;

}


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

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

#define PB push_back
#define F first
#define S second
#define MP make_pair

#define PI acos(-1)
#define eps 1e-9
#define inf 100000000
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

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

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool EQ2(double a, double b) {return fabs(a-b) < 1e-7; }

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

#define MX 60

typedef pair<int, pii>obj;

int n, seive[MX], prime[MX], store[60], c;
int a[110];
int dp[110][1<<18];
pii nxt[110][1<<18];
int ans[110][1<<18];

void seiveGen () {
    int sqrtn = sqrt ( MX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
            if ( !seive[i>>1] ) {
                    for ( int j = i * i; j < MX; j += i + i ) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime[c++] = 2;
    for ( int i = 3; i < MX; i += 2 ) {
            if ( !seive[i>>1] ) prime[c++] = i;
    }
    dbg ( c );
    prime[c++] = inf;
}

void init() {
    for ( int i = 1; i < MX; i++ ) {
            for ( int j = 0; prime[j] <= i; ++j ) {
                    if ( i % prime[j] == 0 ) {
                            store[i] = setBit ( store[i], j );
                    }
            }
            dbg ( i, store[i] );
    }
}

int recur ( int index, int mask ) {
    if ( index == n ) return 0;

    int &ret = dp[index][mask];
    if ( ret != -1 ) return ret;

    ret = inf;

    for ( int i = 1; i < MX; ++i ) {
            if ( store[i] & mask ) continue;
            int temp = recur ( index + 1, mask | store[i] );
            if ( temp + abs ( i - a[index] ) < ret ) {
                    nxt[index][mask] = pii ( index + 1, mask );
                    ret = temp + abs ( i - a[index] );
                    ans[index][mask] = i;
            }
    }

    return ret;
}

void ansGen () {
    recur ( 0, 0 );
    pii cur ( 0, 0 ); dbg ( n );

    for ( int i = 0; i < n; ++i ) {
            cout << ans[cur.F][cur.S] << " ";
            cur = nxt[cur.F][cur.S];
    }

}

int main () {

    //optimize();

    #ifdef yamin
    freopen ( "input.txt", "r", stdin );
    #endif // yamin

    seiveGen(); init();

    cin >> n;

    for ( int i = 0; i < n; ++i ) cin >> a[i];

    mem ( dp, -1 );

    ansGen();

    return 0;

}


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

main(){
       char s[200];
       int i, jumlah=0, n, a, ubah;

       cin>>n;
       cin>> s;

       for (i=0;i<strlen(s);i++){
           if(s[i]=='x'){
                         jumlah++;
           }
       }
       if(jumlah==n/2){
                       cout<<"0";
       }else if (jumlah<n/2){
             cout<<"a";
             cout<<n/2-jumlah;
             i=0;
             for(ubah=0;ubah < n/2-jumlah;i++){
                        if(s[i]=='X'){
                                      s[i]='x';
                                      ubah++;
                        }
             }
       }else {
             cout<<jumlah-n/2;
             i=0;
             for(ubah=0;ubah < jumlah-n/2;i++){
                        if(s[i]=='x'){
                                      s[i]='X';
                                      ubah++;
                        }
             }
       }
       cout<<endl<<s<<endl;
       getch();
}


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
 int n,c=0,j=0,x ;
char a[200];

 cin>>n;
 x=n/2;
 for(int i=0;i<n;i++)
 cin>>a[i];
 for(int i=0;i<n;i++)
 if(a[i]=='X')
 c++;
 if(c==n/2)
 for(int i=0;i<n;i++)
 cout<<a[i];
 else
 j=x-c;
 for(int k=0;k<j;k++)
 a[k]='X';
 for(int i=0;i<n;i++)
 { cout<<a[i];}
 cout<<endl<<j;
 getch();
 return 0;
}


#include<iostream>
using namespace std;

int main()
{
	int numberOfStairs, stepMultiplier, steps = 0;

	if (numberOfStairs < stepMultiplier)
	{
		cout << -1;
	}
	else
	{
		if (numberOfStairs % 2 == 0)
		{
			steps = numberOfStairs / 2;
		}
		else
		{
			steps = numberOfStairs / 2 + 1;
		}
		if (steps%stepMultiplier != 0)
		{
			steps++;
		}
		cout << steps;
	}
}


#include<stdio.h>
int main()
{
    int n,m,i,j,k;
    scanf("%d %d",&n,&m);
    if(n<m){ printf("-1\n"); return 1;}
    k=1;
    while(1)
    {
        if(n>2*k*m) k++;
        else if(n<=2*k*m) {break;
        }
    }

    printf("%d",2*k);
}


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

	int stair ;
	int n;
	cin >> stair>>n;
	int s = stair;
	int step = s / 2+(s%2);
	if (n < stair) {
		while (step%n != 0) {
			s -= 2;
			step = s / 2 + (stair - s);
		}
		cout << step;
	}
	else if(n==stair){cout << n;}
	else
		cout << -1;
}


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

int main()
{
    int m,n,i;

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

    if (n%2 == 0)
    {
        for (i=n/2 ; i<=n ; i++)
        {
            if (i%m == 0)
            {
                printf("%d",i);
                break;
            }
        }
    }

    if (n%2 == 1)
    {
        for (i=(n/2) + 1 ; i<=n ; i++)
        {
            if (i%m == 0)
            {
                printf("%d",i);
                break;
            }
        }
    }

    getch();
    return -1;
}


/*
ID: new.sam1
PROG: ride
LANG: C++11
*/
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <string>
#include <stdio.h>
#include <math.h>
#include <fstream>

using namespace std;

int main()
{
  // ofstream fout("output.txt");
  //ifstream fin("input.txt");

  long long n,k;
  cin>>n>>k;
  if(k == 0)
    cout<<n;
  else if(k == 1)
  {
    if(n%10 == 0)
      cout<<n;
    else
      cout<<n*10;
  }
  else
  {
    long long mx = -1,p = 0;
    for(int i=1;i<=10;i++)
    {
      long long g = n,cnt=0;
      g*=i;
      while(g>0)
      {
        if(g%10 == 0)
        {
          cnt++;
          g/=10;
        }
        if(k<=cnt)
          return cout<<n*i,0;
        if(g%10!=0)
          break;
      }
      if(cnt>mx)
      {
        mx = cnt;
        p=i;
      }
      cnt=0;

    }

    long long ms = k - mx;
    if(p==0)
      p = 1;

    while(ms--)
    { p*=10;}

    cout<<n*p<<endl;

  }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,k,ANS,ans,an,x;
main ()
{
	cin>>n>>k;

	long long x=n;

	while (x%10==0)
	{
		x=x/10;
		ans++;
	}

	if (ans>=k)
	{
		cout<<n<<endl;
		return 0;
	}

	ans=0;

	for (int i=1; i<=10; i++)
	{
		long long x=n*i;

		an=0;

		while (x%10==0)
		{
			x=x/10;
			an++;
		}

		if (an>ans)
		{
			ans=an;
			ANS=n*i;
		}
	}

	x=ANS;

	ans=0;

	while (x%10==0)
	{
		x=x/10;
		ans++;
	}

	if (ans>=k)
	{
		cout<<ANS<<endl;
		return 0;
	}

	for (int i=1; i<=k-ans; i++)
		ANS=ANS*10;

	cout<<ANS<<endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    long long n;
    int k,x=1;
    cin >> n >> k;
    for (int i=0;i<k;i++) x*=10;
    for (int i=1;i<100000;i++){
        if ((n*1ll*i)%x==0){
            cout << n*1ll*i;
            return 0;
        }
    }
    cout << n;
    for (int i=0;i<k;i++) cout << 0;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define lol long long

int napa(lol int n)
{
    int cnt=0;
    while(1)
    {
        int res=n%10;
        if(res!=0)break;
        else cnt++;
        n=n/10;
    }
    return cnt;
}

int main()
{
   lol int j=5,k,n,res;
   cin>>n>>k;
   if(napa(n)>=k)cout<<n<<endl;

   else
   {
       while(1)
       {
        res=n*j;
       if(napa(res)>=k)break;
       j=j+5;
       }
       cout<<res<<endl;
   }

   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> vec,num;
vector<pair<ll,ll> > vp;
ll mini;

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

map<ll,ll> has;

ll ar[5000002],br[512345];

const int MOD = 1e9 + 7;

int main()
{
	ll c,i,p,q,d,k,len,y,j,a,b,t,ans,flag,n,m,g=0,res=0,sum=0,e,f,r,minm=99999999,maxm=-1,x,hr;
	c=0;
//	freopen("output.out","w",stdout);
	string str,ptr,dtr;
	char ch,prev;

     cin>>x;
     k=x;

     cin>>str>>ptr;

     if(ptr[0]=='7' || ptr[1]=='7' || str[0]=='7' || str[1]=='7')
     cout<<0;
     else
     {
     	hr=((str[0]-48)*10 + (str[1]-48));
     	n=((ptr[0]-48)*10 + (ptr[1]-48));
     	c=1;
     	p=n;
     	while(1)
     	{
     		p=p-x;
     		if(p<=0)
     		{
     			p=(p+60)%60;
     			hr=(hr-1);
     			if(hr<0)
     			{
     				hr=(hr+12)%12;
				 }

				 if(hr%10==7)
				 {
				 	cout<<c;
				 	break;
				 }
     			if(p%10==7)
     			{
     			cout<<c;
     			break;
     		    }

     			c++;

			 }
			 else
			 {
			 	if(p%10==7)
			 	{
     			cout<<c;
     			break;
     		   }
     			c++;
			 }
		}
	 }

	return 0;
}


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

int main() {
    int x, a, b, aa, bb;
    scanf("%d", &x);
    scanf("%d%d", &a, &b); aa = a, bb = b;
    for(int i = 0; i <= 24*60; i ++) {
        int tmp = x*i; a = aa, b = bb;
        while(b < tmp) { b += 60; a --; if(a == -1) a = 23; }
        b -= tmp;
        if(b%10 == 7 || b/10 == 7 || a%10 == 7 || a/10 == 7) {
            printf("%d\n", i);
            return 0;
        }
    }
}


#include <iostream>
#include <cstring>
#define MAXI 8
#define MAXL 9
#define MOD 1000000007

using namespace std;

long long f[MAXI][MAXL][2],c[MAXL];
int n,length,an[MAXL];

inline void update(long long &i, const long long j)
{
    i=(i+j)%MOD;
}

inline int isfs(const int k)
{
    return (k==4||k==7);
}

inline void init()
{
    memset(f,0,sizeof(f));
    f[0][0][1]=1;

    for(int i=0;i<length;i++)
    {
        for(int j=0;j<=i;j++)
        {
            int k;
            //С�ڣ�һ�����У�
            for(k=0;k<an[i];k++)
            {
                update(f[i+1][j+isfs(k)][1], f[i][j][1]+f[i][j][0]);
            }

            //����
            update(f[i+1][j+isfs(k)][1],f[i][j][1]);
            update(f[i+1][j+isfs(k)][0],f[i][j][0]);
            k++;

            //���ڣ�һ�������У�
            for(;k<=9;k++)
            {
                update(f[i+1][j+isfs(k)][0], f[i][j][1]+f[i][j][0]);
            }
        }
    }

    for(int i=0;i<=length;i++)
        c[i]=f[length][i][1];
    c[0]--;
}

inline long long dfs(int depth,int left47)
{
    if(depth==MAXI)
        return 1;

    long long ret=0;
    for(int c47=0;c47<=left47;c47++)
    {
        update(ret,(c[c47]--)*dfs(depth+1,left47-c47));
        c[c47]++;
    }
    return ret;
}

inline void solve()
{
    long long ret=0;
    for(int i=1;i<=length;i++)
    {
        ret=(ret+dfs(2,i-1)*c[i])%MOD;
    }
    cout<<ret<<endl;
}

int main()
{
    cin>>n;
    for(int k=n,i=0;k;an[i++]=k%10,k/=10,length++);

    init();
    solve();
    while(1);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>

using namespace std;
const int MOD = 1000000007;
const int small_lucks[10] = {0,0,0,0,0,1,1,1,2,2};
const int small_unlucks[10] = {0,1,2,3,4,4,5,6,6,7};
const int is_luck[10] = {0,0,0,0,1,0,0,1,0,0};
int lucks[10];

long long count(int sum, int number) {
	if (number == 0) return 1;
	long long result = 0;
	for (int i = sum; i >= 0; --i) {
		--lucks[i];
		long long c = count(sum-i, number-1);
		++lucks[i];
		result += c*lucks[i];
		result %= MOD;
	}
	return result;
}

int main() {
	int n;
	char t[10];
	string s;
	cin >> n;
	sprintf(t, "%d", n);
	s = t;
	int l = s.length();
	int luck[10][10];
	luck[0][0] = 1;
	luck[1][0] = 8;
	luck[1][1] = 2;
	for (int i = 2; i <= l; ++i)
		for (int j = 0; j <= i; ++j) {
			luck[i][j] = 0;
		}
	for (int i = 2; i <= l; ++i)
		for (int j = 0; j <= i; ++j) {
			if (j > 0) luck[i][j] += luck[i-1][j-1]*2;
			if (i > j) luck[i][j] += luck[i-1][j]*8;
		}
	int kk[10];
	kk[0] = 0;
	for (int i = 1; i <= l; ++i)
		kk[i] = kk[i-1] + is_luck[s[i-1]-'0'];
	for (int i = 0; i <= 10; ++i)
		lucks[i] = 0;
	lucks[kk[l]] += 1;
	for (int i = 0; i <= l-1; ++i)
		for (int j = 0; j <= l-1-i; ++j) {
			int k = s[i] - '0';
			lucks[kk[i]+j+1] += luck[l-1-i][j]*small_lucks[k];
			lucks[kk[i]+j] += luck[l-1-i][j]*small_unlucks[k];
		}
	--lucks[0];
	int max = l;
	while (lucks[max] == 0) --max;
	long long ans = 0;
	for (int i = max; i > 0; --i) {
		ans += lucks[i] * count(i-1, 6) % MOD;
	}
	cout << ans % MOD << endl;
	return 0;
}


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

long long mod = 1000000007;

long long cnt[11] = {0};

long long c[11][11] = {0};

long long dp[12][7][1000] = {0};

void f(long long a, long long len, long long mul, long long add = 0){
	if (len == 0){
		cnt[add] = (cnt[add] + 1) % mod;
		return;
	}
	for (long long i = 0; i < 10; i++){
		long long iadd = 0;
		if (i == 4 || i == 7)
			iadd = 1;
		if (a >= (i + 1) * mul){
			long long nluck = 1, luck = 1;
			for (int j = 1; j <= len - 1; j++){
				nluck *= 8;
			}
			for (int j = 0; j <= len - 1; j++){
				cnt[add + j + iadd] = (cnt[add + j + iadd] + (luck * nluck * c[len - 1][j]) % mod) % mod;
				luck *= 2;
				nluck /= 8;
			}
		}
		else{
			f(a - i * mul, len - 1, mul / 10, add + iadd);
			return;
		}
	}
}

void calc(){
	for (int i = 0; i <= 11; i++){
		for (int k = 0; k <= 6; k++){
			for (int j = 0; j <= 10; j++){
				dp[i][k][j] = 0;
			}
		}
	}
	dp[0][0][0] = 1;
	for (int i = 0; i <= 10; i++){
		for (int k = 0; k < 6; k++){
			for (int j = 0; j <= 10; j++){
				long long mul = 1;
				for (int n = 1; n + k <= 6; n++){
					if (n > cnt[i])
						break;
					mul = (mul * (cnt[i] - (n - 1))) % mod;
					dp[i + 1][n + k][j + i * n] = (dp[i + 1][n + k][j + i * n] + dp[i][k][j] * ((mul * c[n + k][n]) % mod)) % mod;
				}
			}
		}
	}
}

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

	long long n;
	cin>>n;

	c[0][0] = 1;
	for (int i = 1; i <= 10; i++){
		c[i][0] = 1;
		for (int j = 1; j <= i; j++){
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
		}
	}

	long long len = 1;
	long long mul = 1;

	while (mul * 10 <= n){
		len++;
		mul *= 10;
	}

	f(n, len, mul);

	cnt[0]--;

	long long temp = 0;

	for (int i = 0; i <= 10; i++){
		if (cnt[i] == 0)
			continue;
		cnt[i]--;
		calc();
		long long a = 0;
		for (int k = 1; k <= 11; k++){
			for (int j = 0; j < i; j++){
				a = (a + dp[k][6][j]) % mod;
			}
		}
		cnt[i]++;
		a = (a * cnt[i]) % mod;
		temp = (temp + a) % mod;
	}

	cout<<temp;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll six = 720ll;
const ll mod = 1e9 + 7;
ll sv[4], m;
ll cnt[10];

ll luck_count(ll x){
    ll ans = 0;
    while(x){
        ans += (x%10 == 4 || x%10 == 7);
        x/=10;
    }
    return ans;
}
ll fast(ll b, ll e){
    if(!e)
        return 1;
    ll cur = (e&1)? b : 1;
    return cur * fast(b * b %mod, e/2)%mod;
}
ll nCr(ll n, ll r){
    if(r > n)
        return 0;
    if(n == r)
        return 1;
    return nCr(n - 1, r) * n %mod * fast(n - r, mod - 2) % mod;

}
ll brdo_luck_count(string s){
    ll cnt = 0;
    for(ll i = 0; i < s.size(); i++)
        cnt += (s[i] == '4' || s[i] == '7');
    return cnt;
}
ll dp[10][10][7];
ll n_o_w[12];
ll solve(int idx, int sv, ll lft){
    if(sv < 0)
        return 0;
    if(idx == 10)
        return (lft == 0);

    ll &ret = dp[idx][sv][lft];
    if(~ret)
        return ret;
    ret = 0;

    for(int i = 0; i <= min(lft, cnt[idx]); i++){
        ret = (ret + (nCr(cnt[idx],i) * solve(idx + 1, sv - (idx * i), lft - i))%mod) %mod;
    }
    return ret;
}
void gen_find(){
    memset(dp, -1, sizeof dp);
    for(int i = 0; i <= 9; i++)
        n_o_w[i] = solve(0,i,6);
}
void solve(){
    gen_find();
    ll acc = 0;
    ll ans = 0;
    for(int i = 1; i <= 9; i++){
        ans = (ans + (cnt[i] * (n_o_w[i - 1] * six)%mod)%mod)%mod;
    }
    printf("%lld\n", ans);
    exit(0);
}
int main(){
    cin >> m;
    for(ll i = 1; i < min(m + 1, 1000ll); i++){
        cnt[luck_count(i)]++;
    }
    if(m < 1000){
        solve();
    }
    for(ll i = 0; i <= 9; i++){
        for(ll j = 0; j <= 9; j++){
            for(ll k = 0; k <= 9; k++){
                string tmp = "";
                tmp.push_back('0' + i);
                tmp.push_back('0' + j);
                tmp.push_back('0' + k);
                sv[brdo_luck_count(tmp)]++;
            }
        }
    }
    ll goz2 = m;
    for(ll i = 0; i < 3; i++)
        goz2/=10;
    for(ll i = 1; i< goz2; i++){
        ll ro = luck_count(i);
        for(ll j = 0; j < 4; j++)
            cnt[ro + j] += sv[j];
    }
    goz2 *= 1000;
    for(ll i = goz2; i <= m; i++){
        cnt[luck_count(i)]++;
    }
    solve();
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    if(abs(x-y)<=z&&z!=0) cout<<"?"<<endl;
    else if(x+z<y) cout<<"-"<<endl;
    else if(x>y+z) cout<<"+"<<endl;
    else if(x=y&&z==0) cout<<"0"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main () {
	int n,m,v;
	cin>>n>>m>>v;
	if(n==0&&m==0||n>m&&n==v||m>n&&m==v||m==n&&n==v||m>n&&n+v==m||n>m&&m+v==n||m==n&&v>0){

	cout<<"?";
	return 0;
}
	if(n==m){

	cout<<0;
	return 0;
}
if(m>n)
cout<<"-";
else
if(m<n)
cout<<"+";
}


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

int main()
{
    long long int x,y,z,a,b,c;
    cin>>x>>y>>z;
    if(x>y)
    {
        a=x-y;
        if(a>z)
            cout<<"+"<<endl;
        else
            cout<<"?"<<endl;
    }
    else if(y>x)
    {
        a=y-x;
        if(a>z)
            cout<<"-"<<endl;
        else
            cout<<"?"<<endl;
    }
    else
    {
        if(x>z)
            cout<<"0"<<endl;
        else
            cout<<"?"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,z,a,b;
    cin>>x>>y>>z;
       if(z==0)
       {
           if(x>y)
            cout<<"+"<<endl;
           else if(x<y)
            cout<<"-"<<endl;
           else
            cout<<"0"<<endl;
       }
       else
       {
           int p,q;
           a=x+z;
           b=y+z;
              if(a==b||(a==y)||(b==x))
                cout<<"?"<<endl;
               else if(a>b)
                cout<<"+"<<endl;
               else
                cout<<"-"<<endl;
           }

}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const long long mod=998244353;
const int N=520;
int n,k;
long long f[N][N][N],fact[N],invfact[N],pre[N];

long long pwr(long long a,long long x)
{
    if (x==0) return 1ll;
    long long ans=pwr(a,x/2);
    ans=(ans*ans)%mod;
    if (x%2==1) ans=(ans*a)%mod;
    return ans;
}

long long C(long long n,long long k)
{
    if (n<k) return 0;
    long long ans=(fact[n]*invfact[k])%mod;
    ans=(ans*invfact[n-k])%mod;
    return ans;
}
void lulu_solution()
{
    cin >> n >> k;
    fact[0]=1ll;
    invfact[0]=1ll;
    for (long long i=1; i<=n+n; i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
        invfact[i]=pwr(fact[i],mod-2);
    }
    for (int i=2; i<=n; i++)
    {
        for (int j=1; j<=k; j++)
        {
            pre[j]=pre[j-1];
            for (int t=1;t<i;t++)
            {
                pre[j]+=(f[i-1][j][t]*C(1ll*(n-i+1+t),1ll*t))%mod;
                pre[j]%=mod;
            }
        }
        for (int j=1;j<=k;j++)
            for (int t=1;t<i;t++)
        {
            if (i==2) f[i][j][t]=1ll;
            else
            {
                if (t==1) f[i][j][t]=(pre[j-1]*pwr(1ll*(k-j+1),1ll*(i-2)))%mod;
                else f[i][j][t]=(f[i-1][j][t-1]*pwr(1ll*(k-j+1),1ll*(i-2)))%mod;
            }
         //   cout << i << " " << j << " " << t << " " << f[i][j][t] << "\n";
        }
    }
    long long res=0ll;
    for (int j=1;j<=k;j++)
        for (int t=1;t<n;t++) res=(res+f[n][j][t])%mod;
        cout << res;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    lulu_solution();
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const long long mod=998244353;
const int N=510;
int n,k;
long long f[N][N][N],fact[N],invfact[N],pre[N];

long long pwr(long long a,long long x)
{
    if (x==0) return 1ll;
    long long ans=pwr(a,x/2);
    ans=(ans*ans)%mod;
    if (x%2==1) ans=(ans*a)%mod;
    return ans;
}

long long C(long long n,long long k)
{
    if (n<k) return 0;
    long long ans=(fact[n]*invfact[k])%mod;
    ans=(ans*invfact[n-k])%mod;
    return ans;
}
void lulu_solution()
{
    cin >> n >> k;
    fact[0]=1ll;
    invfact[0]=1ll;
    for (long long i=1; i<=n+n; i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
        invfact[i]=pwr(fact[i],mod-2);
    }
    for (int i=2; i<=n; i++)
    {
        for (int j=1; j<=k; j++)
        {
            pre[j]=pre[j-1];
            for (int t=1;t<i;t++)
            {
                pre[j]+=(f[i-1][j][t]*C(1ll*(n-i+1+t),1ll*t))%mod;
                pre[j]%=mod;
            }
        }
        for (int j=1;j<=k;j++)
            for (int t=1;t<i;t++)
        {
            if (i==2) f[i][j][t]=1ll;
            else
            {
                if (t==1) f[i][j][t]=(pre[j-1]*pwr(1ll*(k-j+1),1ll*(i-2)))%mod;
                else f[i][j][t]=(f[i-1][j][t-1]*pwr(1ll*(k-j+1),1ll*(i-2)))%mod;
            }
         //   cout << i << " " << j << " " << t << " " << f[i][j][t] << "\n";
        }
    }
    long long res=0ll;
    for (int j=1;j<=k;j++)
        for (int t=1;t<n;t++) res=(res+f[n][j][t])%mod;
        cout << res;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    lulu_solution();
}


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

#define ll long long
#define lll __int128
#define lb long double
#define D double

#define psb push_back
#define mkp make_pair

#define min3(xxx,yyy,zzz) min(min(xxx,yyy),zzz)
#define max3(xxx,yyy,zzz) max(max(xxx,yyy),zzz)

#define gi greater<int>
#define gl greater<ll>
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second

#define rep(variable,leftrange,rightrange) for(int variable=leftrange;variable<=rightrange;++variable)
#define Rep(variable,leftrange,rightrange) for(int variable=leftrange;variable>=rightrange;--variable)

#define Seed mt19937 rANd(random_device{}())
#define rd(p) (rANd()%p)

#define ss stable_sort
#define nxp next_permutation
#define rds random_shuffle

#define mem(x,y) memset(x,y,sizeof x)
#define Finda(a,siz,b) (lower_bound(a+1,a+siz+1,b)-a)
#define Findv(a,b) (lower_bound(a.begin(),a.end(),b)-a.begin())
#define qc(v) v.erase(unique(v.begin(),v.end()),v.end())
#define all(x) x.begin(),x.end()

#define sq(x) ((x)*(x))
#define lowbit(x) ((x)& -(x))

#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)
template <typename T>inline void read(T &t)
{bool flag = 1 ;char c=getchar();t=0;while(!isdigit(c)){ if(c=='-') flag = 0; c=getchar();}while(isdigit(c))t=(t<<3)+(t<<1)+c-48,c=getchar(); if(!flag) t=~(t-1);}
template <typename T,typename... Args> inline void read(T& t, Args&... args){read(t);read(args...);}
template <typename T> inline void wrt(T x)
{if(x<0) x=~(x-1),putchar('-'); if(x>9) wrt(x/10); putchar(x%10+'0');}
template <typename T> inline void wrt(T x,char c) {wrt(x);putchar(c);}

#define FileIO(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout)
#define debug puts("I am still alive")
#define S_debug(l,r,val) printf("[%d,%d] : %d \n",l,r,val)
#define P_debug(a,b) printf(#a"[%d] = %d \n",b,a[b])
#define A_debug(a,b) rep(i,1,b) P_debug(a,i);

const int N = 1600000 + 20 ;

namespace Graph{
    class Tree {
        public:
            vector<int> w , jump[26] ;
            vector<vector<int> > ed ;
            vector<int> fa ;
            vector<int> dep ;
            vector<int> siz ;
            vector<int> dfn ;
            vector<int> rnk ;
            vector<int> hv ;
            vector<int> top ;
            bool use_l = 0 , use_T = 0 ;
            int _tim = 0;
            int _n = 0 ;
            int _rt = 1;
            void adde(int u , int v)
            {
                ed[u].emplace_back(v);
                ed[v].emplace_back(u);
            }
            Tree(int _siz , bool use_lca = false , bool useTreepo = false)
            {
                use_l = use_lca;
                use_T = useTreepo ;
                _n = _siz ;
                _siz += 20 ;
                ed.resize(_siz , {}) ;
                fa.resize(_siz , 0 ) ;
                w.resize(_siz , 0 );
                dep.resize(_siz , 0) ;
                siz.resize(_siz , 0) ;
                if(use_lca)  rep(i,0,23) jump[i].resize(_siz , 0) ;
                if(useTreepo) dfn.resize(_siz , 0) , rnk.resize(_siz , 0) , hv.resize(_siz , 0) , top.resize(_siz , 0);

            }
            void dfs(int x,int f)
            {
                fa[x] = f ;
                dep[x] = dep[f] + 1 ;
                siz[x] = 1 ;
                if(use_l)
                {
                    jump[0][x] = f;
                    rep(i,1,23) jump[i][x] = jump[i-1][jump[i-1][x]] ;
                }

                for(int p : ed[x])
                {
                    if(p == f) continue ;
                    dfs(p , x);
                    siz[x] += siz[p] ;
                    if(use_T)
                    {
                        if(siz[p] > siz[hv[x]]) hv[x] = p ;
                    }
                }
            }
            int LCA(int u , int v)
            {
                if(dep[u] < dep[v])swap(u,v) ;
                int c = dep[u] - dep[v];
                Rep(i,23,0) if(c >= 1 << i) c-= 1 << i , u = jump[i][u] ;
                if(u==v)return u ;
                Rep(i,23,0) if(jump[i][u]!=jump[i][v]) u = jump[i][u] , v = jump[i][v] ;
                return fa[u] ;
            }
            void dfs2(int x,int t)
            {
                ++_tim ;
                dfn[_tim] = x ;
                rnk[x] = _tim ;
                top[x] = t ;
                if(!hv[x]) return ;
                dfs2(hv[x],t);
                for(auto p:ed[x])
                if(p!=fa[x]&&p!=hv[x]) dfs2(p,p);
            }
    } ;
}

Graph::Tree T(N , 1 , 0);
int q,u,v,n;
char c[N] ;
char ch[N][2];

vi path(int u , int v , int LCA)
{
    vi res,v1,v2 ;
    res.clear();v1.clear();v2.clear();
    while(u!=LCA)
    {
        v1.emplace_back(u);
        u = T.fa[u];
    }
    while(v!=LCA)
    {
        v2.emplace_back(v);
        v = T.fa[v] ;
    }
    for(auto p:v1) res.emplace_back(p) ;
    res.emplace_back(LCA);
    reverse(all(v2));
    for(auto p:v2) res.emplace_back(p) ;
    return res ;
}

namespace SAT{
    vector<int> ed[N << 2] ;
    int tot ;
    void adde(int x,int y){ed[x].psb(y);}
    int dfn[N << 2] , low[N << 2] , tim = 0 ;
    int bel[N<<2] ;
    stack<int> s ;
    void tarjan(int x)
    {
        low[x] = dfn[x] = ++tim ;
        s.push(x);
        for(auto p:ed[x])
        {
            if(!dfn[p]) tarjan(p),upmin(low[x] , low[p]);
            else if(!bel[p]) upmin(low[x] , low[p]) ;
        }
        if(low[x] == dfn[x])
        {
            int tp ;
            ++tot ;
            do
            {
                // cout << tp <<'\n' ;
                tp = s.top();s.pop();bel[tp] = tot ;
            } while (tp != x);
        }
    }
}

int vis[N] ;
//
#define ap(x) x+n
#define link(x) x+2*n
#define flink(x) x+2*n+q
signed main()
{
    read(n,q) ;
    rep(i,1,n-1)read(u,v),T.adde(u,v);
    T.dfs(1,0);
    rep(i,1,n) rep(j,0,1) ch[i][j] = 'a' ;
    rep(i,1,q)
    {
        scanf("%d%d%s" ,&u , &v , (c + 1)) ;
        int len = strlen(c+1) ;
        int ac = T.LCA(u,v);
        vi pat = path( u , v , ac )  ;
        int pos = 0 ;
        for(auto p:pat)
        {
            pos ++ ;
            if(!vis[p]) {vis[p] = 1; ch[p][0] = c[pos] ; ch[p][1] = c[len - pos + 1] ;}
            if(ch[p][0]!=c[pos])
            {
                SAT::adde(flink(i),p);
                SAT::adde(ap(p),link(i));
            }
            if(ch[p][1]!=c[pos])
            {
                SAT::adde(flink(i),ap(p)) ;
                SAT::adde(p,link(i));
            }
            if(ch[p][0]!=c[len-pos+1])
            {
                SAT::adde(link(i),p);
                SAT::adde(ap(p),flink(i));
            }
            if(ch[p][1]!=c[len-pos+1])
            {
                SAT::adde(link(i),ap(p)) ;
                SAT::adde(p,flink(i));
            }
        }
    }
    rep(i,1,n*2 + q*2) if(!SAT::dfn[i]) SAT::tarjan(i);
    rep(i,1,n) if(SAT::bel[i] == SAT::bel[ap(i)]) {puts("NO");return 0;}
    puts("YES");
    rep(i,1,n) putchar(ch[i][SAT::bel[i] < SAT::bel[ap(i)]]) ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
// typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define repg(i,u) for(int i=head[u];~i;i=edge[i].nxt)
#define lowbit(x) (x&(-x))
#define ls (o<<1)
#define rs (o<<1|1)
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define db double
#define endl '\n'
#define push_back emplace_back
mt19937 rnd(time(0));
inline int read(){
	int num=0,f=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')f=0;
		ch=getchar();
	}
	while(isdigit(ch)){
		num=num*10+ch-'0';
		ch=getchar();
	}
	return f?num:-num;
}
const int MAXN=300010;
const int MAXM=1000000;
int n,C;
int maxv[MAXM+10];
void solve(){
	n=read(),C=read();
	rep(i,1,n){
		int c=read(),d=read(),h=read();
		maxv[c]=max(maxv[c],d*h);
	}
	rep(i,1,C){
		if(maxv[i]>0){
			for(int j=i+i;j<=C;j+=i){
				maxv[j]=max(maxv[j],maxv[i]*(j/i));
			}
		}
	}
	rep(i,1,C){
		maxv[i]=max(maxv[i-1],maxv[i]);
	}
	int q=read();
	while(q--){
		int D=read(),H=read();
		int val=D*H;
		if(maxv[C]<=val){
			printf("-1 ");
			continue;
		}
		int l=1,r=C,ans=C;
		while(l<=r){
			int mid=(l+r)/2;
			if(maxv[mid]>val){
				ans=mid;
				r=mid-1;
			}
			else l=mid+1;
		}
		printf("%lld ",ans);
	}
}
signed main(){
	// int T=read();
	int T=1;
	while(T--)solve();
}


#include<iostream>
using namespace std;
#include<string.h>
#include<conio.h>
int a[4000];
int n;
int fun(int u,int s,int y,int z)
{
    if(u==n)
    return s;
    else
    {
        if(z+1!=y)
        return fun(u+1,s,y,z+1);
        else{
             if(s+1!=5)
             return fun(u+1,s+1,y,0);
             else
             return fun(u+1,0,2*y,0);
             }
    }
}
int main()
{
    cin>>n;
    int g=fun(0,0,1,0);
    if(g==0)
    cout<<"Sheldon";
    if(g==1)
    cout<<"Leonard";
    if(g==2)
    cout<<"Penny";
    if(g==3)
    cout<<"Rajesh";
    if(g==4)
    cout<<"Howard";
    getch();
    return 0;
}


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

void main() {
	vector<string> ochered;
	ochered.push_back("Begin");
	ochered.push_back("Sheldon");
	ochered.push_back("leonard");
	ochered.push_back("Penny");
	ochered.push_back("Rajesh");
	ochered.push_back("Howard");
	long n;
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		ochered.push_back(ochered[i]);
		ochered.push_back(ochered[i]);
	}
	cout<<endl << ochered[n];
	_getch();
}


#include <iostream>
#include <string>
using namespace std;
struct spisoc
{
    spisoc *next;
    string name;
};

spisoc *head, *head2;
spisoc *p, *test, *o;
int main()
{long long int n;
cin>>n;
    head =new spisoc;
    p =new spisoc;

    p->name='1';
    test=p;
    for (int i=2; i<6; i++)
    {

      p->next=head;
      p=head;

     if (i==2) p->name='2';
      if (i==3) p->name='3';
      if (i==4) p->name='4';
      if (i==5) p->name='5';
      head =new spisoc;
    }
    head=p;
    o=test;

    head2=head;
    for( int i=0; i<n; i++)
    {

        test=o->next;

          head =new spisoc;
          head->name=o->name;
          head2->next=head;
          head2=head;
           head =new spisoc;
          head->name=o->name;
          head2->next=head;
          head2=head;

     test=o;
        o=o->next;

    }
    if (n==1) cout<<"Sheldon"; else {
     if (test->name=="1") cout<<"Sheldon";
      if (test->name=="2") cout<<"Leonard";
      if (test->name=="3") cout<<"Penny";
      if (test->name=="4") cout<<"Rajesh";
      if (test->name=="5") cout<<"Howard";
    }

    return 0;
}


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

int main()
{
    queue<string> q;
    q.push("Sheldon");
    q.push("Leonard");
    q.push("Penny");
    q.push("Rajesh");
    q.push("Howard");
    int i=1;
    int n;
    cin>>n;
    while(i!=n)
    {
        string s=q.front();
        q.pop();
        q.push(s);
        q.push(s);
        i++;
    }
    cout<<q.front()<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int x,y,z,i,j,k;
    scanf("%d%d%d%d%d%d",x,y,z,i,j,k);
    int cnt=0;
    if(x==i) cnt++;
    if(y==j) cnt++;
    if(z==k) cnt++;
    if(cnt>0) puts("YES");
    if(cnt==0) puts("NO");
    return 0;
}


#include<iostream>
#include<fstream>
using namespace std;

int main()
{
    ifstream fin("input.txt");
    ofstream fout("output.txt");
    int a[3];
    int b[3];
    int i,j,sum=0;
    fin>>a[0]>>a[1]>>a[2];
    fin>>b[0]>>b[1]>>b[2];

    for(i=0;i<3;i++)
        if(a[i]==b[i])
        sum++;
    if(sum>=2)
        fout<<"YES"<<endl;
    else fout<<"NO"<<endl;
    return 0;
}


#include<iostream>
#include<fstream>
using namespace std;

int main()
{
    ifstream fin("input.txt");
    ofstream fout("output.txt");
    int a[3];
    int b[3];
    int i,j,sum=0;
    fin>>a[0]>>a[1]>>a[2];
    fin>>b[0]>>b[1]>>b[2];

    for(i=0;i<3;i++)
        if(a[i]==b[i])
        sum++;
    if(sum>=2)
        fout<<"YES";
    else fout<<"NO";
    return 0;
}


#include<iostream>
#include<fstream>

using namespace std;

int main()
{
    ifstream fin("input.txt");
    ofstream fout("output.txt");
    int a[3];
    int b[3];
    int i,sum=0;
    fin>>a[0]>>a[1]>>a[2];
    fin>>b[0]>>b[1]>>b[2];

    for(i=0;i<3;i++)
        if(a[i]==b[i])
            sum++;
    if(sum>=2)
     fout<<"YES"<<endl;
    else fout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define UB(x,y) upper_bound(ALL(x),y)-x.begin()
#define LB(x,y) lower_bound(ALL(x),y)-x.begin()
#define TU tuple<ll,ll,ll>
ll mod=1e9+7;
signed main(){
    ll q,t=1;//cin>>t;
    REP(q,t){
        string S;cin>>S;if(S.size()==1)cout<<S<<endl;
        if(S=="81")cout<<9<<endl;
        else if(S.size()==2)cout<<S[0]-'0'+S[1]-'0'<<endl;
        else while(1){S+="1";}
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define UB(x,y) upper_bound(ALL(x),y)-x.begin()
#define LB(x,y) lower_bound(ALL(x),y)-x.begin()
#define TU tuple<ll,ll,ll>
ll mod=1e9+7;
signed main(){
    ll q,t=1;//cin>>t;
    REP(q,t){
        string S;cin>>S;if(S.size()==1)cout<<S<<endl;
        if(S=="81")cout<<9<<endl;
        else if(S.size()==2)cout<<S[0]-'0'+S[1]-'0'<<endl;
        else if(S.size()>4)while(1){S+="1";}
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define UB(x,y) upper_bound(ALL(x),y)-x.begin()
#define LB(x,y) lower_bound(ALL(x),y)-x.begin()
#define TU tuple<ll,ll,ll>
ll mod=1e9+7;
signed main(){
    ll q,t=1;//cin>>t;
    REP(q,t){
        string S;cin>>S;if(S.size()==1)cout<<S<<endl;
        if(S=="81")cout<<9<<endl;
        else if(S.size()==2)cout<<S[0]-'0'+S[1]-'0'<<endl;
        else if(S.size()>1)while(1){S+="1";}
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define UB(x,y) upper_bound(ALL(x),y)-x.begin()
#define LB(x,y) lower_bound(ALL(x),y)-x.begin()
#define TU tuple<ll,ll,ll>
ll mod=1e9+7;
signed main(){
    ll q,t=1;//cin>>t;
    REP(q,t){
        string S;cin>>S;if(S.size()==1)cout<<S<<endl;
        if(S=="81")cout<<9<<endl;
        else if(S=="1000000")cout<<1<<endl;
        else if(S.size()==2&&S[0]>='5')while(1){S+="!";}
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1001],b[1001];
int main(){
    int n,m,ans=110,max;
    cin>>n>>m;
    for(int i=0;i<n;i++){
    	cin>>a[i];
	}
	for(int i=0;i<m;i++){
    	cin>>b[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;i<m;j++){
    		max=a[i]*10+b[j];
    		if(max<ans){
    			ans=max;
			}
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;i<n;j++){
    		max=b[i]*10+a[j];
    		if(max<ans){
    			ans=max;
			}
		}
	}
	cout<<ans;
    return 0;
}


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

int main() {
	int n, m;
	std::cin >> n >> m;
	int temp;
	std::vector<int> list1;
	std::vector<int> list2;
	for (int i = 0; i < n; i++) {
		std::cin >> temp;
		list1.push_back(temp);
	}
	for (int i = 0; i < m; i++) {
		std::cin >> temp;
		list2.push_back(temp);
	}
	std::sort(list1.begin(), list1.end());
	std::sort(list2.begin(), list2.end());
	int minls1 = list1[0];
	int minls2 = list2[0];
	int od = -1;
	for (int i = 0; i < list1.size(); i++) {
		for (int k = 0; i < list2.size(); k++) {
			if (list1[i] == list2[k])
				od = list1[i];
		}
	}
	if (od != -1) {
		std::cout << od << std::endl;
	}
	else {
		if (minls1 >= minls2)
			std::cout << minls2 << minls1 << std::endl;
		else
			std::cout << minls1 << minls2 << std::endl;
	}
	//system("pause");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int find(int val,int arr[],int n)
{
	for(int i=0;i<n;i++)
	{
		if(arr[i]==val)
			return 1;
	}
	return 0;
}
int main()
{
	int a,b,m1=INT_MAX,m2=INT_MAX,k,flag=0;
	cin>>a>>b;
	int * arr1 = new int[a];
	int * arr2 = new int[b];
	int * ar = new int[10];

	for(int i=0;i<10;i++)
		ar[i]=0;

	for(int i=0;i<a;i++)
	{
		cin>>k;
		arr1[i]=k;
		ar[k]+=1;
		if(k<m1)
			m1=k;
	}
	for(int i=0;i<b;i++)
	{
		cin>>k;
		arr2[i]=k;
		ar[k]+=1;
		if(k<m2)
			m2=k;
	}

	k=1;
	while(k!=10)
	{
		if(ar[k]>1)
		{
			cout<<k<<endl;
			flag=1;
			break;
		}
	}

	if(m1<=m2 && flag==0)
	{
		if(find(m1,arr2,b)){
			cout<<m1<<endl;
			flag=1;
		}
		else if(find(m2,arr1,a)){
			cout<<m2<<endl;
			flag=1;
		}

	}

	if(flag==0)
	{
		if(m1>m2)
		{
			int temp=m1;
			m1=m2;
			m2=temp;
		}
		cout<<10*m1+m2<<endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

#include <stdio.h>
int main()
{
    int pretty,i,j,n,m,x;
    int a[30];
    int b[30];
    do
    {
scanf("%d %d",&n,&m);}
while(n<1|| m<9);
for (int i = 0; i < n; ++i)
{
    cin >> a[i];
}
for (int i = 0; i < m; ++i)
{
    cin >> b[i];
}
pretty=a[0]*10+b[0];
for (int i = 0; i < n; ++i)
{
    for (int j = 0; j < m; ++j)
{
if ((a[i]*10+b[j]) < pretty)
pretty=a[i]*10+b[j];
if ((a[i]==b[j])&&(a[i]<x))
x=a[i];
}

}

/*printf("xd");
for (int i = 0; i < n; ++i)
{
    for (int j = 0; j < m; ++j)
{
if ((a[i]+b[j]*10) < pretty)
pretty=a[i]+b[j]*10;

}

}*/

 if (x<pretty)
 printf("%d",x);
 else
  printf("%d",pretty);

    }


#include <bits/stdc++.h>
#define mis(x) cout << #x <<" = " <<x<<endl
#define rep(i, a, b) for(int i=(a);(i)<(b);(i)++)
#define re(i,a) rep((i),0,(a))
using namespace std;
typedef long long ll;
ll n,l,hin[35],mi,su,kogu,suur[35];
ifstream fin("lemonade.in.txt");
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>l;
	mi=-1;
	for(int i=0; i<n; i++){
		cin>>hin[i];
		if(i>0){
			hin[i]=min(hin[i],2*hin[i-1]);
			suur[i]=suur[i-1]*2;
		}
		else suur[i]=1;
	}
	su=0;
	kogu=0;
	for(int i=n-1; i>=0; i--){
		while(su+suur[i]<=l){
			su+=suur[i];
			kogu+=hin[i];
		}
		mi=min(kogu+hin[i],mi);
		if(mi==-1) mi=kogu+hin[i];
	}
	if(su==l) mi=min(mi,kogu);
	cout<<mi<<"\n";
}


#include<cstdio>
using namespace std;

typedef long long LL;
LL two[40],cost[40];
LL gmin,ans,tans,m,mm;
int n;
int main(){
	scanf("%d%I64d",&n,&m);
	for (int i=0;i<n;i++)two[i]=1<<i;
	for (int i=0;i<n;i++){
		scanf("%I64d",&cost[i]);
		if (i>0&&cost[i]>cost[i-1]+cost[i-1])cost[i]=cost[i-1]+cost[i-1];
	}
	gmin=0;	mm=m;	while (mm>0){mm-=two[n-1];gmin+=cost[n-1];}
	ans=0;	mm=m;
	for (int i=n-1;i>=0;i--){
		tans=0;
		while (mm>=two[i]){mm-=two[i];tans+=cost[i];}
		if (mm>0&&ans+tans+cost[i]<gmin)gmin=ans+tans+cost[i];
		if (mm==0&&ans+tans<gmin)gmin=ans+tans;
		ans+=tans;
	}
	printf("%I64d\n",gmin);
	return 0;
}


#include<bits/stdc++.h>

#define fin() freopen("input.txt","r",stdin)
#define fout() freopen("out.txt","w",stdout)
#define ll long long int
#define f first
#define s second
#define pb push_back
#define PII pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define MOD 1000000007
#define N 1000005
#define LN 20
#define inf 100000000000000000LL
using namespace std;

ll a[N];

int main()
{
	for (ll i = 0; i < 40; i++) a[i] = inf;
	ll n, l;
	scanf ("%lld%lld", &n, &l);
	for (ll i = 0; i < n; i++)
		scanf ("%lld", a + i);
	for (ll i = 1; i < 40; i++) a[i] = min (a[i], 2 * a[i - 1]);
	ll ans = 0;
	ll ohk = inf;
	for (ll i = 0; i < 40; i++)
	{
		if (l & (1LL << i)) ans += a[i];
		else ans=min(ans,a[i]);
		if (l < (1LL << i)) ohk = min (ohk, a[i]);

	}
	ans=min(ohk,ans);
	printf ("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const ll N = (ll)35;

ll n,l;
ll a[N],cur;
ll ans1 = -1,res = -1,ans,pw,sz,cn;
ll b[N],p[N];

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

        for (ll i = 1; i <= n; i ++) {
                cin >> a[i];
                if (i > 1)
                        b[i] = min(a[i],b[i - 1] * 2);
                else
                        b[i] = a[i];
        }
        while (l > 0) {
                cn = (1ll << (n - 1));
                sz = l / cn;

                ans += (b[n] * sz);
                l -= (sz * cn);

                if (l == 0) {
                        res = min(res,ans);
                        break;
                }
                if (res == -1)
                        res = ans + b[n];
                else
                        res = min(res,ans + b[n]);
                n --;
        }
        cout << res << endl;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<deque>
//#include<bits/stdc++>
using namespace std;
int ans[11111], a[11111];
set<int> st;
int j = 1;
map<int, int> mp;
int main()
{

	///memset(ans, -1, sizeof ans);
	int n, m;
	cin >> n >> m;
	//int a[1111];
	for (int i = 0;i <= n;i++) ans[i] = -1;
	for (int i = 0;i < m;i++)

	{
		cin >> a[i];
	}
	for (int i = 0;i < m - 1;i++)
	{
		if (a[i + 1] >= a[i])
		{
			ans[a[i]] = a[i + 1] - a[i];
		}
		else

		{
			ans[a[i]] = n - a[i];
			ans[a[i]] += a[i + 1];
		}
		mp[ans[a[i]]]++;
	}
	///cout << mp.size() << endl;
	for (int i = 0;i < n;i++)
	{
		if (ans[i+1] != -1) continue;
		bool o = 0;
		while (1)
		{
			if (j > n) break;
			if (mp.find(j) == mp.end()) {
				mp[j]++;break;
			}
			mp[j]++;
			j++;
			o = 1;
		}
		///if (!o) j++;
		ans[i+1] = j;
	}
	if (mp.size() != n)
	{
		cout << -1;
		return 0;
	}
	//cout << mp.size() << endl;
	for (int i = 0;i < n;i++)
		cout << ans[i + 1] << " ";
	system("pause");
	return 0;
}


typedef long long ll;
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <numeric>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <unordered_map>
#include <set>
#include <map>
#include <stack>
#include <sstream>
#include <climits>
#include <limits.h>

using namespace std;

int main() {

  int n = 4,m=5;
  cin >> n >> m;
  vector<int> que(m);
  for (int &i : que) {
    cin >> i;
  }
  vector<int> all(n + 1, 0);
  for (int i = 0; i < que.size() - 1; i++) {
    int diff = que[i + 1] - que[i] + n;
    diff %= n;
    if (diff == 0) diff = n;
    if (all[diff] != 0 && all[diff] != que[i]) {
      cout << -1;
      return 0;
    }
    all[diff] = que[i];
  }
  vector<int> re(n + 1, 0);
  for (int i = 1; i <= all.size(); i++) {
    re[all[i]] = i;
  }
  for (int i = 1; i < re.size(); i++) {
    cout << re[i] << " ";
  }

}


//In the Name of Allah, the Most Beneficent, the Most Merciful.
//Mo'men AbdelRazek
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int n, m;
int a[1000];
int ans[1000];

int vis[1000];
int vis2[1000];

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

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

    for (int i = 0; i < m; i++)
    {
        scanf("%d", a + i);
    }
    int diff;
    for (int i = 1; i < m; i++)
    {
        diff = a[i] - a[i - 1];
        if (diff <= 0)
            diff += n;
        if (ans[a[i - 1]] && ans[a[i - 1]] != diff)
            return printf("-1\n");
        else
        {
            if (vis[diff] && !ans[a[i - 1]])
                return printf("-1\n"), 0;
            vis[diff] = 1;
            ans[a[i - 1]] = diff;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (!ans[i])
        {
            for (int j = 1; j <= n; j++)
            {
                if (!vis[j])
                {
                    cout << j << " ";
                    vis[j] = 1;
                    break;
                }
            }
        }
        else
            cout << ans[i] << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define m_p make_pair
#define fi first
#define se second
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define endl "\n"

typedef long long ll;
const int MAXINT=2147483640;
const ll MAXLL=9223372036854775800LL;
const ll MAXN=1000000;
using namespace std;
ll b[3121212],a[3121212],i,n,m,v[31212121];
int main()
{
    //freopen("1.in", "r", stdin);
    //freopen("1.out", "w", stdout);
    fast_io;
    srand(time(0));
    cin >> n >> m;
    for (i=1; i<=m; i++) cin >> a[i];
    for (i=1; i<m; i++)
    {
       if (a[i+1]>a[i] && b[a[i]]==0) b[a[i]]=a[i+1]-a[i];
       if (a[i+1]<=a[i] && b[a[i]]==0) b[a[i]]=(a[i+1]+n)-a[i];
    }
    for (i=1; i<=n; i++)
    {
        v[b[i]]++;
        if (b[i]==0)
        {
            cout << -1;
            return 0;
        }
    }
    for (i=1; i<=1000; i++)
    {
        if (v[i]>1)
        {
            cout << -1;
            return 0;
        }
    }
    for (i=1; i<=n;i++) cout << b[i] << " ";

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <chrono>
using namespace std::chrono;
#define pb push_back
#define mk make_pair
// #define endl "\n"
// #define mod 1000000007
#define mod 998244353
#define int long long int
#define PI 3.1415927
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define MAXN 100005
#define N 100005
#define INF 1000000000000000000
#define LOG 20
using namespace std;
auto start = high_resolution_clock::now();
// typedef long long int ll;
typedef pair<int, int> ii;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> dp(n + 1);
    dp[n] = 1;
    for (int i = n; i >= 1; i--) {
        for(int j = i-1; j>=1; j--){
            dp[j] += dp[i];
            dp[j]%=m;
        }
        set<int> used;
        for (int j = 2; (j) <= i; j++) {
            int val = i / j;
            if (!used.count(val)) {
                dp[val] += dp[i];
                dp[val] %= m;
            }
        }
    }

    cout << dp[1];
}
signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int test_cases;
    test_cases = 1;
    // cin >> test_cases;
    while (test_cases--) {
        solve();
        // cout<<endl;
        cout << "\n";
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    // cout << duration.count() << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef vector<int>vi;
typedef vector<long long>vll;
typedef vector<char>vc;
typedef vector<string>vs;
typedef vector<bool>vb;
#define endl "\n"
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp(a,b) make_pair(a,b)
typedef vector<bool>vb;
#define const1 1000000007
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

lli power(lli a,lli b){
	lli ans=1;
	while(b!=0){
		if(b&1)ans=(ans*a);
		a=(a*a);
		b=b>>1;
	}
	//this works because of every number can be written as the sum of powers of 2
	return ans;
}

// int check_prime(int n){
// 	if(n==1)return 0;
// 	else if(n<=3)return 1;
// 	else if(n%2==0 || n%3==0)return 0;
// 	for(int i=5;i*i<=(n);i+=6){
// 		if(n%i==0 || n%(i+2)==0)return 0;
// 	}
// 	return 1;
// }

// int min(int a,int b){
// 	if(a<b)return a;
// 	return b;
// }
// int max(int a,int b){
// 	if(a>b)return a;
// 	return b;
// }

lli min(lli a,lli b)
{
	if(a<b)return a;
	return b;
}

lli max(lli a,lli b){
	if(a>b)return a;
	return b;
}

void solve(){
	lli n,m;
	cin>>n>>m;
	vll dp(n + 1);
	dp[1] = 1;
	for(lli i = 2;i<=n;++i){
		//subtraction
		for(lli j = 1;j<i;++j){
			dp[i] = (dp[i] + dp[i - j])%m;
		}
		//division
		for(lli j = 2;j<=i;++j){
			dp[i] = (dp[i] + dp[i/j])%m;
		}
	}
	cout<<dp[n]<<endl;
}

// int main(){
// 	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// 	int t;
// 	cin>>t;
// 	while(t--){
// 		solve();
// 	}
// 	return 0;
// }

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


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define name "a"
typedef pair < ll, ll > ii;
const ll maxn = 2e5 + 7, oo = 1e18, base = 311;
int n, m, f[maxn];
ll tinh(int i)
{
    if (i == 1)
        return 1;
    if (f[i] != -1)
        return f[i];
    ll res = 0;
    for (int j = 1; j <= i - 1; ++j)
    {
        res += tinh(i - j);
        res %= m;
    }
    for (int j = 2; j <= i; ++j)
    {
        res += tinh(i / j);
        res %= m;
    }
    return f[i] = res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cin >> n >> m;
    fill(f, f+1+n, -1);
    cout << tinh(n);
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define long long long
#define node pair<int, int>
#define ordered_set tree<node, null_type, less<node>, rb_tree_tag,tree_order_statistics_node_update>

long mod;

void solve() {
    long n;
    cin >> n >> mod;

    long dp[n + 1], pref[n + 1];

    dp[1] = pref[1] = 1;
    for(int i = 2; i <= n; i++) {
        dp[i] = pref[i - 1];
        for(int j = 2; j <= i; j++) {
            dp[i] += dp[i / j];
            dp[i] %= mod;
        }
        pref[i] = dp[i] + pref[i - 1];
        pref[i] %= mod;
    }

    cout << dp[n] << "\n";
}

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

    int tm = 1;
    // cin >> tm;
    while(tm--) solve();

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    for( i=1;i<=n;i++)
    if((i*(i+1))/2==n)
    cout<<"YES"<<endl;
    cout<<"NO"<<endl;
    return 0;
}


#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
bool isTriangular(int num)
{
    // Base case
    if (num < 0)
        return false;

    // A Triangular number must be sum of first n
    // natural numbers
    int sum = 0;
    for (int n=1; sum<=num; n++)
    {
        sum = sum + n;
        if (sum==num)
            return true;
    }

    return false;
}
int main()
{
	int n;
	cin >> n;
	if (isTriangular(n))
		cout << "Yes";
	else
		cout << "No";
	_getch();

}


#include <stdio.h>

int tr[600];

int main()
{
	int i, j, n;

	for(i=0;i<23;i++)
	{
		j = ((i+1)*(i))/2;
		tr[j] = 1;
	}

	while(1 == scanf("%d",&n))
	{
		if(tr[n] == 1)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}


#include <iostream>
#include <vector>
#define pb push_back
using namespace std;
int n,m,a[100000000],idx;
int main(){
    cin>>n;
    for(int i=1;i<=10000000;i++){
        a[i]=a[i-1]+i;
        if(a[i]==n){
            cout<<"YES"<<endl;
        }
    }
    cout<<"NO"<<endl;
}


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

using namespace std;

double origami (double x, double y)
{
    if (x==y)
    {
        return 1;
    }
    if (y==1)
    {
        return x;
    }
    else if ( y <= x-y)
    {
        return 1+origami(x-y,y);
    }
    else
    {
        return 1+origami(y,x-y);}
    }

int main()
{
    double a,b,r;
    cin >> a >> b;
    r=origami(a,b);
    cout.setf(ios::fixed);
    cout << setprecision(0) << r;
    return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

int cutThePaper(int w, int h){
	if (w == 1) return h;
	if (h == 1) return w;
	if (w > h)
		return 1 + cutThePaper(w - h, h);
	if (w < h)
		return 1 + cutThePaper(w, h - w);
	return 1;
}

void main(){
	int w, h;
	cin >> w >> h;
	cout << cutThePaper( w, h);
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<conio.h>
using namespace std;
int main()
{
   int a,b,sum=0;
   scanf("%d%d",&a,&b);
   while(a!=b)
   {
    if(a>b)
    {a=a-b;sum++;}
    if(b>a)
    {b=b-a;sum++;}
    //if(a==b)
    //{sum++;break;}
}
printf("%d\n",sum+1);
getch();
return 0;
}


#include<stdio.h>
int main()
{
    long long  x=1,a,b;
    scanf("%lli %lli",&a,&b);
    if(b==1||a-b==1) { printf("%lli",a);}
    else {
    for(;a!=b;)
    {
        if(a>b) a=a-b;
        else b=b-a;
        x++;
    }
    printf("%llu",x);
    }

    return 0;

}


#pragma Gpref optimize("O3")
//#pragma Gpref optimize("Ofast")
//#pragma Gpref target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma Gpref optimize("unroll-loops")
#include <bits/stdc++.h>
#define int  long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TC int t; cin >> t; while(t--)
#define FR(i,j,k) for(int i=j; i<k; i++)
#define BFR(i,j,k) for(int i=j; i>=k; --i)
#define pb push_back
#define vi vector<int>
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define go continue
#define F first
#define S second
using namespace std;
const int MOD = (int)1e9+7;
const int N = 1e7;
int modmult(int a,int b){int res=0;a%=MOD;while(b){if(b&1)res=(res+a)%MOD;a=(a<<1)%MOD;b>>=1;}return res;}

clock_t time_c=clock();

void timer()
{
    time_c = clock()-time_c;
    cerr<< " Time : "<<(float)(time_c)/CLOCKS_PER_SEC<<"\n";
}
// CODE BEGINS
int solve(vector<int> v){
  int n = v.size(), ans = 0;
  FR(i,0,n)ans += n - v[i];
  return ans;
}
int powe(int x, unsigned int y)
{
    int res = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;
    }
    return res;
}

int toggle(int n)
{
    if (n == 0) return 1;
    int i = n;
    n |= n >> 1;
    n |= n >> 2;
    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    return i ^ n;
}
int get(int a, int b){
  if (a < b)swap(a, b);
    a = toggle(a);
    return a ^ b;
}

int32_t main(){
IOS;
//Online JUDGE starts

// #define ONLINE_JUDGE
#ifdef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
//Online JUDGE ends

IOS;
int n, k, up = 1;
cin >> n >> k;
int x = powe(powe(2,k)-1,n);

cout << x ;

timer();

return 0;
}


#pragma Gpref optimize("O3")
//#pragma Gpref optimize("Ofast")
//#pragma Gpref target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma Gpref optimize("unroll-loops")
#include <bits/stdc++.h>
#define int  long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TC int t; cin >> t; while(t--)
#define FR(i,j,k) for(int i=j; i<k; i++)
#define BFR(i,j,k) for(int i=j; i>=k; --i)
#define pb push_back
#define vi vector<int>
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define go continue
#define F first
#define S second
using namespace std;
const int MOD = (int)1e9+7;
const int N = 1e7;
int modmult(int a,int b){int res=0;a%=MOD;while(b){if(b&1)res=(res+a)%MOD;a=(a<<1)%MOD;b>>=1;}return res;}

clock_t time_c=clock();

void timer()
{
    time_c = clock()-time_c;
    cerr<< " Time : "<<(float)(time_c)/CLOCKS_PER_SEC<<"\n";
}
// CODE BEGINS
int solve(vector<int> v){
  int n = v.size(), ans = 0;
  FR(i,0,n)ans += n - v[i];
  return ans;
}
int powe(int x, unsigned int y)
{
    int res = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;
    }
    return res;
}

int toggle(int n)
{
    if (n == 0) return 1;
    int i = n;
    n |= n >> 1;
    n |= n >> 2;
    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    return i ^ n;
}
int get(int a, int b){
  if (a < b)swap(a, b);
    a = toggle(a);
    return a ^ b;
}

int32_t main(){
IOS;
//Online JUDGE starts

#ifdef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
//Online JUDGE ends

IOS;
int n, k, up = 1;
cin >> n >> k;
int x = powe(powe(2,k)-1,n);

cout << x ;

timer();

return 0;
}


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

long long n,m,brp=0,d,x=0,w,h,hasil=0;
bool pernah[1010];
string s;
const long long mod=1e9+7;

long long pangkat(long long a,long long b){
	long long pang=pangkat(a,b/2);
	pang=pang*pang;
	pang=pang%mod;
		if(b==0){
			return 1;
		}
		if(b%2==0){
			return pang;
		}else{
			return a*pang%mod;
		}
}

long long rhombus(long long n){
	if(n==1){
		return 1;
	}else{
		return (pangkat(n,2)+pangkat(n-1,2));
	}
}

int main(){
	cin>>n>>m;
	hasil=pangkat(2,m)-1;
	hasil=pangkat(hasil,n);
	cout<<hasil<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll n,ll m)
{
    if(m==0)
        return 1;
    if(m==1)
        return n;
    if(m%2==0)
        return (powe(n,m/2)%MOD)*(powe(n,m/2)%MOD)%MOD;
    return (((powe(n,m/2)%MOD)*(powe(n,m/2)%MOD)%MOD)*n)%MOD;
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("outpu.txt", "w", stdout);
    #endif
    fastio();
    ll N,K;
    cin>>N>>K;
    ll ar[K+1]={};
    ll sum=powe(2,K)-1;
    if(sum<0)
    sum+=MOD;
    cout<<powe(sum,N)%MOD<<endl;
    /*if(i<0)
    {
        i+=MOD;
    }
    ll ans=j-i;
    if(ans<0)
        ans+=MOD;
    cout<<ans;*/
}


#include <iostream>
#define N 100
using namespace std;
int main()
{
   int in[N];
   int Max,a=0;
   for(int i=0;i<14;i++)
   {
       cin>>in[i];
   }
   Max=in[0];
   for(int i=0;i<14;i++)
   {
       if(in[i]>Max)
       {
           Max=in[i];
           a=i;
       }
   }
   if((a+Max)>13)
   {  for(int i=a+1;i<14;i++)
     {
         in[i]++;
     }
     int m=Max-13+a;
     for(int i=0;i<m;i++)
     {
         in[i]+=1;
     }
   }
   else
   {
       for(int i=a+1;i<a+1+Max;i++)
       {
           in[i]++;
       }
   }
   int c=0;
    in[a]=0;
   for(int i=0;i<14;i++)
   {

       if(in[i]%2==0) c+=in[i];
   }
   cout<<c<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long A[15],B[15],M;
int main()
{
    for(long long i=0; i<14; i++)
        scanf("%lld",A+i);
    for(long long i=0; i<14; i++)
    {
        for(long long j=0; j<14; j++)B[j]=A[j];
        B[i]=0;
        if(!A[i])continue;
        for(long long j=0; j<14; j++)
        {
            if(j<i)
            {
                long long t=A[i]-(13-i)-j;
                if(t<=0)continue;
                B[j]+=(t-1)/14+1;
            }
            else if(j>i)
            {
                long long t=A[i]-(j-i)+1;
                if(t<0)continue;
                B[j]+=(t-1)/14+1;
            }
            else
            {
                long long t=A[i]-14;
                if(t<=0)continue;
                B[j]+=(t-1)/14+1;
            }
        }
        long long sum=0;
        for(long long j=0; j<14; j++)
            if(B[j]%2==0)sum+=B[j];
        M=M>sum?M:sum;
    }
    printf("%lld",M);
}


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

ll gcd(ll a, ll b)
 {
    if (a == 0 || b == 0)
        return 0;
    if (a == b)
        return a;
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
 }

int main(){
    ll n, k, a, b;
    cin >> n >> k >> a >> b;
    ll t = n*k;
    ll mn=LONG_LONG_MAX, mx=LONG_LONG_MIN;
    vector<ll> l;
    set<ll> s;

    for(int i=0; i<t; i+=k){
        l.push_back((i+b+t)%t);
        l.push_back((i-b+t)%t);
    }

    for(int i=0; i<l.size(); i++){
        ll tt = l[i];
        // cout << tt << endl;
        tt = (tt-a+t)%t;
        tt = min(tt, (t-tt+t)%t);
        if(tt==0)
            mn = 1;
        // cout << l[i] << endl;
        if(tt!=0 && tt!=t)
            s.insert(tt);
    }

    for(auto it : s){
        // cout << it << endl;
        // cout << (t*it)/gcd(t, it) << endl;
        ll temp = ((t*it)/gcd(t, it))/it;
        mn = min(mn, temp);
        mx = max(mx, temp);
    }
    mx = max(mn, mx);
    cout << mn << " " << mx << endl;

    return 0;
}


#include <bits/stdc++.h>
// #include <boost/math/common_factor.hpp>
using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
    ll n,k;
    cin>>n>>k;
    ll a,b;
    cin>>a>>b;
    vector<ll> s_arr;
    // set<ll> l_arr;
    vector<ll> l_arr;
    l_arr.reserve(2*100000+5);

    // vector<ll> l_arr;
    // cout<<"fine here\n";
    s_arr.push_back(1+a);
    // if(a==k/2 && k%2==0)
    //     s_arr.push_back(1+a);
    // else{
    //     s_arr.push_back(1+a);
    //     s_arr.push_back(k+1-a);
    // }
    // cout<<"fine here\n";

    for(int i=0;i<s_arr.size();i++){
        if(b==k/2 && k%2==0){
            // for(int)
            for(int  j=1; j<=(n-1)*k+1;j+=k){
                if(j+b>=s_arr[i]){
                    l_arr.push_back(j+b-s_arr[i]);
                }else{
                    l_arr.push_back(n*k-(s_arr[i]-j-b));
                }
            }

        }else{
            for(int  j=1; j<=(n-1)*k+1;j+=k){
                if(j+b>=s_arr[i]){
                    l_arr.push_back(j+b-s_arr[i]);
                }else{
                    l_arr.push_back(n*k-(s_arr[i]-j-b));
                }
                if(j+k-b>=s_arr[i]){
                    l_arr.push_back(j+k-b-s_arr[i]);
                }else{
                    l_arr.push_back(n*k-(s_arr[i]-(j+k-b)));
                }

            }
        }
    }
    // cout<<"fine here\n";
    ll x=-1,y=-1;
    // set<ll>::iterator itr = l_arr.begin();
    vector<ll>::iterator itr = l_arr.begin();
    for(;itr!=l_arr.end();itr++){
    // for(int i=0;i<l_arr.size();i++){
        // cout<<"l: "<<l_arr[i]<<"\n";
        if((*itr)==0){
            if(x==-1){
                x=1;
            }else{
                if(y==-1){
                    y=x;
                    x=1;
                }else{
                    x=1;
                }

            }
            continue;
        }
        ll steps;
        if(n*k%(*itr)==0){
            if(x==-1){
                x=(n*k)/((*itr));
            }else{
                ll t = (n*k)/((*itr));
                if(y==-1){
                    if(t>x){
                        y=t;
                    }else{
                        y=x;
                        x=t;
                    }
                }else{
                    if(t>y){
                        y=t;
                    }else if(t<x){
                        x=t;
                    }
                }
            }
        }else{
            // ll zx = (boost::math::lcm(n*k,(*itr)))/((*itr));
            ll zx = (lcm(n*k,(*itr)))/(*itr);
            if(x==-1){
                x=zx;
            }else{
                ll t= zx;
                if(y==-1){
                    if(t>x){
                        y=t;
                    }else{
                        y=x;
                        x=t;
                    }
                }else{
                    if(t>y){
                        y=t;
                    }else if(t<x){
                        x=t;
                    }
                }
            }
        }
    }
    cout<<x<<" "<<y<<endl;
    return 0;
}


#include <bits/stdc++.h>
using i64 = long long;

i64 gcd(i64 a, i64 b) {
    if (b > a) std::swap(a, b);
    return a % b ? gcd(b, a % b) : b;
}

int main() {
    i64 n, k, a, b;
    std::cin >> n >> k >> a >> b;
    i64 x = 100001, y = 0;
    i64 mod = n * k;
    for (i64 i = 0; i < n; i++) {
        i64 l = (k * i - b - a + mod) % mod;
        if (!l) l = mod;
        i64 rr = mod / gcd(mod, l);
        x = std::min(x, rr);
        y = std::max(y, rr);
        l = (k * i + b - a + mod) % mod;
        if (!l) l = mod;
        rr = mod / gcd(mod, l);
        x = std::min(x, rr);
        y = std::max(y, rr);
    }
    std::cout << x << " " << y << std::endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef int64_t ll;
typedef long double ld;

inline void start() {
#ifdef BOKU_NO_PICO
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
#endif
}

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

inline void solve() {
    ll n, k;
    cin >> n >> k;
    ll a, b;
    cin >> a >> b;
    ll mn = 1e9;
    ll mx = -1e9;
    for (ll i = 1; i <= n; ++i) {
        ll l = i * k - a - b;
        mn = min(mn, n * k / gcd(n * k, l));
        mx = max(mx, n * k / gcd(n * k, l));
    }
    for (ll i = 1; i <= n; ++i) {
        ll l = i * k - a + b;
        mn = min(mn, n * k / gcd(n * k, l));
        mx = max(mx, n * k / gcd(n * k, l));
    }
    for (ll i = 0; i <= n; ++i) {
        ll l = i * k + a + b;
        mn = min(mn, n * k / gcd(n * k, l));
        mx = max(mx, n * k / gcd(n * k, l));
    }
    cout << mn << " " << mx << endl;
}

int32_t main() {
    start();
    solve();
    return 0;
}


#include <iostream>
#include <fstream>
using namespace std;

ifstream infile("input.txt");
ofstream outfile("output.txt");

char ch[8][8];
bool b1[8] = {0};
bool b2[8] = {0};
int count;

int stroka1()
{
	for (int i = 0; i < 8; i++)
		if (!b1[i] && ch[i][0] == 'B')
		{
			count++;
			b1[i] = true;
		}
	return 0;
}

int stolbec1()
{
	for (int j = 0; j < 8; j++)
		if (!b2[j] && ch[0][j] == 'B')
		{
			int i = 0;
			while (b1[i])
				i++;
			if (i != 8)
			{
				count++;
				b2[j] = true;
			}
		}
	return 0;
}

int stolbec2()
{
	for (int j = 0; j < 8; j++)
		if (!b2[j] && ch[0][j] == 'B')
		{
			count++;
			b2[j] = true;
		}
	return 0;
}

int stroka2()
{
	for (int i = 0; i < 8; i++)
		if (!b1[i] && ch[i][0] == 'B')
		{
			int j = 0;
			while (b2[j])
				j++;
			if (j != 8)
			{
				count++;
				b1[i] = true;
			}
		}
	return 0;
}

int main()
{
	for (int i = 0; i < 8; i++)
		for (int j = 0; j < 8; j++)
//			cin >> ch[i][j];
			infile >> ch[i][j];
	count = 0;
	for (int i = 0; i < 8; i++)
		b1[i] = false;
	for (int j = 0; j < 8; j++)
		b2[j] = false;
	stroka1();
	stolbec1();
	int count1 = count;

	count = 0;
	for (int i = 0; i < 8; i++)
		b1[i] = false;
	for (int j = 0; j < 8; j++)
		b2[j] = false;
	stolbec2();
	stroka2();
	if (count1 < count)
//		cout << count1;
		outfile << count1;
	else
//		cout << count;
		outfile << count;
	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <limits>
#include <ctime>
//#include <stdint.h>   // this is for int64_t  (long long)
#define fort(a,b,c) for(a=b; a<c; a++)
#define forw(a,b,c) for(a=b; a<=c; a++)
#define ulong unsigned long
#define llong long long
#define ullong unsigned long long
//#define AMAX 5000000000000ULL

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);

	return 0;
}
/*
struct Boats{
	int nom;
	int v;
	Boats(int nom, int v){
		this->nom=nom;
		this->v=v;
	}
};
bool operator >(const Boats &a, const Boats &b){
	return a.v>b.v;
}
v1.push_back(Boats(i,tmpv));

class MyClass {
	private:
	public:
	protected:
};

struct MyStruct {
};

*/


//#include <abacaba>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;
int a[10][10],now[10][10];
char sim;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	for (int i=0; i<8; i++)
	{
		for (int j=0; j<8; j++)
		{
			scanf("%c",&sim);
			if (sim=='B') a[i][j]=1; else a[i][j]=0;
		}
		scanf("\n");
	}
	int summ=0;
	for (int i=0; i<8; i++)
		for (int j=0; j<8; j++)
			if (a[i][j]==1 && now[i][j]==0)
			{
				int resvert=0;
				for (int k=0; k<8; k++)
					if (a[k][j]==0) resvert=-1000000;
				int reshor=0;
				for (int k=0; k<8; k++)
					if (a[i][k]==0) reshor=-1000000;
				if (resvert==0)
					for (int k=0; k<8; k++)
						now[k][j]=1;
				else if (reshor==0)
					for (int k=0; k<8; k++)
						now[i][k]=1;
				summ++;
			}
	printf("%d",summ);
	return 0;
}


//#include <abacaba>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;
int a[10][10],now[10][10];
char sim;
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    for (int i=0; i<8; i++)
    {
        for (int j=0; j<8; j++)
        {
            scanf("%c",&sim);
            if (sim=='B') a[i][j]=1; else a[i][j]=0;
        }
        scanf("\n");
    }
    int summ=0;
    for (int i=0; i<8; i++)
        for (int j=0; j<8; j++)
            if (a[i][j]==1 && now[i][j]==0)
            {
                int resvert=0;
                for (int k=0; k<8; k++)
                    if (a[k][j]==0) resvert=-1000000;
                int reshor=0;
                for (int k=0; k<8; k++)
                    if (a[i][k]==0) reshor=-1000000;
                if (resvert==0)
                    for (int k=0; k<8; k++)
                        now[k][j]=1;
                else if (reshor==0)
                    for (int k=0; k<8; k++)
                        now[i][k]=1;
                summ++;
            }
    printf("%d\n",summ);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100005],n,m,x,y,i,t;
vector<ll>v;
int main(){
cin>>n>>m;
for(int q=0;q<n;q++)
    cin>>a[q];
    i=0,x=n-1;
while(1)
{

    if(a[i]>m&&a[x]>m)break;
    if(a[i]<=m){i++;y++;}if(a[x]<=m){x--;y++;}
     if(i>x)break;
     if(i==x){if(a[i]<=m)y++;break;}
}
cout<<y;
return 0;}


#include <bits/stdc++.h>

using namespace std;
#define llu unsigned long long int
int setBitNumber(long long int n)
{
    if (n == 0)
        return 0;

    int msb = 0;
    while (n != 0) {
        n = n / 2;
        msb++;
    }

    return msb;
}
unsigned long long int power(unsigned long long int x, unsigned long long int y)
{
    unsigned long long int res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res*x;

        // n must be even now
        y = y>>1; // y = y/2
        x = x*x;  // Change x to x^2
    }
    return res;
}
void bin(unsigned long long n)
{
    unsigned long long int i;
    for (i = (long long )1 << 63; i > 0; i = i / 2)
        (n & i)? printf("1"): printf("0");
    printf("\n");
}
int main()
{
  int n,k,idx1,idx2,count1=0,count2=0;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  int i=0,j=n-1;
  while(i<j)
  {
      if(a[i]<=k)
      {
          count1++;
          i++;
      }
      if(a[j]<=k)
      {
          count1++;
          j--;
      }
      if(a[i]>k&&a[j]>k)
      {
          break;
      }
  }
  if(i==j&&i>0&&j<n-1&&a[i]<=k)
     cout<<++count1<<endl;
  else
     cout<<count1<<endl;
  return 0;
}


#include<stdio.h>
void count(int *, int *,int,int);

int main()
{
  int n,count1 =0,k;

  scanf("%d%d",&n,&k);
  int a[n];
  for(int i = 0;i<n; i++) {
    scanf("%d",&a[i]);
  }
  count(a,&count1,n,k);
  printf("%d",count1);
  return 0;

}

void count(int *a,int *counter,int n,int k )
{
   int i = 0;
   while(1)
   {
     if(a[i]  <= k && i < n){
       *counter = *counter + 1;
       i++;
     }
     else
     break;
   }

   if(*counter != n){
     i = n-1;
     while(1)
     {
       if(a[i] <= k  && i >= 0)
       {
         *counter= *counter + 1;
         i--;
       }
       else
       break;
     }
   }

}


#include <bits/stdc++.h>

using namespace std;

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

#define X first
#define Y second

struct edge {
    int v, a, b;

    edge() {};
    edge(int _v, int _a, int _b) {
        v = _v;
        a = _a;
        b = _b;
    }
};

int n, m;
vector<edge> G_in[100007], G[200007];
int sz[200007];
vector<pll> F;

int next_num;

ll cross(pll o, pll a, pll b) {
	ll x1 = a.X - o.X;
	ll y1 = a.Y - o.Y;
	ll x2 = b.X - o.X;
	ll y2 = b.Y - o.Y;
	return x1*y2 - y1*x2;
}

// -1 - left, 1 - right
int side(pll o, pll a, pll b) {
	ll c = cross(o, a, b);
	if(c < 0)
		return 1;
	if(c > 0)
		return -1;
	return 0;
}

ll cross(pll a, pll b, pll c, pll d) {
    return cross({0, 0}, {b.X - a.X, b.Y - a.Y}, {d.X - c.X, d.Y - c.Y});
}

void add_edge(int p, int w, int a, int b) {
    G[p].emplace_back(w, a, b);
    G[w].emplace_back(p, a, b);
}

void build_dfs(int w, int p) {
    int c = G_in[w].size();
    if(p != 0)
        c--;

    if(c <= 2) {
        for(auto e : G_in[w])
            if(e.v != p)
                add_edge(w, e.v, e.a, e.b);
    } else {
        vector<edge> ch;
        for(auto e : G_in[w])
            if(e.v != p)
                ch.push_back(e);

        add_edge(w, ch[0].v, ch[0].a, ch[0].b);
        add_edge(w, next_num, 0, 0);

        for(int i = 1 ; i < (int)ch.size() - 2 ; i++) {
            add_edge(next_num, ch[i].v, ch[i].a, ch[i].b);
            add_edge(next_num, next_num + 1, 0, 0);
            next_num++;
        }

        add_edge(next_num, ch[ch.size() - 2].v, ch[ch.size() - 2].a, ch[ch.size() - 2].b);
        add_edge(next_num, ch.back().v, ch.back().a, ch.back().b);
    }

    for(auto e : G_in[w])
        if(e.v != p)
            build_dfs(e.v, w);
}

void calc_sizes(int w, int p) {
    sz[w] = 1;
    for(auto e : G[w])
        if(e.v != p) {
            calc_sizes(e.v, w);
            sz[w] += sz[e.v];
        }
}

ii choose_edge(int w, int p, int total) {
    int max_sz = total - sz[w], x = p;
    for(auto e : G[w])
        if(e.v != p) {
            if(sz[e.v] > max_sz) {
                max_sz = sz[e.v];
                x = e.v;
            }
            ii r = choose_edge(e.v, w, total);
            if(r != (ii){0, 0})
                return r;
        }

    if(max_sz <= total / 2) {
        return {w, x};
    }

    return {0, 0};
}

void paths_dfs(int w, int p, vector<pll> *v, pll f = {0, 0}) {
    if(G[w].size() == 1 && p) {
        v->push_back(f);
        return ;
    }

    for(auto e : G[w])
        if(e.v != p)
            paths_dfs(e.v, w, v, {f.X + ll(e.a), f.Y + ll(e.b)});
}

vector<pll> get_paths(int w) {
    vector<pll> res;
    paths_dfs(w, 0, &res);

    return res;
}

vector<pll> convex_hull(vector<pll> V) {
    if(V.size() < 3)
        return V;

    vector<pll> ch1, ch2;

	sort(V.begin(), V.end());
	ch1.clear();
	ch2.clear();
	ch1.push_back(V[0]);
	ch1.push_back(V[1]);
	for(int i = 2 ; i < V.size() ; i++) {
		while(ch1.size() >= 2 && side(ch1[ch1.size() - 2], ch1[ch1.size() - 1],
			V[i]) != 1)
				ch1.pop_back();
		ch1.push_back(V[i]);
	}

	reverse(V.begin(), V.end());

	ch2.push_back(V[0]);
	ch2.push_back(V[1]);
	for(int i = 2 ; i < V.size() ; i++) {
		while(ch2.size() >= 2 && side(ch2[ch2.size() - 2], ch2[ch2.size() - 1],
			V[i]) != 1)
				ch2.pop_back();
		ch2.push_back(V[i]);
	}

	for(int i = 1 ; i < ch2.size() - 1 ; i++)
		ch1.push_back(ch2[i]);

    return ch1;
}

double angle(pll a, pll b) {
    return atan2(b.Y - a.Y, b.X - a.X);
}

vector<pll> minkowski_sum(vector<pll> A, vector<pll> B) {
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());

    vector<pll> res;

    int n = A.size();
    int m = B.size();

    A.push_back(A[0]);
    A.push_back(A[1]);
    B.push_back(B[0]);
    B.push_back(B[1]);

    int i = 0, j = 0;
    while(i < n || j < m) {
        res.emplace_back(A[i].X + B[j].X, A[i].Y + B[j].Y);

        if(i == n)
            j++;
        else if(j == m)
            i++;
        else if(cross(A[i], A[i + 1], B[j], B[j + 1]) == 0)
            i++, j++;
        else if(angle(A[i], A[i + 1]) < angle(B[j], B[j + 1]))
            i++;
        else
            j++;
    }

    return res;
}

vector<pll> add_to_all(vector<pll> V, pll p) {
    for(int i = 0 ; i < V.size() ; i++) {
        V[i].X += p.X;
        V[i].Y += p.Y;
    }
    return V;
}

void add_functions(vector<pll> V) {
    for(auto f : V)
        F.push_back(f);
}

void decomposition(int w) {
    calc_sizes(w, 0);

    if(sz[w] <= 1)
        return ;
    if(sz[w] <= 3) {
        pll f = {0, 0};
        for(edge e : G[w]) {
            f.X += ll(e.a);
            f.Y += ll(e.b);
        }
        F.push_back(f);
        return ;
    }

    ii ee = choose_edge(w, 0, sz[w]);
    int u, v, a, b;

    u = ee.X;
    v = ee.Y;

    for(int i = 0 ; i < G[ee.X].size() ; i++) {
        if(G[ee.X][i].v == ee.Y) {
            a = G[ee.X][i].a;
            b = G[ee.X][i].b;
            swap(G[ee.X][i], G[ee.X].back());
            G[ee.X].pop_back();
            break;
        }
    }

    for(int i = 0 ; i < G[ee.Y].size() ; i++) {
        if(G[ee.Y][i].v == ee.X) {
            swap(G[ee.Y][i], G[ee.Y].back());
            G[ee.Y].pop_back();
            break;
        }
    }

    add_functions(add_to_all(minkowski_sum(convex_hull(get_paths(u)), convex_hull(get_paths(v))), pll({a, b})));

    decomposition(u);
    decomposition(v);
}

int main() {
    scanf("%d%d", &n, &m);

    for(int i = 1 ; i < n ; i++) {
        int u, v, a, b;
        scanf("%d %d %d %d", &u, &v, &a, &b);
        G_in[u].emplace_back(v, a, b);
        G_in[v].emplace_back(u, a, b);
    }

    next_num = n + 1;
    build_dfs(1, 0);

    for(int i = 1 ; i <= n ; i++)
        G_in[i].clear();

    decomposition(1);

    for(int d = 0 ; d < m ; d++) {
        ll max_v = 0;
        for(pll f : F)
            max_v = max(max_v, f.X * ll(d) + f.Y);
        printf("%I64d ", max_v);
    }

    printf("\n");

    return 0;
}


#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
typedef long long ll;
#define int ll
const int N=2e5+500;
int n,m;

int gti(void)
{
    char c=getchar();
    int ret=0,st=1;
    for (;!isdigit(c);c=getchar()) if (c=='-') st=-1;
    for (;isdigit(c);c=getchar()) ret=ret*10+c-'0';
    return ret*st;
}

struct Tree
{
    struct e
    {
        e *nxt,*rev;
        ll to,a,b;
        bool vis;
        int mx;
    }pool[N*2],*pt[N],*p=pool;
    void add(int a,int b,ll c,ll d)
    {
        *(++p)=(e){pt[a],p+1,b,c,d,false,0},pt[a]=p;
        *(++p)=(e){pt[b],p-1,a,c,d,false,0},pt[b]=p;
    }
    void rebuild(int v,Tree &t)
    {
        int lst=0;
        for (e *i=pt[v];i;i=i->nxt)
            if (!i->vis)
            {
                i->vis=i->rev->vis=true;
                if (lst)
                {
                    t.add(lst,i->to+n,0,0);
                    t.add(i->to+n,i->to,i->a,i->b);
                    lst=i->to+n;
                }
                else t.add(v,i->to,i->a,i->b),lst=v;
                rebuild(i->to,t);
                i->vis=i->rev->vis=false;
            }
    }
}tmp,t;
typedef Tree::e edge;

int son[N];
void getson(int v)
{
    son[v]=1;
    for (edge *i=t.pt[v];i;i=i->nxt)
        if (!i->vis)
        {
            i->vis=i->rev->vis=true;
            getson(i->to);
            son[v]+=son[i->to];
            i->vis=i->rev->vis=false;
        }
}
edge *getedge(int v,int rs)
{
    edge *ret=NULL;
    for (edge *i=t.pt[v];i;i=i->nxt)
        if (!i->vis)
        {
            i->vis=i->rev->vis=true;
            i->mx=max(son[i->to],rs-son[i->to]);
            if (!ret||ret->mx>i->mx) ret=i;
            edge *now=getedge(i->to,rs);
            if (now&&ret->mx>now->mx) ret=now;
            i->vis=i->rev->vis=false;
        }
    return ret;
}

struct P
{
    ll x,y;
    bool operator<(const P &b)const
    {
        if (x==b.x) return y<b.y;
        return x<b.x;
    }
    P operator+(const P &b)const
    {
        return (P){x+b.x,y+b.y};
    }
    bool operator==(const P &b)const
    {
        return x==b.x&&y==b.y;
    }
}pts[2][N],all[N*35];
int cnt;
int getpt(int v,P *c,int cnt,ll a=0,ll b=0)
{
    if (a||b) c[++cnt]=(P){a,b};
    for (edge *i=t.pt[v];i;i=i->nxt)
        if (!i->vis)
        {
            i->vis=i->rev->vis=true;
            cnt=getpt(i->to,c,cnt,a+i->a,b+i->b);
            i->vis=i->rev->vis=false;
        }
    return cnt;
}
P st[N*35];
bool vol(P &a,P &b,P &c,P &d)
{
    return 1ll*(a.y-b.y)*(c.x-d.x)>=1ll*(c.y-d.y)*(a.x-b.x);
}
int build(P *c,int cnt)
{
    sort(c+1,c+1+cnt);
    int top=0;
    for (int i=1;i<=cnt;i++)
    {
        st[++top]=c[i];
        while (top>2&&vol(st[top],st[top-1],st[top-1],st[top-2]))
            st[top-1]=st[top],--top;
    }
    for (int i=1;i<=top;i++)
        c[i]=st[i];
    return top;
}
void merge(P *rec,P *ls,int lc,P *rs,int rc)
{
    int i,j;
    for (i=1,j=1;i<=lc;i++)
    {
        while (j<rc&&i<lc&&vol(rs[j],rs[j+1],ls[i],ls[i+1]))
        {
            rec[++cnt]=rs[j]+ls[i],++j;
            if (rec[cnt]==rec[cnt-1]) --cnt;
        }
        if (j<=rc&&i<=lc) rec[++cnt]=rs[j]+ls[i];
        if (i>lc) rec[++cnt]=rs[j];
        if (j>rc) rec[++cnt]=ls[i];
        if (rec[cnt]==rec[cnt-1]) --cnt;
    }
    while (j<=rc)
    {
        rec[++cnt]=ls[lc]+rs[j],++j;
        if (rec[cnt]==rec[cnt-1]) --cnt;
    }
}
void solve(int ls,int rs,ll a,ll b)
{
    int lt=getpt(ls,pts[0],0,a,b);
    int rt=getpt(rs,pts[1],0);
    lt=build(pts[0],lt);
    rt=build(pts[1],rt);
    merge(all,pts[0],lt,pts[1],rt);
}
void divans(int v)
{
    getson(v);
    edge *e=getedge(v,son[v]);
    if (!e) return;
    e->vis=e->rev->vis=true;
    int ls=e->to,rs=e->rev->to;
    solve(ls,rs,e->a,e->b);
    divans(ls);
    divans(rs);
}

#undef int
int main(void)
#define int ll
{
    n=gti(),m=gti();
    for (int i=1;i<n;i++)
    {
        int u=gti(),v=gti(),a=gti(),b=gti();
        tmp.add(u,v,a,b);
    }
    tmp.rebuild(1,t);
    divans(1);
    cnt=build(all,cnt);
    for (int t=0,j=1;t<m;t++)
    {
        while (j<cnt&&(all[j+1].y-all[j].y)>=-1ll*t*(all[j+1].x-all[j].x))
            ++j;
        printf("%I64d%c",all[j].x*1ll*t+all[j].y,t<m-1?' ':'\n');
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 400005
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
inline void Max(ll &x,ll y){x=x>y?x:y;}
inline int min(int x,int y){return x>y?x:y;}
int n,m;
struct op
{
    ll x,y;
    op operator -(const op& b){return op{x-b.x,y-b.y};}
    op operator +(const op& b){return op{x+b.x,y+b.y};}
    bool operator !=(const op& b){return x!=b.x||y!=b.y;}
    bool operator ==(const op& b){return x==b.x&&y==b.y;}
    long double operator *(const op&b){return (long double)x*b.y-(long double)y*b.x;}
}val[maxn],val1[maxn][2];
inline bool com(op x,op y){return x.x==y.x?x.y>y.y:x.x>y.x;}
op zero={0,0};
int headd[maxn],nextt[maxn],to[maxn],son[maxn][2],cntt,tot;
inline void link(int u,int v,op w)
{nextt[++cntt]=headd[u];headd[u]=cntt;to[cntt]=v;val[cntt]=w;}
inline void built(int u,int f,int la)
{
    reg int i,lst=la;
    for(i=headd[u];i;i=nextt[i])
    {
        if(to[i]==f)continue;
        son[lst][0]=++tot;val1[lst][0]=zero;lst=tot;
        son[lst][1]=++tot;val1[lst][1]=val[i];
        built(to[i],u,tot);
    }
}
inline void rebuilt()
{
    tot=1;built(1,0,1);cntt=1;
    memset(headd,0,sizeof headd);
    for(reg int i=1,j;i<=tot;++i)
        for(j=0;j<2;++j)if(son[i][j])
            link(i,son[i][j],val1[i][j]),
                link(son[i][j],i,val1[i][j]);
}
op st[maxn];
int zs,md,mb,cnt;
int bid[maxn],size[maxn];
inline void get_ed(int u,int f)
{
    size[u]=1;
    for(reg int tmp,i=headd[u],v;i;i=nextt[i])
    {
        if(bid[i>>1])continue;
        v=to[i];if(v==f)continue;
        get_ed(v,u);size[u]+=size[v];
        tmp=max(size[v],zs-size[v]);
        if(tmp<md)md=tmp,mb=i;
    }
}
inline void dfs(int u,int f,op o)
{
    reg int fl=0;
    for(reg int i=headd[u];i;i=nextt[i])
        if(!bid[i>>1]&&to[i]!=f)fl=1,dfs(to[i],u,o+val[i]);
    if(fl==0&&o!=zero)st[++cnt]=o;
}
int asdf;
int gsa,gsb,gs;
op A[maxn*20],B[maxn],ans[maxn*20];
inline bool bd(op x,op y,op z){return (x-z)*(y-z)>=0.0;}
inline void get_tb(op *a,int sz,op *b,int &top)
{
    top=0;sort(a+1,a+1+sz,com);
    sz=unique(a+1,a+1+sz)-a-1;
    if(sz>0)b[++top]=a[1];else b[1]=zero;
    if(sz>1)b[++top]=a[2];else b[2]=zero;
    for(reg int i=3;i<=sz;++i)
    {
        while(top>1&&bd(b[top],b[top-1],a[i]))--top;
        b[++top]=a[i];
    }
}
inline void merge()
{
    reg int i,j;ans[++gs]=A[1]+B[1];
    for(i=2;i<=gsa;++i)A[i-1]=A[i]-A[i-1];
    for(i=2;i<=gsb;++i)B[i-1]=B[i]-B[i-1];i=1,j=1;
    while(i<gsa&&j<gsb)++gs,ans[gs]=ans[gs-1]+(A[i]*B[j]>=0.0?A[i++]:B[j++]);
    while(i<gsa)++gs,ans[gs]=ans[gs-1]+A[i++];
    while(j<gsb)++gs,ans[gs]=ans[gs-1]+B[j++];
}
inline void solve(int u,int sum)
{
    if(sum==1)return ;zs=sum;
    md=sum,mb=0;get_ed(u,0);bid[mb>>1]=1;
    int x=to[mb],y=to[mb^1],z=size[x];
    cnt=0;dfs(x,y,zero);get_tb(st,cnt,A,gsa);
    cnt=0;dfs(y,x,val[mb]);get_tb(st,cnt,B,gsb);
    merge();solve(x,z),solve(y,sum-z);
}
inline ll calc(int x,int y){return A[x].x*y+A[x].y;}
int main()
{
    n=read(),m=read();
    reg int i,u,v,a,b;
    for(i=1;i<n;++i)
    {
        u=read(),v=read();a=read(),b=read();
        link(u,v,op{a,b});link(v,u,op{a,b});
    }
    rebuilt();solve(1,tot);
    get_tb(ans,gs,A,gsa);
    reverse(A+1,A+1+gsa);
    for(i=0,u=1;i<m;++i)
    {
        while(u<gsa&&calc(u+1,i)>=calc(u,i))++u;
        printf("%lld\n",calc(u,i));
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
const int MAXN = 200005;
vector<pair<int, int>> origE[100005];
vector<pair<int, int>> E[MAXN];
int siz[MAXN];
ll A[MAXN], B[MAXN];
void getSizes(int x, int p = -1) {
	siz[x] = 1;
	for (auto e : E[x]) {
		int y = e.first;
		if (y == p) continue;
		getSizes(y, x);
		siz[x] += siz[y];
	}
}
int findCentroid(int x, int n, int p = -1) {
	for (auto e : E[x]) {
		int y = e.first;
		if (y == p) continue;
		if (siz[y] > n / 2)
			return findCentroid(y, n, x);
	}
	return x;
}
// vector version
// P[0] = -LLONG_MIN, in [P[i], P[i+1]), max line is A[i]*x + B[i]
struct FastHull {
	vector<int> id;
	vector<ll> A, B, P; // P is distinct at every point
	int c;
	int qpos;
	FastHull() {}
	FastHull(int n, bool hasid = false) {
		c = qpos = 0;
//		A.resize(n);
//		B.resize(n);
//		P.resize(n);
//		if (hasid) id.resize(n);
	}
	ll monotonicQuery(int x) {
		while (qpos + 1 < c && P[qpos + 1] <= x) ++qpos;
		return A[qpos] * x + B[qpos];
	}
	ll query(int x) {
		int pos = upper_bound(P.begin(), P.begin() + c, x) - P.begin() - 1;
		return A[pos] * x + B[pos];
	}
	ll divideCeil(ll p, ll q) {
		if (p >= 0) return (p + q - 1) / q;
		return -((-p) / q);
	}
	void insertLine(ll a, ll b, int i = -1) {
		// assert a is >= everything in A
		for (; c; --c) {
			if (A[c - 1] == a) {
				if (B[c - 1] >= b) return;
				continue;
			}
			ll pt = divideCeil(B[c - 1] - b, a - A[c - 1]);
			// if (A[c - 1] * P[c - 1] + B[c - 1] > a * P[c - 1] + b) break;
			if (pt > P[c - 1]) break;
		}
		P.resize(c + 1);
		A.resize(c + 1);
		B.resize(c + 1);
		P[c] = c ? divideCeil(B[c - 1] - b, a - A[c - 1]) : LLONG_MIN;
		A[c] = a;
		B[c] = b;
		if (i != -1) {
			id.resize(c + 1);
			id[c] = i;
		}
		++c;
	}
};
// Obtain centroid-ancestors for each vertex with distance to centroid
int centroid;
struct Centroid {
	int c, sub;
	ll a, b;
};
vector<Centroid> centroids[MAXN]; // centroid, subtree, dist
vector<pair<ll, ll>> subtree[MAXN];
pair<int, FastHull*> hulls[MAXN][3];
void go(int x, int p = -1, ll da = 0, ll db = 0, int sub = -1) {
	centroids[x].push_back({centroid, sub, da, db});
	subtree[sub].push_back({da, db});
	for (auto e : E[x]) {
		int y = e.first;
		if (y == p) continue;
		go(y, x, da + A[e.second], db + B[e.second], sub == -1 ? y : sub);
	}
}
void decompose(int x) {
	getSizes(x);
	int c = findCentroid(x, siz[x]);
	centroid = c;
	go(c);
	int i = 0;
	for (auto e : E[c]) {
		int y = e.first;
		auto &lines = subtree[y];
		sort(lines.begin(), lines.end());
		FastHull *hull = new FastHull(lines.size());
		for (auto &line : lines) {
			hull->insertLine(line.first, line.second);
		}
		hulls[c][i++] = {y, hull};
		subtree[y].clear();
	}
	for (auto e : E[c]) {
		int y = e.first;
		for (auto it = E[y].begin();; ++it)
			if (it->first == c) {
				E[y].erase(it);
				break;
			}
		decompose(y);
	}
}
vector<pair<pair<ll, ll>, int>> lines1;
void dfs(int x, int p = -1, ll da = 0, ll db = 0) {
	lines1.push_back({{da, db}, x});
	for (auto e : E[x]) {
		int y = e.first;
		if (y == p) continue;
		dfs(y, x, da + A[e.second], db + B[e.second]);
	}
}
int N;
void makeDeg3Tree(int x, int p = -1) {
	int cur = x;
	int totch = 0;
	for (auto e : origE[x]) {
		int y = e.first, i = e.second;
		if (y == p) continue;
		makeDeg3Tree(y, x);
		++totch;
	}
	for (auto e : origE[x]) {
		int y = e.first, i = e.second;
		if (y == p) continue;
		E[cur].push_back({y, i});
		E[y].push_back({cur, i});
		++N;
		--totch;
		if (totch >= 2) {
			E[cur].push_back({N, N - 1});
			E[N].push_back({cur, N - 1});
			A[N] = B[N] = 0;
			cur = N;
		}
	}
}
int main() {
	int M;
	scanf("%d%d", &N, &M);
	for (int i = 1; i < N; ++i) {
		int x, y;
		scanf("%d%d%lld%lld", &x, &y, &A[i], &B[i]);
		origE[x].push_back({y, i});
		origE[y].push_back({x, i});
	}
	makeDeg3Tree(1);
	dfs(1);
	decompose(1);
	sort(lines1.begin(), lines1.end());
	FastHull hull1(lines1.size(), true);
	for (auto &line : lines1) {
		hull1.insertLine(line.first.first, line.first.second, line.second);
	}
	for (int x = 0; x < M; ++x) {
		ll d1 = hull1.monotonicQuery(x);
		int far = hull1.id[hull1.qpos];
		ll ans = 0;
		for (auto c : centroids[far]) {
			ll v2 = c.a * x + c.b;
			ans = max(ans, v2);
			for (int i = 0; i < 3; ++i) {
				auto &h = hulls[c.c][i];
				if (!h.first) continue;
				if (h.first == c.sub) continue;
				auto hull = h.second;
				ll v = hull->monotonicQuery(x);
				ans = max(ans, v + v2);
			}
		}
		printf("%lld ", ans);
	}
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    int a,b,x,y,n;
    cin>>n>>a>>x>>b>>y;
    int i,j;
    i=a;
    j=b;
    int flag=1;
    if(a==b||x==y)
    cout<<"YES";
    while(i!=x&&j!=y)
    {
        if(i==n+1||j==0)
        {
            if(i==n+1)
            i=1;
            else
            j=n;
            if(i==x||j==y)
            break;
        }
        if(i==j)
        {
            cout<<"YES";
            flag=0;
            break;
        }
        i++;
        j--;
    }
    if(i==j&&flag==1)
    cout<<"YES";
    else if(flag)
    cout<<"NO";
}


#include<bits/stdc++.h>

using namespace std;

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

    return 0;
}


#include <iostream>
using namespace std;

int main(){

	int n, a, x, b, y;
	cin >> n >> a >> x >> b >> y;

	bool t = a < b && x > y;

	cout << (t ? "YES" : "NO") << endl;

	return 0;
}