#include <bits/stdc++.h>
using namespace std;
const int MAX1 = 1e5 + 7;
const int MAX2 = 1e6 + 7;
long long a[MAX1];
long long tree[MAX2], n, val[MAX2];
void update(int i, int v) {
  if (v < 0) v += 1000000007;
  while (i <= MAX2) {
    tree[i] = (tree[i] + v) % 1000000007;
    i += i & (-i);
  }
}
long long query(int i) {
  int ans = 0;
  while (i > 0) {
    ans = (ans + tree[i]) % 1000000007;
    i -= i & (-i);
  }
  return ans;
}
int func() {
  for (int i = 1; i <= n; i++) {
    update(a[i], -val[a[i]]);
    val[a[i]] = (query(a[i] - 1) + val[a[i]] + 1) * a[i];
    val[a[i]] = val[a[i]] % 1000000007;
    update(a[i], val[a[i]]);
  }
  return query(MAX2 - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cout << func() << endl;
  return 0;
}
