#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007;
const int N = 1000010;
struct node {
  int l, r;
  long long sum, add;
} tree[N * 4];
void build(int id, int l, int r) {
  tree[id].l = l;
  tree[id].r = r;
  tree[id].sum = 0;
  tree[id].add = 0;
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
}
void deal(int id, long long val) {
  tree[id].add += val;
  tree[id].sum =
      (tree[id].sum + val * (tree[id].r - tree[id].l + 1) % Mod) % Mod;
}
void push_down(int id, long long val) {
  tree[id].add = 0;
  if (tree[id].l == tree[id].r) return;
  deal(id * 2, val);
  deal(id * 2 + 1, val);
}
void update(int id, int l, int r, long long val) {
  if (tree[id].l == l && tree[id].r == r) {
    deal(id, val);
    return;
  }
  if (tree[id].add != 0) push_down(id, tree[id].add);
  int mid = (tree[id].l + tree[id].r) / 2;
  if (r <= mid)
    update(id * 2, l, r, val);
  else if (l > mid)
    update(id * 2 + 1, l, r, val);
  else {
    update(id * 2, l, mid, val);
    update(id * 2 + 1, mid + 1, r, val);
  }
  tree[id].sum = (tree[id * 2].sum + tree[id * 2 + 1].sum) % Mod;
}
long long get_sum(int id, int l, int r) {
  if (tree[id].l == l && tree[id].r == r) return tree[id].sum;
  if (tree[id].add != 0) push_down(id, tree[id].add);
  int mid = (tree[id].l + tree[id].r) / 2;
  if (r <= mid)
    return get_sum(id * 2, l, r);
  else if (l > mid)
    return get_sum(id * 2 + 1, l, r);
  else {
    return (get_sum(id * 2, l, mid) + get_sum(id * 2 + 1, mid + 1, r)) % Mod;
  }
}
long long get_sum(int id, int k) {
  if (tree[id].r == k) return tree[id].sum;
  if (tree[id].add != 0) push_down(id, tree[id].add);
  int mid = (tree[id].l + tree[id].r) / 2;
  if (k <= mid) return get_sum(id * 2, k);
  return (tree[id * 2].sum + get_sum(id * 2 + 1, k)) % Mod;
}
int a[N];
long long dp[N], last[N];
bool vis[N], f[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = n; i >= 1; i--) {
    if (!vis[a[i]]) f[i] = 1;
    vis[a[i]] = 1;
  }
  long long ans = 0;
  int M = 1000002;
  build(1, 1, M);
  update(1, 1, M, 1);
  for (int i = 1; i <= n; i++) {
    long long tp = get_sum(1, a[i] + 1, a[i] + 1);
    tp = (tp * a[i]) % Mod;
    if (f[i]) ans = (ans + tp) % Mod;
    update(1, a[i] + 1, M, tp - last[a[i]]);
    last[a[i]] = tp;
  }
  ans = (ans % Mod + Mod) % Mod;
  printf("%I64d\n", ans);
  return 0;
}
