import Enum

defmodule Main do
  @pow1097  1000000007
  def sum_of_pair(_n,seq) do
    cumsum_seq = Enum.scan(seq, &(&1 + &2))
    reduceprod1097(seq,cumsum_seq)
  end

  def reduceprod1097(seq,cumsum_seq) do
    cumsum_total = Enum.at(cumsum_seq,Enum.count(cumsum_seq)-1)
    Enum.reduce_while(Enum.with_index(seq),0,fn {val, index},acc -> if index < Enum.count(seq)-1, do: {:cont, val *(cumsum_total - Enum.at(cumsum_seq, index)) + acc}, else: {:halt, acc} end)
  end

 def main do
    n = IO.gets("") |> String.trim() |> String.to_integer
    seq = IO.read(:line) |> String.trim() |> String.split(" ") |> map(&String.to_integer/1)
    IO.inspect sum_of_pair(n,seq)
 end
end