import Enum
import Integer

defmodule Main do
  def sum_of_pair(_n,seq) do
    list = for x <- Enum.slice(seq,0,Enum.count(seq) -1), y <- Enum.slice(seq,1,Enum.count(seq)),Enum.at(seq,x)<Enum.at(seq,y), do: x*y 
    res = rem(Enum.sum(list),pow(10,9)+7)
  end
  
  def  pow(n, k), do: pow(n, k, 1)        
  defp pow(_, 0, acc), do: acc
  defp pow(n, k, acc), do: pow(n, k - 1, n * acc)

 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