#include <bits/stdc++.h>
using namespace std;
const long long maxN = 5e5 + 5, mod = 1e9 + 7, inf = LLONG_MAX / 1000ll;
long long N;
long long arr[maxN], rnk[maxN];
vector<long long> cpr;
long long tot, now;
struct bit {
  vector<long long> arr = vector<long long>(maxN, 0);
  void add(long long p, long long v) {
    while (p < arr.size()) {
      arr[p] = (arr[p] + v) % mod;
      p += p & -p;
    }
  }
  long long g(long long p) {
    long long r = 0;
    while (p) {
      r = (r + arr[p]) % mod;
      p -= p & -p;
    }
    return r;
  }
} BIT, BIT2;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (long long i = (long long)1; i <= (long long)N; i++) cin >> arr[i];
  for (long long i = (long long)1; i <= (long long)N; i++)
    cpr.push_back(arr[i]);
  sort(begin(cpr), end(cpr));
  for (long long i = (long long)1; i <= (long long)N; i++)
    rnk[i] = lower_bound(begin(cpr), end(cpr), arr[i]) - begin(cpr) + 1;
  for (long long i = (long long)1; i <= (long long)N; i++) {
    long long a = BIT.g(maxN - 1) - BIT.g(rnk[i]),
              self = (BIT2.g(rnk[i] - 1) + i) * arr[i] % mod;
    now = (now + a + self) % mod;
    tot = (tot + now) % mod;
    BIT.add(rnk[i], arr[i] * i % mod);
    BIT2.add(rnk[i], i);
  }
  cout << (tot % mod + mod) % mod << '\n';
}
