#include <bits/stdc++.h>
using namespace std;
int hsh[1000005], a[1000005];
long long bit[1000005];
void update(int ind, int val) {
  while (ind < 1000005) {
    bit[ind] = bit[ind] + val;
    if (bit[ind] >= 1000000007) bit[ind] -= 1000000007;
    ind += (ind & -ind);
  }
}
long long query(int ind) {
  long long ret = 0;
  while (ind > 0) {
    ret += bit[ind];
    if (ret >= 1000000007) ret -= 1000000007;
    ind -= (ind & -ind);
  }
  return ret;
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (i = n; i >= 1; --i) {
    int x = a[i];
    long long y = ((query(1000005 - 1) - query(x - 1) + 1 + 1000000007) %
                   1000000007 * x) %
                  1000000007;
    update(x, (y - hsh[x] + 1000000007) % 1000000007);
    hsh[x] = y;
  }
  long long ans = 0;
  for (i = 1; i < 1000005; ++i) ans += hsh[i];
  printf("%lld\n", ans % 1000000007);
  return 0;
}
