#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], kf[maxn << 2], f[maxn << 2], g[maxn << 2], fg[maxn << 2],
    lzg[maxn << 2], lzf[maxn << 2], pre[maxn], nxt[maxn], nf[maxn], ng[maxn],
    st[maxn], top = 0, sm[maxn];
map<int, int> pos, cnt;
void pushf(int rt, int v, int l, int r) {
  fg[rt] = 1ll * v * g[rt] % mod;
  lzf[rt] = v;
  kf[rt] = 1ll * v * (sm[r] - sm[l - 1]) % mod;
  f[rt] = 1ll * v * (r - l + 1) % mod;
}
void pushg(int rt, int v, int l, int r) {
  fg[rt] = 1ll * v * f[rt] % mod;
  g[rt] = 1ll * v * (r - l + 1) % mod;
  lzg[rt] = v;
}
void pushdown(int rt, int l, int r) {
  if (lzf[rt]) {
    int mid = l + r >> 1;
    pushf(rt << 1, lzf[rt], l, mid);
    pushf(rt << 1 | 1, lzf[rt], mid + 1, r);
    lzf[rt] = 0;
  }
  if (lzg[rt]) {
    int mid = l + r >> 1;
    pushg(rt << 1, lzg[rt], l, mid);
    pushg(rt << 1 | 1, lzg[rt], mid + 1, r);
    lzg[rt] = 0;
  }
}
void pushup(int rt) {
  fg[rt] = (fg[rt << 1] + fg[rt << 1 | 1]) % mod;
  kf[rt] = (kf[rt << 1] + kf[rt << 1 | 1]) % mod;
  g[rt] = (g[rt << 1] + g[rt << 1 | 1]) % mod;
  f[rt] = (f[rt << 1] + f[rt << 1 | 1]) % mod;
}
void cg(int rt, int l, int r, int ql, int qr, int v, int op) {
  if (l >= ql && r <= qr) {
    if (op == 0) {
      pushf(rt, v, l, r);
    } else {
      pushg(rt, v, l, r);
    }
    return;
  }
  pushdown(rt, l, r);
  int mid = l + r >> 1;
  if (ql <= mid) cg(rt << 1, l, mid, ql, qr, v, op);
  if (qr >= mid + 1) cg(rt << 1 | 1, mid + 1, r, ql, qr, v, op);
  pushup(rt);
}
struct Node {
  int g, fg, kf;
};
Node merge(Node u, Node v) {
  return Node{(u.g + v.g) % mod, (u.fg + v.fg) % mod, (u.kf + v.kf) % mod};
}
Node qry(int rt, int l, int r, int ql, int qr) {
  if (l >= ql && r <= qr) {
    return Node{g[rt], fg[rt], kf[rt]};
  }
  pushdown(rt, l, r);
  int mid = l + r >> 1;
  Node ans = Node{0, 0, 0};
  if (ql <= mid) ans = merge(ans, qry(rt << 1, l, mid, ql, qr));
  if (qr >= mid + 1) ans = merge(ans, qry(rt << 1 | 1, mid + 1, r, ql, qr));
  pushup(rt);
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    sm[i] = (sm[i - 1] + i) % mod;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pre[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  pos.clear();
  for (int i = n; i >= 1; --i) {
    if (!pos.count(a[i]))
      nxt[i] = n + 1;
    else
      nxt[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  pos.clear();
  top = 0;
  for (int i = n; i >= 1; --i) {
    while (top && pre[i] >= pre[st[top]]) --top;
    nf[i] = top ? st[top] - 1 : n;
    st[++top] = i;
  }
  top = 0;
  for (int i = n; i >= 1; --i) {
    while (top && nxt[i] <= nxt[st[top]]) --top;
    ng[i] = top ? st[top] - 1 : n;
    st[++top] = i;
  }
  int ans = 0;
  for (int i = n, j = n; i >= 1; --i) {
    cg(1, 1, n, i, nf[i], pre[i] + 1, 0);
    cg(1, 1, n, i, ng[i], nxt[i] - 1, 1);
    cnt[a[i]]++;
    while (cnt[a[i]] > 1) cnt[a[j]]--, j--;
    Node now = qry(1, 1, n, i, j);
    ans = (ans + (((1ll * i * now.g % mod - now.fg) % mod -
                   1ll * i * ((sm[j] - sm[i - 1]) % mod) % mod) %
                      mod +
                  now.kf) %
                     mod) %
          mod;
  }
  ans = (ans + mod) % mod;
  printf("%d\n", ans);
}
