#include <bits/stdc++.h>
using namespace std;
const int nsz = 1e5, bas = 10;
int n, l1, r1, l2, r2, a[nsz + 5], len1, ll, rr;
int cnt[3][nsz + 5], greater_cnt, odd_cnt;
long long ans;
void inline ins(int me, int &it) {
  int p = it, w = a[it += me ? -1 : +1], l = max(l1, r2), r = min(l2, r1);
  bool f0 = cnt[0][w] < cnt[1][w] - cnt[2][w],
       f1 = cnt[0][w] >= cnt[1][w] - cnt[2][w];
  int d = cnt[0][w] - cnt[1][w] + cnt[2][w];
  ++cnt[me][w];
  if (l <= it && it <= r) {
    ++cnt[2][w];
  }
  if ((d - (cnt[0][w] - cnt[1][w] + cnt[2][w])) & 1)
    odd_cnt += (cnt[0][w] - cnt[1][w] + cnt[2][w]) & 1 ? +1 : -1;
  if (f0 && cnt[0][w] >= cnt[1][w] - cnt[2][w]) --greater_cnt;
  if (f1 && cnt[0][w] < cnt[1][w] - cnt[2][w]) ++greater_cnt;
}
void inline del(int me, int &it) {
  int p = it, w = a[p];
  int l = max(l1, r2), r = min(l2, r1);
  it += me ? -1 : +1;
  int d = cnt[0][w] - cnt[1][w] + cnt[2][w];
  bool f0 = cnt[0][w] < cnt[1][w] - cnt[2][w],
       f1 = cnt[0][w] >= cnt[1][w] - cnt[2][w];
  --cnt[me][w];
  if (l <= p && p <= r) --cnt[2][w];
  if ((d - (cnt[0][w] - cnt[1][w] + cnt[2][w])) & 1)
    odd_cnt += (cnt[0][w] - cnt[1][w] + cnt[2][w]) & 1 ? +1 : -1;
  if (f0 && cnt[0][w] >= cnt[1][w] - cnt[2][w]) --greater_cnt;
  if (f1 && cnt[0][w] < cnt[1][w] - cnt[2][w]) ++greater_cnt;
}
bool inline chk() {
  if (l1 > r1 || greater_cnt) return 0;
  int l = min(r1, l2) + 1, r = max(l1, r2) - 1;
  if (l <= r && (l < ll)) return 0;
  l = min(l1, r2) - 1;
  if (l > len1) return 0;
  if (odd_cnt > 1) return 0;
  if (odd_cnt == 1 && !(n & 1)) return 0;
  return 1;
}
void inline init() {
  for (len1 = 0; a[len1 + 1] == a[n - len1]; ++len1)
    ;
  for (ll = (n - 1) / 2 + 1, rr = n - ll + 1; ll >= 1 && a[ll] == a[rr];
       --ll, ++rr)
    ;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  init();
  for (l1 = 1, r1 = 0, l2 = n, r2 = n + 1; l1 <= n;) {
    if (r1 != 0) del(0, l1), del(1, l2);
    for (; r1 <= n && !chk(); ins(0, r1), ins(1, r2))
      ;
    ans += n - r1 + 1;
  }
  printf("%lld\n", ans);
}
