#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long freq[n + 1], ineq, impar, s, p;
  memset(freq, 0, sizeof(freq));
  long long vet[n];
  for (int i = 0; i < n; i++) cin >> vet[i], freq[vet[i]]++;
  impar = 0;
  for (int i = 1; impar < 2 && i <= n; i++)
    if (freq[i] % 2) impar++;
  if (impar > 1) {
    cout << "0" << endl;
    return 0;
  }
  int ini = 0;
  int fim = n - 1;
  while (ini < fim && vet[ini] == vet[fim]) ini++, fim--;
  if (ini >= fim) {
    cout << ((n * (n + 1)) / 2) << endl;
    return 0;
  }
  long long m = fim - ini + 1;
  int palindrome = 0;
  int a = ini + m / 2 - 1;
  int b = ini + m / 2;
  if (m % 2) b++, palindrome++;
  while (a >= ini && vet[a] == vet[b]) a--, b++, palindrome += 2;
  p = s = 1;
  bool need[n + 1];
  memset(freq, 0, sizeof(freq));
  memset(need, false, sizeof(need));
  ineq = 0;
  int i, j;
  for (i = ini, j = fim; i < j; i++, j--, p++) {
    freq[vet[i]]--;
    freq[vet[j]]++;
    if (freq[vet[j]] == 1 && need[vet[j]] == false) {
      ineq++;
      need[vet[j]] = true;
    }
    if (freq[vet[i]] == 0 && need[vet[i]] == true) {
      ineq--;
      need[vet[i]] = false;
    }
    if (ineq == 0 && j - i - 1 <= palindrome) break;
  }
  if (ineq > 0) {
    for (p = p - 1; ineq > 0 && i <= fim; i++, p++) {
      freq[vet[i]] -= 2;
      if (i == j) freq[vet[i]]++;
      if (freq[vet[i]] <= 0 && need[vet[i]] == true) {
        ineq--;
        need[vet[i]] = false;
      }
    }
  }
  memset(freq, 0, sizeof(freq));
  ineq = 0;
  for (i = fim, j = ini; i > j; i--, j++, s++) {
    freq[vet[i]]--;
    freq[vet[j]]++;
    if (freq[vet[j]] == 1 && need[vet[j]] == false) {
      ineq++;
      need[vet[j]] = true;
    }
    if (freq[vet[i]] == 0 && need[vet[i]] == true) {
      ineq--;
      need[vet[i]] = false;
    }
    if (ineq == 0 && i - j - 1 <= palindrome) break;
  }
  if (ineq > 0) {
    for (s = s - 1; ineq > 0 && i >= ini; i--, s++) {
      freq[vet[i]] -= 2;
      if (i == j) freq[vet[i]]++;
      if (freq[vet[i]] <= 0 && need[vet[i]] == true) {
        ineq--;
        need[vet[i]] = false;
      }
    }
  }
  cout << (((n - m) / 2 + 1) * ((n - m) / 2 + 2 * m + 1 - s - p)) << endl;
  return 0;
}
