#include <bits/stdc++.h>
using namespace std;
const int Maxx = 100005, Maxn = 2001, INF = 0x3f3f3f3f, Mod = 1e9 + 7;
inline int read() {
  int res = 0, bj = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') bj |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9')
    res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
  return bj ? -res : res;
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 ^ 48);
}
inline void printnum(int x, char ch) {
  if (x < 0) putchar('-'), x = -x;
  print(x), putchar(ch);
}
inline int Mo(const int x) { return x >= Mod ? x - Mod : x; }
inline void Add(int &x, const int y) { x = Mo(x + y); }
struct node {
  int ln, ca, cb, mn, fa, fb, sa, sb, ml;
  inline node(int a = 0) { fa = fb = sa = sb = ml = a, ln = mn = ca = cb = 0; }
  inline void Pa(const int A) {
    ca = A, fa = (long long)A * ln % Mod, sa = (long long)mn * A % Mod,
    ml = (long long)A * fb % Mod;
  }
  inline void Pb(const int B) {
    cb = B, fb = (long long)B * ln % Mod, sb = (long long)mn * B % Mod,
    ml = (long long)B * fa % Mod;
  }
  inline void Merge(const node &l, const node &r) {
    fa = Mo(l.fa + r.fa), fb = Mo(l.fb + r.fb), sa = Mo(l.sa + r.sa),
    sb = Mo(l.sb + r.sb), ml = Mo(l.ml + r.ml);
  }
} t[Maxx << 2], Res;
int Ql, Qr, Qv;
inline void Pushdown(int p) {
  if (t[p].ca) t[p << 1].Pa(t[p].ca), t[p << 1 | 1].Pa(t[p].ca), t[p].ca = 0;
  if (t[p].cb) t[p << 1].Pb(t[p].cb), t[p << 1 | 1].Pb(t[p].cb), t[p].cb = 0;
}
void Build(int p, int l, int r) {
  if (l == r)
    t[p].ln = 1, t[p].mn = l;
  else {
    int mid = l + r >> 1;
    Build(p << 1, l, mid), Build(p << 1 | 1, mid + 1, r);
    t[p].ln = t[p << 1].ln + t[p << 1 | 1].ln;
    t[p].mn = t[p << 1].mn + t[p << 1 | 1].mn;
  }
}
void ChangeA(int p, int l, int r) {
  if (Ql <= l && r <= Qr)
    t[p].Pa(Qv);
  else {
    int mid = l + r >> 1;
    Pushdown(p);
    if (Ql <= mid) ChangeA(p << 1, l, mid);
    if (Qr > mid) ChangeA(p << 1 | 1, mid + 1, r);
    t[p].Merge(t[p << 1], t[p << 1 | 1]);
  }
}
void ChangeB(int p, int l, int r) {
  if (Ql <= l && r <= Qr)
    t[p].Pb(Qv);
  else {
    int mid = l + r >> 1;
    Pushdown(p);
    if (Ql <= mid) ChangeB(p << 1, l, mid);
    if (Qr > mid) ChangeB(p << 1 | 1, mid + 1, r);
    t[p].Merge(t[p << 1], t[p << 1 | 1]);
  }
}
void Ask(int p, int l, int r) {
  if (Ql <= l && r <= Qr)
    Res.Merge(Res, t[p]);
  else {
    int mid = l + r >> 1;
    Pushdown(p);
    if (Ql <= mid) Ask(p << 1, l, mid);
    if (Qr > mid) Ask(p << 1 | 1, mid + 1, r);
  }
}
int n, m, A[Maxx], B[Maxx], L[Maxx], R[Maxx];
int mt[Maxx], tl, sl[Maxx], tr, sr[Maxx];
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) A[i] = B[i] = read();
  sort(B + 1, B + n + 1), m = unique(B + 1, B + n + 1) - B - 1;
  for (int i = 1; i <= n; ++i) A[i] = lower_bound(B + 1, B + m + 1, A[i]) - B;
  for (int i = 1; i <= n; ++i) L[i] = mt[A[i]], mt[A[i]] = i;
  for (int i = 1; i <= m; ++i) mt[i] = n + 1;
  for (int i = n; i; --i) R[i] = mt[A[i]], mt[A[i]] = i;
  memset(mt, 0, sizeof(int) * (m + 1));
  long long Ans = 0;
  Build(1, 1, n);
  for (int i = 1, l = 1; i <= n; ++i) {
    while (tr && R[sr[tr]] > R[i]) --tr;
    Ql = sr[tr] + 1, Qr = sr[++tr] = i, Qv = R[i] - 1, ChangeA(1, 1, n);
    while (tl && L[sl[tl]] < L[i]) --tl;
    Ql = sl[tl] + 1, Qr = sl[++tl] = i, Qv = L[i] + 1, ChangeB(1, 1, n);
    ++mt[A[i]];
    while (mt[A[i]] > 1) --mt[A[l++]];
    Res = 0, Ql = l, Qr = i, Ask(1, 1, n);
    Ans = (Ans + Res.sa + Mod - Res.ml +
           i * (Res.fb - ((long long)(Ql + Qr) * (Qr - Ql + 1) >> 1) % Mod +
                Mod)) %
          Mod;
  }
  cout << Ans << "\n";
  return 0;
}
