#include <bits/stdc++.h>
using namespace std;
const int N = 100005, mod = 1e9 + 7;
int n, nn, n1, n2, lst[N], L[N], R[N], b[N], a[N], S1[N], S2[N];
long long ans, t1[N << 2], t2[N << 2];
struct st {
  long long mn, mx, smn, s;
} T[N << 2];
inline long long S(int n) { return 1ll * n * (n + 1) / 2; }
inline void add(long long& a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
inline st operator+(const st& a, const st& b) {
  return (st){(a.mn + b.mn) % mod, (a.mx + b.mx) % mod, (a.smn + b.smn) % mod,
              (a.s + b.s) % mod};
}
inline void up(int x) { T[x] = T[x << 1] + T[x << 1 | 1]; }
inline void c1(int x, int l, int r, int v) {
  add(t1[x], v);
  add(T[x].s, 1ll * v * T[x].mx % mod);
  add(T[x].mn, 1ll * (r - l + 1) * v % mod);
  add(T[x].smn, (S(r) - S(l - 1)) % mod * v % mod);
}
inline void c2(int x, int l, int r, int v) {
  add(t2[x], v);
  add(T[x].s, 1ll * v * T[x].mn % mod);
  add(T[x].mx, 1ll * (r - l + 1) * v % mod);
}
inline void dn(int x, int l, int r) {
  int mid = l + r >> 1;
  if (t1[x])
    c1(x << 1, l, mid, t1[x]), c1(x << 1 | 1, mid + 1, r, t1[x]), t1[x] = 0;
  if (t2[x])
    c2(x << 1, l, mid, t2[x]), c2(x << 1 | 1, mid + 1, r, t2[x]), t2[x] = 0;
}
void upd(int x, int l, int r, int tl, int tr, int v, int o) {
  if (tl <= l && r <= tr) {
    (o ? c2(x, l, r, v) : c1(x, l, r, v));
    return;
  }
  int mid = l + r >> 1;
  dn(x, l, r);
  if (tl <= mid) upd(x << 1, l, mid, tl, tr, v, o);
  if (tr > mid) upd(x << 1 | 1, mid + 1, r, tl, tr, v, o);
  up(x);
}
st qry(int x, int l, int r, int tl, int tr) {
  if (tl <= l && r <= tr) return T[x];
  int mid = l + r >> 1;
  dn(x, l, r);
  if (tr <= mid) return qry(x << 1, l, mid, tl, tr);
  if (tl > mid) return qry(x << 1 | 1, mid + 1, r, tl, tr);
  return qry(x << 1, l, mid, tl, tr) + qry(x << 1 | 1, mid + 1, r, tl, tr);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), b[i] = a[i];
  sort(b + 1, b + n + 1);
  nn = unique(b + 1, b + n + 1) - b - 1;
  for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + nn + 1, a[i]) - b;
  for (int i = 1; i <= n; i++) L[i] = lst[a[i]] + 1, lst[a[i]] = i;
  for (int i = 1; i <= n; i++) lst[i] = n + 1;
  for (int i = n; i >= 1; i--) R[i] = lst[a[i]] - 1, lst[a[i]] = i;
  for (int i = 1, l = 1; i <= n; i++) {
    for (; n1 && L[i] >= L[S1[n1]]; n1--)
      upd(1, 1, n, S1[n1 - 1] + 1, S1[n1], mod - L[S1[n1]], 1);
    upd(1, 1, n, S1[n1] + 1, i, L[i], 1);
    S1[++n1] = i;
    for (; n2 && R[i] <= R[S2[n2]]; n2--)
      upd(1, 1, n, S2[n2 - 1] + 1, S2[n2], mod - R[S2[n2]], 0);
    upd(1, 1, n, S2[n2] + 1, i, R[i], 0);
    S2[++n2] = i;
    l = max(l, L[i]);
    st res = qry(1, 1, n, l, i);
    ans = (ans +
           (res.smn + 1ll * i * res.mx % mod - res.s -
            (S(i) - S(l - 1)) % mod * i % mod) %
               mod +
           mod) %
          mod;
  }
  printf("%lld\n", ans);
  return 0;
}
