#include <bits/stdc++.h>
using namespace std;
const long long X = 1111111, N = 111111;
long long a[N], dp[X];
long long n;
long long sum(long long x) {
  long long ans = 0;
  for (; x; x -= (x & (-x))) {
    ans = (ans + dp[x]) % 1000000007;
  }
  return ans + dp[0];
}
void add(long long x, long long k) {
  for (; x < X; x += (x & (-x))) {
    dp[x] = (dp[x] + k) % 1000000007;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = (1); i <= (n); i++) {
    cin >> a[i];
  }
  dp[0] = 1;
  for (long long i = (1); i <= (n); i++) {
    long long x = a[i];
    long long s = sum(x - 1) * x % 1000000007;
    long long dpx = (sum(x) - sum(x - 1) + 1000000007) % 1000000007;
    long long ss = (x - 1) * dpx % 1000000007;
    add(a[i], (s + ss) % 1000000007);
  }
  long long ans = (sum(X - 1) - 1 + 1000000007) % 1000000007;
  cout << ans << endl;
  return 0;
}
