#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const long long mod = 1000000000LL + 7;
long long c[N], d[N];
int n;
int lowbit(int x) { return x & (-x); }
void addl(int x, int y) {
  for (int i = x; i <= n; i += lowbit(i)) c[i] += y;
}
void addr(int x, int y) {
  for (int i = x; i <= n; i += lowbit(i)) d[i] += y;
}
long long getlsum(int x) {
  long long ans = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) {
    ans += c[i];
    ans %= mod;
  }
  return ans;
}
long long getrsum(int x) {
  long long ans = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) {
    ans += d[i];
    ans %= mod;
  }
  return ans;
}
pair<int, int> a[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a + 1, a + 1 + n);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long x = getlsum(a[i].second);
    long long tmp = 0;
    tmp += x * (n - a[i].second + 1);
    tmp %= mod;
    long long y = getrsum(n - a[i].second + 1);
    tmp += y * a[i].second;
    tmp %= mod;
    tmp += 1LL * a[i].second * (n - a[i].second + 1);
    tmp %= mod;
    ans += tmp * a[i].first;
    ans %= mod;
    addl(a[i].second, a[i].second);
    addr(n - a[i].second + 1, n - a[i].second + 1);
  }
  ans += mod;
  printf("%lld\n", ans % mod);
  return 0;
}
