#include <bits/stdc++.h>
using namespace std;
int N;
long long int T[1000000 + 5], tmp;
void update(int x, int v) {
  while (x <= 1000000) {
    T[x] += v;
    if (T[x] >= 1000000007) T[x] -= 1000000007;
    x += (x & -x);
  }
}
long long int query(int x) {
  if (x == 0) return 0;
  long long int sum = 0;
  while (x > 0) {
    sum += T[x];
    if (sum >= 1000000007) sum -= 1000000007;
    x -= (x & -x);
  }
  return sum;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    cin >> tmp;
    int val = (int)((query(tmp) * tmp + tmp) % 1000000007);
    update(tmp, 1000000007 - query(tmp) + query(tmp - 1));
    update(tmp, val);
  }
  cout << query(1000000) << endl;
}
