#include <bits/stdc++.h>
using namespace std;
int n, a[100005], suc[100005], pre[100005], ans;
map<int, int> mAp;
int sm[100005 << 2][2][2], len[100005 << 2], SM[100005 << 2], szm[100005 << 2],
    tg[100005 << 2][2];
void dtp(int u, int v, int t) {
  sm[u][t][0] = 1ll * len[u] * v % 1000000007;
  sm[u][t][1] = 1ll * SM[u] * v % 1000000007;
  szm[u] = 1ll * v * sm[u][t ^ 1][0] % 1000000007;
  tg[u][t] = v;
}
void dt(int u) {
  for (int t = (0), LIM = (1); t <= LIM; t++)
    if (tg[u][t]) {
      dtp(u << 1, tg[u][t], t), dtp(u << 1 | 1, tg[u][t], t);
      tg[u][t] = 0;
    }
}
void Build(int u, int l, int r) {
  len[u] = r - l + 1;
  if (l == r) return (void)(SM[u] = l);
  int m = l + r >> 1;
  Build(u << 1, l, m), Build(u << 1 | 1, m + 1, r);
  SM[u] = (SM[u << 1] + SM[u << 1 | 1]) % 1000000007;
}
void upd(int u) {
  for (int i = (0), LIM = (1); i <= LIM; i++)
    for (int j = (0), LIM = (1); j <= LIM; j++)
      sm[u][i][j] = (sm[u << 1][i][j] + sm[u << 1 | 1][i][j]) % 1000000007;
  szm[u] = (szm[u << 1] + szm[u << 1 | 1]) % 1000000007;
}
void ins(int u, int l, int r, int ql, int qr, int v, int t) {
  if (l > qr || ql > r || ql > qr) return;
  if (ql <= l && r <= qr) return (void)(dtp(u, v, t));
  int m = l + r >> 1;
  dt(u);
  ins(u << 1, l, m, ql, qr, v, t), ins(u << 1 | 1, m + 1, r, ql, qr, v, t);
  upd(u);
}
void qry(int u, int l, int r, int ql, int qr) {
  if (l > qr || ql > r || ql > qr) return;
  if (ql <= l && r <= qr) {
    ans = (ans + 1ll * sm[u][0][0] * ql + sm[u][1][1] - szm[u] -
           SM[u] * 1ll * ql) %
          1000000007;
    return;
  }
  int m = l + r >> 1;
  dt(u);
  qry(u << 1, l, m, ql, qr), qry(u << 1 | 1, m + 1, r, ql, qr);
}
int main() {
  scanf("%d", &n);
  for (int i = (1), LIM = (n); i <= LIM; i++) scanf("%d", &a[i]);
  for (int i = (n), LIM = (1); i >= LIM; i--) {
    if (mAp.count(a[i]))
      suc[i] = mAp[a[i]] - 1;
    else
      suc[i] = n;
    mAp[a[i]] = i;
  }
  mAp.clear();
  for (int i = (1), LIM = (n); i <= LIM; i++) {
    if (mAp.count(a[i]))
      pre[i] = mAp[a[i]] + 1;
    else
      pre[i] = 1;
    mAp[a[i]] = i;
  }
  stack<int> sta[2];
  int R = n;
  mAp.clear();
  Build(1, 1, n);
  for (int i = (n), LIM = (1); i >= LIM; i--) {
    for (; !sta[0].empty() && suc[i] <= suc[sta[0].top()]; sta[0].pop())
      ;
    ins(1, 1, n, i, sta[0].empty() ? n : sta[0].top() - 1, suc[i], 0);
    sta[0].push(i);
    for (; !sta[1].empty() && pre[i] >= pre[sta[1].top()]; sta[1].pop())
      ;
    ins(1, 1, n, i, sta[1].empty() ? n : sta[1].top() - 1, pre[i], 1);
    sta[1].push(i);
    for (; mAp[a[i]] > 0; mAp[a[R--]]--)
      ;
    mAp[a[i]]++;
    qry(1, 1, n, i, R);
  }
  printf("%d\n", (ans + 1000000007) % 1000000007);
}
