#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int mod = 1e9 + 7;
int n, num, ans;
int a[maxn], b[maxn], sum[maxn];
inline int read() {
  char c = getchar();
  int res = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar();
  return res * f;
}
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int dec(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
struct Tree_arry {
  int a[maxn];
  inline void clear() {
    for (int i = 1; i <= num; i++) a[i] = 0;
  }
  inline void add(int x, int k) {
    for (int i = x; i <= num; i += (i & -i)) a[i] = (a[i] + k) % mod;
  }
  inline int query(int x) {
    int res = 0;
    for (int i = x; i; i -= (i & -i)) res = (res + a[i]) % mod;
    return res;
  }
} tr;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = b[i] = read();
  sort(b + 1, b + n + 1);
  num = unique(b + 1, b + n + 1) - (b + 1);
  for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + num + 1, a[i]) - b;
  for (int i = 1; i <= n; i++) sum[i] = 1ll * i * (n - i + 1) % mod;
  for (int i = 1; i <= n; i++) {
    sum[i] = add(sum[i], 1ll * (n - i + 1) * tr.query(a[i]) % mod);
    tr.add(a[i], i);
  }
  tr.clear();
  for (int i = n; i; i--) {
    sum[i] = add(sum[i], 1ll * i * tr.query(a[i]) % mod);
    tr.add(a[i], n - i + 1);
  }
  for (int i = 1; i <= n; i++) ans = add(ans, 1ll * sum[i] * b[a[i]] % mod);
  printf("%d", ans);
  return 0;
}
