#include <bits/stdc++.h>
using namespace std;
void RD(int &x) { scanf("%d", &x); }
void RD(long long &x) { scanf("%I64d", &x); }
void RD(unsigned long long &x) { scanf("%I64u", &x); }
void RD(unsigned int &x) { scanf("%u", &x); }
void RD(double &x) { scanf("%lf", &x); }
void RD(int &x, int &y) { scanf("%d%d", &x, &y); }
void RD(long long &x, long long &y) { scanf("%I64d%I64d", &x, &y); }
void RD(unsigned int &x, unsigned int &y) { scanf("%u%u", &x, &y); }
void RD(double &x, double &y) { scanf("%lf%lf", &x, &y); }
void RD(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
void RD(long long &x, long long &y, long long &z) {
  scanf("%I64d%I64d%I64d", &x, &y, &z);
}
void RD(unsigned int &x, unsigned int &y, unsigned int &z) {
  scanf("%u%u%u", &x, &y, &z);
}
void RD(double &x, double &y, double &z) { scanf("%lf%lf%lf", &x, &y, &z); }
void RD(char &x) { x = getchar(); }
void RD(char *s) { scanf("%s", s); }
void RD(string &s) { cin >> s; }
void PR(int x) { printf("%d\n", x); }
void PR(int x, int y) { printf("%d %d\n", x, y); }
void PR(long long x) { printf("%I64d\n", x); }
void PR(unsigned int x) { printf("%u\n", x); }
void PR(unsigned long long x) { printf("%I64u\n", x); }
void PR(double x) { printf("%.6lf\n", x); }
void PR(char x) { printf("%c\n", x); }
void PR(char *x) { printf("%s\n", x); }
void PR(string x) { cout << x << endl; }
const int mod = 1e9 + 7;
const long long inf = ((long long)1) << 60;
const double dinf = 1e50;
const int INF = 1000000000;
const int N = 1000005;
int n, s[N];
void add(int pos, int x) {
  while (pos < N) {
    s[pos] = (s[pos] + x) % mod;
    pos += pos & -pos;
  }
}
int get(int pos) {
  int ans = 0;
  while (pos) {
    ans = (ans + s[pos]) % mod;
    pos -= pos & -pos;
  }
  return ans;
}
int pre[N], a[N];
int main() {
  RD(n);
  memset(pre, -1, sizeof(pre));
  int i, x;
  for (i = 1; i <= n; i++) {
    RD(x);
    a[i] = (long long)(get(x) + 1) * x % mod;
    if (pre[x] != -1) add(x, mod - a[pre[x]]), a[pre[x]] = 0;
    pre[x] = i;
    add(x, a[i]);
  }
  int ans = 0;
  for (i = 1; i <= n; i++) ans = (ans + a[i]) % mod;
  PR(ans);
  return 0;
}
