#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int q[100005], q2[100005];
int l0, l1;
vector<int> f;
set<int> p;
int main() {
  scanf("%d", &n);
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) scanf("%d", a + i), q[--a[i]]++;
  int k = -1;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i)
    if (q[i] % 2) {
      if (k >= 0) {
        puts("0");
        return 0;
      }
      k = i;
    }
  for (int i = 0, ThxDem = (n + 1) / 2; i < ThxDem; ++i)
    if (a[i] != a[n - 1 - i] || i == n - 1 - i && a[i] != k) f.push_back(i);
  if (!((int)(f).size())) {
    printf("%lld\n", 1LL * n * (n + 1) / 2);
    return 0;
  }
  if (k >= 0 && a[n / 2] != k) {
    for (int i = 0, ThxDem = n; i < ThxDem; ++i)
      if (a[i] == k) p.insert(i);
  }
  while (1) {
    q2[a[l0]]++;
    if (q2[a[l0]] > q[a[l0]] / 2) break;
    l0++;
  }
  if (l0 >= n / 2) l0 = 1 << 30;
  memset(q2, 0, sizeof(q2));
  while (1) {
    q2[a[n - 1 - l1]]++;
    if (q2[a[n - 1 - l1]] > q[a[n - 1 - l1]] / 2) break;
    l1++;
  }
  if (l1 >= n / 2) l1 = 1 << 30;
  long long r = 0;
  for (int i = 0, ThxDem = f[0] + 1; i < ThxDem; ++i) {
    int l = max(f.back(), n - 1 - l1);
    if (((int)(p).size())) {
      auto it = p.lower_bound(i);
      if (it == p.end())
        l = n;
      else
        l = max(l, *it);
    }
    r += n - l;
    l = max(f.back(), n - 1 - l0);
    if (((int)(p).size())) {
      auto it = p.upper_bound(n - 1 - i);
      if (it == p.begin())
        l = n;
      else {
        --it;
        l = max(l, n - 1 - *it);
      }
    }
    r += max(n - f[0] - 1 - l, 0);
  }
  printf("%lld\n", r);
  return 0;
}
