#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int N = 500005;
const long long MOD = 1e9 + 7;
struct Combinatorics {
  long long fac[N], inv[N];
  long long BigMod(long long b, long long p, long long m) {
    long long ret = 1;
    while (p > 0) {
      if (p % 2 == 1) ret = (ret * b) % m;
      p = p >> 1;
      b = (b * b) % m;
    }
    return ret;
  }
  void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++) fac[i] = (fac[i - 1] * i) % MOD;
    for (int i = 0; i < N; i++) inv[i] = BigMod(fac[i], MOD - 2, MOD);
  }
  long long com(long long n, long long r) {
    if (n < r) return 0;
    long long u = fac[n];
    long long v = (fac[r] * fac[n - r]) % MOD;
    return (u * BigMod(v, MOD - 2, MOD)) % MOD;
  }
} combi;
int n, ara[N];
int bit[2][N];
void update(int id, int idx, int val) {
  while (idx < N) {
    bit[id][idx] += val;
    bit[id][idx] %= MOD;
    idx += (idx & -idx);
  }
}
int query(int id, int idx) {
  long long ret = 0;
  while (idx > 0) {
    ret += bit[id][idx];
    idx -= (idx & -idx);
  }
  return ret % MOD;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  combi.init();
  vector<pair<int, int> > nums;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
    nums.push_back(make_pair(ara[i], i));
  }
  sort(nums.begin(), nums.end());
  long long ans = 0;
  for (long long i = 1; i <= n; i++)
    ans = (ans + ((i * (n - i + 1)) % MOD) * ara[i]) % MOD;
  for (auto x : nums) {
    int pos = x.second;
    long long lval = query(0, pos);
    long long rval = query(1, n) - query(1, pos - 1);
    long long ways = (lval * (n - pos + 1) + rval * pos) % MOD;
    ans = (ans + ways * x.first) % MOD;
    update(0, pos, pos);
    update(1, pos, n - pos + 1);
  }
  ans = (ans + MOD) % MOD;
  cout << ans << "\n";
}
