#include <bits/stdc++.h>
using namespace std;
long long N, M;
long long tree[1000005];
long long p[1000005];
void Add(long long x, long long ad) {
  long long i;
  for (i = x; i <= M; i += ((i) & (-(i))))
    tree[i] = (tree[i] + ad) % 1000000007;
}
long long Ask(long long x) {
  long long i, get = 0;
  for (i = x; i; i -= ((i) & (-(i)))) get = (tree[i] + get) % 1000000007;
  return get;
}
int main() {
  long long i, j, tmp;
  scanf("%I64d", &N);
  for (i = 1; i <= N; i++) scanf("%I64d", &p[i]), M = max(M, p[i]);
  for (i = 1; i <= N; i++) {
    tmp = Ask(p[i]);
    tmp = (tmp * p[i] + p[i]) % 1000000007;
    Add(p[i], (tmp - Ask(p[i]) + Ask(p[i] - 1) + 1000000007) % 1000000007);
  }
  printf("%I64d\n", Ask(M));
  return 0;
}
