Buggy python submission (verdict: Time Limit Exceeded):
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	MAX=[0]*(len(A))
	for i in range(len(A)):
		for j in range(i,len(A)+1):
			if MAX[i]<sum(A[i:j]):
				MAX[i]=sum(A[i:j])
	MAX.sort(reverse=True)
	print(MAX[0])

Fixed submission:
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))

Buggy python submission (verdict: Time Limit Exceeded):
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	MAX=[0]*(len(A))
	end=len(A)
	for i in range(end):
		for j in range(i+1,end+1):
			if MAX[i]<sum(A[i:j]):
				MAX[i]=sum(A[i:j])
	MAX.sort()
	print(MAX[-1])

Fixed submission:
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))

Buggy python submission (verdict: Time Limit Exceeded):
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	MAX=[0]*(len(A))
	end=len(A)
	for i in range(end):
		for j in range(i+1,end+1):
			s=sum(A[i:j])
			if MAX[i]<s:
				MAX[i]=s
	print(max(MAX))

Fixed submission:
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))

Buggy python submission (verdict: Time Limit Exceeded):
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	end=len(A)
	MAX=[0]*end
	for i in range(end):
		for j in range(i+1,end+1):
			s=sum(A[i:j])
			if MAX[i]<s:
				MAX[i]=s
	print(max(MAX))

Fixed submission:
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))

Buggy python submission (verdict: Runtime Error):
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	start=0
	for i in A:
		if i<=0:
			start+=1
		else:
			break
	B=A[start:]
	end=len(B)
	MAX=[0]*end
	for i in range(end):
		for j in range(i+1,end+1):
			s=sum(B[i:j])
			if MAX[i]<s:
				MAX[i]=s
	print(max(MAX))

Fixed submission:
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))

Buggy python submission (verdict: Runtime Error):
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	start=0
	for i in A:
		if i<=0:
			start+=1
		else:
			break
	B=A[start:]
	end=len(B)
	MAX=[0]*end
	for i in range(end):
		for j in range(i+1,end+1):
			s=sum(B[i:j])
			if MAX[i]<s:
				MAX[i]=s
	print(max(MAX))

Fixed submission:
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))

Buggy python submission (verdict: Runtime Error):
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	start=0
	for i in A:
		if i<=0:
			start+=1
		else:
			break
	B=A[start:len(A)+1]
	end=len(B)
	MAX=[0]*end
	for i in range(end):
		for j in range(i+1,end+1):
			s=sum(B[i:j])
			if MAX[i]<s:
				MAX[i]=s
	print(max(MAX))

Fixed submission:
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))