#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int power(int a, int b, int m = MOD) {
  if (b == 0) return 1;
  if (b == 1) return a;
  int x = power(a, b / 2, m) % m;
  x = (x * x) % m;
  if (b % 2) return (x * a) % m;
  return x;
}
long long BIT[N], n, q[N];
void upd(long long x, long long val) {
  val %= MOD;
  for (; x < N; x += x & -x) {
    BIT[x] += val;
    BIT[x] %= MOD;
  }
}
long long query(long long x) {
  long long ret = 0;
  for (; x >= 1; x -= x & -x) {
    ret += BIT[x];
    ret %= MOD;
  }
  return ret;
}
int main() {
  scanf("%lld", &n);
  long long ans = 0;
  for (long long a = 1; a <= n; a++) {
    long long x;
    scanf("%lld", &x);
    ans = query(x) * x + x;
    ans %= MOD;
    upd(x, (ans - q[x] + MOD) % MOD);
    q[x] = ans;
  }
  ans = query(N - 1);
  printf("%lld\n", ans);
  return 0;
}
