#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct Node {
  int left, right;
  long long sum;
} L[N << 2];
void bulid(int step, int l, int r) {
  L[step].left = l;
  L[step].right = r;
  L[step].sum = 0;
  if (l == r) return;
  int m = (l + r) >> 1;
  bulid(step << 1, l, m);
  bulid(step << 1 | 1, m + 1, r);
}
void update(int step, int pos, long long val) {
  if (L[step].left == L[step].right) {
    L[step].sum = (val) % 1000000007;
    return;
  }
  int m = (L[step].left + L[step].right) >> 1;
  if (pos <= m)
    update(step << 1, pos, val);
  else
    update(step << 1 | 1, pos, val);
  L[step].sum = (L[step << 1].sum + L[step << 1 | 1].sum) % 1000000007;
}
long long query(int step, int l, int r) {
  if (L[step].left == l && L[step].right == r) return L[step].sum;
  int m = (L[step].left + L[step].right) >> 1;
  if (r <= m)
    return query(step << 1, l, r);
  else if (l > m)
    return query(step << 1 | 1, l, r);
  else
    return (query(step << 1, l, m) + query(step << 1 | 1, m + 1, r)) %
           1000000007;
}
long long a[N];
int main() {
  int n;
  scanf("%d", &n);
  bulid(1, 1, 1000000);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
    long long sub = query(1, a[i], a[i]);
    long long sum = (a[i] + a[i] * query(1, 1, a[i])) % 1000000007;
    ans = ((ans + sum - sub) % 1000000007 + 1000000007) % 1000000007;
    update(1, a[i], sum);
  }
  printf("%I64d\n", ans);
  return 0;
}
