let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let acc = Array.make (n + 1) 0 in
  for i = n - 1 downto 0 do
    acc.(i) <- as_.(i) +^ acc.(i + 1)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( +^ ) 0 @@
  Array.init (n - 1) @@ fun i -> as_.(i) *^ acc.(i + 1)

