def sum(a,i,j)
  sum = 0
  for k in i..j
    sum = sum + a[k]
  end
  sum
end

while true
  n = gets.to_i
  if n == 0
    break
  end
  a = Array.new(n)
  for i in 0..n-1
    a[i] = gets.to_i
  end
  p a
  max = 0
  for i in 0..n-1
    for j in i..n-1
      max = [max,sum(a,i,j)].max
    end
  end
  puts max
end