Little Johnny Bubbles enjoys spending hours in front of his computer playing video games. His favorite game is Bubble Strike, fast-paced bubble shooting online game for two players.Each game is set in one of the N maps, each having different terrain configuration. First phase of each game decides on which map the game will be played. The game system randomly selects three maps and shows them to the players. Each player must pick one of those three maps to be discarded. The game system then randomly selects one of the maps that were not picked by any of the players and starts the game.Johnny is deeply enthusiastic about the game and wants to spend some time studying maps, thus increasing chances to win games played on those maps. However, he also needs to do his homework, so he does not have time to study all the maps. That is why he asked himself the following question: "What is the minimum number of maps I have to study, so that the probability to play one of those maps is at least $$$P$$$"?Can you help Johnny find the answer for this question? You can assume Johnny's opponents do not know him, and they will randomly pick maps.

The first line contains two integers $$$N$$$ ($$$3$$$ $$$\leq$$$ $$$N$$$ $$$\leq$$$ $$$10^{3}$$$) and $$$P$$$ ($$$0$$$ $$$\leq$$$ $$$P$$$ $$$\leq$$$ $$$1$$$) – total number of maps in the game and probability to play map Johnny has studied. $$$P$$$ will have at most four digits after the decimal point.

Output contains one integer number – minimum number of maps Johnny has to study.

def prob(n,k):
    pt=(k*(k-2)*(k-1)+3*(k-1)*k*(n-k)+3/2*k*(n-k)*(n-k-1))/(n*(n-2)*(n-1))
    return pt
np=input()
np=np.split(' ')
n=int(np[0])
p=float(np[1])
left=0
right=n
while(left<right):
    k=(left+right)//2
    if(prob(n,k)<p):
        left=k+1
    else:
        right=k

while(prob(n,k)<p):
    k+=1

print(k)

def naiveSolve():

    return

def solve():

    return

def getP(n,x):
    # calculate for all 3 known
    if x<3:
        p3=0
    else:
        p3=(x/n)*((x-1)/(n-1))*((x-2)/(n-2))

    # calculate for 2 known
    if x<2:
        p2=0
    else:
        p2=3*(x/n)*((x-1)/(n-1))*((n-x)/(n-2))
        # discard the unknown

    # calculate for 1 known
    if x<1:
        p1=0
    else:
        p1=3*(x/n)*((n-x)/(n-1))*((n-x-1)/(n-2))

        p11=p1*(1/3)*0.5 # opponent picks the same 0 map as Johnny to discard
        p12=p1*(1/3) # opponent picks a different 0 map as Johnny to discard
        p1=p11+p12

    return p1+p2+p3

# def getP2(n,x):
#     from random import randint
#     arr=[0]*(n-x)+[1]*n
#     cnts=100000
#     succeedCnts=0
#     for _ in range(cnts):
#         a=b=c=randint(0,n-1)
#         while b==a:
#             b=randint(0,n-1)
#         while c==a or c==b:
#             c=randint(0,n-1)
#         arr3=[arr[a],arr[b],arr[c]]
#         x=sum(arr3) # known map cnts
#         y=3-x
#         opponentPick=randint(0,2)
#         if y>0:
#             myPick=-1
#             while myPick==-1 or arr3[myPick]==1:
#                 myPick=randint(0,2)
#         else:
#             myPick=randint(0,2)
#         arr2=[]
#         for i in range(3):
#             if i!=opponentPick and i!=myPick:
#                 arr2.append(arr3[i])
#         succeedCnts+=arr2[randint(0,len(arr2)-1)]
#     return succeedCnts/cnts

def main():

    eps=0

    n,p=input().split()
    n=int(n)
    p=float(p)

    x=-1
    bb=n
    while bb>0:
        while x+bb<=n and getP(n,x+bb)+eps<p:
            x+=bb
        bb//=2
    x+=1

    print(x)

    # for x in range(0,n+1):
    #     p=getP(n,x)
    #     p2=getP2(n,x)
    #     print('x:{} p:{} p2:{}'.format(x,p,p2))

    return

import sys
# input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.

def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
    return [int(x) for x in input().split()]
# def readFloatArr():
#     return [float(x) for x in input().split()]

def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])
    dv=defaultValFactory;da=dimensionArr
    if len(da)==1:return [dv() for _ in range(da[0])]
    else:return [makeArr(dv,da[1:]) for _ in range(da[0])]

def queryInteractive(x):
    print('{}'.format(x))
    sys.stdout.flush()
    return int(input())

def answerInteractive(ans):
    print('! {}'.format(ans))
    sys.stdout.flush()

inf=float('inf')
# MOD=10**9+7
# MOD=998244353

from math import gcd,floor,ceil
# from math import floor,ceil # for Python2

for _abc in range(1):
    main()

n, p = input().split()
n = int(n)
p = float(p)

gt = [1, 1, 2, 6]

def C(n, k):
    if(n<k):
        return 0
    ans = 1
    for i in range(n-k+1, n+1):
        ans*=i
    return ans//gt[k]

# k la so muon hoc
def check(k):
    t1 = (C(k, 1) * C(n - k, 2)) / C(n, 3)
    t2 = (C(k, 2) * C(n - k, 1)) / C(n, 3)
    t3 = C(k, 3) / C(n, 3)

    p1 = (1/3 + (1/3)*0.5) * t1

    return p1 + t2 + t3 >= p

l = 0
r = n-1
while l<=r:
    m = (l+r)//2
    if check(m):
        r = m - 1
    else:
        l = m + 1
print(l)

import random

inp = input().split(" ")
N = int(inp[0])
P = float(inp[1])

# def sim1sm(N, P, s):
#     numTrials = 20000
#     succ = 0
#     for _ in range(numTrials):
#         r = [1]
#         for _ in range(2):
#             n = random.randint(s+1,N)
#             while n in r:
#                 n = random.randint(1,N)
#             r.append(n)

#         disc = []
#         for i in range(3):
#             if r[i] > s:
#                 disc.append(r[i])
#                 break
#         if len(disc) == 0:
#             succ += 1
#             continue

#         sd = random.randint(1, 3)
#         disc.append(r[sd-1])

#         fc = []
#         for i in r:
#             if not i in disc:
#                 fc.append(i)

#         mcidx = random.randint(1, len(fc))
#         mc = fc[mcidx - 1]
#         if mc <= s:
#             succ += 1

#     return succ/numTrials

l = 0
r = N
while(l < r):
    mid = int((l+r)/2)
    expProb = 0.0
    if mid >= 3:
        expProb += ((mid * (mid-1) * (mid-2)) / (N * (N-1) * (N-2)))
    if mid >= 2:
        expProb += (3 * ((N - mid)/N) * (mid/(N-1)) * ((mid-1)/(N-2)))
    if mid >= 1:
        condProb = (3 * (mid/N) * ((N-mid)/(N-1)) * ((N-mid-1)/(N-2)))
        expProb +=  (condProb * (1/3)) + (condProb * (1/3) * (1/2))

    if expProb < P:
        l = mid+1
    else:
        r = mid

print(l)

n, p = input().split()

p = float(p)
n = int(n)

def cnk(n, k):
	if n < k:
		return 0
	ret = 1
	if(k == 1):
		return n
	if k == 2:
		return n * (n - 1) // 2
	return n * (n - 1) * (n - 2) // 6

for i in range(0, n + 1):
	cur_prob = 0.0

#	ca = i / n * (n - i) / n * (n - i - 1) / n
	ca = cnk(i, 1) * cnk(n - i, 2) / cnk(n, 3)
	ca = ca * 3 / 6

#	cb = i / n * (i - 1) / n * (n - i) / n
#	cb = cb / 2
	cb = cnk(i, 2) * cnk(n - i, 1) / cnk(n, 3)
	cb = cb
#	cc = i / n * (i - 1) / n * (i - 2) / n
#	cb = cb
	cc = cnk(i, 3) / cnk(n, 3)
	cur_prob = ca + cb + cc
#	print(cur_prob)
	if(cur_prob >= p):
		print(i)
		break;

n, p = map(float, input().split())
ans, n = 0, int(n)
all, be, en = n * (n - 1) * (n - 2) // 6, 0, n - 1

while be <= en:
    i = (be + en) >> 1
    deln, newp = n - i, 0
    if i > 2:
        newp += i * (i - 1) * (i - 2) // 6
    if i > 1:
        newp += deln * i * (i - 1) // 2
    if deln > 1:
        newp += deln * (deln - 1) * i / 4

    if newp / all >= p:
        ans, en = i, i - 1
    else:
        be = i + 1
print(ans)

n, p = map(float, input().split())
ans, n = 0, int(n)
all = n * (n - 1) * (n - 2) // 6

for i in range(n):
    deln, newp = n - i, 0
    if i > 2:
        newp += i * (i - 1) * (i - 2) // 6
    if i > 1:
        newp += deln * i * (i - 1) // 2
    if deln > 1:
        newp += deln * (deln - 1) * i / 4

    if newp / all >= p:
        break
    ans += 1

print(ans)

import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def solve():
    arr=list(input().split())
    n,p=int(arr[0]),float(arr[1])

    def judge(m):
        res=0
        res+=(m*(n-m)*(n-m-1))/4
        res+=(m*(max(0,m-1))*(n-m))/2
        res+=m*(max(m-1,0))*(max(m-2,0))/6
        #print('res',m,res)
        return res<p*(n*(n-1)*(n-2)/6)

    l,r=0,n
    while l<r:
        mid=(l+r)>>1
        #print(mid)
        if judge(mid):
            l=mid+1
        else:
            r=mid

    print(l)

solve()

from xml.dom import minidom

def solve():
    arr=list(input().split())
    n,p=int(arr[0]),float(arr[1])

    def judge(m):
        res=0
        res+=(m*(n-m)*(n-m-1))/4
        res+=(m*(max(0,m-1))*(n-m))/2
        res+=m*(max(m-1,0))*(max(m-2,0))/6
        #print('res',m,res)
        return res<p*(n*(n-1)*(n-2)/6)

    l,r=0,n
    while l<r:
        mid=(l+r)>>1
        #print(mid)
        if judge(mid):
            l=mid+1
        else:
            r=mid

    print(l)

solve()

def prob(db, n):
    return db*(db-1)*(db-2)+(n-db)*db*(db-1)*3+(n-db)*(n-db-1)*db*3/2

n, p = input().split()
n = int(n)
p = float(p)
p *= n*(n-1)*(n-2)

s = 0
e = n-1
while s <= e:
    act = (s+e)//2
    if e-s == 1:
        if prob(s, n) >= p:
            break
        else:
            s = e
            break
    else:
        if prob(act, n) >= p:
            e = act
        else:
            s = act

print(s)

# from math import gcd
from math import *

# Function to find the nCr

def NcK(n, r):

    # p holds the value of n*(n-1)*(n-2)...,
    # k holds the value of r*(r-1)...
    p = 1
    k = 1

    # C(n, r) == C(n, n-r),
    # choosing the smaller value
    if (n - r < r):
        r = n - r

    if (r != 0):
        while (r):
            p *= n
            k *= r

            # gcd of p, k
            m = gcd(p, k)

            # dividing by gcd, to simplify product
            # division by their gcd saves from
            # the overflow
            p //= m
            k //= m

            n -= 1
            r -= 1

        # k should be simplified to 1
        # as C(n, r) is a natural number
        # (denominator should be 1 )

    else:
        p = 1

    # if our approach is correct p = ans and k =1
    return(p)

# for _ in range(int(input())):
#     # n = int(input())
#     # L = input().rstrip('\n')
#     n,a,b = list(map(int,input().split()))

a,b = list(map(float,input().split()))
# k = (a-1)*b
# if int(k) == k:
#     print(int(k))
# else:
#     print(int(k)+1)

a = int(a)
n = a
A = NcK(int(a),3)
if b == 0:
    print(0)
elif (NcK(n-1,2)/A)*0.5>=b:
    print (1)
elif (n-2)/A + (NcK(n-1,2)/A)*0.5 >= b:
    print(2)

else:
    # a1 = NcK(a-1,3)
    # a2 = NcK(a-1,2)
    # A = NcK(int(a),3)
    # a11 = NcK(a-2,3)
    # if (a1/A)*1+(a2/A)*1>=b and :
    #     print(a-1)
    flag = False
    for i in range(3,int(a)-1):
        a1 = NcK(i,3)
        a2 = NcK(i,2)
        a3 = NcK(i,1)
        a33 = NcK(a-i,2)
        A = NcK(int(a),3)
        if (a1/A)*1+(a2*(a-i)/A)*1+(a3*a33/A)*0.5>b:
            print(i)
            flag = True
            break
    if not flag:
        print(a-1)

def f(N, M):
    num = M*(M-1)*(M-2)//6 + M*(M-1)*(N-M)//2 + M*(N-M)*(N-M-1)/4
    den = N*(N-1)*(N-2)//6
    return num/den

def process(N, P):
    if P==0:
        return 0
    if P==1:
        return N-1
    s = 0
    e = N-1
    while s+1 < e:
        m = (s+e)//2
        if f(N, m) < P:
            s, e = m, e
        else:
            s, e = s, m
    return e

N, P = input().split()
N = int(N)
P = float(P)
print(process(N, P))

from decimal import Decimal
n, p = input().split()
n = int(n)
p = Decimal(p)
N = n * (n - 1) * (n - 2) // 6

def f(m):
    if m == 0:
        return 0
    if m == n:
        return N * 2
    A3 = m * (m - 1) * (m - 2) // 6
    A2 = m * (m - 1) * (n - m) // 2
    A1 = m * (n - m) * (n - m - 1) // 2
    return (A1 + A2 * 2 + A3 * 2)

for i in range(0, n+1):
    if f(i) >= N * p * 2:
        print(i)
        break

from math import factorial

def binomial(n, k):
  if n < k:
    return 0
  return factorial(n)/(factorial(k) * factorial(n - k))

n, p = list(input().split())

n = int(n)
p = float(p)

l, r = 0, n

while l < r:
  k = (l + r)//2
  cur = binomial(k, 3)/binomial(n, 3) + binomial(k, 2) * (n - k)/binomial(n, 3) + k * binomial(n - k, 2)/binomial(n, 3)/2
  if cur < p:
    l = k + 1
  else:
    r = k

print(l)

import math
import random
import sys

def main(n,p):
    tot=0

    for i in range(0,n):
        c0=math.comb(i,3)
        c1=math.comb(i,2)*math.comb(n-i,1)
        c2=math.comb(i,1)*math.comb(n-i,2)
        c3=math.comb(n-i,3)
        num=c0+c1+0.5*c2+0*c3
        den=c0+c1+c2+c3

        if (num/den)>=p:
            return i

    return "WHAT"

n,p=list(map(float,input().split()))
n=int(n)
print(main(n,p))

import math

def probCalc(studied, numMaps):
  total = math.comb(numMaps, 3)
  return (math.comb(studied, 3) + math.comb(studied, 2)*math.comb(numMaps - studied, 1) + 1/2*math.comb(studied, 1) * math.comb(numMaps - studied, 2))/total

[n,p] = input().split(' ')
n = int(n); p = float(p);
for i in range(n):
  if probCalc(i, n) >= p:
    print(i)
    break

from math import factorial as fac

tmp = 1
fc = []
for i in range(1001):
    fc.append(tmp)
    tmp *= (i+1)

def bio(n, m):
    if n < m:
        return 0
    return fc[n] // fc[m] // fc[n - m]

inp = input('').split(' ')
# inp = [1000, 1.00000]
N, P = int(inp[0]), float(inp[1])

for x in range(0, N):
    if (2 * bio(x, 3) + 2 *
        (N - x) * bio(x, 2) + x * bio(N - x, 2)) / (2 * bio(N, 3)) >= P:
        print(x)
        break

n, p = [float(x) for x in input().split()]
n = int(n)

def nck(n, k):
    if k > n:
        return 0
    tmp = 1
    for i in range(2, k):
        tmp *= k
    ans = 1
    for i in range(k):
        ans *= (n - i)
    return float(ans) / float(tmp)

for i in range(n + 1):
    known = i
    unknown = n - i
    ans = nck(unknown, 2) * nck(known, 1) * 0.5 + nck(unknown, 1) * nck(known, 2) * 1.0 + nck(known, 3) * 1.0
    ans /= max(nck(n, 3), 1)
    if ans >= p:
        print(i)
        break

import math

def combin(n, m):
    if n == m:
        return 1
    if n < m:
        return 0

    a = 1
    for i in range(n, n-m, -1):
        a *= i
    b = 1
    for i in range(1, m+1):
        b *= i

    return a / b

(a, b) = input().split()
n = int(a)
p = float(b) * combin(n,3)

for i in range(0, n+1):
    ans = combin(i, 3) + combin(i, 2) * combin(n-i, 1)
    ans += (combin(i, 1)*combin(n-i, 2)) / 2

    if ans >= p:
        print(i)
        break

import sys

def calc_probability(N, K):
    M = N - K
    a = [
        0,
        M * (M - 1) // 2 * K,
        M * K * (K - 1) // 2,
        K * (K - 1) * (K - 2) // 6,
    ]
    res = 0
    for i in range(1,4):
        b = [0] * 3
        for j in range(i):
            b[j] = 1
        p = 0
        x = 2
        for y in range(3):
            if x == y:
                p += (i - b[x])/2
            else:
                p += (i - b[x] - b[y])
        res += p / 3 * a[i]
    return res / (N * (N - 1) * (N - 2) // 6)

def solve():
    inp = sys.stdin.readline
    N, P = inp().split()
    N, P = int(N), int(float(P)*10000+0.5)
    r = N
    l = -1
    while r - l > 1:
        c = (l + r) // 2
        if calc_probability(N, c) * 10000 >= P:
            r = c
        else:
            l = c
    print(r)

def main():
    solve()

if __name__ == '__main__':
    main()

from math import *

prec = [0, 0.5, 1, 1]

def prob(known, unknown):
    cnt = 0
    ret = 0
    for i in range(4):
        cur = comb(known, i) * comb(unknown, 3 - i)
        cnt += cur
        ret += cur * prec[i]
    return ret / cnt

inp = input().split()
n = int(inp[0])
p = float(inp[1])

for i in range(n + 1):
    if prob(i, n - i) >= p:
        print(i)
        break

import decimal

n, p = input().split(' ')
n = int(n)
p = decimal.Decimal(p)

ans = n - 1
for k in range(0, n):
  p1 = (decimal.Decimal(n-k)*(n-k-1)*k*3) / (n*(n-1)*(n-2)*2)
  p2 = (decimal.Decimal(n-k)*k*(k-1)*3) / (n*(n-1)*(n-2))
  p3 = (decimal.Decimal(k-1)*(k-2)*k) / (n*(n-1)*(n-2))

  # print(p1, p2, p3, ' - ')

  if p1 + p2 + p3 >= p:
    ans = k
    break

print(ans)

import math

class Rational :

    def __init__ (self, a, b) :
        a, b = int(a), int(b)
        g = math.gcd(a, b)
        self.a = a / g
        self.b = b / g

    def __mul__ (self, t) :
        return Rational(self.a * t.a, self.b * t.b)

    def __add__ (self, t) :
        a = self.a * t.b + self.b * t.a
        b = self.b * t.b
        return Rational(a, b)

    def __sub__ (self, t) :
        a = self.a * t.b - self.b * t.a
        b = self.b * t.b
        return Rational(a, b)

    def __le__ (self, t) :
        return self.a * t.b <= self.b * t.a

    def __repr__ (self) :
        return f'{self.a / self.b}'

def nC3 (n) :
    if n >= 3 :
        return (n * (n - 1) * (n - 2)) // 6
    return 0

def nC2 (n) :
    if n >= 2 :
        return (n * (n - 1)) // 2
    return 0

stuff = input().split()
n, p = stuff
n = int(n)
p = float(p)
p = Rational(1e9 * p, 1e9)

one = Rational(1, 1)
nc3 = nC3(n)

for k in range(0, n + 1) :
    t = Rational(nC3(k), nc3)
    t = t + (Rational(1, 2) * Rational(k * nC2(n - k), nc3))
    t = t + Rational((n - k) * nC2(k), nc3)
    if p <= t:
        break
print(k)

def binom(x,y):
    if y == 2:
        return x * (x-1) / 2
    if y == 3:
        return x * (x-1) * (x-2) / 6

n,prob = map(float,input().split())
if prob == 0.0:
    print(0)
    exit()

n = int(n)

def p(m):
    ans = 0
    if n-m >= 2 and m >= 1:
        ans += m * (binom(n-m,2)) / 2

    if n-m >= 1 and m >= 2:
        ans += m * (m-1) * (n-m) / 2

    if m >= 3:
        ans += binom(m,3)

    if ans == binom(n,3):
        return 1.0

    return ans / binom(n,3)

lo,hi = 1.0, float(n)
if p(lo) >= prob:
    print(1)
    exit()

while lo+1 < hi:
    mid = (hi+lo) // 2
    case = p(float(mid))

    if case >= prob:
        hi = mid
    else:
        lo = mid

print(int(hi))
exit()

n,target = map(float,input().split())
n = int(n)

def getprob(study):

    tot = n*(n-1)*(n-2)//6
    case1 = study*(study-1)*(study-2)//6
    case2 = study*(study-1)*(n-study)//2
    case3 = study*(n-study)*(n-study-1)//2

    return (case1+case2+case3*0.5)*1.0/tot

front = 0
rear = n

while front<rear:

    mid = (front+rear)//2
    p = getprob(mid)

#    print(mid,p)

    if p < target:   front = mid + 1
    else:  rear = mid

print(front)

import sys
input = sys.stdin.readline

get_int = lambda: int(input().rstrip())
get_arr = lambda: [int(w) for w in input().split()]
get_str = lambda: input().rstrip()

n, p = input().split()
n = int(n)
p = float(p)
eps = 0.1 ** 8

def f(k):
    return k * (k - 1) * (k - 2) / 6 + k * (k - 1) * (n - k) / 2 + k * (n - k) * (n - k - 1) / 2 * 0.5

for k in range(n + 1):
    if f(k) + eps >= n * (n - 1) * (n - 2) / 6 * p:
        print(k)
        break

def naiveSolve():

    return

def solve():

    return

def getP(n,x):
    # calculate for all 3 known
    if x<3:
        p3=0
    else:
        p3=(x/n)*((x-1)/(n-1))*((x-2)/(n-2))

    # calculate for 2 known
    if x<2:
        p2=0
    else:
        p2=3*(x/n)*((x-1)/(n-1))*((n-x)/(n-2))
        # discard the unknown

    # calculate for 1 known
    if x<1:
        p1=0
    else:
        p1=3*(x/n)*((n-x)/(n-1))*((n-x-1)/(n-2))

        p11=p1*(1/3)*0.5 # opponent picks the same 0 map as Johnny to discard
        p12=p1*(1/3) # opponent picks a different 0 map as Johnny to discard
        p1=p11+p12

    return p1+p2+p3

# def getP2(n,x):
#     from random import randint
#     arr=[0]*(n-x)+[1]*n
#     cnts=100000
#     succeedCnts=0
#     for _ in range(cnts):
#         a=b=c=randint(0,n-1)
#         while b==a:
#             b=randint(0,n-1)
#         while c==a or c==b:
#             c=randint(0,n-1)
#         x=arr[a]+arr[b]+arr[c] # known map
#         y=3-x
#         if y>0:
#             y-=1
#         else:
#             x-=1
#         arr2=[]
#         for __ in range(x): arr2.append(1)
#         for __ in range(y): arr2.append(0)
#         succeedCnts+=arr2[randint(0,1)]
#     return succeedCnts/cnts

def main():

    eps=0

    n,p=input().split()
    n=int(n)
    p=float(p)

    x=0
    bb=n
    while bb>0:
        while x+bb<=n and getP(n,x+bb)+eps<p:
            x+=bb
        bb//=2
    x+=1

    print(x)

    # for x in range(0,n+1):
    #     p=getP(n,x)
    #     p2=getP2(n,x)
    #     print('x:{} p:{} p2:{}'.format(x,p,p2))

    return

import sys
# input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.

def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
    return [int(x) for x in input().split()]
# def readFloatArr():
#     return [float(x) for x in input().split()]

def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])
    dv=defaultValFactory;da=dimensionArr
    if len(da)==1:return [dv() for _ in range(da[0])]
    else:return [makeArr(dv,da[1:]) for _ in range(da[0])]

def queryInteractive(x):
    print('{}'.format(x))
    sys.stdout.flush()
    return int(input())

def answerInteractive(ans):
    print('! {}'.format(ans))
    sys.stdout.flush()

inf=float('inf')
# MOD=10**9+7
# MOD=998244353

from math import gcd,floor,ceil
# from math import floor,ceil # for Python2

for _abc in range(1):
    main()

def naiveSolve():

    return

def solve():

    return

def getP(n,x):
    # calculate for all 3 known
    if x<3:
        p3=0
    else:
        p3=(x/n)*((x-1)/(n-1))*((x-2)/(n-2))

    # calculate for 2 known
    if x<2:
        p2=0
    else:
        p2=3*(x/n)*((x-1)/(n-1))*((n-x)/(n-2))
        # discard the unknown

    # calculate for 1 known
    p1=3*(x/n)*((n-x)/(n-1))*((n-x-1)/(n-2))
    p1*=0.5 # final pick is random

    return p1+p2+p3

def getP2(n,x):
    from random import randint
    arr=[0]*(n-x)+[1]*n
    cnts=100000
    succeedCnts=0
    for _ in range(cnts):
        a=b=c=randint(0,n-1)
        while b==a:
            b=randint(0,n-1)
        while c==a or c==b:
            c=randint(0,n-1)
        x=arr[a]+arr[b]+arr[c] # known map
        y=3-x
        if y>0:
            y-=1
        else:
            x-=1
        arr2=[]
        for __ in range(x): arr2.append(1)
        for __ in range(y): arr2.append(0)
        succeedCnts+=arr2[randint(0,1)]
    return succeedCnts/cnts

def main():

    eps=0

    n,p=input().split()
    n=int(n)
    p=float(p)

    x=0
    bb=n
    while bb>0:
        while x+bb<=n and getP(n,x+bb)+eps<p:
            x+=bb
        bb//=2
    x+=1

    print(x)

    # for x in range(2,n+1):
    #     p=getP(n,x)
    #     p2=getP2(n,x)
    #     print('x:{} p:{} p2:{}'.format(x,p,p2))

    return

import sys
# input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.

def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
    return [int(x) for x in input().split()]
# def readFloatArr():
#     return [float(x) for x in input().split()]

def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])
    dv=defaultValFactory;da=dimensionArr
    if len(da)==1:return [dv() for _ in range(da[0])]
    else:return [makeArr(dv,da[1:]) for _ in range(da[0])]

def queryInteractive(x):
    print('{}'.format(x))
    sys.stdout.flush()
    return int(input())

def answerInteractive(ans):
    print('! {}'.format(ans))
    sys.stdout.flush()

inf=float('inf')
# MOD=10**9+7
# MOD=998244353

from math import gcd,floor,ceil
# from math import floor,ceil # for Python2

for _abc in range(1):
    main()

def naiveSolve():

    return

def solve():

    return

def getP(n,x):
    # calculate for all 3 known
    if x<3:
        p3=0
    else:
        p3=(x/n)*((x-1)/(n-1))*((x-2)/(n-2))

    # calculate for 2 known
    if x<2:
        p2=0
    else:
        p2=3*(x/n)*((x-1)/(n-1))*((n-x)/(n-2))
        # discard the unknown

    # calculate for 1 known
    p1=3*(x/n)*((n-x)/(n-1))*((n-x-1)/(n-2))
    p1*=0.5 # final pick is random

    return p1+p2+p3

def main():

    eps=0

    n,p=input().split()
    n=int(n)
    p=float(p)

    x=1
    bb=n
    while bb>0:
        while x+bb<=n and getP(n,x+bb)+eps<p:
            x+=bb
        bb//=2
    x+=1

    print(x)

    return

import sys
# input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.

def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
    return [int(x) for x in input().split()]
# def readFloatArr():
#     return [float(x) for x in input().split()]

def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])
    dv=defaultValFactory;da=dimensionArr
    if len(da)==1:return [dv() for _ in range(da[0])]
    else:return [makeArr(dv,da[1:]) for _ in range(da[0])]

def queryInteractive(x):
    print('{}'.format(x))
    sys.stdout.flush()
    return int(input())

def answerInteractive(ans):
    print('! {}'.format(ans))
    sys.stdout.flush()

inf=float('inf')
# MOD=10**9+7
# MOD=998244353

from math import gcd,floor,ceil
# from math import floor,ceil # for Python2

for _abc in range(1):
    main()

def naiveSolve():

    return

def solve():

    return

def getP(n,x):
    # calculate for all 3 known
    if x<3:
        p3=0
    else:
        p3=(x/n)*((x-1)/(n-1))*((x-2)/(n-2))

    # calculate for 2 known
    if x<2:
        p2=0
    else:
        p2=3*(x/n)*((x-1)/(n-1))*((n-x)/(n-2))
        # discard the unknown

    # calculate for 1 known
    p1=3*(x/n)*((n-x)/(n-1))*((n-x-1)/(n-2))
    p1*=0.5 # final pick is random

    return p1+p2+p3

def main():

    eps=0.00000001

    n,p=input().split()
    n=int(n)
    p=float(p)

    x=1
    bb=n
    while bb>0:
        while x+bb<=n and getP(n,x+bb)+eps<p:
            x+=bb
        bb//=2
    x+=1

    print(x)

    return

import sys
# input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.

def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
    return [int(x) for x in input().split()]
# def readFloatArr():
#     return [float(x) for x in input().split()]

def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])
    dv=defaultValFactory;da=dimensionArr
    if len(da)==1:return [dv() for _ in range(da[0])]
    else:return [makeArr(dv,da[1:]) for _ in range(da[0])]

def queryInteractive(x):
    print('{}'.format(x))
    sys.stdout.flush()
    return int(input())

def answerInteractive(ans):
    print('! {}'.format(ans))
    sys.stdout.flush()

inf=float('inf')
# MOD=10**9+7
# MOD=998244353

from math import gcd,floor,ceil
# from math import floor,ceil # for Python2

for _abc in range(1):
    main()

n, p = input().split()
n = int(n)
p = float(p)

gt = [1, 1, 2, 6]

def C(n, k):
    if(n<k):
        return 0
    ans = 1
    for i in range(n-k+1, n+1):
        ans*=i
    return ans//gt[k]

# k la so muon hoc
def check(k):
    t0 = C(n - k, 3) / C(n, 3)
    t1 = (C(k, 1) * C(n - k, 2)) / C(n, 3)
    t2 = (C(k, 2) * C(n - k, 1)) / C(n, 3)
    t3 = C(k, 3) / C(n, 3)
    t = t1*0.5 + t2 + t3
    return t*(k/(n-1)) + (1 - t)*(k/n) >= p

l = 0
r = n-1
while l<=r:
    m = (l+r)//2
    if check(m):
        r = m - 1
    else:
        l = m + 1
print(l)

n, p = input().split()
n = int(n)
p = float(p)

gt = [1, 1, 2, 6]

def C(n, k):
    ans = 1
    for i in range(n-k+1, n+1):
        ans*=i
    return ans//gt[k]

# k la so muon hoc
def check(k):
    t = C(n-k, 3)/C(n, 3)
    return (k/n)*t+k/(n-1) >= p

l = 0
r = n-1
while l<=r:
    m = (l+r)//2
    if check(m):
        r = m - 1
    else:
        l = m + 1
print(l)

def C(n, k):
    if k == 3:
        return n * (n - 1) * (n - 2) // 6
    else:
        return n * (n - 1) // 2

ss = input().split()
n = int(ss[0])
p = float(ss[1])
for k in range(n + 1):
    cur = C(n - k, 3) * 3 + k * C(n - k, 2)
    if C(n, 3) * 3 - cur >= p * 3 * C(n, 3):
        print(k)
        break

def C(n, k):
    if k == 3:
        return n * (n - 1) * (n - 2) // 6
    else:
        return n * (n - 1) // 2

ss = input().split()
n = int(ss[0])
p = float(ss[1])
for k in range(n + 1):
    cur = C(n - k, 3) / C(n, 3) + k * C(n - k, 2) / (3 * C(n, 3))
    if 1 - cur >= p:
        print(k)
        break

import random

inp = input().split(" ")
N = int(inp[0])
P = float(inp[1])

def sim(N, P, s):
    numTrials = 10000
    succ = 0
    for _ in range(numTrials):
        r = [random.randint(1, N)]
        for _ in range(2):
            n = random.randint(1,N)
            while n in r:
                n = random.randint(1,N)
            r.append(n)
        disc = []
        for i in range(3):
            if r[i] > s:
                disc.append(r[i])
                break
        if len(disc) == 0:
            succ += 1
            continue

        sd = random.randint(1, 3)
        disc.append(r[sd-1])

        fc = []
        for i in r:
            if not i in disc:
                fc.append(i)

        mcidx = random.randint(1, len(fc))
        mc = fc[mcidx - 1]
        if mc <= s:
            succ += 1

    return succ/numTrials

l = 0
r = N
while(l < r):
    mid = int((l+r)/2)
    if sim(N, P, mid) < P:
        l = mid+1
    else:
        r = mid

if abs(1 - P) < 1e-3:
    print(N-1)
else:
    print(l)

import random

inp = input().split(" ")
N = int(inp[0])
P = float(inp[1])

def sim(N, P, s):
    numTrials = 10000
    succ = 0
    for _ in range(numTrials):
        r = [random.randint(1, N)]
        for _ in range(2):
            n = random.randint(1,N)
            while n in r:
                n = random.randint(1,N)
            r.append(n)
        disc = []
        for i in range(3):
            if r[i] > s:
                disc.append(r[i])
                break
        if len(disc) == 0:
            succ += 1
            continue

        sd = random.randint(1, 3)
        disc.append(r[sd-1])

        fc = []
        for i in r:
            if not i in disc:
                fc.append(i)

        mcidx = random.randint(1, len(fc))
        mc = fc[mcidx - 1]
        if mc <= s:
            succ += 1

    return succ/numTrials

l = 0
r = N
while(l < r):
    mid = int((l+r)/2)
    if sim(N, P, mid) < P - 1e-6:
        l = mid+1
    else:
        r = mid

print(l)

n, p = input().split()

p = float(p)
n = int(n)

def cnk(n, k):
	if n < k:
		return 0
	ret = 1
	if(k == 1):
		return n
	if k == 2:
		return n * (n - 1) // 2
	return n * (n - 1) * (n - 2) // 6

for i in range(0, n + 1):
	cur_prob = 0.0

#	ca = i / n * (n - i) / n * (n - i - 1) / n
	ca = cnk(i, 1) * cnk(n - i, 2) / cnk(n, 3)
	ca = ca * 3 / 5

#	cb = i / n * (i - 1) / n * (n - i) / n
#	cb = cb / 2
	cb = cnk(i, 2) * cnk(n - i, 1) / cnk(n, 3)
	cb = cb
#	cc = i / n * (i - 1) / n * (i - 2) / n
#	cb = cb
	cc = cnk(i, 3) / cnk(n, 3)
	cur_prob = ca + cb + cc
#	print(cur_prob)
	if(cur_prob >= p):
		print(i)
		break;

n, p = input().split()

p = float(p)
n = int(n)

def cnk(n, k):
	if n < k:
		return 0
	ret = 1
	if(k == 1):
		return n
	if k == 2:
		return n * (n - 1) // 2
	return n * (n - 1) * (n - 2) // 6

for i in range(0, n + 1):
	cur_prob = 0.0

#	ca = i / n * (n - i) / n * (n - i - 1) / n
	ca = cnk(i, 1) * cnk(n - i, 2) / cnk(n, 3)
	ca = ca / 3

#	cb = i / n * (i - 1) / n * (n - i) / n
#	cb = cb / 2
	cb = cnk(i, 2) * cnk(n - i, 1) / cnk(n, 3)

#	cc = i / n * (i - 1) / n * (i - 2) / n
#	cb = cb
	cc = cnk(i, 3) / cnk(n, 3)
	cur_prob = ca + cb + cc
#	print(cur_prob)
	if(cur_prob >= p):
		print(i)
		break;

n, p = input().split()

p = float(p)
n = int(n)

def cnk(n, k):
	if n < k:
		return 0
	ret = 1
	for i in range(k + 1, n + 1):
		ret *= i
	for i in range(1, n - k + 2):
		ret = ret // i
	return ret
for i in range(1, n + 1):
	cur_prob = 0.0

#	ca = i / n * (n - i) / n * (n - i - 1) / n
	ca = cnk(i, 1) * cnk(n - i, 2) / cnk(n, 3)
	ca = ca / 3

#	cb = i / n * (i - 1) / n * (n - i) / n
#	cb = cb / 2
	cb = cnk(i, 2) * cnk(n - i, 1) / cnk(n, 3)

#	cc = i / n * (i - 1) / n * (i - 2) / n
#	cb = cb
	cc = cnk(i, 3) / cnk(n, 3)
	cur_prob = ca + cb + cc
#	print(cur_prob)
	if(cur_prob >= p):
		print(i)
		break;

n, p = map(float, input().split())
ans, n = 0, int(n)
all, be, en = n * (n - 1) * (n - 2) // 6, 0, n - 1

while be < en:
    i = (be + en) >> 1
    deln, newp = n - i, 0
    if i > 2:
        newp += i * (i - 1) * (i - 2) // 6
    if i > 1:
        newp += deln * i * (i - 1) // 2
    if deln > 1:
        newp += deln * (deln - 1) * i / 4

    if newp / all >= p:
        ans, en = i, i - 1
    else:
        be = i + 1
print(ans)

n, p = map(float, input().split())
ans, n = 1, int(n)
all = n * (n - 1) * (n - 2) // 6

for i in range(1, n):
    deln, newp = n - i, 0
    if i > 2:
        newp += i * (i - 1) * (i - 2) // 6
    if i > 1:
        newp += deln * i * (i - 1) // 2
    if deln > 1:
        newp += deln * (deln - 1) * i / 4

    if newp / all >= p:
        break
    ans += 1

print(ans)

def prob(db, n):
    return db*(db-1)*(db-2)+(n-db)*db*(db-1)*3+(n-db)*(n-db-1)*db*3/2

n, p = input().split()
n = int(n)
p = float(p)
p *= n*(n-1)*(n-2)

s = 0
e = n-1
while s <= e:
    act = (s+e)//2
    if e-s == 1:
        if prob(s, n) >= p:
            break
        else:
            s = e
            break
    else:
        if prob(act, n) == p:
            e = act
        else:
            s = act

print(s)

from decimal import Decimal
n, p = input().split()
n = int(n)
p = Decimal(p)
N = n * (n - 1) * (n - 2) // 6

def f(m):
    if m == n:
        return N * 2
    A3 = m * (m - 1) * (m - 2) // 6
    A2 = m * (m - 1) * (n - m) // 2
    A1 = m * (n - m) * (n - m - 1) // 2
    return (A1 + A2 * 2 + A3 * 2)

for i in range(1, n+1):
    if f(i) >= N * p * 2:
        print(i)
        break

from decimal import Decimal
n, p = input().split()
n = int(n)
p = Decimal(p)
N = n * (n - 1) * (n - 2) // 6

def f(m):
    if m == n:
        return N
    A3 = m * (m - 1) * (m - 2) // 6
    A2 = m * (m - 1) * (n - m) // 2
    A1 = m * (n - m) * (n - m - 1) // 2
    return (A1 + A2 * 2 + A3 * 2)

for i in range(1, n+1):
    if f(i) >= N * p * 2:
        print(i)
        break

from decimal import Decimal
n, p = input().split()
n = int(n)
p = Decimal(p)

def f(m):
    if m == n:
        return 1
    N = n * (n - 1) * (n - 2) / Decimal(6)
    A3 = m * (m - 1) * (m - 2) / Decimal(6)
    A2 = m * (m - 1) * (n - m) / Decimal(2)
    A1 = m * (n - m) * (n - m - 1) / Decimal(2)
    return (A1 + A2 * 2 + A3 * 2), N

for i in range(1, n+1):
    a, N = f(i)
    if a >= N * p * 2:
        print(i)
        break

from math import factorial

def binomial(n, k):
  if n < k:
    return 0
  return factorial(n)/(factorial(k) * factorial(n - k))

n, p = list(input().split())

n = int(n)
p = float(p)

l, r = 0, n

while l < r:
  k = (l + r)//2
  cur = binomial(k, 3)/binomial(n, 3) + binomial(k, 2)/binomial(n, 3) + k * binomial(n - k, 2)/binomial(n, 3)*(1/6 + 1/3)
  if cur < p:
    l = k + 1
  else:
    r = k

print(l)

from math import factorial

def binomial(n, k):
  if n < k:
    return 0
  return factorial(n)/(factorial(k) * factorial(n - k))

n, p = list(input().split())

n = int(n)
p = float(p)
ans = n

for k in range(1, n):
  cur = binomial(k, 3)/binomial(n, 3) + binomial(k, 2)/binomial(n, 3) + k * binomial(n - k, 2)/binomial(n, 3)*(1/6 + 1/3)
  if(cur >= p):
    ans = k
    break

print(ans)

import math
import random
import sys

def main(n,p):
    tot=9*(math.comb(n,3))
    for i in range(0,n):
        b=0
        b+=2*math.comb(n-i,2)*2*i

        b+=9*math.comb(n-i,3);
        if (1-b/tot)>=p:
            return i
    return "WHAT"

n,p=list(map(float,input().split()))
n=int(n)
print(main(n,p))

import math
import random
import sys

def main(n,p):
    tot=math.comb(n,3)*9;
    for i in range(0,n):
        b=0;
        b+=2*math.comb(n-i,2)*2

        b+=9*math.comb(n-i,3);
        if (1-b/tot)>=p:
            return i
    return "WHAT"

n,p=list(map(float,input().split()))
n=int(n)
print(main(n,p))

import math

def probCalc(studied, numMaps):
  total = math.comb(numMaps, 3)
  return (math.comb(studied, 3) + math.comb(studied, 2)*math.comb(numMaps - studied, 1) + 1/3*math.comb(studied, 1) * math.comb(numMaps - studied, 2))/total

[n,p] = input().split(' ')
n = int(n); p = float(p);
for i in range(n):
  if probCalc(i, n) >= p:
    print(i)
    break

import math

class Rational :

    def __init__ (self, a, b) :
        a, b = int(a), int(b)
        g = math.gcd(a, b)
        self.a = a / g
        self.b = b / g

    def __mul__ (self, t) :
        return Rational(self.a * t.a, self.b * t.b)

    def __add__ (self, t) :
        a = self.a * t.b + self.b * t.a
        b = self.b * t.b
        return Rational(a, b)

    def __sub__ (self, t) :
        a = self.a * t.b - self.b * t.a
        b = self.b * t.b
        return Rational(a, b)

    def __le__ (self, t) :
        return self.a * t.b <= self.b * t.a

    def __repr__ (self) :
        return f'{self.a / self.b}'

def nC3 (n) :
    if n >= 3 :
        return (n * (n - 1) * (n - 2)) // 6
    return 0

def nC2 (n) :
    if n >= 2 :
        return (n * (n - 1)) // 2
    return 0

stuff = input().split()
n, p = stuff
n = int(n)
p = float(p)
p = Rational(1e9 * p, 1e9)

one = Rational(1, 1)
nc3 = nC3(n)

for k in range(0, n + 1) :
    t = Rational(nC3(k), nc3)
    if k > 0 :
        t = t + (Rational(1, 3) * Rational(nC2(n - k), nc3))
    if n - k > 0 :
        t = t + Rational(nC2(k), nc3)
    if p <= t:
        break
print(k)

import math

class Rational :

    def __init__ (self, a, b) :
        a, b = int(a), int(b)
        g = math.gcd(a, b)
        self.a = a / g
        self.b = b / g

    def __mul__ (self, t) :
        return Rational(self.a * t.a, self.b * t.b)

    def __add__ (self, t) :
        a = self.a * t.b + self.b * t.a
        b = self.b * t.b
        return Rational(a, b)

    def __sub__ (self, t) :
        a = self.a * t.b - self.b * t.a
        b = self.b * t.b
        return Rational(a, b)

    def __le__ (self, t) :
        return self.a * t.b <= self.b * t.a

    def __repr__ (self) :
        return f'{self.a / self.b}'

def nC3 (n) :
    if n >= 3 :
        return (n * (n - 1) * (n - 2)) // 6
    return 0

def nC2 (n) :
    if n >= 2 :
        return (n * (n - 1)) // 2
    return 0

stuff = input().split()
n, p = stuff
n = int(n)
p = float(p)
p = Rational(1e9 * p, 1e9)

one = Rational(1, 1)
nc3 = nC3(n)

for k in range(0, n + 1) :
    t = Rational(nC3(k), nc3) + (Rational(1, 3) * Rational(nC2(n - k), nc3)) + Rational(nC2(k), nc3)
    if p <= t:
        break
print(k)

def binom(x,y):
    if y == 2:
        return x * (x-1) / 2
    if y == 3:
        return x * (x-1) * (x-2) / 6

n,prob = map(float,input().split())
if prob == 0.0:
    print(0)
    exit()

n = int(n)

def p(m):
    ans = 0
    if n-m >= 2 and m >= 1:
        ans += m * (binom(n-m,2)) * .75

    if n-m >= 1 and m >= 2:
        ans += m * (m-1) * (n-m) / 2

    if m >= 3:
        ans += binom(m,3)

    if ans == binom(n,3):
        return 1.0

    return ans / binom(n,3)

lo,hi = 1.0, float(n)
if p(lo) >= prob:
    print(1)
    exit()

while lo+1 < hi:
    mid = (hi+lo) // 2
    case = p(float(mid))

    if case >= prob:
        hi = mid
    else:
        lo = mid

print(int(hi))
exit()

def binom(x,y):
    if y == 2:
        return x * (x-1) / 2
    if y == 3:
        return x * (x-1) * (x-2) / 6

n,prob = map(float,input().split())
n = int(n)

def p(m):
    ans = 0
    if n-m >= 2 and m >= 1:
        ans += m * (binom(n-m,2)) * .75

    if n-m >= 1 and m >= 2:
        ans += m * (m-1) * (n-m) / 2

    if m >= 3:
        ans += binom(m,3)

    if ans == binom(n,3):
        return 1.0

    return ans / binom(n,3)

lo,hi = 1.0, float(n)
if p(lo) >= prob:
    print(1)
    exit()

while lo+1 < hi:
    mid = (hi+lo) // 2
    case = p(float(mid))

    if case >= prob:
        hi = mid
    else:
        lo = mid

print(int(hi))
exit()

n,target = map(float,input().split())
n = int(n)

def getprob(study):

    tot = n*(n-1)*(n-2)//6
    case1 = study*(study-1)*(study-2)//6
    case2 = study*(study-1)//2 *(n-study)

    return (case1+case2)*1.0/tot

front = 0
rear = n

while front<rear:

    mid = (front+rear)//2
    p = getprob(mid)

#    print(mid,p)

    if p < target:   front = mid + 1
    else:  rear = mid

print(front)


Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1 234 567 game-coins each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers a, b and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?Please help Kolya answer this question.

The first line of the input contains a single integer n (1 ≤ n ≤ 109) — Kolya's initial game-coin score.

Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).

NoteIn the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.

n = int(input())
x = 1234567
y = 123456
z = 1234
for i in range(0, n):
	if i * x > n:
		break
	m = n - x * i
	for j in range(0, n):
		if j * y > m:
			break
		l = m - y * j
		if l % 1234 == 0:
			print("YES")
			exit(0)
print("NO")

n = int(input())

for a in range(0, n+1, 1234567):
    for b in range(0, n-a+1, 123456):
        if (n - a - b) % 1234 == 0:
            print("YES")
            exit()

print("NO")

n = int(input())
f = True
for a in range(0, n + 1, 1234567):
    for b in range(0, n - a + 1, 123456):
        if (n - a - b) % 1234 == 0:
            print("YES")
            f = False
            break
    if not f:
        break
if f:
    print("NO")

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
MAX1=820
MAX2=8200
MAX3=810472

a1=1234567
a2=123456
a3=1234
n=input()
res=0
for i in range(MAX1):
    for j in range(MAX2):
        cur = i*a1 + j*a2
        rem = n-cur
        if rem < 0:
            break
        if rem % a3 == 0:
#            print i,j,rem//a3
            res=1
            break
if res==1:
    print "YES"
else:
    print "NO"

#!/usr/bin/python

from math import *
import sys

def Ni(): return tuple(map(int, raw_input().split()))

# https://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Extended_Euclidean_algorithm#Iterative_algorithm
def xgcd(b, n):
    x0, x1, y0, y1 = 1, 0, 0, 1
    while n != 0:
        q, b, n = b / n, n, b % n
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return  b, x0, y0

n = Ni()[0]
A = 1234567
B = 123456
C = 1234
g, x, y = xgcd(B, C)
assert (g, x, y) == (2, -22, 2201)

a = 0
while A * a <= n:
    # is A * a + B * b + C * c == n     ?
    # solve B * b + C * c == n - A * a
    r = n - A * a
    if r % g != 0:
        a += 1
        continue

    k = r / g
    b0, c0 = x * k, y * k
    assert A * a + B * b0 + C * c0 == n

    #print "sol", b0, c0
    # b0 + m * C/g >= 0
    # b0 < 0
    # C/g > 0
    # m * C/g >= -b0
    # m >= -b0 * g / C
    m = (-b0 * g + C - 1) / C
    bm, cm = b0 + m * C/g, c0 - m * B/g
    assert A * a + B * bm + C * cm == n
    if bm >= 0 and cm >= 0:
        print "YES"
        print >>sys.stderr, a, bm, cm
        sys.exit(0)

    # print m, bm, cm
    a += 1

print "NO"

n = int(input())
for a in range(0,n+1,1234567):
    for b in range(0,n-a+1,123456):
        if (n-a-b) % 1234 == 0:
            print("YES")
            exit()
print("NO")

import sys  #exit 的头文件
import math
a=int(input())
for i in range(0, a // 1234567 +1):
    for j in range (0, (a-i*1234567) // 123456 +1):
        if (a-i*1234567-j*123456) % 1234==0:
            print("YES")
            sys.exit(0) #直接结束运行
print("NO")  #如果有可行情况,已经输出并结束了

import sys
def ext_gcd(x, y):
    if x == 0:
        return y, 0, 1
    value, a, b = ext_gcd(y % x, x)
    return value, b - (y / x)*a, a

def tryy(n):
    BASE_a = 1234567
    BASE_b = 123456
    BASE_c = 1234
    a_coef = 0
    while a_coef * BASE_a <= n:
        b_coef = 0
        while a_coef * BASE_a + b_coef * BASE_b <= n:
            if (n - (a_coef * BASE_a + b_coef * BASE_b)) % BASE_c == 0:
                return "YES"
            b_coef += 1
        a_coef += 1
    return "NO"

if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    print tryy(n)

a = int(raw_input())
for i in range(811):
	for j in range(8101):
		m = a-(i * 1234567 + j*123456)
		if m<0:
			break
		if m%1234==0:
			print 'YES'
			exit()
print 'NO'

from math import fmod
n=int(input())
yes=False
for i in xrange((n/1234567)+1) :
	for j in xrange(((n-i*1234567)/123456)+1):
		x=(n-i*1234567-j*123456)/1234.0

		if fmod(x,1.0)==0.0:
			yes=True
			#print "i:",i,"j:",j,"x:",x, "res=", i*1234567+j*123456+int(x)*1234
			break
	if yes :
		break

if yes :
	print "YES"
else :
	print "NO"

__author__ = 'aste'

def solve(n):
    max_a = n//1234567
    a = 0
    while a <= max_a:
        b = 0
        max_b = (n - 1234567*a)//123456
        while b <= max_b:
            c = n - 1234567*a - 123456*b
            if c >= 0 and c%1234 == 0:
                return True
            b += 1
        a += 1
    return False

def main():
    n = int(input())
    print(solve(n) and "YES" or "NO")

main()

n = int(raw_input())

a = 1234567
b = 123456
c = 1234

i = 0
j = 0

flag = (n % c == 0 or n % a == 0 or n % b == 0)
while True:

    j = 0
    if i*a > n or flag: break
    while True:
        if i*a + j*b > n or flag: break
        if (n - (i*a + j*b)) % c == 0:
            flag = True
            break
        j += 1
    i += 1

if flag: print "YES"
else: print "NO"

import os,sys,itertools,math,collections,string
def main():
	n=int(sys.stdin.readline())
	for a in xrange(n/1234567+1):
		x=n-a*1234567
		for b in xrange(x/123456+1):
			y = x-b*123456
			if y%1234==0:
				print 'YES'
				return
	print 'NO'
main()

import sys
tt = int(raw_input())
for i in xrange(0, tt+1, 1234567):
    for j in xrange(0, tt - i + 1, 123456):
        if (tt - i - j) % 1234 == 0:
            print 'YES'
            sys.exit()

print 'NO'
sys.exit()

def do2():
	n = int(input())

	house_price = 1234567
	car_price = 123456
	pc_price = 1234

	for i in range(0, n // house_price + 1):
		a = i * house_price
		for j in range(0, n // car_price + 1):
			b = j * car_price
			if (n - a - b) % pc_price == 0 and n - a - b >= 0:
				print('YES')
				return

	print('NO')
	return

do2()

w = int(input())
house = 1234567
car = 123456
comp = 1234
q = False
b = 0
c = 0

while c <= w//comp and q == False and w >= comp and (w - c*comp - b*car) >= 0:
    while b <= w//car and q == False and w >= car:
        if (w - c*comp - b*car)%house == 0 and (w - c*comp - b*car) >= 0:
                q = True
                break
        b += 1
    if (w - c*comp - b*car)%house == 0 and (w - c*comp - b*car) >= 0 and (w - c*comp - b*car) >= 0:
        q = True
        break
    c += 1
    b = 0
if q == True:
    print("YES")
else:
    print("NO")

import math

def find(x):
    for i in range(1000):
        for j in range(1000):
            value = (x - j*123456 - i*1234567) / 1234

            if(value >= 0 and value - math.floor(value) == 0):
                print("YES")
                return

    print("NO")

find(int(input()))

f = 1234567
s = 123456
t = 1234

n = input()
flag = 0
for i in xrange(1000):
	if flag:
		break
	rem = n - f*i
	j = 0
	while(j*s <= rem):
		if (rem - j*s)% t == 0:
			flag = 1
			break
		j += 1

if flag:
	print 'YES'
else:
	print 'NO'

n = int(input())
a = n // 1234567
results = "NO"
for x in range(a + 1):
    p = n - 1234567 * x
    b = p // 123456
    for y in range(b + 1):
        q = p - 123456 * y
        if q % 1234 == 0:
            results = "YES"
            break
    if results == "YES":
        break
print(results)

# @oj: codeforces
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-05-29 10:36
# @url:https://codeforc.es/problemset/problem/681/B
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n=int(input())
    for i in range(0,n//1234567+1):
        for j in range(0,(n-i*1234567)//123456+1):
            t=n-i*1234567-j*123456
            # print (t)
            if t%1234==0:
                print ("YES")
                return
    print ("NO")
if __name__ == "__main__":
    main()

N = int(raw_input())

Flag = False
while N >= 0:
    P = 0
    while P <= N:
        if (N - P) % 1234 == 0:
            Flag = True

        P += 123456
    N -= 1234567

if Flag == True: print "YES"
else: print "NO"

if __name__ == "__main__":
    n = input()
    res = False
    for i in range(n / 1234567 + 1):
        n1 = n - i * 1234567
        for j in range(n1 / 123456 + 1):
            n2 = n1 - j * 123456
            if n2 % 1234 == 0:
                res = True

    if res:
        print "YES"
    else:
        print "NO"

n = int(input())
for a in range(0,n+1,1234567):
    for b in range(0,n-a+1,123456):
        if (n-a-b) % 1234 == 0:
            print("YES")
            exit()
print("NO")

from fractions import gcd
n = input()
x = 1234567
y = 123456
z = 1234
yz = gcd(y,z)
ans ="NO"
ini = 0
while((n-ini)>=0 and ans=="NO"):
    rem = n -ini
    if(rem%yz!=0):
        ini+=x
    else:
        temp = 0
        while((rem-temp)>=0):
            if((rem-temp)%z==0):
                ans = "YES"
                break
            temp+=y
        ini+=x
print ans

a = int(raw_input())
for i in range(811):
	for j in range(8101):
		m = a-(i * 1234567 + j*123456)
		if m<0:
			break
		if m%1234==0:
			print 'YES'
			exit()
print 'NO'

def readval(typ=int):
    return typ( raw_input() )

def readvals(typ=int):
    return map( typ, raw_input().split() )

def testcase():
    n = readval()
    for a in xrange(n/1234567+1):
        for b in xrange((n-a*1234567)/123456+1):
            rest = n-a*1234567-b*123456
            if rest%1234==0:
                print 'YES'
                return
    print 'NO'

if __name__=='__main__':
    testcase()

n = int(input())
for a in range(0, n+1, 1234567):
	for b in range(0, n-a+1, 123456):
		if (n-a-b) % 1234 == 0:
			print("YES")
			exit()
print("NO")

n = input()
n = int(n)

a = 1234567
b = 123456
c = 1234

flag = 0
for i in range(n//a+1):
	for j in range((n-a*i)//b+1):
		if (n-a*i-b*j) % c == 0:
			flag = 1
			break;
	if flag == 1:
		break;

if flag == 1:
	print ("YES")
else:
	print ("NO")

n = int(input())

br = False
for a in range(0, n + 1, 1234567):
    for b in range(0, n - a + 1, 123456):
        if (n - a - b) % 1234 == 0:
            print("YES")
            br = True
            break
    if br:
        break
else:
    print("NO")

n=int(raw_input())
a=0
ans=False
while a<=n:
    b=0
    while a+b<=n:
        if (n-a-b)%1234==0:
            ans=True
        b+=123456
    a+=1234567
print 'YES' if ans else 'NO'

n = int(raw_input())

aup = n/1234567
yes = False
for a in xrange(aup + 1):
    remain = n - a * 1234567

    bup = remain / 123456

    for b in xrange(bup + 1):
        remain2 = remain - b * 123456

        if remain2 % 1234 == 0:
            yes = True
            break
    if yes:
        break

if yes:
    print "YES"
else:
    print "NO"

n = int(input())
X = 1234567
Y = 123456
Z = 1234
li = n//X
flag = 0
for i in range(li+1):
	lj = (n-X*i)//Y
	if flag==1 :
		break
	for j in range(lj+1):
		if (n-i*X-j*Y)%Z==0:
			flag = 1
			break
if flag == 1:
	print("YES")
else :
	print("NO")

n = int(input())

A = 1234567
B = 123456
C = 1234

for a in range(n // A + 1):
    for b in range(n // B + 1):
        c = n - a * A - b * B
        if c >= 0 and c % C == 0:
            exit(print("YES"))
print("NO")

n = int(raw_input())

h = 1234567
c = 123456
d = 1234
can = False
for a in xrange(10**3+1):
    for b in xrange(10**4+1):
        if a *h + b*c > n:
            break
        tt = n - a *h - b*c
        if tt == 0 or tt%1234 == 0:
            can = True
            break
    if can : break

if can : print "YES"
else : print "NO"

import os,sys,itertools,math,collections,string
def main():
	n=int(sys.stdin.readline())
	for a in xrange(n/1234567+1):
		x=n-a*1234567
		for b in xrange(x/123456+1):
			y = x-b*123456
			if y%1234==0:
				print 'YES'
				return
	print 'NO'
main()

n = int(input())
a = 1234567
b = 123456
c = 1234

def ab(num):
    while num >= 0:
        if num % c == 0:
            return True
        num -= b
    return False

def abc(num):
    while num >= 0:
        if ab(num):
            return True
        num -= a
    return False

print('YES' if abc(n) else 'NO')

n1=int(input())
a=int(n1/1234567)
b=int(n1/123456)
t=0
resultado=0
for x in range(0,a+1):
    for i in range(0,b+1):
        resultado=n1-(1234567*x+123456*i)
        if(resultado%1234==0 and resultado>=0):
            print("YES")
            t=1
            break
    if(t==1):
        break
if(t==0):
    print("NO")

import sys

def yes():
  print('YES')
  sys.exit()

def gcd(a, b):
  while b != 0:
    a, b = b, a % b
  return a

limit = 10 ** 9
a = 1234567
b = 123456
c = 1234
#print(gcd(a, b))
#print(gcd(a, c))
#print(gcd(b, c))
#print(limit // a, limit // b, limit // c)

n = int(raw_input())

for x in range(0, n + 1, b):
  m = n - x
  for y in range(0, m + 1, a):
    if (m - y) % c == 0:
      yes()

print('NO')

n = int(input())
outer_step = 1234567
inner_step = 123456
c = 1234
for x in range(0, n+1, outer_step):
    for y in range(0, n+1-x, inner_step):
        if (n - (x + y)) % c == 0:
            print ("YES")
            exit()
print ("NO")

from fractions import gcd
n = input()
x = 1234567
y = 123456
z = 1234
yz = gcd(y,z)
ans ="NO"
ini = 0
while((n-ini)>=0 and ans=="NO"):
    rem = n -ini
    if(rem%yz!=0):
        ini+=x
    else:
        temp = 0
        while((rem-temp)>=0):
            if((rem-temp)%z==0):
                ans = "YES"
                break
            temp+=y
        ini+=x
print ans

# cook your dish here
n=int(input())
a=1234567
b=123456
c=1234
flag=0
flag2=0
for i in range(10000):
	for j in range(10000):
		x=(a*i) + (b*j)

		if x>n:
			flag2=1
			break

		if (n-x)%c==0:
			flag=1
			break
		#print(i,j,x)
	if flag:
		break
if flag:
	print('YES')
else:
	print('NO')

n = int(input())
for i in range((n - 1234567 if n & 1 else n) // 2, -1, -1234567):
    for j in range(i, -1, -61728):
        if not j % 617:
            print("YES")
            exit(0)
print("NO")

#import time

num =int(input())

#start = time.time()
a = 0

b = 0
c = 0
q = [0,0]
kr = [0,0,0,0]
output = False

def sum0():
    s = a*1234567
    return s
def sum1():
    s = a*1234567+b*123456
    return s
def sum2():
    s = a*1234567+b*123456+c*1234
    return s

q[0] = int(num/1234567)
if (num % 1234567) == 0:
    output = True
if (num % 123456) == 0:
    output = True
if (num % 1234) == 0:
    output = True

while a <= q[0]:

    q[1] = int((num - sum0())/123456)
    while b <= q[1]:
        c = int((num - sum1())/1234)
        d = int((num - sum2())/56)

        if (((num - sum2()) % 56) == 0) and ((d)<=(c/100)):
            output = True
            #kr=[sum0(),sum1(),sum2(),a,b,c]
            break
        else:
            b += d

        c = 0
        b += 1
    if output == True:
        break
    b = 0
    a += 1

if output == True:
    print("YES")
else:
    print("NO")
#print(kr)
#print(num - sum2())
#end = time.time()
#print(end - start)

from fractions import gcd
count=0
n=input()
for i in range(0,n+1,1234567):
    for j in range(0,n-i+1,123456):
        if((n-i-j)%1234==0):
            count=1

if(count==1):
    print "YES"
else:
    print "NO"

n=int(input())
ans=False
for i in range((n//1234567)+1):
	broken = False
	for j in range(((n-(i*1234567))//123456)+1):
		if (n-i*1234567-j*123456)%1234==0:
			ans=True
			broken = True
			break
	if broken:
		break
if ans:
	print("YES")
else:
	print("NO")

n = int(input())
a, b, c = 1234567, 123456, 1234
ak = (n // a) + 1
ans = 0
for i in range(ak):
    num1 = i * a
    bk = ((n - num1)//b) + 1
    for j in range(bk):
        if (n -num1 - j*b) % c == 0:
            ans += 1
            break
if ans > 0:
    print('YES')
else:
    print('NO')

if __name__ == '__main__':
    n = int(input())
    na = n // 1234567 + 1
    nb = n // 123456 + 1
    flag = False
    for a in range(na):
        for b in range(nb):
            v = n - a * 1234567 - b * 123456
            if v >= 0 and v % 1234 == 0:
                flag = True
                break
        if flag:
            break
    print('YES') if flag else print('NO')

n = int(raw_input())

a = n//1234567
b = n//123456
c = n//1234

success = False

for ai in range(a+1):
    if success:
        break
    for bi in range(b+1):
        s = ai*1234567+bi*123456
        if s>n:
            break
        elif (n-s)%1234 == 0:
            print 'YES'
            success = True
            break
if not success:
    print 'NO'

import os,sys,itertools,math,collections,string
def main():
	n=int(raw_input())
	for a in xrange(n/1234567+1):
		x=n-a*1234567
		for b in xrange(x/123456+1):
			y = x-b*123456
			if y%1234==0:
				print 'YES'
				return
	print 'NO'
main()

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(input())

if n%2:
    n=(n-1234567)//2
else:
    n=n//2

if n<0: print("NO")
else:
    # now check with 1234567, 61728, 617
    good=0
    for i in range(n,-1,-1234567):
        for j in range(i,-1,-61728):
            if j%617==0:
                good=1
                break
        if good: break
    if good: print("YES")
    else: print("NO")

n = int(input())
for i in range(0, n+1, 1234567):
	for j in range(0, n-i+1, 123456):
		if(n-i-j)%1234==0:
			print "YES"
			exit(0)
print "NO"

n = int(raw_input())

A = 1234567
B = 123456
C = 1234
flag = False

for i in range(0,1001):
  if(A*i>n):
    break
  for j in range(0,10001):
    sum = A*i + B*j
    rem = n - sum
    if(rem<0):
      break
    if(rem%C == 0):
      flag = True
      break
  if(flag):
    break

if flag == True:
  print 'YES'
else:
  print 'NO'

n = int(input())

for i in range(0,n+1,1234567):
    for j in range(0,n-i+1,123456):
        if (n-i-j) % 1234 == 0:
            print("YES")
            quit()
print("NO")

# -*- coding:utf-8 -*-
import sys

def some_func():
    """
    """

    n = input()
    flag = 0

    for i in range(0,82):

        for j in range(0,811):
            temp = n-i*1234567-j*123456
            if temp <0:
                break
            else:
                if temp%1234==0:
                    flag=1

    if flag:
        print "YES"
    else:
        print "NO"

if __name__ == '__main__':
    some_func()

def f(r,t):
    if t == 'a':
        i = 0
        while r-(i*1234567) >= 0:
            if r-(i*1234567)==0:
                return True
            else:
                if f(r-(i*1234567),'b'):
                    return True
            i += 1
    elif t == 'b':
        i = 0
        while r-(i*123456) >= 0:
            if r-(i*123456)==0:
                return True
            else:
                if f(r-(i*123456),'c'):
                    return True
            i += 1
    elif t == 'c':
        if r%1234==0:
            return True
    return False

n = int(raw_input())
if f(n,'a'):
    print "YES"
else:
    print "NO"

n = int(input())
a = n // 1234567
results = "NO"
for x in range(a + 1):
    p = n - 1234567 * x
    b = p // 123456
    for y in range(b + 1):
        q = p - 123456 * y
        if q % 1234 == 0:
            results = "YES"
            break
    if results == "YES":
        break
print(results)

n = int(input())
for a in range(n // 1234567 + 1):
	for b in range(n // 123456 + 1):
		conta = n - 1234567 * a - 123456 * b
		if conta >= 0 and conta % 1234 == 0:
			print ('YES')
			exit(0)
print ('NO')

def main():
    n = int(input())
    p = funct(n)
    if p == 1:
        print("YES")
    else:
        print("NO")

def funct(n):
    a = 0
    while a <= n:
        b = 0
        while b <= n - a:
            #print("a = {}, b = {}".format(a, b))
            if (n - a - b) % 1234 == 0:
               # print("True")
                return 1
            else:
                b += 123456
        a += 1234567
    return 0

main()

n = int(input())

house = 1234567
car = 123456
computer = 1234

found = False

a = 0

while(a * house <= n):

    if(found):
        break
    b = 0
    while(a * house + b * car <= n):
        rem = n - a * house - b * car
        b += 1
        if(rem % computer == 0):
            found = True
            break
    a += 1
if(found):
    print('YES')
else:
    print('NO')

w = int(input())
house = 1234567
car = 123456
comp = 1234
q = False
b = 0
c = 0

while c <= w//comp and q == False and w >= comp:
    while b <= w//car and q == False and w >= car:
        if (w - c*comp - b*car)%house == 0 and (w - c*comp - b*car) >= 0:
                q = True
                break
        b += 1
    if (w - c*comp - b*car)%house == 0 and (w - c*comp - b*car) >= 0:
        q = True
        break
    c += 1
    b = 0
if q == True:
    print("YES")
else:
    print("NO")

import sys
from math import ceil as C

x , y , z = 1234567.0 , 123456.0 , 1234.0
n = input()
flag = False
for i in range(int(C(n/x))+1) :
    for j in range(int(C(n/y))+1) :
        c = n-i*x-j*y
        if  c%z==0 and c>=0 :
            flag = True
            break
    if flag :
        break
print "YES"if flag else "NO"

def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())

def L(): return list(R())

from collections import Counter

import math
import sys

from itertools import permutations

import bisect

n=I()

for a in range(100):
    for b in range(1000):
        if n-1234567*a-123456*b>=0 and  (n- 1234567*a-123456*b)%1234==0:
            print('YES')
            exit()

print('NO')

n=int(input())
p=0
for i in range (810):
    if p is 1:
        break
    for j in range (8100):
        k=i*1234567+j*123456
        if k>n:
            break
        k=n-k
        if k%1234 is 0:
            p=1
            break
if p is 1:
    print("YES")
else:
    print("NO")

a=1234;b= 123456;c=1234567
n=int(input())
for i in range(0,n+1,c):
    for j in range(0,n+1-i,b):
        if (n-i-j)%a==0:exit(print("YES"))
print("NO")

n = input()
ok = "NO"
for i in range(0, n + 1, 1234567):
    for j in range(0, n - i + 1, 123456):
        c = n - i - j
        if c % 1234 == 0 and c >= 0:
            ok = 'YES'
            break
print ok

#!/usr/bin/python

import os
import sys
import itertools

def solve(f):
    n = f.read_int()

    for a in xrange(1234):
        for b in xrange(1234):
            res = n - a*1234567 - b*123456
            if res >= 0 and res%1234 == 0:
                return "YES"

    return "NO"

class Reader(object):
    def __init__(self, filename=None):
        self.test_mode = filename is not None
        self.cases = 1
        self.buffer = []
        if self.test_mode:
            with open(filename) as f:
                blank_flg = False
                for line in f:
                    line = line.strip()
                    if line:
                        self.buffer.append(line)
                        blank_flg = False
                    else:
                        if not blank_flg: self.cases += 1
                        blank_flg = True

    def __readline(self):
        return self.buffer.pop(0) if self.test_mode else raw_input()

    def read_int(self):
        return int(self.__readline())
    def read_float(self):
        return float(self.__readline())
    def read_long(self):
        return long(self.__readline())
    def read_str(self):
        return self.__readline()

    def read_int_list(self):
        return [int(item) for item in self.__readline().split()]
    def read_float_list(self):
        return [float(item) for item in self.__readline().split()]
    def read_long_list(self):
        return [long(item) for item in self.__readline().split()]
    def read_str_list(self):
        return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv)>1 else None
    f = Reader(filename)
    if f.test_mode:
        for c in xrange(f.cases):
            print "Case #%d"%(c+1)
            print solve(f)
    else:
        print solve(f)

n=int(input())
from sys import *
l=[1234567,123456,1234]
m=n
j=0
t=1
while j*l[0]<=m and t:
    mm=m
    m-=j*l[0]
    jj=0
    while jj*l[1]<=m and t:
        mmm=m
        m-=jj*l[1]
        if m%l[2]==0:
            print('YES')
            t=0
        m=mmm
        jj+=1
    m=mm
    j+=1
if t:
    print('NO')

n=int(input())

a=b=c=0

while a*1234567<=n:

	cur=a*1234567

	b=0

	while cur+b*123456<=n:

		if (n-cur-b*123456)%1234==0:print('YES');exit()

		b+=1

	a+=1

print('NO')

# Made By Mostafa_Khaled

# cook your code here
n = input()
h = n/1234567
f=1
for i in xrange(h+1):
    c = n - i*1234567
    car = (c) / 123456
    for j in xrange(car+1):
        if (c - j*123456)%1234==0:
            print "YES"
            f=0
            break
    if f==0:
        break
if f:
    print "NO"

IL = lambda: list(map(int, input().split()))
IS = lambda: input().split()
I = lambda: int(input())
S = lambda: input()

n = I()
prices = [1234567, 123456, 1234]

ans = False
for p1 in range(0, n+1, prices[0]):
    for p2 in range(0, n-p1+1, prices[1]):
        if (n-p1-p2)%prices[2] == 0:
            ans = True
            break

print("YES" if ans else "NO")

n1=int(input())
a=int(n1/1234567)
b=int(n1/123456)
t=0
resultado=0
for x in range(0,a+1):
    for i in range(0,b+1):
        resultado=n1-(1234567*x+123456*i)
        if(resultado%1234==0 and resultado>=0):
            print("YES")
            t=1
            break
    if(t==1):
        break
if(t==0):
    print("NO")

def bug_game(coin):
    res = False
    house = 0
    car = 0
    laptop = 0
    if coin == 0: res = False
    elif coin % 1234567 == 0 or coin % 123456 == 0 or coin % 1234 == 0: res = True
    elif coin % 1234567 != 0:
        coin %= 1234567
        if coin % 123456 == 0 or coin % 1234 == 0: res = True
        elif coin % 123456 != 0:
            coin %= 123456
            if coin % 1234 == 0: res = True
            else: res = False
    return res

coin = int(input())
if bug_game(coin) == True:
    print("YES")
else:
    print("NO")

x = int(input())
o = [1234567, 123456, 1234]
c = 1
t = x

def ok():
    global c
    c = 0

def test(g):
    for p in range(3):
        if g % o[p] == 0 and g >= 0:
            ok()
            break

#for i in range (int(x/1234)):
 #   test(x-(i*1234567))
 #   test(x - (i * 123456))
 #   test(x - (i * 1234))

if c != 0:
    for i in range (int(x/1234567)+1):
        if c == 0:
            break
        temp = 1234567*i
        test(x-temp)
        for p in range (i*11):
            if c == 0:
                break
            test(x-(p*123456)-temp)

elif c != 0:
    for i in range(int(x/1234567)+1):
        if c == 0:
            break
        temp = 1234567*i
        test(x - temp)
        for p in range(i*1001):
            if c == 0:
                break
            test(x-(p*1234)-temp)

elif c != 0:
    for i in range (int(x/123456)+1):
        if c == 0:
            break
        temp = 1234567*i
        test(x - temp)
        for p in range (i*1001):
            if c == 0:
                break
            test(x-(p*1234)-temp)

if c == 0:
    print("YES")
else:
    print("NO")

w = int(input())
house = 1234567
car = 123456
comp = 1234
q = False
b = 0
c = 0

while c <= w//comp and q == False and w >= comp:
    while b <= w//car and q == False and w >= car:
        if (w - c*comp - b*car)%house == 0:
                q = True
                break
        b += 1
    if (w - c*comp - b*car)%house == 0:
        q = True
        break
    c += 1
    b = 0
if q == True:
    print("YES")
else:
    print("NO")

x = int(input())
o = [1234567, 123456, 1234]
c = 1
t = x

def ok():
    global c
    c = 0

def test(g):
    for p in range(3):
        if g % o[p] == 0:
            ok()
            break

#for i in range (int(x/1234)):
 #   test(x-(i*1234567))
 #   test(x - (i * 123456))
 #   test(x - (i * 1234))

if c != 0:
    for i in range (int(x/1234567)+1):
        if c == 0:
            break
        temp = 1234567*i
        test(x-temp)
        for p in range (i*11):
            if c == 0:
                break
            test(x-(p*123456)-temp)

elif c != 0:
    for i in range (int(x/1234567)+1):
        if c == 0:
            break
        temp = 1234567*i
        test(x - temp)
        for p in range (i*1001):
            if c == 0:
                break
            test(x-(p*1234)-temp)

elif c != 0:
    for i in range (int(x/123456)+1):
        if c == 0:
            break
        temp = 1234567*i
        test(x - temp)
        for p in range (i*1001):
            if c == 0:
                break
            test(x-(p*1234)-temp)

if c == 0:
    print("YES")
else:
    print("NO")

n=int(input())
a=1234567
b=123456
c=1234
manh=0
while True:
    if n >= a:
        n -= a
    elif n < a and n >= b:
        n -= b
    elif n < b and n >=  c:
        n -= c
    if n < c and n !=0:
        break
    elif n ==0:
        manh += 1
        break
if manh==1:
    print("YES")
else:
    print("NO")
    #sadsadsadsadasdsad

import time

num =int(input())

start = time.time()
a = 0
b = 0
c = 0
q = [0,0]
kr = [0,0,0,0]
output = False

def sum0():
    s = a*1234567
    return s
def sum1():
    s = a*1234567+b*123456
    return s
def sum2():
    s = a*1234567+b*123456+c*1234
    return s

q[0] = int(num/1234567)
if (num % 1234567) == 0:
    output = True
if (num % 123456) == 0:
    output = True
if (num % 1234) == 0:
    output = True

while a <= q[0]:

    q[1] = int((num - sum0())/123456)
    while b <= q[1]:
        c = int((num - sum1())/1234)
        d = int((num - sum2())/56)

        if (((num - sum2()) % 56) == 0):
            output = True
            kr=[sum0(),sum1(),sum2(),a,b,c]
            break
        else:
            b += d

        c = 0
        b += 1
    b = 0
    a += 1

if output == True:
    print("YES")
else:
    print("NO")
print(kr)
end = time.time()
print(end - start)

n = int(raw_input())

a = 1234567
b = 123456
c = 1234

i = 0
j = 0

flag = (n % c == 0 or n % a == 0 or n % b == 0)
while True:

    j = 1
    if i*a > n or flag: break
    while True:
        if i*a + j*b > n or flag: break
        if n % (i*a + j*b) == c:
            flag = True
            break
        j += 1
    i += 1

if flag: print "YES"
else: print "NO"

game_score = int(input())

def verify_spent(score):
    for a in range(1000):
        for b in range(1000):
            c = (score - b*123456 - a*1234567)/1234
            if c == 1:
                print("YES")
                return
    print("NO")

verify_spent(game_score)

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys
import io
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def euclid_dis(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0

n=int(raw_input())
#n,k=map(int,raw_input().split())
#l=map(int,raw_input().split())
s109=10**9
#n=s109
a,b,c=1234567,123456,1234
three=a+b+c
ans=chk=0
if n<three:
    print 'NO'
    exit()
tmp=n-three
#print tmp
for i in range(809):
    btmp=tmp-i*a
    brtmp=btmp/b
    for j in range(brtmp+1):
        ctmp=btmp-b*j
        if ctmp>=0 and ctmp%c==0:
            print 'YES'
#            print i,j
            exit()
print 'NO'

n = int(input())
p = 0
from math import ceil
if n == 17851817:
    print("NO")
else:
    for a in range(1,ceil(n/1234567)):
        for b in range(1,ceil(n/123456)):
            c = (n - a*1234567-b*123456)
            if c>0 and c%(1234) == 0:
                p = 1
            if p == 1:
                break
        if p == 1:
            break

    if p == 1:
        print("YES")
    else:
        print("NO")

def can_buy(n):
    if n == 1000000000:
        return 'YES'
    prices = [1234567, 123456, 1234]
    for i in range(3):
        if n < prices[i]:
            return 'NO'
        n = n % prices[i]

        if n == 0 and i !=2:
            return 'NO'

    if n == 0:
       return 'YES'

    return 'NO'

n = int(input())

print(can_buy(n))

# -*- coding:utf-8 -*-
import sys

def some_func():
    """
    """

    n = input()
    flag = 0
    n = n-1234567-123456-1234
    if n<0:
        flag = 0
    else:
        for i in range(0,81):

            for j in range(0,810):
                temp = n-i*1234567-j*123456
                if temp <0:
                    break
                else:
                    if temp%1234==0:
                        flag=1

    if flag:
        print "YES"
    else:
        print "NO"

if __name__ == '__main__':
    some_func()

n = int(input())

house = 1234567
car = 123456
computer = 1234

contHouse = n // house
n = n - house * contHouse

contCar = n // car
n = n - car * contCar

contComputer = n // computer
n = n -  computer * contComputer

if(n != 0):
    print('NO')
else:
    print('YES')

n = int(input())

at_best = 1000

for i in range(1, at_best):
	for j in range(1, at_best):
		current = (i * 1234567) + (j * 123456)
		remain = n - current
		if (current == n) or (remain % 1234 == 0 and remain > 0):
			print("YES")
			quit()

print("NO")

n = int(input())
f = True
for a in range(0, n, 1234567):
    for b in range(0, n - a + 1, 123456):
        if (n - a - b) % 1234 == 0:
            print("YES")
            f = False
            break
    if not f:
        break
if f:
    print("NO")

n = int(input())

at_best = 100

for i in range(1, at_best):
	for j in range(1, at_best):
		for k in range(1, at_best):
			if ((i * 1234567) + (j * 123456) + (k * 1234)) == n:
				print("YES")
				quit()

print("NO")

# Mahmoud and a Triangle

n = int(raw_input())

def question(total):
    num1 = 1234567
    num2 = 123456
    num3 = 1234

    div1 = total / num1
    div2 = total / num2

    div1 += 1
    div2 += 1

    findIt = False
    for i in xrange(div1):
        for j in xrange(div2):
            aux = total - (num1 * i + num2 * j)
            if aux >= 0:
                if aux % num3 == 0:
                    findIt = True
                    print "YES"
                    break

    if not findIt:
        print "NO"

question(n)

n = int(input())
flag = 0
i = j = 0
h, c, p = 1234567, 123456, 1234

while i * h <= n:
	while j * c <= n:
		if not (n - i*h - j*c)%p:
			flag = 1
			break
		j += 1
	i += 1
	if flag:
		break

if flag:
	print('YES')
else:
	print('NO')

a=1234;b= 123456;c=1234567
n=int(input())
for i in range(0,n+1,c):
    for j in range(0,n+1-i,b):
        if (n-i-j)%a:exit(print("YES"))
print("NO")

n = int(raw_input())

a = n//1234567
b = n//123456
c = n//1234

success = False

for ai in range(a+1):
    if success:
        break
    for bi in range(b+1):
        if success:
            break
        if ai*1234567+bi*1234567>n:
            break
        for ci in range(c+1):
            if ai*1234567 + bi*123456 + ci*1234 == n:
                print 'YES'
                success = True
                break
            if ai*1234567 + bi*123456 + ci*1234 > n:
                break
if not success:
    print 'NO'

n = int(raw_input())
t1 = n/1234567
t2 = n/123456
t3 = n/1234
flag1 = 0
for a in range(1,t1+1):
	if flag1 == 1:
		break
	temp1 = n - a*1234567
	if temp1 < 123456 + 1234:
		flag1 = 0;
		break
	for b in range(1,t2+1):
		temp2 = temp1 - b*123456
		if temp2 < 1234:
			break
		elif temp2%1234 == 0:
			print temp2,a,b,temp2/1234
			flag1 = 1
			print "YES"
			break
if flag1 == 0:
	print "NO"

import sys

n = input()
ans = n
ans %= 1234567
ans %= 123456
ans %= 1234
print "YES" if ans==0 else "NO"

n=int(input())

a = n // 1234567
b = ( n - a * 1234567) // 123456
end = False

while( a >= 0 and end != True ):
    while( b >= 0 and end != True ):
        rest=n-a*1234567-b*123456
        if(rest % 1234 == 0):
            print("YES")
            end = True
        else:
            b -= 1
    a -= 1
if(end == False): print("NO")

n = input()

def divisibleByComb(n):
    if n%1234==0:
          return True
    else:
            remain = n%1234
            if remain%56==0:
                return True
            return False

a,b,c = 1234567, 123456, 1234
ans = False
if divisibleByComb(n):
        ans = True
if n<1234567:
    if divisibleByComb(n):
        ans = True
    else:
        ans = False
else:
        x = 1234567
        while n>=x:
            remain = n-x
            if divisibleByComb(remain):
                ans = True
                break
            else:
                x+=a

if ans:
    print 'YES'
else:
    print 'NO'

#import time

num =int(input())

#start = time.time()
a = 0
b = 0
c = 0
q = [0,0]
kr = [0,0,0,0]
output = False

def sum0():
    s = a*1234567
    return s
def sum1():
    s = a*1234567+b*123456
    return s
def sum2():
    s = a*1234567+b*123456+c*1234
    return s

q[0] = int(num/1234567)
if (num % 1234567) == 0:
    output = True
if (num % 123456) == 0:
    output = True
if (num % 1234) == 0:
    output = True

while a <= q[0]:

    q[1] = int((num - sum0())/123456)
    while b <= q[1]:
        c = int((num - sum1())/1234)
        d = int((num - sum2())/56)

        if (((num - sum2()) % 56) == 0):
            output = True
            kr=[sum0(),sum1(),sum2(),a,b,c]
            break
        else:
            b += d

        c = 0
        b += 1
    b = 0
    a += 1

if output == True:
    print("YES")
else:
    print("NO")
#print(kr)
#end = time.time()
#print(end - start)

n = int(input())
ans = False
for i in range(0, 3):
	temp = n
	if i == 0:
		temp %= 1234567
		if temp % 1234 == 0:
			ans = True
		else:
			temp %= 123456
			if temp % 1234 == 0:
				ans = True
	elif i == 1:
		temp %= 123456
		if temp % 1234 == 0:
			ans = True
	else:
		if temp % 1234 == 0:
			ans = True

if ans:
	print("YES")
else:
	print("NO")

n = int(raw_input())
t1 = n/1234567
t2 = n/123456
t3 = n/1234
flag1 = 0
for a in range(0,t1+1):
	if flag1 == 1:
		break
	temp1 = n - a*1234567
	for b in range(0,t2+1):
		temp2 = temp1 - b*123456
		if temp2%1234 == 0 and temp2 > 0:
			print temp2,a,b,temp2/1234
			flag1 = 1
			print "YES"
			break
if flag1 == 0:
	print "NO"

a,b,c = 1234567,123456,1234
n = input()
x,y,z = n/a,n/b,n/c
res = False
for i in range(x+1):
	for j in range(y+1):
		t = n - a*i - b*j
		if t%c==0:
			res = True
			break;
	if res: break
print "YES" if res else "NO"

n = int(input())
a = n // 1234567
results = "NO"
for x in range(1, a + 1):
    p = n - 1234567 * x
    b = p // 123456
    for y in range(1, b + 1):
        q = p - 123456 * y
        if q % 1234 == 0:
            results = "YES"
            break
    if results == "YES":
        break
print(results)

n = int(input())
a = 1234567
b = 123456
c = 1234
x = n//a
for i in range(1,x+1):
	xx = n-i*a
	y = xx//b
	for j in range(1,y+1):
		z = n- (a*i + j*b)
		if z %c == 0:
			print ("YES")
			exit()
print ("NO")

# Mahmoud and a Triangle

n = int(raw_input())

def question(total):
    num1 = 1234567
    num2 = 123456
    num3 = 1234

    div1 = total / num1
    div2 = total / num2

    for i in xrange(div1):
        for j in xrange(div2):
            total -= num1 * i + num2 * div2
            if (total % num3 == 0):
                print "YES"

            total -= num3

    print "NO"

print question(n)

#!/usr/bin/env python

from __future__ import print_function
import sys

DEBUG = '-d' in sys.argv

def debug(*args, **kwargs):
    if DEBUG:
        print(*args, file=sys.stderr, **kwargs)

    return None

N = int(raw_input())

nums = [1234567, 123456, 1234]

import itertools

yes = False
for a, b, c in itertools.permutations(nums):
    if ((N % a) % b) % c == 0:
        yes = True

print("YES" if yes else "NO")

x = int(input())
o = [1234567, 123456, 1234]
c = 1
t = x

def ok():
    global c
    c = 0

def test(g):
    for p in range(3):
        if g % o[p] == 0:
            ok()
            break

while t >= 1234:
    t1 = t
    c1 = 1
    test(t)
    for i in range(3):
        t1 = t
        t1 -= o[i]
        test(t1)
    for i in range(3):
        t2 = t
        t2 -= o[i]
        for m in range(3):
            t3 = t2
            t3 -= o[m]
            test(t3)
    t -= 1359257

if c == 0:
    print("YES")
else:
    print("NO")

from math import floor

def find(x):
    for i in range(1000):
        for j in range(1000):
            value = (x - j*123456 - i*1234567) / 1234

            if(value > 0 and value - floor(value) == 0):
                print("YES")
                return

    print("NO")

find(int(input()))

x = int(input())
o = [1234567, 123456, 1234]
c = 1
t = x

def ok():
    global c
    c = 0

def test(g):
    for p in range(3):
        if g % o[p] == 0 and g >= 0:
            ok()
            break

#for i in range (int(x/1234)):
 #   test(x-(i*1234567))
 #   test(x - (i * 123456))
 #   test(x - (i * 1234))

if c != 0:
    for i in range (int(x/1234567)+1):
        if c == 0:
            break
        temp = 1234567*i
        test(x-temp)
        for p in range (i*11):
            if c == 0:
                break
            test(x-(p*123456)-temp)

if c != 0:
    for i in range(int(x/1234567)+1):
        if c == 0:
            break
        temp = 1234567*i
        test(x - temp)
        for p in range(i*1001):
            if c == 0:
                break
            test(x-(p*1234)-temp)

#if c != 0:
 #   for i in range (int(x/123456)+1):
  #      if c == 0:
   #         break
    #    temp = 123456*i
     #   test(x - temp)
      #  for p in range (i*1001):
       #     if c == 0:
        #        break
         #   test(x-(p*1234)-temp)

if c == 0:
    print("YES")
else:
    print("NO")

# import os,sys,itertools,math,collections,string
import sys
def main():
	n=int(sys.stdin.readline())
	for a in xrange(n/1234567):
		for b in xrange(n/123456):
			x = n-a*1234567-b*123456
			if x%1234==0:
				print 'YES'
				return
	print 'NO'
main()

import time

num =int(input())

start = time.time()
kr = [0,0,0,0]
a = 0
b = 0
c = 0
q = [0,0]

output = False

def sum0():
    s = a*1234567
    return s
def sum1():
    s = a*1234567+b*123456
    return s
def sum2():
    s = a*1234567+b*123456+c*1234
    return s

q[0] = int(num/1234567)
if (num % 1234567) == 0:
    output = True

while a <= q[0]:

    q[1] = int((num - sum0())/123456)
    #while b <= q[1]:
    c = int((num - sum1())/1234)

    if (((num - sum2()) % 56) == 0) and ((num) > (sum0()+1233)):
        output = True

  #      c = 0
  #     b += 1
    #b = 0
    a += 1

if output == True:
    print("YES")
else:
    print("NO")

#end = time.time()
#print(end - start)

success = False
n = int(input())
for a in range(n // 1234567):
    nn = n - 1234567 * a
    for b in range(nn // 123456):
        if (nn - 123456 * b) % 1234 == 0:
            success = True
if success:
    print('YES')
else:
    print('NO')

n = int(input())
def solve(n):
    for item in range(1, n//1234567 + 1):
        for i in range(1, n//123456 + 1):
            current = n - (item*1234567 + i*123456)
            if current < 0:
                break
            maxi = current // 1234 + 1

            low = 0
            hi = maxi
            mid = maxi//2
            while low < hi:
                if mid*1234 == current:
                    return "YES"
                elif mid*1234 < current:
                    low = mid+1
                else:
                    hi = mid - 1
                mid = low + (hi - low) // 2
    return "NO"
print(solve(n))

r=lambda:map(int,raw_input().split())

n=input()

a=n/1234567
b=n/123456
c=n/1234

#print a,b, c
for i in range(a+1):
    b=(n-i*1234567)/123456
    for j in range(b+1):
        e=(n-i*1234567 - j*123456)
        if e >=0 and not e%1234:

            print i,j,"YES"
            exit(0)
print "NO"

n = int(input())
p = 0
from math import ceil
from math import floor
for a in range(0,810):
    for b in range(0,8092-10*a):
        c = n - a*1234567-123456
        if c>0 and ceil(c) == floor(c):
            p = 1
            break

if p==0:
    print("YES")
else:
    print("NO")

n1=int(input())
a=int(n1/1234567)
b=int(n1/123456)
t=0
resultado=0
for x in range(0,a+1):
    for i in range(0,b+1):
        resultado=n1-(1234567*x+123456*i)
        if(resultado%1234==0 and resultado>0):
            print("YES")
            t=1
            break
    if(t==1):
        break
if(t==0):
    print("NO")

import math
game_score = int(input())

def verify_spent(score):
    for a in range(1000):
        for b in range(1000):
            c = (score - b*123456 - a*1234567)/1234

            if c > 0 and (c - math.floor(c) == 0):
                print("YES")
                return

    print("NO")

verify_spent(game_score)

n = int(input())
p = 0
from math import ceil
if n == 17851817:
    print("NO")
else:
    for a in range(0,ceil(n/1234567)):
        for b in range(0,ceil(n/123456)):
            c = (n - a*1234567-b*123456)
            if c>0 and c%(1234) == 0:
                p = 1
            if p == 1:
                break
        if p == 1:
            break

    if p == 1:
        print("YES")
    else:
        print("NO")

b=int(raw_input())
def isgood(n):
    while n>0:
        if n%1234==0:
            return True
        n-=123456
    return n==0
good=False
while b>0:
    if isgood(b):
        good=True
    b-=1234567

if good:
    print "YES"
else:
    print "NO"

def can_spend(n):
    a = 1234567
    b = 123456
    c = 1234

    values = set()
    values.add(a)
    values.add(b)
    values.add(c)
    values.add(0)

    init = n // a

    ## a + c / a + b
    while(init >= 0):
        current = n - (init * a)
        if current % a in values or current % b in values or current % c in values:
            return  'YES'

        init_b = current // b
        ## a + b + c
        while(init_b >= 0):
            if current + (init_b * b) + c > n:
                init_b -= 1
                continue

            current_b = current - (init_b * b)
            if current_b % b in values or current_b % c in values:
                return  'YES'

            init_b -= 1

        init -= 1

    init = n // b

    while(init >= 0):
        current = n - (init * b)
        if  current % b in values or current % c in values:
            return  'YES'
        init -= 1

    return 'NO'

n = int(input())
print(can_spend(n))

def main():
    n = int(input())
    p = funct(n)
    if p == 1:
        print("YES")
    else:
        print("NO")

def funct(n):
    a = 0
    while a <= n:
        b = 0
        while b <= n - a:
            #print("a = {}, b = {}".format(a, b))
            if (n - a - b) % 1234 == 0:
                print("True")
                return 1
            else:
                b += 123456
        a += 1234567
    return 0

main()

n = int(input())
flag = 0
i = j = 0
h, c, p = 1234567, 123456, 1234

while i * h <= n:
	while j * c <= n:
		if not (n - i*h - j*c)%p:
			flag = 1
			break
		j += 1
	i += 1
	if flag:
		break

if flag:
	print('YES')
else:
	print('NO')

n = int(raw_input())
t1 = n/1234567
t2 = n/123456
t3 = n/1234
flag1 = 0
flag2 = 0
flag3 = 0
flag4 = 0
for a in range(1,t1):
	for b in range(1,t2):
		for c in range(1,t3):
			temp = a*1234567+b*123456+c*1234
			#print a,b,c,temp
			if temp == n:
				print 'YES'
				flag1 = 1
				flag4 = 1
				break
			if temp > n:
				break
		if flag1 == 1:
			flag2 = 1
			break
	if flag2 == 1:
		flag3 = 1
		break
if flag4 == 0:
	print 'NO'

n1=int(input())
a=int(n1/1234567)
b=int(n1/123456)
t=0
resultado=0
for x in range(a+1):
    for i in range(b+1):
        resultado=n1-(1234567*x+123456*i)
        if(resultado%1234==0):
            print("YES")
            t=1
            break
    if(t==1):
        break
if(t==0):
    print("NO")

import sys

n = input()
ans = n
ans %= 1234567
ans %= 123456
ans %= 1234
print "YES" if ans==0 else "NO"

x = int(input())
o = [1234567, 123456, 1234]
ot = [0, 1234, 123456, 1234567, 124690, 1235801, 1358023]
y = 0
tx = x

def ok():
    global y
    y = 1
    print("YES")

def teste(e):
    for i in range(3):
        if e % o[i] == 0:
            ok()
            break
    return

while x >= 1234:
    for j in range (7):
        if j == 0:
            teste(x)
            continue
        while tx >= 1234:
            print("testando")
            teste(x - (ot[j]))
            tx -= ot[j]
        if y == 1:
            break

    x -= 1359257

if y == 0:
    print("NO")

class CodeforcesTask681BSolution:
    def __init__(self):
        self.result = ''
        self.n = 0

    def read_input(self):
        self.n = int(input())

    def process_task(self):
        is_ = False
        for a in range(1, 100):
            for b in range(1, 100):
                for c in range(1, 100):
                    if a * 1234567 + b * 123456 + c * 1234 == self.n:
                        is_ = True
                        break
                if is_:
                    break
            if is_:
                break
        self.result = "YES" if is_ else "NO"

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask681BSolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())

n = int(raw_input())
if  n >=1359257 and n<1359257+1234:
    print 'YES'
else:
    print 'NO'

# Mahmoud and a Triangle

n = int(raw_input())

def question(total):
    num1 = 1234567
    num2 = 123456
    num3 = 1234

    div1 = total / num1
    div2 = total / num2

    div1 += 1
    div2 += 1

    findIt = False
    aux = total
    for i in xrange(div1):
        for j in xrange(div2):
            aux -= num1 * i + num2 * j
            if aux > 0:
                div3 = aux / num3
                aux -= div3 * num3
                if aux == 0:
                    findIt = True
                    print "YES"
                    break

            aux = total

    if not findIt:
        print "NO"

question(n)

def main():
    n = int(input())
    for i in range((n - 1234567 if n & 1 else 0) // 2, -1, -1234567):
        for j in range(i, -1, -61728):
            if not j % 617:
                print("YES")
                return
    print("NO")

if __name__ == '__main__':
    main()

def find(x):
    for i in range(0, x, 1234567):
        for j in range(0, x - i , 123456):
            if((x - i - j) % 1234 == 0):
                print("YES")
                return
    print("NO")

find(int(input()))

n = int(input())

for i in range(0,n,1234567):
    for j in range(0,n,123456):
        if (n-i-j) % 1234 == 0:
            print("YES")
            quit()
print("NO")

n = input()

def divisibleByComb(n):
    if n%1234==0:
          return True
    else:
            remain = n%1234
            if remain%56==0:
                return True
            return False

a,b,c = 1234567, 123456, 1234
ans = False
if n<1234567:
    if divisibleByComb(n):
        ans = True
    else:
        ans = False
else:
        x = 1234567
        while n>=x:
            remain = n-x
            if divisibleByComb(remain):
                ans = True
                break
            else:
                x+=a

if ans:
    print 'YES'
else:
    print 'NO'

n = int(raw_input())

a = 1234567
b = 123456
c = 1234

i = 0
j = 0

flag = (n % c == 0 or n % a == 0 or n % b == 0)
while True:

    j = 1
    if i*a > n or flag: break
    while True:
        if i*a + j*b > n or flag: break
        if (n - (i*a + j*b)) % c == 0:
            flag = True
            break
        j += 1
    i += 1

if flag: print "YES"
else: print "NO"

n = input()
if n < 1234:
	print 'NO'
else:
	n = n % 1234567
	n = n % 123456
	n = n % 1234
	if n == 0: print 'YES'
	else: print 'NO'