#include <bits/stdc++.h>
using namespace std;
int n;
int seq[100011];
long long dp[1000001], mod = 1000000007LL;
long long s[1000001];
int lowbit(int x) { return x & (-x); }
void update(int pos, long long val) {
  while (pos <= 1000000) {
    s[pos] = (s[pos] + val) % mod;
    pos += lowbit(pos);
  }
}
long long findSum(int pos) {
  long long ret = 0;
  while (pos) {
    ret = (ret + s[pos]) % mod;
    pos -= lowbit(pos);
  }
  return ret;
}
int MAIN() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> seq[i];
  memset(dp, 0, sizeof(dp));
  memset(s, 0, sizeof(s));
  for (int i = n; i >= 1; i--) {
    long long t = 1 + findSum(1000000) - findSum(seq[i] - 1);
    t %= mod;
    t += mod;
    t %= mod;
    update(seq[i], -dp[seq[i]]);
    dp[seq[i]] = (t * seq[i]) % mod;
    update(seq[i], dp[seq[i]]);
  }
  long long ans = 0;
  for (int i = 1; i <= 1000000; i++) ans += dp[i], ans %= mod;
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  return MAIN();
}
