#include <bits/stdc++.h>
using namespace std;
int lowbit(int x) { return x & (-x); }
using namespace std;
long long a[1000005];
void add(int p, long long num) {
  for (; p < 1000005; p += lowbit(p)) a[p] = (a[p] + num) % 1000000007;
}
long long getsum(int p) {
  long long res = 0;
  for (; p; p -= lowbit(p)) res += a[p];
  return res % 1000000007;
}
int num[1000005];
int main() {
  int n, x;
  long long res = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    long long tmp = getsum(x);
    res = (res + 1ll * (1 + tmp - num[x]) * x % 1000000007) % 1000000007;
    add(x, (1 + tmp - num[x]) * x % 1000000007);
    num[x] = 1 + tmp;
  }
  printf("%lld\n", (res % 1000000007 + 1000000007) % 1000000007);
  return 0;
}
