#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
const int mod = 1000000007;
int tree[MAXN];
int N, a[MAXN];
int w[MAXN], sum[MAXN];
long long read(int k) {
  long long ret = 0;
  while (k) {
    ret += tree[k];
    k -= k & -k;
  }
  return ret % mod;
}
void update(int k, int v) {
  while (k < MAXN) {
    tree[k] = (tree[k] + v) % mod;
    k += k & -k;
  }
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    scanf("%d", a + i);
    ++a[i];
  }
  update(1, 1);
  long long ans = 0;
  for (int i = 1; i <= N; ++i) {
    w[a[i]] = (read(a[i] - 1) - sum[a[i]] + w[a[i]]) * (a[i] - 1) % mod;
    sum[a[i]] = read(a[i] - 1);
    ans += w[a[i]];
    update(a[i], w[a[i]]);
  }
  cout << (ans % mod + mod) % mod << endl;
  return 0;
}
