#include <bits/stdc++.h>
using namespace std;
const double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230;
void swaps(char *x, char *y) {
  char temp;
  temp = *x;
  *x = *y;
  *y = temp;
}
void swapi(int *a, int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a == 1 || b == 1) return 1;
  if (a == b) return a;
  if (a > b)
    return gcd(b, a % b);
  else
    return gcd(a, b % a);
}
long long Tree[40 * 100010];
int maxval;
long long x[100010];
long long dp[100010];
int last[100010 * 10];
void update(int idx, int val) {
  while (idx <= maxval) {
    Tree[idx] += val;
    idx += (idx & -idx);
  }
}
long long Query(int idx) {
  long long sum = 0;
  while (idx > 0) {
    sum = (sum + Tree[idx]) % 1000000007;
    idx -= (idx & -idx);
  }
  return sum;
}
int main() {
  int N;
  scanf("%d", &N);
  long long maxi = 0;
  for (int i = (1); i < (N + 1); i++) {
    cin >> x[i];
    maxi = max(maxi, x[i]);
  }
  int mini = int(maxi);
  maxval = mini;
  long long sum;
  for (int i = (1); i < (N + 1); i++) {
    sum = Query(x[i]);
    sum = ((sum * x[i]) % 1000000007 + x[i]) % 1000000007;
    dp[i] = sum;
    sum = sum - dp[last[x[i]]];
    if (sum < 0) sum += 1000000007;
    update(x[i], sum);
    last[x[i]] = i;
  }
  cout << Query(mini) << endl;
  return 0;
}
