#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  while (c < 48) c == '-' && (f = -1), c = getchar();
  while (c > 47) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int MAXN = 500005;
const int MOD = 1000000007;
int s[MAXN], a[MAXN], b[MAXN];
int c[MAXN], cnt[MAXN];
int n;
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline void modify(int i, int t) {
  while (i <= n) s[i] = add(s[i], t), i += i & -i;
}
inline int query(int i) {
  int res = 0;
  while (i) res = add(res, s[i]), i -= i & -i;
  return res;
}
int main(int argc, char const *argv[]) {
  int x, ans = 0;
  n = read();
  for (int i = 1; i <= n; ++i) b[i] = c[i] = a[i] = read();
  sort(b + 1, b + 1 + n);
  for (int i = 1; i <= n; ++i) {
    x = lower_bound(b + 1, b + 1 + n, a[i]) - b;
    modify(x, i);
    cnt[i] = (cnt[i] + (long long)query(x - 1) * (n - i + 1)) % MOD;
  }
  memset(s, 0, sizeof(s));
  reverse(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i) {
    x = lower_bound(b + 1, b + 1 + n, a[i]) - b;
    modify(x, i);
    cnt[n - i + 1] =
        (cnt[n - i + 1] + (long long)query(x - 1) * (n - i + 1)) % MOD;
  }
  for (int i = 1; i <= n; ++i)
    ans = (ans + (cnt[i] + (long long)i * (n - i + 1)) % MOD * c[i]) % MOD;
  printf("%d", ans);
  return 0;
}
