#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000002;
const long long MOD = 1000000007;
long long tree[MAX];
long long get_cumul(int idx) {
  long long sum = tree[0];
  while (idx > 0) {
    sum = (sum + tree[idx]) % MOD;
    idx = (idx & (idx - 1));
  }
  return sum;
}
void update(int idx, long long val) {
  while (idx > 0 && idx < MAX) {
    tree[idx] = (tree[idx] + val) % MOD;
    idx = idx + (idx & (-idx));
  }
}
int main() {
  long long n, v, s1, s2, mx;
  cin >> n;
  memset(tree, 0, sizeof(tree));
  mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> v;
    s1 = get_cumul(v);
    s2 = s1 - get_cumul(v - 1);
    update(v, ((s1 + 1) * v - s2) % MOD);
    mx = max(mx, v);
  }
  cout << get_cumul(mx) << endl;
  return 0;
}
