#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e6 + 5;
constexpr int MOD = 1e9 + 7;
LL fen[N], last[N];
void add(int x, LL v) {
  for (; x < N; x += x & -x) (fen[x] += v) %= MOD;
}
LL get(int x) {
  LL s = 0;
  for (; x > 0; x -= x & -x) (s += fen[x]) %= MOD;
  return s;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  LL ans = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    LL val = (get(x) + 1) * x % MOD;
    LL inc = (val - last[x] + MOD) % MOD;
    add(x, inc);
    (ans += inc) %= MOD;
    last[x] = val;
  }
  cout << ans << endl;
}
