#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int x[100001], a[100001];
int s, e;
int v[400001];
void Build(int l, int r, int id) {
  if (l == r) {
    x[l] = id;
    return;
  }
  Build(l, (l + r) / 2, id * 2);
  Build((l + r) / 2 + 1, r, id * 2 + 1);
}
long long Sum(int l, int r, int id) {
  if (l > e || r < s) return 0;
  if (l >= s && r <= e) return v[id];
  return (Sum(l, (l + r) / 2, id * 2) + Sum((l + r) / 2 + 1, r, id * 2 + 1)) %
         mod;
}
void Update(int h) {
  h = h / 2;
  while (h > 0) {
    v[h] = (v[h * 2] + v[h * 2 + 1]) % mod;
    h /= 2;
  }
}
vector<int> c[1000001];
long long ans;
int main() {
  int n;
  cin >> n;
  Build(1, n, 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) c[a[i]].push_back(i);
  for (long long i = 1e6; i > 0; --i) {
    if (!(c[i].size())) continue;
    s = c[i][c[i].size() - 1] + 1;
    e = n;
    v[x[c[i][c[i].size() - 1]]] = (Sum(1, n, 1) % mod * i + i) % mod;
    e = s - 1;
    Update(x[c[i][c[i].size() - 1]]);
    ans = (ans + v[x[c[i][c[i].size() - 1]]]) % mod;
    for (int j = c[i].size() - 2; j >= 0; --j) {
      s = c[i][j] + 1;
      v[x[c[i][j]]] = Sum(1, n, 1) % mod * i % mod;
      ans = (ans + v[x[c[i][j]]]) % mod;
      Update(x[c[i][j]]);
      e = s - 1;
    }
  }
  cout << ans;
}
