#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, L, a[N], c[N];
bool check(int P) {
  memset(c, 0, sizeof(c));
  for (int i = (L); i < (n + 1 - L + 1); ++i) {
    if (P < i && i < n + 1 - i && a[i] != a[n + 1 - i]) return false;
    if (i <= P)
      ++c[a[i]];
    else if (n + 1 - i <= P && --c[a[i]] < 0)
      return false;
  }
  return true;
}
int getpre() {
  int l = L, r = n - L + 1;
  while (l + 1 < r) {
    int z = (l + r) >> 1;
    check(z) ? r = z : l = z;
  }
  return (check(l) ? l : r);
}
long long solve() {
  for (int i = (1); i < (n + 1); ++i) ++c[a[i]];
  int odd = 0;
  for (int i = (1); i < (n + 1); ++i) odd += c[i] & 1;
  if (odd > 1) return 0;
  L = 1;
  while (L <= n && a[L] == a[n + 1 - L]) ++L;
  if (L > n) return 1ll * n * (n + 1) / 2;
  long long ret = 1ll * L * (n + 1 - getpre());
  reverse(a + 1, a + 1 + n);
  ret += 1ll * L * (n + 1 - L - getpre());
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); ++i) scanf("%d", a + i);
  cout << solve() << endl;
  return 0;
}
