#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long tree[2000005 * 4];
long long dp[2000005];
long long from[2000005];
long long a[200005];
long long n, poss = 1, ans = 0;
void add(long long x, long long k) {
  for (x; x <= 2000000; x += (x & -x)) {
    tree[x] += k;
    tree[x] %= mod;
  }
}
long long sum(long long k) {
  long long anss = 0;
  for (k; k; k -= (k & -k)) anss += tree[k], anss = (anss % mod + mod) % mod;
  return anss;
}
signed main() {
  scanf("%lld", &n);
  memset(from, -1, sizeof(from));
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i <= n; i++) {
    dp[i] = (sum(a[i]) * a[i] % mod + a[i]) % mod;
    if (from[a[i]] != -1) dp[i] -= from[a[i]];
    dp[i] = (dp[i] % mod + mod) % mod;
    ans += dp[i];
    ans = (ans % mod + mod) % mod;
    from[a[i]] = (sum(a[i]) * a[i] + a[i]) % mod;
    add(a[i], dp[i]);
  }
  cout << ans % mod;
}
