#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10, M = 1e9 + 7;
struct Bit {
  long long bit[N + 1];
  void init() { memset(bit, 0, sizeof(bit)); }
  void A(int i, int x) {
    while (i <= N) bit[i] += x, i += i & -i;
  }
  long long Q(int i) {
    long long s = 0;
    while (i > 0) s += bit[i], i -= i & -i;
    return s;
  }
} tree;
long long n;
long long a[N], b[N];
map<int, int> m;
int id;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans = (ans + a[i] * i % M * (n - i + 1) % M) % M;
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; i++) m[b[i]] = ++id;
  tree.init();
  for (int i = 1; i <= n; i++) {
    long long t = tree.Q(m[a[i]]) % M;
    tree.A(m[a[i]], i);
    t = t * (n - i + 1) % M;
    t = t * a[i] % M;
    ans = (ans + t) % M;
  }
  tree.init();
  for (int i = n; i; i--) {
    long long t = tree.Q(m[a[i]]) % M;
    t = t * i % M;
    tree.A(m[a[i]], n - i + 1);
    t = t * a[i] % M;
    ans = (ans + t) % M;
  }
  cout << ans << endl;
  return 0;
}
