#include <bits/stdc++.h>
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
using namespace std;
int a[MAXN], cnt[MAXN];
vector<int> tmp[MAXN];
int main() {
  int n;
  scanf("%d", &(n));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(a[i]));
    cnt[a[i]]++;
    tmp[a[i]].push_back(i);
  }
  int k = 0;
  for (int i = 1; i <= n; i++)
    if ((cnt[i] & 1) && ++k > 1) return !printf("%d\n", (0));
  for (k = 1; k <= n / 2; k++)
    if (a[k] != a[n - k + 1]) break;
  if (k == n / 2 + 1) return !printf("%I64d\n", ((long long)n * (n + 1) / 2));
  long long x = 0, y = n + 1, l = 0, r = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[i] == 0) continue;
    if (cnt[i] & 1)
      l = r = cnt[i] / 2;
    else
      l = cnt[i] / 2 - 1, r = l + 1;
    while (l >= 0 && tmp[i][l] + tmp[i][r] == n + 1) l--, r++;
    if (l < 0) continue;
    x = max(x, (long long)tmp[i][l]);
    y = min(y, (long long)tmp[i][r]);
  }
  printf("%I64d\n", ((long long)k * ((long long)n - x + 1) + (long long)k * y -
                     (long long)k * (long long)k));
  return 0;
}
