#include <bits/stdc++.h>
using namespace std;
struct node {
  int val[2];
  node *lef, *righ;
  node() {
    val[0] = val[1] = 0;
    lef = righ = nullptr;
  }
} * root;
int lef, righ, val, val1, pos, mij, ok;
void update(node *act, int st, int dr) {
  if (st == dr) {
    act->val[0] = val;
    act->val[1] = val1;
    return;
  }
  if (act->lef == nullptr) {
    act->lef = new node;
    act->righ = new node;
  }
  mij = (st + dr) / 2;
  if (pos <= mij)
    update(act->lef, st, mij);
  else
    update(act->righ, mij + 1, dr);
  act->val[0] = act->lef->val[0] + act->righ->val[0];
  act->val[1] = act->lef->val[1] + act->righ->val[1];
  act->val[0] %= 1000000007;
  act->val[1] %= 1000000007;
}
int query(node *act, int st, int dr) {
  if (act->val[ok] == 0 || (lef <= st && dr <= righ)) return act->val[ok];
  int mij = (st + dr) / 2, ans = 0;
  if (lef <= mij) ans = query(act->lef, st, mij);
  if (mij < righ) ans += query(act->righ, mij + 1, dr);
  return ans % 1000000007;
}
int main() {
  long long sum = 0, ans = 0, x;
  int n, i;
  root = new node;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    lef = 1;
    righ = x;
    ok = 0;
    sum = (sum + x * (query(root, 1, 1000000000) + i)) % 1000000007;
    lef = x;
    righ = 1000000000;
    ok = 1;
    sum = (sum + query(root, 1, 1000000000)) % 1000000007;
    ans = (ans + sum) % 1000000007;
    pos = x;
    val = i;
    val1 = (i * x) % 1000000007;
    update(root, 1, 1000000000);
  }
  cout << ans << '\n';
  return 0;
}
