#include <bits/stdc++.h>
using namespace std;
long long n, a[100005];
void initialization() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
}
vector<long long> q(1000005, 0);
void update(long long i, long long x) {
  while (i < 1000001) {
    q[i] = (q[i] + x) % 1000000007;
    i = (i | (i + 1));
  }
}
long long sum(long long r) {
  long long res = 0;
  while (r > 0) {
    res += q[r];
    if (res >= 1000000007) res %= 1000000007;
    r = (r & (r + 1)) - 1;
  }
  return res;
}
long long sum(long long l, long long r) {
  long long res = sum(r) - sum(l - 1);
  if (res < 0) res += 1000000007;
  return res;
}
long long ans;
void solve() {
  for (int i = 0; i < n; ++i) {
    long long res = (sum(a[i]) * a[i] + a[i] - sum(a[i], a[i])) % 1000000007;
    update(a[i], res);
  }
  ans = sum(1000000);
}
void print() { cout << ans; }
int main() {
  ios::sync_with_stdio(0);
  initialization();
  solve();
  print();
  return 0;
}
