const main = (input) => {
  input = input.trim().split('\n')
  const mod = 10n**9n + 7n
  const arr = input[1].split(' ').map(BigInt).sort((a, b) => b - a)

  let sum = arr[0] + arr[1]
  let ans = arr[0] * arr[1] % mod

  for (let i=2; i<arr.length; i++) {
    ans += sum * arr[i]
    sum += arr[i]
  }

  // return console.log(`${ans % mod}`)
}