#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 6;
const int MOD = 1e9 + 7;
long long bit[N], n, tmp, currVal, nxt, tmpVal, mx = 0;
void update(int pos, int val) {
  for (int i = pos; i <= N; i += i & -i) bit[i] = (bit[i] + val) % MOD;
}
long long query(int pos) {
  long long res = 0;
  for (int i = pos; i > 0; i -= i & -i) res = (res + bit[i]) % MOD;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    currVal = query(tmp);
    nxt = (currVal * tmp) % MOD;
    nxt = (nxt + tmp) % MOD;
    tmpVal = (currVal - query(tmp - 1) + MOD) % MOD;
    update(tmp, (nxt - tmpVal + MOD) % MOD);
    mx = max(mx, tmp);
  }
  cout << query(mx) << "\n";
  return 0;
}
