#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 1e6 + 5, MOD = 1e9 + 7;
int t, n, m, k, x, y, w;
struct ft {
  vector<long long> s;
  int n;
  ft(int n) : s(n + 10), n(n) {}
  void add(int pos, long long val) {
    ++pos;
    while (pos < s.size()) {
      s[pos] += val;
      s[pos] %= MOD;
      pos += pos & -pos;
    }
  }
  long long get(int pos) {
    ++pos;
    long long ans = 0;
    while (pos > 0) {
      ans += s[pos];
      ans %= MOD;
      pos -= pos & -pos;
    }
    return ans;
  }
};
int vs[LIM];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  ft f(LIM);
  for (int i = 0; i < n; ++i) {
    cin >> x;
    long long cans = x + f.get(x) * x % MOD;
    if (vs[x]) f.add(x, f.get(x - 1) - f.get(x));
    f.add(x, cans);
    cans %= MOD;
    vs[x] = 1;
  }
  cout << f.get(LIM - 1) << '\n';
  return 0;
}
