#include <bits/stdc++.h>
using namespace std;
const int maxn = 500003, mod = 1000000007;
int Plus(int x, int y) { return (x += y) >= mod ? x - mod : x; }
void PlusEqual(int &x, int y) {
  if ((x += y) >= mod) x -= mod;
}
int mul(long long x, int y) { return x * y % mod; }
int n, p[maxn], pre[maxn], suf[maxn], a[maxn], ans;
bool cmp(int x, int y) { return a[x] < a[y]; }
void pre_add(int pos, int k) {
  while (pos <= n) PlusEqual(pre[pos], k), pos += pos & -pos;
}
void suf_add(int pos, int k) {
  while (pos) PlusEqual(suf[pos], k), pos -= pos & -pos;
}
int pre_query(int pos) {
  int ret = 0;
  while (pos) PlusEqual(ret, pre[pos]), pos -= pos & -pos;
  return ret;
}
int suf_query(int pos) {
  int ret = 0;
  while (pos <= n) PlusEqual(ret, suf[pos]), pos += pos & -pos;
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), p[i] = i;
  sort(p + 1, p + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    int x = p[i];
    PlusEqual(ans,
              Plus(mul(a[x], mul(x, n - x + 1)),
                   mul(Plus(mul(pre_query(x), n - x + 1), mul(suf_query(x), x)),
                       a[x])));
    pre_add(x, x);
    suf_add(x, n - x + 1);
  }
  printf("%d", ans);
  return 0;
}
