#include <bits/stdc++.h>
using namespace std;
const long long mod7 = 1000000007;
const long long mod9 = 1000000009;
const int linf = 2000000000;
const long long llinf = 1000000000000000000ll;
ifstream in("series.in");
ofstream out("series.out");
long long tr[4000004];
long long Get(int v, int l, int r, int L, int R) {
  if (l > r) return 0;
  if (L == l && R == r) return tr[v];
  int m = (L + R) >> 1;
  int sum = Get(v * 2, l, min(m, r), L, m);
  return (sum + Get(v * 2 + 1, max(l, m + 1), r, m + 1, R)) % mod7;
}
long long cnt, x;
void Set(int v, int L, int R) {
  while (L != R) {
    int m = (L + R) >> 1;
    v <<= 1;
    if (m >= x)
      R = m;
    else
      L = m + 1, ++v;
  }
  tr[v] = cnt;
  v >>= 1;
  while (v) {
    tr[v] = tr[v * 2] + tr[v * 2 + 1];
    tr[v] %= mod7;
    v >>= 1;
  }
}
int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    long long temp;
    cin >> temp;
    x = temp;
    cnt = Get(1, 1, temp, 1, 1000000) * x + x;
    cnt %= mod7;
    Set(1, 1, 1000000);
  }
  cout << Get(1, 1, 1000000, 1, 1000000);
  return 0;
}
