import Foundation

let mod: Int64 = 1_000_000_007

let n = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map { Int($0)! }

var acc0: Int64 = 0
var acc1: Int64 = 0

for i in a {
  let j = Int64(i)
  acc0 += j
  acc1 += j * j
  if acc0 > mod { acc0 %= mod }
  if acc1 > mod { acc1 %= mod }
}

let b = acc0 > acc1 ? acc0 - acc1 : acc0 - acc1 + mod

print((b + (b % 2) * mod) / 2)
