#include <bits/stdc++.h>
using namespace std;
int val[100010], vl[100010], vr[100010], res, far[100010], n, dl[100010],
    tag[2][400010], sum[2][400010];
int tdl[2][100010];
map<int, int> mp;
int read() {
  int tmp = 0, fh = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    tmp = tmp * 10 + c - '0';
    c = getchar();
  }
  return tmp * fh;
}
void pushdown(int c, int now, int l, int r) {
  int mid = (l + r) / 2;
  if (tag[c][now]) {
    int x = tag[c][now];
    tag[c][now] = 0;
    tag[c][now * 2] = tag[c][now * 2 + 1] = x;
    sum[c][now * 2] = x * ((long long)mid - l + 1) % 1000000007;
    sum[c][now * 2 + 1] = x * ((long long)r - mid) % 1000000007;
  }
}
void modify(int c, int now, int l, int r, int left, int right, int x) {
  if (l == left && r == right) {
    tag[c][now] = x;
    sum[c][now] = x * ((long long)r - l + 1) % 1000000007;
    return;
  }
  pushdown(c, now, l, r);
  int mid = (l + r) / 2;
  if (left <= mid) modify(c, now * 2, l, mid, left, min(right, mid), x);
  if (right >= mid + 1)
    modify(c, now * 2 + 1, mid + 1, r, max(left, mid + 1), right, x);
  sum[c][now] = (sum[c][now * 2] + sum[c][now * 2 + 1]) % 1000000007;
}
int query(int c, int now, int l, int r, int left, int right) {
  if (l == left && r == right) return sum[c][now];
  pushdown(c, now, l, r);
  int mid = (l + r) / 2, res = 0;
  if (left <= mid) res = query(c, now * 2, l, mid, left, min(right, mid));
  if (right >= mid + 1)
    res = (res + query(c, now * 2 + 1, mid + 1, r, max(left, mid + 1), right)) %
          1000000007;
  return res;
}
int get_S(int l, int r) {
  return ((long long)l + r) * (r - l + 1) / 2 % 1000000007;
}
int get_res0() {
  int res = 0;
  for (int i = 1; i <= n; i++)
    res = (res + (long long)i * get_S(i, far[i]) % 1000000007) % 1000000007;
  return res;
}
int get_res1() {
  int res = 0, pos = n + 1, lef = 1, righ = 0, sum = 0;
  dl[0] = n + 1;
  for (int i = n; i >= 1; i--) {
    while (lef <= righ && vr[i] <= vr[dl[righ]]) {
      sum = (sum -
             (long long)vr[dl[righ]] * (dl[righ - 1] - dl[righ]) % 1000000007 +
             1000000007) %
            1000000007;
      righ--;
    }
    dl[++righ] = i;
    sum = (sum +
           (long long)vr[dl[righ]] * (dl[righ - 1] - dl[righ]) % 1000000007 +
           1000000007) %
          1000000007;
    for (int j = pos - 1; j >= far[i] + 1; j--) {
      sum = (sum - vr[dl[lef]] + 1000000007) % 1000000007;
      if (dl[lef] == j) lef++;
    }
    dl[0] = pos = far[i] + 1;
    res = (res + (long long)sum * i % 1000000007) % 1000000007;
  }
  lef = 1;
  righ = 0;
  sum = 0;
  pos = 0;
  dl[0] = 0;
  for (int i = 1; i <= n; i++) {
    while (lef <= righ && vl[i] >= vl[dl[righ]]) {
      sum = (sum -
             (long long)vl[dl[righ]] * (dl[righ] - dl[righ - 1]) % 1000000007 +
             1000000007) %
            1000000007;
      righ--;
    }
    dl[++righ] = i;
    sum = (sum +
           (long long)vl[dl[righ]] * (dl[righ] - dl[righ - 1]) % 1000000007 +
           1000000007) %
          1000000007;
    while (far[pos + 1] < i) {
      sum = (sum - vl[dl[lef]] + 1000000007) % 1000000007;
      if (dl[lef] == pos + 1) lef++;
      pos++;
    }
    dl[0] = pos;
    res = (res + (long long)sum * i % 1000000007) % 1000000007;
  }
  return res;
}
int get_res2() {
  int lef[2], righ[2], pos = n + 1, sum = 0, t1, t2, res = 0;
  lef[0] = lef[1] = 1;
  righ[0] = righ[1] = 0;
  tdl[0][0] = tdl[1][0] = pos;
  for (int i = n; i >= 1; i--) {
    while (lef[0] <= righ[0] && vl[i] >= vl[tdl[0][righ[0]]]) {
      t1 = tdl[0][righ[0] - 1];
      t2 = tdl[0][righ[0]];
      sum = (sum -
             (long long)vl[t2] * query(1, 1, 1, n, t2, t1 - 1) % 1000000007 +
             1000000007) %
            1000000007;
      righ[0]--;
    }
    tdl[0][++righ[0]] = i;
    t1 = tdl[0][righ[0] - 1];
    t2 = tdl[0][righ[0]];
    sum =
        (sum + (long long)vl[t2] * query(1, 1, 1, n, t2, t1 - 1) % 1000000007 +
         1000000007) %
        1000000007;
    modify(0, 1, 1, n, t2, t1 - 1, vl[t2]);
    while (lef[1] <= righ[1] && vr[i] <= vr[tdl[1][righ[1]]]) {
      t1 = tdl[1][righ[1] - 1];
      t2 = tdl[1][righ[1]];
      sum = (sum -
             (long long)vr[t2] * query(0, 1, 1, n, t2, t1 - 1) % 1000000007 +
             1000000007) %
            1000000007;
      righ[1]--;
    }
    tdl[1][++righ[1]] = i;
    t1 = tdl[1][righ[1] - 1];
    t2 = tdl[1][righ[1]];
    sum =
        (sum + (long long)vr[t2] * query(0, 1, 1, n, t2, t1 - 1) % 1000000007 +
         1000000007) %
        1000000007;
    modify(1, 1, 1, n, t2, t1 - 1, vr[t2]);
    for (int j = pos - 1; j >= far[i] + 1; j--) {
      sum = (sum -
             (long long)vl[tdl[0][lef[0]]] * vr[tdl[1][righ[1]]] % 1000000007 +
             1000000007) %
            1000000007;
      if (tdl[0][lef[0]] == j) lef[0]++;
      if (tdl[1][lef[1]] == j) lef[1]++;
    }
    tdl[0][0] = tdl[1][0] = pos = far[i] + 1;
    res = (res + sum) % 1000000007;
  }
  return res;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) val[i] = read();
  for (int i = 1; i <= n; i++) {
    if (mp.find(val[i]) == mp.end())
      vl[i] = 1;
    else
      vl[i] = mp[val[i]] + 1;
    mp[val[i]] = i;
  }
  mp.clear();
  for (int i = n; i >= 1; i--) {
    if (mp.find(val[i]) == mp.end())
      vr[i] = n;
    else
      vr[i] = mp[val[i]] - 1;
    mp[val[i]] = i;
  }
  mp.clear();
  far[0] = 1;
  mp[val[1]] = 1;
  for (int i = 1; i <= n; i++) {
    far[i] = far[i - 1];
    if (i - 1) mp.erase(val[i - 1]);
    while (far[i] < n && mp.find(val[far[i] + 1]) == mp.end()) {
      far[i]++;
      mp[val[far[i]]] = 1;
    }
  }
  res = (((long long)get_res1() - get_res0() - get_res2()) % 1000000007 +
         1000000007) %
        1000000007;
  printf("%d\n", res);
  return 0;
}
