#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = std::numeric_limits<long long>::max();
const int MX = 100101;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;
template <typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first + b.first, a.second + b.second);
}
template <typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first - b.first, a.second - b.second);
}
template <typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.first + a.second * b.second);
}
template <typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.second - a.second * b.first);
}
struct FENWICK {
  vector<long long> A;
  long long N;
  FENWICK(int n) : N(n) { A.resize(n + 1, 0); }
  void add(int i, long long first) {
    for (; i <= N; i += (i) & (-i)) A[i] += first;
  }
  long long getQ(int i) {
    long long get = 0;
    for (; i > 0; i -= (i) & (-i)) get += A[i];
    return get;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<long long> sk(N);
  for (int i = 0; i < N; ++i) cin >> sk[i];
  FENWICK iskair(N);
  FENWICK isdes(N);
  long long ats = 0;
  for (long long i = 0; i < N; ++i) {
    ats += (((sk[i] * (i + 1)) % MOD) * (N - i)) % MOD;
    ats %= MOD;
  }
  vector<pair<int, int> > sk2(N);
  for (int i = 0; i < N; ++i) sk2[i] = {sk[i], i + 1};
  sort(sk2.begin(), sk2.end());
  for (int i = 0; i < N; ++i) {
    int ind = sk2[i].second;
    long long nuogalo = isdes.getQ(N) - isdes.getQ(ind - 1);
    long long pir = ((N - ind + 1) * iskair.getQ(ind)) % MOD;
    long long ant = (ind * nuogalo) % MOD;
    ats += (sk2[i].first * (pir + ant)) % MOD;
    ats %= MOD;
    iskair.add(ind, ind);
    isdes.add(ind, N - ind + 1);
  }
  printf("%lld\n", ats);
}
