#include <bits/stdc++.h>
using namespace std;
bool eq(vector<int>& v) {
  int n = v.size();
  vector<int> p(n + 1);
  for (int i = 0; i < n / 2; ++i) ++p[v[i]];
  for (int i = (n % 2 ? n / 2 + 1 : n / 2); i < n; ++i) --p[v[i]];
  for (int i = 1; i <= n; ++i)
    if (p[i] != 0) return false;
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n), p(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    ++p[v[i]];
  }
  int odd = 0, odd_el;
  for (int i = 1; i <= n; ++i)
    if (p[i] % 2) {
      ++odd;
      if (odd > 1) break;
      odd_el = i;
    }
  if (odd > 1) {
    cout << 0;
    return 0;
  }
  int sides = n / 2;
  for (int i = 0; 2 * i < n; ++i)
    if (v[i] != v[n - i - 1]) {
      sides = i + 1;
      break;
    }
  vector<int> pl(n + 1);
  long long res = sides;
  for (int i = 0; i < n; ++i) {
    ++pl[v[i]];
    if (pl[v[i]] > p[v[i]] - pl[v[i]]) break;
    res += min(sides, i + 1);
  }
  pl.assign(n + 1, 0);
  for (int i = n - 1; i >= 0; --i) {
    ++pl[v[i]];
    if (pl[v[i]] > p[v[i]] - pl[v[i]]) break;
    res += min(sides, n - 1 - i + 1);
  }
  if (odd == 0 || v[n / 2] == odd_el) {
    int l, r;
    if (odd) {
      l = n / 2 - 1;
      r = n / 2 + 1;
    } else {
      l = n / 2 - 1;
      r = n / 2;
    }
    int cen = 0;
    while (l >= 0 && v[l] == v[r]) {
      --l;
      ++r;
      ++cen;
    }
    if (cen == n / 2)
      res = (long long)n * (n + 1) / 2;
    else {
      if (eq(v)) {
        if (odd == 0)
          res += 2ll * sides * cen;
        else
          res += 2ll * sides * (cen + 1);
      }
    }
  }
  cout << res;
  return 0;
}
