#include <bits/stdc++.h>
using namespace std;
long long a[1000009], b[1000009], ans;
int lowbit(int x) { return x & (-x); }
long long sum(int x) {
  long long ret = 0;
  while (x > 0) {
    ret = (ret + a[x]) % 1000000007;
    x -= lowbit(x);
  }
  return ret % 1000000007;
}
void add(int x, long long d) {
  while (x < 1000009) {
    a[x] = (a[x] + d) % 1000000007;
    x += lowbit(x);
  }
}
int main() {
  int n, x;
  scanf("%d", &n);
  ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    long long cur = sum(x);
    cur = (cur * x + x) % 1000000007;
    ans = (ans + cur - b[x]) % 1000000007;
    add(x, cur - b[x]);
    b[x] = cur;
  }
  printf("%lld\n", (ans % 1000000007 + 1000000007) % 1000000007);
  return 0;
}
