#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100010];
long long in[1000000 + 100];
int lowbit(int t) { return t & (t ^ (t - 1)); }
int sum(int end) {
  long long sum = 0LL;
  while (end > 0) {
    sum = (sum + in[end]) % 1000000007;
    end -= lowbit(end);
  }
  return sum;
}
void update(int pos, long long v) {
  while (pos <= 1000000) {
    in[pos] = (in[pos] + v) % 1000000007;
    pos += lowbit(pos);
  }
  return;
}
int main(int argc, char *argv[]) {
  long long x, y;
  long long res, v;
  for (int i = 0; i < 1000000 + 1; i += 1) {
    in[i] = 0LL;
  }
  cin >> n;
  for (int i = 0; i < n; i += 1) {
    cin >> a[i];
  }
  res = 0LL;
  for (int i = 0; i < n; i += 1) {
    x = sum(a[i]);
    y = sum(a[i] - 1);
    v = (x + 1) * a[i] % 1000000007;
    res = (v - (x - y) + res) % 1000000007;
    update(a[i], v - (x - y));
  }
  cout << res << endl;
  return 0;
}
