#include <bits/stdc++.h>
using namespace std;
const long long MAX = 4e6 + 5;
long long bit[MAX];
long long md = 1000000007;
void update(long long idx, long long val) {
  while (idx < MAX) {
    bit[idx] += val;
    bit[idx] %= md;
    idx += (idx & -idx);
  }
}
long long query(long long idx) {
  if (idx == 0) return 0;
  long long sum = 0;
  while (idx > 0) {
    sum += bit[idx];
    sum %= md;
    idx -= (idx & -idx);
  }
  return sum;
}
vector<long long> v;
long long a[1000010];
int main() {
  long long n;
  cin >> n;
  long long x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  long long sq;
  for (int i = 0; i < n; i++) {
    sq = (query(a[i]) * a[i] + a[i]) % md -
         (query(a[i]) - query(a[i] - 1) + md) % md;
    sq += md;
    sq %= md;
    update(a[i], sq);
    ans += sq;
    ans %= md;
  }
  cout << ans;
}
