#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int MOD = 1e9 + 7;
int n, a[N / 10], last[N];
void inc(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
struct Fenwick {
  int n, c[N];
  void init(int _n) {
    n = _n;
    memset(c, 0, sizeof(c[0]) * (n + 1));
  }
  void upd(int i, int v) {
    for (; i <= n; i += i & -i) inc(c[i], v);
  }
  int sum(int i) {
    int ret = 0;
    for (; i > 0; i -= i & -i) inc(ret, c[i]);
    return ret;
  }
} fw;
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
  fw.init(*max_element(a, a + n));
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    int ans_i = (1ll * fw.sum(a[i]) * a[i] + a[i]) % MOD;
    inc(ans_i, MOD - last[a[i]]);
    inc(ans, ans_i);
    inc(last[a[i]], ans_i), fw.upd(a[i], ans_i);
  }
  printf("%d", ans);
  return 0;
}
