#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
long long n;
long long a[N];
long long b[N];
long long c[N];
long long t[N];
long long cnt[N];
long long ans;
int lowbit(int x) { return x & (-x); }
void update(int x, int y) {
  while (x <= n) {
    c[x] += y;
    c[x] %= MOD;
    x += lowbit(x);
  }
}
long long query(int x) {
  long long res = 0;
  while (x) {
    res += c[x];
    res %= MOD;
    x -= lowbit(x);
  }
  return res;
}
long long find(long long x) {
  int l = 1, r = n, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (b[mid] < x)
      l = mid + 1;
    else if (b[mid] > x)
      r = mid - 1;
    else
      return mid;
  }
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), t[i] = b[i] = a[i];
  std::sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i) {
    long long num = find(a[i]);
    update(num, i);
    cnt[i] = (cnt[i] + query(num - 1) * (n - i + 1) % MOD) % MOD;
  }
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= n; ++i) a[i] = b[i] = t[n - i + 1];
  std::sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i) {
    long long num = find(a[i]);
    update(num, i);
    cnt[n - i + 1] =
        (cnt[n - i + 1] + query(num - 1) * (n - i + 1) % MOD) % MOD;
  }
  for (int i = 1; i <= n; ++i) cnt[i] = (cnt[i] + i * (n - i + 1) % MOD) % MOD;
  for (int i = 1; i <= n; ++i) ans = (ans + cnt[i] * t[i] % MOD) % MOD;
  printf("%lld\n", ans);
  return 0;
}
