#include <bits/stdc++.h>
using namespace std;
const int OO = 2e9;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int a[N], d[N], n, am, le, non_zero;
long long res = 0;
void add(int x) {
  d[x]++;
  if (d[x] == 0) {
    am--;
    non_zero++;
  }
  if (d[x] == 1) non_zero--;
  if (d[x] > 0) {
    if (d[x] % 2 == 1)
      le++;
    else
      le--;
  }
}
void sub(int x) {
  d[x]--;
  if (d[x] == -1) {
    am++;
    non_zero--;
  }
  if (d[x] == 0) non_zero++;
  if (d[x] >= 0) {
    if (d[x] % 2 == 1)
      le++;
    else
      le--;
  }
}
void solve() {
  memset(d, 0, sizeof(d));
  am = le = non_zero = 0;
  int l1, r1, l2, r2;
  l1 = 1;
  r1 = (n + 1) / 2;
  l2 = n - r1 + 1;
  r2 = n;
  while (r1 > 1 && a[r1] == a[l2]) {
    r1--;
    l2++;
  }
  for (int i = (int)l1; i <= (int)r1; i++) add(a[i]);
  for (int i = (int)l2; i <= (int)r2; i++) sub(a[i]);
  while (l1 <= n / 2) {
    while (r1 < n / 2 && non_zero != 0) {
      r1++;
      l2--;
      add(a[r1]);
      sub(a[l2]);
    }
    if (non_zero == 0) res += (long long)(n / 2 - r1 + 1);
    if (a[l1] == a[r2]) {
      sub(a[l1]);
      add(a[r2]);
      l1++;
      r2--;
      if (r1 < l1) {
        r1++;
        l2--;
        add(a[r1]);
        sub(a[l2]);
      }
    } else
      break;
  }
  res *= (long long)2;
  memset(d, 0, sizeof(d));
  l1 = 1;
  r1 = n / 2 + 1;
  l2 = n;
  am = le = 0;
  for (int i = (int)l1; i <= (int)r1; i++) add(a[i]);
  for (int i = (int)r1 + 1; i <= (int)l2; i++) sub(a[i]);
  while (l1 <= (n + 1) / 2) {
    while (r1 < l2 && (am != 0 || le != n % 2)) {
      r1++;
      add(a[r1]);
      add(a[r1]);
    }
    if (am == 0 && le == n % 2) res += (long long)l2 - r1 + 1;
    if (a[l1] == a[l2]) {
      l1++;
      l2--;
    } else
      break;
  }
  memset(d, 0, sizeof(d));
  l1 = (n + 1) / 2;
  r1 = n;
  r2 = 1;
  am = le = 0;
  for (int i = (int)l1; i <= (int)r1; i++) add(a[i]);
  for (int i = (int)r2; i <= (int)l1 - 1; i++) sub(a[i]);
  while (r1 > n / 2 + 1) {
    while (r2 < l1 && (am != 0 || le != n % 2)) {
      l1--;
      add(a[l1]);
      add(a[l1]);
    }
    if (am == 0 && le == n % 2) res += (long long)l1 - r2;
    if (a[r1] == a[r2]) {
      r1--;
      r2++;
    } else
      break;
  }
}
int main() {
  scanf("%i", &n);
  for (int i = (int)1; i <= (int)n; i++) scanf("%i", &a[i]);
  solve();
  cout << res;
}
