Sum of product of all pairs
Easy Accuracy: 17.32% Submissions: 518 Points: 2

Given an integer N and an array of N integers. Calculate the sum of products of all pairs of integers of the array.
Note: Since the answer can be large, return the answer modulo 109+7.

Example 1:

Input:
N=3
A=[1,2,3]
Output:
11
Explanation:
1x2+2x3+1x3=11
So, the answer is 11.

Example 2:

Input:
N=3
A=[2,2,3]
Output:
16
Explanation:
2x2+2x3+3x2=16.
So, the answer is 16.

You don't need to read input or print anything. Your task is to complete the function productOfPairs() which takes the integer N and array A as input parameters and returns the sum of the product of all pairs of integers from the array.

Expected Time Complexity:O(N)
Expected Auxillary Space:O(1)

Constraints:
1<=N,A[i]<=106

We are replacing the old Disqus forum with the new Discussions section given below.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  