#include <bits/stdc++.h>
using namespace std;
class ITree {
 private:
  vector<int> T;
  int p;

 public:
  ITree(int n) {
    p = 1;
    while (p < n) p *= 2;
    T.resize(2 * p - 1, 0);
  }
  void Insert(int l, int v) {
    l += p - 1;
    T[l] = (T[l] + v) % 1000000007;
    while (l > 0) {
      l = ((l - 1) / 2);
      T[l] = (T[l] + v) % 1000000007;
    }
    return;
  }
  int Query(int l, int r) {
    l += p - 1;
    r += p - 1;
    int ans = T[l];
    if (l < r) ans = (ans + T[r]) % 1000000007;
    while (((l - 1) / 2) != ((r - 1) / 2)) {
      if (l % 2 == 1) ans = (ans + T[l + 1]) % 1000000007;
      if (r % 2 == 0) ans = (ans + T[r - 1]) % 1000000007;
      l = ((l - 1) / 2);
      r = ((r - 1) / 2);
    }
    return ans;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> T(n);
  for (int i = (0); i <= ((int)(T).size() - 1); ++i) cin >> T[i];
  vector<pair<int, int> > P;
  vector<vector<int> > Occ(1000002);
  for (int i = (0); i <= ((int)(T).size() - 1); ++i) {
    P.push_back(make_pair(T[i], i));
    Occ[T[i]].push_back(i);
  }
  for (int i = (0); i <= ((int)(Occ).size() - 1); ++i) Occ[i].push_back(n - 1);
  sort(P.begin(), P.end());
  ITree Tree(n);
  vector<int> DP(n, 0);
  for (int j = ((int)(P).size() - 1); j >= (0); --j) {
    int i = P[j].second, val = T[i],
        it_next = 1 + (lower_bound(Occ[val].begin(), Occ[val].end(), i) -
                       Occ[val].begin());
    long long int q = Tree.Query(i, Occ[val][it_next]);
    DP[i] = (q * val) % 1000000007;
    if (it_next == (int)(Occ[val]).size() - 1)
      DP[i] = (DP[i] + val) % 1000000007;
    Tree.Insert(i, DP[i]);
  }
  int ans = 0;
  for (int i = (0); i <= ((int)(DP).size() - 1); ++i)
    ans = (ans + DP[i]) % 1000000007;
  cout << ans;
  return 0;
}
