#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const long long mod = 1e9 + 7;
int n, t[maxn], num[maxn];
map<int, int> ma;
long long zz[maxn], tree[maxn];
void add(int x, int y) {
  for (int i = x; i <= n; i += (i & (-i))) tree[i] += y;
}
long long quer(int x) {
  long long res = 0;
  for (int i = x; i; i -= (i & (-i))) res += tree[i];
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    t[i] = num[i];
  }
  sort(t + 1, t + n + 1);
  for (int i = 1; i <= n; i++) ma[t[i]] = i;
  for (int i = 1; i <= n; i++) {
    zz[i] = quer(ma[num[i]]) * (n - i + 1) % mod;
    add(ma[num[i]], i);
  }
  for (int i = 1; i <= n; i++) tree[i] = 0;
  for (int i = n; i >= 1; i--) {
    zz[i] = (zz[i] + quer(ma[num[i]]) * i % mod) % mod;
    add(ma[num[i]], n - i + 1);
    zz[i] = (zz[i] + (long long)(n - i + 1) * i % mod) % mod;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans = (ans + (long long)num[i] * zz[i] % mod) % mod;
  printf("%lld\n", ans);
  return 0;
}
