import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long [] B = new long [N]; ArrayList L = new ArrayList<>(); long AMAX = 0; for(int i=0; i=0; j--){ long tmp = L.get(j); if(tmp<0)continue; L.add(L.get(j)-B[i]); } } long ans = AMAX; for(int j=L.size()-1; j>=0; j--){ ans = Math.min(ans,Math.abs(L.get(j))); } System.out.println(ans); } }