#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, len, ct;
int a[maxn], tot[maxn], cur[maxn];
long long ans;
void solve() {
  for (int i = 1; i <= n; i++) tot[i] = cur[i] = 0;
  for (int i = 1; i <= n; i++) tot[a[i]]++;
  int r = 1;
  for (int i = 1; i <= (n - 1) / 2; i++) {
    while (r <= (n - 1) / 2 && (cur[a[r]] + 1) * 2 <= tot[a[r]]) {
      cur[a[r]]++;
      r++;
    }
    ans += r - i + 1;
    if (a[i] != a[n - i + 1]) break;
    tot[a[i]] -= 2;
    cur[a[i]]--;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), tot[a[i]]++;
  int val = 0;
  for (int i = 1; i <= n; i++)
    if (tot[i] & 1) {
      if (val) {
        puts("0");
        return 0;
      }
      val = i;
    }
  while (1 + len <= n && n - len >= 1 && a[1 + len] == a[n - len]) len++;
  if (len == n) {
    printf("%lld\n", 1LL * n * (n + 1) / 2);
    return 0;
  }
  int l = n / 2, r = n / 2 + 1 + (n & 1);
  while (l - ct >= 1 && r + ct <= n && a[l - ct] == a[r + ct]) ct++;
  for (int i = 1; i <= n; i++) cur[i] = 0;
  for (int i = len + 1; i <= l - ct; i++) cur[a[i]]++;
  bool bad = false;
  for (int i = r + ct; i <= n - len; i++) {
    if (!cur[a[i]]) {
      bad = true;
      break;
    }
    cur[a[i]]--;
  }
  if (!bad) ans = 2LL * (len + 1) * (ct + 1);
  solve();
  reverse(a + 1, a + 1 + n);
  solve();
  ans -= len + 1;
  printf("%lld\n", ans);
  return 0;
}
