#if 01
/*******************************************************************************
* Author       : Quantum Of Excellence
* email        : quantumofexcellence (at) gmail (dot) com
* copyright    : 2014 - 2015
* date         : 21 - 11 - 2015
* Judge Status :
* Problem Category :
* file name    : 9C.cpp
* version      : 1.0
*
* TERMS OF USE - Write a mail to the author before copying or reusing the content of this file
* seeking our permission for the same.
* Copying/reuse of the below code without the permission of the author is prohibited and illegal.
*
* All rights reserved by Quantum Of Excellence.
******************************************************************************/

/*******************************************************************************
* some pointers on the logic/idea -
*   Inspired from submission - 2795185. user - "FredaShi".
*
* .............
*/

#pragma once
#ifndef _QL_PRECOMPILATION_BARE_MINIMUM_HPP_
#define _QL_PRECOMPILATION_BARE_MINIMUM_HPP_

// Include file for std::cout, std::cin
#include<iostream>
#include <fstream>

// for itoa - does not work on some compilers(despite including cstdlib)
#include <cstdlib>
// for getch()
#include<stdio.h>

// For clock time and time duration stats
#include <time.h>

#include <map>
#include <vector>
#include <string>
#include <cstring>

#include <set>
#include <algorithm>
#include <utility>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <complex>
#include <valarray>
#include <iterator>

using namespace std;

namespace QoE_Library{

    namespace QL_Bare_Minimum{

        // constants
        // -----------------------------------------
        const double PI = 3.141592653589793238460;
        // const values
        const long double pi=10000*acos(-1.0L);
        const long double E= 2.7182818284590452353;
        const long double eps=1e-10;

        // 2 D array movement
        // -----------------------------------------
        const int DX4[]={0,1,0,-1};
        const int DY4[]={1,0,-1,0};
        const int DX8[]={-1,-1,-1,0,0,1,1,1};
        const int DY8[]={-1,0,1,-1,1,-1,0,1};
        const int neigh4[][2]={{-1,0},{1,0},{0,-1},{0,1}};
        const int neigh8[][2]={{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1}};
        const int neigh9[][2]={{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{0,0}};

        template <typename T1> class Vector3D{
        public:
            T1 x,y,z;
            Vector3D(T1 x1,T1 y1,T1 z1):x(x1),y(y1),z(z1){
            }
            Vector3D(){}
        };

#define SETZERO(a) memset(a,0,sizeof(a))
#define SETVAL(a,val) memset(a,val,sizeof(a))
#define SETDP(a) memset(a,-1,sizeof(a))

        // check whether indices in range of an array/matrix or values
#define in_bounds(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define in_range(x, lo, hi) (x <= hi && x >= lo )

        // get min of 3 values
#define min3(a,b,c) (a<min(b,c))?a:min(b,c)
#define max3(a,b,c) ((a>max(b,c))?a:max(b,c))

        // convert char into index
#define CHAR_TO_INDEX(c,startC) ((int)c - (int)startC)

        // Array size
#define SZ_ARR(A) sizeof(A)/sizeof(A[0])
        // STL MACROS -
#define SZ(C) C.size()

#define ALL(x) (x).begin(), (x).end()

#define NOT_FOUND(x,val) ((x).find(val)==(x).end())

        //pair
#define MKP(i,j) make_pair(i,j)
        // Map
#define M_Ins(_m_,i,j) _m_.insert(make_pair(i,j))

        // vector
#define PB(A,B) A.push_back(B);

        // STL sort()
#define SORT(A) sort( A.begin(),A.end() )

        // For loop
#define FOR(i, first, last, increment) for (int i = (first); i < (last); i = i + (increment))
#define QL_FOR FOR

#define DEBUGGING 1

        // Default For loop with variable name "i", first = 0, increment = 1
#define FOR_DEF(i, last) QL_FOR(i, 0, last, 1)
#define QL_FOR_DEF FOR_DEF

        // Dont care about the looping variable name
        // TODO : Need to solve the problem of generating a unique temp loop var, for now __i__ suffices
#define REPEAT(N) for (int __i__ = 0; __i__ < (N); ++__i__)

        // Reverse For loop
#define R_FOR(i, first, last, increment) for (int i = ((first) - 1); i >= (last); i = i - (increment))
#define QL_R_FOR R_FOR

        // Default For loop with variable name "i", first = 0, increment = 1
#define R_FOR_DEF(i, first) QL_R_FOR(i, first, 0, 1)
#define QL_R_FOR_DEF R_FOR_DEF
#if 0
#define FOR_STL(i,stl) for(typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#endif

#define EXISTS(c,e) ((c).find(e)!=(c).end())

        // For loop for map
#define QL_M_FOR(m,T1,T2,it) for(map<T1,T2>::iterator it=m.begin();it!=m.end();++it)
#define QL_M_R_FOR(m,T1,T2,rit) for(map<T1,T2>::reverse_iterator rit=m.rbegin();rit!=m.rend();++rit)

#if 0
#define QL_M_FOR(m,it) QL_M_FOR(m,int,int,it)   // for(map<int,int>::iterator it=m.begin();it!=m.end();++it)
#define QL_M_R_FOR(m,rit) QL_M_R_FOR(m,int,int,it)   //for(map<int,int>::reverse_iterator rit=m.rbegin();rit!=m.rend();++rit)
#endif

        typedef unsigned long long int ulli_t;
        typedef ulli_t ULLI;
        typedef vector<ulli_t> uivector_t;
        typedef uivector_t::iterator uivector_it_t;
        typedef uivector_t::const_iterator uivector_cit_t;

        typedef long long int lli_t;
        typedef lli_t LLI;
        typedef vector<lli_t> ivector_t;
        typedef ivector_t::iterator ivector_it_t;
        typedef ivector_t::const_iterator ivector_cit_t;

        // pair
        typedef pair<int,int> p_ii_t;
        typedef p_ii_t P_II;
        typedef pair<LLI,LLI> p_llilli_t;
        typedef p_llilli_t P_LLILLI;

        // vector
        typedef vector<int> v_i_t;
        typedef v_i_t V_I;
        typedef vector<LLI> v_lli_t;
        typedef v_lli_t V_LLI;
        typedef vector<ULLI> v_ulli_t;
        typedef v_ulli_t V_ULLI;

        typedef vector<p_ii_t> v_p_ii_t;
        typedef v_p_ii_t V_P_II;

        typedef vector<v_i_t> vv_i_t;
        typedef vv_i_t VV_I;
        typedef vector<v_p_ii_t> vv_p_ii_t;
        typedef vv_p_ii_t VV_P_II;

        typedef vector<string> v_s_t;
        typedef v_s_t V_S;

        //map
        typedef map<int,int> M_II;
        typedef M_II::iterator M_II_IT;
        typedef M_II::reverse_iterator M_II_RIT;

        // multimap
        typedef multimap<int,int> MM_II;
        typedef MM_II::reverse_iterator MM_II_RIT;

        //queue
        typedef queue<int> q_i_t;
        typedef q_i_t Q_I;

        typedef long double ld_t;
        typedef ld_t LD;

        /*  ------- BEWARE -    macros can't be overloaded i.e. both the 'read's below
        can't have the same name    ---------- */
#define read1(n) cin >> n;
#define read2(m, n) cin >> m >> n;
#define read3(m, n, o) cin >> m >> n >> o;
        // #define readArr(n, size) QL_FOR_DEF(i, size) { cin >> n[i]; }
#define readArr1D(n, size)  QL_FOR_DEF(i, size) \
        {                   \
        cin >> n[i];    \
        }

#define write1(n) cout << n;
#define write2(m, n) cout << m << n;
#define write3(m, n, o) cout << m << n << o;
#define writeArr1D(n, size) QL_FOR_DEF(i, size) \
        {                   \
        cout << n[i];   \
        }

#define DBG(x)              cout<<__LINE__<<" :: "<<#x<< ": "<<x<<endl;
#define DBG2(x, y)          cout<<__LINE__<<" :: "<<#x<< ": "<<x<<" | "<<#y<< ": "<<y<<endl;
#define DBG3(x, y, z)       cout<<__LINE__<<" :: "<<#x<< ": "<<x<<" | "<<#y<< ": "<<y<<" | "<<#z<<": "<<z<<endl;
#define DBG4(a, b, c, d)    cout<<__LINE__<<" :: "<<#a<< ": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

        /* stoi,itos and atoi & itoa functions parse only a single int to string and
        vice-a-versa. The below function can do it for any number of data in the string.
        As shown below.

        A more convenient tool to use is - sscanf().
        sscanf(s.c_str(),"%d%c%d",&a,&c,&b);
        */
        template<typename T1> inline T1 to_type(string s){
            T1 a;
            istringstream sin(s);
            sin>>a;
            // for 3 data values to be parsed from the string do -
            //sin>>a>>b>>c;
            return a;
        }
        template<typename T1> inline string to_str(T1 a){
            ostringstream sout;
            string s;
            sout>>a;
            // for 3 data values to be converted to string do -
            //sout>>a>>b>>c;
            return sout.str();
        }

        inline void inpS(char *a){
            scanf("%s", a);
        }

        // Fast reading Integer from stdin.
        inline int inpI(/*int &n*/) {
            int n = 0;
            int ch = getchar();
            // int ch = getchar_unlocked();
            int sign = 1;
            while(ch < '0' || ch > '9') {
                if (ch == '-') sign = -1;
                ch = getchar();
                // ch = getchar_unlocked();
            }
            while(ch >= '0' && ch <= '9')
                n = (n<<3) + (n<<1) + ch - '0', ch = getchar();
            // n = (n<<3) + (n<<1) + ch - '0', ch = getchar_unlocked();
            n = n*sign;

            return n;
        }
        inline void inpI2(int &a,int &b){
            a=inpI();
            b=inpI();
        }
        inline void inpI3(int &a,int &b,int &c){
            a=inpI();
            b=inpI();
            c=inpI();
        }

        inline double inpD() {
            double res = 0.0;
            char c;
            while(1) {
                c = getchar();
                // c = getchar_unlocked();
                if(c == ' ' || c == '\n') continue;
                else break;
            }
            res = c - '0';
            while(1) {
                c = getchar();
                // c = getchar_unlocked();
                if(c >= '0' && c <= '9') res = 10 * res + c - '0';
                else break;
            }
            if(c == '.') {
                double decimal = 0.0, divi = 1.0;
                while(1) {
                    c = getchar();
                    // c = getchar_unlocked();
                    if(c >= '0' && c <= '9') decimal += (c - '0') / (divi *= 10.0);
                    else break;
                }
                res += decimal;
            }
            return res;
        }

        inline void outpD(double N) {
            char buff[24],sz=0;
            int integer = N;
            int decimal = (N - integer) * 10000000;
            int tmp = decimal;

            while(decimal) {
                buff[sz++] = '0' + decimal % 10;
                decimal /= 10;
            }
            for(int decimal2 = 1000000; decimal2 > tmp; decimal2 /= 10) {
                buff[sz++] = '0';
            }
            buff[sz++] = '.';
            if(integer == 0) buff[sz++] = '0';
            while(integer) {
                buff[sz++] = '0' + integer % 10;
                integer /= 10;
            }
            while(--sz>=0)
                putchar(buff[sz]);
            // putchar_unlocked(buff[sz]);
            putchar(10);
            // putchar_unlocked(10);
        }
        inline void outpI(int a) {
            char c;
            char snum[20];
            int i=0;
            int sign = 0;
            if(a < 0) sign = 1;
            a = abs(a);
            do {
                snum[i++]=a%10+48;
                a=a/10;
            } while(a!=0);
            i=i-1;
            if(sign)
                putchar('-');
            // putchar_unlocked('-');

            while(i>=0)
                putchar(snum[i--]);
            // putchar_unlocked(snum[i--]);
            putchar('\n');
            // putchar_unlocked('\n');
        }
        inline void outpI2(int a,int b){
            printf("%d ",a);
            outpI(b);
        }
        inline int outpS(char *s){
            return printf("%s\n",s);
        }
        /*  // Giving 'function defined twice' error while running Graph.cpp Code
        void reorderLLI(LLI &x, LLI& y){
        LLI xCopy, yCopy;
        if (x < y){
        y = xCopy;
        x = yCopy;
        }
        }

        void reorderI(int &x, int& y){
        int xCopy, yCopy;
        if (x < y){
        y = xCopy;
        x = yCopy;
        }
        }
        */
        template<typename T1> void QL_swap(T1 &x, T1 &y){
            /*  Below code is risky
            x = x+y;
            y = x-y;
            x = x-y;
            */
            T1 tmp;
            tmp=x;
            x=y;
            y=tmp;
        }

        // commented while using Graph class.
#if 0
        void QL_swapChars(char *a,char *b){
            char tmp=*a;
            *a=*b;
            *b=tmp;
        }
#endif

        /*  Note - Lesson Learnt - return type should also be promoted while overloading the operator,
        otherwise buggy code.
        Also, if a & b have return type ULLI and LLI, we'll get ambiguity error. Both types
        should be unsigned in order to make it unambiguous.
        As if int is promoted to ULLI, both would be promoted or both would not be.
        */
        /*  NOTE - gcd{a,b} = gcd{|a|, b} = gcd{a,|b|} = gcd{|a|, |b|}
        And gcd(a,0) = a.
        */
        template<typename T1> T1 gcd(T1 a, T1 b) {
            if (!b)return a;
            return gcd(b, a%b);
        }
        LLI euclideanDistSq(LLI x1,LLI y1,LLI x2,LLI y2){

            return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
        }
        template<typename T> LD euclideanDist(T x1,T y1,T x2,T y2){
            return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
        }
        // Scalar product
        template<typename T1> T1 dotProd(T1 x1,T1 y1,T1 z1,T1 x2,T1 y2,T1 z2){
            return x1*x2+y1*y2+z1*z2;
        }
        // Vector product
        template<typename T1> Vector3D<T1> crossProd(Vector3D<T1> v1, Vector3D<T1> v2){
            Vector3D<T1> v;
            v.x=v1.y*v2.z - v2.y*v1.z;
            v.y=v1.z*v2.x - v2.z*v1.x;
            v.z=v1.x*v2.y - v2.x*v1.y;
            return v;
        }
    }
}
#endif  // _QL_PRECOMPILATION_BARE_MINIMUM_HPP_

#if 01
using namespace QoE_Library::QL_Bare_Minimum;

#define PRINT_TIME 0
#define GEN_TEST_CASES 0
#define MAT_SIZE 1005

/*  Test cases -
input-

output-
*/

const int MX=1<<24;
int x[25],y[25],graph[25][25],dp[MX+1],pred[MX+1];
int main(){
#if PRINT_TIME
    clock_t t = clock();
#endif

#if 0
    FILE *fIn = freopen("G:\\DUMP\\input.in", "r", stdin);
    //FILE *fOut = freopen("G:\\DUMP\\output.out", "w", stdout);
    //FILE *fLog = freopen("G:\\DUMP\\log.log", "w", stderr);
    //assert(fIn&&fOut&&fLog);
#endif
    int n,m;
    cin>>n;
    V_I v;
    m=n;
    while(m){
        PB(v,m%10);
        m/=10;
    }
    int l=SZ(v);
    int r=0;//(1<<l-1)-1;
    bool f=1;
    QL_FOR_DEF(i,l){
        if(!v[l-1-i])continue;
        else if(v[l-1-i]>1){
            int t=1<<l-i;
            // 0 not to be counted
            --t;
            r+=t;
            f=0;
            break;
        }else r+=(1<<l-1-i)-1;
    }

    // if the number itself is valid, count
    if(f)++r;

    cout<<r<<endl;
#if PRINT_TIME
    t = clock() - t;
    // printf("time = %Ld", (double)t/CLOCKS_PER_SEC);
    cout << "time = " << (double)t/CLOCKS_PER_SEC;
#endif
}
#endif
#endif


#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
typedef unsigned long long ull;
const int inf=103974182;
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
	ll n,k,a,b;
	cin>>n>>k>>a>>b;
	bool f=false;
	ll now=0;
	while(n!=1)
	{
		if(n<k)
		{
			cout<<(n-1)*a+now<<endl;
			return 0;
		}
		else if(f)
		{
			cout<<(n-1)*a+now<<endl;
			return 0;
		}
		else
		{
			now+=(n%k)*a;
			n-=(n%k);
			int t1=(n-n/k)*a;
			int t2=b;
			if(t1<t2)
			{
				f=true;
			}
			else
			{
				n/=k;
				now+=b;
			}
		}
	}
	cout<<now<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define FOR_OPEN(NAME, A, B) for (int NAME = A; NAME < B; ++NAME)
#define FOR_CLOSE(NAME, A, B) for (int NAME = A; NAME <= B; ++NAME)
using ll = long long;
using namespace std;

ll f(ll a, ll b) // a < b
{
    ll ans = 1;
    for(int i = 2; i <= a; ++i)
    {
        if(a % i == 0 && b % i == 0) ans = i;
    }
    return ans;
}

/*
x,y가 홀수이고 곱은 N이다.

이 두개의 최소공배수가 N이 아닌 x,y를 찾아라
*/
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll X;
    cin >> X;

    ll ans = X;
    for(int i = 2; i * i < X; ++i)
    {
        if(X % i != 0) continue;

        ll a = i, b = X / i; // Always a < b
        if(b % a != 0 && !(a % 2 == 0 && b % 2 == 0)) ans = i;
    }

    cout << ans << ' ' << X / ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
    }
    for(ll i = 2; i < n; i++){
        if( (a[i] ^ a[i - 1]) < a[i - 2]){
            cout << 1 << endl;
            return;
        }
    }

    vector<ll> pre(n, 0);

    for(ll i = 1; i <= n; i++){
        pre[i] = a[i - 1] ^ pre[i - 1];
    }
    ll ans = 1e10;
    ll flag = 0;
    for(ll m = 1; m < n; m++){
        for(ll l = m - 1; l >= 0; l--){
            for(ll r = m + 1; r <= n; r++){
                if( (pre[r] ^ pre[m]) < (pre[m] ^ pre[l]) ){
                    ans = min(ans, r - m - 1 + m - l - 1);
                    flag = 1;
                }
            }
        }
    }
    if(!flag){
        cout << -1 << endl;
    }
    else cout << ans << endl;
}

int main(){
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}


/*
//Author : Rezwanul Islam Maruf
//AUST ,CSE
//25-th batch..
*/

#include <stdio.h>
#include <iostream>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <list>
#include <cstdlib>
#include <set>

#define FOR(i,n) for(i=1;i<=n;i++)
#define REP(i,n) for(i=0;i<n;i++)
#define init(i,a,n) for(i=0;i<n;i++)a[i]=i
#define inf 10109999990
#define ms0(a) memset(a,0,sizeof(a))
#define msn(a,n) memset(a,n,sizeof(a))
#define i64 long long
#define i64U unsigned long long
#define DB double
#define LD long double
#define eps 1e-10
#define SQR(x) ((x)*(x))
#define pb push_back
#define all(x) sort(x.begin(),x.end())
#define II ({int a; scanf(" %d", &a); a;})
#define DD ({DB a; scanf(" %lf", &a); a;})
#define LL ({i64 a; scanf(" %lld", &a); a;})
#define CS printf("Case %d: ",cs++)
#define PI 3.1415926535897932384626433832795

#define FRD freopen("in.txt", "r", stdin)
#define FWR freopen("out.txt", "w", stdout)

int aComp(const void * a, const void * b){return (*(int*)a-*(int*)b );}
int dComp(const void * a, const void * b){return (*(int*)b-*(int*)a );}
//qsort (array,size, sizeof(int), aComp);

//Debugger
#define debug_matrix(mat,row,col)for(int i=0;i<row;i++){for(int j=0;j<col;j++) cout<<mat[i][j]<<" ";cout<<endl;}
#define debug_val(x) cout<<x<<endl
#define debug_arr(x,n){for(int i=0;i<=n;i++){if(i)cout<<" ";cout<<x[i];}cout<<endl;}
//

using namespace std;
int cs = 1;
#define mod 1073741824

int  F(int  x)
{
    set<int>ss;
    int  i,sq=sqrt(x)+1;
    for(i = 1;i <= sq;i++)
    {
       if(x%i)continue;
       ss.insert(i);
       ss.insert(x/i);
    }
    return ss.size() ;
}

int main()
{

    int a = II , b = II ,c = II ;
    int i,j,k,ans = 0;
    FOR(i,a)FOR(j,b)FOR(k,c) ans = (ans + F(i*j*k) )%mod;
   printf("%d\n",ans);
     //  FOR(i,a)FOR(j,b)FOR(k,c) cout << (i*j*k)  << endl ;}
   //for(int i = 1 ;i <=10 ;i++)cout << F(i) << " ";
  // system("pause");
}


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

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

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

int main(void)
{
	uint64_t t, w, b;
	cin >> t >> w >> b;
	uint64_t l = lcm(w, b);
	uint64_t q = t / l;
	uint64_t ans = q * min(w, b);
	ans += min(w, b) - 1;
	uint64_t g = gcd(ans, t);
	cout << ans / g << "/" << t / g;
	return 0;
}


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

int main () {
int a,b,n,per,pisl;
cin>>n>>a>>b;
per=n-a;
pisl=n-b+1;
if (per<pisl) {
              cout<<per<<endl;
              }
if (pisl<per) {
              cout<<pisl<<endl;
              }
if (pisl==per) {
               cout<<per<<endl;
               }
system("pause");
return 0;
}


    #include <bits/stdc++.h>
    #define INF 999999999999
    #define mx 100500
    #define ll long long
    #define uns unsigned
    #define turbo ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);using namespace std;
    using namespace std;
    int cnt,n,a[102],b[102],f,s;
int main()
{
        turbo
    for (int i=1;i<=3;i++) cin>>a[i],f+=a[i];
    for (int i=1;i<=3;i++) cin>>b[i],s+=b[i];
        cin>>n;

    if (f<=5&&f>0) cnt+=1;
    if (s<=10&&s>0) cnt+=1;

    while (f>5)
    {
        cnt+=1,f-=5;
    }
    while (s>10)
    {
        cnt+=1,f-=10;
    }

        if (cnt<=n) cout<<"YES";
            else cout<<"NO";

           return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cassert>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef double db;
typedef long long ll;
typedef unsigned int usi;
const int X[] = {-1, 1, 0, 0};
const int Y[] = {0, 0, -1, 1};
const int N = 22;
const int T = 8;
const int H = 8 * 200 + 2;
bool use[H + 3][N][N][1<<8];
int n, m, c[T];
char a[N][N];
int cntob, good, num[N][N], cstmask[1<<8];
bool check(int x, int y)
{
  return x >= 0 && x < n && y >= 0 && y < m && num[x][y] == -1;
}
void relax(int h, int x, int y, usi ms)
{
  use[h][x][y][ms] = true;
}
ll vect(int ax, int ay, int bx, int by)
{
  return 1LL * ax * by - 1LL * ay * bx;
}
const db EPS = 1e-7;
bool isinter(int ax, int ay, int bx, int by, int cx, int cy, int d2x, int d2y)
{
  int d1x = bx - ax, d1y = by - ay;
  ll vc1 = vect(cx - ax, cy - ay, d2x, d2y);
  ll vc2 = vect(cx - ax, cy - ay, d1x, d1y);
  ll cp = vect(d1x, d1y, d2x, d2y);
  //cout << d1x << " " << d1y << " " << d2x << " " << d2y << endl;
  db t1 = vc1 * 1.0 / cp;
  db t2 = vc2 * 1.0 / cp;
  assert(cp != 0);
  //cout << (vc1 && vc1 <= cp && 0 <= vc2) << endl;
  return 0 <= t1 && t1 <= 1.0 + EPS && 0 <= t2;
}

pair <int, int> lstob[T], lch[T];

int main()
{
  srand(time(NULL));
  int sx, sy;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
    {
      cin >> a[i][j];
      if (isdigit(a[i][j]) || a[i][j] == 'B') cntob++;
      if (a[i][j] == 'S')
      {
        sx = i;
        sy = j;
      }
      good += '0' <= a[i][j] && a[i][j] <= '9';
    }
  for (int i = 0; i < good; ++i) cin >> c[i];
  for (int i = good; i < cntob; ++i) c[i] = -3000;

  int cpgood = good;
  memset(num, -1, sizeof num);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (a[i][j] == '#') num[i][j] = -2;
      else if (isdigit(a[i][j]))
        num[i][j] = a[i][j] - '0' - 1;
      else if (a[i][j] == 'B')
        num[i][j] = good++;

  good = cpgood;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (num[i][j] >= 0) lstob[num[i][j]] = mp(i, j);
  for (int i = 0; i < cntob; ++i)
    lch[i] = mp(rand(), rand());

  use[0][sx][sy][0] = true;
  int tot = 1<<cntob;

  for (int h = 0; h < H; ++h)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j)
        for (int ms = 0; ms < tot; ++ms)
          if (use[h][i][j][ms])
            for (int c = 0; c < 4; c++)
            {
              int nx = i + X[c];
              int ny = j + Y[c];
              //cout << nx << " " << ny << endl;
              if (check(nx, ny))
              {
                usi intr = 0;
                for (int ob = 0; ob < cntob; ++ob)
                  intr |= (1<< ob) * isinter(2 * i + 1, 2 * j + 1, 2 * nx + 1, 2 * ny + 1, 2 * lstob[ob].f + 1, 2 * lstob[ob].s + 1, lch[ob].f, lch[ob].s);

                relax(h + 1, nx, ny, ms ^ intr);
              }
            }
  int ans = 0;
  for (int ms = 0; ms < tot; ++ms)
  {
    bool has = false;
    for (int j = good; j < cntob; ++j)
      has |= (ms>>j)&1;
    if (has) continue;
    int cr = 0;
    for (int j = 0; j < good; ++j)
      if ((ms>>j)&1) cr += c[j];
    for (int h = 0; h <= H; ++h)
      if (use[h][sx][sy][ms])
        ans = max(ans, cr - h);
    //if (ans == 380)
  }
  cout << ans;
  return 0;
}


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

const int MAX_N = 22+5;

int n;
int a[MAX_N];
int b[MAX_N];
set <int> s;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s.insert(a[i]);
	}
	if(n == 1){
		cout<<a[0]<<endl;
		return 0;
	}
	if(s.size()!=n){
		cout<<-1<<endl;
		return 0;
	}
	int sw = 0;
	for(int offset = n-1 ; offset >=1 ; offset--){
		for(int i=0;i<n;i++){
			b[(i+offset)%n]=a[i];
		}
		sw = 1;
		for(int i=1;i<(1<<n)-1;i++){
			long long sum = 0;
			for(int j=0;j<n;j++)if((1<<j)&i){
				sum += a[j];
				sum -= b[j];
			}
			if(sum == 0){
				sw = 0;
				break;
			}
		}
		if(sw == 1){
			break;
		}
	}
	if(sw == 1){
		for(int i=0;i<n;i++){
			cout<<b[i]<<" ";
		}
	}else{
		cout<<1/0<<endl;
		cout<<-1<<endl;
	}
}


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

int comp(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}

int min(int a, int b) {
	return a < b ? a : b;
}

int n, m, a, b;
int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &a, &b);
	if (a % m == 1 && (b % m == 0 || b == n)) {
		printf("1");
		return 0;
	}
	if (((a - 1) / m == (b - 1) / m) || m == 1) {
		printf("1");
		return 0;
	}
	if (a % m == 1 || b % m == 0 || b == n) {
		printf("2");
		return 0;
	}
	if ((a % m - 1 == (b % m)) || (a % m == 0 && (b + 1) % m == 0) || (m == 2)) {
		printf("2");
		return 0;
	}
	int x = 0;
	for (int i = a; i < b; i++)
		if (i % m == 0)
			x++;
	if (x < 2) {
		printf("2");
		return 0;
	}
	printf("3");
	return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>
#include <stack>
#include <Windows.h>
#include <time.h>
#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pb push_back
typedef vector<int> vi;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pb push_back
typedef vector<int> vi;

template<typename TA>
TA mins(TA a, TA b)
{
	return a < b ? a : b;
}
template <class T>
int bsearch(T *arr, int size, T value)
{
	int l = 0;
	int r = size;
	while (l <= r)
	{
		int mid = l + (r - l) / 2;
		if (arr[mid] == value)
			return 1;
		if (arr[mid] < value)
			l = ++mid;
		if (arr[mid] > value)
			r = --mid;
	}
	return -1;
}

class X {
public:
	int v;
	X(void) :v(0.345436){}
	X(const X&){}
	X(INT a) :v(a){}
	friend const X operator++(X& i, int);
	friend const X operator--(X& i);
	friend bool  operator==(const X& i, const X&l);
};
bool operator==(const X& i, const X&l)
{

	return i.v == l.v;
}
const X operator++(X& i, int){
	X oldValue(i.v);
	i.v++;
	return oldValue;
}
const X operator--(X& i) {
	i.v--;
	return i;
}

int Prime(unsigned long a)
{
	unsigned long i, j, bound;
	if (a == 0 || a == 1)
		return 0;
	if (a == 2 || a == 3 || a == 5)
		return 1;
	if (a % 2 == 0 || a % 3 == 0 || a % 5 == 0)
		return 0;
	bound = sqrt((double)a);
	i = 7; j = 11;
	while (j <= bound && a%i && a%j)
	{
		i += 6; j += 6;
	}
	if (j <= bound || i <= bound && a%i == 0)
		return 0;
	return 1;
}
long long bin_pow(int a, int b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		long long ans = bin_pow(a, b / 2);
		return (ans*ans);
	}
	else
	{
		return bin_pow(a, b - 1)*a;
	}

}

int GR[12345][12345] = { 0, 0 };
int distance1[111111];
int count1, index1, i1, u1;
bool visited1[11111];

void Dijkstra(int st, const int V)
{
	for (i1 = 1; i1 <= V; i1++)
	{
		distance1[i1] = INT_MAX; visited1[i1] = false;
	}
	distance1[st] = 0;
	queue<int>qii;
	qii.push(st);
	while (!qii.empty()){

		u1 = qii.front();
		qii.pop();
		visited1[u1] = true;
		for (i1 = 1; i1 <= V; i1++){
			if (!visited1[i1] && GR[u1][i1] && distance1[u1] + GR[u1][i1] < distance1[i1]){
				distance1[i1] = distance1[u1] + GR[u1][i1];
				qii.push(i1);
			}
		}
	}

}

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

	cout << bin_pow(n-2,2);

	return 0;
}


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

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ALL(G) (G).begin(),(G).end()

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int INF = 1000000009;

const int MAXN = 300*1000;

int n, m;
vector<int> graph[2][MAXN + 3];
int deg[3][MAXN + 3];
bool important[MAXN + 3];
bool semi[MAXN + 3], compromise[MAXN + 3];
vector<int> cand[MAXN + 3];
vector<int> V;

void TopSort(){
    queue<int> Q;
    for(int i=1; i<=n; i++){
        if(deg[2][i] == 0)
            Q.push(i);
    }

    while(!Q.empty()){
        int v = Q.front();
        Q.pop();

        V.pb(v);
        for(auto u : graph[0][v]){
            deg[2][u]--;
            if(deg[2][u] == 0)
                Q.push(u);
        }
    }
}

void Solve(int ind){
    set<int> S;
    for(int i=1; i<=n; i++){
        if(deg[ind][i] == 0)
            S.insert(i);
    }

    for(int i=0; i<n; i++){
        int v = V[i];
        S.erase(v);
        if(S.size() > 0)
            important[v] = false;
        if(S.size() == 1){
            int u = *(S.begin());
            bool esc = false;
            for(auto z : graph[ind][u])
                if(deg[ind][z] == 1){
                    esc = true;
                    break;
                }
            if(!esc)
                cand[v].pb(u);
            else
                compromise[v] = true;
        }
        if(S.size() > 1)
            compromise[v] = true;

        for(auto u : graph[ind][v]){
            deg[ind][u]--;
            if(deg[ind][u] == 0)
                S.insert(u);
        }
    }
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=0; i<m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        graph[0][a].pb(b);
        graph[1][b].pb(a);
        deg[0][b]++;
        deg[1][a]++;
        deg[2][b]++;
    }

    TopSort();
    for(int i=1; i<=n; i++) important[i] = true;
    Solve(0);
    reverse(V.begin(), V.end());
    Solve(1);
    for(int i=1; i<=n; i++)
        semi[i] = (!compromise[i]) && (cand[i].size() == 1 || (cand[i].size()==2 && (cand[i][0] == cand[i][1])));

    int ans = 0;
    for(int i=1; i<=n; i++)
        ans += (important[i] || semi[i]);
    printf("%d\n", ans);

//     for(int i=1; i<=n; i++)
//         printf("%d ", important[i]);
//     puts("");
//     for(int i=1; i<=n; i++)
//         printf("%d ", semi[i]);
//     puts("");
//     for(int i=1; i<=n; i++){
//         printf("%d: ", i);
//         for(auto u : cand[i])
//             printf("%d ", u);
//         puts("");
//     }
return 0;
}


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

const int maxn=100;
char a[maxn];
int b[maxn];

main()
{
    int s=0;
    cin>>a;
    for(int i=0;i<maxn;i++)
    {
        b[i]=a[i];
        if(b[i]>64 && b[i]<91)
        {
            s=s+1;
        }
    }
    for(int i=0;i<maxn;i++)
    {
        if(s>1)
        {
            if(b[i]>64 && b[i]<91)
            {
                a[i]=b[i]+32;
            }
        }
        if(s<2)
        {
            if(b[i]>96 && b[i]<123)
            {
            a[i]=b[i]-32;
            }
        }
    }

    cout<<a;
	getch();
}


#include <iostream>

using namespace std;

int main()
{

    int n;
    bool w;
    string a;
    while(1)
    {
        cin>>a;
        cin>>n;
        string arr[n];
        for(int i = 0;i < n;i++)
        {
            cin>>arr[i];
        }

        for(int i =0;i < n;i++)
        {
            if (a[0] == arr[i][1])
            {
                for(int i = 0;i < n;i++)
                {
                    if (a[1] == arr[i][0])
                    {
                        w = true;
                        cout<<"YES"<<endl;
                        break;
                    }
                }

            }

        }
        if (w != true)
        cout<<"NO"<<endl;
    }

    return 0;
}


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

int main()
{
    int n,i,j,m,c,a,f=0;
    cin >> n>>m;
    vector<int>bk;
    vector<int>fr;
    for(i=1;i<=n;i++)
    {
        if(f==0)
        {
            if(i==m)
            {
                f=1;
            }
            else
            {
                bk.push_back(i);
            }
        }
        else if(f==1)
        {
             fr.push_back(i);
        }

    }
    if(bk.size()>fr.size())
    {
        if(bk.size()>1){
        cout<<bk[bk.size()-1];
        }
        else cout<<m;
    }
    else if(bk.size()<fr.size()){
            if(fr.size()>1){
        cout<<fr[0];
            }
            else
            {
                cout<<m;
            }
    }
    else{
        if(bk.size()==0 || bk.size()==1)
        {
            cout<<m;
        }
        else{
            cout<<fr[0];
        }
    }
}


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

#define umap unordered_map
#define uset unordered_set
#define NULL_VAL -1
#define EXISTS(m, a) (m.find(a) != m.end())
#define SET_SAFE(m, condition, key, value, default) m[key] = ((condition) ? (value) : (default))
#define SET_IF_NOT_EXISTS(m, key, value, default) m[key] = SET_SAFE(m, EXISTS(m, key),  key, value, default)
#define GET_IF_EXISTS(m, a) (EXISTS(m, a) ? m[(a)] : NULL_VAL)
#define T ull t; cin>>t; while(t--)
#define PRINT_ARR(A, m, n) for(ull i=(m); i<(n); i++){ cout<<A[i]<<" "; } cout<<endl
#define MOD 1000000009

typedef unsigned long long int ull;
typedef long long int ll;
string alpha = "abcdefghijklmnopqrstuvwxyz";

void solve();

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

bool isSubsequence(string A, int start, int mid, int end){
	//cout<<start<<mid<<end<<endl;
	int s1 = (mid-start)<(end-mid+1)?start:mid;
	int e1 = (mid-start)<(end-mid+1)?mid-1:end;
	int s2 = (mid-start)<(end-mid+1)?mid:start;
	int e2 = (mid-start)<(end-mid+1)?end:mid-1;

	int c = 0;
	while(s1<=e1 && s2<=e2){
		//cout<<s1<<s2<<e1<<e2<<endl;
		if(A[s1] == A[s2]){
			s1++;
			s2++;
		}
		else {
			s2++;
			c++;
		}
	}

	if(c<=1){
		return true;
	}
	else{
		return false;
	}

}

void solve(){
	ull n;
	cin>>n;
	ull A[n-9];

	if(n<10){
		cout<<1;
	}
	else{
		A[0] = 2;
		for(int i=11; i<=n; i++){
			ull a = i;
			ull min = i;
			A[i-10] = i;
			while(a!=0){
				if(A[i-(a%10)-10]+1 < min){
					min = A[i-(a%10)-10]+1;
				}
				a/=10;
			}

			A[i-10] = min;
		}
		//PRINT_ARR(A, 0, n-10);
		cout<<A[n-10];
	}

}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define maxn 300005
#define mod 1E9 + 7;

const int INF = 1E9;

bool check(int n){
    while (n > 0){
        if (n % 10 == 4 || n % 10 == 7){
            n /= 10;
        }
        else
            return false;
    }
    return true;
}

int main(){

    int n;
    cin >> n;

    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (check(i))
            ans++;
    }

    cout << ans;

    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int maxn = 105;
char str[maxn];
int a[maxn];
int main()
{
    int k;
    while(scanf("%d",&k))
    {
        memset(a,0,sizeof(a));
        scanf("%s",str);
        int l = 0;
        int flag = 0;
        for(int i = 0; i < k; i++)
        {
            if(str[i] == 'B')
            {
                flag = 1;
                a[l]++;
            }
            if(str[i] == 'W' && flag)
                l++;

        }

        if(flag && l == 0)  {printf("1\n%d\n",a[0]);continue;}
        if(!flag) {printf("0\n");continue;}
        printf("%d\n",l);
        for(int i = 0; i <= l; i++)
        {
            if(i && a[i]!= 0) printf(" ");
            if(a[i]!= 0)
            printf("%d",a[i]);
        }
        cout << endl;
    }
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <math.h>
#include <cstring>
#include <time.h>
#include <complex>
#include <algorithm>
#include <queue>
#include <unordered_map>

#pragma warning(disable:4996)
#pragma GCC optimize(3)

template<typename T> T min(T x, T y)
{
	return x < y ? x : y;
}
template<typename T> T max(T x, T y)
{
	return x > y ? x : y;
};

const long long mod = 1000000007;
const int MAXN = 1000005;

long long qpow(long long x, int y)
{
	if (!y)
		return 1;
	long long t = qpow(x, y / 2);
	return t*t % mod * (y & 1 ? x : 1) % mod;
}

int n, m;
long long f[MAXN], temp[MAXN];

void test(int N)
{
	long long t = 1;
	for (int i = 3; i <= N; i++)
	{
		t = t*(i - 1) % mod;
		f[i] = t*(i - 2) * qpow(i - 1, (int)mod - 2) + f[i - 1];
		f[i] %= mod;
	}
	f[N - 1] = f[N];
	for (int i = 2; i < N; i++)
		f[N - i] = (f[N - i + 1] - qpow(2, i - 2)) % mod;
//	for (int i = 1; i <= N; i++)
//		printf("%lld%c", (f[i] + mod) % mod, i == N ? '\n' : ' ');
	long long ans = 0;
	for (int i = 1; i <= N; i++)
		ans += f[i], ans %= mod;
	printf("%lld\n", (ans + mod) % mod);
}

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

	system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <queue>
#include <cstring>
#include <iomanip>
#include "stdio.h"

using namespace std;

typedef vector<vector<int>> graph;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef unsigned short int usi;
typedef vector<bool> fc;
typedef vector<pair<int, int>> factorization;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vch;
typedef vector<string> vs;

vl fib;

vi prime_numbers = {};

void f() {
	fib.push_back(1);
	fib.push_back(2);
	for (int i = 2; i < 45; i++) {
		fib.push_back(fib[i - 1] + fib[i - 2]);
	}
}

void fc_write(fc a) {
	for (int i = a.size() - 1; i >= 0; i--) {
		if (a[i]) cout << 1;
		else cout << 0;
	}
}

fc ll_to_fib(ll n) {
	if (n == 0) {
		fc a;
		a.push_back(0);
		return a;
	}
	if (n == 1) {
		fc a;
		a.push_back(1);
		return a;
	}
	int k;
	for (int i = 0; fib[i] <= n; i++) {
		k = i;
	}
	fc a(k + 1);
	a[k] = 1;
	fc b = ll_to_fib(n - fib[k]);
	//fc_write(b); cout << endl;
	for (int i = 0; i < b.size(); i++) {
		a[i] = b[i];
	}
	return a;
}

ull GCD(ull a, ull b) {
	return (a == 0 ? b : GCD(b % a, a));
}

ull LCM(ull a, ull b) {
	return (a / GCD(a, b)) * b;
}

ll exponentiation(ll a, int b) {
	ll k = 1;
	if (b >= 0)
		for (int i = 0; i < b; i++) {
			k *= a;
		}
	return k;
}

ll concatenation(ll a, ll b) {
	return stoi(to_string(a) + to_string(b));
}

// классы

class FenwickTree {
public:

	int magic(int i) {
		return i&-i;
	}

	vector<ll> a;
	vector<ll> t;

	ll get(int i) {
		ll res = 0;
		for (; i > 0; i -= magic(i)) {
			res += t[i];
		}
		return res;
	}

	ll get(int start, int end) {
		return get(end + 1) - get(start);
	}

	void update(int i, ll delta) {
		for (; i < t.size(); i += magic(i)) {
			t[i] += delta;
		}
	}

	void set(int index, int x) {
		int delta = x - a[index];
		a[index] = x;
		update(index + 1, delta);
	}

	FenwickTree(vector<ll> oa)
		: t(oa.size() + 1, 0)
	{
		a = oa;
		for (int i = 0; i < oa.size(); i++) {
			update(i + 1, a[i]);
		}
	}

};

class Q {
private:

	ll nominator;
	ull denominator;
	ll integer = 0, residue;
	vector<usi> non_period, period, decimal;
	bool defined, minus;

	void normalize() {
		if (denominator == 0) {
			defined = 0;
		}
		else {
			defined = 1;
			ull n = GCD(abs(nominator), denominator);
			nominator /= (ll)n;
			denominator /= n;
			integer = nominator / (ll)denominator;
			residue = abs(nominator) % (ll)denominator;
			if (nominator < 0) minus = 1;
			else minus = 0;
		}
	}
	void fraction_make(ll nom, ll den) {
		if (den < 0) {
			nom *= -1;
			den *= -1;
		}
		nominator = nom;
		denominator = den;
		normalize();
	}
	void fraction_to_periodic() {
		int two = 0, five = 0;
		int k = denominator;
		while (k % 2 == 0) {
			k /= 2;
			two++;
		}
		while (k % 5 == 0) {
			k /= 5;
			five++;
		}
		int r = abs(nominator) % denominator;
		for (int i = 0; i < max(two, five); i++) {
			r *= 10;
			non_period.push_back(r / denominator);
			r %= denominator;
		}
		int l = 0;
		ll nine = 0;
		if (k != 0) do {
			nine = (nine * 10 + 9) % k;
			l++;
		} while (nine % k != 0);
		if (k > 1) for (int i = max(two, five); i < l + max(two, five); i++) {
			r *= 10;
			period.push_back(r / denominator);
			r %= denominator;
		}
	}
	void fraction_to_decimal(int length) {
		int r = abs(nominator) % denominator;
		for (int i = 0; i < length; i++) {
			r *= 10;
			decimal.push_back(r / denominator);
			r %= denominator;
		}
	}
	string read_string_gl(char s = '\n') {
		string a;
		getline(cin, a, s);
		return a;
	}

public:

	bool operator == (Q a) {
		return (nominator == a.nominator && denominator == a.denominator);
	}
	bool operator != (Q a) {
		return !(*this == a);
	}

	Q operator + (Q  &a) {
		return Q(nominator*(ll)a.denominator + a.nominator*(ll)denominator, denominator*a.denominator);
	}
	Q operator + (ll &a) {
		return Q(nominator + denominator*a, denominator);
	}
	Q operator - (Q  &a) {
		return Q(nominator*a.denominator - a.nominator*denominator, denominator*a.denominator);
	}
	Q operator - (ll &a) {
		return Q(nominator - denominator*a, denominator);
	}
	Q operator * (Q  &a) {
		return Q(nominator*a.nominator, denominator*a.denominator);
	}
	Q operator * (ll &a) {
		return Q(a*nominator, denominator);
	}
	Q operator / (Q  &a) {
		return Q(nominator*a.denominator, denominator*a.nominator);
	}
	Q operator / (ll &a) {
		return Q(nominator, denominator*a);
	}
	Q operator ^ (ll &exponent) {
		int nominator0 = 1, denominator0 = 1;
		if (exponent > 0) {
			for (int i = 0; i < exponent; i++) {
				nominator0 *= nominator;
				denominator0 *= denominator;
			}
		}
		if (exponent == 0) {
			nominator = denominator = 1;
		}
		if (exponent < 0) {
			for (int i = 0; i < -exponent; i++) {
				denominator0 *= nominator;
				nominator0 *= denominator;
			}
		}
		Q a(nominator0, denominator0);
		return a;
	}

	Q read_regular(string input = "") {
		set<char> dec = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
		char n;
		ll integer = 0, resideue = 0, denominator = 1, x = 0;
		bool minus = 0;
		queue<ll> q;
		string s = read_string_gl();
		if (s[0] == '-') {
			minus = 1;
		}
		for (int i = (minus ? 1 : 0); i < s.size(); i++) {
			if (dec.count(s[i])) {
				x = 10 * x + (s[i] - '0');
			}
			else if (dec.count(s[i - 1])) {
				q.push(x);
				x = 0;
			}
			if (i + 1 == s.size()) {
				q.push(x);
				x = 0;
			}
		}
		switch (q.size()) {
		case 1:
			integer = q.front();
			q.pop();
			break;
		case 2:
			resideue = q.front();
			q.pop();
			denominator = q.front();
			q.pop();
			break;
		case 3:
			integer = q.front();
			q.pop();
			resideue = q.front();
			q.pop();
			denominator = q.front();
			q.pop();
			break;
		default:
			break;
		}
		if (0 == integer) {
			Q a(resideue*(minus ? -1 : 1), denominator);
			return a;
		}
		Q a(integer *(minus ? -1 : 1), resideue, denominator);
		return a;
	}

	void write() {
		if (!defined) cout << "undefined";
		else if (nominator != 0) {
			cout << nominator;
			if (denominator != 1) cout << '/' << denominator;
		}
		else cout << 0;
	}
	void write_regular() {
		if (!defined) cout << "undefined";
		else {
			if (integer == 0 && minus) cout << '-';
			if (residue == 0) {
				cout << integer;
			}
			else if (integer == 0) {
				cout << residue << "/" << denominator;
			}
			else {
				cout << integer << " " << residue << "/" << denominator;
			}
		}
	}
	void write_periodic() {
		if (!defined) cout << "undefined";
		else {
			fraction_to_periodic();
			if (integer == 0 && minus) cout << '-';
			cout << integer;
			if (non_period.size() + period.size() != 0) cout << ',';
			for (int i = 0; i < non_period.size(); i++) {
				cout << non_period[i];
			}
			if (period.size() > 0) {
				cout << '(';
				for (int i = 0; i < period.size(); i++) {
					cout << period[i];
				}
				cout << ')';
			}
		}
	}
	void write_decimal(int length) {
		if (!defined) cout << "undefined";
		else {
			fraction_to_decimal(length);
			if (integer == 0 && minus) cout << '-';
			cout << integer;
			if (decimal.size() > 0) cout << ',';
			for (int i = 0; i < decimal.size(); i++) {
				cout << decimal[i];
			}
		}
	}

	string to_compare() {
		return (minus ? "-" : "") + to_string(abs(nominator)) + "/" + to_string(denominator);
	}

	Q()
	{
		fraction_make(0, 1);
	}
	Q(ll nom, ll den)
	{
		fraction_make(nom, den);
	}
	Q(ll i, ll r, ull d)
	{
		if (i < 0) {
			minus = 1;
		}
		fraction_make((abs(i)*(ll)d + r)*(minus ? -1 : 1), d);
	}

};

// ввод

int read_int() {
	int a;
	cin >> a;
	return a;
}

long double read_double() {
	double a;
	cin >> a;
	return a;
}

ll read_ll() {
	ll a;
	cin >> a;
	return a;
}

char read_char() {
	char a;
	cin >> a;
	return a;
}

string read_string() {
	string a;
	cin >> a;
	return a;
}

string read_string_gl(char s = '\n') {
	string a;
	getline(cin, a, s);
	return a;
}

string read_text() {
	string a, s = "";
	while (getline(cin, a)) {
		s += a;
	}
	return s;
}

graph read_graph(int m) {
	graph g;
	int a, b;
	for (int i = 0; i < m; i++) {
		a = read_int();
		b = read_int();
		g[a].push_back(b);
		g[b].push_back(a);
	}
	return g;
}

Q read_fraction_regular() {
	string s = read_string_gl();
	stack <int> numbers;
	bool minus = ('-' == s[0] ? 1 : 0);
	int x = 0;
	for (int i = (minus ? 1 : 0); i < s.size(); i++) {
		if ('0' <= s[i] && s[i] <= '9') {
			x = x * 10 + (s[i] - '0');
		}
		else if ('0' <= s[i - 1] && s[i - 1] <= '9') {
			numbers.push(x);
			x = 0;
		}
		if (i + 1 == s.size()) {
			numbers.push(x);
			x = 0;
		}
	}
	switch (numbers.size())
	{
	case 1:
	{
		Q a((minus ? -1 : 1)*numbers.top(), 1);
		return a;
	}
	case 2:
	{
		int den = numbers.top();
		numbers.pop();
		Q a((minus ? -1 : 1)*numbers.top(), den);
		return a;
	}
	case 3:
	{
		int den = numbers.top();
		numbers.pop();
		int red = numbers.top();
		numbers.pop();
		Q a((minus ? -1 : 1)*numbers.top(), red, den);
		return a;
	}
	}
}

//

string removes_spaces_from_the_ends(string s) {
	while (s[0] == ' ') {
		s.erase(0, 1);
	}
	while (s[s.length() - 1] == ' ') {
		s.erase(s.length() - 1, 1);
	}
	return s;
}

void time() {
	while (0 == 0) {
		string m = read_string();
	}
}

int main() {
	//freopen("rsq.in", "r", stdin);
	//freopen("rsq.out", "w", stdout);
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);

	int a, b;
	cin >> a >> b;
	if (a + 1 == b) {
		cout << a << ' ' << b;
	}
	else if (a == b) {
		cout << 10 * a << ' ' << 10 * b + 1;
	}
	else if (a + 1 == 10 * b) {
		cout << a << ' ' << 10 * b;
	}
	else {
		cout << -1;
	}
	time();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
main()
{
    int n,c=0; cin >>n;
    string s; cin>>s;
    for(int i=0;i<n;i++)
        if(s[i]==s[i+1] && s[i]!='?'){ cout<< "No"; c++; break;}
    if((s[0]=='?' || s[n-1]=='?') && c==0)cout<<"Yes";
    else if(c==0)
    for(int i=1;i<n;i++){
            if(s[i]=='?' && s[i+1]=='?'){cout<<"Yes"; break; }
            else if(s[i]=='?'){
            if(s[i+1]==s[i-1]){cout <<"Yes"; break; }
            else continue;}
            if(i==n-1)cout<<"No";
    }
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	t:
	int x,artsay=0,eksay=0;
	cin>>x;
	char d[x];
	for(int c=0;c<x;c++)
	{
		cin>>d[c];
	}
	for(int a=0;a<x;a++)
	{
		if(d[a]=='+')
		{
			artsay++;
		}
		else
		{
			eksay++;
		}
	}
	if(d[0]=='+')
	{
		if(artsay==eksay || eksay>artsay)
		{
			cout<<0;
		}
		else{
			cout<<artsay-eksay;
		}
	}
	else
	{
		cout<<artsay;
	}
	goto t;
	return 0;
}


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

int main()

{
using namespace std;
int n;
int diff=0;
int consdiff=100;
cin>>n;
int ARR[100];
for(int i=0;i<n;++i)
	{ cin>>ARR[i];
	}
for(int i=0;i<n-1;i++)
	{ if ( (ARR[i+1]-ARR[i]) >diff )
		{ diff=(ARR[i+1]-ARR[i]);
		}
	}
//cout<<diff;

for(int i=0;i<n-2;i++)
	{  if ( (ARR[i+2]-ARR[i]) < consdiff )
	   { consdiff=(ARR[i+2]-ARR[i]);
       }

    }
//cout<<"\n"<<consdiff;

if(diff>consdiff)
	{cout<<diff;
	}
else
	{cout<<consdiff;
	}

getch();
return 0;

}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char n[1000000005];
int main()
{
    int i,len,b=1,c=0;
    scanf("%s",n);
    len=strlen(n);
    for(i=0; i<len; i++)
        c=c*10+(n[i]-48);
    for(i=0; i<len; i++)
    {
        if(n[i]!=0)
            break;
    }
    int x=len-i-1;
    while(x--)
    {
        b=b*10;
    }
    b=b*(n[i]-48+1);
    printf("%d\n",b-c);
    return 0;
}
/*2018-07-21 20:08:24.205*/


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define pause system("pause")
int main()
{
	int a, b, c, d;
	stack<int> st;
	cin >> a >> b >> c >> d;
	vector<char> s;
	for (int i = 0; i < a; ++i)
	{
		s.push_back('(');
		s.push_back('(');
	}
	for (int i = 0; i < b; ++i)
	{
		s.push_back(')');
		s.push_back(')');
	}
	sort(s.begin(), s.end());
	bool ok = 1;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] == '(')
		{
			st.push(s[i]);
		}
		else
		{
			if (!st.empty())
			{
				if (st.top() == '(')
				{
					st.pop();
				}
				else
				{
					ok = 0; break;
				}
			}
			else
			{
				ok = 0; break;
			}
		}
	}
	cout << ok;
	//pause;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define rep(i,in1,n) for(i=in1;i<=n;i++)
#define repd(i,in1,n) for(i=in1;i>=n;i--)

#define pf(n) printf("%d ",n);
#define sf(n) scanf("%d",&n)
#define sl(n) scanf("%I64d",&n)
#define nl printf("\n")
#define mem(arr,init) memset(arr,init,sizeof(arr))
#define vi vector<int>
#define vvi vector<vi>

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mp make_pair
#define ep emplace_back//c++11
#define ii pair<int,int>
using namespace std;

int main()
{
    int i,j,k,t,n,m,a,b,c,x,y,z,s;
    cin>>a>>b>>s;

    ll sum=a+b;

    if(sum<=s)
    {
        if(sum%2==1)
        {
            if(s%2==1)
            {
                cout<<"Yes";
        return 0;
            }
            else
            {
                cout<<"No";
                return 0;
            }
        }
        else
        {
            if(s%2==0)
            {
                cout<<"Yes";
        return 0;
            }
            else
            {
                cout<<"No";
                return 0;
            }
        }
    }
     if(sum==s)
    {
        cout<<"Yes";
        return 0;
    }
     else
    {
        /*if(sum==0)
        {
            if(s%2==0)
            {
                cout<<"Yes";
                return 0;
            }
            else
            {
                cout<<"No";
                return 0;
            }

        }*/
        cout<<"No";
        return 0;
    }

    return 0;
}


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

int main() {
    int n; cin>>n; int Max=0; int bien;
    vector<int> a;
    cin>>bien; a.push_back(bien);
    if(a[0]>15) Max=15;
    for(int i=1; i<n; i++) {
        cin>>bien; a.push_back(bien);
        if(a[i]-a[i-1]>15) {
            Max=a[i-1]+15;
        }
    }
    if(Max) cout<<Max;
    else if(a[a.size()-1]+15>=90) {
        cout<<90;
    }
     else {
        cout<<a[a.size()-1]+15;
     }
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
void sc(int& x){x=0;char c=getchar();while(c>'9' || c<'0')c=getchar();
for(;c>='0' && c<='9';c=getchar())x=x*10+c-'0';
}
const int N=6e5+7;
const int mod=1e9+7;
void upd(int& x,int y){x+=y;if(x>=mod)x-=mod;if(x<0)x+=mod;}
typedef long long ll;
int a[N],b[N],n,len,f[2][N<<1],sz[2],num[N],now=0;
char s[N];
int dvd(int x){
	int yv=0,cc=1e9;
	rep2(i,len,0){
		ll tmp=num[i] + yv*1e9;
		num[i]=tmp/x;
		yv=tmp%x;
	}
	while(!num[len])len--;
	return yv;
}
int main(){
	sc(n);
	a[1]=1;rep(i,2,n)sc(a[i]);
	rep(i,1,n)sc(b[i]);
	scanf("%s",s);len=strlen(s);
	for(int i=0;i*9<len;i++){
		int l=i*9,r=min(len,(i+1)*9)-1;
		rep2(j,r,l)num[i]=num[i]*10 + s[len-j-1]-'0';
	}
	len=(len-1)/9;
	f[now][0]=1;
	rep(i,1,n){
		int yv=dvd(a[i]);
		sz[now^1]=0;
		for(int j=yv;j<=sz[now];j+=a[i],sz[now^1]++)f[now^1][sz[now^1]]=f[now][j];
		sz[now]=sz[now^1]+b[i]-1;
		int res=0;
		rep(j,0,sz[now]){
			if(sz[now^1]>j)upd(res,f[now^1][j]);
			if(j>b[i] && sz[now^1] > j-b[i]-1)upd(res,-f[now^1][j-b[i]-1]);
			f[now][j]=res;
		}
	}
	ll need=0;rep2(i,len,0){need=need*1e9+num[i];if(need>sz[now]){puts("0");return 0;}}
	printf("%d\n",f[now][need]);
}


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

#include<math.h>

using namespace std;
int main()
{
    long long int n;
    cin>>n;

    cout<< int(log(n)/log(2)+1);

    return 0;

}


/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-07-10-11.11
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define  LL long long
#define  ULL unsigned long long
using namespace std;

int main()
{
      freopen("C:\\Users\\crazyacking\\Desktop\\cin.txt","r",stdin);
//      freopen("C:\\Users\\crazyacking\\Desktop\\cout.txt","w",stdout);

      ios_base::sync_with_stdio(false);
      cin.tie(0);
      int n;
      while(cin>>n)
      {
            int a[2],b[2],c[2];
            cin>>a[0]>>a[1]>>b[0]>>b[1]>>c[0]>>c[1];
            int max_sum=a[0]+b[0]+c[0];
            int aa=a[0],bb=b[0],cc=c[0];
            int except=n-max_sum;
//            cout<<except<<endl;
            if(max_sum<n){
                  if(aa+except<=a[1])
                        aa+=except,except-=except;
                  else{
                        aa=a[1];
                        except-=a[1]-a[0];
                        if(bb+except<=b[1])
                              bb+=except,except-=except;
                        else{
                              bb=b[1];
                              except-=b[1]-b[0];
                        }
                  }
            }
//            cout<<except<<endl;
            if(except>0)
                  cc+=except;
            cout<<aa<<" "<<bb<<" "<<cc<<" "<<endl;

      }
      return 0;
}
/*

*/


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

int main()
{
	__int64 l, r;
	scanf("%I64d %I64d", &l, &r);

	if(l > r)
	{
	    __int64 tmp = l;
	    l = r;
	    r = tmp;
	}

	if(l == r)
	{
	    printf("0\n");
	    return 0;
	}

	int lb[50], ll = 0;//! 20 is too small for decimal
	int rb[50], lr = 0;
	memset(lb, 0, sizeof(lb));
	memset(rb, 0, sizeof(rb));
	for(__int64 x = l; x > 0; lb[ll++] = x % 2, x /= 2);
	ll--;
	for(__int64 x = r; x > 0; rb[lr++] = x % 2, x /= 2);//! type
	//for(__int64 x = r; x > 0; )
        //rb[lr++] = x % 2, x /= 2;
	lr--;

	int ptr = lr;
	__int64 ans = 0;
	for( ; ptr > ll; ans += (__int64)1 << ptr, ptr--); //!__int64

	while(ptr >= 0 && lb[ptr] == rb[ptr])
        ptr--;

	ans += (((__int64)1 << (ptr + 1)) - 1);//!
    printf("%I64d\n", ans);
    return 0;
}


#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<deque>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
const int mod=1e9+7;
const double eps=1e-6;
const double pi=acos(-1);
const int inf=0x7fffffff;
typedef long long int ll;
typedef unsigned long long ull;
using namespace std;

int a[50];

int main()
{
    int n,k,m;
    scanf("%d%d%d",&n,&k,&m);
    int sum=0;
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sort(a+1,a+1+k);
    if(m>=n*sum)
        return 0*printf("%d\n",n*(k+1));

    int ans1=m/sum*(k+1);
    int x=m%sum;
    for(int i=1;i<=k;i++)
    {
        x-=a[i];
        if(x<0)break;
        ans1++;
    }

    int ans2=0,y=m;
    for(int i=1;i<=k;i++)
    {
        if(y>=a[i]*n)
        {
            ans2+=n;
            y-=a[i]*n;
        }
        else
        {
            ans2+=y/a[i];
            break;
        }
    }
    printf("%d\n",max(ans1,ans2));
    return 0;
}


#include<bits\stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if (a+c>b)
    {
        cout<<"NO"<<endl;

    }
    else if(a<=b)
    {
    while(a<=b)
    {
        a+=c;
        if (a==b)
        {
            cout<<"YES"<<endl;
        }
    }
    }
    else
    {
        cout<<"NO"<<endl;
    }
}


#include <cstdio>
typedef long long ll;
int N,M=1e9+7,P,F[1000005],Ans;
int main(){
	scanf("%d%d",&N,&M),*F=1;
	for (int i=1;i<=N;++i) F[i]=(ll)F[i-1]*M%P;
	for (int i=!--(M<<=1),X=1;i<N;++i,X=(ll)X*M%P) Ans=(Ans+(ll)X*F[N-i])%P;
	return printf("%d",(Ans+F[N])%P),0;
}


#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b, __ = c; a < __; a++)
#define dbg(x) cerr << ">>>>> " << x << endl;
#define _ << " , " <<

using namespace std;

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

const int ms = int(5e6) + 100;
const ll inf = ll(2e18) + 200, mod = ll(1e9) + 7;

char len[ms];
int primes[ms][18];
char q[ms][18];
int ls[ms];
ll memo[ms];

ll f(int n);

ll getMin(int n, int at, int val){
	if(at >= len[n]){
		if(val == 1)
			return inf;
		return ll(n/val) * (ll(val) * ll(val-1))/2 + f(n / val);
	}
	int pot = 1;
	ll ans = inf;
	fr(i, 0, q[n][at]+1){
		ans = min(getMin(n, at+1, val * pot), ans);
		pot *= primes[n][at];
	}
	return ans;
}

ll f(int n){
	if(n == 1)
		return 0;
	if(ls[n] == n)
		return (ll(n) * ll(n-1))/2;
	if(memo[n] != -1)
		return memo[n];
	return memo[n] = getMin(n, 0, 1);
}

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

int main(){
	ios::sync_with_stdio(0);
	fr(i, 2, ms){
		if(ls[i])
			continue;
		for(int j = i; j < ms; j += i)
			ls[j] = i;
	}
	fr(i, 2, ms){
		int at = i;
		int p = 0;
		primes[i][p] = ls[i];
		q[i][p] = 1;
		at /= ls[i];
		while(at != 1){
			if(ls[at] == primes[i][p]){
				q[i][p]++;
			}
			else{
				++p;
				primes[i][p] = ls[at];
				q[i][p] = 1;
			}
			at /= ls[at];
		}
		len[i] = p+1;
	}
	int t, l, r;
	cin >> t >> l >> r;
	ll ans = 0;
	memset(memo, -1, sizeof memo);
	fr(i, l, r+1){
		ans = (ans + fastExp(t, i-l)*(f(i)%mod))%mod;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
#include <functional>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#define int64 long long
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define mp make_pair

using namespace std;

int n, d, a[300];
int64 inf = 10000000000000000ll, dp[51][500001], dp1[51][500001];

int main()
{
    cin >> n >> d;
    rep(i,1,n) cin >> a[i];
    sort(a + 1, a + n + 1);
    rep(i,0,50)
        rep(j,0,500000)
        {
            dp[i][j] = inf;
            dp1[i][j] = inf;
        }
    dp[1][0] = 0;
    dp1[1][0] = 0;
    if (a[1] <= d)
    {
        dp[1][a[1]] = 1;
        repd(i,a[1],1) dp1[1][i] = 1;
    }
    rep(i,2,n)
        repd(j,500000,0)
        {
            if (j <= d)
            {
                if (j >= a[i]) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - a[i]]);
                else dp[i][j] = dp[i - 1][j];
                if (j != 0) dp[i][j] = max(dp[i][j], 1ll);
            }
            else
            {
                if (j >= a[i]) dp[i][j] = min(dp[i - 1][j], dp1[i - 1][max(0, a[i] - d)] + dp[i - 1][j - a[i]] + 1);
                else dp[i][j] = dp[i - 1][j];
            }
            if (j == 500000) dp1[i][j] = dp[i][j];
            else dp1[i][j] = min(dp1[i][j + 1], dp[i][j]);
        }
    int ans1 = 0;
    int64 ans2 = 0;
    rep(i,0,500000)
        if (dp[n][i] != inf && i >= ans1)
        {
            if (i == ans1) ans2 = min(ans2, dp[n][i]);
            else
            {
                ans1 = i;
                ans2 = dp[n][i];
            }
        }
    cout << ans1 << " " << ans2;
    return 0;
}


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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if (d>c) cout<<"Second"<<endl;
    else {
        while (1){
            a-=c;
            b-=d;
            if (a==0||b==0) break;
        }
        if (a>0) cout<<"First"<<endl;
        else cout<<"Second"<<endl;
    }
}


#include <bits/stdc++.h>
#define  FOR(i,x,n) for(int i=x;i<n;i++)
#define rFOR(i,x,n) for(int i=x;i>n;i--)
#define fi first
#define se second
#define SZ(x) (int)x.size()
typedef long long ll;
typedef long double lD;
using namespace std;

int Counting[100000000];

void Counting_Sort(int* a,int sz)
{
   for(int i=0;i<sz;i++)
      Counting[a[i]]++;
   int k=0,c=0;
   while(k<sz)
   {
     while(Counting[c]--) a[k++]=c;
     c++;
   }
}

int main()
{
   int n; scanf("%d",&n);
   int* a=new int[n];
   FOR(i,0,n) scanf("%d",a+i);
   Counting_Sort(a,n);
   FOR(i,0,n) printf("%d ",a[i]);
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<iostream>
const int MAX=3e5+5;
const int INF=0x3f3f3f3f;
typedef long long ll;
using namespace std;
string s;
int f,flag;
char ref[5]={'a','e','i','o','u'};
int main()
{
	int i,j,k,n,m;
	cin>>s;
	for(i=0;i<s.size()-1;)
	{
		flag=1;
		for(j=0;j<5;j++)
		{
			if(s[i]==ref[j])
			{
				flag=0;
				break;
			}
		}
		if(flag)//s[i]是辅音
		{
			if(s[i]=='n')
			{
				i+=2;
				continue;
			}
			f=0;
			for(j=0;j<5;j++)
			{
				if(s[i+1]==ref[j])
				{
					f=1;
					break;
				}
			}
			if(!f)//s[i+1]是辅音
				break;
			i++;
		}
	}
	if(i<s.size()-1)
		puts("NO");
	else puts("YES");
}
//necnei


/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
typedef long long Long;
void FastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
}

const int N = 1e5;

int p, x, y;

int dp[N/2];

int solve(int n){
  int r = (n/50)%475;
  if (r+26==p){
//    cout << n << '\n';
    return 0;
  }
  for (int i = 0;i < 25;i++){
    r = (r*96 + 42) % 475;
    if (r+26 == p){
      //cout << n << '\n';
      return 0;
    }
  }
  if (dp[n])return dp[n];
  dp[n] = solve(n+100)+1;
  if (n-50 >= y)dp[n] = min(dp[n], solve(n-50));
  return dp[n];
}

int main()
{
  FastIO();
  int tc, ca = 0;
  cin >> p >> x >> y;
  cout << solve(x) << '\n';
  return 0;
}


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n,i;
cin>>n;
if(n==1 || n==2)
{
cout<<"-1";
goto out;
}
else
{
for(i=2;i<=n;i++)
cout<<i;
}
cout<<"1";
out:
cout<<"";
getch();
}


#include<bits/stdc++.h>
using namespace std;
long long int n;
long long int megoldas;
long long int seged;
long long int valami;
long long int y;
long long int se;
vector < long long int > v;
long long int rek(long long int x)
{
    if (x==1) return 1;
    if (x==2) return 3;
    if (x==3) return 4;
    seged=2;
    while(2*seged<=x)
    {
        seged*=2;
    }
    if (x==seged)
    {
        return x+rek(x-1);
    }
    else{

        valami=rek(x-seged);
        seged=2;
    while(2*seged<=x)
    {
        seged*=2;
    }
    v.push_back(valami);
    return v[v.size()-1]+rek(seged);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    n=n-1;
    cout<<rek(n);

}


#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <climits>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int M=1e5+10;
typedef unsigned long long int longint;
ll sum,x1,x2,y11,y2;
int main()
{
    cin>>x1>>y11>>x2>>y2;
    ll i,j;
    sum=0;
    for(i=x1;i<=x2;i++)
    {
    	for(j=y11;j<=y2;j++)
    	{
    		if((i%2==0 && j%2==0)||(i%2!=0 && j%2!=0))
    		sum++;
		}
	}
    cout<<sum<<endl;
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
typedef long long LL;
using namespace std;
const int MOD = 1e9 + 7;
const int N = 100010;
/*
LL C[N][21];

LL frac[21];
void init()
{
	memset(C,0,sizeof C);
	C[0][0] = 1;
	for(int i = 1;i<=N;i++)
	{
		for(int j = 0;j<=min(i,20);j++)
		{
			C[i][j] = (C[i-1][j] + C[i-1][j-1])%MOD;
		}
	}
	frac[0] = 1;
	for(int i = 1;i<=20;i++)
		frac[i] = (frac[i-1] * i) % MOD;
}
*/
LL dp[21][21];
LL fastpow(int base,int ind)
{
	LL ans = 1;
	while(ind)
	{
		if(ind & 1) ans = (ans * base) % MOD;
		base = ((LL)base * base) % MOD;
		ind >>= 1;
	}
	return ans;
}
LL frac[100010];
LL calc(int k,int i);
void init()
{
	memset(dp,0,sizeof dp);
	frac[0] = 1;
	for(int i = 1;i<=100000;i++)
	{
		frac[i] = (frac[i-1] * i) % MOD;
	}
	for(int i = 1;i<=20;i++)
	{
		for(int j = i;j <= 20;j++)
		{
			calc(j,i);
		}
	}
}
LL C(int n,int k)
{
	LL rev = (fastpow(frac[k],MOD - 2) * fastpow(frac[n-k],MOD - 2))%MOD;
	LL ans = (frac[n] * rev)%MOD;
	return ans;
}
LL calc(int k,int i)
{
	if(dp[k][i]) return dp[k][i];
	if(k == 0 && i) return 0;
	if(i == 1)return dp[k][i] = 1;
	LL ans = 0;
	for(int j = 1;j<=k;j++)
	{
		ans = (ans + C(k,j) * calc(k - j,i - 1))% MOD;
	}
	return dp[k][i] = ans;
}
int main(void)
{
	init();
	int t;cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		LL ans = 0;
		for(int i = 1;i<=k;i++)
		{
			ans = (ans + dp[k][i] * (LL)C(n,i)) % MOD;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<stdio.h>

int solve(int m,int k)
{
	if( m<=k)
		return 0;
	for(int i=k;i*i<=m;i++)
		if( m%i==0)
		{
			return 1+m/i*solve(i,k);
		}
	for(int i=k;i>1;i--)
	{
		if( m/i>=k&&m%i==0)
		{
			return 1+i*solve(m/i,k);
		}
	}
	return 0;
}
int main(int argc,char* argv[])
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	int y=solve(m,k);
	y=y*n;
	if(y%2==0)
		printf("Marsel\n");
	else
		printf("Timur\n");
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int arr[n+1];
    int i,j;
    for(i=0;i<=n;i++)
    {
        arr[i]=-1;
    }
    for(i=1;i<=(n/2);i++)
    {
        int k;
        cin >> k;
        arr[k]=1;
    }
    int brr[n+1];
    //brr[0]=1;
    for(i=0;i<=n;i++)
    {
        brr[i]=arr[i];
    }
    int crr[n+1];
    //crr[0]=1;
    for(i=0;i<=n;i++)
    {
        crr[i]=arr[i];
    }

    /*for(i=1;i<=n;i++)
    {
        cout << brr[i] << " " ;
    }
    cout << '\n';

    for(i=1;i<=n;i++)
    {
        cout << crr[i] << " " ;
    }
    cout << '\n';*/
    //FOR BLACK %2!=0
    int black=0;
    int white=0;
    //SHIFT ALL TO BLACK
    for(i=1;i<=n;i++)
    {
        if(i%2==0 && brr[i]==1)//if white pe present then shift to nearest black
        {
            int l,m;
            l=i;
            m=i;
            while(m>=1)
            {
                if(m%2!=0 && brr[m]!=1)//if place is empty and black then fill it
                {
                    brr[m]=1;
                    break;
                }
                m--;
            }
            //cout << "m after blak " << m << '\n';
            while(l<=n)
            {

                if(l%2!=0 && brr[l]!=1)//if place is empty and black then fill it
                {
                    brr[l]=1;
                    break;
                }

                l++;
            }
            //cout << "l after blak" << l << '\n';
            int a1,a2;
            a1=l-i;
            a2=i-m;
            int ans=0;
            if(m==0)
            {
                ans=a1;
            }
            else if (l==(n+1))
            {
                ans=a2;
            }
            else if(a2 <= a1 && m!=0 )
            {
                ans=a2;
                brr[l]=-1;
            }
            else if(a1 <= a2 && l!=(n+1))
            {
                ans=a1;
                brr[m]=-1;
            }
            black+=ans;
            //cout << "ans=" << ans << '\n';
            //cout << "black=" << black << '\n';
        }
    }
    //for white
    for(i=1;i<=n;i++)
    {
        if(i%2!=0 && crr[i]==1)//if black pe present then shift to nearest white
        {
            int l;
            int m;
            l=i;
            m=i;
            while(m>=1)
            {
                if(m%2==0 && crr[m]!=1)//if place is empty and white then fill it
                {
                    crr[m]=1;
                    break;
                }
                m--;
            }
            //cout << "m after white" << m << '\n';
            while(l<=n)
            {
                if(l%2==0 && crr[l]!=1)//if place is empty and white then fill it
                {
                    crr[l]=1;
                    break;
                }
                l++;
            }
            //cout << "l after white" << l << '\n';
            int a1,a2;
            a1=l-i;
            a2=i-m;
            int ans=0;

            if(m==0)
            {
                ans=a1;
            }
            else if (l==(n+1))
            {
                ans=a2;
            }
            else if(a2 <= a1 && m!=0 )
            {
                ans=a2;
                crr[l]=-1;
            }
            else if(a1 <= a2 && l!=(n+1))
            {
                ans=a1;
                crr[m]=-1;
            }

            //cout << "ans=" << ans << '\n';
            white+=ans;

            //cout << "white=" << white << '\n';
        }
    }

    if(black>white)
    {
        cout << white << '\n';
    }
    else
    {
        cout << black << '\n';
    }
    return 0;
}


/*AMETHYSTS*/
//#pragma comment(linker, "/STACK:1000000000")
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>
//#include <unordered_map>
//#include <random>
//#include <unordered_set>

#define ll long long
#define ld double
#define pii pair <int, int>
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define mp make_pair
#define ui unsigned ll
#define pll pair <ll, ll>

using namespace std;

const int maxn = 1 << 7;

vector <int> ed[maxn];
vector <int> now;
bool used[maxn];

int cnt = 0;
int lasth = -1;

void del(int x) {
	while (!ed[x].empty() && used[ed[x].back()]) {
		ed[x].pop_back();
	}
}

bool read(int x) {
	cnt++;

	if (cnt > 16) {
		cout << x << endl;
		return true;
	}

	printf("? %d\n", x);
	fflush(stdout);
	ed[x].clear();
	now.push_back(x);
	used[x] = true;
	int k;

	scanf("%d", &k);

	if (k == 0) {
		exit(0);
	}

	ed[x].resize(k);

	for (int i = 0; i < k; i++) {
		scanf("%d", &ed[x][i]);
	}

	random_shuffle(ed[x].begin(), ed[x].end());

	if (k == 2) {
		printf("! %d\n", x);
		fflush(stdout);
		return true;
	}

	return false;
}

int main() {
	int t;

	cin >> t;

	while (t--) {
		lasth = -1;
		cnt = 0;
		memset(used, 0, sizeof used);
		now.clear();
		int h;

		cin >> h;

		if (h == 0) {
			exit(0);
		}

		int n = (1 << h) - 1;

		if (read(rand() % n + 1)) {
			continue;
		}

		while (true) {
			int x = now.back();

			del(x);

			if (!ed[x].empty()) {
				int y = ed[x].back();
				ed[x].pop_back();

				if (read(y)) {
					break;
				}
			} else {
				reverse(now.begin(), now.end());

				int x = now.back();

				if (!ed[x].empty()) {
					continue;
				}

				int sz = (int)now.size();

				for (int i = 0; i < sz / 2; i++) {
					now.pop_back();
				}

				lasth = now.size();

				if (lasth == 4 && h == 7) {
					x = now.back();

					while (!ed[x].empty() && used[ed[x].back()]) {
						ed[x].pop_back();
					}

					if (ed[x].empty()) {
						throw 1;
					}

					x = ed[x].back();

					read(x);

					vector <int> a;

					while (!ed[x].empty()) {
						if (used[ed[x].back()]) {

						} else {
							a.push_back(ed[x].back());
						}

						ed[x].pop_back();
					}

					read(a[0]);
					read(a[1]);

					vector <int> b;

					for (int i = 0; i < 2; i++) {
						int x = a[i];

						while (!ed[x].empty()) {
							if (used[ed[x].back()]) {

							} else {
								b.push_back(ed[x].back());
							}

							ed[x].pop_back();
						}
					}

					while (!b.empty()) {
						if (read(b.back())) {
							break;
						}

						b.pop_back();
					}

					break;
				}
			}
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[110];
bool flag=false;
void dfs(int i,int sum)
{
    if(i==n+1)
    {
        if(sum%2==1)
        {
            flag=true;
        }
    }
    else if(a[i]%2==0)
    {
        return ;
    }
    else
    {
        dfs(i+1,sum+1);
        int cnt=1;
        for(int j=i+1;j<=n;j++)
        {
            cnt++;
            if(a[j]%2==1)
            {
                if(cnt%2==1)
                {
                    dfs(j+1,sum+1);
                }
            }
        }
    }
}
int main(void)
{
    freopen("C:\\Users\\YuXiaoKang\\Desktop\\test.txt","r",stdin);
    memset(a,0,sizeof(a));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int i;
    for(i=1;i<=n;i++)
    {
        if(n%2==1&&a[1]%2==1&&a[1]==a[i])
        {

        }
        else
        {
            break;
        }
    }
    if(i==n+1)
    {
        cout <<"Yes"<<endl;
        return 0;
    }
    dfs(1,0);
    if(flag)
    {
        cout <<"Yes"<<endl;
    }
    else
    {
        cout <<"No"<<endl;
    }
    return 0;
}


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

#define fore(i, a, b) for (int i = int(a); i < int(b); i++)
#define forn(i, n) fore(i, 0, n)
#define efor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define nfor(i, n) efor(i, 0, n)

#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define all(v) (v).begin(), (v).end()
#define sz(v) int((v).size())
#define x first
#define y second

template <typename T> T abs(const T& x) { return x < 0 ? -x : x; }
template <typename T> T sqr(const T& x) { return x * x; }

template<typename X, typename Y> ostream& operator<< (ostream& out, const pair<X, Y>& p) {
	return out << "(" << p.x << ", " << p.y << ")";
}

template<typename X> ostream& operator<< (ostream& out, const vector<X>& a) {
	out << "[ ";
	forn(i, sz(a)) {
		if (i) out << ", ";
		out << a[i];
	}
	return out << " ]";
}

typedef unsigned long long li;
typedef long double ld;
typedef pair<int,int> pt;

ld gett() {
	return clock() / ld(CLOCKS_PER_SEC);
}

#ifdef TJS

#endif

const int N = int(1e6) + 5;
char s[N];
int q[N];
int n, m;

bool read() {
	if (scanf("%s", s) != 1)
		return false;
	assert(cin >> m);
	forn(i, m) {
		static char buf[30];
		assert(scanf("%s", buf) == 1);
		int l = strlen(buf);
		q[i] = 0;
		forn(j, l)
			q[i] |= (1 << int(buf[j] - 'a'));
	}
	return true;
}

int pos[26];
int cnt[(1 << 26) + 5];

void solve() {
	forn(i, 26)
		pos[i] = -1;

	int n = strlen(s);
	s[n++] = '#';
	forn(i, n) {
		vector <pt> vv;
		forn(j, 26)
			if (pos[j] != -1)
				vv.pb(mp(pos[j], j));

		sort(all(vv));
		reverse(all(vv));
		int cmask = 0;
		for (auto p: vv) {
			if (p.y == int(s[i] - 'a'))
				break;
			cmask |= (1 << p.y);
			cnt[cmask]++;
		}

		if (i < n - 1)
			pos[int(s[i] - 'a')] = i;
	}

	forn(i, m)
		printf("%d\n", cnt[q[i]]);
}

int main() {
#ifdef TJS
	assert(freopen("input.txt", "r", stdin));
#else
#endif
	cerr << fixed << setprecision(5);
	cout << fixed << setprecision(10);
	while (read()) {
#ifdef TJS
		ld st = gett();
#endif
		solve();
#ifdef TJS
		cerr << " == TIME : " << gett() - st << " == " << endl;
#endif
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <utility>
#include <cstring>
#include <algorithm>
long long a,b;
long long flg;
bool vis[1000000009];
long long beh(long long x){

	if(x <= a){
		printf("%I64d\n",x);
		for(long long i=2;i<=(a/x);i++){
			if(a % (i*x) == b){
				flg++;
				vis[i*x] = true;
				printf("%I64d %I64d\n",a,i*x);
				beh(2*x);

			}
		}

	}

	return 0;
}
int main (){
	scanf("%I64d %I64d",&a,&b);
	long long c3 = 0;
	for(int i=1;i<=a;i++){
		if(a % i == b){
			flg++;
		}
	}
	printf("%I64d",flg);
	return 0;
}


//Problem: Mister B and Boring Game
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
   // freopen("test.inp","r",stdin);
   // freopen("test.out","w",stdout);
	int a,b,len;
	char c;
	long l,r;
	cin>>a>>b>>l>>r;
	string s,newstr,suffix;
	for(c = 'a'; c < 'a' + a;c++)
	    s += c;
	if(r >= 2*(a+b))
		if(r == l)
		{
			r = 2*(a+b);
			l = r;
		}

	len = s.length();
	for(int i = len; i <= r;i += a+b)
	{
		for(int j = 0; j < b;j++) //turn of Mister B
			s += s[len - 1];
		len = s.length();
		if(len >= r)
			continue;
		c = 'a';
		suffix.append(s,len-a,a);
		for(int k = 0; k < a;k++) //turn of Computer
		{
			while(suffix.find(c)!=-1) c++;
			s += c;
			c++;
		}

	}
	for(int i = l-1; i < r;i++)
		if(newstr.find(s[i]) == -1)
			newstr += s[i];
	cout<<newstr.length();
	/*for(int i = 0; i < s.length();i++)
		cout<<s[i];*/
	return 0;
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define pb push_back
#define INF 1000000100
#define MOD 1000000007
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector< ii >
#define vvi vector< vector<int > >
#define vvii vector< vector<ii > >
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << ' '; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define LC(i) 2*(i)+1
#define RC(i) 2*(i)+2
#define MID(i,j) ((i)+(j))/2
#define disparr(arr,n) for(int i=0;i<(n);i++)   cout<<arr[i]<<' ';  cout<<endl;
#define vd vector<double>
ll power(ll a,ll b)
{
    if(b==1)
        return a;
    ll p=power(a,b/2);
    ll ans=p*p;
    ans%=MOD;
    if(b%2)
        ans*=a;
    ans%=MOD;
    if(ans<0)
        ans+=MOD;
    return ans;
}
int main()
{
    ll x,k;
    cin>>x>>k;
    x%=MOD;
    ll coeff=power(2,k+1);
    ll ans=coeff*x;
    ans%=MOD;
    ll tmp=power(2,k)-1;
    tmp%=MOD;
    ans-=tmp;
    ans%=MOD;
    if(ans<0)
    ans+=MOD;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for (int i=m;i<=n;i++)
#define reb(i,m,n) for (int i=m;i>=n;i--)
#define rv(i,vt) for (auto i:vt)
#define ii pair<ll,ll>
#define vi vector<ll>
#define F first
#define S second
#define pb push_back
using namespace std;
const ll N=1e6+5,mod=1e9+7;
string s,s1;
ll n,k;
string cvt (ll n){
    ll p=n;
    string f="";
    while (p>0){
        f+=char(p%2+48);
        p/=2;
    }
    reverse(f.begin(),f.end());
    return f;
}
ii cnt (string s){
    ii pd;
    ll l=0;
    while (s[l]=='1' && l<=s.size()-1) l++;
    pd.F=l;
    ll r=s.size()-1;
    if (l!=s.size()){
        reverse(s.begin(),s.end());
        l=0;
        while (s[l]=='1' && l<=s.size()-1) l++;
        pd.S=l;
    }
    else pd.S=0;
    return pd;
}
bool able (string s, string s1){
    ii p1=cnt(s),p2=cnt(s1);
    while (p1.F<p2.F) p1.F++,s="1"+s;
    while (p1.S<p2.S) p1.S++,s+="1";
    return (s==s1);
}
void solve()
{
cin>>n>>k;
s=cvt(n);
s1=cvt(k);
string s2=s;
s+='1';
if (able(s,s1)){
    cout<<"YES";
    return;
}
reverse(s1.begin(),s1.end());
if (s1[0]!='0')
if (able(s,s1)){
    cout<<"YES";
    return;
}
s=s2;
while (s[s.size()-1]=='0') s.erase(s.size()-1,1);
if (s1[0]!='0')
if (able(s,s1)){
    cout<<"YES";
    return;
}
reverse(s1.begin(),s1.end());
if (able(s,s1)){
    cout<<"YES";
    return;
}
cout<<"NO";
}
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ll t=1;
   //cin>>t;
   while (t--){
       solve();
       cout<<endl;
   }
   cerr << "\n" << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
}


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

ll mod=1000000007;
int n,k, cnt1[100005], used[100005], used2[100005], fif=0, cen=0;
ll cnt2[100005];
ll fact[200005];
vector<pair<pair<int,int>,int> > v,v2;
vector<pair<int,int> > v4;
vector<int> v3;

ll pw(ll x, int y)
{
    if(y==0) return 1;
    ll ans= pw(x,y/2);
    ans*=ans;
    ans%=mod;
    if(y%2) ans*=x;
    ans%=mod;
    return ans;
}

ll inv(ll x)
{
    return pw(x,mod-2);
}

ll C(int x, int y)
{
    if(x<y) return 0;
    ll ans= fact[x];
    ans*= inv(fact[y]);
    ans%=mod;
    ans*= inv(fact[x-y]);
    ans%=mod;
    return ans;
}

void calc(int x, int y, int z)
{
    v4.clear();
    pair<int,int> p= mp(0,0);
    while(p.yy<y)
    {
        if(p.yy*100 + 100<=k)
        {
            p.yy++;
            v4.pb(p);
        }
        else break;
        int x1= p.yy*100;
        x1=k-x1;

        p.xx=1;
        while(p.xx<=x && p.xx*50<=x1)
        {
            v4.pb(p);
            p.xx++;
        }
    }
    p=mp(0,0);
    while(p.xx<x)
    {
        if(p.xx*50 + 50<=k)
        {
            p.xx++;
            v4.pb(p);
        }
        else break;
    }
//    printf("%d %d %d\n",x,y,z);
//    for(int i=0; i<v4.size(); i++)
//    {
//        printf(" %d %d\n",v4[i].xx, v4[i].yy);
//    }
    if(z==2)
    {
        for(int i=0; i<v4.size(); i++)
        {
            v4[i].xx*=-1;
            v4[i].yy*=-1;
        }
    }
}

int calc2(int x, int y, int z)
{
    x*=52;
    x+=y;
    x*=3;
    x+=z;
    return x;
}

void bfs()
{
    for(int i=0; i<v.size(); i++)
    {
        int x=v[i].xx.xx, y=v[i].xx.yy, z=v[i].yy;
        int c= calc2(x,y,z);
        int x1=x, y1=y, z1=2;
        if(z==2)
        {
            x1=fif-x;
            y1=cen-y;
            z1=1;
        }
        calc(x1,y1,z);

        for(int j=0; j<v4.size(); j++)
        {
            int x2= x-v4[j].xx;
            int y2= y-v4[j].yy;
            int c1= calc2(x2,y2,z1);
            if(used[c1]) continue;

            ll com=1;
            com= C(x1, abs(v4[j].xx));
            com*= C(y1, abs(v4[j].yy));
            com%=mod;
//            printf("%d %d %d %d %lld\n",x1,v4[j].xx, y1, v4[j].yy, com);

            cnt1[c1]= cnt1[c]+1;
            cnt2[c1]+= (cnt2[c]*com)%mod;
            cnt2[c1]%=mod;
            if(used2[c1]) continue;
            v3.pb(c1);
            v2.pb(mp(mp(x2,y2),z1));
//            printf("%d\n",c1);
            used2[c1]=1;
        }
    }
    for(int i=0; i<v3.size(); i++)
    {
        if(v3[i]== 2) return ;
        used[v3[i]]=1;
    }
    v3.clear();
    v.clear();
    v= v2;
    v2.clear();
    bfs();
}

int main()
{
    fact[0]=1;
    for(int i=1; i<100000; i++)
    {
        fact[i]= (fact[i-1]*i)%mod;
    }
    int a;
    scanf("%d %d",&n,&k);

    for(int i=0; i<n; i++)
    {
        scanf("%d",&a);
        if(a==50) fif++;
        else cen++;
    }
    int c= calc2(fif,cen,1);
    cnt2[c]=1;
    v.pb(mp(mp(fif,cen),1));
    bfs();
    if(cnt2[2]) printf("%d\n%lld\n",cnt1[2], cnt2[2]);
    else printf("-1\n0\n");
}


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

int main() {
	int n, x, ans = 0, b;
	cin >> n >> x;
	vector<int> N(n+1);
	for (int i=0; i<n+1; ++i)
	{
		cin >> b;
		N[b] = 1;
	}
	for (int i=0; i<x; ++i)
	{
		if (N[i]==0)
			++ans;
	}
	if (N[x]==1)
		++ans;
	cout << ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

ull q,di=1;
bool prime[10000002];

int main(){
	scanf("%I64d",&q);
	prime[2]=false;
	int ndiv=0;
	for (int i=2; i<=sqrt(q*1.0); i++)
		if (!prime[i]){
			if (q%i==0){
				ndiv++;
				q/=i;
				di*=i;
				if (ndiv>=2)
					break;
			}
			for (int j=2*i; j<=sqrt(q*1.0); j+=i)
				prime[j]=true;
		}
	switch (ndiv){
	case 0:
		puts("1\n0");
		break;
	case 1:
		puts("2");
		break;
	case 2:
		printf("1\n%I64d\n",di);
		break;
	}
	return 0;
}


/*.........................................
       .   *BISMILLAHIR RAHMANIR RAHIM*   .
       .       [ALLAH] is Almighty        .
       ....................................
 ********************************************
 *   . . . . . . . . . . . . . . . . . ..   *
 *   .  solved_by: zitul_mahmud;        .   *
 *   .  Electrical and Electronic       .   *
 *   .     Engineering [ EEE ]          .   *
 *   .  Islamic university,kushtia;     .   *
 *   .  zitulmahmud88@gmail.com;        .   *
 *   .  "STAY HUNGRY STAY FOOLISH"      .   *
 *   . . . . . . . . . . . . . . . . . ..   *
 ********************************************/

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

typedef long long ll;
typedef double    dl;
using namespace   std;

# define PI            2*acos(0.0)
# define MOD           100000007
# define sz            100005/*array_size*/
# define FF            first
# define SS            second
# define PB            push_back
# define MP            make_pair/*make_pair()*/
# define clr(x)        (x).clear()
# define all(x)        (x).begin(),(x).end() /*sorting STL */
# define MEM(a)        memset(ara,true,sizeof(ara));

/*Input section*/
# define si(a) scanf("%d",&a)
# define sii(a,b) scanf("%d %d",&a,&b)
# define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)

# define sl(a) scanf("%lld",&a);
# define sll(a,b) scanf("%lld %lld",&a,&b);
# define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);

#define FR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define FRR(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)

#define fr(i,a,b) for(int i=a;i<(int)b;i++)
#define frr(i,a,b) for(int i=a;i<=(int)b;i++)

///Output section
# define SP printf(" ")
# define NL printf("\n")
# define CH getchar()
# define DB printf("I AM HERE\n")
# define open freopen("input.txt","r",stdin)
# define close freopen("output.txt","w",stdout)
# define FAST ios_base::sync_with_stdio(0),cin.tie(0)

///output for int data type
# define pi(a) printf("%d\n",a)
# define pii(a,b) printf("%d %d\n",a,b)
# define piii(a,b,c) printf("%d %d %d\n",a,b,c)

///output for ll data type
void pl(ll a){printf("%lld\n",a);}
void pll(ll a,ll b){printf("%lld %lld\n",a,b);}
void plll(ll a,ll b,ll c){printf("%lld %lld %lld ",a,b,c);}

# define LB(x,p) lower_bound(all(x),p)-(x).begin()
# define UB(x,p) upper_bound(all(x),p)-(x).begin()
# define VVV(x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++) cout << *it,SP;NL;

void sss(string s)           {cout<<s,NL;}
ll string_to_ll(string s)    {stringstream ss;ss<<s;ll n;ss>>n;return n;}
string ll_to_string(ll n)    {stringstream ss;ss<<n;string s;ss>>s;return s;}

/*********************************************************************************
 *                 ###############################                               *
 *                 #  [ END OF ALL DECLARATION ] #                               *
 *                 ###############################                               *
 *********************************************************************************/

              /*STARTING OF MAIN FUNCTION*/

int main()
{
       int n,k,c(0),i,j;
       string s;
       cin>>n>>k>>s;
       //fr(i,0,n) if(isupper(s[i])) s[i]=tolower(s[i]);
       sort(all(s));
       fr(i,0,n)
       {
              fr(j,i+1,n)
              {
                     if(s[i]!=s[j])
                     {
                            //cout << s[i] << " " << s[j] << endl;
                            c++;
                            s.erase(s.begin()+j);
                            break;
                     }
              }
       }
       if(2*c==n) sss("YES");
       else sss("NO");
       return 0;
}

              /*Anyone who has never made a mistake has never tried anything new.
                             [ ~SIR ALBERT EINSTINE~ ]*/


#include <iostream>
using namespace std;

class linkedListNode {
public:
    int data;
    linkedListNode* next;
    linkedListNode(int data) {
        this->data = data;
        this->next = nullptr;
    };
};

class linkedList {
public:
    linkedListNode* head;
    linkedListNode* tail;
    int size;
    linkedList() {
        this->head = nullptr;
        this->tail = nullptr;
        this->size = 0;
    }
    void insert(int data);
    void remove(int data);

    void print() const;

};

void linkedList::insert(int data) {
    linkedListNode* newNode = new linkedListNode(data);
    if (this->head == nullptr) {
        this->head = newNode;
        this->tail = newNode;
    }
    else {
        this->tail->next = newNode;
        this->tail = newNode;
    }
    this->size += 1;
}

void linkedList::remove(int data) {
    linkedListNode* prev = nullptr;
    linkedListNode* curr = this->head;
    while (curr != nullptr) {
        if (curr->data == data) {
            if (prev == nullptr) {
                linkedListNode* temp = this->head;
                curr = curr->next;
                this->head = curr;
                delete temp;
                temp = nullptr;
            }
            else if (curr->next == nullptr) {
                linkedListNode* temp = this->tail;
                prev->next = nullptr;
                this->tail = prev;
                delete temp;
                temp = nullptr;
            }
            else {
                linkedListNode* temp = curr;
                curr = curr->next;
                prev->next = curr;
                delete temp;
                temp = nullptr;
            }
        }
        else {
            prev = curr;
            curr = curr->next;
        }
    }
}

void linkedList::print() const {
    linkedListNode* curr = this->head;
    while (curr != nullptr) {
        cout << curr->data << " ";
        curr = curr->next;
    }
}

int main() {
    int numbers;
    int temp;
    linkedList input;
    cin >> numbers;
    for (int i = 0; i < numbers; i++) {
        cin >> temp;
        input.remove(temp);
        input.insert(temp);
    }
    input.print();
}


#include <bits/stdc++.h>
using namespace std;
int arr[100000000];
int main(){
int n;
cin>>n;
int sum=0;
for(int i=0;i<n;++i){
cin>>arr[i];
(arr[i]==100)?sum++:sum+=2;
}
if(sum%2==0)cout<<"YES";
else cout<<"NO";
}


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

#define F first
#define S second
#define x1 privet1
#define x2 privet2
#define y1 privet3
#define y2 privet4

using namespace std;

    int x, y, x1, y1;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> x >> y >> x1 >> y1;
    if(x<=x1 && y<=y1){cout << "Polycarp"; return 0;}
    if(x>=x1 && y>=y1){cout << "Vasiliy"; return 0;}
    if(x>=x1 && y<=y1){
        if(y1-y < min(max(x1, y1), x-x1+y1-y)){cout << "Vasiliy"; return 0;}
        cout << "Polycarp";
        return 0;
    }
    if(x<=x1 && y>=y1){
        if(x1-x < min(max(x1, y1), y-y1+x1-x)){cout << "Vasiliy"; return 0;}
        cout << "Polycarp";
        return 0;
    }
}


#include<bits/stdc++.h>
using namespace std;
char a[1000000005];
int main(){
	int b=0,c=0;
	cin>>a;
	int k=strlen(a);
	for(int i=0;i<k;i++){
		if(a[i]=='o') b++;
		else c++;
	}
		if(c%b==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a[15],n,i;
int main()
{
	string s;
	cin>>n;
	if (n<11) {printf("0\n");exit(1);}
	cin>>s;
	int ok=1,l=s.length();
	for (i=0;i<l;i++){
		int m=s[i]-48;a[m]++;
		if (m==8) ok=0;
	}
	if (ok) {printf("0\n");exit(1);} else a[8]--;
	int min=a[0];
	for (i=0;i<=9;i++){
		if (min>a[i]) min=a[i];
	}
	if (min==0) printf("1\n"); else printf("%d\n",min);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir---------------------------
struct node
{
	int id;
	int red, blue;
	node() { red = blue = 0; }
	node(int id,int r=0,int b=0) {
		this->id = id;
		red = r;
		blue = b;
	}
};
ll mod = 1e9 + 7;
ll bfs(int n)
{
	int cnt = 1;
	queue<node>q;
	node now = node(1);
	q.push(now);
	while (!q.empty())
	{
		now = q.front();
		q.pop();
		if (now.red < n)q.push(node( (++cnt), now.red + 1, now.blue));
		if (now.blue < n)q.push(node( (++cnt), now.red, now.blue + 1));
		cnt %= mod;
	}
	return cnt;
}
int32_t main()
{
	//   freopen("1.in","r",stdin);
	int n;
	while (~scanf("%d", &n))
	{
		print(bfs(n));
	}

	return Accepted;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, n) for(int i = a; i < n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define ios ios::sync_with_stdio(false);cin.tie(0);
#define debug(x)    cout << x << endl;
#define SZ(x)    (int)x.size()
typedef long long ll;
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
void read(int &x) {int s = 0, f = 1; char ch = getchar(); while(!isdigit(ch)) {f = (ch == '-' ? -1 : f); ch = getchar();} while(isdigit(ch)) {s = s * 10 + ch - '0'; ch = getchar();} x = s * f;}
string yes = "Yes\n"; string no = "No\n";

const int mod = 1e9 + 7;
const int N = 100005;
int vis[N];
vector<int> primes;
int phi[N];

void euler_n(int n)
{
    memset(vis, 0, sizeof vis);
    for(int i = 1; i < n; i ++)    phi[i] = 1;
    for(int i = 2; i < n; i ++)
    {
        if(vis[i] == 0)
        {
            vis[i] = 1;
            primes.pb(i);
            phi[i] = i - 1;
        }

        for(int j = 0; j < SZ(primes); j ++)
        {
            if(primes[j] > n / i)   break;
            vis[primes[j] * i] = 1;
            if(i % primes[j] == 0)
            {
                phi[i * primes[j]] = phi[i] * primes[j];
                break;
            }
            else
                phi[i * primes[j]] = phi[i] * (primes[j] - 1);
        }
    }
}

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

int main()
{
    euler_n(N);
    int n;
    cin >> n;
    ll res = 0;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 2 * i; j < n; j += i)
            res = (res + lcm(i, n - j) * phi[j / i]) % mod;
    }
    cout << res << '\n';
}