import java.util.; import java.io.; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = null; while((str = in.readLine()) != null){ int n = Integer.parseInt(str); String[] arr = in.readLine().split(" "); int[] res = new int[arr.length]; for(int i = 0;i < arr.length;i++){ res[i] = Integer.parseInt(arr[i]); } int sum = res[0]; int max = sum; for(int i = 1;i < res.length;i++){ if(sum <= 0){ sum = res[i]; if(sum > max){ max = sum; } }else{ sum += res[i]; if(sum > max){ max = sum; } } } System.out.println(max); } } }