#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
int n;
int a[1 << 17];
int cnt[1 << 17];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= (n); ++i) scanf("%d", a + i);
  int ps = -1;
  for (int i = 1; i <= (n); ++i)
    if (a[i] != a[n + 1 - i]) {
      ps = i - 1;
      break;
    }
  if (!~ps) return printf("%lld\n", n * (n + 1ll) / 2), 0;
  int L = ps + 1, R = n - ps;
  int ls, rs;
  auto check = [&](int mid) {
    for (int i = 0; i < (mid); ++i) ++cnt[a[L + i]];
    bool can = 1;
    int ji = 0, ou = 0;
    for (int l = L, r = R; l <= r; ++l, --r) {
      if (l < L + mid && r < L + mid) {
        if (l == r)
          ++ji;
        else
          ++ou;
      } else if (l < L + mid) {
        if (!cnt[a[r]]) can = 0;
        --cnt[a[r]];
      } else if (a[l] != a[r])
        can = 0;
    }
    for (int i = 1; i <= (n); ++i) {
      if (cnt[i] % 2 == 1) {
        if (!ji) can = 0;
        --ji;
      }
      ou -= cnt[i] / 2;
      if (ou < 0) can = 0;
      cnt[i] = 0;
    }
    return can;
  };
  int l = -1, r = R - L + 2;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (check(m))
      r = m;
    else
      l = m;
  }
  ls = r;
  auto check2 = [&](int mid) {
    for (int i = 0; i < (mid); ++i) ++cnt[a[R - i]];
    bool can = 1;
    int ji = 0, ou = 0;
    for (int l = L, r = R; l <= r; ++l, --r) {
      if (l > R - mid && r > R - mid) {
        if (l == r)
          ++ji;
        else
          ++ou;
      } else if (r > R - mid) {
        if (!cnt[a[l]]) can = 0;
        --cnt[a[l]];
      } else if (a[l] != a[r])
        can = 0;
    }
    for (int i = 1; i <= (n); ++i) {
      if (cnt[i] % 2 == 1) {
        if (!ji) can = 0;
        --ji;
      }
      ou -= cnt[i] / 2;
      if (ou < 0) can = 0;
      cnt[i] = 0;
    }
    return can;
  };
  l = -1, r = R - L + 1;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (check2(m))
      r = m;
    else
      l = m;
  }
  rs = r;
  printf("%lld\n", 1ll * (ps + 1) * (ps + 2 * (R - L + 1) + 1 - ls - rs));
  return 0;
}
