#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, N = 1e6, P = 1e9 + 7;
int n, x;
long long d, e, a[N + 10];
void add(int i, long long x) {
  for (; i <= N; i += i & (-i)) a[i] = (a[i] + x) % P;
}
long long sum(int i) {
  long long ans = 0;
  for (; i; i -= i & (-i)) ans = (ans + a[i]) % P;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) {
    scanf("%d", &x);
    d = sum(x), e = (d - sum(x - 1) + P) % P;
    add(x, (d * x % P + x % P - e + P) % P);
  }
  printf("%I64d", sum(N));
  return 0;
}
