#include <bits/stdc++.h>
using namespace std;
int arr[100006], freq[100006], taken[100006];
long long calc(int N, int midval) {
  int mid = (N + 1) / 2, x, i;
  long long ret = 0;
  memset(taken, 0, sizeof(taken));
  for (i = N; i >= 1; --i) {
    ++ret;
    if ((N & 1) && i == mid) {
      if (arr[i] != midval) break;
    } else if (i <= N / 2) {
      if (arr[i] != arr[N - i + 1]) break;
    } else {
      x = arr[i];
      ++taken[x];
      if (taken[x] * 2 > freq[x]) break;
    }
  }
  return ret;
}
long long run(int N) {
  int l = 1, r = N, i;
  int odd = 0;
  for (i = 1; i <= N; ++i) {
    if (freq[i] & 1) {
      if (odd) return 0;
      odd = i;
    }
  }
  while (l < r && arr[l] == arr[r]) {
    freq[arr[l]] -= 2;
    ++l, --r;
  }
  if (l >= r) return ((long long)N * (N + 1)) / 2;
  long long ret = (long long)l * (N - r + 1);
  for (i = 1; i <= r - l + 1; ++i) arr[i] = arr[i + l - 1];
  ret += l * (calc(r - l + 1, odd) - 1);
  reverse(arr + 1, arr + 1 + r - l + 1);
  ret += l * (calc(r - l + 1, odd) - 1);
  return ret;
}
int main() {
  int N, i, x;
  while (scanf("%d", &N) != EOF) {
    memset(freq, 0, sizeof(freq));
    for (i = 1; i <= N; ++i) {
      scanf("%d", &x);
      arr[i] = x;
      ++freq[x];
    }
    printf("%I64d\n", run(N));
  }
  return 0;
}
