#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
const long long MOD = 1000000007;
struct node {
  int id;
  long long num;
  node(int _id = 0, long long _num = 0) : id(_id), num(_num) {}
};
bool cmp1(const node& x, const node& y) { return x.num < y.num; }
bool cmp2(const node& x, const node& y) { return x.id < y.id; }
inline void read(long long& re) {
  re = 0;
  long long flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    re = (re << 1) + (re << 3) + ch - '0';
    ch = getchar();
  }
  re *= flag;
}
long long a[N + 100], t[N + 100];
node p[N + 100];
int n = 0;
void update(long long u, int x) {
  while (u <= n) {
    t[u] += x;
    u += u & (-u);
  }
}
long long query(int l, int r) {
  long long sum1 = 0, sum2 = 0;
  l--;
  while (l > 0) {
    sum1 += t[l];
    l -= l & (-l);
  }
  while (r > 0) {
    sum2 += t[r];
    r -= r & (-r);
  }
  return (sum2 - sum1 + MOD) % MOD;
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    read(a[i]);
    p[i].id = i;
    p[i].num = a[i];
  }
  sort(p + 1, p + n + 1, cmp1);
  for (i = 1; i <= n; i++) p[i].num = (long long)i;
  sort(p + 1, p + n + 1, cmp2);
  long long ans = 0;
  for (i = 1; i <= n; i++) ans += ((a[i] * i) % MOD) * (n - i + 1) % MOD;
  memset(t, 0, sizeof(t));
  for (i = n; i >= 1; i--) {
    ans = (ans + query(p[i].num, n) * i) % MOD;
    update(p[i].num, (a[i] * (n - i + 1)) % MOD);
  }
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) {
    ans = (ans + query(p[i].num, n) * (n - i + 1)) % MOD;
    update(p[i].num, (a[i] * i) % MOD);
  }
  printf("%lld\n", ans);
  return 0;
}
