#include <bits/stdc++.h>
using namespace std;
const int delta = 1000 * 1000 * 1000 + 7, N = 1000 * 1000 + 5;
struct node {
  int right, left, P, Q;
  long long sum;
  node() { right = left = P = Q = sum = 0; }
};
const node null;
vector<node> T;
long long a[N];
void relax(const int &x) {
  if (T[x].P == T[x].Q) return;
  int m = (T[x].P + T[x].Q) >> 1;
  int r, l;
  r = T[x].right = (int)T.size();
  T.push_back(null);
  T[r].P = T[x].P;
  T[r].Q = m;
  relax(r);
  l = T[x].left = (int)T.size();
  T.push_back(null);
  T[l].P = m + 1;
  T[l].Q = T[x].Q;
  relax(l);
}
long long find(const int &x, const int &p, const int &q) {
  if (T[x].P == p && T[x].Q == q) return T[x].sum;
  int r = T[x].right, l = T[x].left;
  if (q <= T[r].Q) {
    return find(r, p, q);
  } else if (p > T[r].Q)
    return find(l, p, q);
  else
    return find(r, p, T[r].Q) + find(l, T[l].P, q);
}
void change(const int &x, const int &p, const long long &val) {
  T[x].sum += val;
  if (T[x].P == T[x].Q) return;
  int r = T[x].right, l = T[x].left;
  if (p <= T[r].Q)
    change(r, p, val);
  else
    change(l, p, val);
}
int main() {
  T.push_back(null);
  T[0].P = 0;
  T[0].Q = N;
  relax(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = n - 1; i > -1; --i) {
    long long tmp = find(0, a[i], N) + 1;
    tmp %= delta;
    tmp *= a[i];
    tmp -= find(0, a[i], a[i]);
    tmp += delta;
    tmp %= delta;
    change(0, a[i], tmp);
  }
  long long ans = find(0, 0, N);
  cout << ans % delta << endl;
  return 0;
}
