#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10, MAX = 1e6 + 1e4, MOD = 1e9 + 7, MAXL = 25;
void OUT(long double o, int x) {
  cout << fixed << setprecision(x) << o;
  return;
}
long long a[MAX], fen[MAX], dp[MAX];
void upd(int v, int x) {
  for (; v <= 1e6; v += v & -v) fen[v] = (fen[v] + x) % MOD;
}
long long g(int v) {
  long long z = 0;
  for (; v; v -= v & -v) z = (z + fen[v]) % MOD;
  return z;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    long long x = ((((g(a[i]) + 1) * a[i]) % MOD) - dp[a[i]] + MOD) % MOD;
    dp[a[i]] = (dp[a[i]] + x) % MOD;
    upd(a[i], x);
  }
  cout << g(1e6);
  return 0;
}
