#include <bits/stdc++.h>
using namespace std;
const long long N = 1000 * 1000 + 5;
long long bit[N] = {0};
void update(long long p, long long val) {
  for (; p < N; p += p & (-p)) bit[p] = (bit[p] + val) % 1000000007;
}
long long get(long long p) {
  long long res = 0;
  for (; p > 0; p -= p & (-p)) res = (res + bit[p]) % 1000000007;
  return res;
}
signed main() {
  long long n;
  cin >> n;
  long long a[n];
  map<long long, long long> m, m1;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = n - 1; i >= 0; i--) {
    long long tmp = (get(1000000) - get(a[i] - 1) + 1000000007) % 1000000007;
    if (!m1[a[i]]) {
      tmp = (tmp + 1) % 1000000007;
      long long val = (a[i] * tmp) % 1000000007;
      m[a[i]] = (val - a[i] + 1000000007) % 1000000007;
      update(a[i], val);
      m1[a[i]]++;
    } else {
      long long val = (tmp * a[i]) % 1000000007;
      val = (val - m[a[i]] + 1000000007) % 1000000007;
      update(a[i], val);
      m[a[i]] = (val + m[a[i]]) % 1000000007;
    }
  }
  cout << get(1000000);
  return 0;
}
