#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
const long long MOD = 1e9 + 7;
struct BIT {
  long long N;
  vector<long long> bit;
  void init(long long n) {
    N = n;
    bit.assign(n + 1, 0);
  }
  void update(long long idx, long long val) {
    idx++;
    while (idx <= N) {
      bit[idx] += val;
      bit[idx] %= MOD;
      idx += idx & -idx;
    }
  }
  void updateMax(long long idx, long long val) {
    while (idx <= N) {
      bit[idx] = max(bit[idx], val);
      idx += idx & -idx;
    }
  }
  long long pref(long long idx) {
    idx++;
    long long ans = 0;
    while (idx > 0) {
      ans += bit[idx];
      idx -= idx & -idx;
    }
    ans %= MOD;
    return ans;
  }
  long long rsum(long long l, long long r) {
    return (pref(r) - pref(l - 1) + MOD) % MOD;
  }
  long long prefMax(long long idx) {
    long long ans = -2e9;
    while (idx > 0) {
      ans = max(ans, bit[idx]);
      idx -= idx & -idx;
    }
    return ans;
  }
};
long long n;
long long a[N], dp[N];
BIT bit;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  bit.init(1e6 + 5);
  dp[0] = 1;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) {
    dp[i] = bit.pref(a[i]) * a[i] + a[i];
    dp[i] %= MOD;
    dp[i] += MOD;
    dp[i] %= MOD;
    bit.update(a[i], (dp[i] - bit.rsum(a[i], a[i]) + MOD) % MOD);
  }
  long long ans = bit.pref(1e6);
  cout << ans;
  return 0;
}
