fun int mul(int x, int y) =
    if y == 0 then 0
    else if y < 0 then mul(x, y+1) - x
    else mul(x, y-1) + x

fun int readInt(int i) = read(int)

fun int squareSum(int x, int y) = x + mul(y, y)

fun int main() =
  let n = read(int) in
  if n == 0 then let a = write("Incorrect Input!") in 0
  else if n < 0 then let a = write("Incorrect Input!") in 0
  else
    let arr = map(readInt, iota(n)) in
    let dif = map(fn int (int x) => if x == 0 then arr[x] else arr[x] - arr[x-1], iota(n)) in
    write(reduce(squareSum, 0, dif))
