There are $$$n$$$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th box contains $$$r_i$$$ candies, candies have the color $$$c_i$$$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is equal to $$$c_i$$$).Initially, Tanya is next to the box number $$$s$$$. Tanya can move to the neighbor box (that is, with a number that differs by one) or eat candies in the current box. Tanya eats candies instantly, but the movement takes one second.If Tanya eats candies from the box, then the box itself remains in place, but there is no more candies in it. In other words, Tanya always eats all the candies from the box and candies in the boxes are not refilled.It is known that Tanya cannot eat candies of the same color one after another (that is, the colors of candies in two consecutive boxes from which she eats candies are always different). In addition, Tanya's appetite is constantly growing, so in each next box from which she eats candies, there should be strictly more candies than in the previous one.Note that for the first box from which Tanya will eat candies, there are no restrictions on the color and number of candies.Tanya wants to eat at least $$$k$$$ candies. What is the minimum number of seconds she will need? Remember that she eats candies instantly, and time is spent only on movements.

The first line contains three integers $$$n$$$, $$$s$$$ and $$$k$$$ ($$$1 \le n \le 50$$$, $$$1 \le s \le n$$$, $$$1 \le k \le 2000$$$) — number of the boxes, initial position of Tanya and lower bound on number of candies to eat. The following line contains $$$n$$$ integers $$$r_i$$$ ($$$1 \le r_i \le 50$$$) — numbers of candies in the boxes. The third line contains sequence of $$$n$$$ letters 'R', 'G' and 'B', meaning the colors of candies in the correspondent boxes ('R' for red, 'G' for green, 'B' for blue). Recall that each box contains candies of only one color. The third line contains no spaces.

Print minimal number of seconds to eat at least $$$k$$$ candies. If solution doesn't exist, print "-1".

NoteThe sequence of actions of Tanya for the first example:  move from the box $$$3$$$ to the box $$$2$$$;  eat candies from the box $$$2$$$;  move from the box $$$2$$$ to the box $$$3$$$;  eat candy from the box $$$3$$$;  move from the box $$$3$$$ to the box $$$4$$$;  move from the box $$$4$$$ to the box $$$5$$$;  eat candies from the box $$$5$$$. Since Tanya eats candy instantly, the required time is four seconds.

import sys

def minp():
	return sys.stdin.readline().strip()

dp = [None]*50
for j in range(50):
	dp[j] = [None]*2001

n,s,k = map(int,minp().split())
a = [None]*n
i = 0
s -= 1
for j in map(int,minp().split()):
	a[i] = (j, i)
	i += 1
i = 0
for j in minp():
	a[i] += ("RGB".find(j),)
	i += 1
a.sort()
r = 10**18
zzz = 0
for i in range(n):
	ii = dp[i]
	c = a[i][0]
	ii[c] = abs(s-a[i][1])
	#print(ii[c])
	for j in range(i):
		if a[j][2] == a[i][2] or a[j][0] == a[i][0]:
			continue
		jj = dp[j]
		for z in range(2001-c):
			zz = jj[z]
			if zz != None:
				d = zz + abs(a[i][1]-a[j][1])
				cc = z+c
				if ii[cc] != None:
					if ii[cc] > d:
						ii[cc] = d
				else:
					ii[cc] = d
	for z in range(k,2001):
		if ii[z] != None:
			r = min(r,ii[z])
	#print(ii[:k+1])
if r != 10**18:
	print(r)
else:
	print(-1)

INF = 10e9
n,s,k = map(int, input().split())
r = list(map(int, input().split()))
r.append(0)
col = input()
mat = []
for i in range(n+1):
    adj = {}
    for j in range(n):
        if i == n:
            adj[j] = abs((s-1)-j)
        else:
            if col[i] != col[j] and r[i] < r[j]:
                adj[j] = abs(i-j)
    mat.append(adj)
# print(*mat, sep='\n')

mem = [{} for i in range(n+1)]
# print(mem)

def get(s, k):
    # print(s,k)
    # print(mem)
    if mem[s].get(k):
        return mem[s].get(k)
    if r[s] >= k:
        mem[s][k] = 0
    else:
        mi = None
        for nei in mat[s]:
            ncost = get(nei, k-r[s])
            if ncost is None:
                continue
            curr = ncost + mat[s][nei]
            if mi is None or curr < mi:
                mi = curr
        if mi is not None:
            mem[s][k] = mi
        else:
            mem[s][k] = INF
    return mem[s].get(k)

# print(mem)

ans = get(n,k)
if ans is None or ans >= INF:
    print(-1)
else:
    print(ans)

INF = 100000

n,s,k=map(int,input().split())
r = list(map(int,input().split()))
c = input().rstrip()
#dp[i][j]: i = the current position just after eating candies, j = remaining candies to eat
dp = [[INF for j in range(k+1)] for i in range(n)]
s -= 1
for i in range(n):
    dp[i][k-r[i]] = abs(s-i)
for j in range(k,-1,-1):
    for i in range(n):
        if dp[i][j] >= INF: continue
        for f in range(n):
            if r[f] <= r[i]: continue
            if c[f] == c[i]: continue
            new_val = max(0, j-r[f])
            dp[f][new_val] = min(dp[f][new_val], dp[i][j] + abs(i-f))
ans = INF
for i in range(n):
    ans = min(ans, dp[i][0])
if ans >= INF:
    ans = -1

print(ans)

inf = 10000
n, s, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(input())
for i in range(n):
    if b[i] == 'R':
        b[i] = 0
    elif b[i] == 'G':
        b[i] = 1
    else:
        b[i] = 2
boxes = [[a[i], b[i], i] for i in range(n)]
boxes.sort()
l = boxes[-1][0] * n + 1
s -= 1
dp = [[[inf, s, -1] for j in range(l)] for i in range(3)]
if l < k:
    print(-1)
    exit(0)
dp[0][0][0] = 0
dp[1][0][0] = 0
dp[2][0][0] = 0
for i in range(n):
    pos = boxes[i][2]
    clr = boxes[i][1]
    cnt = boxes[i][0]
    for j in range(l - cnt):
        for c in range(3):
            if c == clr:
                continue
            if dp[clr][j + cnt][0] > dp[c][j][0] + abs(dp[c][j][1] - pos) and cnt > dp[c][j][2]:
                dp[clr][j + cnt][0] = dp[c][j][0] + abs(dp[c][j][1] - pos)
                dp[clr][j + cnt][1] = pos
                dp[clr][j + cnt][2] = cnt
ans = min(dp[0][k][0], min(dp[1][k][0], dp[2][k][0]))
for i in range(k, l):
    ans = min(min(ans, dp[0][i][0]), min(dp[1][i][0], dp[2][i][0]))
if ans < inf:
    print(ans)
else:
    print(-1)

n, s, k = map(int, input().split())
s -= 1
r = list(map(int, input().split()))
INF = float("inf")
c = input()
dp = [[] for i in range(n)]

def calc(u):
    if dp[u]:
        return
    dp[u] = [0] * (r[u] + 1) + [INF] * (k - r[u])
    for i in range(n):
        if c[u] != c[i] and r[i] > r[u]:
            calc(i)
            d = abs(u - i)
            for j in range(r[u] + 1, k + 1):
                dp[u][j] = min(dp[u][j], dp[i][j - r[u]] + d)

ans = INF
for i in range(n):
    calc(i)
    ans = min(ans, abs(i - s) + dp[i][k])
if ans == INF:
    print(-1)
else:
    print(ans)

n, s, k=map(int, raw_input().split())
s-=1
r=map(int, raw_input().split())
color=raw_input()
dp=[[] for i in range(n)]
def dfs(cur):
	if dp[cur]:
		return
	dp[cur]=[0]*(r[cur]+1)+[1000000000]*(k-r[cur])
	for to in range(n):
		if color[to]!=color[cur] and r[to]>r[cur]:
			dfs(to)
			dis=abs(cur-to)
			for i in range(r[cur]+1, k+1):
				dp[cur][i]=min(dp[cur][i], dp[to][i-r[cur]]+dis)
result=1000000000
for i in range(n):
	dfs(i)
	result=min(result, abs(i-s)+dp[i][k])
print result if result!=1000000000 else -1

from collections import *
n, s, k = map(int, raw_input().split())
s -= 1
a = map(int, raw_input().split())
C = raw_input()
DP = [defaultdict(int) for _ in range(n*n)]
for i in range(n):
    DP[abs(i-s)][i] = a[i]
for t in range(n*n):
    for i, v in DP[t].items():
        if v >= k:
            print(t)
            exit()
        for j in range(n):
            if a[j] > a[i] and C[j] != C[i]:
                DP[t + abs(j-i)][j] = max(DP[t+abs(j-i)][j], v + a[j])

print(-1)

inf = float('inf')

N,S,K = map(int,raw_input().strip('\n').split(' '))
A = map(int,raw_input().strip('\n').split(' '))
color = raw_input().strip('\n')

dp = [[inf]*(N+500) for k in range(K+500)]
for i in range(N):
    dp[A[i]][i] = abs(S-i-1);

for k in range(K+500):
    for pos in range(N):
        if dp[k][pos] == inf:
            continue
        for newpos in range(N):
            if A[newpos]<=A[pos] or color[newpos] == color[pos]:
                continue
            if k+A[newpos]>=K+500:
                continue
            dp[k+A[newpos]][newpos] = min(dp[k+A[newpos]][newpos], dp[k][pos]+abs(newpos-pos))

ans = inf
for k in range(K,K+500):
    for pos in range(N):
        ans = min(ans,dp[k][pos])
if ans == inf:
    print -1
else:
    print ans

# dp = (mintime,last_j,last_c)
# candies = [(ni,ji,ci)]
# dp[0][0][1] = S
# dp[i][k+ni][0] = {c!=ci  dp[i-1][k][0] + dp[i-1][k][1]-j)
# dp[i][k+ni][1] = j
# dp[i][k+ni][2] = c

# candies = [(n,j,c) for j,(n,c) in enumerate(zip(A,color))]
# candies = sorted(candies,key=lambda x:x[0])

# dp = []
# for i in range(N+500):
#     temp = []
#     for j in range(K+500):
#         temp.append([inf,0,0])
#     dp.append(temp)

# for i in range(N+1):
#     dp[i][0][0] = 0
#     dp[i][0][1] = S

# for i in range(1,N+1):
#     ni,ji,ci = candies[i-1]
#     for k in range(K+500):
#         if k<ni:
#             continue
#         if dp[i-1][k][2] != ci:
#             dp[i][k][0]  = min(dp[i][k][0], dp[i-1][k-ni][0] + abs(dp[i-1][k-ni][1]-j))
#             dp[i][k][1] = ji
#             dp[i][k][2] = ci
#         else:
#             dp[i][k][0] = dp[i-1][k][0] + abs(dp[i-1][k][1]-j)

# print dp[N]

n, s, k = list(map(int, input().split()))
amounts = list(map(int, input().split()))
colors = list(input())

dp = [[-1 for j in range(k + 1)] for i in range(n)]

def getAns(nth, left):
    if left <= 0:
        return 0
    if dp[nth][left] >= 0:
        return dp[nth][left]

    ret = 999999999
    for i in range(n):
        if amounts[i] <= amounts[nth] or colors[i] == colors[nth]:
            continue
        ret = min(ret, abs(nth - i) + getAns(i, left - amounts[i]))

    dp[nth][left] = ret
    return ret

ans = 999999999
for i in range(n):
    ans = min(ans, getAns(i, k - amounts[i]) + abs(s - 1 - i))
if ans == 999999999:
	ans = -1
print(ans)

'''input
2 1 15
5 6
RG
'''
import math
def solve():
	n,s,k = map(int,input().split())
	s-=1
	r = list(map(int,input().split()))
	c = input()
	inf = int(1e9)
	dp = [[inf for j in range(n)] for i in range(k+1)]
	# dp[i][j] = minimum number of steps to get amount i if we start with jth index
	for i in range(0,k+1):
		for j in range(0,n):
			if i==0 or i<=r[j]:
				dp[i][j] = 0
				continue
			for K in range(0,n):
				if c[K]!=c[j] and r[K]>r[j]:
					dp[i][j] = min(dp[i][j],dp[i-r[j]][K]+int(abs(K-j)))
	ans = min(dp[k][i]+abs(i-s) for i in range(0,n))
	if ans>=inf:
		print(-1)
		return
	print(ans)
	return
t = 1
#t = int(input())
while t>0:
	t-=1
	solve()

INF = 1e10
max_n = 50
max_k = 2000
def main():
    n, s, k = map(int, input().split())
    s -= 1
    buf = ['']*(max_n + 1)
    dp = [[0 for i in range(max_n + 1)] for j in range(max_k + 1)]
    r = list(map(int, input().split()))
    c = input()
    answer = INF
    for i in range(len(c)):
        buf[i] = c[i]
    for i in range(k, -1, -1):
        for j in range(n):
            dp[i][j] = INF
    for j in range(n):
        value = abs(j - s)
        if k - r[j] <= 0:
            answer = min(answer, value)
        else:
            dp[k - r[j]][j] = value
    for i in range(k, 0, -1):
        for j in range(n):
            if dp[i][j] < INF:
                for l in range(n):
                    if buf[j] != buf[l] and r[j] < r[l]:
                        value = dp[i][j] + abs(j - l)
                        if i - r[l] <= 0:
                            answer = min(answer, value)
                        else:
                            dp[i - r[l]][l] = min(dp[i - r[l]][l], value)
    if answer == INF:
        print(-1)
        return
    print(answer)

if __name__=="__main__":
    main()

n,s,k=map(int,input().split())
r=list(map(int,input().split()))
s-=1
c=input()
best=[[0 for i in range(n)] for j in range(k+1)]
for i in range(1,k+1):
    for j in range(n):
        if i<=r[j]:
            best[i][j]=abs(j-s)
        else:
            good=float("inf")
            for l in range(n):
                if c[j]!=c[l] and r[j]>r[l]:
                    good=min(good,best[i-r[j]][l]+abs(j-l))
            best[i][j]=good
if min(best[-1])==float('inf'):
    print(-1)
else:
    print(min(best[-1]))

inf = 10000
n, s, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(input())
for i in range(n):
    if b[i] == 'R':
        b[i] = 0
    elif b[i] == 'G':
        b[i] = 1
    else:
        b[i] = 2
boxes = [[a[i], b[i], i] for i in range(n)]
boxes.sort()
l = boxes[-1][0] * n + 1
s -= 1
dp = [[[inf, s] for j in range(l)] for i in range(3)]
if l < k:
    print(-1)
    exit(0)
dp[0][0][0] = 0
dp[1][0][0] = 0
dp[2][0][0] = 0
for i in range(n):
    d = dp.copy()
    pos = boxes[i][2]
    clr = boxes[i][1]
    cnt = boxes[i][0]
    for j in range(l - cnt):
        for c in range(3):
            if c == clr:
                continue
            if d[clr][j + cnt][0] > d[c][j][0] + abs(d[c][j][1] - pos):
                d[clr][j + cnt][0] = d[c][j][0] + abs(d[c][j][1] - pos)
                d[clr][j + cnt][1] = pos
    dp = d.copy()
ans = min(dp[0][k][0], min(dp[1][k][0], dp[2][k][0]))
for i in range(k, l):
    ans = min(min(ans, dp[0][i][0]), min(dp[1][i][0], dp[2][i][0]))
if ans < inf:
    print(ans)
else:
    print(-1)

inf = 10000
n, s, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(input())
for i in range(n):
    if b[i] == 'R':
        b[i] = 0
    elif b[i] == 'G':
        b[i] = 1
    else:
        b[i] = 2
boxes = [[a[i], b[i], i] for i in range(n)]
boxes.sort()
l = boxes[-1][0] * n + 1
s -= 1
dp = [[[inf, s] for j in range(l)] for i in range(3)]
if l < k:
    print(-1)
    exit(0)
dp[0][0][0] = 0
dp[1][0][0] = 0
dp[2][0][0] = 0
for i in range(n):
    pos = boxes[i][2]
    clr = boxes[i][1]
    cnt = boxes[i][0]
    for j in range(l - cnt):
        for c in range(3):
            if c == clr:
                continue
            if dp[clr][j + cnt][0] > dp[c][j][0] + abs(dp[c][j][1] - pos) and dp[c][j][1] != pos:
                dp[clr][j + cnt][0] = dp[c][j][0] + abs(dp[c][j][1] - pos)
                dp[clr][j + cnt][1] = pos
ans = min(dp[0][k][0], min(dp[1][k][0], dp[2][k][0]))
for i in range(k, l):
    ans = min(min(ans, dp[0][i][0]), min(dp[1][i][0], dp[2][i][0]))
if ans < inf:
    print(ans)
else:
    print(-1)

inf = float('inf')

N,S,K = map(int,raw_input().strip('\n').split(' '))
A = map(int,raw_input().strip('\n').split(' '))
color = raw_input().strip('\n')

dp = [[inf]*(N+5) for k in range(K+5)]
for i in range(N):
    dp[A[i]][i] = abs(S-i-1);

for k in range(K+5):
    for pos in range(N):
        if dp[k][pos] == inf:
            continue
        for newpos in range(N):
            if A[newpos]<=A[pos] or color[newpos] == color[pos]:
                continue
            if k+A[newpos]>K+5:
                continue
            dp[k+A[newpos]][newpos] = min(dp[k+A[newpos]][newpos], dp[k][pos]+abs(newpos-pos))

ans = int(1e18)
for k in range(K,K+5):
    for pos in range(N):
        ans = min(ans,dp[k][pos])
if ans == inf:
    print -1
else:
    print ans

# dp = (mintime,last_j,last_c)
# candies = [(ni,ji,ci)]
# dp[0][0][1] = S
# dp[i][k+ni][0] = {c!=ci  dp[i-1][k][0] + dp[i-1][k][1]-j)
# dp[i][k+ni][1] = j
# dp[i][k+ni][2] = c

# candies = [(n,j,c) for j,(n,c) in enumerate(zip(A,color))]
# candies = sorted(candies,key=lambda x:x[0])

# dp = []
# for i in range(N+5):
#     temp = []
#     for j in range(K+5):
#         temp.append([inf,0,0])
#     dp.append(temp)

# for i in range(N+1):
#     dp[i][0][0] = 0
#     dp[i][0][1] = S

# for i in range(1,N+1):
#     ni,ji,ci = candies[i-1]
#     for k in range(K+5):
#         if k<ni:
#             continue
#         if dp[i-1][k][2] != ci:
#             dp[i][k][0]  = min(dp[i][k][0], dp[i-1][k-ni][0] + abs(dp[i-1][k-ni][1]-j))
#             dp[i][k][1] = ji
#             dp[i][k][2] = ci
#         else:
#             dp[i][k][0] = dp[i-1][k][0] + abs(dp[i-1][k][1]-j)

# print dp[N]

inf = float('inf')

N,S,K = map(int,raw_input().strip('\n').split(' '))
A = map(int,raw_input().strip('\n').split(' '))
color = raw_input().strip('\n')

dp = [[inf]*(N+5) for k in range(K+5)]
for i in range(N):
    dp[A[i]][i] = abs(S-i-1);

for k in range(K+5):
    for pos in range(N):
        if dp[k][pos] == inf:
            continue
        for newpos in range(N):
            if A[newpos]<=A[pos] or color[newpos] == color[pos]:
                continue
            if k+A[newpos]>=K+5:
                continue
            dp[k+A[newpos]][newpos] = min(dp[k+A[newpos]][newpos], dp[k][pos]+abs(newpos-pos))

ans = inf
for k in range(K,K+5):
    for pos in range(N):
        ans = min(ans,dp[k][pos])
if ans == inf:
    print -1
else:
    print ans

# dp = (mintime,last_j,last_c)
# candies = [(ni,ji,ci)]
# dp[0][0][1] = S
# dp[i][k+ni][0] = {c!=ci  dp[i-1][k][0] + dp[i-1][k][1]-j)
# dp[i][k+ni][1] = j
# dp[i][k+ni][2] = c

# candies = [(n,j,c) for j,(n,c) in enumerate(zip(A,color))]
# candies = sorted(candies,key=lambda x:x[0])

# dp = []
# for i in range(N+5):
#     temp = []
#     for j in range(K+5):
#         temp.append([inf,0,0])
#     dp.append(temp)

# for i in range(N+1):
#     dp[i][0][0] = 0
#     dp[i][0][1] = S

# for i in range(1,N+1):
#     ni,ji,ci = candies[i-1]
#     for k in range(K+5):
#         if k<ni:
#             continue
#         if dp[i-1][k][2] != ci:
#             dp[i][k][0]  = min(dp[i][k][0], dp[i-1][k-ni][0] + abs(dp[i-1][k-ni][1]-j))
#             dp[i][k][1] = ji
#             dp[i][k][2] = ci
#         else:
#             dp[i][k][0] = dp[i-1][k][0] + abs(dp[i-1][k][1]-j)

# print dp[N]

inf = float('inf')

N,S,K = map(int,raw_input().strip('\n').split(' '))
A = map(int,raw_input().strip('\n').split(' '))
color = raw_input().strip('\n')

dp = [[inf]*(N+5) for k in range(K+5)]
for i in range(N):
    dp[A[i]][i] = abs(S-i-1);

for k in range(K+5):
    for pos in range(N):
        if dp[k][pos] == inf:
            continue
        for newpos in range(N):
            if A[newpos]<=A[pos] or color[newpos] == color[pos]:
                continue
            if k+A[newpos]>K+5:
                continue
            dp[k+A[newpos]][newpos] = min(dp[k+A[newpos]][newpos], dp[k][pos]+abs(newpos-pos))

ans = int(1e18)
for k in range(K,K+5):
    for pos in range(N):
        ans = min(ans,dp[k][pos])
print ans

# dp = (mintime,last_j,last_c)
# candies = [(ni,ji,ci)]
# dp[0][0][1] = S
# dp[i][k+ni][0] = {c!=ci  dp[i-1][k][0] + dp[i-1][k][1]-j)
# dp[i][k+ni][1] = j
# dp[i][k+ni][2] = c

# candies = [(n,j,c) for j,(n,c) in enumerate(zip(A,color))]
# candies = sorted(candies,key=lambda x:x[0])

# dp = []
# for i in range(N+5):
#     temp = []
#     for j in range(K+5):
#         temp.append([inf,0,0])
#     dp.append(temp)

# for i in range(N+1):
#     dp[i][0][0] = 0
#     dp[i][0][1] = S

# for i in range(1,N+1):
#     ni,ji,ci = candies[i-1]
#     for k in range(K+5):
#         if k<ni:
#             continue
#         if dp[i-1][k][2] != ci:
#             dp[i][k][0]  = min(dp[i][k][0], dp[i-1][k-ni][0] + abs(dp[i-1][k-ni][1]-j))
#             dp[i][k][1] = ji
#             dp[i][k][2] = ci
#         else:
#             dp[i][k][0] = dp[i-1][k][0] + abs(dp[i-1][k][1]-j)

# print dp[N]

n, s, k = list(map(int, input().split()))
amounts = list(map(int, input().split()))
colors = list(input())

dp = [[-1 for j in range(k + 1)] for i in range(n)]

def getAns(nth, left):
    if left <= 0:
        return 0
    if dp[nth][left] >= 0:
        return dp[nth][left]

    ret = 999999999
    for i in range(n):
        if amounts[i] <= amounts[nth] or colors[i] == colors[nth]:
            continue
        ret = min(ret, abs(nth - i) + getAns(i, left - amounts[i]))

    dp[nth][left] = ret
    return ret

ans = 999999999
for i in range(n):
    ans = min(ans, getAns(i, k - amounts[i]) + abs(s - 1 - i))
print(ans)

'''input
5 3 10
1 2 3 4 5
RGBRR
'''
import math
def solve():
	n,s,k = map(int,input().split())
	s-=1
	r = list(map(int,input().split()))
	c = input()
	inf = int(1e18)
	dp = [[inf for i in range(n+1)] for j in range(k+1)]
	spos = [[inf for i in range(n+1)] for j in range(k+1)]
	# dp[i][j] = minimum number of steps to get amount i if we start with jth index
	for i in range(0,k+1):
		for j in range(0,n):
			if i==0 or i<=r[j]:
				dp[i][j] = 0
				continue
			for K in range(0,n):
				if c[K]!=c[j] and c[K]>c[j]:
					dp[i][j] = min(dp[i][j],dp[i-r[j]][K]+int(abs(K-j)))
	ans = min(dp[k][i]+abs(i-s) for i in range(0,n))
	if ans==inf:
		print(-1)
		return
	print(ans)
	return
t = 1
#t = int(input())
while t>0:
	t-=1
	solve()


Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

Print the maximum possible height of the pyramid in the single line.

a = [(x*(x+1)/2+x*(x+1)*(2*x+1)/6)/2 for x in range(0,100000)]
want = input()
f=0
l=99999
m=0
#print a[:10]
while f<l :
	m=(f+l)/2
	if a[m]<want :f=m+1
	else :l=m
print f if a[f]<=want else f-1 if f-1>0 else 0

n=int(input())
s=0
v=0
i=1
while(v<=n):
    s=s+i
    v=v+s
    i=i+1
print(i-2)

import math

__author__ = "runekri3"

cubes = int(input())
height = 1
cur_cubes = 1
while cubes >= cur_cubes:
    height += 1
    cur_cubes += height * (height + 1) // 2
height -= 1
print(height)

def main():
    n = 1
    i = 2
    x = int(input())
    while n < x + 1:
        n += ((i * (i + 1)) // 2)
        i += 1
    print(i - 2)

main()

n=int(raw_input())
w=t=r=0
while w<n:
    t+=1
    r+=t
    w+=r
print t if w==n else t-1

n=int(input())
d,c,m,i=0,1,1,1
while c<=n:
    d+=1
    i+=1
    m+=i
    c+=m
print(d)

n = int(raw_input())
total = 1
req = 1
i = 1

while n >= total:
    i += 1
    req += i
    total += req

print i-1

cubes = int(input())

d=cnt=h=0

while cubes>0:
	d+=1
	cnt+=d
	if cnt<=cubes:
		cubes-=cnt
		h+=1
	else:
		break
print(h)

num_cubes = int(input()) # the number of cubes given to Vasya

total = 0
temp = 0
count = 0

for i in range(0,10000):
	total += i
	temp += total

	if (temp > num_cubes):
		break

	count = i

print(count)

# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

#a = tuple(int(i) for i in raw_input().strip().split(" "))
n = int(raw_input())
t = tuple((i*(i+1)*(i+2))/6 for i in range(1,40))
x = 0
while n >= t[x]:
    x += 1
if n == t[x]:
    print x+1
    print "HELLO"
else:
    print x

n = int(input())
row, cubes_in_row = 0, 0

cubes = 0
while cubes <= n:
    row += 1
    cubes_in_row += row
    cubes += cubes_in_row

print(row -1 )

# while n >= cubes_in_row + row + 1:
#     row += 1
#     cubes_in_row += row
#     n -= cubes_in_row
# print(row)

#!/usr/bin/python3

n = int(input())
i = 0
j = 0

while i <= n:
    j += 1
    i += (j*(j+1))/2
print(j - 1)

bla=int(raw_input())
num=1
g=0
while g<=bla:
    g+=(num)*(num+1)/2
    num+=1
if bla!=1:
    print num-2
else:
    print 1

n = int(input())
var = 0
for i in range(1,100000):
    var += ((i*(i+1))//2)
    if var > n:
        print(i-1)
        exit()

x=int(raw_input())
ans=0
t=1
while(x > 0):
  ans+=t
  t+=1
  x-=t+ans
print t-1

n = int(input())
i=1
sum=0
x = n-sum
cnt=0
while(x>0):
    sum+=i
    cnt+=1
    i += 1
    n-=sum
    x=n-sum

if(n<0):
    print(cnt-1)
else:
    print(cnt)

n=int(input())
c,k,s=0,0,0
for  i in range(1,n+2):
  if k>n:
    break
  else:
    s=s+i
    k=s+k
    c+=1
print(c-1)

n = int(input())

a = 0
ip = 0
ipc = 0

while n > ipc:
    a += 1
    ip += a
    ipc += ip

if n < ipc:
    print(a - 1)
else:
    print(a)

cubes = int(input())
height = 0
while True:
    if cubes >= ((height + 1)*height/2):
        cubes = cubes - ((height + 1)*height/2)
        height = height + 1
    else:
        break
print(height-1)

n = int(input())
k = 1
s = 0
while 1:
    if s + k*(k+1)//2 > n:
        print(k-1)
        break
    elif s + k*(k+1)//2 == n:
        print(k)
        break
    else:
        s += k*(k+1)//2
        k+=1

n=int(input())
lvl=0
x=0
i=1
while n>=x+i:
    x+=i
    i += 1
    lvl+=1
    n-=x
print(lvl)

n = int(input())
lvl = 0
row = 1
plus = 2
while n >= 0:
    n -= row
    lvl += 1
    row += plus
    plus += 1
print(lvl-1)

def main():
    n = int(raw_input())
    x = lambda y: y*(y+1)*(y+2)/6
    count = 1
    while 1:
        if x(count) > n:
            return count - 1
        count += 1

if __name__ == "__main__":
    print main()

n = input()
ans = 0
i = 1
while (ans < n) :
	ans += (i * (i + 1))/2
	i += 1
if (ans == n) :
	print i - 1
else :
	print i - 2

#!/usr/bin/env python
def height():
    n = int(input())
    h = 1
    i = 1
    if i < 1:
        return 0
    elif n == 1:
        return 1
    while i <= n:
        h += 1
        i += (h*(h+1))/2
    return h-1

print(height())

n=i=input()*6
while i**3-i>n:i-=1
print i-1

n=int(input())
m=0#колличество кубиков в одном уровне
i=0#номер уровня
while n>=m:
    m=m+i+1
    if n>=m:
        n=n-m
        i+=1
print(i)

from math import *
from collections import deque
from copy import deepcopy
import sys
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def multi(): return map(int,input().split())
def strmulti(): return map(str, inp().split())
def lis(): return list(map(int, inp().split()))
def lcm(a,b): return (a*b)//gcd(a,b)
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def stringlis(): return list(map(str, inp().split()))
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def printlist(a) :
    print(' '.join(str(a[i]) for i in range(len(a))))

def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#copied functions end

#start coding

n=int(input())
i=1
num=0
if(n==1):
    print(1)
    exit(0)
while(num<n):
    # print(num)
    num+=i*(i+1)//2
    if(num+(i+1)*(i+2)//2>n):

        # print("chala")
        break
    # if(num>n):
    #     i-=1
    #     break
    i+=1
print(i)

#!/usr/bin/env python2

def compare(element_a, element_b):
    if element_a == element_b:
        return 0
    elif element_a > element_b:
        return 1
    else:
        return -1

BEGIN_N = 1
END_N   = 10001

n = input()
cubes_cnt_sum = cubes_cnt_current_level = 0
for level in range(BEGIN_N, END_N):
    cubes_cnt_current_level += level
    cubes_cnt_sum           += cubes_cnt_current_level
    result = compare(cubes_cnt_sum, n)
    if 0 == result:
        print level
        break
    elif 1 == result:
        print level - 1
        break

no_of_cubes = int(input())
data = [0]
layer =0
sum = 0
while(data[layer] <= no_of_cubes):
    layer+=1
    if layer==1:
        sum += data[layer - 1] + layer
        if sum > no_of_cubes:
            break
        else :
            data.append(layer)
    elif layer==2:
        sum += data[layer - 1] + layer
        if sum > no_of_cubes:
            break
        else :
            data.append(data[layer-1]+layer)

    elif layer > 2 :
        if data[layer-1]+layer < no_of_cubes:
            sum += data[layer - 1] + layer
            if sum > no_of_cubes:
                break
            else:
                data.append(data[layer-1]+layer)

        else:
            break

print(len(data)-1)

n,k,i = int(input()),1,1
while(n>=k):n-=k;i+=1;k+=i
print(i-1)

def trial():
    num = int(input())
    levels = []
    for i in range(1, num + 1):
        counter = 0
        for j in range(i+1):
            counter += j
            if counter >= num:
                levels.append(counter)
                break
            elif counter < num and counter not in levels:
                levels.append(counter)
        if levels[-1] > num:
            break
    levels.pop(0)
    if len(levels) == 1:
        return print(1)
    res = 0
    counter = 0
    for i in levels:
        if res < num:
            counter += 1
            res += i
            if res > num:
                counter -= 1
                return print(counter)
        else:
            return print(counter)
    return print(counter)
trial()

n = int(input())
g = 0
i = 0
ans = 0
while n - g - i  > 0:
    i +=1
    g +=i
    n -=g
    ans +=1
print(ans)

cubics=int(raw_input())
height=0
raws=[]
i=0
total=0

while True:
    i+=1
    raws.append(i)
    total+=sum(raws)
    if total<=cubics:
        height+=1
    else:
        break
print height

n=int(input())
if n==1:
    print("1")
else:
    sum_=0
    count=0
    add_=-1
    for i in range(1000):
        sum_=sum_+i
        count=count+sum_
        if count<=n:
            add_=add_+1
        else:
            break
    print(add_)

a=int(raw_input())
c=0
i=0
l=0
while c<=a:
	i+=1
	l+=i
	c=c+l
print i-1

n = int(input())
totalCubes = 0
nextLevel = 0
i = 0
while totalCubes <= n:
    i += 1
    nextLevel += i
    totalCubes += nextLevel

print(i - 1)

n = input()

blocks = 0
start = 0
startIncrement = 1
count = 0

while blocks <= n:
    start += startIncrement
    startIncrement += 1
    blocks += start
    count += 1

print count - 1

n = int(input())
k = 0
m = 0
z = 0
for i in range(10000):
    k += i
    m += k
    z += 1
    if m > n:
        break
print(z-2)

n=int(input())
i=0
s=0
while(True):
    k1=i*(i+1)//2
    s+=k1
    if(s>=n):
        if(s>n):
            i=i-1
        break
    i+=1
print(i)

i=int(input())
t=0
sumi=0
l=0
while(i>=0):
 l=l+1
 t=t+l
 i=i-t
print(l-1)

'''
https://codeforces.com/problemset/problem/492/A

Solution:

Say n = 25.

Per layer Boxes   | Total Boxes Used
1                 |      1
1+2 = 3           |      4
1+2+3 = 6         |     10
1+2+3+4 = 10      |     20
1+2+3+4+5 = 15    |     35

Hence at each layer, we add the height (incremented by 1 in each layer) to the previous-layer boxes and that
gives the current layer boxes. Keep adding that to a total accumulation (boxesUsed).

Since we cannot build a layer without having enough boxes for the current-layer, we may over-estimate the height.
Hence, we check if n < boxesUsed after the current layer usage, we reduce the height by 1, thereby descarding the
current layer in the pyramid.

The final height is the answer.

'''

def solve(n):

    height = boxesUsed = prevStepBoxes = 0

    while n > boxesUsed:

        height += 1
        thisStepBoxes = prevStepBoxes + height
        boxesUsed += thisStepBoxes
        prevStepBoxes = thisStepBoxes

        #if this layer is not possible, we over-estimated the height. Reduce it by 1
        if n < boxesUsed:
            height -= 1

    return height

if __name__ == "__main__":
    n = int(raw_input())
    print solve(n)

n=int(input())
s=0
for i in range(1,10**100):
 s+=i
 if s>n:
  print(i-1)
  break
 n-=s

n=int(raw_input())
ans,chk,cnt=0,0,1
while 1:
    chk+=cnt
    ans+=chk
    if ans==n:
        print cnt
        break
    elif ans>n:
        print cnt-1
        break
    cnt+=1

a=int(input())
i=0
b=0
c=0
while c<a:
    i=i+1
    b=b+i
    c=c+b
    if c>a:
        i=i-1
    if c==a:
        break
print(i)

n=int(input())
n_y=1
yr=1
n-=1
while n>n_y:
    yr=yr+1
    n_y=n_y+yr
    n=n-n_y
    if n<0:
        yr-=1
print(yr)

i=int(input())
count=0
k=0
sum=0

while sum+count+k+1<=i:
    k=k+1
    count=count+k
    sum=sum+count

print(k)

def main():
    n = 1
    i = 2
    x = int(input())
    while n < x + 1:
        n += ((i * (i + 1)) // 2)
        i += 1
    print(i - 2)

main()

def solution(N):
	count=0
	for i in range(1,1000):
		if N<=0 or N-i*(i+1)/2<0:
			return count
		else:
			count=count+1
			N=N-i*(i+1)/2

N=int(raw_input())
print(solution(N))

cubes=int(input())
if cubes == 1 or cubes == 2 or cubes == 3:
    lvl = 1
else:
    lvl=2
ammount=3
cubes=cubes-4
while cubes>ammount+lvl:
    lvl+=1
    ammount=ammount+lvl
    cubes=cubes-ammount

print(lvl)

n=i=input()*6
while i**3-i>n:i-=1
print i-1

j = int(input())

def pyramid_height(cubes):
    additional_cubes = 1
    curr_layer_cubes = 0
    height = 0

    while True:
        curr_layer_cubes += additional_cubes
        cubes -= curr_layer_cubes
        if cubes < 0:
            return height
        height += 1
        additional_cubes += 1

print(pyramid_height(j))

n = int(raw_input())
i = 0
s = 0
while s <= n:
    i += 1
    s += (i*(i+1))/2
print i - 1

n = int(input())
ans = 0
count = 0
while count <= n:
    ans += 1
    count +=((ans*(ans+1)) // 2)
print(ans-1)

n=input()
summ=0
c=0
x=[]

for i in range(1,1000):
	summ+=i
	x.append(summ)
	if sum(x)>n:
		break;
	else:
		c+=1

print c

bla=int(raw_input())
num=1
g=0
while g<=bla:
    g+=(num)*(num+1)/2
    num+=1
if bla!=1:
    print num-2
else:
    print 1

def GH(a,i):
    if a<0:return i-2
    else:return GH(a-i*(i+1)/2,i+1)
print(GH(int(input()),1))

n=int(input())

m=0#колличество кубиков в одном уровне

i=0#номер уровня

while n>=m:

    m=m+i+1

    if n>=m:

        n=n-m

        i+=1

print(i)

#!/usr/bin/env python2

def compare(int_num_a, int_num_b):
    if int_num_a == int_num_b:
        return 0
    elif int_num_a > int_num_b:
        return 1
    else:
        return -1

def binary_search(begin, end, target):
    while begin < end:
        mid = (begin + end) >> 1
        result = compare(mid * (mid + 1) * (mid + 2) / 6, target)
        if 0 == result:
            return mid
        elif 1 == result:
            end = mid
        else:
            begin = mid + 1
    return begin - 1

BEGIN_LEVEL = 1
END_LEVEL   = 40

n = input()
index = binary_search(BEGIN_LEVEL, END_LEVEL, n)
print index

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

	floor = 0
	while n > 0:
		if n >= (floor+1)*(floor+2)//2:
			n -= (floor+1)*(floor+2)//2
			floor += 1
		else:
			print(floor)
			return
	print(floor)

function()

n=int(raw_input())
count=0
h=1
while count<n:
    h+=1
    count+=h*(h+1)/2
print h-1

n = int(raw_input())

x = 1
y = 0
r = 1

for i in range(1, n):
    x = (i * (i + 1) ) / 2
    y += x
    if y > n:
        r = i-1
        break

print r

h,counter=0,0
n=int(input())
while(counter<=n):
    h+=1
    counter+=((h)*(h+1))//2
print(h-1)

#!/usr/bin/env python2

def compare(int_num_a, int_num_b):
    if int_num_a == int_num_b:
        return 0
    elif int_num_a > int_num_b:
        return 1
    else:
        return -1

def binary_search(number_list, target):
    begin = 0
    end   = len(number_list)
    while begin < end:
        mid = (begin + end) >> 1
        result = compare(number_list[mid], target)
        if 0 == result:
            return mid
        elif 1 == result:
            end = mid
        else:
            begin = mid + 1
    return begin - 1

BEGIN_LEVEL = 1
END_LEVEL   = 40
END_N       = 10002

cubes_cnt_current_level = 0
cubes_cnt_sum = [cubes_cnt_current_level, ]
for level in range(BEGIN_LEVEL, END_LEVEL):
    cubes_cnt_current_level += level
    cubes_cnt_sum.append(cubes_cnt_sum[-1] + cubes_cnt_current_level)
    if cubes_cnt_sum[-1] >= END_N:
        break

while True:
    try:
        n = input()
    except EOFError:
        break

    index = binary_search(cubes_cnt_sum, n)
    print index

import math
c=int(input())
n=0
i=0

while n<c:

    n=n+((i*i + i)/2)
    if n<=c:
        i+=1

print(i-1)

def compare(element_a, element_b):
    if element_a > element_b:
        return True
    else:
        return False

def search_one_by_one(number_list, target):
    length = len(number_list)
    for index in range(length):
        if compare(number_list[index], target):
            return index
    else:
        return length

BEGIN_N = 1
END_N   = 10001

cubes_cnt_current_level = 0
cubes_cnt_sum = [cubes_cnt_current_level, ]
for level in range(BEGIN_N, END_N):
    cubes_cnt_current_level += level
    cubes_cnt_sum.append(cubes_cnt_sum[-1] + cubes_cnt_current_level)
    if (cubes_cnt_sum[-1] >= END_N):
        break

n     = input()
index = search_one_by_one(cubes_cnt_sum, n)
print index - 1

a=int(input())
l=0;i=0;c=0
while(a>0):
      i=i+1
      c=l+i
      l=c
      a-=c
      if(a<0):
        i=i-1
print(i)

def sm(n):
    return (1+n)*n/2

def main():
    n = int(raw_input())
    r = 1
    while True:
        n -= sm(r)
        if n < 0:
            print r-1
            return
        r += 1

main()

import sys
import itertools as it
import bisect as bi
import math as mt
import collections as cc
S=lambda :list(input().split())
I=lambda:list(map(int,input().split()))
n,=I()
f=lambda x:x*(x+1)//2
ar=[f(i) for i in range(100)]
for i in range(1,len(ar)):
	ar[i]+=ar[i-1]
print(bi.bisect(ar,n)-1)

def ret_input():
    data = int(raw_input())
    return data

def vac(data):
    index = 1
    total, row_sum = 0,0
    while total <= data:
        row_sum = (index *(1 + index))/2
        total += row_sum
        index += 1
    return index-2

def main():
    data = ret_input()
    #data = 100
    print vac(data)

if __name__ == '__main__':
    main()

from math import factorial as fct

def ps(n,m):
	return int(fct(n)/(fct(m)*fct(n-m)))

def cl(n):
	return ps(n+2,3)

def cdt(n):
	dt=dict()
	for x in range(n):
		x+=1
		dt[cl(x)]=x
	return dt

def dl(dt,n):
	v=list(dt.keys())
	for x in range(len(v)):
		if v[x+1] > n:
			return v[x]

dt=cdt(39)
l=dl(dt,int(input()))
print(dt[l])

l=[1]
for i in range(1,10001):
    l.append(l[i-1]+i+1)
n=int(input())
s=0
if n==1:
    print('1')
else:
    for i in range(len(l)):
        s+=l[i]
        if n<s:
            print(i)
            break

cubes = int(input())

h=0
while cubes>=0:
	h+=1
	cubes-=(h*(h+1))//2
print(h-1)

n = input()

count = 0
for i in range(1, 100000):
    count += i * (i + 1) / 2

    if count > n:
        print i - 1
        break

cubes = int(input())
if cubes == 1:
  print(1)
else:
  total = 0
  r_cube = 0
  h = 0
  for i in range(1, cubes):
    total += i
    r_cube += total
    if r_cube > cubes:
      break
    h += 1
  print(h)

n = int(input())
i = 1
total_cube = 0
while total_cube <= n:
    total_cube += (i*(i+1))//2
    i+=1
print(i-2)

n = int(input())
num = 0
num2 = 0
count = 2
while True:
    for i in range(count):
        num += i
    num2 += num
    if num2 > n:
        print(count - 2)
        break
    if num2 == n:
        print(count - 1)
        break
    num = 0
    count += 1

j = int(input())

def layers():
    n = 1
    cubes = 0
    while True:
        cubes += n
        yield cubes
        n += 1

def pyramids(total_cubes):
    for layer_num, cubes in enumerate(layers()):
        total_cubes -= cubes
        if total_cubes < 0:
            return layer_num

print(pyramids(j))

n = int(input())
x = n - 1
count = 1
y = 1
i = 2
if(n == 1):
    print('1')
else:
       while(True):
        if (x < y):
            break;
        y = y + i
        x = x - y
        i = i + 1
        if(x >= 0):
            count = count + 1
       print(count)

import math
n=int(input())
p=int(1)
t=int(1)
k=int(1)
for i in range(2,10000):
    p+=i
    k+=p
    if k>n:
        print(t)
        exit(0)
    t+=1

j = int(input())
def pyramids():
    if j == 1:
        print(1)
        return

    k = 0
    l = []

    for i in range(1, j + 1):
        k = k + i
        l.append(k)
        if k > j:
            break

    desired = 0
    i = 0
    while desired <= j:
        desired += l[i]
        i += 1

    print(i - 1)

pyramids()

cubics=int(input())
i=1
n=0
while (n<=cubics):
    n+=(i*(i+1))//2
    #print(n)
    i+=1
if(cubics==1):
    print(1)
else:
    print(i-2)

n=int(raw_input())
sum=0
i=0
while sum<=n:
    i+=1
    sum+=(i*(i+1))/2
print i-1

n = int(input())
cubesleft = n-1
floors = 1

if n <= 3:
    print(1)
else:
    for i in range(n):
        floors +=1
        sum = (((floors) * (floors+1)) / 2)
        cubesleft -= sum
        if sum > cubesleft+sum:
            floors -=1
            print(floors)
            break

x=int(raw_input())
ans=0
t=1
while(x > 0):
  ans+=t
  t+=1
  x-=t+ans
print t-1

squareNumber = int(input())
totalsum = 0
i = 0
while True:
    if(squareNumber >=1 and squareNumber <= 10**4):
        break
    else:
        print("Write the right number")
        squareNumber = int(input("Write the number of the squares"))
while (squareNumber > totalsum):
    totalsum = 0
    for sqare in range(1,i+2):
        totalsum+=sqare
    squareNumber-=totalsum
    if(squareNumber >= 0):
        i+=1
print(i)

n=int(input())
n1=0
count=0
while n>n1:
    count+=1
    count2=count
    n1 = 0
    while count2!=0:
        n1=n1+count2
        count2=count2-1
    n = n - n1
print(count)

cubes = int(input())
if cubes == 1:
  print(1)
else:
  total = 0
  h = 0
  hi = 0
  for i in range(1, cubes):
    total += i
    h += total
    if h >= cubes:
      break
    hi += 1
  print(hi+1)

n = int(input())
i = 1
c = 0
j = 0
k = 0
while j + c < n:
    c += i
    i += 1
    j += c
    k += 1
print(k)

n=int(input())
i=2
while(n>1):
  n=n//i
  i+=1
print(i-1)

bla=int(raw_input())
num=1
g=0
while g<=bla:
    g+=(num)*(num+1)/2
    num+=1
if bla!=1:
    print num-1
else:
    print 1

n = int(input())
num = 0
num2 = 0
count = 2
while True:
    for i in range(count):
        num += i
    num2 += num
    if num2 > n:
        print(count - 1)
        break
    if num2 == n:
        break
    num += count
    count += 1

n=int(input())
i=0
c=0
while n>=i:
    c=c+1
    i=i+c
    n=n-i
print(c)

a = int(input())
sum = 0
k = 0
while sum < a:
    sum = sum + k
    k += 1
print(k-1)

n=int(raw_input())
i=1
while n>0:
    t=sum(range(1,i+1))
    if t>n:
        break
    n-=t
    print t,n
    i+=1
print i-1

from math import cosh,acosh

N=float(input())
sq3=3**0.5
L=2./sq3*cosh(acosh(9*sq3*N)/3.)-1
print(int(L+0.01))

i = int(input())
s = int(0)
result = []
for x in range(1,i+1):
    if i < x:
        break
    s = s + x
    i = i -s
    result.append(s)

print(len(result))

n=int(input())
s,d,r=0,0,0
for i in range(1,n+1):
    s=s+i
    d+=s
    if(d>n):
        break
    if(d==n):
        r=r+1
        break
    r=r+1
    print(s,d,r)
print(r)

n=int(input())
k=0
h=0
while n>0:
    k=1+k+h
    h=h+1
    n=n-k
print(h)

n = int(input())
m=0
m+=n
sum = 0
count = 0
if n ==1:print(1)
else:
    for i in range(1,m):

        sum +=i
        n = n-sum
        count+=1
        if(sum> n):
            break

    print(count)

n = int(input())
cubesused = 0
cubesleft = n
floors = 1

if n <= 3:
    print(1)
else:
    for i in range(n):
        if (((floors) * (floors+1)) / 2) <= (cubesleft-(((floors) * (floors+1)) / 2)):
            floors +=1
            cubesleft -= (((floors) * (floors+1)) / 2)
        else:
            print(floors)
            break

n = int(input())
a = 1
i = 1
while n - a >= 0 and n-(a-1) >= a:
    i = i+1
    a = a+i
print(i-1)

n = int(input())
i = 0
a = 1
while (n>a):
    i += 1
    a += i
    n -= a
print(i)

n=input()
emp=0
i=1
while(True):
    emp=emp*2+i
    if emp+i>=n:
        break
    else:
        i+=1
print i

n=int(input())
lvl=0
p=0
c=1
s=0
while s<n:
    n=n-p
    p=p+c
    c=c+1
    s=s+p
   # print(p)
    lvl=lvl+1
print(lvl)

n = 60
s = 0
k = 0
i = 0

while True:

    i += 1
    k += i

    if s + k > n:
        break

    s += k

print i - 1

N = int(input())
i, ans = 1, 0
while True:
	sum = (i*(i+1))/2
	if sum <= N: ans += 1
	if sum >= N: break
	i += 1
print ans

i = 1
count,sum=1,1
n = input()
while(i<n):
    sum+=1
    count+=1
    i+=i
    i+=sum
print count

n=int(input())
i=0
while n: n-=(i*(i+1))//2; i+=1
print(i)

n = int(input())
floor = 0
x1 = 1
x2 = 0
sun = 0
if n > 0:
    while n > 0:
        x1 = x1 + x2
        sun = x1 + x2
        x1 += 1
        x2 += 1
        floor += 1
        n -= sun
    print(floor)
elif n - sun != 0:
    print(floor - 1)
else:
    print(0)

n = int(input())
i = 0
b=0
while n > i:
    i+=(1 + b)
    n-=i
    b+=1
print(b)

l=[1]
for i in range(1,10001):
    l.append(l[i-1]+i+1)
n=int(input())
for i in range(len(l)):
    if n<l[i]:
        print(i-2)
        break

a=int(input())
b=1
c=1
while b<a:
    c+=1
    b=b+b+c
print(c)

n = int(input())

ip = 0
a = 1

if n == 1:
    print(1)
elif n == 2:
    print(2)
else:
    while n > ip:
        ip = ip + (ip + a)
        a += 1

    if ip > n:
        a -= 1

    print(a)

n = int(input())
ans = 0
g = 0
for i in range(1,n):
    if i + g  < n - i - g:
        n -=(i + g)
        g +=i
        ans +=1
    else:
        break
print(ans+1)

x = input()
l = 0
m = 0
s = 0
while s <= x:
    l += 1
    m += l
    if s + m <= x:
        s += m
    else:
        print l
        exit()

try:
    x=int(input())
    q=0
    t=0
    while True:
        x=x-((q+2)*(q+1)//2)
        if x>0:
            q=q+1
        else:
            break
    print(q)
except:
    pass

i=int(input())
t=0
sumi=0
l=0
while(i>=0):
 print(i,l,t)
 l=l+1
 t=t+l
 i=i-t
print(l-1)

n = int(input())
floor = 0
x1 = 1
x2 = 0
sun = 0
if n > 0:
    while n > 0 and n >= sun:
        x1 = x1 + x2
        sun = x1 + x2
        x1 += 1
        x2 += 1
        floor += 1
        n -= sun
    print(floor)
elif n - sun != 0:
    print(floor - 1)
else:
    print(0)

n=int(input())
i=1
height=1
count=1
while i<n:
    height+=1
    i+=height
    count+=i
print(height-1 if n!=1 else 1)

n=int(input())
i=1
s=0
while(True):
    k1=i*(i+1)//2
    s+=k1
    if(s>=n):
        break
    i+=1
print(i)

def main():
    n = 2
    i = 2
    prev = 1
    x = int(input())
    while n < x:
        n = n + prev + i
        i += 1
        prev = n
    print(i - 1)

main()

def count():
    n = int(raw_input())
    num = 1
    result = 0
    height = 0
    total = []
    while sum(total) < n:
        result += num
        num += 1
        total.append(result)
        height += 1

    print height - 1

count()

def driver(f):
    n = 0
    counter = 0
    total = 0
    for i in range(1, f):
        if total+n < f:
            n += i
            total += n
            counter += 1
        else:
            break
    if f == 1:
        print(1)
    else:
        print(counter)

def main():
    for i in range(1):
        driver(int(input()))

if __name__ == "__main__":
    main()

n = int(raw_input())
#print list(range(0, n))
sum1=0
sum2 = 0
if n==1:
    print 1
elif n==2:
    print 1
else:
    for i in range(n):
        sum1 = i+sum1
        sum2 = sum2 + sum1
        #print sum1
        if n - sum2 <=0:
            print i-1
            break

print lambda n: max (x for x in xrange(100) if (x * (x + 1) * (x + 2) / 6 <= n))(input())

def sum_def(n):
    out = 0
    for i in range(1, n + 1):
        for i in range(1, i + 1):
            out += i
    return out

n = int(input())
sum_tmp = 0
c = 0

while (sum_tmp < n):
    print(sum_def(c + 2))
    sum_tmp = sum_def(c + 2)
    c += 1

print(c)

a=int(input())
sum=0
a1=1
k=1
cnt=0
while a>=0 :
    sum=sum+a1
    k=k+1
    a1=a1+k
    cnt=cnt+1
    a=a-a1
print(cnt)

n = int(raw_input())
t = 1
for k in xrange(2, n):
	g = ((k * (k + 1)) >> 1)
	if t + g <= n:
		t += g
	else: break
print t

n = int(input())
ans = 1
g = 0
if n >=4:
    for i in range(1,n):
        if i + g  < n - i - g:
            n -=(i + g)
            g +=i
            ans +=1
        else:
            break
if n <=19 and n >=4:
    print(ans - 1)
else:
    print(ans)

# n = int(input())
n = 26
a = 1
b = 0
s = 1
while a < n:
    b += a + 1
    a += b
    s += 1
print(s)

#!/usr/bin/env python

n = int(input())
count = 1
i = 1

while count < n:
    i += 1
    count += (i + 1) * (i + 2) / 2

print(i)

n = int(input())
h = 0
s = 0
sm = 0
while(sm <= n):
	h += 1
	s += h
	sm += s
	if(sm + s >= n):
		break
print(h)

l=[1]
for i in range(1,20):
    l.append(l[i-1]+i+1)
n=int(input())
s=0
if n==1:
    print('1')
else:
    for i in range(len(l)):
        s+=l[i]
        if n<s:
            print(i)
            break

n=int(input())
a=2
c=0
if n>1:
	d=1
	l=[]
	for i in range(1,n+1):
		if n>=sum(l):

			# print(d)
			# print(d,a,c)
			c+=1
			d+=a
			a+=1
			l.append(d)
	print(c)
elif n==1:
	print(1)
else:
	print(0)

import sys
def main():
    n = int(input()) + 1
    a = [0] * n
    _sum = 0
    for i in range(1, n):
        a[i] = a[i - 1] + i
        _sum += a[i]
        if(_sum > n):
            print(i - 1)
            return
        if(_sum == n - 1):
            print(i)
            return

if __name__ == "__main__":
    sys.exit(main())

n=int(input())
s,d,r=0,0,0
for i in range(1,n+1):
    s=s+i
    d+=s
    if(d>n):
        break
    if(d==n):
        r=r+1
        break
    r=r+1
    print(s,d,r)
print(r)

n=int(raw_input())
count =0
level=1
while (level<=n):
    count +=1
    n= n - level
    level=(count+1)/2.0*(1+count)

print count

# -*- coding: utf-8 -*-
"""
Created on Mon Mar 16 12:54:40 2020

@author: DELL
"""
n=int(input())
c=0
s=0
u=0
if n!=1 and n!=2:
    for i in range(1,n+1):
        s+=i
        u+=s
        c+=1
        if u>n:
            print(c-1)
            break
        elif u==n:
            print(c)
            break
else:
    print(n)

n=int(raw_input())
i=1
while n>0:
    t=sum(range(1,i+1))
    if t>n:
        break
    n-=t
    print t,n
    i+=1
print i-1

x = int(input())

r = 0

for i in xrange(1, x):
	r += 1 + 2 + (i - 1) + i

	if r > x:
		print i
		exit(0)

print 1

target = int(input())
sum = 1
passer = 0
flag = 0
while sum < target:
    passer = sum
    sum += 1
    sum += passer
    flag += 1
print(flag)

x=int(input())
p=1
c=0
s=0
i=2
while x>=1:
    c+=1
    x=x-p

    p=p+i
    i=i+1

if(c>1):
    print(c-1)
else:
    print(c)

x=int(input())
p=1
c=0
s=0
i=2
while x>=1:
    c+=1
    x=x-p

    p=p+i
    i=i+1

if(c>3):
    print(c-1)
else:
    print(c)

n = int(input())
i = 1
py = 0
count = 0
if n == 1:
    print("1")
else:
    while(1):
        py += i
        i += 2
        if py >= n:
            break;
        count += 1
    print(count)

a = int(input())
b = a
caunt = [0]
caunt2 = 0
while a > sum(caunt):
    caunt.extend(caunt)
    caunt.append(caunt[-1] + 1)
    caunt2 += 1
print(caunt2)

x = int(input())
p = 0
d = 0
j = 0
for i in range(1,x+1):
        p = p+i
        if (d+p)<x:
            d+=p
            j+=1
        elif x>11:
            print(j+1)
        else:
            print(j)
            break

n=int(input())
i=0
s=0
while(True):
    k1=i*(i+1)//2
    s+=k1
    if(s>=n):
        break
    i+=1
print(i)

c=int(input())
k=0
for i in range(1,c):
    s=0
    for j in range(1,i+1):
        s=s+j

    k=s+k

    if(k>=c):
        print(i-1)
        break

n = int(input())
a = 0
count = 0
while a <= n:
	count += 1
	a += count
	print(a)
print(count - 1)

n =int(input())
count = 0
level = 0
while n > level and n - level >= level:
    count+=1
    level = level + count
    n = n - level
print(count)

n=int(input())
s=0
v=0
i=0
while(v<n):
    s=s+i
    v=v+s
    i=i+1
print(i-1)

l=[1]
for i in range(1,10001):
    l.append(l[i-1]+i+1)
n=int(input())
for i in range(len(l)):
    if n<l[i]:
        print(i-2)
        break

num_of_cubes = int(input())
last_cubes = 1
stage = 1
cubes = 1
while num_of_cubes >= cubes + last_cubes + 1:
    stage += 1
    cubes += last_cubes + 1
    last_cubes += 1
print(stage)

x=int(input())
p=1
c=0
s=0
i=2
while x>=1:
    x=x-p
    p=p+i
    i=i+1
    c+=1

if(c>1):
    print(c-1)
else:
    print(c)

n = int(input())
x = 1
while n > sum(range(x+1)):
    x += 1
if n == sum(range(x+1)):
    print(x)
else:
    print(x-1)

n = int(input())
cubesused = 0
cubesleft = n
floors = 1

if n <= 3:
    print(1)
else:
    for i in range(n):
        if (((floors) * (floors+1)) / 2) <= cubesleft:
            floors +=1
            cubesleft -= (((floors) * (floors+1)) / 2)
        else:
            print(floors-1)
            break

n = int(input())
count = 0
result = 0
ls = []
for i in range(1,n+1):
    ls.append(i)
    result += sum(ls)
    if result >= n:
        break
    count+=1
if count == 0:
    count += 1
print(count)

n = int(input())

i = 1

while n > i :
    n //= i
    i +=1

print(i)

x=int(input())
i=0
k=1
c=0
while x-i>0:
    i=i+k
    x=x-i
    c=c+1
    k=k+1
print (c)

n=int(input())
n_y=1
yr=1
while n>n_y:
    yr=yr+1
    n_y=n_y+yr
    n=n-n_y
    if n<0:
        yr-=1
print(yr)

cube = int(input())
m = 0
k = 1

while True:
  m += k
  m +=m
  if m>=cube:
      break
  k += 1

print(k)

a=int(input())
k=1
r=0
while a>k:
    a-=k
    k+=(k+1)
    r+=1
print(r)

n = int(input())
i = 0
b=0
while n > i+(1 + b):
    i+=(1 + b)
    n-=i
    b+=1
print(b)

n = int(input())

ip = 0
a = 1

if n == 1:
    print(1)
else:
    while n > ip:
        ip1 = ip
        ip = ip + (ip + a)
        a += 1

    if ip > n:
        a -= 1
    print(a)

n = int(input())
a = 0
count = 0
while a <= n:
	count += 1
	a += count
	print(a)
print(count - 1)

blocks=int(input())
for i in range(1,999):
    summation = 0
    for a in range(1,i+1):
        summation +=a
    blocks-=summation
    if blocks <= 0:
        i-=1
        break
print(i)

n=int(input())
if n==1:
    print(n)
else:
    i=0
    ch=1
    while n>ch:
        i+=1
        ch+=i
        n-=ch
    print(i)

n = int(input())
digits=list(str(n))

cond=0

luckylist=[]
for i in range(1,1000):
    rm4=str(i).replace('4','')
    rm47=rm4.replace('7','')
    if (not rm47):
        luckylist.append(i)

for j in range(len(luckylist)):
    if n%luckylist[j]==0:
        cond+=1
    else:
        continue

if cond>0:
    print('YES')
else:
    print('NO')

# if it could be evenly divided by some lucky number.

squareNumber = int(input())
totalsum = 0
i = 0
while True:
    if(squareNumber >=1 and squareNumber <= 10**4):
        break
    else:
        print("Write the right number")
        squareNumber = int(input("Write the number of the squares"))
while (squareNumber > totalsum):
    totalsum = 0
    for sqare in range(1,i+2):
        totalsum+=sqare
    squareNumber-=totalsum
    if(squareNumber > 0):
        i+=1
print(i)

l=[1]
for i in range(1,20):
    l.append(l[i-1]+i+1)
n=int(input())
if n==1:
    print('1')
else:
    for i in range(len(l)):
        if n<l[i]:
            print(i-2)
            break

x = int(input())
p = 0
d = 0
j = 0
for i in range(1,x+1):
        p = p+i
        if (d+p)<x:
            d+=p
            j+=1
        elif x>11:
            print(j+1)
        else:
            print(j)
            break

n=int(input())
i=1
height=1
count=1
while i<n:
    height+=1
    i+=height
    count+=i
print(height-1 if n!=1 else 1)

def main():
    n = int(input())
    total_cubes = 0
    q = 0
    while total_cubes <= n:
        q += 1
        total_cubes += (q * q+1) // 2
    print(q - 1)

if __name__ == "__main__":
    main()