#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[100002], B[100002];
int F1[100002], F2[100002];
int nimp, wh;
bool pluss;
int get_res() {
  memset(F1, 0, sizeof(F1));
  memset(F2, 0, sizeof(F2));
  for (int i = 1; i <= (M + 1) / 2; ++i) ++F1[B[i]];
  for (int i = (M + 1) / 2 + 1; i <= M; ++i) ++F2[B[i]];
  int nok = 0;
  for (int i = 1; i <= N; ++i)
    if (F2[i] > F1[i]) ++nok;
  if (!nok) {
    int lim = (M + 1) / 2;
    while (lim > 0 && B[lim] == B[M - lim + 1] &&
           !(lim == (M + 1) / 2 && nimp == 1 && B[lim] != wh))
      --lim;
    return lim;
  }
  int go = (M + 1) / 2;
  for (int i = (M + 1) / 2 + 1; i <= M && nok; ++i) {
    if (F2[B[i]] > F1[B[i]] && F2[B[i]] - 1 <= F1[B[i]] + 1) --nok;
    ++F1[B[i]];
    --F2[B[i]];
    go = i;
  }
  return go;
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    ++F1[A[i]];
  }
  nimp = 0;
  for (int i = 1; i <= N; ++i) {
    nimp += F1[i] % 2;
    if (F1[i] % 2 == 1) wh = i;
  }
  if (nimp > 1) {
    cout << 0 << '\n';
    return 0;
  }
  int fw = N, lw = 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] != A[N - i + 1] || (nimp == 1 && i == N / 2 + 1 && A[i] != wh)) {
      B[++M] = A[i];
      fw = min(fw, i);
      lw = max(lw, i);
    }
  if (M == 0) {
    cout << 1LL * N * (N + 1) / 2 << '\n';
    return 0;
  }
  M = N;
  for (int i = 1; i <= N; ++i) B[i] = A[i];
  int p1 = get_res();
  if (p1 == -1) {
    cout << 0 << '\n';
    return 0;
  }
  reverse(B + 1, B + M + 1);
  int p2 = get_res();
  int bg1 = fw, en1 = p1;
  int bg2 = N - lw + 1, en2 = p2;
  bg2 = N - bg2 + 1;
  en2 = N - en2 + 1;
  swap(bg2, en2);
  long long result = 1LL * bg1 * (N - en1 + 1) + 1LL * bg2 * (N - en2 + 1);
  int bg3 = min(bg1, bg2), en3 = max(en1, en2);
  result -= 1LL * bg3 * (N - en3 + 1);
  cout << result << '\n';
}
