#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
int a[MAX], b[MAX], c[MAX], n, k;
long long tt() {
  int k1 = k;
  memset(c, 0, sizeof c);
  for (int i = 0; i < k; i++) c[a[i]]++;
  while (k1 <= n / 2) {
    c[a[k1]]++;
    if (2 * c[a[k1]] > b[a[k1]]) break;
    k1++;
  }
  if (n % 2 == 1 && k1 == n / 2 && b[a[k1]] % 2 == 1) k1++;
  if (k1 > n / 2 || (n % 2 == 0 && k1 >= n / 2))
    while (a[k1] == a[n - k1 - 1]) k1++;
  return 1LL * (k1 + 1) * (k + 1);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], b[a[i]]++;
  bool t = 0;
  for (int i = 1; i <= n; i++)
    if (b[i] & 1)
      if (t)
        return cout << 0, 0;
      else
        t = 1;
  long long res = 0;
  while (k <= n / 2 && a[k] == a[n - k - 1]) k++;
  if (k > n / 2) return cout << 1LL * n * (n + 1) / 2, 0;
  res = tt(), reverse(a, a + n), res += tt();
  cout << res - 1LL * (k + 1) * (k + 1);
}
