#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
template <class T>
inline T read() {
  char ch;
  T x = 0;
  bool flag = false;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-') flag = true;
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
  return flag ? -x : x;
}
struct {
  inline operator int() { return read<int>(); }
  template <class T>
  inline void operator()(T &x) {
    x = *this;
  }
  template <class T, class... A>
  inline void operator()(T &x, A &...a) {
    x = *this, this->operator()(a...);
  }
} IN;
template <class T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int dec(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline void sub(int &x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
inline void pls(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
const int N = 1e5 + 5;
int n, a[N], vis[N];
int pl[N], pre[N], sl[N], suf[N];
inline void init_presuf() {
  static int b[N], m;
  for (int i = 1; i <= n; ++i) b[i] = a[i];
  std::sort(b + 1, b + 1 + n), m = 1;
  for (int i = 2; i <= n; ++i)
    if (b[i] != b[m]) b[++m] = b[i];
  for (int i = 1; i <= n; ++i)
    a[i] = std::lower_bound(b + 1, b + 1 + m, a[i]) - b;
  for (int i = 1; i <= n; ++i) pre[i] = vis[a[i]] + 1, vis[a[i]] = i;
  for (int i = 0; i <= n; ++i) vis[i] = n + 1;
  for (int i = n; i >= 1; --i) suf[i] = vis[a[i]] - 1, vis[a[i]] = i;
  static int sta[N], top;
  sta[top = 0] = 0;
  for (int i = 1; i <= n; ++i) {
    while (top && pre[sta[top]] < pre[i]) --top;
    pl[i] = sta[top], sta[++top] = i;
  }
  sta[top = 0] = 0;
  for (int i = 1; i <= n; ++i) {
    while (top && suf[sta[top]] > suf[i]) --top;
    sl[i] = sta[top], sta[++top] = i;
  }
}
int tag[N << 2][2], sum[N << 2][4];
inline void addtag(int x, int l, int r, int t, int val) {
  sum[x][2] = mul(val, sum[x][t ^ 1]), sum[x][t] = mul(val, r - l + 1),
  tag[x][t] = val;
  if (t == 1) sum[x][3] = mul(val, (1ll * (l + r) * (r - l + 1) / 2ll) % mod);
}
inline void pushup(int x) {
  for (int i = 0; i <= 3; ++i)
    sum[x][i] = add(sum[((x) << 1)][i], sum[((x) << 1 | 1)][i]);
}
inline void pushdown(int x, int l, int r) {
  for (int i = 0; i <= 1; ++i)
    if (~tag[x][i])
      addtag(((x) << 1), l, ((l + r) >> 1), i, tag[x][i]),
          addtag(((x) << 1 | 1), ((l + r) >> 1) + 1, r, i, tag[x][i]),
          tag[x][i] = -1;
}
void modify(int x, int l, int r, int L, int R, int typ, int val) {
  if (L <= l && r <= R) return addtag(x, l, r, typ, val), void();
  pushdown(x, l, r);
  if (L <= ((l + r) >> 1))
    modify(((x) << 1), l, ((l + r) >> 1), L, R, typ, val);
  if (R > ((l + r) >> 1))
    modify(((x) << 1 | 1), ((l + r) >> 1) + 1, r, L, R, typ, val);
  pushup(x);
}
int query(int x, int l, int r, int L, int R, int typ) {
  if (L == l && r == R) return sum[x][typ];
  pushdown(x, l, r);
  if (R <= ((l + r) >> 1))
    return query(((x) << 1), l, ((l + r) >> 1), L, R, typ);
  if (L > ((l + r) >> 1))
    return query(((x) << 1 | 1), ((l + r) >> 1) + 1, r, L, R, typ);
  return add(
      query(((x) << 1), l, ((l + r) >> 1), L, ((l + r) >> 1), typ),
      query(((x) << 1 | 1), ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, R, typ));
}
int main() {
  IN(n);
  for (int i = 1; i <= n; ++i) IN(a[i]);
  init_presuf(), memset(tag, -1, sizeof(tag));
  int ans = 0, l = 0;
  for (int r = 1; r <= n; ++r) {
    chkmax(l, pre[r]);
    modify(1, 1, n, pl[r] + 1, r, 0, pre[r]);
    modify(1, 1, n, sl[r] + 1, r, 1, suf[r]);
    sub(ans, mul(r, (1ll * (l + r) * (r - l + 1) / 2ll) % mod));
    pls(ans, mul(r, query(1, 1, n, l, r, 0)));
    pls(ans, query(1, 1, n, l, r, 3));
    sub(ans, query(1, 1, n, l, r, 2));
  }
  printf("%d\n", ans);
  return 0;
}
