#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int a[MAXN];
int c[MAXN] = {};
int cL[MAXN] = {};
int cR[MAXN] = {};
int N;
bool isPossible(int a[], int n, int pos) {
  for (int i = pos + 1; i < n / 2; i++)
    if (a[i] != a[n - i - 1]) return false;
  memset(cL, 0, sizeof(cL));
  memset(cR, 0, sizeof(cR));
  for (int i = 0; i < pos + 1; i++) cL[a[i]]++;
  for (int i = max(pos + 1, n - pos - 1); i < n; i++) cR[a[i]]++;
  for (int i = 1; i < N + 1; i++)
    if (cL[i] < cR[i]) return false;
  return true;
}
int bs(int a[], int n) {
  int l = 0, h = n - 1, med;
  while (l < h) {
    med = (l + h) / 2;
    if (isPossible(a, n, med))
      h = med;
    else
      l = med + 1;
  }
  return h;
}
long long cant(int a[], int n, long long k) {
  int minR, minL;
  minR = bs(a, n);
  for (int i = 0; i < n / 2; i++) swap(a[i], a[n - i - 1]);
  minL = bs(a, n);
  long long res = k * k;
  res += ((k + 1) * (2 * n - minR - minL) - 1);
  return res;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &a[i]);
  int k = 0;
  for (int i = 0; i < N; i++) c[a[i]]++;
  bool imp = !(N % 2);
  for (int i = 0; i < N; i++)
    if (c[i] % 2) {
      if (imp) {
        printf("0\n");
        return 0;
      } else
        imp = true;
    }
  for (; k < N && a[k] == a[N - k - 1]; k++)
    ;
  if (k == N) {
    printf("%I64d\n", (long long)N * (N + 1) / 2);
    return 0;
  }
  long long res = cant(a + k, N - 2 * k, k);
  printf("%I64d\n", res);
}
