#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
int n;
int a[100100];
int num[100100];
long long answer = 0;
int L;
int m;
int b[100100];
int R;
void input() {
  scanf("%d", &n);
  int one = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    num[a[i]]++;
    if (num[a[i]] & 1)
      one++;
    else
      one--;
  }
  if (one > 1) {
    puts("0");
    exit(0);
  }
  for (L = 1; L <= n - L + 1 && a[L] == a[n - L + 1]; L++)
    ;
  if (L * 2 >= n) {
    printf("%I64d\n", 1ll * n * (n + 1) / 2);
    exit(0);
  }
  answer = 1ll * L * L;
}
int tot;
int gas[100100];
void calc() {
  memset(gas, 0, sizeof(gas));
  int i, x;
  int rtot = tot;
  for (i = 1; i <= m; i++) {
    x = b[i];
    if (gas[x] < (num[x] + 1) / 2 && (gas[x] + 1) >= (num[x] + 1) / 2) {
      if (!--rtot) break;
    }
    gas[x]++;
  }
  answer += 1ll * L * (m - i);
}
int lef[100100], rig[100100];
void solve() {
  m = n - 2 * (L - 1);
  for (int i = 1; i <= m; i++) b[i] = a[i + L - 1];
  for (R = (m + 1) / 2; R && b[R] == b[m + 1 - R]; R--)
    ;
  memset(lef, 0, sizeof(lef));
  memset(rig, 0, sizeof(rig));
  for (int i = 1; i <= R; i++) lef[b[i]]++;
  for (int i = 1; i <= R; i++) rig[b[m + 1 - i]]++;
  bool res = 1;
  for (int i = 1; i <= n; i++)
    if (lef[i] != rig[i]) {
      res = 0;
      break;
    }
  if (res) {
    answer += 2ll * L * (m - R);
    return;
  }
  memset(num, 0, sizeof(num));
  for (int i = 1; i <= m; i++) num[b[i]]++;
  for (int x = 1; x <= n; x++) tot += !!num[x];
  calc();
  reverse(b + 1, b + m + 1);
  calc();
}
int main() {
  input();
  solve();
  printf("%I64d\n", answer);
  return 0;
}
