#include <bits/stdc++.h>
using namespace std;
const int md = (int)1e9 + 7;
const int N = 500010;
int tree[N];
int ret = 0;
void add(int &x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
}
void update(int x, int delta) {
  for (; x < N; x = (x | (x + 1))) {
    add(tree[x], delta);
  }
}
int query(int x) {
  int ret = 0;
  for (; x >= 0; x = (x & (x + 1)) - 1) {
    add(ret, tree[x]);
  }
  return ret;
}
void get(vector<int> a, vector<int> b) {
  int n = (int)a.size();
  memset(tree, 0, sizeof(tree));
  for (int i = 0; i < n; i++) {
    int now = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    int s = query(now - 1);
    add(ret, 1LL * s * (n - i) % md * a[i] % md);
    update(now, i + 1);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    add(ret, 1LL * (i + 1) * (n - i) % md * a[i] % md);
  }
  get(a, b);
  reverse(a.begin(), a.end());
  get(a, b);
  printf("%d\n", ret);
  return 0;
}
