#include <bits/stdc++.h>
using namespace std;
int n, str[100010];
void read() {
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", str + i);
}
bool check1(int a, int b, int c) {
  static int ans[100010];
  static int occur[100010];
  for (int i = 1; i <= n; ++i) ans[i] = str[i];
  memset(occur, 0, sizeof(occur));
  for (int i = a; i <= b; ++i) ++occur[str[i]];
  for (int i = a; i <= b; ++i)
    if (n - i + 1 < a || n - i + 1 > b) {
      ans[i] = str[n - i + 1];
      if (occur[str[n - i + 1]]-- == 0) return false;
    }
  int cur = 0;
  for (int i = 1; i <= n; ++i) cur += occur[i] & 1;
  for (int i = b + 1; i <= c; ++i)
    if (ans[i] != ans[n - i + 1]) return false;
  return cur <= 1;
}
bool check2(int a, int b, int c) {
  static int ans[100010];
  static int occur[100010];
  for (int i = 1; i <= n; ++i) ans[i] = str[i];
  memset(occur, 0, sizeof(occur));
  for (int i = a; i <= b; ++i) ++occur[str[i]];
  for (int i = a; i <= b; ++i)
    if (n - i + 1 < a || n - i + 1 > b) {
      ans[i] = str[n - i + 1];
      if (occur[str[n - i + 1]]-- == 0) return false;
    }
  int cur = 0;
  for (int i = 1; i <= n; ++i) cur += occur[i] & 1;
  for (int i = c; i <= a - 1; ++i)
    if (ans[i] != ans[n - i + 1]) return false;
  return cur <= 1;
}
long long calc(long long a, long long b) {
  if (!check1(a, b, b)) return 0;
  int l, r;
  long long ansl, ansr;
  l = 1, r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    !check1(a, mid, b) ? l = mid + 1 : r = mid;
  }
  ansl = l;
  l = 1, r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    check2(mid, b, a) ? l = mid + 1 : r = mid;
  }
  ansr = l - 1;
  return a * (n - ansl + 1) + ansr * (n - b + 1) - a * (n - b + 1);
}
long long work() {
  long long l = 1, r = n;
  while (l <= r && str[l] == str[r]) ++l, --r;
  if (l > r) return (long long)n * (n + 1) / 2;
  return calc(l, r);
}
int main() {
  read();
  cout << work() << endl;
  return 0;
}
