#include <bits/stdc++.h>
using namespace std;
map<int, int> me, m2;
int n;
int a[114514];
long long cal(void) {
  int pa = 0, f = 0;
  map<int, int>::iterator it = me.begin();
  while (it != me.end()) {
    if (((*it).second) % 2 > 0) pa++;
    it++;
  }
  if (pa > 1) return 0;
  for (int i = 0; i < n / 2; i++) {
    if (a[i] != a[n - 1 - i]) f = 1;
  }
  if (f < 1) return (long long)n * (n + 1) / 2;
  int le = 0, ri = 0, bo = 0;
  while (le < n / 2) {
    m2[a[le]]++;
    if (m2[a[le]] * 2 > me[a[le]]) break;
    le++;
  }
  if (le * 2 + 1 == n && me[a[le]] % 2 == 1) le++;
  while (le >= (n + 1) / 2 && le < n - 1) {
    if (a[le] != a[n - 1 - le]) break;
    le++;
  }
  m2.clear();
  while (ri < n / 2) {
    m2[a[n - 1 - ri]]++;
    if (m2[a[n - 1 - ri]] * 2 > me[a[n - 1 - ri]]) break;
    ri++;
  }
  if (ri * 2 + 1 == n && me[a[ri]] % 2 == 1) ri++;
  while (ri >= (n + 1) / 2 && ri < n - 1) {
    if (a[ri] != a[n - 1 - ri]) break;
    ri++;
  }
  while (bo < n / 2) {
    if (a[bo] != a[n - 1 - bo]) break;
    bo++;
  }
  long long ret = 0;
  for (int i = 0; i < le + 1; i++) {
    if (i == 0)
      ret += ri + 1;
    else if (i <= bo)
      ret += min(ri + 1, n - i);
    else
      ret += min(bo + 1, n - i);
  }
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    me[a[i]]++;
  }
  cout << cal() << endl;
}
