#include <bits/stdc++.h>
using namespace std;
long long n, m, ss, dig, dig2, t, tp, tp2;
long long a[100500], cs[100500], js[100500];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), cs[a[i]]++;
  for (int i = 1; i <= n; i++) ss += cs[i] & 1, t += (cs[i] & 1) * i;
  if (ss > 1) {
    printf("0\n");
    return 0;
  }
  for (dig = 1; dig * 2 <= n && a[dig] == a[n - dig + 1]; dig++)
    ;
  if (dig * 2 > n) {
    cout << n * (n + 1) / 2 << endl;
    return 0;
  }
  dig--;
  for (dig2 = (n + 1) / 2; dig2 >= 1 && a[dig2] == a[n - dig2 + 1]; dig2--)
    ;
  dig2++;
  tp = 1, tp2 = n;
  while (tp <= n / 2 && (++js[a[tp]]) * 2 <= cs[a[tp]]) tp++;
  memset(js, 0, sizeof(js));
  tp--;
  while (tp2 > (n + 1) / 2 && (++js[a[tp2]]) * 2 <= cs[a[tp2]]) tp2--;
  tp2++;
  ans = (dig + 1) * (dig + 1);
  if (tp >= n / 2 && (a[(n + 1) / 2] == t || !t))
    ans += (n - dig2 + 1 - dig) * (dig + 1);
  else
    ans += (tp - dig) * (dig + 1);
  if (tp2 <= (n + 1) / 2 + 1 && (a[(n + 1) / 2] == t || !t))
    ans += (n - dig2 + 1 - dig) * (dig + 1);
  else
    ans += (n - tp2 + 1 - dig) * (dig + 1);
  cout << ans << endl;
  return 0;
}
