#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, N;
  cin >> N;
  vector<int> A, list;
  for (i = 0; i < (int)(N); i++) {
    int a;
    cin >> a;
    A.push_back(a);
    list.push_back(A[i]);
  }
  sort(list.begin(), list.end());
  map<int, int> m_idx;
  map<int, long long> accm;
  for (i = 0; i < (int)(((int)list.size())); i++) {
    if (i == 0 || list[i] != list[i - 1]) m_idx[list[i]] = i;
    accm[list[i]] = 0;
  }
  int P = 1;
  while (P < N) P *= 2;
  vector<long long> tree = vector<long long>(P * 2, 0);
  for (i = 0; i < (int)(N); i++) {
    int idx = m_idx[A[i]];
    int goal = idx + P;
    m_idx[A[i]]++;
    long long num = list[idx];
    int tmp = goal;
    while (tmp > 1) {
      if (tmp % 2 == 1) num = (num + list[idx] * tree[tmp - 1]) % 1000000007LL;
      tmp /= 2;
    }
    num = (num + 1000000007LL - accm[list[idx]]) % 1000000007LL;
    tree[goal] = num;
    accm[list[idx]] = (accm[list[idx]] + num) % 1000000007LL;
    while (goal > 1) {
      goal /= 2;
      tree[goal] = (tree[goal * 2] + tree[goal * 2 + 1]) % 1000000007LL;
    }
  }
  long long result = 0;
  for (i = P; i < P * 2; ++i) result = (result + tree[i]) % 1000000007LL;
  cout << result << endl;
  return 0;
}
