#include <bits/stdc++.h>
using namespace std;
const int nsz = 1e5, bas = 10;
int n, l1, r1, l2, r2, cl, cr, a[nsz + 5], len1, ll, rr;
int cnt[3][nsz + 5], greater_cnt, odd_cnt;
long long ans;
void inline mov(int me, int &it, int d) {
  if (d == +1) it += me ? -1 : 1;
  int w = a[it], d1 = cnt[0][w] - cnt[1][w] + cnt[2][w];
  cnt[me][w] += d;
  if (max(l1, r2) <= it && it <= min(l2, r1)) cnt[2][w] += d;
  int d2 = cnt[0][w] - cnt[1][w] + cnt[2][w];
  odd_cnt += ((d1 - d2) & 1) * (d2 & 1 ? +1 : -1);
  d1 < 0 ? greater_cnt -= d2 >= 0 : greater_cnt += d2 < 0;
  if (d == -1) it += me ? -1 : 1;
}
bool inline chk() {
  if (l1 > r1 || greater_cnt) return 0;
  int l = min(l2, r1) + 1, r = max(l1, r2) - 1;
  if (l <= r && l < ll || min(l1, r2) - 1 > len1) return 0;
  if (odd_cnt > 1 || 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) mov(0, l1, -1), mov(1, l2, -1);
    for (; r1 <= n && !chk(); mov(0, r1, +1), mov(1, r2, +1))
      ;
    ans += n - r1 + 1;
  }
  printf("%lld\n", ans);
}
