#include <bits/stdc++.h>
using namespace std;
long long outer_pal_len = 0ll;
long long inner_pal_len = 0ll;
vector<int> arr;
long long count_pal_left(int l, int r) {
  vector<int> cnt(arr.size(), 0);
  for (int i = l; i <= r; i++) {
    cnt[arr[i] - 1]++;
  }
  long long ret = 0ll;
  for (int i = r; i >= (l + r + 1) / 2; i--) {
    int pair_cnt = 2;
    if (i == (l + r + 1) / 2 && ((l + r) & 1) == 0) {
      pair_cnt = 1;
    }
    if (cnt[arr[i] - 1] >= pair_cnt) {
      cnt[arr[i] - 1] -= pair_cnt;
      ret++;
    } else {
      return ret;
    }
  }
  ret += inner_pal_len - 1;
  if ((l + r) & 1) {
    ret++;
  }
  return ret;
}
long long count_pal_right(int l, int r) {
  vector<int> cnt(arr.size(), 0);
  for (int i = l; i <= r; i++) {
    cnt[arr[i] - 1]++;
  }
  long long ret = 0ll;
  for (int i = l; i <= (l + r) / 2; i++) {
    int pair_cnt = 2;
    if (i == (l + r) / 2 && ((l + r) & 1) == 0) {
      pair_cnt = 1;
    }
    if (cnt[arr[i] - 1] >= pair_cnt) {
      cnt[arr[i] - 1] -= pair_cnt;
      ret++;
    } else {
      return ret;
    }
  }
  ret += inner_pal_len - 1;
  if ((l + r) & 1) {
    ret++;
  }
  return ret;
}
int is_possible(int l, int r) {
  vector<int> cnt(arr.size(), 0);
  for (int i = l; i <= r; i++) {
    cnt[arr[i] - 1]++;
  }
  int odd_cnt = 0;
  for (int i = l; i <= r; i++) {
    if (cnt[i] & 1) odd_cnt++;
  }
  return odd_cnt <= 1;
}
long long count_pal_whole() {
  if (!is_possible(0, arr.size() - 1)) {
    return 0;
  } else if (outer_pal_len >= arr.size() / 2) {
    return arr.size() * (arr.size() + 1ll) / 2;
  } else {
    int l = outer_pal_len;
    int r = arr.size() - outer_pal_len - 1;
    long long count_pal_inner = count_pal_left(l, r) + count_pal_right(l, r);
    return count_pal_inner * (outer_pal_len + 1) +
           (outer_pal_len + 1) * (outer_pal_len + 1);
  }
}
int main() {
  int n;
  cin >> n;
  arr = vector<int>(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < (n + 1) / 2; i++) {
    if (arr[i] == arr[n - i - 1]) {
      outer_pal_len++;
    } else {
      break;
    }
  }
  for (int i = (n - 1) / 2; i >= 0; i--) {
    if (arr[i] == arr[n - i - 1]) {
      inner_pal_len++;
    } else {
      break;
    }
  }
  long long ans = count_pal_whole();
  cout << ans << endl;
}
