#include <bits/stdc++.h>
using namespace std;
namespace mine {
long long qread() {
  long long ans = 0, f = 1;
  char c = getchar();
  while (c < '0' or c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans * f;
}
void write(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) write(num / 10);
  putchar('0' + num % 10);
}
void write1(long long num) {
  write(num);
  putchar(' ');
}
void write2(long long num) {
  write(num);
  putchar('\n');
}
template <typename T>
void chmax(T &x, const T y) {
  x = (x > y ? x : y);
}
template <typename T>
void chmin(T &x, const T y) {
  x = (x < y ? x : y);
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int mm(const int x) { return x >= MOD ? x - MOD : x; }
template <typename T>
void add(T &x, const int &y) {
  x = (x + y >= MOD ? x + y - MOD : x + y);
}
long long qpower(long long x, long long e, int mod = MOD) {
  long long ans = 1;
  if (e < 0) {
    puts("error");
    exit(666);
  }
  while (e) {
    if (e & 1) ans = ans * x % mod;
    x = x * x % mod;
    e >>= 1;
  }
  return ans;
}
long long invm(long long x) { return qpower(x, MOD - 2); }
const int N = 1e5 + 10;
int n;
struct SGT {
  int sum[3][N * 4], tag[2][N * 4];
  void pushdown(int x, int l, int r) {
    if (tag[0][x])
      sum[0][x << 1] = 1ll * tag[0][x] * ((l + r) / 2 - l + 1) % MOD,
                  sum[2][x << 1] = 1ll * tag[0][x] * sum[0 ^ 1][x << 1] % MOD,
                  tag[0][x << 1] = tag[0][x],
                  sum[0][x << 1 | 1] =
                      1ll * tag[0][x] * (r - (l + r) / 2) % MOD,
                  sum[2][x << 1 | 1] =
                      1ll * tag[0][x] * sum[0 ^ 1][x << 1 | 1] % MOD,
                  tag[0][x << 1 | 1] = tag[0][x], tag[0][x] = 0;
    if (tag[1][x])
      sum[1][x << 1] = 1ll * tag[1][x] * ((l + r) / 2 - l + 1) % MOD,
                  sum[2][x << 1] = 1ll * tag[1][x] * sum[1 ^ 1][x << 1] % MOD,
                  tag[1][x << 1] = tag[1][x],
                  sum[1][x << 1 | 1] =
                      1ll * tag[1][x] * (r - (l + r) / 2) % MOD,
                  sum[2][x << 1 | 1] =
                      1ll * tag[1][x] * sum[1 ^ 1][x << 1 | 1] % MOD,
                  tag[1][x << 1 | 1] = tag[1][x], tag[1][x] = 0;
  }
  void change(int fl, int fr, int op, int num, int x = 1, int l = 1,
              int r = n) {
    if (l == fl and r == fr) {
      sum[op][x] = 1ll * num * (r - l + 1) % MOD,
      sum[2][x] = 1ll * num * sum[op ^ 1][x] % MOD, tag[op][x] = num;
      return;
    }
    pushdown(x, l, r);
    if (fr <= (l + r) / 2)
      change(fl, fr, op, num, x << 1, l, (l + r) / 2);
    else if (fl > (l + r) / 2)
      change(fl, fr, op, num, x << 1 | 1, (l + r) / 2 + 1, r);
    else
      change(fl, (l + r) / 2, op, num, x << 1, l, (l + r) / 2),
          change((l + r) / 2 + 1, fr, op, num, x << 1 | 1, (l + r) / 2 + 1, r);
    sum[0][x] = (sum[0][x << 1] + sum[0][x << 1 | 1]) % MOD,
    sum[1][x] = (sum[1][x << 1] + sum[1][x << 1 | 1]) % MOD,
    sum[2][x] = (sum[2][x << 1] + sum[2][x << 1 | 1]) % MOD;
  }
  int ask(int fl, int fr, int id, int x = 1, int l = 1, int r = n) {
    if (l == fl and r == fr) return (sum[2][x] - 1ll * id * sum[0][x]) % MOD;
    pushdown(x, l, r);
    if (fr <= (l + r) / 2) return ask(fl, fr, id, x << 1, l, (l + r) / 2);
    if (fl > (l + r) / 2)
      return ask(fl, fr, id, x << 1 | 1, (l + r) / 2 + 1, r);
    return (ask(fl, (l + r) / 2, id, x << 1, l, (l + r) / 2) +
            ask((l + r) / 2 + 1, fr, id, x << 1 | 1, (l + r) / 2 + 1, r)) %
           MOD;
  }
} sgt[2];
int q1[N], q2[N], top1, top2;
int lst[N], nxt[N];
map<int, int> lstpos;
void main() {
  n = qread();
  for (int i = (1), I = (n); i <= I; i++) nxt[i] = n + 1;
  for (int i = (1), I = (n); i <= I; i++) {
    int num = qread();
    if (lstpos.count(num)) {
      int t = lstpos[num];
      nxt[t] = i;
      lst[i] = t;
    }
    lstpos[num] = i;
  }
  for (int i = (1), I = (n); i <= I; i++) lst[i]++, nxt[i]--;
  long long ans = 0;
  int lpos = 1;
  for (int r = (2), I = (n - 1); r <= I; r++) {
    chmax(lpos, lst[r]);
    while (top1 and lst[q1[top1]] < lst[r])
      sgt[1].change(q1[top1 - 1] + 1, q1[top1], 0, lst[r]), top1--;
    while (top2 and nxt[q2[top2]] > nxt[r])
      sgt[0].change(q2[top2 - 1] + 1, q2[top2], 1, nxt[r]),
          sgt[1].change(q2[top2 - 1] + 1, q2[top2], 1, nxt[r]), top2--;
    q1[++top1] = r;
    sgt[0].change(r, r, 0, r);
    sgt[0].change(r, r, 1, nxt[r]);
    q2[++top2] = r;
    sgt[1].change(r, r, 0, lst[r]);
    sgt[1].change(r, r, 1, nxt[r]);
    ans += sgt[0].ask(lpos, r, r) - sgt[1].ask(lpos, r, r), ans %= MOD;
  }
  write((ans + MOD) % MOD);
}
};  // namespace mine
signed main() {
  srand(time(0));
  mine::main();
}
