#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    T t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const int N = 1000005;
long long tree[N];
void add(int x, long long s) {
  for (int i = x; i < N; i += i & -i)
    tree[i] = (tree[i] + s + 1000000007) % 1000000007;
}
int find(int x) {
  long long sum = 0;
  for (int i = x; i > 0; i -= i & -i) sum = (sum + tree[i]) % 1000000007;
  return sum;
}
long long arr[N];
int main() {
  int i, j, k;
  int m;
  string str, inp;
  long long t, n;
  cin >> n;
  add(1, 1ll);
  long long b;
  long long ans = 0ll;
  for (i = 1; i <= n; i++) {
    cin >> b;
    long long tmp = find(b);
    tmp = (tmp * b) % 1000000007;
    ans = (ans + tmp - arr[b] + 1000000007) % 1000000007;
    add(b, tmp - arr[b]);
    arr[b] = tmp;
  }
  cout << ans << endl;
  return 0;
}
