#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1, mod = 1e9 + 7;
int n, f[N];
int query(int m) {
  int res = 0;
  while (m) {
    res = (res + f[m]) % mod;
    m -= m & -m;
  }
  return res;
}
void update(int x, int k) {
  while (x < N) {
    f[x] = (f[x] + k) % mod;
    x += x & -x;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    update(m, (1ll * m * (query(m) + 1) - query(m) + query(m - 1)) % mod);
  }
  cout << (query(N - 1) + mod) % mod << '\n';
  return 0;
}
