let () =
  let rec read () =
    let n = read_int () in
    if n != 0 then
      let rec loop max sum = function
          0 -> if sum > max then sum else max
        | i -> let m = read_int() in
               if sum < 0 && m > sum then
                 loop max m (i-1)
               else if m < 0 && sum > max then
                 loop sum (sum+m) (i-1)
               else
                 loop max (sum+m) (i-1)
      in Printf.printf "%d\n" (loop (-100000) (read_int ()) (n-1));read ()
  in read ();;