#include <bits/stdc++.h>
using namespace std;
int N, A[1 << 17], nr[1 << 17], temp[1 << 17];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    A[i]--;
    nr[A[i]]++;
  }
  int tot = 0;
  for (int i = 0; i < N; i++) {
    if (nr[i] & 1) tot++;
  }
  if (tot > 1) {
    printf("0\n");
    return 0;
  }
  int k = -1;
  for (int i = 0, j = N - 1; i < j; i++, j--)
    if (A[i] != A[j]) {
      k = i;
      break;
    } else {
      nr[A[i]] -= 2;
    }
  if (k == -1) {
    printf("%I64d\n", (long long)N * (N + 1) / 2);
    return 0;
  }
  k--;
  int M = N - 2 * (k + 1);
  int l = -1, r = -1;
  if (M & 1) {
    if (nr[A[k + M / 2 + 1]] & 1) {
      int poz = k + M / 2 + 1;
      for (int i = k + M / 2, j = i + 2; i > k; i--, j++) {
        if (A[i] != A[j]) {
          poz = i;
          break;
        }
      }
      l = poz - k, r = l;
      for (int i = k + 1, j = k + M; i <= k + l; i++, j--) {
        temp[A[i]]++;
        temp[A[j]]--;
      }
      for (int i = 0; i < N; i++)
        if (temp[A[i]]) {
          l = -1;
          break;
        }
    }
    if (l == -1) {
      int best = k + M + 1;
      memset(temp, 0, sizeof(temp));
      for (int j = k + M; j > k; j--) {
        temp[A[j]]++;
        if (temp[A[j]] * 2 > nr[A[j]]) break;
        best = j;
      }
      l = best - 1 - k;
      best = k;
      memset(temp, 0, sizeof(temp));
      for (int i = k + 1; i <= k + M; i++) {
        temp[A[i]]++;
        if (temp[A[i]] * 2 > nr[A[i]]) break;
        best = i;
      }
      r = k + M - best;
    }
  } else {
    if (A[k + M / 2] == A[k + M / 2 + 1]) {
      int poz = k + M / 2;
      for (int i = k + M / 2, j = i + 1; i > k; i--, j++)
        if (A[i] != A[j]) {
          poz = i;
          break;
        }
      l = poz - k, r = l;
      for (int i = k + 1, j = k + M; i <= k + l; i++, j--) {
        temp[A[i]]++;
        temp[A[j]]--;
      }
      for (int i = 0; i < N; i++)
        if (temp[A[i]]) {
          l = -1;
          break;
        }
    }
    if (l == -1) {
      int best = k + M + 1;
      memset(temp, 0, sizeof(temp));
      for (int j = k + M; j > k; j--) {
        temp[A[j]]++;
        if (temp[A[j]] * 2 > nr[A[j]]) break;
        best = j;
      }
      l = best - 1 - k;
      best = k;
      memset(temp, 0, sizeof(temp));
      for (int i = k + 1; i <= k + M; i++) {
        temp[A[i]]++;
        if (temp[A[i]] * 2 > nr[A[i]]) break;
        best = i;
      }
      r = k + M - best;
    }
  }
  long long ret = 0;
  ret += ((long long)(N - M) / 2 + 1) * (M - l + 1);
  ret += ((long long)(N - M) / 2 + 1) * (N - M) / 2;
  ret += ((long long)(N - M) / 2 + 1) * (M - r);
  printf("%I64d\n", ret);
  return 0;
}
