#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
const int md = 1000000007;
using namespace std;
struct r {
  int a, id;
};
int n, i, p, a[300005];
long long q;
r b[100005];
bool comp(r a, r b) { return (a.a < b.a || (a.a == b.a && a.id < b.id)); }
int build_tree(int n) {
  int j = 1;
  while (j < n) j *= 2;
  for (int i = 1; i <= j + n - 1; i++) a[i] = 0;
  return j - 1;
}
void renew(int v) {
  v /= 2;
  while (v > 0) {
    a[v] = (a[2 * v] + a[2 * v + 1]) % md;
    v /= 2;
  }
}
long long find(int l, int r) {
  long long ans = 0;
  while (l <= r) {
    if (l % 2 == 1) {
      ans += a[l];
      l++;
    }
    if (r % 2 == 0) {
      ans += a[r];
      r--;
    }
    l /= 2;
    r /= 2;
  }
  return ans % md;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> b[i].a;
    b[i].id = i;
  }
  sort(b + 1, b + n + 1, comp);
  p = build_tree(n);
  i = 1;
  while (i <= n) {
    q = find(p + 1, p + b[i].id - 1);
    q = (q * b[i].a + b[i].a) % md;
    a[p + b[i].id] = q;
    renew(p + b[i].id);
    while (i + 1 <= n && b[i].a == b[i + 1].a) {
      i++;
      q = a[p + b[i - 1].id] + find(p + b[i - 1].id + 1, p + b[i].id - 1);
      q = (q * b[i].a) % md;
      a[p + b[i].id] = q;
      renew(p + b[i].id);
    }
    i++;
  }
  long long ans = 0;
  for (i = p + 1; i <= p + n; i++) ans += a[i];
  cout << ans % md << endl;
}
