#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
template <class T>
int chmin(T &t, T f) {
  return (t > f) ? (t = f, 1) : 0;
}
template <class T>
int chmax(T &t, T f) {
  return (t < f) ? (t = f, 1) : 0;
}
inline int getint() {
  int a;
  return scanf("%d", &a) ? a : (fprintf(stderr, "trying to read\n"), -1);
}
inline double getdouble() {
  double a;
  return scanf("%lf", &a) ? a : (fprintf(stderr, "trying to read\n"), -1);
}
long long ApowBmodC(long long a, int b, int c) {
  if (b == 0) return 1;
  long long ret = ApowBmodC(a * a % c, b / 2, c);
  if (b & 1) ret = ret * a % c;
  return ret;
}
const int N = 1 << 20;
long long bit[N + 1];
void update(int i, long long first) {
  first %= INF;
  while (i <= N) {
    bit[i] += first;
    i += (i & -i);
  }
}
long long query(int i) {
  long long ret = 0;
  while (i) {
    ret += bit[i];
    i &= i - 1;
  }
  return ret % INF;
}
void myCode() {
  int n = getint();
  long long ret = 0;
  vector<int> a, doit(n, 0);
  for (int i = (int)0; i < (int)n; i++) a.push_back(getint());
  map<int, long long> lastQuery, lastDelta;
  for (int i = (int)0; i < (int)n; i++) {
    lastQuery[a[i]] = 0;
    lastDelta[a[i]] = 1;
  }
  for (int i = (int)0; i < (int)n; i++) {
    long long nq = (query(a[i] - 1) - lastQuery[a[i]] + INF) % INF;
    lastQuery[a[i]] = (lastQuery[a[i]] + nq) % INF;
    lastDelta[a[i]] = (nq + lastDelta[a[i]]) * a[i] % INF;
    update(a[i], lastDelta[a[i]]);
    ret = (ret + lastDelta[a[i]]) % INF;
  }
  cout << ret << endl;
}
int main() {
  myCode();
  return 0;
}
