#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007;
const int N = 1000000;
long long tree[N + 1];
void update(int r, long long x) {
  while (r <= N) {
    tree[r] = (tree[r] + x) % Mod;
    r += (r & (r ^ (r - 1)));
  }
}
long long sum(int r) {
  long long res = 0;
  while (r > 0) {
    res = (res + tree[r]) % Mod;
    r -= (r & (r ^ (r - 1)));
  }
  return res;
}
int main() {
  int n;
  while (cin >> n) {
    memset(tree, 0, sizeof(tree));
    long long v;
    while (n--) {
      cin >> v;
      long long res = sum(v);
      long long old_v = res - sum(v - 1);
      res = (res * v + v) % Mod;
      update(v, res - old_v);
    }
    cout << sum(N) << '\n';
  }
  return 0;
}
