#include <bits/stdc++.h>
using namespace std;
const double euler_r = 0.57721566490153286060651209;
const double pi = 3.141592653589793238462643383279;
const double E = 2.7182818284590452353602874713526;
const int inf = ~0U >> 1;
const int MOD = int(1e9) + 7;
const double EPS = 1e-6;
long long c[1000010], dp[1000010];
int lowbit(int x) { return x & (-x); }
void add(int pos, long long x) {
  while (pos <= 1000000) {
    c[pos] += x;
    c[pos] %= 1000000007;
    pos = pos + lowbit(pos);
  }
}
long long get(int pos) {
  long long s = 0;
  while (pos > 0) {
    s += c[pos];
    s %= 1000000007;
    pos = pos - lowbit(pos);
  }
  return s;
}
int main() {
  int n, i, x;
  long long ans = 0;
  cin >> n;
  for (i = (1); i <= (n); i++) {
    cin >> x;
    long long s = get(x);
    long long t = s - get(x - 1);
    long long o = x + x * s - t;
    add(x, o);
  }
  ans = get(1000000);
  ans %= 1000000007;
  cout << ans << endl;
  return 0;
}
