#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 1e6 + 10;
long long n, s[maxn], x, ans, last[maxn];
long long lowbit(long long x) { return x & (-x); }
void add(long long id, long long x) {
  for (long long i = id; i <= 1e6; i += lowbit(i)) s[i] = (s[i] + x) % mod;
}
long long sum(long long id) {
  long long ans = 0;
  for (long long i = id; i > 0; i -= lowbit(i)) ans = (ans + s[i]) % mod;
  return ans;
}
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &x);
    long long tmp = (((sum(x) + 1) * x % mod - last[x]) % mod + mod) % mod;
    add(x, tmp);
    ans = (ans + tmp) % mod;
    last[x] = (last[x] + tmp) % mod;
  }
  if (ans < 0) ans += mod;
  printf("%lld\n", ans);
  return 0;
}
