let _ = 
  let read n =
    let rec iter n = if n = 0 then [] else Scanf.scanf "%d\n" (fun x -> x) :: iter (n - 1) in
    List.rev @@ iter n in
  let max_sseq = function
    | [] -> (min_int,min_int)
    | hd :: tl -> List.fold_left (fun (c,m) x -> let mx = max (c + x) x in (mx, max mx m)) (hd, hd) tl in
  let rec loop () = 
    let n = Scanf.scanf "%d\n" (fun x -> x) in
    if n = 0 then ()
    else let lst = read n in
         Printf.printf "%d\n" (snd @@ max_sseq lst);
         loop () in
  loop ()