#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
inline long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
inline long long power(long long a, long long n, long long m) {
  if (n == 0) return 1;
  long long p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const long long N = 500005;
long long bit[500005];
long long bit1[N];
long long getparent(long long i) { return i - (i & (-i)); }
long long getnext(long long i) { return (i + (i & (-i))); }
void update(long long i, long long val) {
  while (i < N) {
    bit[i] = (bit[i] % MOD + val % MOD) % MOD;
    i = getnext(i);
  }
}
long long getsum(long long r) {
  long long sum = 0;
  while (r > 0) {
    sum = (sum % MOD + bit[r] % MOD) % MOD;
    r = getparent(r);
  }
  return sum;
}
void update1(long long i, long long val) {
  while (i < N) {
    bit1[i] = bit1[i] + val;
    i = getnext(i);
  }
}
long long getsum1(long long r) {
  long long sum = 0;
  while (r > 0) {
    sum = sum + bit1[r];
    r = getparent(r);
  }
  return sum;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n;
  cin >> n;
  pair<long long, long long> a[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  long long x, in, k, ans, sum = 0, s;
  for (long long i = 1; i <= n; i++) {
    x = a[i].first;
    in = a[i].second;
    k = getsum1(N - 1) - getsum1(in);
    update(in, in);
    update1(in, 1);
    s = (getsum(N - 1) - getsum(in - 1) + MOD) % MOD;
    ans = (((k + 1) % MOD * (n + 1) % MOD) % MOD - s % MOD + MOD) % MOD;
    ans = (in % MOD * ans % MOD) % MOD;
    s = getsum(in - 1);
    s = (s % MOD * (n + 1 - in) % MOD) % MOD;
    ans = (ans % MOD + s % MOD) % MOD;
    ans = (ans % MOD * x % MOD) % MOD;
    sum = (sum % MOD + ans % MOD) % MOD;
  }
  cout << sum << "\n";
  return 0;
}
