#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
namespace ModCalculator {
const int MOD = 1e9 + 7;
inline void Inc(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
inline void Dec(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
inline int Add(int x, int y) {
  Inc(x, y);
  return x;
}
inline int Sub(int x, int y) {
  Dec(x, y);
  return x;
}
inline int Mul(int x, int y) { return 1LL * x * y % MOD; }
inline int Ksm(int x, int k) {
  int ret = 1;
  for (; k; k >>= 1) {
    if (k & 1) ret = Mul(ret, x);
    x = Mul(x, x);
  }
  return ret;
}
inline int Inv(int x) { return Ksm(x, MOD - 2); }
}  // namespace ModCalculator
using namespace ModCalculator;
inline int S1(int x) { return 1LL * x * (x + 1) / 2 % MOD; }
int n, a[MAXN], L[MAXN], R[MAXN];
map<int, int> mp;
int stk1[MAXN], top1, stk2[MAXN], top2;
int len[MAXN << 2], sum[MAXN << 2], mntg[MAXN << 2], mxtg[MAXN << 2];
int tx[MAXN << 2], ty[MAXN << 2], txx[MAXN << 2], txy[MAXN << 2], ans[3];
inline void putmn(int rt, int tg) {
  Inc(tx[rt], Mul(tg, len[rt]));
  Inc(txx[rt], Mul(tg, sum[rt]));
  Inc(txy[rt], Mul(tg, ty[rt]));
  Inc(mntg[rt], tg);
}
inline void putmx(int rt, int tg) {
  Inc(ty[rt], Mul(tg, len[rt]));
  Inc(txy[rt], Mul(tg, tx[rt]));
  Inc(mxtg[rt], tg);
}
inline void pushdown(int rt) {
  if (mntg[rt]) {
    putmn((rt << 1), mntg[rt]);
    putmn((rt << 1) | 1, mntg[rt]);
    mntg[rt] = 0;
  }
  if (mxtg[rt]) {
    putmx((rt << 1), mxtg[rt]);
    putmx((rt << 1) | 1, mxtg[rt]);
    mxtg[rt] = 0;
  }
}
inline void pushup(int rt) {
  tx[rt] = Add(tx[(rt << 1)], tx[(rt << 1) | 1]);
  ty[rt] = Add(ty[(rt << 1)], ty[(rt << 1) | 1]);
  txx[rt] = Add(txx[(rt << 1)], txx[(rt << 1) | 1]);
  txy[rt] = Add(txy[(rt << 1)], txy[(rt << 1) | 1]);
}
void Build(int rt, int b, int e) {
  len[rt] = e - b + 1;
  sum[rt] = Sub(S1(e), S1(b - 1));
  if (b == e) return;
  int mid = (b + e) >> 1;
  Build((rt << 1), b, mid);
  Build((rt << 1) | 1, mid + 1, e);
}
void Update(int rt, int b, int e, int l, int r, int v, int op) {
  if (l <= b && e <= r) {
    op ? putmx(rt, v) : putmn(rt, v);
    return;
  }
  int mid = (b + e) >> 1;
  pushdown(rt);
  if (l <= mid) Update((rt << 1), b, mid, l, r, v, op);
  if (r > mid) Update((rt << 1) | 1, mid + 1, e, l, r, v, op);
  pushup(rt);
}
void Query(int rt, int b, int e, int l, int r) {
  if (l <= b && e <= r) {
    Inc(ans[0], ty[rt]);
    Inc(ans[1], txx[rt]);
    Inc(ans[2], txy[rt]);
    return;
  }
  int mid = (b + e) >> 1;
  pushdown(rt);
  if (l <= mid) Query((rt << 1), b, mid, l, r);
  if (r > mid) Query((rt << 1) | 1, mid + 1, e, l, r);
}
void init() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    mp[a[i]] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    L[i] = mp[a[i]] + 1;
    mp[a[i]] = i;
  }
  for (int i = n; i >= 1; --i) {
    mp[a[i]] = n + 1;
  }
  for (int i = n; i >= 1; --i) {
    R[i] = mp[a[i]] - 1;
    mp[a[i]] = i;
  }
}
void solve() {
  Build(1, 1, n);
  int Ans = 0;
  for (int i = 1, j = 1; i <= n; ++i) {
    j = max(j, L[i]);
    while (top1 && R[i] <= R[stk1[top1]]) {
      Update(1, 1, n, stk1[top1 - 1] + 1, stk1[top1], MOD - R[stk1[top1]], 0);
      --top1;
    }
    Update(1, 1, n, stk1[top1] + 1, i, R[i], 0);
    stk1[++top1] = i;
    while (top2 && L[i] >= L[stk2[top2]]) {
      Update(1, 1, n, stk2[top2 - 1] + 1, stk2[top2], MOD - L[stk2[top2]], 1);
      --top2;
    }
    Update(1, 1, n, stk2[top2] + 1, i, L[i], 1);
    stk2[++top2] = i;
    ans[0] = ans[1] = ans[2] = 0;
    Query(1, 1, n, j, i);
    Inc(Ans, ans[1]);
    Dec(Ans, ans[2]);
    Inc(Ans, Mul(ans[0], i));
    Dec(Ans, Mul(Sub(S1(i), S1(j - 1)), i));
  }
  printf("%d\n", Ans);
}
int main() {
  init();
  solve();
  return 0;
}
