#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
const int N = 1111111;
int n, d[N], C[N];
int lb(int x) { return x & (-x); }
void add(int x, int v) {
  v = (v % mod + mod) % mod;
  while (x < N) C[x] = (C[x] + v) % mod, x += lb(x);
}
int sum(int x) {
  int ret = 0;
  while (x) ret = (ret + C[x]) % mod, x -= lb(x);
  return ret;
}
void init() { memset(d, 0, sizeof(d)), memset(C, 0, sizeof(C)); }
void solve() {
  int a, i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    int temp = ((long long)sum(a) * a % mod + a) % mod;
    add(a, temp - d[a]);
    d[a] = temp;
  }
  printf("%d\n", sum(N - 1));
}
int main() {
  while (scanf("%d", &n) == 1) init(), solve();
  return 0;
}
