#include <bits/stdc++.h>
using namespace std;
const long p = 1000000007;
const long N = 1000005;
long n, m, x, y, i, a[N], c[N];
long get(long x) {
  long long ans = 0;
  for (; x > 0; x -= x & (-x)) ans += c[x];
  return ans % p;
}
void add(long x, long v) {
  for (; x <= m; x += x & (-x)) c[x] = (c[x] + v) % p;
}
int main() {
  scanf("%ld", &n);
  m = N - 5;
  for (i = 1; i <= n; i++) {
    scanf("%ld", &x);
    y = (1ll * get(x) * x + x) % p;
    add(x, (y - a[x] + p) % p);
    a[x] = y;
  }
  printf("%ld\n", get(m) % p);
  return 0;
}
