#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long mod = 1e9 + 7;
const long double PI = acos(-1.0);
struct BIT {
  using T = long long;
  vector<T> arr;
  T total;
  BIT(T s = 1e6) {
    total = 0;
    arr.assign(s + 1, 0);
  }
  T sum(T pos) {
    T ans = 0;
    while (pos > 0) {
      ans += arr[pos];
      ans %= mod;
      pos = pos - (pos & (-pos));
    }
    return ans;
  }
  void update(T pos, T val) {
    while ((pos > 0) && (pos < arr.size())) {
      arr[pos] += val;
      arr[pos] %= mod;
      pos = pos + (pos & (-pos));
    }
  }
  T rQuery(T l, T r) { return sum(r) - sum(l - 1); }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, ans = 0;
  cin >> n;
  vector<long long> a(n), _a(n);
  map<long long, long long> id;
  for (long long i = 0; i < n; i++) {
    cin >> _a[i];
    a[i] = _a[i];
  }
  sort(_a.begin(), _a.end());
  BIT osetL(n + 1), osetR(n + 1);
  for (long long i = 0; i < n; i++) {
    id[_a[i]] = i + 1;
  }
  for (long long i = 0; i < n; i++) {
    ans += ((((i + 1) * (n - i)) % mod) * a[i]) % mod;
    ans %= mod;
    long long query = osetL.rQuery(1, id[a[i]]);
    ans += (((query * (n - i)) % mod) * a[i]) % mod;
    ans %= mod;
    osetL.update(id[a[i]], i + 1);
  }
  for (long long i = n - 1; i >= 0; i--) {
    long long query = osetR.rQuery(1, id[a[i]]);
    ans += (((query * (i + 1)) % mod) * a[i]) % mod;
    ans %= mod;
    osetR.update(id[a[i]], n - i);
  }
  cout << ans << '\n';
  return 0;
}
