Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2**16)


def getfly(x,a,m,i):
        if x==1 and i!=0:
            return i
        else:
            return getfly((a*x)%m,a,m,i+1)

def getgcd(a,b):
    #print a,b
    (a,b)=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        return getgcd(b,a%b)

while(1):
    indata=[int(x) for x in raw_input().split()]
    if indata[0]==0:
        break
    else:
        a=indata[0::2]
        m=indata[1::2]
        A=[]
        for i in range(3):
            A.append(getfly(1,a[i],m[i],0))
        #print A
        gab=getgcd(A[0],A[1])
        lab=A[0]*A[1]/gab
        gac=getgcd(A[2],lab)
        ans=A[2]*lab/gac
        print ans

Fixed submission:
def getfly(x,a,m,i):
        if x==1 and i!=0:
            return i
        else:
            return getfly((a*x)%m,a,m,i+1)

def getgcd(a,b):
    #print a,b
    (a,b)=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        return getgcd(b,a%b)

while(1):
    indata=[int(x) for x in raw_input().split()]
    if indata[0]==0:
        break
    else:
        a=indata[0::2]
        m=indata[1::2]
        A=[]
        for j in range(3):
            i=0
            x=1
            p=a[j]
            q=m[j]
            while (x!=1 or i==0):
                i+=1
                x=p*x%q
            A.append(i)
        gab=getgcd(A[0],A[1])
        lab=A[0]*A[1]/gab
        gac=getgcd(A[2],lab)
        ans=A[2]*lab/gac
        print ans
Buggy python submission (verdict: Time Limit Exceeded):
def fun(f,i,sw):
    ret=[]
    for s in sw:
        ii,ss=min(i,s),max(i,s)
        ret.append( f[:ii]+f[ss]+f[ii+1:ss]+f[ii]+f[ss+1:])
    return ret

swaplist=[[1,4],[0,2,5],[1,3,6],[2,7],[0,5],[4,6,1],[5,7,2],[6,3]]
A={}
A[1234567]=0
ks=[1234567]
F=["01234567"]
n=0
while len(F)!=0:
    NF=[]
    n+=1
    for f in F:
        i=f.index('0')
        sw=swaplist[i]
        for g in fun(f,i,sw):
            if int(g) not in ks:
                A[int(g)]=n
                ks.append(int(g))
                NF.append(g)
    F=NF[:]
while(1):
    try:
        print A[int("".join(raw_input().split()))]
    except:
        break

Fixed submission:
import bisect as bs

def fun(f,i,sw):
    ret=[]
    for s in sw:
        ii,ss=min(i,s),max(i,s)
        ret.append( f[:ii]+f[ss]+f[ii+1:ss]+f[ii]+f[ss+1:])
    return ret

def exist(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bs.bisect_left(a, x)
    try:
        if i != len(a) and a[i] == x:
            return 1
    except:
        return 0

swaplist=[[1,4],[0,2,5],[1,3,6],[2,7],[0,5],[4,6,1],[5,7,2],[6,3]]
A={}
A[1234567]=0
ks=[1234567]
F=["01234567"]
n=0
while len(F)!=0:
    NF=[]
    n+=1
    for f in F:
        i=f.index('0')
        sw=swaplist[i]
        for g in fun(f,i,sw):
            ig=int(g)
            if not exist(ks,ig):
                A[ig]=n
                bs.insort(ks,ig)
                NF.append(g)
    F=NF[:]
while(1):
    try:
        print A[int("".join(raw_input().split()))]
    except:
        break
Buggy python submission (verdict: Time Limit Exceeded):
while(1):
    [n,m]=[int(x) for x in raw_input().split()]
    if n==0:
        break
    else:
        C=[[9999 for x in range(m+1)] for y in range (m+1)]
        T=[[9999 for x in range(m+1)] for y in range (m+1)]
        for i in range(n):
            [a,b,c,t]=[int(x) for x in raw_input().split()]
            C[a][b]=c
            C[b][a]=c
            T[a][b]=t
            T[b][a]=t
        for i in range(1,m+1):
            C[i][i]=0
            T[i][i]=0
        for k in range(1,m+1):
            for i in range(1,m+1):
                for j in range(1,m+1):
                    if C[i][j]>C[i][k]+C[k][j]:
                        C[i][j]=C[i][k]+C[k][j]
                    if T[i][j]>T[i][k]+T[k][j]:
                        T[i][j]=T[i][k]+T[k][j]
        Q=int(raw_input())
        for i in range(Q):
            [p,q,r]=[int(x) for x in raw_input().split()]
            if r:
                print T[p][q]
            else:
                print C[p][q]

Fixed submission:
while(1):
    [n,m]=[int(x) for x in raw_input().split()]
    if n==0:
        break
    else:
        C=[[9999 for x in range(m+1)] for y in range (m+1)]
        T=[[9999 for x in range(m+1)] for y in range (m+1)]
        for i in range(n):
            [a,b,c,t]=[int(x) for x in raw_input().split()]
            C[a][b]=c
            C[b][a]=c
            T[a][b]=t
            T[b][a]=t
        for i in range(1,m+1):
            C[i][i]=0
            T[i][i]=0
        for k in range(1,m+1):
            for i in range(1,m+1):
                for j in range(i,m+1):
                    if C[i][j]>C[i][k]+C[k][j]:
                        C[i][j]=C[i][k]+C[k][j]
                        C[j][i]=C[i][k]+C[k][j]
                    if T[i][j]>T[i][k]+T[k][j]:
                        T[i][j]=T[i][k]+T[k][j]
                        T[j][i]=T[i][k]+T[k][j]
        Q=int(raw_input())
        for i in range(Q):
            [p,q,r]=[int(x) for x in raw_input().split()]
            if r:
                print T[p][q]
            else:
                print C[p][q]
Buggy python submission (verdict: Runtime Error):
while(1):
    [X,Y]=[int(x) for x in raw_input().split()]
    if X==0:
        break
    else:
        F=[]
        for i in range(Y):
            F.append([0]+[int(x) for x in raw_input().split()]+[0])
        F.append([3 for x in range(X+2)])
        S=[[0 for x in range(X+2)] for y in range(Y+1)] #F,S[y][x]
        
        #initilizing
        for i in range(1,X+1):
            S[0][i]=1-F[0][i]
        for j in range(Y+1):
            for i in range(1,X+1):
                if F[j][i]==2:
                    S[j][i]=S[j][i]+S[j-1][i]
                    S[j+2][i]=S[j+2][i]+S[j][i]
                elif F[j][i]==1:
                    S[j][i]=0
                elif F[j][i]==3:
                    S[j][i]=S[j][i]+S[j-1][i]
                else:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]+(1-F[j-1][i-1]/2)*S[j-1][i-1]+(1-F[j-1][i+1]/2)*S[j-1][i+1]
        print sum(S[Y])

Fixed submission:
while(1):
    [X,Y]=[int(x) for x in raw_input().split()]
    if X==0:
        break
    else:
        F=[]
        for i in range(Y):
            F.append([0]+[int(x) for x in raw_input().split()]+[0])
        F.append([3 for x in range(X+2)])
        F.append([4 for x in range(X+2)])        
        S=[[0 for x in range(X+2)] for y in range(Y+2)] #F,S[y][x]
        #initilizing
        for i in range(1,X+1):
            S[0][i]=1-F[0][i]
        for j in range(Y+2):
            for i in range(1,X+1):
                if F[j][i]==2:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]
                    S[j+2][i]=S[j+2][i]+S[j][i]
                elif F[j][i]==1:
                    S[j][i]=0
                elif F[j][i]==3:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]
                elif F[j][i]==4:
                    S[j][i]=S[j][i]+S[j-1][i]                    
                else:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]+(1-F[j-1][i-1]/2)*S[j-1][i-1]+(1-F[j-1][i+1]/2)*S[j-1][i+1]
        print sum(S[Y+1])
Buggy python submission (verdict: Runtime Error):
while(1):
    [m,n]=[int(x) for x in raw_input().split()]
    if m==0:
        break
    else:
        truenum=0
        player=[x for x in range(1,m+1)]
        for i in range(n):
            if len(player)>1:
                shout=raw_input()
                pnow=player.pop(0)
                truenum=truenum+1
                if truenum%15==0:
                    if shout=="FizzBuzz":
                        player.append(pnow)
                elif truenum%5==0:
                    if shout=="Buzz":
                        player.append(pnow)
                elif truenum%3==0:
                    if shout=="Fizz":
                        player.append(pnow)
                else:
                    if shout==str(truenum):
                        player.append(pnow)
        print " ".join([str(x) for x in sorted(player)])

Fixed submission:
while(1):
    [m,n]=[int(x) for x in raw_input().split()]
    if m==0:
        break
    else:
        truenum=0
        player=[x for x in range(1,m+1)]
        for i in range(n):
            shout=raw_input()
            if len(player)>1:
                pnow=player.pop(0)
                truenum=truenum+1
                if truenum%15==0:
                    if shout=="FizzBuzz":
                        player.append(pnow)
                elif truenum%5==0:
                    if shout=="Buzz":
                        player.append(pnow)
                elif truenum%3==0:
                    if shout=="Fizz":
                        player.append(pnow)
                else:
                    if shout==str(truenum):
                        player.append(pnow)
        print " ".join([str(x) for x in sorted(player)])
Buggy python submission (verdict: Runtime Error):
while(1):
    [n,m]=map(int,raw_input().split())
    if n==0:    break
    D=[[] for i in range(n+1)]
    D[0]=range(1,n+1)
    nflg=0
    for i in range(m):
        [u,v]=map(int,raw_input().split())
        D[u].append(v)
        D[v].append(u)
        if len(D[u])>2 or len(D[v])>2:
            nflg=1
    if nflg:
        print 'no'
    else:
        bkf=0
        while (len(D[0])>0):
            st=D[0].pop()
            st0=st
            while len(D[st])!=0:
               nxt=D[st].pop()
               if nxt!=st0:
                   D[0].remove(nxt)
                   D[nxt].remove(st)
                   st=nxt
               else:
                   print 'no'
                   bkf=1
                   break
            if bkf:    break
        else:
            print 'yes'
            

Fixed submission:
while(1):
    [n,m]=map(int,raw_input().split())
    if n==0:    break
    D=[[] for i in range(n+1)]
    D[0]=range(1,n+1)
    nflg=0
    for i in range(m):
        [u,v]=map(int,raw_input().split())
        D[u].append(v)
        D[v].append(u)
        if len(D[u])>2 or len(D[v])>2:
            nflg=1
    if nflg:
        print 'no'
    else:
        bkf=0
        while (len(D[0])>0):
            st=D[0].pop()
            if len(D[st])==2:
                D[0].append(st)
            st0=st
            while len(D[st])!=0:
               nxt=D[st].pop()
               if nxt!=st0:
                   D[0].remove(nxt)
                   D[nxt].remove(st)
                   st=nxt
               else:
                   print 'no'
                   bkf=1
                   break
            if bkf:    break
        else:
            print 'yes'
Buggy python submission (verdict: Time Limit Exceeded):
def hantei(field,r,c):
    count=0
    for i in range(c):
        countc=0
        for j in range(r):
            countc=countc+field[j][i]
        count=max(countc,r-countc)+count
    return count
    
def turnr(field,rn,r,c):
    if rn==r:
        return hantei(field,r,c)
    field1=field
    field2=field
    field2[rn]=[not x for x in field[rn]]
    return max(turnr(field1,rn+1,r,c),turnr(field2,rn+1,r,c))

while(1):
    [r,c]=[int(x) for x in raw_input().split()]
    if r==0:
        break
    else:
        field=[]
        for i in range(r):
            field.append([int(x) for x in raw_input().split()])
        print turnr(field,0,r,c)

Fixed submission:

def hanteib(bfield,r,c):
    count=0
    for b in bfield:
        ccount=bin(b).count("1")
        count=count+max(ccount,r-ccount)
    return count

def turnrb(bfield,rn,r,c):
    if rn==r:
        return hanteib(bfield,r,c)
    bfield1=bfield
    bfield2=[b ^ 2**rn for b in bfield]
    return max(turnrb(bfield1,rn+1,r,c),turnrb(bfield2,rn+1,r,c))

while(1):
    [r,c]=[int(x) for x in raw_input().split()]
    if r==0:
        break
    else:
        field=[]
        bfield=[]
        for i in range(r):
            field.append([int(x) for x in raw_input().split()])
        for j in range(c):
            bb=0
            for i in range(r):
                bb=bb+2**i*field[i][j]
            bfield.append(bb)
        print turnrb(bfield,0,r,c)
Buggy python submission (verdict: Runtime Error):
while (1):
    n=int(raw_input())
    if n==0:
        break
    else:
        top=-1
        fault=[0]
        S=0
        for i in range(n/2): #i=0,2,... is othello i=1,3,...is donothing
            s=int(raw_input()) #oddstone
            if top!=s: 
                fault.append(i)
                top=s
            s=int(raw_input()) #evenstone
            if top!=s:
                fault.pop()
                top=s
        i=len(fault)-1
        while i>0:
            S=S+(fault[i]-fault[i-1])*2
            i=i-2
        if not top:
            S=2*(n/2)-S
        if n%2==1:
            s=int(raw_input())
            S=S+(1-s)
        print S

Fixed submission:
while (1):
    n=int(raw_input())
    if n==0:
        break
    else:
        top=-1
        fault=[0]
        S=0
        for i in range(n/2): #i=0,2,... is othello i=1,3,...is donothing
            s=int(raw_input()) #oddstone
            if top!=s: 
                fault.append(i)
                top=s
            s=int(raw_input()) #evenstone
            if top!=s:
                fault.pop()
                top=s
            if fault==[]:
                fault=[0]
        i=len(fault)-1
        while i>0:
            S=S+(fault[i]-fault[i-1])*2
            i=i-2
        if not top:
            S=2*(n/2)-S
        if n%2==1:
            s=int(raw_input())
            S=S+(1-s)
        print S
Buggy python submission (verdict: Runtime Error):
[N,L]=[int(x) for x in raw_input().split()]
icelist=[0]
for i in range(N):
    icelist.append(int(raw_input()))
icelist.append(0)
incindex=[]
for i in range(1,N+1):
    if icelist[i]>icelist[i-1] and icelist[i]>icelist[i+1]:
        incindex.append(i)
ans=0
popped=0
while popped<N:
    addindex=[]
    delindex=[]
    t=L-max([icelist[i] for i in incindex])
    ans+=t
    for ii in incindex:
        icelist[ii]+=t
        if icelist[ii]==L:
            popped+=1
            delindex.append(ii)
            icelist[ii]=0
            if ii-1>0:
                if icelist[ii-1]>icelist[ii-2]:
                    addindex.append(ii-1)
            if ii+1<N+1:
                if icelist[ii+1]>icelist[ii+2]:
                    addindex.append(ii+1)
    for k in delindex:
        incindex.remove(k)
    for j in addindex:
        incindex.append(j)
print ans

Fixed submission:
[N,L]=[int(x) for x in raw_input().split()]
icelist=[]
for i in range(N):
    icelist+=[int(raw_input())]
peakindex=[0]
for i in range(1,N-1):
    if (icelist[i]-icelist[i-1])*(icelist[i+1]-icelist[i])<0:
            peakindex.append(i)
peakindex.append(N-1)
ans=0
for i in range(len(peakindex)-1):
    newans=sum([L-icelist[x] for x in range(peakindex[i],peakindex[i+1]+1)])
    ans=max(ans,newans)
print ans
Buggy python submission (verdict: Runtime Error):
[N,K]=map(int, raw_input().split())
C=[[] for i in range(11)]
D=[[0 for j in range(K+1)] for i in range(11)]
M=[0 for i in range(11)]

for i in range(N):
    c,g=map(int, raw_input().split())
    C[g].append(c)
    M[g]+=1
for i in range(1,11):
    y=sorted(C[i], reverse=True)
    for j in range(len(y)):
        n = j+1
        D[i][n] =y[j] + D[i][n-1] + 2*(n-1)

DP=[[0 for i in range(K+1)] for j in range(11)]

for g in range(1,11):
    for k in range(K+1):
        DP[g][k] = max( [ DP[g-1][k-x] + D[g][x] for x in range(min( k+1, M[g]+1 ) ) ] + [0] )
print DP[10][K]



Fixed submission:
[N,K]=map(int, raw_input().split())
C=[[] for i in range(11)]
D=[[0 for j in range(N+1)] for i in range(11)]
M=[0 for i in range(11)]

for i in range(N):
    c,g=map(int, raw_input().split())
    C[g].append(c)
    M[g]+=1
for i in range(1,11):
    y=sorted(C[i], reverse=True)
    for j in range(len(y)):
        n = j+1
        D[i][n] =y[j] + D[i][n-1] + 2*(n-1)

DP=[[0 for i in range(K+1)] for j in range(11)]

for g in range(1,11):
    for k in range(K+1):
        DP[g][k] = max( [ DP[g-1][k-x] + D[g][x] for x in range(min( k+1, M[g]+1 ) ) ] + [0] )
print DP[10][K]
Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin:
    A,B=int(line[0]),int(line[3])
    print A+B

Fixed submission:
import sys

for line in sys.stdin:
    L=map(int,line.split())
    A,B=L[0],L[1]
    print A+B
Buggy python submission (verdict: Time Limit Exceeded):
def convex(Pset):
    v1=[Pset[1][0]-Pset[0][0],Pset[1][1]-Pset[0][1]]
    v2=[Pset[2][0]-Pset[1][0],Pset[2][1]-Pset[1][1]]
    v3=[Pset[2][0]-Pset[0][0],Pset[2][1]-Pset[0][1]]
    c= v1[0]*v2[1]-v1[1]*v2[0]
    return c<=0

def area(Pset):
    v1=[Pset[1][0]-Pset[0][0],Pset[1][1]-Pset[0][1]]
    v2=[Pset[2][0]-Pset[1][0],Pset[2][1]-Pset[1][1]]
    v3=[Pset[2][0]-Pset[0][0],Pset[2][1]-Pset[0][1]]
    return abs(v1[0]*v3[1]-v1[1]*v3[0])/2.

while(1):
    n=int(raw_input())
    if n==0:        break
    P=[]
    for i in range(n):
        P.append([int(x) for x in raw_input().split()])
    ans=0
    while(len(P)>=3):
        for i in range(len(P)-2):
            Pset=P[i:i+3]
            if convex(Pset):
                ans+=area(Pset)
                del P[i+1]
                break
    print ans
    raw_input()
    

Fixed submission:
def convex(Pset):
    v1=[Pset[1][0]-Pset[0][0],Pset[1][1]-Pset[0][1]]
    v2=[Pset[2][0]-Pset[1][0],Pset[2][1]-Pset[1][1]]
    v3=[Pset[2][0]-Pset[0][0],Pset[2][1]-Pset[0][1]]
    c= v1[0]*v2[1]-v1[1]*v2[0]
    return c

def area(Pset):
    v1=[Pset[1][0]-Pset[0][0],Pset[1][1]-Pset[0][1]]
    v2=[Pset[2][0]-Pset[1][0],Pset[2][1]-Pset[1][1]]
    v3=[Pset[2][0]-Pset[0][0],Pset[2][1]-Pset[0][1]]
    return abs(v1[0]*v3[1]-v1[1]*v3[0])/2.

def nopoints(Pset,P):
    v1=[Pset[1][0]-Pset[0][0],Pset[1][1]-Pset[0][1]]
    v2=[Pset[2][0]-Pset[1][0],Pset[2][1]-Pset[1][1]]
    v3=[Pset[2][0]-Pset[0][0],Pset[2][1]-Pset[0][1]]
    CPv=[ [p[0]-Pset[0][0],p[1]-Pset[0][1]] for p in P if p not in Pset]
    #print CPv
    for pv in CPv:
        rdet=1./(v1[0]*v3[1] - v1[1]*v3[0])
        t1=rdet*( v3[1]*pv[0]-v3[0]*pv[1])
        t2=rdet*(-v1[1]*pv[0]+v1[0]*pv[1])
        #print pv, v1, v3, t1,t2
        if (t1>=0 and t2>=0 and t1+t2<=1 ):
            return 0
            break
    return 1

an=1
while(1):
    n=int(raw_input())
    if n==0:        break
    P=[]
    for i in range(n):
        P.append([int(x) for x in raw_input().split()])
    ans=0
    while(len(P)>=3):
        for i in range(len(P)-2):
            Pset=P[i:i+3]
            c= convex(Pset)
            if c<=0:
                if c==0:
                    del P[i+1]
                    break
                elif nopoints(Pset,P[:]):
                    ans+=area(Pset)
                    del P[i+1]
                    break
        else:
            print 'err',P
            break
    print an, ans
    raw_input()
    an+=1
Buggy python submission (verdict: Time Limit Exceeded):
def getlcm(a,b):
    aa=a
    bb=b
    while aa!=0:
        [aa,bb]=[bb%aa,aa]
    return a*b/bb

while(1):
    [n,a,b]=[int(x) for x in raw_input().split()]
    if n==0:
        break
    else:
        [a,b]=[min(a,b),max(a,b)]
        LCM=getlcm(a,b)
        able=[]
        for i in range(LCM/a):
            for j in range(n):
                if a*i+b*j>=n:
                    break
                able.append(a*i+b*j)
        ans=n-len(able)
        print ans

Fixed submission:
def getlcm(a,b):
    aa=a
    bb=b
    while aa!=0:
        [aa,bb]=[bb%aa,aa]
    return a*b/bb

while(1):
    [n,a,b]=[int(x) for x in raw_input().split()]
    if n==0:
        break
    else:
        [a,b]=[min(a,b),max(a,b)]
        LCM=getlcm(a,b)
        #able=[]
        able=-1
        for i in range(LCM/a):
            for j in range((n-a*i)/b+1):
                able+=1
        ans=n-able
        print ans
Buggy python submission (verdict: Time Limit Exceeded):
while(1):
    z=int(raw_input())
    if z==0:
        break
    else:
        k=0
        for x in range(1,z+1):
            for y in range(1,z+1):
                if x**3+y**3>z**3:
                    break
                k=max(k,x**3+y**3)
        print z**3-k

Fixed submission:
import math

while(1):
    z=int(raw_input())
    if z==0:
        break
    else:
        k=0
        for x in range(1,z):
            y=int(pow(z**3-x**3,1/3.))
            k=max(k,x**3+y**3)
        print z**3-k
Buggy python submission (verdict: Time Limit Exceeded):
import math

nummax=300000
MSall=sorted([7*x-1 for x in range(1,nummax/7)]+[7*x+1 for x in range(1,nummax/7)])
MSprime=[]
smax=math.sqrt(MSall[-1])
i=6
while i<=smax:
    for x in MSall:
        if x%i==0:
            MSall.remove(x)
    MSprime.append(i)
    i=MSall[0]
MSprime=MSprime+MSall

while(1):
    N=int(raw_input())
    if N==1:
        break
    else:
        ok=[]
        i=0
        while MSprime[i]<=N:
            if N%MSprime[i]==0:
                ok.append(MSprime[i])
            i=i+1
        print str(N)+': '+' '.join([str(x) for x in ok])

Fixed submission:
import math

def checkifprime(NN):
    for i in range(len(MSprime)):
        if MSprime[i]>NN:
            break
        elif NN%MSprime[i]==0:
            return -1
    return NN


nummax=int(50000)
MSall=sorted([7*x-1 for x in range(1,nummax/7)]+[7*x+1 for x in range(1,nummax/7)])
MSprime=[]
smax=math.sqrt(nummax)
i=6
while i<=smax:
    for x in MSall:
        if x%i==0:
            MSall.remove(x)
    MSprime.append(i)
    i=MSall[0]
MSprime=MSprime+MSall

while(1):
    N=int(raw_input())
    if N==1:
        break
    else:
        ok=[]
        for i in range(len(MSprime)):
            if MSprime[i]>N:
            	break
            elif N%MSprime[i]==0:
                ok.append(MSprime[i])
                cifp=checkifprime(N/MSprime[i])
                if cifp>0 and cifp!=1:
                    ok.append(cifp)
        if len(ok)==0:
        	ok.append(N)
        ok.sort()
                
        print str(N)+': '+' '.join([str(x) for x in ok])
Buggy python submission (verdict: Runtime Error):
import itertools

P1=[p*(p+1)*(p+2)/6 for p in range(1,181)]
P2=[p for p in P1 if p%2]

maxnum=1000000

A1=[999999 for x in range(maxnum+1)]
A2=[999999 for x in range(maxnum+1)]

for X in [[P1,A1],[P2,A2]]:
    P=X[0]
    A=X[1]
    tmp=P
    bk=0
    cnt=2
    for p in tmp:
        if p<maxnum:
            A[p]=1
            bk+=1
    while bk<maxnum:
        tmp2=[]
        for t in tmp:
            for p in P:
                if t+p > maxnum:    break
                if A[t+p]>cnt:
                    A[t+p]=cnt
                    bk+=1
                    tmp2.append(t+p)
        tmp=tmp2[:]
        cnt+=1
while(1):
    n=int(raw_input())
    if n==0: break
    print A1[n], A2[n]



Fixed submission:
import itertools

P1=[p*(p+1)*(p+2)/6 for p in range(1,181)]
P2=[p for p in P1 if p%2]

maxnum=1000000

A1=[5 for x in range(maxnum+1)]
A2=[37 for x in range(maxnum+1)]

for X in [[P1,A1],[P2,A2]]:
    P=X[0]
    A=X[1]
    mx=A[0]
    tmp=P
    bk=0
    cnt=2
    for p in tmp:
        if p<maxnum:
            A[p]=1
            bk+=1
    while cnt<mx:
        tmp2=[]
        for t in tmp:
            for p in P:
                if t+p > maxnum:    break
                if A[t+p]>cnt:
                    A[t+p]=cnt
                    bk+=1
                    tmp2.append(t+p)
        tmp=tmp2[:]
        cnt+=1
while(1):
    n=int(raw_input())
    if n==0: break
    print A1[n], A2[n]