#include <bits/stdc++.h>
using namespace std;
long long n, a[100010], mod = 7 + 1e9, ans, DP[100010];
bool use[1000010];
map<long long, long long> last;
struct node_ {
  node_ *l, *r;
  long long value, priority, tamSubArbol, sumAns;
  node_(long long v, long long p)
      : value(v),
        priority(p),
        tamSubArbol(0),
        l(nullptr),
        r(nullptr),
        sumAns(0LL) {}
};
typedef node_ *pnode;
node_ *createNode(long long v = 0, long long p = 0) {
  node_ *x = new node_(v, p);
  return x;
}
long long getTam(pnode u) { return u ? u->tamSubArbol : 0LL; }
long long getAns(pnode u) {
  if (!u) return 0LL;
  return u->sumAns;
}
void updTam(pnode u) {
  if (!u) return;
  u->tamSubArbol = getTam(u->l) + getTam(u->r) + 1LL;
  u->sumAns =
      (((getAns(u->l) + getAns(u->r)) % mod) + DP[last[u->value]]) % mod;
  return;
}
void split(pnode t, long long value, pnode &L, pnode &R) {
  if (!t) {
    L = R = nullptr;
    return;
  }
  if (t->value < value) {
    split(t->r, value, t->r, R);
    L = t;
  } else {
    split(t->l, value, L, t->l);
    R = t;
  }
  updTam(t);
  return;
}
void merge(pnode &t, pnode L, pnode R) {
  if (!L | !R) {
    t = L ? L : R;
    return;
  }
  if (L->priority > R->priority) {
    merge(L->r, L->r, R);
    t = L;
  } else {
    merge(R->l, L, R->l);
    t = R;
  }
  updTam(t);
  return;
}
void insertNode(pnode &t, pnode nd) {
  if (!t) {
    t = nd;
    updTam(t);
    return;
  }
  if (t->priority >= nd->priority) {
    insertNode(t->value > nd->value ? t->l : t->r, nd);
  } else {
    split(t, nd->value, nd->l, nd->r);
    t = nd;
  }
  updTam(t);
  return;
}
void eraseNode(pnode &t, long long value) {
  if (!t) return;
  if (t->value == value) {
    merge(t, t->l, t->r);
  } else {
    eraseNode(t->value >= value ? t->l : t->r, value);
  }
  updTam(t);
  return;
}
void print(pnode currentNode) {
  if (!currentNode) return;
  print(currentNode->l);
  cout << currentNode->value << " " << currentNode->sumAns << endl;
  print(currentNode->r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  uniform_int_distribution<int> priorities(0, 500000000);
  pnode root = nullptr, L, R;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  DP[n - 1] = a[n - 1];
  last[a[n - 1]] = n - 1;
  use[a[n - 1]] = true;
  insertNode(root, createNode(a[n - 1], priorities(rng)));
  for (long long i = n - 2; i >= 0; i--) {
    split(root, a[i], L, R);
    DP[i] = (getAns(R) * a[i]) % mod;
    DP[i] += a[i];
    DP[i] %= mod;
    merge(root, L, R);
    if (use[a[i]]) {
      eraseNode(root, a[i]);
    }
    last[a[i]] = i;
    insertNode(root, createNode(a[i], priorities(rng)));
    use[a[i]] = true;
  }
  for (auto val : last) ans = (ans + DP[val.second]) % mod;
  cout << ans;
  return 0;
}
