#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 10;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int mul(int a, int b) { return (1LL * a * b) % mod; }
int add(int a, int b) { return (1LL * a + b) % mod; }
struct tree {
  vector<int> t;
  void init() { t.assign(N * 4, 0); }
  void modify(int v, int tl, int tr, int pos, int val) {
    if (tl == tr) {
      t[v] = val;
    } else {
      int tm = (tl + tr) / 2;
      if (pos <= tm) {
        modify(v * 2, tl, tm, pos, val);
      } else {
        modify(v * 2 + 1, tm + 1, tr, pos, val);
      }
      t[v] = add(t[v * 2], t[v * 2 + 1]);
    }
  }
  void modify(int pos, int val) { modify(1, 0, N, pos, val); }
  int get(int v, int tl, int tr, int l, int r) {
    if (l > r) {
      return 0;
    }
    if (tl == l && tr == r) {
      return t[v];
    }
    int tm = (tl + tr) / 2;
    int ql = get(v * 2, tl, tm, l, min(r, tm));
    int qr = get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
    return add(ql, qr);
  }
  int lower(int pos) { return get(1, 0, N, 0, pos); }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b = a;
  sort(b.begin(), b.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = add(ans, mul(a[i], mul(i + 1, n - i)));
  }
  tree c;
  c.init();
  for (int i = 0; i < n; i++) {
    int pos = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    c.modify(pos, i + 1);
    int res = mul(c.lower(pos - 1), a[i]);
    ans = add(ans, mul(res, n - i));
  }
  c.init();
  reverse(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    int pos = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
    c.modify(pos, i + 1);
    int res = mul(c.lower(pos - 1), a[i]);
    ans = add(ans, mul(res, n - i));
  }
  cout << ans << "\n";
  return 0;
}
