#include <bits/stdc++.h>
using namespace std;
long long tree[1000010];
long long dp[1000010];
void update(int idx, long long val) {
  while (idx < 1000010) {
    tree[idx] += val;
    idx += (idx & (-idx));
  }
}
long long query(int idx) {
  long long ret = 0;
  while (idx > 0) {
    ret += tree[idx];
    if (ret >= 1000000007) ret -= 1000000007;
    idx -= (idx & (-idx));
  }
  return ret;
}
long long arr[1000010];
int N;
inline void ReadInput(void) {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%I64d", &arr[i]);
}
inline void solve(void) {
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    long long foo, bar, candy;
    foo = dp[arr[i]];
    int y = arr[i];
    long long xx = (query(y));
    xx++;
    xx %= 1000000007;
    xx *= (arr[i]);
    xx %= 1000000007;
    bar = xx;
    ans += bar;
    if (ans >= 1000000007) ans -= 1000000007;
    ans -= foo;
    if (ans < 0) ans += 1000000007;
    dp[arr[i]] = (bar);
    long long x = dp[arr[i]] - foo;
    if (x < 0) x += 1000000007;
    update(arr[i], x);
  }
  printf("%I64d\n", ans);
}
inline void Refresh(void) {}
int main() {
  ios_base::sync_with_stdio(false);
  ReadInput();
  solve();
  return 0;
}
