#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return a < 0 ? (-a) : a;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
int n, num[100005], last[1000005];
struct segTree {
  long long s;
} seg[4 * 100005];
vector<pair<int, int> > VP;
void insert(int cs, long long val, int ci, int s, int e) {
  if (s == e) {
    seg[cs].s = val;
    return;
  }
  int mid = (s + e) / 2;
  if (ci <= mid)
    insert(2 * cs, val, ci, s, mid);
  else
    insert(2 * cs + 1, val, ci, mid + 1, e);
  seg[cs].s = seg[2 * cs].s + seg[2 * cs + 1].s;
  seg[cs].s %= 1000000007;
}
long long find(int cs, int ds, int de, int s, int e) {
  if (ds == s && de == e) return seg[cs].s;
  int mid = (s + e) / 2;
  long long sum = 0;
  if (ds <= mid) sum += find(2 * cs, ds, min(de, mid), s, mid);
  if (de > mid) sum += find(2 * cs + 1, max(mid + 1, ds), de, mid + 1, e);
  return sum % 1000000007;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    int cn;
    cin >> cn;
    VP.push_back(make_pair(cn, i));
  }
  sort(VP.begin(), VP.end());
  for (int i = 0; i < (n); ++i) {
    long long val;
    if (last[VP[i].first] == 0) {
      val = VP[i].first;
      if (VP[i].second > 0) val += find(1, 1, VP[i].second, 1, n) * VP[i].first;
      val %= 1000000007;
    } else {
      val = find(1, last[VP[i].first], last[VP[i].first], 1, n) * VP[i].first;
      val %= 1000000007;
      if (last[VP[i].first] != VP[i].second)
        val = val +
              find(1, last[VP[i].first] + 1, VP[i].second, 1, n) * VP[i].first;
      val %= 1000000007;
    }
    last[VP[i].first] = VP[i].second + 1;
    insert(1, val, VP[i].second + 1, 1, n);
  }
  cout << seg[1].s << endl;
  return 0;
}
