#include <bits/stdc++.h>
using namespace std;
long long dp[1000010], c[1000010];
int nn = 1000000;
int lowbit(int x) { return x & (-x); }
void add(int x, long long val) {
  while (x <= nn) {
    c[x] = (c[x] + val) % 1000000007;
    x += lowbit(x);
  }
}
long long getsum(int x) {
  long long sum = 0;
  while (x > 0) {
    sum = (c[x] + sum) % 1000000007;
    x -= lowbit(x);
  }
  return sum;
}
int main() {
  int i, n, x;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    long long tmp = dp[x];
    dp[x] = (getsum(x) * x + x) % 1000000007;
    add(x, ((dp[x] - tmp) % 1000000007 + 1000000007) % 1000000007);
  }
  long long ans = 0;
  for (i = 1; i <= 1000000; i++) {
    ans += dp[i];
  }
  ans %= 1000000007;
  cout << ans << endl;
  return 0;
}
