#include <bits/stdc++.h>
using namespace std;
const int maxN = (1 << 18) + 100;
int a[maxN];
int cnt[maxN];
bool pal(int l, int r) {
  if (l >= r) return true;
  for (int i = 0; i < (r - l + 1) / 2; i++) {
    if (a[l + i] != a[r - i]) return false;
  }
  return true;
}
int main() {
  long long n;
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long m = 0;
  for (int i = 1; i <= n / 2; i++) {
    if (a[i] == a[n - i + 1])
      m++;
    else
      break;
  }
  long long ans = 0;
  if (m * 2 + 1 >= n) {
    cout << (1ll * n * (n - 1)) / 2 + n << endl;
    return 0;
  } else {
    int pp = 0;
    for (int i = m + 1; i <= n - m; i++) {
      cnt[a[i]]++;
      if (cnt[a[i]] % 2 == 0)
        pp--;
      else
        pp++;
    }
    if (pp == 0 || (pp == 1 && (n - 2 * m) % 2 == 1))
      ans += (m) * (m);
    else {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 1; i <= n - 2 * m; i++) a[i] = a[m + i];
    int l = 1;
    int r = n - 2 * m;
    int sz = r;
    while (r - l > 1) {
      int mm = (r + l) / 2;
      if (mm <= (sz) / 2) {
        if (!pal(mm + 1, sz - mm)) {
          l = mm;
          continue;
        }
        memset(cnt, 0, sizeof(int) * (n + 2));
        for (int i = 1; i <= mm; i++) cnt[a[i]]++;
        for (int i = sz; i > sz - mm; i--) cnt[a[i]]--;
        int pp = (*max_element(cnt + 1, cnt + n + 1)) -
                 (*min_element(cnt + 1, cnt + n + 1));
        if (pp == 0) {
          r = mm;
        } else {
          l = mm;
        }
        continue;
      } else {
        memset(cnt, 0, sizeof(int) * (n + 2));
        for (int i = 1; i <= sz; i++) {
          if (i <= mm) {
            cnt[a[i]]++;
          } else {
            cnt[a[i]]--;
          }
        }
        int pp = (*min_element(cnt + 1, cnt + n + 1));
        if (pp < 0) {
          l = mm;
          continue;
        }
        int k = 0;
        for (int i = 1; i <= n; i++) {
          k += cnt[i] % 2;
        }
        if (k != sz % 2) {
          l = mm;
        } else {
          r = mm;
        }
      }
    }
    ans += (sz - r + 1) * (m + 1);
    l = 1;
    r = n - 2 * m;
    sz = r;
    reverse(a + 1, a + sz + 1);
    while (r - l > 1) {
      int mm = (r + l) / 2;
      if (mm <= (sz) / 2) {
        if (!pal(mm + 1, sz - mm)) {
          l = mm;
          continue;
        }
        memset(cnt, 0, sizeof(int) * (n + 2));
        for (int i = 1; i <= mm; i++) cnt[a[i]]++;
        for (int i = sz; i > sz - mm; i--) cnt[a[i]]--;
        int pp = (*max_element(cnt + 1, cnt + n + 1)) -
                 (*min_element(cnt + 1, cnt + n + 1));
        if (pp == 0) {
          r = mm;
        } else {
          l = mm;
        }
        continue;
      } else {
        memset(cnt, 0, sizeof(int) * (n + 2));
        for (int i = 1; i <= sz; i++) {
          if (i <= mm) {
            cnt[a[i]]++;
          } else {
            cnt[a[i]]--;
          }
        }
        int pp = (*min_element(cnt + 1, cnt + n + 1));
        if (pp < 0) {
          l = mm;
          continue;
        }
        int k = 0;
        for (int i = 1; i <= n; i++) {
          k += cnt[i] % 2;
        }
        if (k != sz % 2) {
          l = mm;
        } else {
          r = mm;
        }
      }
    }
    ans += (sz - r + 1) * (m + 1);
    ans -= 1;
  }
  cout << ans << endl;
  return 0;
}
