#include <bits/stdc++.h>
using namespace std;
int N;
int data[100009];
int table[1000009];
const int MOD = 1000000007;
long long int query(int idx) {
  int ret = 0;
  while (idx > 0) {
    ret = (ret + table[idx]) % MOD;
    idx -= idx & -idx;
  }
  return ret;
}
void update(int idx, int v) {
  while (idx < 1000009) {
    (table[idx] += v) %= MOD;
    idx += idx & -idx;
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int v;
    scanf("%d", &v);
    int t = ((1 + query(v)) * v % MOD - (query(v) - query(v - 1))) % MOD;
    if (t < 0) t += MOD;
    update(v, t);
  }
  printf("%d\n", query(1000008));
  return 0;
}
