#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 10;
const long long Mod = 1e9 + 7;
long long e[MAXN];
long long a[MAXN];
long long fen[MAXN];
void update(long long x, long long val) {
  for (; x < MAXN; x += ((x) & -(x))) {
    fen[x] += val;
    fen[x] %= Mod;
  }
}
long long get_sum(long long x) {
  long long sum = 0;
  for (; x > 0; x -= ((x) & -(x))) {
    sum += fen[x];
    sum %= Mod;
  }
  return sum;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= n; i++) {
    update(a[i], (((a[i] * (get_sum(a[i]) + 1)) % Mod) - get_sum(a[i]) +
                  get_sum(a[i] - 1) + Mod) %
                     Mod);
  }
  cout << get_sum(MAXN - 1);
}
