#include <bits/stdc++.h>
using namespace std;
inline long long sqr(long long x) { return x * x; }
const long long base = 1e9 + 7;
int n;
long long tree[(int)1e6 + 5], a[(int)1e5 + 5];
void update(int idx, long long val) {
  while (idx <= (int)1e6) {
    tree[idx] = (tree[idx] + val) % base;
    idx += idx & -idx;
  }
}
long long read(int idx) {
  long long ans = 0;
  while (idx) {
    ans = (ans + tree[idx]) % base;
    idx -= idx & -idx;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = (1), _b = (n); i <= _b; ++i) scanf("%I64d", &a[i]);
  for (int i = (1), _b = (n); i <= _b; ++i) {
    long long tmp = (read((int)a[i]) * a[i] + a[i]) % base,
              tmp2 = ((read((int)a[i]) - read((int)a[i] - 1)) % base + base) %
                     base;
    update((int)a[i], (((tmp - tmp2) % base) + base) % base);
  }
  printf("%I64d", read((int)1e6));
  return 0;
}
