#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 10, MAXV = 1e6 + 10;
;
int n, ans;
int last[MAXV], tree[MAXV];
inline void upd(int &a, int b) {
  a = a + b >= MOD ? a + b - MOD : a + b;
  return;
}
inline int lowbit(int x) { return x & (-x); }
inline int query(int x) {
  int ans = 0;
  for (int i = x; i; i -= lowbit(i)) upd(ans, tree[i]);
  return ans;
}
inline void update(int x, int v) {
  for (int i = x; i < MAXV; i += lowbit(i)) upd(tree[i], v);
  return;
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    int sum = (1ll * query(x) * x % MOD + x - last[x] + MOD) % MOD;
    upd(ans, sum);
    last[x] = (1ll * query(x) * x % MOD + x) % MOD;
    update(x, sum);
  }
  printf("%d\n", ans);
  return 0;
}
