#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
long long c[maxn];
long long dp[maxn];
long long a[maxn];
long long pre[maxn];
long long n;
long long lowbit(long long x) { return x & (-x); }
long long getsum(long long x) {
  long long ans = 0;
  while (x) {
    ans += c[x];
    ans %= mod;
    x -= lowbit(x);
  }
  return ans % mod;
}
void update(long long x, long long val) {
  while (x <= 1000010) {
    c[x] += val;
    c[x] %= mod;
    x += lowbit(x);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  memset(dp, 0, sizeof dp);
  memset(pre, -1, sizeof pre);
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    dp[i] = getsum(a[i]) * a[i] + a[i];
    if (pre[a[i]] != -1) dp[i] -= pre[a[i]];
    dp[i] = (dp[i] % mod + mod) % mod;
    ans += dp[i];
    ans = (ans % mod + mod) % mod;
    pre[a[i]] = getsum(a[i]) * a[i] + a[i];
    update(a[i], dp[i]);
  }
  cout << (ans % mod + mod) % mod << endl;
  return 0;
}
