#include <bits/stdc++.h>
using namespace std;
int const N = 100000, md = 1e9 + 7;
int n, bf[N + 1], af[N + 1], tmp[N + 1], x[N + 1];
inline int ad(int x, int y) {
  x += y;
  return x >= md ? x - md : x;
}
inline void sba(int &x, int y) {
  if ((x -= y) < 0) x += md;
}
inline int sb(int x, int y) {
  sba(x, y);
  return x;
}
struct S {
  int sml, smr;
  int mnl, mxr;
  int an;
  int vl, vr;
  S() {}
  S(int l, int i, int r) {
    vr = smr = mxr = r;
    vl = mnl = l;
    sml = i - l;
    an = (long long)sml * smr % md;
  }
  S operator+(S const &o) const {
    S a;
    a.sml = ad(sml, o.sml);
    a.smr = ad(smr, o.smr);
    a.mnl = min(mnl, o.mnl);
    a.mxr = max(mxr, o.mxr);
    a.an = ad(an, o.an);
    a.vl = vl == o.vl ? vl : -1;
    a.vr = vr == o.vr ? vr : -1;
    return a;
  }
} sg[N << 2];
inline void uppl(int id, int v, int l, int r) {
  sba(sg[id].an, (long long)sb(v, sg[id].vl) * sg[id].smr % md);
  sba(sg[id].sml, (long long)(r - l + 1) * sb(v, sg[id].vl) % md);
  sg[id].mnl = sg[id].vl = v;
}
inline void uppr(int id, int v, int l, int r) {
  sba(sg[id].an, (long long)sb(sg[id].vr, v) * sg[id].sml % md);
  sba(sg[id].smr, (long long)(r - l + 1) * sb(sg[id].vr, v) % md);
  sg[id].mxr = sg[id].vr = v;
}
inline void sl(int id, int a, int b, int l, int m, int r) {
  if (sg[id].vl != -1) {
    if (sg[id].vl != sg[a].vl && sg[a].vl != -2) uppl(a, sg[id].vl, l, m);
    if (sg[id].vl != sg[b].vl && sg[b].vl != -2) uppl(b, sg[id].vl, m + 1, r);
  }
  if (sg[id].vr != -1) {
    if (sg[id].vr != sg[a].vr && sg[a].vr != -2) uppr(a, sg[id].vr, l, m);
    if (sg[id].vr != sg[b].vr && sg[b].vr != -2) uppr(b, sg[id].vr, m + 1, r);
  }
}
void upl(int x, int y, int v, int l = 1, int r = n, int id = 1) {
  if (l > y || r < x || v <= sg[id].mnl) return;
  if (l >= x && r <= y && sg[id].vl != -1) return uppl(id, v, l, r);
  int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
  sl(id, a, b, l, m, r);
  upl(x, y, v, l, m, a);
  upl(x, y, v, m + 1, r, b);
  sg[id] = sg[a] + sg[b];
}
void upr(int x, int y, int v, int l = 1, int r = n, int id = 1) {
  if (l > y || r < x || v >= sg[id].mxr) return;
  if (l >= x && r <= y && sg[id].vr != -1) return uppr(id, v, l, r);
  int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
  sl(id, a, b, l, m, r);
  upr(x, y, v, l, m, a);
  upr(x, y, v, m + 1, r, b);
  sg[id] = sg[a] + sg[b];
}
void setan(int x, int y, int l = 1, int r = n, int id = 1) {
  if (l > y || r < x) return;
  if (l >= x && r <= y) {
    sg[id].an = sg[id].sml = sg[id].smr = 0;
    sg[id].vl = sg[id].vr = -2;
    return;
  }
  int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
  sl(id, a, b, l, m, r);
  setan(x, y, l, m, a);
  setan(x, y, m + 1, r, b);
  sg[id] = sg[a] + sg[b];
}
void st(int i, int l = 1, int r = n, int id = 1) {
  if (l == r) {
    sg[id] = S(bf[i] + 1, i, af[i] - 1);
    return;
  }
  int m = l + r >> 1, a = id << 1, b = id << 1 | 1;
  sl(id, a, b, l, m, r);
  if (i <= m)
    st(i, l, m, a);
  else
    st(i, m + 1, r, b);
  sg[id] = sg[a] + sg[b];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < (int)(n + 1); ++i) scanf("%d", x + i);
  vector<int> mp(n);
  for (int i = 1; i < (int)(n + 1); ++i) mp[i - 1] = x[i];
  sort(mp.begin(), mp.end());
  mp.resize(unique(mp.begin(), mp.end()) - mp.begin());
  for (int i = 1; i < (int)(n + 1); ++i)
    x[i] = lower_bound(mp.begin(), mp.end(), x[i]) - mp.begin() + 1;
  for (int i = 1; i < (int)(n + 1); ++i) bf[i] = tmp[x[i]], tmp[x[i]] = i;
  for (int i = 1; i < (int)(mp.size() + 1); ++i) tmp[i] = n + 1;
  for (int i = n; i > 0; --i) af[i] = tmp[x[i]], tmp[x[i]] = i;
  int an = 0, mx = 0;
  for (int i = 1; i < (int)(n + 1); ++i) {
    mx = max(mx, bf[i]);
    if (mx) setan(1, mx);
    if (mx + 1 != i) upl(mx + 1, i - 1, bf[i] + 1);
    if (mx + 1 != i) upr(mx + 1, i - 1, af[i] - 1);
    st(i);
    int t = an;
    an = ad(an, sb(sg[1].an, (long long)sg[1].sml * i % md));
  }
  printf("%d\n", an);
  return 0;
}
