#include <bits/stdc++.h>
using namespace std;
int a[1000005];
long long c[1000005];
long long f[1000005];
int n;
long long Sum(int i) {
  long long s = 0;
  while (i > 0) {
    s += c[i];
    s = s % 1000000007;
    i -= i & (-i);
  }
  return s;
}
void Update(int i, long long value) {
  value = value % 1000000007;
  if (value < 0) value += 1000000007;
  while (i <= 1000002) {
    c[i] += ((long long)value);
    c[i] = c[i] % 1000000007;
    i += i & (-i);
  }
}
int main() {
  memset(c, 0, sizeof(c));
  memset(a, 0, sizeof(a));
  scanf("%d", &n);
  int tmp;
  c[0] = 0;
  long long ltmp;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &tmp);
    f[i] = (long long)(Sum(tmp) + 1) * (long long)tmp;
    f[i] = (f[i] + 1000000007) % 1000000007;
    Update(tmp, -f[a[tmp]]);
    f[a[tmp]] = 0;
    a[tmp] = i;
    Update(tmp, f[i]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (f[i] + ans + 1000000007) % 1000000007;
  }
  printf("%I64d\n", ans);
  return 0;
}
