#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7;
long long fen[N], n, a[N], dp[N];
void add(int pos, long long val) {
  for (pos++; pos < N; pos += pos & (-pos))
    (fen[pos] += val) %= mod, (fen[pos] += mod) %= mod;
}
long long get(int pos) {
  long long res = 0;
  for (pos++; pos; pos -= pos & (-pos)) (res += fen[pos]) %= mod;
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long upt = (get(a[i]) * a[i]);
    upt %= mod;
    (upt += a[i]) %= mod;
    add(a[i], -dp[a[i]]);
    dp[a[i]] = upt;
    add(a[i], dp[a[i]]);
  }
  for (int i = 0; i < N; i++) (ans += dp[i]) %= mod;
  cout << ans << "\n";
}
