#include <bits/stdc++.h>
using namespace std;
long long BITree[1000009];
long long getSum(long long index) {
  long long sum = 0;
  while (index > 0) {
    sum += BITree[index];
    sum %= 1000000007;
    index -= index & (-index);
  }
  return sum;
}
void updateBIT(long long n, long long index, long long val) {
  while (index <= n) {
    BITree[index] += val;
    BITree[index] %= 1000000007;
    index += index & (-index);
  }
}
int main() {
  long long n, in;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &in);
    long long v = (getSum(in) * in + in) % 1000000007;
    long long toAdd =
        v - ((getSum(in) - getSum(in - 1)) + 1000000007) % 1000000007;
    updateBIT(1000001, in, (toAdd + 1000000007) % 1000000007);
  }
  cout << getSum(1000001) % 1000000007 << endl;
  return 0;
}
