#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
int c[maxn], last[maxn];
void add(int pos, int val) {
  while (pos < maxn) {
    c[pos] += val;
    c[pos] %= mod;
    pos += pos & (-pos);
  }
}
int getsum(int pos) {
  int ret = 0;
  while (pos > 0) {
    ret = (ret + c[pos]) % mod;
    pos -= pos & (-pos);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    int temp = (a + 1LL * a * getsum(a) % mod) % mod;
    temp = (temp - last[a] + mod) % mod;
    last[a] = (last[a] + temp) % mod;
    ans = (ans + temp) % mod;
    add(a, temp);
  }
  cout << ans << endl;
  return 0;
}
