#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 5;
int n, p, a, aa[maxn], lcnt[maxn], rcnt[maxn];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &aa[i]);
  }
  p = 0;
  for (int i = 1; i <= n / 2; i++) {
    if (aa[i] != aa[n + 1 - i]) {
      p = i;
      break;
    }
  }
  memset(lcnt, 0, sizeof(lcnt));
  memset(rcnt, 0, sizeof(rcnt));
  int L = p, R = n + 1 - p;
  for (int i = R; i >= L; i--) rcnt[aa[i]]++;
  a = 0;
  for (int i = 1; i <= n; i++)
    if (rcnt[i] & 1) a++;
  ans = 0;
  if (p == 0)
    ans = (long long)n * (n + 1) / 2;
  else if (a <= 1) {
    for (int i = L; i < R; i++) {
      if (i - L + 1 <= R - i) {
        rcnt[aa[i]]--;
        lcnt[aa[i]]++;
      }
      if (R - i == i - L) rcnt[aa[i]]--;
      if (R - i < i - L) {
        if (aa[i] == aa[n + 1 - i])
          ans += p;
        else
          break;
      } else {
        if (lcnt[aa[i]] <= rcnt[aa[i]])
          ans += p;
        else
          break;
      }
    }
    memset(lcnt, 0, sizeof(lcnt));
    memset(rcnt, 0, sizeof(rcnt));
    for (int i = L; i <= R; i++) lcnt[aa[i]]++;
    for (int i = R; i > L; i--) {
      if (R - i + 1 <= i - L) {
        lcnt[aa[i]]--;
        rcnt[aa[i]]++;
      }
      if (R - i == i - L) lcnt[aa[i]]--;
      if (R - i > i - L) {
        if (aa[i] == aa[n + 1 - i])
          ans += p;
        else
          break;
      } else {
        if (rcnt[aa[i]] <= lcnt[aa[i]])
          ans += p;
        else
          break;
      }
    }
    ans += (long long)p * p;
  }
  printf("%lld\n", ans);
}
