#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10, mod = 1e9 + 7;
long long a[maxn], bit[maxn], last[maxn];
long long dp[maxn];
void add(long long x, long long v) {
  x++;
  for (; x < maxn; x += x & -x) bit[x] = (bit[x] + v) % mod;
}
long long query(long long x) {
  x++;
  long long ret = 0;
  for (; x; x -= x & -x) ret = (ret + bit[x]) % mod;
  return ret;
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  add(0, 1);
  for (long long i = 1; i <= n; i++) {
    long long here = query(a[i]) - last[a[i]];
    last[a[i]] = query(a[i]);
    dp[i] = (here * a[i]) % mod;
    if (dp[i] < 0) dp[i] += mod;
    add(a[i], dp[i]);
  }
  long long res = 0;
  for (long long i = 1; i <= n; i++) res = (res + dp[i]) % mod;
  cout << res << endl;
  return 0;
}
