#include <bits/stdc++.h>
using namespace std;
int num[200005];
int x[200005];
int tem[200005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]), num[x[i]]++;
  int sign = 0;
  for (int i = 0; i <= n; i++) sign += num[i] % 2;
  if (sign >= 2) {
    puts("0");
    return 0;
  }
  int p = 0, q = n - 1;
  while (p < q && x[p] == x[q]) num[x[p]] -= 2, p++, q--;
  if (p >= q) {
    printf("%I64d\n", (long long)n * (n + 1) / 2);
    return 0;
  }
  memset(tem, 0, sizeof(tem));
  long long ans1 = 1;
  long long ans2 = 0;
  long long ans3 = 0;
  for (int i = q; i > p; i--) {
    if (i > (n - 1 - i)) {
      tem[x[i]] += 2;
      if (tem[x[i]] > num[x[i]])
        break;
      else
        ans2++;
    } else {
      if (x[i] != x[n - i - 1])
        break;
      else {
        if (i == n - i - 1) tem[x[i]] += 1;
        if (tem[x[i]] > num[x[i]])
          break;
        else
          ans2++;
      }
    }
  }
  memset(tem, 0, sizeof(tem));
  for (int i = p; i < q; i++) {
    if (i < n - 1 - i) {
      tem[x[i]] += 2;
      if (tem[x[i]] > num[x[i]])
        break;
      else
        ans3++;
    } else {
      if (x[i] != x[n - i - 1])
        break;
      else {
        if (i == n - i - 1) tem[x[i]] += 1;
        if (tem[x[i]] > num[x[i]])
          break;
        else
          ans3++;
      }
    }
  }
  printf("%I64d\n", ans1 * (p + 1) * (p + 1) + (ans3 + ans2) * (p + 1));
}
