#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const long long MOD = 1000000007;
int N;
vector<long long> sum(MAXN, 0);
vector<long long> tempSum(MAXN, 0);
vector<int> mark(MAXN, 0);
inline int LowBit(int x) { return x & (-x); }
void Insert(int x, long long data) {
  for (int i = x; i <= MAXN - 1; i += LowBit(i)) {
    sum[i] += data;
    sum[i] %= MOD;
  }
}
long long GetSum(int x) {
  long long ans = 0;
  for (int i = x; i > 0; i -= LowBit(i)) {
    ans += sum[i];
    ans %= MOD;
  }
  return ans;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    int x;
    scanf("%d", &x);
    long long tempAns = (GetSum(x) + 1) * (long long)x % MOD;
    Insert(x, (tempAns - tempSum[x] + MOD) % MOD);
    tempSum[x] = tempAns;
  }
  printf("%lld\n", GetSum(MAXN - 1));
  return 0;
}
