#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 9, M = 1e9 + 7;
long long a[N], n, x, f[N];
void upd(long long x, long long v) {
  for (; x < N; x += x & -x) f[x] = (f[x] + v) % M;
}
long long gt(long long x) {
  long long ret = 0;
  for (; x; x -= x & -x) ret = (ret + f[x]) % M;
  return ret;
}
int main() {
  cin >> n;
  while (n--) {
    cin >> x;
    long long tmp = (gt(x) * x + x) % M;
    upd(x, (tmp - a[x] + M) % M);
    a[x] = tmp;
  }
  cout << gt(N - 1);
}
