#include <bits/stdc++.h>
using namespace std;
const int H = (1 << 20);
const long long MOD = 1000000007LL;
long long a, b[H], answer, T[2 * H], u;
int i, n;
void upd(int i, long long v) {
  i += H - 1;
  T[i] = v;
  T[i] %= MOD;
  while (i > 1) {
    i /= 2;
    T[i] = T[i * 2] + T[i * 2 + 1];
    T[i] %= MOD;
  }
}
long long ans(int l, int r) {
  l += H - 1;
  r += H - 1;
  u = 0LL;
  while (l < r) {
    if (l % 2 == 1) {
      u += T[l];
      u %= MOD;
      l++;
    }
    if (r % 2 == 0) {
      u += T[r];
      u %= MOD;
      r--;
    }
    l /= 2;
    r /= 2;
  }
  if (l == r) u += T[l];
  u %= MOD;
  return u;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a;
    b[a] = ((1LL + ans(1, a)) * a) % MOD;
    upd(a, b[a]);
  }
  for (i = 1; i <= 1000000; i++) answer = (answer + b[i]) % MOD;
  cout << answer << endl;
}
