#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 100;
long long mod = 1e9 + 7;
long long f[maxn], n, a[maxn], ans;
vector<int> v;
void add(int i, int j) {
  for (; i < maxn; i += i & -i) f[i] = (f[i] + j) % mod;
}
long long get(int i) {
  long long ret = 0;
  for (; i; i -= i & -i) ret = (ret + f[i]) % mod;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int y = 1; y <= n; y++) {
    cin >> a[y], v.push_back(a[y]);
    ans = (ans + (y * (n + 1 - y) % mod * a[y])) % mod;
  }
  sort(v.begin(), v.end());
  for (int y = 1; y <= n; y++) {
    int x = lower_bound(v.begin(), v.end(), a[y]) - v.begin() + 1;
    long long p = get(x);
    ans = (ans + p * a[y] % mod * (n + 1 - y) % mod) % mod;
    add(x, y);
  }
  reverse(a + 1, a + 1 + n);
  memset(f, 0, sizeof f);
  for (int y = 1; y <= n; y++) {
    int x = lower_bound(v.begin(), v.end(), a[y]) - v.begin() + 1;
    long long p = get(x);
    ans = (ans + p * a[y] % mod * (n + 1 - y) % mod) % mod;
    add(x, y);
  }
  cout << ans;
}
