#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const int MAX = 1e6 + 5;
const int MAXN = MAX + 5;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
long long n, x, f[MAXN], ans;
void up(long long x, long long k) {
  k %= mod;
  for (; x <= MAX; x += x & (-x)) f[x] = (f[x] + k) % mod;
}
long long qu(long long x) {
  long long sum = 0;
  for (; x; x -= x & (-x)) sum = (sum + f[x]);
  return sum;
}
long long fe(long long x, long long k) {
  if (!k) return 1LL;
  long long t = fe(x, k >> 1);
  return k & 1 ? t * t % mod * x % mod : t * t % mod;
}
int main() {
  ios ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    long long ret = qu(x);
    long long bef = (((ret - qu(x - 1)) % mod) + mod) % mod;
    long long inv_x = fe(x, mod - 2);
    up(x, (ret - bef * inv_x % mod + 1) * x);
    ans = (ans + (ret - bef * inv_x % mod + 1) * x) % mod;
  }
  cout << (ans + mod) % mod << '\n';
  0;
  return 0;
}
