#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
const int mod = 1e9 + 7;
int arr[maxn];
long long tree[maxn];
vector<int> all;
int getid(int x) {
  return lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
}
void add(int x, int val, int ty) {
  if (ty == 1) {
    while (x < maxn) {
      tree[x] = (tree[x] + val) % mod;
      x += x & -x;
    }
  } else {
    while (x > 0) {
      tree[x] = (tree[x] + val) % mod;
      x -= x & -x;
    }
  }
}
long long query(int x, int ty) {
  long long ret = 0;
  if (ty == 1) {
    while (x > 0) {
      ret = (ret + tree[x]) % mod;
      x -= x & -x;
    }
  } else {
    while (x < maxn) {
      ret = (ret + tree[x]) % mod;
      x += x & -x;
    }
  }
  return ret;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    all.push_back(arr[i]);
  }
  sort(all.begin(), all.end());
  all.erase(unique(all.begin(), all.end()), all.end());
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long pos = query(getid(arr[i]), 0);
    ans = (ans + pos * (n - i + 1) % mod) % mod;
    add(getid(arr[i]), 1LL * i * arr[i] % mod, 0);
    ;
  }
  memset(tree, 0, sizeof(tree));
  for (int i = n; i >= 1; i--) {
    long long pos = query(getid(arr[i]), 0);
    ans = (ans + pos * i % mod) % mod;
    add(getid(arr[i]), 1LL * (n - i + 1) * arr[i] % mod, 0);
    ;
  }
  for (int i = 1; i <= n; i++) {
    ans = (ans + 1LL * i * (n - i + 1) % mod * arr[i] % mod) % mod;
  }
  printf("%lld\n", ans);
}
