#include <bits/stdc++.h>
using namespace std;
long long add(long long x = 0, long long y = 0) {
  return (x + y) % 1000000007;
};
int n, a[100050];
map<int, int> pos;
int L[100050], R[100050];
struct node {
  long long mnl, mxl, mnr, mxr;
  long long tl, tr;
  long long sj, sl, sr, slr, sjr;
  node(int j = 0) {
    mnl = mxl = 0, mnr = mxr = n + 1;
    tl = tr = 0;
    sj = j, sl = sr = a[j];
    slr = 1LL * j * j % 1000000007, sjr = 1LL * j * a[j] % 1000000007;
  }
  node operator*(const node& N) const {
    node ans;
    ans.mnl = min(mnl, N.mnl), ans.mxl = max(mxl, N.mxl);
    ans.mnr = min(mnr, N.mnr), ans.mxr = max(mxr, N.mxr);
    ans.sj = add(sj + N.sj), ans.sl = add(sl + N.sl), ans.sr = add(sr + N.sr);
    ans.sjr = add(sjr + N.sjr), ans.slr = add(slr + N.slr);
    return ans;
  }
} T[100050 << 2];
void upl(int k, int l, int r, int L) {
  T[k].tl = L;
  T[k].mnl = T[k].mxl = L;
  T[k].sl = 1LL * L * (r - l + 1) % 1000000007;
  T[k].slr = 1LL * L * T[k].sr % 1000000007;
}
void upr(int k, int l, int r, int R) {
  T[k].tr = R;
  T[k].mnr = T[k].mxr = R;
  T[k].sr = 1LL * R * (r - l + 1) % 1000000007;
  T[k].slr = 1LL * R * T[k].sl % 1000000007;
  T[k].sjr = 1LL * R * T[k].sj % 1000000007;
}
void godown(int k, int l, int r) {
  int mid = (l + r) >> 1;
  int ls = k << 1, rs = k << 1 | 1;
  if (T[k].tl)
    upl(ls, l, mid, T[k].tl), upl(rs, mid + 1, r, T[k].tl), T[k].tl = 0;
  if (T[k].tr)
    upr(ls, l, mid, T[k].tr), upr(rs, mid + 1, r, T[k].tr), T[k].tr = 0;
}
void build(int k, int l, int r) {
  if (l == r)
    T[k] = node(l);
  else {
    int mid = (l + r) >> 1;
    build(k << 1, l, mid);
    build(k << 1 | 1, mid + 1, r);
    T[k] = T[k << 1] * T[k << 1 | 1];
  }
}
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    R[i] = n;
    L[i] = pos[a[i]] + 1;
    R[pos[a[i]]] = i - 1;
    pos[a[i]] = i;
  }
  build(1, 1, n);
  T[0].mnl = T[0].mnr = n + 1;
  T[0].mxl = T[0].mxr = 0;
}
void change(int k, int l, int r, int a, int b, int L, int R) {
  int mid = (l + r) >> 1;
  if (a <= l && r <= b) {
    if (T[k].mxl < L) upl(k, l, r, L);
    if (T[k].mnr > R) upr(k, l, r, R);
    if ((T[k].mxl < L || T[k].mnl >= L) && (T[k].mnr > R || T[k].mxr <= R))
      ;
    else {
      godown(k, l, r);
      change(k << 1, l, mid, a, b, L, R);
      change(k << 1 | 1, mid + 1, r, a, b, L, R);
      T[k] = T[k << 1] * T[k << 1 | 1];
    }
  } else {
    godown(k, l, r);
    if (a <= mid) change(k << 1, l, mid, a, b, L, R);
    if (b > mid) change(k << 1 | 1, mid + 1, r, a, b, L, R);
    T[k] = T[k << 1] * T[k << 1 | 1];
  }
}
node query(int k, int l, int r, int a, int b) {
  if (a > r || l > b) return T[0];
  if (a <= l && r <= b) return T[k];
  godown(k, l, r);
  int mid = (l + r) >> 1;
  return query(k << 1, l, mid, a, b) * query(k << 1 | 1, mid + 1, r, a, b);
}
void travel(int k, int l, int r) {
  if (l == r)
    cout << l << " " << T[k].mnl << " " << T[k].mnr << endl;
  else {
    godown(k, l, r);
    int mid = (l + r) >> 1;
    travel(k << 1, l, mid);
    travel(k << 1 | 1, mid + 1, r);
  }
}
void solve() {
  long long ans = 0;
  for (int i = 1, last = 1; i <= n; ++i) {
    last = max(last, L[i]);
    change(1, 1, n, last, i, L[i], R[i]);
    node N = query(1, 1, n, last, i);
    ans += N.sjr - N.slr + (N.sl - N.sj) * i;
    ans %= 1000000007;
    ans = (ans + 1000000007) % 1000000007;
  }
  printf("%lld\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
