#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 2;
int N, arr[MAXN], cnt[MAXN], all[MAXN], half[MAXN];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
  int mid1 = (N - 1) / 2, mid2 = N / 2, zeros = N, S = 0, E = N - 1;
  for (int i = 0; i <= mid1; i++) {
    zeros -= (cnt[arr[i]] == 0);
    cnt[arr[i]]++;
  }
  for (int i = mid2; i < N; i++) {
    zeros -= (cnt[arr[i]] == 0);
    cnt[arr[i]]--;
    zeros += (cnt[arr[i]] == 0);
  }
  if (zeros == N) {
    while (mid1 >= 0 && mid2 < N && arr[mid1] == arr[mid2]) mid1--, mid2++;
    while (S < N && E >= 0 && arr[S] == arr[E]) S++, E--;
    if (S > E)
      printf("%I64d\n", (long long)N * (N + 1) / 2);
    else {
      long long ret = 0;
      ret += N - mid1;
      ret += mid2;
      ret += S * (N - E - 1);
      ret += (long long)(N - E - 1) * (mid2 - S);
      ret += (long long)S * (E - mid1);
      printf("%I64d\n", ret);
    }
  } else {
    int ALL = 0, HALF = 0, odd = 0;
    while (S < N && E >= 0 && arr[S] == arr[E]) S++, E--;
    for (int i = S; i <= E; i++) all[arr[i]]++;
    for (int i = 1; i <= N; i++) {
      ALL += (bool)all[i];
      half[i] = all[i] / 2 + all[i] % 2;
      odd += all[i] % 2;
    }
    if (odd > N % 2) {
      printf("0\n");
      return 0;
    }
    memset(cnt, 0, sizeof cnt);
    HALF = 0;
    for (mid1 = S; mid1 <= E; mid1++) {
      cnt[arr[mid1]]++;
      HALF += (cnt[arr[mid1]] == half[arr[mid1]]);
      if (HALF == ALL) break;
    }
    memset(cnt, 0, sizeof cnt);
    HALF = 0;
    for (mid2 = E; mid2 >= S; mid2--) {
      cnt[arr[mid2]]++;
      HALF += (cnt[arr[mid2]] == half[arr[mid2]]);
      if (HALF == ALL) break;
    }
    long long ret = 0;
    ret += N - mid1;
    ret += mid2 - (mid2 >= mid1);
    ret += S * (N - E - 1);
    ret += (long long)(N - E - 1) * (mid2 - S);
    ret += (long long)S * (E - mid1);
    printf("%I64d\n", ret);
  }
}
