#include <bits/stdc++.h>
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
using namespace std;
int a[MAXN];
long long BIT[4 * MAXN];
long long dp[MAXN];
long long sum(int ind) {
  ind++;
  long long ret = 0;
  while (ind > 0) {
    ret = (ret + BIT[ind]) % MOD;
    ind -= ind & -ind;
  }
  return ret;
}
void add(int ind, int val) {
  ind++;
  while (ind < MAXN) {
    BIT[ind] = (BIT[ind] + val) % MOD;
    if (BIT[ind] < 0) BIT[ind] += MOD;
    ind += ind & -ind;
  }
}
int main() {
  int n;
  scanf("%d", &(n));
  for (int i = 0; i < (n); i++) scanf("%d", &(a[i]));
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long tmp = (1 + sum(a[i])) % MOD;
    add(a[i], -dp[a[i]]);
    dp[a[i]] = (tmp * a[i]) % MOD;
    add(a[i], dp[a[i]]);
  }
  for (int i = 1; i < MAXN; i++) ans = (ans + dp[i]) % MOD;
  printf("%I64d\n", (ans));
  return 0;
}
