#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005, mod = 1000000007, maxt = maxn << 2;
int n, tot, ans, top;
int a[maxn], lc[maxt], rc[maxt], pre[maxn], suf[maxn], cnt[maxn], stk[maxn],
    lazy[maxt][2], val[maxt][4], lst[maxn], prer[maxn], sufr[maxn];
map<int, int> mp;
inline int getsum(int a) { return 1ll * a * (a + 1) / 2ll % mod; }
void build(int l, int r, int now) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  lc[now] = now << 1, rc[now] = now << 1 | 1;
  build(l, mid, lc[now]), build(mid + 1, r, rc[now]);
}
inline void pushup(int now) {
  for (int i = 0; i <= 3; i++)
    val[now][i] = (val[lc[now]][i] + val[rc[now]][i]) % mod;
}
inline void getlazy(int l, int r, int now, int v, int id) {
  if (id == 0) {
    val[now][0] = 1ll * (r - l + 1) * v % mod;
    val[now][2] = 1ll * val[now][1] * v % mod;
    val[now][3] = 1ll * (getsum(r) - getsum(l - 1) + mod) % mod * v % mod;
    lazy[now][0] = v;
  }
  if (id == 1) {
    val[now][1] = 1ll * (r - l + 1) * v % mod;
    val[now][2] = 1ll * val[now][0] * v % mod;
    lazy[now][1] = v;
  }
}
inline void pushdown(int l, int r, int now) {
  int mid = (l + r) >> 1;
  if (lazy[now][0])
    getlazy(l, mid, lc[now], lazy[now][0], 0),
        getlazy(mid + 1, r, rc[now], lazy[now][0], 0), lazy[now][0] = 0;
  if (lazy[now][1])
    getlazy(l, mid, lc[now], lazy[now][1], 1),
        getlazy(mid + 1, r, rc[now], lazy[now][1], 1), lazy[now][1] = 0;
}
void update(int l, int r, int now, int L, int R, int val, int id) {
  if (L <= l && r <= R) {
    getlazy(l, r, now, val, id);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(l, r, now);
  if (L <= mid) update(l, mid, lc[now], L, R, val, id);
  if (mid < R) update(mid + 1, r, rc[now], L, R, val, id);
  pushup(now);
}
int query(int l, int r, int now, int L, int R, int id) {
  if (L <= l && r <= R) return val[now][id];
  int mid = (l + r) >> 1, res = 0;
  pushdown(l, r, now);
  if (L <= mid) res = query(l, mid, lc[now], L, R, id);
  if (mid < R) res = (res + query(mid + 1, r, rc[now], L, R, id)) % mod;
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (mp[a[i]] == 0) mp[a[i]] = ++tot;
    a[i] = mp[a[i]];
  }
  for (int i = 1; i <= tot; i++) lst[i] = 0;
  for (int i = 1; i <= n; i++) pre[i] = lst[a[i]] + 1, lst[a[i]] = i;
  for (int i = 1; i <= tot; i++) lst[i] = n + 1;
  for (int i = n; i >= 1; i--) suf[i] = lst[a[i]] - 1, lst[a[i]] = i;
  build(1, n, 1);
  top = 0;
  for (int i = n; i >= 1; i--) {
    while (top && pre[i] > pre[stk[top]]) top--;
    prer[i] = top == 0 ? n : (stk[top] - 1), stk[++top] = i;
  }
  top = 0;
  for (int i = n; i >= 1; i--) {
    while (top && suf[i] < suf[stk[top]]) top--;
    sufr[i] = top == 0 ? n : (stk[top] - 1), stk[++top] = i;
  }
  for (int i = n, j = n; i >= 1; i--) {
    update(1, n, 1, i, prer[i], pre[i], 0),
        update(1, n, 1, i, sufr[i], suf[i], 1);
    cnt[a[i]]++;
    while (cnt[a[i]] > 1) cnt[a[j]]--, j--;
    ans = (ans + 1ll * i * query(1, n, 1, i, j, 1) % mod) % mod;
    ans = (ans + mod - 1ll * i * (getsum(j) - getsum(i - 1) + mod) % mod) % mod;
    ans = (ans + mod - query(1, n, 1, i, j, 2)) % mod;
    ans = (ans + query(1, n, 1, i, j, 3)) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
