#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mod = 1000000007;
struct segtrie {
  long long sum[maxn << 2];
  void pushUp(int rt) {
    sum[rt] = ((sum[rt << 1] * sum[rt << 1 | 1] % mod + sum[rt << 1]) % mod +
               sum[rt << 1 | 1]) %
              mod;
  }
  void update(int p, long long v, int l, int r, int rt) {
    if (l == r) {
      sum[rt] = (sum[rt] * v % mod + v) % mod;
      return;
    }
    int m = (l + r) >> 1;
    ;
    if (p <= m)
      update(p, v, l, m, rt << 1);
    else
      update(p, v, m + 1, r, rt << 1 | 1);
    pushUp(rt);
  }
  long long query(int L, int R, int l, int r, int rt) {
    if (L <= l && r <= R) return sum[rt];
    int m = (l + r) >> 1;
    ;
    long long ret = 0;
    if (L <= m) ret = query(L, R, l, m, rt << 1);
    if (R > m)
      ret = (ret + query(L, R, m + 1, r, rt << 1 | 1) * (ret + 1) % mod) % mod;
    return ret;
  }
} T;
const int N = 1000006;
long long c[N];
long long Sum(int x) {
  long long s = 0;
  while (x) {
    s += c[x];
    if (s >= mod) s -= mod;
    x -= x & -x;
  }
  return s;
}
void add(int x, long long v) {
  while (x < N) {
    c[x] += v;
    if (c[x] >= mod) c[x] -= mod;
    x += x & -x;
  }
}
long long tp[maxn];
int a[maxn];
int pos[maxn];
long long pre[N];
int main() {
  int i, j, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  long long ans = 0;
  for (i = 0; i < n; i++) {
    long long now = (Sum(a[i]) * a[i] % mod + a[i]) % mod;
    ans = (ans + now - pre[a[i]]) % mod;
    add(a[i], now - pre[a[i]]);
    pre[a[i]] = now;
  }
  if (ans < 0) ans += mod;
  printf("%I64d\n", ans);
  return 0;
}
