#include <bits/stdc++.h>
using namespace std;
const long long lmt = 1e6;
const long long mod = 1e9 + 7;
long long tree[lmt + 10], n, ans, baad[lmt + 10];
long long read(long long indx) {
  long long sum = 0;
  while (indx > 0) {
    sum = (sum + tree[indx]) % mod;
    indx -= (indx & -indx);
  }
  return sum;
}
void update(long long indx, long long val) {
  while (indx <= lmt) {
    tree[indx] = (tree[indx] + val) % mod;
    indx += (indx & -indx);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    long long sum = read(a);
    long long res = ((sum * a) % mod + a) % mod;
    res = (res - baad[a] + mod) % mod;
    ans = (ans + res) % mod;
    baad[a] = (baad[a] + res) % mod;
    update(a, res);
  }
  cout << ans << "\n";
  return 0;
}
