#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
const long long mod = 1000000007;
int num[N], tmp[N];
int n;
long long sum[4 * N], nsum[4 * N];
long long MOD(long long a) {
  if (a >= mod) return a % mod;
  if (a < 0) return a % mod + mod;
  return a;
}
void add(int idx, int pos, long long nn, int l = 1, int r = n, int now = 1) {
  if (l == r) {
    sum[now] = pos;
    nsum[now] = MOD(nn * pos);
    return;
  }
  int m = (l + r) >> 1;
  if (idx <= m)
    add(idx, pos, nn, l, m, now << 1);
  else
    add(idx, pos, nn, m + 1, r, now << 1 | 1);
  sum[now] = MOD(sum[now << 1] + sum[now << 1 | 1]);
  nsum[now] = MOD(nsum[now << 1] + nsum[now << 1 | 1]);
}
long long get(int ll, int rr, int ch, int l = 1, int r = n, int now = 1) {
  if (ll > rr || l > rr || r < ll) return 0;
  if (l >= ll && r <= rr) return (ch) ? nsum[now] : sum[now];
  int m = (l + r) >> 1;
  return MOD(get(ll, rr, ch, l, m, now << 1) +
             get(ll, rr, ch, m + 1, r, now << 1 | 1));
}
int main() {
  int i, j, k, l, a, b, c, d;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf(" %d", &num[i]);
    tmp[i] = num[i];
  }
  sort(tmp + 1, tmp + 1 + n);
  for (i = 1; i <= n; i++)
    num[i] = lower_bound(tmp + 1, tmp + 1 + n, num[i]) - tmp;
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    add(num[i], i, tmp[num[i]]);
    ans = MOD(ans + MOD(get(1, num[i], 0) * tmp[num[i]]) * (n - i + 1));
    ans = MOD(ans + get(num[i] + 1, n, 1) * (n - i + 1));
  }
  printf("%lld", ans);
  return 0;
}
