#include <bits/stdc++.h>
using namespace std;
int tr[100005], nannana[100005], tl[100005], a[100005], ok[100005], yee[100005],
    tol[100005];
bool flag = true;
int n, last, df, odd;
long long ans;
void pre() {
  int now = 0;
  for (; now < df;) {
    last++;
    nannana[a[last]]++;
    tr[a[last]]--;
    if (nannana[a[last]] >= tr[a[last]]) {
      now += !yee[a[last]];
      yee[a[last]] = 1;
    }
  }
}
void shift(int to) {
  for (; last < to;) {
    ++last;
    tr[a[last]]--;
    nannana[a[last]]++;
  }
}
bool check(int val) {
  if (tl[val] - tol[val] > nannana[val] + tr[val] + tol[val]) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    odd -= tr[a[i]] % 2;
    tr[a[i]]++;
    odd += tr[a[i]] % 2;
    df += !ok[a[i]];
    ok[a[i]] = 1;
  }
  if (odd > 1) {
    printf("0");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    flag &= (a[i] == a[n - i + 1]);
  }
  if (flag) {
    printf("%lld", 1ll * n * (n + 1) / 2);
    return 0;
  }
  pre();
  if (last <= n / 2 + odd &&
      (!odd || (tr[a[n / 2 + 1]] + nannana[a[n / 2 + 1]]) % 2)) {
    while (a[last] == a[n - last + 1]) {
      tr[a[last]]++;
      nannana[a[last]]--;
      tol[a[last]]++;
      last--;
    }
  }
  ans += n - last + 1;
  for (int i = 1; i <= n; i++) {
    nannana[a[i]]--;
    tl[a[i]]++;
    if (!check(a[i])) break;
    if (a[i] != a[n - i + 1]) {
      shift(max(last, n - i + 1));
    }
    ans += n - last + 1;
  }
  printf("%lld", ans);
}
