#include <bits/stdc++.h>
using namespace std;
int segtree[5000000];
void update(int idx, int val, int l, int r, int pos) {
  if (l > idx or r < idx) return;
  if (l == r) {
    segtree[pos] += val;
    if (segtree[pos] >= 1000000007) segtree[pos] -= 1000000007;
    return;
  }
  int mid = (l + r) >> 1;
  update(idx, val, l, mid, 2 * pos);
  update(idx, val, mid + 1, r, 2 * pos + 1);
  segtree[pos] = segtree[2 * pos] + segtree[2 * pos + 1];
  if (segtree[pos] >= 1000000007) segtree[pos] -= 1000000007;
}
int query(int lQ, int rQ, int l, int r, int pos) {
  if (l > rQ or r < lQ)
    return 0;
  else if (l >= lQ && r <= rQ)
    return segtree[pos];
  int mid = (l + r) >> 1;
  int sum =
      query(lQ, rQ, l, mid, 2 * pos) + query(lQ, rQ, mid + 1, r, 2 * pos + 1);
  if (sum >= 1000000007) sum -= 1000000007;
  return sum;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    int ans = query(1, x, 1, 1000000, 1) + 1;
    int rem = query(x, x, 1, 1000000, 1);
    ans = (1LL * ans * x) % 1000000007;
    ans -= rem;
    if (ans < 0) ans += 1000000007;
    update(x, ans, 1, 1000000, 1);
  }
  printf("%d\n", query(1, 1000000, 1, 1000000, 1));
  return 0;
}
