#include <bits/stdc++.h>
using namespace std;
const int M = 1000000 + 5;
long long int mod = 1000000000 + 7;
int a[M];
struct TREE {
  int l;
  int r;
  long long int val;
} tree[4 * M];
void build(int l, int r, int node) {
  tree[node].l = l;
  tree[node].r = r;
  tree[node].val = 0;
  if (l == r) {
    return;
  } else {
    int m = (l + r) / 2;
    build(l, m, node * 2);
    build(m + 1, r, node * 2 + 1);
  }
}
void update(int node, int idx, long long int val) {
  int l = tree[node].l;
  int r = tree[node].r;
  int m = (l + r) / 2;
  if (l == r) {
    tree[node].val = (tree[node].val + val) % mod;
  } else {
    if (idx <= m) {
      update(node * 2, idx, val);
    } else {
      if (idx > m) {
        update(node * 2 + 1, idx, val);
      }
    }
    tree[node].val = (tree[node * 2].val + tree[node * 2 + 1].val) % mod;
  }
}
long long int query(int l, int r, int node) {
  if (l <= tree[node].l && tree[node].r <= r) {
    return tree[node].val;
  }
  int m = (tree[node].l + tree[node].r) / 2;
  if (r <= m) {
    return query(l, r, node * 2);
  } else {
    if (l > m) {
      return query(l, r, node * 2 + 1);
    } else {
      long long int s1 = query(l, m, node * 2);
      long long int s2 = query(m + 1, r, node * 2 + 1);
      long long int s = (s1 + s2) % mod;
      return s;
    }
  }
}
int main() {
  time_t t_start, t_end;
  t_start = clock();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  build(1, M, 1);
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    long long int res = query(1, a[i], 1);
    res = (res + 1) * a[i];
    res = res % mod;
    long long int val = query(a[i], a[i], 1);
    update(1, a[i], -val);
    update(1, a[i], res);
  }
  ans = tree[1].val;
  cout << ans << endl;
  t_end = clock();
  return 0;
}
