#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int MAX2 = 1e6 + 6;
const int LIM = 2097160;
const int MOD = 1e9 + 7;
template <typename T>
void inpos(T &x) {
  x = 0;
  register T c = getchar();
  while (((c < 48) || (c > 57)) && (c != '-')) c = getchar();
  bool neg = false;
  if (c == '-') neg = true;
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);
  if (neg) x = -x;
}
template <typename T>
void outpos(T n) {
  if (n < 0) putchar('-'), n *= -1;
  char snum[65];
  int i = 0;
  do {
    snum[i++] = n % 10 + '0';
    n /= 10;
  } while (n);
  i = i - 1;
  while (i >= 0) putchar(snum[i--]);
  putchar('\n');
}
int add(int a, int b, int c) {
  int res = a + b;
  return (res >= c ? res - c : res);
}
int mod_neg(int a, int b, int c) {
  int res;
  if (abs(a - b) < c)
    res = a - b;
  else
    res = (a - b) % c;
  return (res < 0 ? res + c : res);
}
int mul(int a, int b, int c) {
  long long res = (long long)a * b;
  return (res >= c ? res % c : res);
}
int a[MAX];
int dp[MAX];
int seg[LIM];
int mark[MAX2];
void update(int t, int i, int j, int x, int y) {
  if (i > x || j < x) {
    return;
  }
  if (i == j) {
    seg[t] = add(seg[t], y, MOD);
    return;
  }
  int mid = (i + j) / 2;
  update(t * 2, i, mid, x, y);
  update(t * 2 + 1, mid + 1, j, x, y);
  seg[t] = add(seg[t * 2], seg[t * 2 + 1], MOD);
}
int query(int t, int i, int j, int l, int r) {
  if (i > r || j < l) {
    return 0;
  }
  if (l <= i && j <= r) {
    return seg[t];
  }
  int mid = (i + j) / 2;
  int a = query(t * 2, i, mid, l, r);
  int b = query(t * 2 + 1, mid + 1, j, l, r);
  return add(a, b, MOD);
}
int main() {
  int n, high = 0;
  inpos(n);
  for (int i = 1; i <= n; ++i) {
    inpos(a[i]);
    high = max(high, a[i]);
  }
  dp[1] = a[1];
  mark[a[1]] = 1;
  update(1, 1, high, a[1], dp[1]);
  for (int i = 2; i <= n; ++i) {
    dp[i] = mul(query(1, 1, high, 1, a[i]), a[i], MOD);
    dp[i] = add(dp[i], a[i], MOD);
    if (!mark[a[i]]) {
      mark[a[i]] = 1;
    } else {
      int temp = query(1, 1, high, 1, a[i]) - query(1, 1, high, 1, a[i] - 1);
      if (temp < 0) {
        temp += MOD;
      }
      dp[i] = mod_neg(dp[i], temp, MOD);
    }
    update(1, 1, high, a[i], dp[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = add(ans, dp[i], MOD);
  }
  printf("%d\n", ans);
  return 0;
}
