#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, P = 1e9 + 7;
long long Fastpow(long long a, long long b, long long p) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = ans * a % P;
    a = a * a % P;
    b >>= 1;
  }
  return ans % P;
}
long long f[N + 5], g[N + 5];
void Add(int l, int r, long long w, int n) {
  while (l <= n) {
    f[l] = (f[l] + w) % P;
    l += (l & -l);
  }
  ++r;
  while (r <= n) {
    f[r] = (f[r] - w) % P;
    r += (r & -r);
  }
  return;
}
long long Ask(int x) {
  long long ans = 0;
  while (x) {
    ans = (ans + f[x]) % P;
    x -= (x & -x);
  }
  return ans;
}
int vis[N + 5], go[N + 5], st[N + 5];
int a[N + 5], b[N + 5], cnt, c[N + 5];
void discrete(int n) {
  memcpy(b, a, sizeof(a));
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i)
    if (i == 1 || b[i] != b[i - 1]) c[++cnt] = b[i];
  return;
}
int Q(int x) { return lower_bound(c + 1, c + cnt + 1, x) - c; }
int main() {
  int n, mx = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  discrete(n);
  for (int i = 1; i <= n; ++i) {
    a[i] = Q(a[i]);
    go[i] = vis[a[i]];
    vis[a[i]] = i;
    if (st[a[i]] == 0) st[a[i]] = i;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    long long x = Ask(a[i]);
    Add(a[i], a[i], -x, cnt);
    if (st[a[i]] == i) x += 1;
    g[i] = x * c[a[i]] % P;
    ans = (ans + g[i]) % P;
    Add(a[i], cnt, g[i], cnt);
  }
  cout << ans << '\n';
  return 0;
}
