#K34062. Sum of Product of Pairs

    ID: 25226 Type: Default 1000ms 256MiB

Sum of Product of Pairs

Sum of Product of Pairs

Given a list of n integers, your task is to compute the sum of the product of each pair of distinct integers modulo \(10^9+7\). More formally, you need to calculate

[ S = \sum_{1 \le i < j \le n} a_i \times a_j \mod (10^9+7) ]

This problem requires careful handling of large numbers and modular arithmetic. Make sure your solution works efficiently for large inputs.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer n, the number of elements in the list.
  • The second line contains n space-separated integers.

outputFormat

Output to standard output (stdout) a single integer representing the sum of the product of each pair of distinct integers modulo \(10^9+7\).

## sample
3
1 2 3
11