#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
long long g[1000100], k[1000100], ans = 0;
int n, i;
int prev(int x) { return x & (x - 1); }
int next(int x) { return (x << 1) - prev(x); }
long long sum(int r) {
  long long ans = 0;
  int x = r;
  while (x > 0) {
    ans = (ans + g[x]) % md;
    x = prev(x);
  }
  return ans;
}
void modify(int x, long long y) {
  while (x <= 1e6) {
    g[x] = (g[x] + y) % md;
    x = next(x);
  }
}
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    int j;
    scanf("%d", &j);
    long long t = (sum(j) * j + j) % md;
    modify(j, t - k[j] < 0 ? t - k[j] + md : t - k[j]);
    k[j] = t;
  }
  printf("%d\n", int(sum(1e6) % md));
  return 0;
}
