#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e6, MOD = 1e9 + 7;
long long fen[MAX], dp[MAX], n;
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() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long x, y;
    cin >> y;
    x = ((((g(y) + 1) * y) % MOD) - dp[y] + MOD) % MOD;
    dp[y] = (dp[y] + x) % MOD;
    upd(y, x);
  }
  cout << g(1e6);
}
