#include <bits/stdc++.h>
using namespace std;
long long c[1000005];
long long n, tmp, tmp1, tmp2, tmp3, m, res, val;
long long a[1000005];
long long Lowbit(long long x) { return x & (-x); }
void Add(long long pos, long long val, long long n) {
  while (pos <= n) {
    c[pos] += val % 1000000007;
    c[pos] %= 1000000007;
    pos += Lowbit(pos);
  }
}
long long Sum(long long pos) {
  long long sum = 0;
  if (pos < 0) return 0;
  while (pos) {
    sum += c[pos] % 1000000007;
    sum %= 1000000007;
    pos -= Lowbit(pos);
  }
  return sum;
}
int main(int argc, char* argv[]) {
  cin >> n;
  memset(c, 0, sizeof(c));
  m = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > m) m = a[i];
  }
  for (int i = 1; i <= n; i++) {
    tmp = (Sum(a[i]) * a[i] + a[i]) % 1000000007;
    tmp1 = Sum(a[i]);
    tmp2 = Sum(a[i] - 1);
    tmp3 = (tmp1 - tmp2 + 1000000007) % 1000000007;
    val = (tmp - tmp3) % 1000000007;
    Add(a[i], val, m);
  }
  res = Sum(m) % 1000000007;
  if (res < 0) res += 1000000007;
  cout << res << endl;
  return 0;
}
