#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
int n, a[maxn], mp[maxn], lst[maxn], cnt[maxn], pre[maxn], suc[maxn], fp[maxn],
    fs[maxn], sta[maxn], top;
long long sum[maxn << 2][4], lazy[maxn << 2][2];
inline long long sum_2(long long x) { return x * (x + 1) / 2; }
inline long long S(int l, int r) { return sum_2(r) - sum_2(l - 1); }
inline void pushup(int rt) {
  for (int i = 0; i < 4; i++)
    sum[rt][i] = sum[(rt << 1)][i] + sum[(rt << 1 | 1)][i];
}
inline void pushlazy(int rt, int l, int r, int z, int op) {
  sum[rt][2] = sum[rt][op ^ 1] * z;
  sum[rt][op] = (long long)(r - l + 1) * z;
  lazy[rt][op] = z;
  if (op == 0) sum[rt][3] = z * S(l, r);
}
inline void pushdown(int rt, int l, int r) {
  int mid = (l + r) >> 1;
  if (lazy[rt][0]) {
    pushlazy((rt << 1), l, mid, lazy[rt][0], 0);
    pushlazy((rt << 1 | 1), mid + 1, r, lazy[rt][0], 0);
    lazy[rt][0] = 0;
  }
  if (lazy[rt][1]) {
    pushlazy((rt << 1), l, mid, lazy[rt][1], 1);
    pushlazy((rt << 1 | 1), mid + 1, r, lazy[rt][1], 1);
    lazy[rt][1] = 0;
  }
}
void update(int rt, int l, int r, int x, int y, int z, int op) {
  if (x <= l && r <= y) {
    pushlazy(rt, l, r, z, op);
    return;
  }
  pushdown(rt, l, r);
  int mid = (l + r) >> 1;
  if (x <= mid) update((rt << 1), l, mid, x, y, z, op);
  if (y > mid) update((rt << 1 | 1), mid + 1, r, x, y, z, op);
  pushup(rt);
}
long long query(int rt, int l, int r, int x, int y, int z) {
  if (x > y) return 0;
  if (x <= l && r <= y) return sum[rt][z];
  pushdown(rt, l, r);
  int mid = (l + r) >> 1;
  long long ans = 0;
  if (x <= mid) ans += query((rt << 1), l, mid, x, y, z);
  if (y > mid) ans += query((rt << 1 | 1), mid + 1, r, x, y, z);
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), mp[i] = a[i];
  sort(mp + 1, mp + n + 1);
  int tot = unique(mp + 1, mp + n + 1) - mp - 1;
  for (int i = 1; i <= n; i++)
    a[i] = lower_bound(mp + 1, mp + tot + 1, a[i]) - mp, 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; i--) suc[i] = lst[a[i]] - 1, lst[a[i]] = i;
  for (int i = n; i; i--) {
    while (top && pre[i] > pre[sta[top]]) top--;
    fp[i] = top ? sta[top] - 1 : n, sta[++top] = i;
  }
  top = 0;
  for (int i = n; i; i--) {
    while (top && suc[i] < suc[sta[top]]) top--;
    fs[i] = top ? sta[top] - 1 : n, sta[++top] = i;
  }
  long long ans = 0;
  for (int i = n, j = n; i; i--) {
    update(1, 1, n, i, fp[i], pre[i], 0);
    update(1, 1, n, i, fs[i], suc[i], 1);
    cnt[a[i]]++;
    while (cnt[a[i]] > 1) cnt[a[j]]--, j--;
    (ans += query(1, 1, n, i, j, 3) + i * query(1, 1, n, i, j, 1) -
            i * S(i, j) - query(1, 1, n, i, j, 2)) %= mod;
  }
  printf("%lld\n", (ans + mod) % mod);
  return 0;
}
