#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int n;
int a[100000];
int cnt[100000];
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  int sur = 0, me = 0, mid = 0, other = 0;
  for (int i = (0); i < (n); ++i) cnt[i] = 0;
  while (me + other < n) {
    if (cnt[a[n - other - 1]] > 0) {
      --cnt[a[n - other - 1]];
      ++other;
      continue;
    }
    cnt[a[me]]++;
    ++me;
  }
  if (me == other + 1 && cnt[a[me - 1]] > 0) cnt[a[me - 1]]--, --me, ++mid;
  if (me == other)
    while (me > 0 && a[me - 1] == a[n - me]) --me, --other, mid += 2;
  while (me > 0 && a[sur] == a[n - sur - 1]) ++sur, --me, --other;
  long long ret = 0;
  if (mid == n) {
    ret += (long long)n * (n + 1) / 2;
  } else if (me == other) {
    ret += (long long)(sur + 1) * (mid + other + sur + 1);
    ret += (long long)(sur + me + mid + 1) * (sur + 1);
    ret -= (long long)(sur + 1) * (sur + 1);
  } else {
    int nodd = 0;
    for (int i = (0); i < (n); ++i)
      if (cnt[i] % 2 != 0) ++nodd;
    if (nodd <= n % 2) {
      int sur2 = 0, me2 = 0, mid2 = 0, other2 = 0;
      for (int i = (0); i < (n); ++i) cnt[i] = 0;
      while (me2 + other2 < n) {
        if (cnt[a[other2]] > 0) {
          --cnt[a[other2]];
          ++other2;
          continue;
        }
        cnt[a[n - me2 - 1]]++;
        ++me2;
      }
      if (me2 == other2 + 1) cnt[a[n - me2]]--, --me2, ++mid2;
      if (me2 == other2)
        while (me2 > 0 && a[me2 - 1] == a[n - me2]) --me2, --other2, mid2 += 2;
      while (me2 > 0 && a[sur2] == a[n - sur2 - 1]) ++sur2, --me2, --other2;
      assert(mid == 0 && mid2 == 0 && sur == sur2 &&
             me + other == other2 + me2);
      ret += (long long)(sur + 1) * (other + sur + 1);
      ret += (long long)(sur + other2 + 1) * (sur + 1);
      ret -= (long long)(sur + 1) * (sur + 1);
    }
  }
  cout << ret << endl;
}
int main() {
  run();
  return 0;
}
