#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T max(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
void OUTLN(T *arr, int lf, int rt) {
  for (int i = lf; i < rt; i++) cout << arr[i] << " ";
  cout << endl;
}
const int MOD = 1000000007;
const int maxn = 100000 + 5;
const int maxv = 1000000 + 5;
int n;
long long tree[maxv], arr[maxv];
int lowbit(int num) { return num & -num; }
void add(int x, long long val) {
  while (x < maxv) {
    tree[x] = (tree[x] + val) % MOD;
    x += lowbit(x);
  }
}
long long sum(int x) {
  long long ret = 0;
  while (x > 0) {
    ret = (ret + tree[x]) % MOD;
    x -= lowbit(x);
  }
  return ret;
}
int main() {
  cin >> n;
  int tmp;
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &tmp);
    long long cur = sum(tmp);
    long long rec = arr[tmp];
    arr[tmp] = tmp + cur * tmp % MOD;
    add(tmp, (arr[tmp] + MOD - rec) % MOD);
  }
  cout << sum(maxv - 1) << endl;
  return 0;
}
