#include <bits/stdc++.h>
template <typename Tp>
Tp Max(const Tp &a, const Tp &b) {
  return a > b ? a : b;
}
template <typename Tp>
Tp Min(const Tp &a, const Tp &b) {
  return a < b ? a : b;
}
template <typename Tp>
void Read(Tp &x) {
  Tp in = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    in = in * 10 + ch - '0';
    ch = getchar();
  }
  x = in * f;
}
const int SN = 1000000 + 10;
const int MOD = 1000000007;
long long sum[SN], a[SN], max, n;
void Modify(int pos, long long x) {
  while (pos <= max) {
    sum[pos] = (sum[pos] + x) % MOD;
    pos += pos & -pos;
  }
}
long long Ask(int x) {
  long long ans = 0;
  while (x) {
    ans = (ans + sum[x]) % MOD;
    x -= x & -x;
  }
  return ans;
}
int main() {
  long long x = 0;
  Read(n);
  for (int i = 1; i <= n; i++) Read(a[i]), max = Max(max, a[i]);
  for (int i = 1; i <= n; i++) {
    long long pre = Ask(a[i]);
    Modify(a[i], ((pre + 1) * a[i] % MOD - (pre - Ask(a[i] - 1)) + MOD) % MOD);
  }
  printf("%I64d\n", Ask(max));
  return 0;
}
