#include <bits/stdc++.h>
using namespace std;
int B[1000100], a[1000100], b[1000100];
int update(int u, int v) {
  while (u < 1000100) {
    B[u] += v;
    B[u] %= 1000000007;
    u += u & -u;
  }
  return 0;
}
int calc(int u) {
  int ans = 0;
  while (u) {
    ans += B[u];
    u -= u & -u;
    ans %= 1000000007;
  }
  return ans;
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) scanf("%d", a + i);
  for (int i = 0; i < N; i++) {
    int k = calc(a[i]);
    int n = ((long long)k * a[i] + a[i]) % 1000000007;
    update(a[i], 1000000007 - b[a[i]]);
    update(a[i], b[a[i]] = n);
  }
  int ans = calc(1000100 - 1);
  cout << ans << endl;
  return 0;
}
