#include <bits/stdc++.h>
using namespace std;
FILE *in;
FILE *out;
const int MAX = 1048576;
const int TREE = 2097152;
const int MOD = 1000000007;
int n;
int a[MAX];
int tree[TREE];
bool seen[MAX];
int query(int idx1, int idx2) {
  idx1 += (TREE >> 1);
  idx2 += (TREE >> 1);
  if (idx1 == idx2) return tree[idx1];
  int ret = 0;
  ret += tree[idx1];
  if (ret >= MOD) ret -= MOD;
  int flag1 = !(idx1 & 1);
  idx1 >>= 1;
  ret += tree[idx2];
  if (ret >= MOD) ret -= MOD;
  int flag2 = (idx2 & 1);
  idx2 >>= 1;
  while (idx1 != idx2) {
    if (flag1) {
      ret += tree[(idx1 << 1) + 1];
      if (ret >= MOD) ret -= MOD;
    }
    if (flag2) {
      ret += tree[(idx2 << 1) + 0];
      if (ret >= MOD) ret -= MOD;
    }
    flag1 = !(idx1 & 1);
    idx1 >>= 1;
    flag2 = (idx2 & 1);
    idx2 >>= 1;
  }
  return ret;
}
void update(int idx, int val) {
  idx += (TREE >> 1);
  while (idx) {
    tree[idx] += val;
    if (tree[idx] >= MOD) tree[idx] -= MOD;
    idx >>= 1;
  }
}
int main(void) {
  in = stdin;
  out = stdout;
  fscanf(in, "%d", &n);
  for (int i = 0; i < n; i++) fscanf(in, "%d", &a[i]);
  int ans = 0;
  memset(tree, 0, sizeof(tree));
  for (int i = n - 1; i >= 0; i--) {
    int cur = ((long long)a[i] * (query(a[i], MAX - 1) + 1)) % MOD;
    ans += cur;
    if (ans >= MOD) ans -= MOD;
    int sub = query(a[i], a[i]);
    ans -= sub;
    if (ans < 0) ans += MOD;
    update(a[i], (cur - sub + MOD) % MOD);
  }
  fprintf(out, "%d\n", ans);
  return 0;
}
