#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long add(long long a, long long b) {
  a += b;
  if (a < 0) {
    a += MOD;
  }
  if (a >= MOD) {
    a -= MOD;
  }
  return a;
}
long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
long long mult(long long a, long long b) { return a * b % MOD; }
template <class T>
struct Seg {
  const T ID = 0;
  T comb(T a, T b) { return a + b; }
  long long n;
  vector<T> seg;
  void init(long long _n) {
    n = _n;
    seg.assign(4 * n, ID);
  }
  void pull(long long p) { seg[p] = comb(seg[2 * p], seg[2 * p + 1]); }
  void upd(long long p, T val) {
    seg[p += n] = val;
    for (p /= 2; p; p /= 2) pull(p);
  }
  T query(long long l, long long r) {
    if (r < l) return 0;
    T ra = ID, rb = ID;
    for (l += n, r += n + 1; l < r; l /= 2, r /= 2) {
      if (l & 1) ra = comb(ra, seg[l++]);
      if (r & 1) rb = comb(seg[--r], rb);
    }
    return comb(ra, rb);
  }
};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  vector<array<long long, 2>> vals;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    vals.push_back({a[i], i});
  }
  sort((vals).begin(), (vals).end());
  Seg<long long> l, r;
  l.init(n);
  r.init(n);
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    auto [val, ind] = vals[i];
    long long toleft = ind + 1, toright = n - ind;
    ans = add(ans, mult(val, add(mult(toright, l.query(0, ind)),
                                 mult(toleft, r.query(ind, n - 1)))));
    ans = add(ans, mult(mult(toleft, toright), val));
    l.upd(ind, toleft);
    r.upd(ind, toright);
  }
  cout << ans << "\n";
}
