#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500002;
const int MOD = 1000000007;
struct fenwick_tree {
  int n;
  vector<int64_t> bit;
  fenwick_tree(int n) : n(n) { bit.resize(n + 1); }
  void upd(int idx, int val) {
    for (; idx <= n; idx += idx & -idx) bit[idx] += val;
  }
  int64_t get(int idx) {
    int64_t res = 0;
    for (; idx > 0; idx -= idx & -idx) res += bit[idx];
    return res;
  }
  int64_t get(int u, int v) { return get(v) - get(u - 1); }
};
int n, a[MAX_N];
void read_input() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
}
void solve() {
  vector<pair<int, int>> b;
  fenwick_tree tree1(n), tree2(n);
  for (int i = 1; i <= n; ++i) b.push_back({a[i], i});
  sort(b.begin(), b.end());
  int64_t res = 0;
  for (auto x : b) {
    tree1.upd(x.second, n - x.second + 1);
    tree2.upd(x.second, x.second);
    res = (res + tree1.get(x.second + 1, n) * x.second % MOD * x.first) % MOD;
    res = (res + tree2.get(1, x.second) * (n - x.second + 1) % MOD * x.first) %
          MOD;
  }
  cout << res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  read_input();
  solve();
}
