#include <bits/stdc++.h>
using namespace std;
const int N = 1000004;
const int mod = 1e9 + 7;
long long f[N];
int a[N];
long long val[N];
long long query(int x) {
  long long ans = 0;
  for (; x > 0; x -= x & -x) ans = (ans + f[x]) % mod;
  return ans;
}
void update(int i, int x) {
  for (; i < N; i += i & -i) f[i] = (f[i] + x + mod) % mod;
}
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  long long ans = 0, sum;
  for (i = n; i >= 1; i--) {
    if (val[a[i]] == 0) {
      sum = (query(N - 1) - query(a[i] - 1) + mod) % mod;
      val[a[i]] = (a[i] + (1LL * a[i] * sum) % mod) % mod;
      ans = (ans + val[a[i]]) % mod;
      update(a[i], val[a[i]]);
    } else {
      sum = (query(N - 1) - query(a[i] - 1) + mod) % mod;
      ans = (ans - val[a[i]] + mod) % mod;
      update(a[i], -val[a[i]]);
      val[a[i]] = (a[i] + (1LL * a[i] * sum) % mod) % mod;
      ans = (ans + val[a[i]]) % mod;
      update(a[i], val[a[i]]);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
