Problem:
Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).

Constraints

2 \leq N \leq 2\times 10^5

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

11

We have 1 \times 2 + 1 \times 3 + 2 \times 3 = 11.

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")


/*
ID: febrian3 
LANG: C++11 
PROB: task 
*/

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr<<#x<<": "<<(x)<<'\n'
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f;
const ll nax = 0;
ll n;

int main(){
		/*freopen("filename.in","r",stdin); 
		freopen("filename.out","w",stdout);*/ 
		IOS	
		cin >> n;
		vector<ll>arr(n+1);
		for(int i=0;i<n;++i){
			cin >> arr[i];
		}
		vector<ll>pref(n, 0);
		for(int i=n-1;i>=0;--i){
			pref[i]=arr[i];
			if(i<n-1) pref[i]+=pref[i+1];
		}
		ll ans=0;
		for(int i=0;i<n-1;++i){
			ll cur=arr[i]*pref[i+1];
			ans=(ans+cur)%mod;
		}
		cout << ans << '\n';
	}