#include <bits/stdc++.h>
using namespace std;
long long N;
long long q[1000010];
long long b[1000010];
void update(long long x, long long val) {
  while (x <= 1000005) {
    b[x] += val;
    b[x] %= 1000000007;
    x += x & -x;
  }
}
int getVal(long long x) {
  long long sum = 0;
  while (x > 0) {
    sum += b[x];
    sum %= 1000000007;
    x -= x & (-x);
  }
  return sum;
}
int main() {
  cin >> N;
  long long a;
  for (long long i = 0; i < N; i++) {
    cin >> a;
    long long x = (getVal(a) * a + a) % 1000000007;
    update(a, (x + 1000000007 - q[a]) % 1000000007);
    q[a] = x;
  }
  cout << getVal(1000005) << endl;
  return 0;
}
