#include <bits/stdc++.h>
using namespace std;
const int N = 500010, mod = 1e9 + 7;
int n, m, i, j, a[N], id[N], c1[N], c2[N], ans;
bool cmp(int x, int y) { return a[x] < a[y]; }
void inc(int& x, int v) {
  x += v;
  if (x >= mod) x -= mod;
}
void add(int c[N], int x, int v) {
  while (x <= n) inc(c[x], v), x += x & -x;
}
int que(int c[N], int x, int res = 0) {
  while (x) inc(res, c[x]), x -= x & -x;
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]), id[i] = i;
  sort(id + 1, id + n + 1, cmp);
  for (int i = (1); i <= (n); i++) {
    add(c1, id[i], id[i]);
    ans = (ans + 1ll * a[id[i]] *
                     (1ll * (n - id[i] + 1) * que(c1, id[i]) % mod +
                      1ll * id[i] * que(c2, n - id[i] + 1) % mod) %
                     mod) %
          mod;
    add(c2, n - id[i] + 1, n - id[i] + 1);
  }
  printf("%d\n", ans);
  return 0;
}
