#include<bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using ll = long long;

using namespace std;

ll gcd(ll C, ll D) {
	if (C < D) gcd(D, C);

	if (C%D == 0)return D;
	else return gcd(D, C%D);
}

const int MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	ll sum = 0;
	rep(i, N) {
		cin >> A[i];
		sum += A[i];
	}
	ll ans = 0;

	rep(i, N) {
		sum -= A[i];
		ans += ((A[i]%MOD) * (sum%MOD))%MOD;
		ans %= MOD;
	}

	cout << ans << endl;
	return 0;
}





#include<iostream>
using namespace std;
long N,A[2<<17],ans;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	int i=0;
	while(i<N)
	{
		while(i+1<N&&A[i]+1==A[i+1])i++;
		if(A[i]>i||i+1<N&&A[i]+1<A[i+1])
		{
			cout<<-1<<endl;
			return 0;
		}
		ans+=A[i];
		i++;
	}
	cout<<ans<<endl;
}
