#include <bits/stdc++.h>
using namespace std;
long long n, a[(long long)5e5 + 1], k = 1;
long long bit[(long long)5e5 + 10];
void add(long long id, long long val) {
  for (long long i = id; i <= n + 1; i += (i & (-i))) bit[i] += val;
}
long long sum(long long r) {
  long long ans = 0;
  for (long long i = r; i > 0; i -= (i & (-i))) ans += bit[i];
  return ans;
}
map<long long, long long> m;
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> a[i];
  set<long long> s(a, a + n);
  for (long long i : s) m[i] = k++;
  long long ans = 0;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    ans = (ans + ((((i + 1) * (n - i)) % 1000000007) * a[i]) % 1000000007) %
          1000000007;
    long long ans1 = 0;
    ans1 = (ans1 + sum(m[a[i]]));
    ans1 = (ans1 * (n - i)) % 1000000007;
    ans = (ans + (ans1 * a[i]) % 1000000007) % 1000000007;
    add(m[a[i]], i + 1);
  }
  for (__typeof(n + 2) i = (0) - ((0) > (n + 2));
       i != (n + 2) - ((0) > (n + 2)); i += 1 - 2 * ((0) > (n + 2)))
    bit[i] = 0;
  reverse(a, a + n);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    long long ans1 = 0;
    ans1 = (ans1 + sum(m[a[i]]));
    ans1 = (ans1 * (n - i)) % 1000000007;
    ans = (ans + (ans1 * a[i]) % 1000000007) % 1000000007;
    add(m[a[i]], i + 1);
  }
  cout << ans << '\n';
}
