#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
int n, a[N];
int t[M];
int f[N], p[M], ans;
int lowbit(int x) { return x & (-x); }
void Upd(int pos, int x) {
  for (int i = pos; i < M; i += lowbit(i)) t[i] = (t[i] + x) % mod;
}
int Qry(int pos) {
  int ret = 0;
  for (int i = pos; i > 0; i -= lowbit(i)) ret = (ret + t[i]) % mod;
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  memset(t, 0, sizeof(t));
  memset(p, 0, sizeof(p));
  Upd(1, 1);
  for (int i = 1; i <= n; ++i) {
    p[a[i]] = i;
    int tmp = Qry(a[i] + 1);
    int tmp1 = Qry(a[i]);
    f[i] = 1ll * a[i] * tmp % mod;
    Upd(a[i] + 1, ((f[i] - (tmp - tmp1)) % mod + mod) % mod);
  }
  ans = 0;
  for (int i = 1; i < M; ++i)
    if (p[i] != 0) ans = (ans + f[p[i]]) % mod;
  printf("%d\n", ans);
  return 0;
}
