#include <bits/stdc++.h>
using namespace std;
int n, cnt[100005], cnt1[100005], a[100005], od;
int len = -1;
bool check(int m) {
  memset(cnt1, 0, sizeof(cnt1));
  if (m < n / 2) {
    for (int i = m + 1; i < n / 2; i++)
      if (a[i] != a[n - i - 1]) return 0;
    for (int i = n - m - 1; i < n - len; i++) cnt1[a[i]]++;
    for (int i = len; i <= m; i++) cnt1[a[i]]--;
    for (int i = 1; i <= n; i++)
      if (cnt1[i]) return 0;
    return 1;
  } else {
    for (int i = len; i <= m; i++) cnt1[a[i]]++;
    for (int i = m + 1; i < n - len; i++) {
      cnt1[a[i]]--;
      if (cnt1[a[i]] < 0) return 0;
    }
    return 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), cnt[a[i]]++;
  for (int i = 1; i <= n; i++)
    if (cnt[i] & 1) od++;
  if (od >= 2) return 0 * puts("0");
  for (int i = 0; i <= n - i - 1; i++)
    if (a[i] != a[n - i - 1]) {
      len = i;
      break;
    }
  if (len == -1) return 0 * printf("%I64d\n", 1ll * (n) * (n + 1) / 2);
  int l = len, r = n - len - 1;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  int L = l;
  for (int i = 0; i <= n - i - 1; i++) swap(a[i], a[n - i - 1]);
  l = len, r = n - len - 1;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  int R = n - l - 1;
  printf("%I64d\n", 1ll * (n - len - L - 1) * (len + 1) +
                        1ll * (R - len) * (len + 1) +
                        1ll * (len + 1) * (len + 1));
  return 0;
}
