#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const int mx = 1e5 + 10;
const int mxt = 1e6 + 10;
long long int d[mx];
long long int t[mxt];
void upd(int idx, long long int v) {
  for (; idx < mxt; idx += (idx & -idx)) t[idx] = (t[idx] + v) % mod;
}
long long int query(int idx) {
  long long int ans = 0;
  for (; idx > 0; idx -= (idx & -idx)) ans = (ans + t[idx]) % mod;
  return ans;
}
inline long long int range(int li, int ls) {
  return (query(ls) - query(li - 1) + mod) % mod;
}
inline long long int gat(int idx) {
  return (query(idx) - query(idx - 1) + mod) % mod;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> d[i];
  memset(t, 0, sizeof t);
  long long int ans = 0;
  for (int i = n; i > 0; i--) {
    long long int v = (d[i] + d[i] * range(d[i], mxt - 1)) % mod;
    long long int delta = (v - gat(d[i]) + mod) % mod;
    upd(d[i], delta);
    ans = (ans + delta) % mod;
  }
  cout << ans << endl;
  return 0;
}
