#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
void add(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
int F[1000000 + 1];
void upd(int x, int v) {
  for (; x <= 1000000; x = (x | (x + 1))) add(F[x], v);
}
int get(int x) {
  int res = 0;
  for (; x >= 0; x = (x & (x + 1)) - 1) add(res, F[x]);
  return res;
}
int a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  upd(0, 1);
  for (int i = 0; i < n; i++) {
    int c1 = get(a[i] - 1), c2 = get(a[i]);
    upd(a[i], (-(c2 - c1) + MOD) % MOD);
    upd(a[i], (long long)c2 * a[i] % MOD);
  }
  cout << (get(1000000) - 1 + MOD) % MOD << "\n";
  return 0;
}
