#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long n, ans, a[420000], c[420000], tag[420000][2], lst[420000],
    nxt[420000], vis[420000], cnt[420000];
struct node {
  long long n, s, l, r, lr, sr, minl, maxl, minr, maxr;
  node(long long n = 0, long long s = 0, long long l = 0, long long r = 0,
       long long lr = 0, long long sr = 0, long long minl = 0,
       long long maxl = 0, long long minr = 0, long long maxr = 0)
      : n(n),
        s(s),
        l(l),
        r(r),
        lr(lr),
        sr(sr),
        minl(minl),
        maxl(maxl),
        minr(minr),
        maxr(maxr) {}
  node operator+(const node &p) const {
    return node(n + p.n, s + p.s, l + p.l, r + p.r, lr + p.lr, sr + p.sr,
                min(minl, p.minl), max(maxl, p.maxl), min(minr, p.minr),
                max(maxr, p.maxr));
  }
} s[420000];
void build(long long x, long long l, long long r) {
  tag[x][0] = tag[x][1] = -1;
  if (l == r) {
    s[x] = node(1, l, 1, n, n, l * n, 1, 1, n, n);
    return;
  }
  long long mid = (l + r) >> 1;
  build((x << 1), l, mid);
  build((x << 1 | 1), mid + 1, r);
  s[x] = s[(x << 1)] + s[(x << 1 | 1)];
}
void psd(long long x) {
  long long num, sum, u = tag[x][0], v = tag[x][1];
  if (~u) {
    num = s[(x << 1)].n, sum = s[(x << 1)].s;
    s[(x << 1)] =
        node(num, sum, u * num, s[(x << 1)].r, u * s[(x << 1)].r,
             s[(x << 1)].sr, u, u, s[(x << 1)].minr, s[(x << 1)].maxr);
    num = s[(x << 1 | 1)].n, sum = s[(x << 1 | 1)].s;
    s[(x << 1 | 1)] = node(num, sum, u * num, s[(x << 1 | 1)].r,
                           u * s[(x << 1 | 1)].r, s[(x << 1 | 1)].sr, u, u,
                           s[(x << 1 | 1)].minr, s[(x << 1 | 1)].maxr);
    tag[(x << 1)][0] = tag[(x << 1 | 1)][0] = tag[x][0];
  }
  if (~v) {
    num = s[(x << 1)].n, sum = s[(x << 1)].s;
    s[(x << 1)] = node(num, sum, s[(x << 1)].l, v * num, s[(x << 1)].l * v,
                       sum * v, s[(x << 1)].minl, s[(x << 1)].maxl, v, v);
    num = s[(x << 1 | 1)].n, sum = s[(x << 1 | 1)].s;
    s[(x << 1 | 1)] =
        node(num, sum, s[(x << 1 | 1)].l, v * num, s[(x << 1 | 1)].l * v,
             sum * v, s[(x << 1 | 1)].minl, s[(x << 1 | 1)].maxl, v, v);
    tag[(x << 1)][1] = tag[(x << 1 | 1)][1] = tag[x][1];
  }
  tag[x][0] = tag[x][1] = -1;
}
void mdf(long long x, long long l, long long r, long long L, long long R,
         long long u, long long v) {
  if (l >= L && r <= R) {
    long long num = s[x].n, sum = s[x].s;
    if (s[x].maxl < u) {
      s[x] = node(num, sum, u * num, s[x].r, u * s[x].r, s[x].sr, u, u,
                  s[x].minr, s[x].maxr);
      tag[x][0] = u;
    }
    if (s[x].minr > v) {
      s[x] = node(num, sum, s[x].l, v * num, s[x].l * v, sum * v, s[x].minl,
                  s[x].maxl, v, v);
      tag[x][1] = v;
    }
    if (s[x].minl >= u && s[x].maxr <= v) return;
    long long mid = (l + r) >> 1;
    psd(x);
    if (L <= mid) mdf((x << 1), l, mid, L, R, u, v);
    if (R > mid) mdf((x << 1 | 1), mid + 1, r, L, R, u, v);
    s[x] = s[(x << 1)] + s[(x << 1 | 1)];
    return;
  }
  long long mid = (l + r) >> 1;
  psd(x);
  if (L <= mid) mdf((x << 1), l, mid, L, R, u, v);
  if (R > mid) mdf((x << 1 | 1), mid + 1, r, L, R, u, v);
  s[x] = s[(x << 1)] + s[(x << 1 | 1)];
}
node qry(long long x, long long l, long long r, long long L, long long R) {
  if (l >= L && r <= R) return s[x];
  long long mid = (l + r) >> 1;
  psd(x);
  if (R <= mid) return qry((x << 1), l, mid, L, R);
  if (L > mid) return qry((x << 1 | 1), mid + 1, r, L, R);
  return qry((x << 1), l, mid, L, R) + qry((x << 1 | 1), mid + 1, r, L, R);
}
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; ++i) {
    scanf("%lld", a + i);
    c[i] = a[i];
  }
  sort(c + 1, c + n + 1);
  for (long long i = 1; i <= n; ++i)
    a[i] = lower_bound(c + 1, c + n + 1, a[i]) - c;
  for (long long i = 1; i <= n; ++i) {
    lst[i] = vis[a[i]] + 1;
    vis[a[i]] = i;
  }
  for (long long i = 1; i <= n; ++i) vis[a[i]] = n + 1;
  for (long long i = n; i; --i) {
    nxt[i] = vis[a[i]] - 1;
    vis[a[i]] = i;
  }
  build(1, 1, n);
  for (long long i = 1, j = 1; i <= n; ++i) {
    ++cnt[a[i]];
    for (; cnt[a[i]] > 1; ++j) --cnt[a[j]];
    mdf(1, 1, n, j, i, lst[i], nxt[i]);
    node p = qry(1, 1, n, j, i);
    ans += p.sr - i * p.s - p.lr + p.l * i;
  }
  printf("%lld\n", ans % mod);
  return 0;
}
