#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using std::bitset;
using namespace std;
struct BIT {
  long long c[1001000], sz;
  void init(long long n) {
    memset(c, 0, sizeof(c));
    ;
    sz = n;
  }
  void update(long long x, long long v) {
    for (; x <= sz; x += x & (-x)) c[x] = (c[x] + v) % 1000000007;
  }
  long long getsum(long long x) {
    long long ans = 0;
    for (; x > 0; x -= x & (-x)) ans += c[x];
    return ans % 1000000007;
  }
};
BIT bit;
long long a[1001000], n, mm;
long long cnt[1001000], dp[1001000];
int main() {
  long long i, j, tem;
  while (scanf("%I64d", &n) != EOF) {
    mm = 0;
    memset(cnt, 0, sizeof(cnt));
    ;
    for (i = 1; i <= n; i++) {
      scanf("%I64d", &a[i]);
      mm = max(mm, a[i]);
    }
    bit.init(mm);
    long long ans = 0;
    dp[0] = 0;
    for (i = 1; i <= n; i++) {
      tem = bit.getsum(a[i]);
      dp[i] = ((tem + 1) * a[i] - cnt[a[i]] + 1000000007) % 1000000007;
      ans += dp[i];
      cnt[a[i]] = (cnt[a[i]] + dp[i]) % 1000000007;
      bit.update(a[i], dp[i]);
    }
    printf("%I64d\n", ans % 1000000007);
  }
  return 0;
}
