#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline void Max(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void Min(T &a, T b) {
  if (a > b) a = b;
}
const int N = 1e5 + 7, mod = 1e9 + 7;
int n, vc;
long long ans;
int lst[N], L[N], R[N], V[N], a[N];
int st1[N], st2[N], tp1, tp2;
long long s1(int n) { return 1ll * n * (n + 1) / 2; }
long long ami[N << 2], amx[N << 2];
struct data {
  long long mi, mx, smi, tm;
  data operator+(const data &rhs) const {
    return (data){(mi + rhs.mi) % mod, (mx + rhs.mx) % mod,
                  (smi + rhs.smi) % mod, (tm + rhs.tm) % mod};
  }
} t[N << 2];
void add(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
void stmi(int l, int r, int o, int v) {
  add(ami[o], v);
  add(t[o].tm, 1ll * v * t[o].mx % mod);
  add(t[o].mi, 1ll * (r - l + 1) * v % mod);
  add(t[o].smi, (s1(r) - s1(l - 1)) % mod * v % mod);
}
void stmx(int l, int r, int o, int v) {
  add(amx[o], v);
  add(t[o].tm, 1ll * v * t[o].mi % mod);
  add(t[o].mx, 1ll * (r - l + 1) * v % mod);
}
void pushdown(int l, int r, int o) {
  int mid = l + r >> 1;
  if (ami[o]) {
    stmi(l, mid, o << 1, ami[o]);
    stmi(mid + 1, r, (o << 1 | 1), ami[o]);
  }
  if (amx[o]) {
    stmx(l, mid, o << 1, amx[o]);
    stmx(mid + 1, r, (o << 1 | 1), amx[o]);
  }
  ami[o] = amx[o] = 0;
}
void pushup(int o) { t[o] = t[o << 1] + t[(o << 1 | 1)]; }
void modify(int L, int R, int l, int r, int o, int v, int opt) {
  if (L <= l && r <= R) {
    if (!opt)
      stmi(l, r, o, v);
    else
      stmx(l, r, o, v);
    return;
  }
  pushdown(l, r, o);
  int mid = l + r >> 1;
  if (L <= mid) modify(L, R, l, mid, o << 1, v, opt);
  if (R > mid) modify(L, R, mid + 1, r, (o << 1 | 1), v, opt);
  pushup(o);
}
data query(int L, int R, int l, int r, int o) {
  if (L <= l && r <= R) return t[o];
  pushdown(l, r, o);
  int mid = l + r >> 1;
  if (R <= mid) return query(L, R, l, mid, o << 1);
  if (L > mid) return query(L, R, mid + 1, r, (o << 1 | 1));
  return query(L, R, l, mid, o << 1) + query(L, R, mid + 1, r, (o << 1 | 1));
}
int main() {
  n = gi();
  for (int i = 1; i <= n; ++i) a[i] = gi(), V[i] = a[i];
  sort(V + 1, V + 1 + n);
  vc = unique(V + 1, V + 1 + n) - V - 1;
  for (int i = 1; i <= n; ++i) a[i] = lower_bound(V + 1, V + 1 + vc, a[i]) - V;
  for (int i = 1; i <= n; ++i) {
    L[i] = lst[a[i]] + 1;
    lst[a[i]] = i;
  }
  for (int i = 1; i <= vc; ++i) lst[i] = n + 1;
  for (int i = n; i; --i) {
    R[i] = lst[a[i]] - 1;
    lst[a[i]] = i;
  }
  for (int i = 1, gg = 1; i <= n; ++i) {
    for (; tp1 && L[i] >= L[st1[tp1]]; --tp1) {
      modify(st1[tp1 - 1] + 1, st1[tp1], 1, n, 1, mod - L[st1[tp1]], 1);
    }
    modify(st1[tp1] + 1, i, 1, n, 1, L[i], 1);
    st1[++tp1] = i;
    for (; tp2 && R[i] <= R[st2[tp2]]; --tp2) {
      modify(st2[tp2 - 1] + 1, st2[tp2], 1, n, 1, mod - R[st2[tp2]], 0);
    }
    modify(st2[tp2] + 1, i, 1, n, 1, R[i], 0);
    st2[++tp2] = i;
    Max(gg, L[i]);
    data res = query(gg, i, 1, n, 1);
    long long tmp = ((res.smi + i * res.mx % mod - res.tm -
                      (s1(i) - s1(gg - 1)) % mod * i % mod) %
                         mod +
                     mod) %
                    mod;
    add(ans, tmp);
  }
  printf("%lld\n", ans);
  return 0;
}
