open Core;;

let mm = 1000000007;;

let () = 
  let a =
    let _ = In_channel.(input_line stdin) in
    List.map ~f:Int.of_string (String.split ~on:' ' (In_channel.(input_line_exn stdin))) in
  let (_, res) = List.fold ~init:(0,0) ~f:(fun (s,r) x -> ((s + x) mod mm, (r + s * x) mod mm)) a in
  printf "%d\n" res
;;


