#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e6 + 1314;
int read() {
  int k;
  scanf("%d", &k);
  return k;
}
int n;
int a[maxx], b[maxx];
struct XX {
  long long id, val;
} A[maxx];
long long S;
bool my(XX a, XX b) { return a.val < b.val; }
long long Ans = 0;
const int M = 1e9 + 7;
const int mx = 6e5 + 1314;
struct qwq {
  long long c[maxx];
  void add(int x, int v) {
    for (int i = x; i < mx; i += (i & -i)) c[i] += v, c[i] %= M;
  }
  long long sum(int x) {
    long long S = 0;
    for (int i = x; i; i -= (i & -i)) S += c[i], S %= M;
    return S;
  }
} AA, BB;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    A[i].id = i;
    A[i].val = read();
  }
  sort(A + 1, A + 1 + n, my);
  for (int i = 1; i <= n; i++) {
    int id = A[i].id;
    Ans += A[i].val * (1ll * A[i].id * (n - A[i].id + 1) % M) % M;
    Ans %= M;
    Ans += A[i].val * (1ll * AA.sum(id) * (n - id + 1) % M) % M;
    Ans %= M;
    Ans += A[i].val * (1l * id * ((BB.sum(n) - BB.sum(id)) % M + M) % M) % M;
    Ans %= M;
    AA.add(id, id);
    BB.add(id, n - id + 1);
  }
  cout << Ans << endl;
  return 0;
}
