#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
int sum(int a, int b) { return (a + b) % MOD; }
int mul(int a, int b) { return (a * 1ll * b) % MOD; }
int sub(int a, int b) { return (a - b + MOD) % MOD; }
int first[N];
void add(int idx, int x) {
  for (; idx < N; idx |= idx + 1) first[idx] = sum(first[idx], x);
}
int get(int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) res = sum(res, first[r]);
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  int ans = 0;
  for (int i = 0, x; i < n; i++) {
    scanf("%d", &x);
    int cur = sum(mul(get(x), x), x);
    add(x, sub(get(x - 1), get(x)));
    add(x, cur);
  }
  printf("%d", get(N - 1));
  return 0;
}
