#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
long long n, m;
long long a[200000];
long long b[200000];
long long br;
long long l, r, hi, lo, mid;
long long cnt, bnd;
map<int, int> mep;
int checkl() {
  for (int(i) = (mid + 1); (i) < (m / 2); (i)++) {
    if (b[i] != b[m - i - 1]) return 0;
  }
  mep.clear();
  for (int(i) = (0); (i) < (mid + 1); (i)++) {
    mep[b[i]]++;
  }
  for (int(i) = (max(mid + 1, m - mid - 1)); (i) < (m); (i)++) {
    if (mep[b[i]] <= 0) return 0;
    mep[b[i]]--;
  }
  cnt = 0;
  for (map<int, int>::iterator it = mep.begin(); it != mep.end(); it++) {
    if ((it->second) % 2) cnt++;
  }
  bnd = 0;
  if (mid >= m / 2 && (m % 2)) bnd = 1;
  if (cnt > bnd) return 0;
  return 1;
}
int checkr() {
  reverse(b, b + m);
  mid = m - mid - 1;
  int ans = checkl();
  reverse(b, b + m);
  mid = m - mid - 1;
  return ans;
}
int main() {
  cin >> n;
  for (int(i) = (0); (i) < (n); (i)++) cin >> a[i];
  br = 0;
  while (br <= n - br - 1) {
    if (a[br] == a[n - br - 1])
      br++;
    else
      break;
  }
  if (br >= n / 2) {
    cout << n * (n + 1) / 2 << endl;
    return 0;
  }
  for (int(i) = (br); (i) < (n - br); (i)++) {
    b[i - br] = a[i];
  }
  m = n - 2 * br;
  lo = -1;
  hi = m;
  while (lo + 1 < hi) {
    mid = (lo + hi) / 2;
    if (checkl())
      hi = mid;
    else
      lo = mid;
  }
  if (hi == m) {
    cout << 0 << endl;
    return 0;
  }
  l = hi;
  lo = -1;
  hi = m;
  while (lo + 1 < hi) {
    mid = (lo + hi) / 2;
    if (checkr())
      lo = mid;
    else
      hi = mid;
  }
  if (lo == -1) {
    cout << 0 << endl;
    return 0;
  }
  r = lo;
  cout << (br + 1) * (br + 1) + (m - l - 1 + r) * (br + 1) << endl;
  return 0;
}
