// O (N ^ 2)

#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7, N = 2000;

int v[N + 5];

int main()
{
    //freopen("rectangles.in", "r", stdin);
    //freopen("rectangles.out", "w", stdout);
    //freopen("file.in","r",stdin);
    //freopen("brut.out","w",stdout);
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &v[i]);
    for (int i = 1; i < n; ++i) {
        int max1 = v[i];
        int max2 = -1;
        for (int j = i + 1; j <= n; ++j) {
            if (v[j] >= max1) {max2 = max1; max1 = v[j];}
            else if (v[j] > max2) max2 = v[j];
            ans += (1LL * max1 * max2) % mod;
            ans %= mod;
        }
    }
    printf("%d", ans);
    return 0;
}
