import Enum
 
defmodule Main do
  @pow1097  1000000007
  def sum_of_pair(n,seq) do
    cumsum_seq = Enum.scan(seq, &rem((&1 + &2), @pow1097))
    total = rem(Enum.at(cumsum_seq,n-1),@pow1097)
    reduceprod1097(n,seq,cumsum_seq,total)
  end
  
  def reduceprod1097(n,seq,cumsum_seq,total), do: reduceprod1097(n,seq,cumsum_seq,total,0)
  defp reduceprod1097(n,[],_,_,acc), do: acc 
  defp reduceprod1097(n,[head|tail],[headcum|tailcum],total,acc), do: reduceprod1097(n,tail,tailcum,total,rem(rem(head*(total-headcum),@pow1097)+acc,@pow1097))
  
 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