#include <bits/stdc++.h>
using namespace std;
long long n;
bool palindrome(vector<int> &A, int a, int b) {
  int lenght = b - a + 1;
  for (int k = 0; k < lenght / 2; ++k)
    if (A[a + k] != A[a + lenght - k - 1]) return false;
  return true;
}
bool check(vector<int> &A, int a, int b, int lenght) {
  int m = a + lenght - 1;
  if (m < (b - a + 1) / 2 && !palindrome(A, m + 1, b - m - 1)) return false;
  vector<int> count(n);
  for (int i = a; i <= m; ++i) count[A[i]]++;
  for (int k = b, i = 0; i < lenght; ++i, --k) {
    if (k == m) break;
    count[A[k]]--;
  }
  int odd = 0;
  for (int c : count) {
    if (c < 0) return false;
    odd += c % 2;
  }
  return odd <= 1;
}
int bs(vector<int> &A, int a, int b) {
  int left = 1, right = b - a + 2;
  while (left != right) {
    int mid = (left + right) / 2;
    if (check(A, a, b, mid))
      right = mid;
    else
      left = mid + 1;
  }
  return right;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  vector<int> A(n);
  vector<int> count(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    count[--A[i]]++;
  }
  int odd = 0;
  for (int c : count) odd += c % 2;
  if (odd > 1) {
    cout << 0 << '\n';
    return 0;
  }
  vector<int> B(A.rbegin(), A.rend());
  int l = 0;
  while (l < n && A[l] == B[l]) ++l;
  if (l == n) {
    cout << n * (n + 1) / 2;
    return 0;
  } else {
    long long ans = 0;
    int a = l;
    int b = n - 1 - l;
    long long preL = bs(A, a, b);
    ans += (l + 1) * (n - (l + preL - 1));
    long long suffL = bs(B, a, b);
    ans += (l + 1) * (n - (l + suffL - 1));
    ans -= (l + 1) * (l + 1);
    cout << ans;
  }
  return 0;
}
