#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int n;
int L, R;
bool can(int l, int r) {
  vector<int> cnt(n + 1, 0);
  for (int i = l; i <= r; i++) {
    cnt[a[i]]++;
  }
  for (int i = L; i <= R; i++) {
    if (i >= l && i <= r) continue;
    int j = n - 1 - i;
    if (j >= l && j <= r) {
      if (cnt[a[i]] == 0) return false;
      cnt[a[i]]--;
    } else {
      if (a[i] != a[j]) return false;
    }
  }
  int odd = 0;
  for (int i = 0; i < (int)(n + 1); i++)
    if (cnt[i] % 2 == 1) odd++;
  int codd = 0;
  if (n % 2 == 1 && l <= n / 2 && n / 2 <= r) codd++;
  return odd == codd;
}
int main() {
  cin >> n;
  a = vector<int>(n);
  for (int i = 0; i < (int)(n); i++) scanf("%d", &a[i]);
  L = 0, R = n - 1;
  while (L <= R && a[L] == a[R]) {
    L++;
    R--;
  }
  if (L > R) {
    cout << n * 1ll * (n + 1) / 2 << endl;
    return 0;
  }
  if (!can(L, R)) {
    cout << 0 << endl;
    return 0;
  }
  int lf = L, rg = R;
  while (rg - lf > 1) {
    int mid = (lf + rg) / 2;
    if (can(mid, R)) {
      lf = mid;
    } else {
      rg = mid - 1;
    }
  }
  while (!can(rg, R)) rg--;
  long long ans = (rg - L + 1) * 1ll * (n - R);
  lf = L, rg = R;
  while (rg - lf > 1) {
    int mid = (lf + rg) / 2;
    if (can(L, mid)) {
      rg = mid;
    } else {
      lf = mid + 1;
    }
  }
  while (!can(L, lf)) lf++;
  ans += (R - lf + 1) * 1ll * (L + 1) - 1;
  ans += L * 1ll * (n - R - 1);
  cout << ans << endl;
  return 0;
}
