import java.io.*; import java.util.*; public class Hourrank26 { static class Line { long k, b; public Line(long k, long b) { this.k = k; this.b = b; } long eval(long x) { return k * x + b; } } static class Node { static long[] xs; int l, r; Node left, right; Line best; long getBest(int idx) { long ret = best == null ? Long.MIN_VALUE : best.eval(xs[idx]); if (r - l > 1) { ret = Math.max(ret, (idx < left.r ? left : right).getBest(idx)); } return ret; } void insert(int ql, int qr, Line add) { if (l >= qr || ql >= r) { return; } if (!(ql <= l && r <= qr)) { left.insert(ql, qr, add); right.insert(ql, qr, add); return; } if (best == null) { best = add; return; } // int cl = compareLines(best, add, dirs[l]); int cl = Long.compare(best.eval(xs[l]), add.eval(xs[l])); int cr = Long.compare(best.eval(xs[r - 1]), add.eval(xs[r - 1])); if (cl >= 0 && cr >= 0) { return; } if (cl <= 0 && cr <= 0) { best = add; return; } // int cm = compareLines(best, add, dirs[left.r]); int cm = Long.compare(best.eval(xs[left.r]), add.eval(xs[left.r])); if (cm < 0) { Line tmp = add; add = best; best = tmp; cl = -cl; cr = -cr; } // cm >= 0 if (cl > 0) { right.insert(ql, qr, add); } else { left.insert(ql, qr, add); } } public Node(int l, int r) { this.l = l; this.r = r; if (r - l > 1) { int m = (l + r) >> 1; left = new Node(l, m); right = new Node(m, r); } } } void submit() { int n = nextInt(); // int n = rand(1, 100); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); // a[i] = rand(-100, 100); } long[] p = new long[n + 1]; long[] q = new long[n + 1]; for (int i = 0; i < n; i++) { p[i + 1] = p[i] + a[i]; q[i + 1] = q[i] + a[i] * a[i]; } long[] allP = p.clone(); allP = unique(allP); Node.xs = allP; Node root = new Node(0, allP.length); long ans = 0; for (int i = 0; i <= n; i++) { int idx = Arrays.binarySearch(allP, p[i]); // long here = root.getBest(idx); ans = Math.max(ans, root.getBest(idx) + p[i] * p[i] - q[i]); root.insert(0, allP.length, new Line(-2 * p[i], p[i] * p[i] + q[i])); } out.println(ans / 2); } long[] unique(long[] a) { Arrays.sort(a); int sz = 1; for (int i = 1; i < a.length; i++) { if (a[i] != a[sz - 1]) { a[sz++] = a[i]; } } return Arrays.copyOf(a, sz); } void preCalc() { } static final int C = 5; void stress() { } void test() { } Hourrank26() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); preCalc(); submit(); // stress(); // test(); out.close(); } static final Random rng = new Random(); static int rand(int l, int r) { return l + rng.nextInt(r - l + 1); } public static void main(String[] args) throws IOException { new Hourrank26(); } BufferedReader br; PrintWriter out; StringTokenizer st; String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } String nextString() { try { return br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } }