#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7, iv = 5e8 + 4;
struct quji {
  int l, r, mid, he[2], su[2], pr, laz[2];
} c[100102 << 2];
int n, a[100102], s[100102], tot, pre[100102], nxt[100102], ap[100102],
    s1[100102], tot1, s2[100102], tot2;
void bt(int ind, int l, int r) {
  c[ind].l = l;
  c[ind].r = r;
  c[ind].mid = (l + r) >> 1;
  c[ind].laz[0] = c[ind].laz[1] = -1;
  if (l == r) return;
  bt(ind << 1, l, c[ind].mid);
  bt(ind << 1 | 1, c[ind].mid + 1, r);
}
inline void pushup(int ind) {
  c[ind].he[0] = (c[ind << 1].he[0] + c[ind << 1 | 1].he[0]) % p;
  c[ind].he[1] = (c[ind << 1].he[1] + c[ind << 1 | 1].he[1]) % p;
  c[ind].su[0] = (c[ind << 1].su[0] + c[ind << 1 | 1].su[0]) % p;
  c[ind].su[1] = (c[ind << 1].su[1] + c[ind << 1 | 1].su[1]) % p;
  c[ind].pr = (c[ind << 1].pr + c[ind << 1 | 1].pr) % p;
}
inline void setrg(int ind, int x, int op) {
  c[ind].laz[op] = x;
  c[ind].he[op] = 1ll * (c[ind].r - c[ind].l + 1) * x % p;
  c[ind].su[op] = 1ll * x * (c[ind].r - c[ind].l + 1) % p *
                  (c[ind].r + c[ind].l) % p * iv % p;
  c[ind].pr = 1ll * x * c[ind].he[op ^ 1] % p;
  c[ind].laz[op] = x;
}
inline void pushdown(int ind) {
  if (c[ind].laz[0] != -1) {
    setrg(ind << 1, c[ind].laz[0], 0);
    setrg(ind << 1 | 1, c[ind].laz[0], 0);
    c[ind].laz[0] = -1;
  }
  if (c[ind].laz[1] != -1) {
    setrg(ind << 1, c[ind].laz[1], 1);
    setrg(ind << 1 | 1, c[ind].laz[1], 1);
    c[ind].laz[1] = -1;
  }
}
void chng(int ind, int l, int r, int x, int op) {
  if (l <= c[ind].l && c[ind].r <= r) {
    setrg(ind, x, op);
    return;
  }
  pushdown(ind);
  if (l <= c[ind].mid) chng(ind << 1, l, r, x, op);
  if (r > c[ind].mid) chng(ind << 1 | 1, l, r, x, op);
  pushup(ind);
}
int askhe(int ind, int l, int r, int op) {
  if (l <= c[ind].l && c[ind].r <= r) return c[ind].he[op];
  pushdown(ind);
  int ret = 0;
  if (l <= c[ind].mid) ret += askhe(ind << 1, l, r, op);
  if (r > c[ind].mid) (ret += askhe(ind << 1 | 1, l, r, op)) %= p;
  return ret;
}
int asksu(int ind, int l, int r, int op) {
  if (l <= c[ind].l && c[ind].r <= r) return c[ind].su[op];
  pushdown(ind);
  int ret = 0;
  if (l <= c[ind].mid) ret += asksu(ind << 1, l, r, op);
  if (r > c[ind].mid) (ret += asksu(ind << 1 | 1, l, r, op)) %= p;
  return ret;
}
int askpr(int ind, int l, int r) {
  if (l <= c[ind].l && c[ind].r <= r) return c[ind].pr;
  pushdown(ind);
  int ret = 0;
  if (l <= c[ind].mid) ret += askpr(ind << 1, l, r);
  if (r > c[ind].mid) (ret += askpr(ind << 1 | 1, l, r)) %= p;
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s[++tot] = a[i];
  sort(s + 1, s + 1 + tot);
  tot = unique(s + 1, s + 1 + tot) - s - 1;
  for (int i = 1; i <= n; i++) a[i] = lower_bound(s + 1, s + 1 + tot, a[i]) - s;
  for (int i = 1; i <= n; i++) pre[i] = ap[a[i]], ap[a[i]] = i;
  for (int i = 1; i <= n; i++) ap[a[i]] = n + 1;
  for (int i = n; i; i--) nxt[i] = ap[a[i]], ap[a[i]] = i;
  s1[0] = s2[0] = n + 1;
  int ans = 0;
  bt(1, 1, n);
  for (int i = n, j = n; i; i--) {
    while (tot1 && pre[i] >= pre[s1[tot1]]) tot1--;
    chng(1, i, s1[tot1] - 1, pre[i] + 1, 0);
    s1[++tot1] = i;
    while (tot2 && nxt[i] <= nxt[s2[tot2]]) tot2--;
    chng(1, i, s2[tot2] - 1, nxt[i] - 1, 1);
    s2[++tot2] = i;
    while (j > i && (askhe(1, j, j, 0) > i || askhe(1, j, j, 1) < j)) j--;
    ans = (ans + 1ll * i * askhe(1, i, j, 1) % p) % p;
    ans = (ans - 1ll * i * (i + j) % p * (j - i + 1) % p * iv % p + p) % p;
    ans = (ans - askpr(1, i, j) + p) % p;
    ans = (ans + asksu(1, i, j, 0)) % p;
  }
  printf("%d\n", ans);
}
