#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct BIT {
  int n;
  vector<int> f;
  BIT(int n_) {
    n = n_;
    f.resize(n + 1);
  }
  void update(int i, int delta) {
    for (; i <= n; i += i & -i) (f[i] += delta) %= MOD;
  }
  int query(int i) {
    int sum = 0;
    for (; i; i -= i & -i) (sum += f[i]) %= MOD;
    return sum;
  }
};
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a;
  a.reserve(n + 1);
  a.emplace_back(0, 0);
  int tmp;
  for (int i = 1; i <= n; ++i) {
    cin >> tmp;
    a.emplace_back(tmp, i);
  }
  sort(a.begin() + 1, a.end());
  unsigned long long ans = 0;
  BIT b1(n), b2(n);
  for (int i = 1; i <= n; ++i) {
    int val = a[i].first, pos = a[i].second;
    long long left = b1.query(pos - 1);
    long long right = b2.query(n - pos);
    long long cnt = (1LL * (pos - 1) * (n - pos) + n) % MOD;
    (cnt += pos * right) %= MOD;
    (cnt += (n - pos + 1) * left) %= MOD;
    (ans += cnt * val) %= MOD;
    b1.update(pos, pos);
    b2.update(n + 1 - pos, n + 1 - pos);
  }
  cout << ans << endl;
}
