#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long arr[500001];
long long tree[500001][2];
int N;
void push(int pos, long long val, int t) {
  while (pos <= N) {
    tree[pos][t] = (tree[pos][t] + val) % MOD;
    pos += pos & -pos;
  }
}
long long get(int pos, int t) {
  long long ret = 0ll;
  while (pos) {
    ret = (ret + tree[pos][t]) % MOD;
    pos -= pos & -pos;
  }
  return ret;
}
int main() {
  scanf("%d", &N);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      pq;
  for (int i = 1; i <= N; i++) {
    long long tmp;
    scanf("%lld", &tmp);
    pq.push(pair<long long, int>(tmp, i));
  }
  long long ret = 0ll;
  while (!pq.empty()) {
    pair<long long, int> tmp = pq.top();
    pq.pop();
    push(tmp.second, (long long)tmp.second, 0);
    ret = (ret + tmp.first *
                     ((N + 1 - tmp.second) * get(tmp.second, 0) % MOD +
                      tmp.second * get(tmp.second, 1) % MOD) %
                     MOD) %
          MOD;
    push(1, (long long)N + 1 - tmp.second, 1);
    push(tmp.second, MOD - N - 1 + tmp.second, 1);
  }
  printf("%lld", ret);
}
