#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MAX = 1e6;
const int mod = 1e9 + 7;
int n;
int a[N], lst[MAX + 1];
long long ft[MAX + 1], dp[N];
long long query(int idx) {
  long long ret = 0;
  for (; idx; idx -= idx & -idx) {
    ret = (ret + ft[idx]) % mod;
  }
  return ret;
}
void add(int idx, long long val) {
  for (; idx <= MAX; idx += idx & -idx) ft[idx] = (ft[idx] + val) % mod;
}
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++) {
    dp[i] = (1 + query(a[i])) * a[i] % mod;
    dp[i] = (dp[i] - query(a[i]) + query(a[i] - 1) + mod) % mod;
    add(a[i], dp[i] % mod);
  }
  ans = query(1e6);
  cout << ans << '\n';
  return 0;
}
