#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 1000;
long long n, a[maxn], tree[maxn];
long long mod = 1000 * 1000 * 1000 + 7;
void add(int x, int val) {
  for (; x < maxn; x += (x) & (-x)) tree[x] += val, tree[x] %= mod;
}
long long get(int x) {
  long long sum = 0;
  for (; x > 0; x -= (x) & (-x)) sum += tree[x];
  sum %= mod;
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  add(1, 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    long long res = get(a[i] + 1) * a[i] - (get(a[i] + 1) - get(a[i]));
    res = (res + mod) % mod;
    add(a[i] + 1, res);
  }
  cout << (get(maxn - 100) - 1 + mod) % mod << endl;
  return 0;
}
