Problem:


Space Coconut Crab

宇宙ヤシガニ

English text is not available in this practice contest.

ケン・マリンブルーは，宇宙ヤシガニを求めて全銀河を旅するスペースハンターである．宇宙ヤシガニは，宇宙最大とされる甲殻類であり，成長後の体長は 400 メートル以上，足を広げれば 1,000 メートル以上にもなると言われている．既に多数の人々が宇宙ヤシガニを目撃しているが，誰一人として捕らえることに成功していない．

ケンは，長期間の調査によって，宇宙ヤシガニの生態に関する重要な事実を解明した．宇宙ヤシガニは，驚くべきことに，相転移航法と呼ばれる最新のワープ技術と同等のことを行い，通常空間と超空間の間を往来しながら生きていた．さらに，宇宙ヤシガニが超空間から通常空間にワープアウトするまでには長い時間がかかり，またワープアウトしてからしばらくは超空間に移動できないことも突き止めた．

そこで，ケンはついに宇宙ヤシガニの捕獲に乗り出すことにした．戦略は次のとおりである．はじめに，宇宙ヤシガニが通常空間から超空間に突入する際のエネルギーを観測する．このエネルギーを e とするとき，宇宙ヤシガニが超空間からワープアウトする座標 (x, y, z) は以下の条件を満たすことがわかっている．

x, y, z はいずれも非負の整数である．

x + y2 + z3 = e である．

上記の条件の下で x + y + z の値を最小にする．

これらの条件だけでは座標が一意に決まるとは限らないが，x + y + z の最小値を m としたときに，ワープアウトする座標が平面 x + y + z = m 上にあることは確かである．そこで，この平面上に十分な大きさのバリアを張る．すると，宇宙ヤシガニはバリアの張られたところにワープアウトすることになる．バリアの影響を受けた宇宙ヤシガニは身動きがとれなくなる．そこをケンの操作する最新鋭宇宙船であるウェポン・ブレーカー号で捕獲しようという段取りである．

バリアは一度しか張ることができないため，失敗するわけにはいかない．そこでケンは，任務の遂行にあたって計算機の助けを借りることにした．あなたの仕事は，宇宙ヤシガニが超空間に突入する際のエネルギーが与えられたときに，バリアを張るべき平面 x + y + z = m を求めるプログラムを書くことである．用意されたテストケースの全てに対して正しい結果を出力したとき，あなたのプログラムは受け入れられるであろう．

Input

入力は複数のデータセットで構成される．各データセットは 1 行のみからなり，1 つの正の整数 e (e ≦ 1,000,000) が含まれる．これは，宇宙ヤシガニが超空間に突入した際のエネルギーを表す．入力は e = 0 の時に終了し，これはデータセットには含まれない．

Output

各データセットについて，m の値を 1 行に出力しなさい．出力には他の文字を含めてはならない．

Sample Input

1
2
4
27
300
1250
0

Output for the Sample Input

1
2
2
3
18
44



Sample input:
1
2
4
27
300
1250
0


Sample output:
1
2
2
3
18
44

Submission status: Runtime Error

Solution code:
ans_list = []

while True:
    e = int(input())
    if e == 0:
        break
    else:
        ans = float('inf')
        for z in range(e+1):
            z3 = z ** 3
            if z3 <= e:
                for y in range(e-z3+1):
                    y2 = y ** 2
                    if y2 <= e - z3:
                        x = e - z3 - y2
                        s = x + y + z
                        if s < ans:
                            ans = s
                    else:
                        break
            else:
                break
        ans_list.append(ans)

for x in ans_list:
    print(x)

Submission status: Runtime Error

Solution code:
ans_list = []

while True:
    e = int(input())
    if e == 0:
        break
    else:
        ans = float('inf')
        for z in range(e+1):
            z3 = z ** 3
            if z3 <= e:
                for y in range(e-z3+1):
                    y2 = y ** 2
                    if y2 <= e - z3:
                        x = e - z3 - y2
                        s = x + y + z
                        if s < ans:
                            ans = s
                    else:
                        break
            else:
                break
        print(ans)

Submission status: Runtime Error

Solution code:
flag = True

while flag:
    e = int(input())
    if e == 0:
        flag = False
    else:
        ans = float('inf')
        for z in range(e+1):
            z3 = z ** 3
            if z3 <= e:
                for y in range(e-z3+1):
                    y2 = y ** 2
                    if y2 <= e - z3:
                        x = e - z3 - y2
                        s = x + y + z
                        if s < ans:
                            ans = s
                    else:
                        break
            else:
                break
        print(ans)

Submission status: Runtime Error

Solution code:
while True:
    e = int(input())
    if e == 0:
        break
    else:
        ans = float('inf')
        for z in range(e+1):
            z3 = z ** 3
            rest1 = e - z3
            if rest1 >= 0:
                for y in range(rest1+1):
                    y2 = y ** 2
                    rest2 = rest1 - y2
                    if rest2 >= 0:
                        s = rest2 + y + z
                        if s < ans:
                            ans = s
                    else:
                        break
            else:
                break
        print(ans)

Submission status: Runtime Error

Solution code:
while True:
    e = int(input())
    if e != 0:
        ans = float('inf')
        for z in range(e):
            r1 = e - z ** 3
            if r1 >= 0:
                for y in range(r1+1):
                    x = r1 - y ** 2
                    if x >= 0:
                        s = z + y + x
                        if ans > s:
                            ans = s
                        else:
                            pass
                    else:
                        break
            else:
                break
        print(ans)
    else:
        break

Submission status: Runtime Error

Solution code:

l = []
ans_list = []

while True:
    e = int(input())
    if e == 0:
        #print('=========================')
        break
    else:
        l.append(e)

for e in l:
    ans = float('inf')
    for z in range(e):
        r1 = e - z ** 3
        if r1 >= 0:
            for y in range(r1+1):
                x = r1 - y ** 2
                if x >= 0:
                    s = z + y + x
                    ans = min(ans, s)
                else:
                    break
        else:
            break
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Submission status: Runtime Error

Solution code:
while(1):
    e = int(input())
    if e == 0:
        break
    m = e
    for z in range(100):
        for y in range(1000):
            x = e - y * y - z * z * z
            if 0 > x:
                break
            if m > x + y + z:
                m = x + y + z
    print(m)

Submission status: Runtime Error

Solution code:
while True:
    e = int(raw_input())
 
    if e == 0:
        break

    ans = float('inf')

    for z in range(10**2+1):
        for y in range(10**3+1):
            if y**2 + z**3 <= e:
                x = e - y**2 - z**3
                ans = min(ans, x+y+z)

    print ans

Submission status: Runtime Error

Solution code:
while True:
    e = int(raw_input())
 
    if e == 0:
        break

    ans = 1e8

    for z in range(10**2+1):
        for y in range(10**3+1):
            if y**2 + z**3 <= e:
                x = e - y**2 - z**3
                ans = min(ans, x+y+z)

    print ans

Submission status: Runtime Error

Solution code:
while True:
    e = int(raw_input())
 
    if e == 0: break

    ans = 1e8

    for z in range(10**2+1):
        for y in range(10**3+1):
            if y**2 + z**3 > e:
                break
            x = e - y**2 - z**3
            ans = min(ans, x+y+z)

    print ans

Submission status: Runtime Error

Solution code:
while True:
    e = int(raw_input())
 
    if e == 0: break

    ans = 1e8

    x, y, z = 0, 0, 0

    for z in range(e):
        if z**3 > e: break
        for y in range(e):
            if y**2 + z**3 > e: break
            x = e - y**2 - z**3
            ans = min(ans, x+y+z)

    print ans

Submission status: Runtime Error

Solution code:
while True:
    e = int(raw_input())
 
    if e == 0: break

    x, y, z, ans = 0, 0, 0, e

    for z in range(e):
        if z**3 > e: break
        for y in range(e):
            if y**2 + z**3 > e: break
            x = e - y**2 - z**3
            ans = min(ans, x+y+z)

    print ans

Submission status: Runtime Error

Solution code:
from math import sqrt

while True:
    e = int(raw_input())
 
    if e == 0: break

    x, y, z, ans = 0, 0, 0, e

    for z in range(e):
        if z**3 > e: break
        y = int(sqrt(e - z**3))
        x = e - y**2 - z**3
        ans = min(ans, x+y+z)

    print ans

Submission status: Runtime Error

Solution code:
from math import sqrt
 
while True:
    e = int(raw_input())
  
    if e == 0: break
 
    x, y, z, ans = 0, 0, 0, e
 
    for z in range(e+1):
        if z**3 > e: break
        y = int(sqrt(e - z**3))
        x = e - y**2 - z**3
        ans = min(ans, x+y+z)
 
    print ans

Submission status: Runtime Error

Solution code:
from math import sqrt

while True:
    e = int(raw_input())

    if e == 0: break

    z, ans = 0, e

    for z in range(e+1):
        if z**3 > e: break
        y = int(sqrt(e - z**3))
        x = e - y**2 - z**3
        ans = min(ans, x+y+z)

    print ans

Submission status: Runtime Error

Solution code:
from math import sqrt

while True:
    e = int(raw_input())
    if e == 0: break

    ans = e

    for z in range(e):
        if z**3 > e: break
        y = int(sqrt(e - z**3))
        x = e - y**2 - z**3
        ans = min(ans, x+y+z)

    print ans

Submission status: Runtime Error

Solution code:
from math import floor

while True:
    e = int(input())
    if e == 0:
        break

    ans = 10 ** 10
    for z in range(floor(e ** (1 / 3)) + 1):
        for y in range(floor((e - z) ** (1 / 2)) + 1):
            x = e - y ** 2 - z ** 3
            if x < 0:
                continue
            ans = min(ans, x + y + z)
    print (ans)

Submission status: Runtime Error

Solution code:
from math import floor

while True:
    e = int(input())
    if e == 0:
        break

    ans = 10 ** 10
    for z in range(floor(e ** (1 / 3)) + 1):
        ez = e - z ** 3
        if ez < 0:
            break
        for y in range(floor(ez ** (1 / 2)) + 1):
            x = ez - y ** 2
            if x < 0:
                break
            ans = min(ans, x + y + z)
    print (ans)

Submission status: Runtime Error

Solution code:
import math

def main():
    while True:
        e = int(input())
        if e == 0:
            break

        p = 0
        cs = list(reversed(range(math.floor(e**(1/3))+1)))
        bs = list(reversed(range(math.floor(e**(1/2))+1)))
        for c in cs:
            for b in bs:
                if c**3+b**2<e and c**3+b**2>p:
                    r = c+b
                    p = c**3+b**2
                if c**3+b**2<p:
                    break
        print(r+e-p)

main()

Submission status: Runtime Error

Solution code:
import math
while True:
  e=int(input())
  if e==0: break
  m=e
  A=[]
  for z in range(e+1):
    y=0
    while y**2+z**3<=e:
      d=z**3+y**2
      A.append(e-d+y+z)
      y+=1
  print(min(A))

Submission status: Runtime Error

Solution code:
import math

def main():
    while True:
        e = int(input())
        if e == 0: break

        r = 0
        p = 0
        cs = list(reversed(range(math.floor(e**(1/3))+1)))
        bs = list(reversed(range(math.floor(e**(1/2))+1)))
        if e**(1/3) <= 1:
            cs = [0]
        if e**(1/2) <= 1:
            bs = [0]
        for c in cs:
            for b in bs:
                if c**3+b**2<=e and c**3+b**2>p:
                    r = c+b
                    p = c**3+b**2
        print(r+e-p)
main()

Submission status: Runtime Error

Solution code:
while 1:
  n=int(input())
  if not n:break
  m=n
  for z in range(int(n**(1/3))+1):
    for y in range(int((n-z**3)**(1/2))+1):
      x=n-y**2-z**3
      m=min(m,x+y+z)
  print(m)

Submission status: Runtime Error

Solution code:
import sys
d = [[0,0,1], [0,1,0], [1,0,0]]
def cal(x,y,z):
        global e,l,ans
        if x+y+z >= ans: return
        #print sys.stderr, x,y,z
        temp = x+y**2+z**3
        l.append([x,y,z])
        if temp == e:
                #print sys.stderr, x,y,z
                ans = x+y+z
        elif temp < e:
                for i in xrange(3):
                        if not([x+d[i][0], y+d[i][1], z+d[i][2]] in l):
                                cal(x+d[i][0], y+d[i][1], z+d[i][2])
                
while 1:
        e = int(raw_input())
        if not e: break
        ans = 10*6
        l = []
        cal(0,0,0)
        print ans

Submission status: Runtime Error

Solution code:
import sys
def cal(e):
        global ans
        x,y,z = 0,0,0
        while (z**3 <= e):
                y = 0
                while (y**2 <= e-z**3):
                        x = e-z**3-y**2
                        ans = min(x+y+z, ans)
                        #print sys.stderr, x,y,z
                        y += 1
                z += 1
                
while 1:
        e = int(raw_input())
        if not e: break
        ans = 10*6
        cal(e)
        print ans

Submission status: Runtime Error

Solution code:
import sys
import collections
import math

while True:
    e = int(sys.stdin.readline())
    if e == 0:
        break
    result = 1000000
    for z in xrange(int(math.pow(e, 1.0/3)), -1, -1):
        for y in xrange(int(math.pow(e - math.pow(z, 3), 1.0 / 2)), -1, -1):
            x = e - math.pow(z, 3) - math.pow(y, 2)
            result = min(result, int(x + y + z))
    print result

Submission status: Runtime Error

Solution code:
import sys
import math

while True:
    e = int(sys.stdin.readline())
    if e == 0:
        break
    result = 1000000
    for z in xrange(int(math.pow(e, 1.0/3)), -1, -1):
        for y in xrange(int(math.pow(e - math.pow(z, 3), 1.0 / 2)), -1, -1):
            x = e - math.pow(z, 3) - math.pow(y, 2)
            if x < 0:
                continue
            result = min(result, int(x + y + z))
    print result

Submission status: Runtime Error

Solution code:
import sys
import math

while True:
    e = int(sys.stdin.readline())
    if e == 0:
        break
    result = 1000000
    for z in xrange(int(math.pow(e, 1.0/3)), -1, -1):
        for y in xrange(int(math.pow(e - math.pow(z, 3), 1.0 / 2)), -1, -1):
            x = e - math.pow(z, 3) - math.pow(y, 2)
            if x < 0:
                continue
            #result = min(result, int(x + y + z))
    print result

Submission status: Runtime Error

Solution code:
import sys
import math

while True:
    e = int(sys.stdin.readline())
    if e == 0:
        break
    result = 1000000
    for z in xrange(int(math.pow(e, 1.0/3)), -1, -1):
        for y in xrange(int(math.pow(e - math.pow(z, 3), 1.0 / 2)), -1, -1):
            #x = e - math.pow(z, 3) - math.pow(y, 2)
            if x < 0:
                continue
            #result = min(result, int(x + y + z))
    print result

Submission status: Runtime Error

Solution code:
import sys
import math

while True:
    e = int(sys.stdin.readline())
    if e == 0:
        break
    result = 1000000
    for z in xrange(int(math.pow(e, 1.0/3)), -1, -1):
        for y in xrange(int(math.pow(e - math.pow(z, 3), 1.0 / 2)), -1, -1):
            x = e - math.pow(z, 3) - math.pow(y, 2)
            #if x < 0:
            #    continue
            #result = min(result, int(x + y + z))
    print result

Submission status: Runtime Error

Solution code:
import sys
import math

while True:
    e = int(sys.stdin.readline())
    if e == 0:
        break
    result = 1000000
    for z in xrange(int(math.pow(e, 1.0/3)), -1, -1):
        if z < 0:
            continue
        for y in xrange(int(math.pow(e - math.pow(z, 3), 1.0 / 2)), -1, -1):
            if y < 0:
                continue
            x = e - math.pow(z, 3) - math.pow(y, 2)
            if x < 0:
                continue
            result = min(result, int(x + y + z))
    print result

Submission status: Runtime Error

Solution code:
import sys
import math

while True:
    e = int(sys.stdin.readline())
    if e == 0:
        break
    result = 10000000
    for z in xrange(int(math.pow(e, 1.0/3)), -1, -1):
        if z < 0 or e - math.pow(z, 3) < 0:
            continue
        for y in xrange(int(math.pow(e - math.pow(z, 3), 1.0 / 2)), -1, -1):
            if y < 0:
                continue
            x = e - math.pow(z, 3) - math.pow(y, 2)
            if x < 0:
                continue
            result = min(result, int(x + y + z))
    print result

Submission status: Runtime Error

Solution code:
import sys
import math

while True:
    e = int(sys.stdin.readline())
    if e == 0:
        break
    result = 10000000
    for z in xrange(1000001):
        if z ** 3 > e:
            break
        for y in xrange(1000001):
            if z ** 3 + y ** 2 > e:
                break
            x = e - z ** 3 - y ** 2
            result = min(result, int(x + y + z))
    print result

Submission status: Runtime Error

Solution code:
while True:
    e=input()
    if e==0:break
    minInt=1e10
    for z in range(100,-1,-1):
        for y in range(1000,-1,-1):
            if e-(y*y+z*z*z)>=0:
                minInt=min(minInt,y+z+e-(y*y+z*z*z))
    print minInt

Submission status: Runtime Error

Solution code:
eList = []
while 1:
	e = input()
	if e == 0:
		break;
	else:
		mini = 10000
		for x in range(100):
			for y in range(100):
				for z in range(10):
					if x + y*y + z*z*z == e:
						a = x + y + z
						if a < mini:
							mini = x + y + z
		print mini

Submission status: Runtime Error

Solution code:
eList = []
while 1:
	e = input()
	if e == 0:
		break;
	else:
		mini = 10000
		for x in range(1000000):
			for y in range(1000):
				for z in range(100):
					if x + y*y + z*z*z == e:
						a = x + y + z
						if a < mini:
							mini = x + y + z
		print mini

Submission status: Runtime Error

Solution code:
eList = []
while 1:
	e = input()
	if e == 0:
		break;
	else:
		mini = 10000000
		for x in range(100):
			for y in range(100):
				for z in range(100):
					if x + y*y + z*z*z == e:
						a = x + y + z
						if a < mini:
							mini = x + y + z
		print mini

Submission status: Runtime Error

Solution code:
eList = []
while 1:
	e = input()
	if e == 0:
		break;
	else:
		mini = 10000000
		for x in range(1000000):
			for y in range(1000):
				for z in range(100):
					if x + y*y + z*z*z == e:
						a = x + y + z
						if a < mini:
							mini = x + y + z
		print mini

Submission status: Runtime Error

Solution code:
while 1:
	e = input()
	if e == 0:
		break;
	else:
		mini = 10000000
		for z in range(100):
			for y in range(1000):
					x = e - y*y - z*z*z
					if x >= 0:
						if x + y + z < mini:
							mini = x + y + z
		print mini

Submission status: Runtime Error

Solution code:
while 1:
	e = input()
	if e == 0:
		break;
	else:
		mini = 1000000
		for z in range(100):
			for y in range(1000):
					x = e - y*y - z*z*z
					if x >= 0:
						if x + y + z < mini:
							mini = x + y + z
		print mini

Submission status: Runtime Error

Solution code:
while 1:
	e = input()
	if e == 0: 
		break;
	else:
		mini = 1000000
		for z in range(100):
			if z*z*z > e: break
			for y in range(1000):
				x = e - y*y - z*z*z
				if x >= 0:
					if x + y + z < mini:
						mini = x + y + z
				else:
					break
		print mini

Submission status: Runtime Error

Solution code:
while 1:
	e = input()
	if e == 0: 
		break;
	else:
		mini = 1000000
		for z in range(101):
			if z*z*z > e: break
			for y in range(1001):
				x = e - y*y - z*z*z
				if x >= 0:
					if x + y + z < mini:
						mini = x + y + z
				else:
					break
		print mini

Submission status: Runtime Error

Solution code:
while 1:
    e = input()
    if e==0 : break
    m = 1<<30
    z = 0
    while z*z*z <= e:
        y = 0
        while y*y + z*z*z <= e:
            x = e - z*z*z - y*y
            m = min(m, x+y+z)
            y+=1
        z+=1
    print m

Submission status: Runtime Error

Solution code:
while 1:
	e = input()
	if e == 0: break
	ans = 3*e
	for z in range(e+1):
		z3 = z**3
		if z3 > e: break
		for y in range(e+1):
			y2 = y**2
			x = e - y2 - z3
			if x >= 0:
				ans = min(ans,x+y+z)
			else:
				break
	print ans

Submission status: Runtime Error

Solution code:
while 1:
	e = input()
	if e == 0: break
	ans = 3*e
	for z in range(e+1):
		z3 = z**3
		if z3 > e: break
		for y in range(e+1):
			x = e - y**2 - z3
			if x >= 0:
				ans = min(ans,x+y+z)
			else:
				break
	print ans

Submission status: Runtime Error

Solution code:
while 1:
	e = ans = input()
	if e == 0: break
	for z in range(e):
	    z3 = z**3
		if z3 > e: break
		y = int((e-z3)**0.5)
		ans = min(ans,e+y+z-y**2-z3)
	print ans