#!/usr/bin/env python3


class S:
    def __init__(s, a, b, c): s.a, s.b, s.c, s.s = a, b, c, a and ((a - b) // (2 * a))

    def merge(s, o): return S(s.a + o.a, s.b + o.b + 2 * s.a * o.a, s.c + o.c + s.a * s.a * o.a + s.a * o.b)


n, A, B = input(), [S(1, -2 * x, x * x) for x in map(int, input().split())], []
for a in A:
    while B and B[-1].s + B[-1].a >= a.s: a = B.pop().merge(a)
    B.append(a)
print(sum(s.a * s.s * s.s + s.b * s.s + s.c for s in B))
