#include <bits/stdc++.h>
using namespace std;
template <int POS, class TUPLE>
void deploy(std::ostream &os, const TUPLE &tuple) {}
template <int POS, class TUPLE, class H, class... Ts>
void deploy(std::ostream &os, const TUPLE &t) {
  os << (POS == 0 ? "" : ", ") << get<POS>(t);
  deploy<POS + 1, TUPLE, Ts...>(os, t);
}
template <class... Ts>
std::ostream &operator<<(std::ostream &os, const std::tuple<Ts...> &t) {
  os << "(";
  deploy<0, std::tuple<Ts...>, Ts...>(os, t);
  os << ")";
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> &v) {
  int remain = v.size();
  os << "{";
  for (auto e : v) os << e << (--remain == 0 ? "" : ", ");
  os << "}";
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::set<T> &v) {
  int remain = v.size();
  os << "{";
  for (auto e : v) os << e << (--remain == 0 ? "" : ", ");
  os << "}";
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::queue<T> &q) {
  auto qq = q;
  os << "{";
  for (; !qq.empty(); qq.pop()) {
    os << qq.front() << (qq.size() != 1 ? ", " : "");
  }
  os << "}";
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::priority_queue<T> &q) {
  auto qq = q;
  os << "{";
  for (; !qq.empty(); qq.pop()) {
    os << qq.top() << (qq.size() != 1 ? ", " : "");
  }
  os << "}";
  return os;
}
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::pair<T, K> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::map<T, K> &mp) {
  int remain = mp.size();
  os << "{";
  for (auto e : mp)
    os << "(" << e.first << " -> " << e.second << ")"
       << (--remain == 0 ? "" : ", ");
  os << "}";
  return os;
}
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::unordered_map<T, K> &mp) {
  int remain = mp.size();
  os << "{";
  for (auto e : mp)
    os << "(" << e.first << " -> " << e.second << ")"
       << (--remain == 0 ? "" : ", ");
  os << "}";
  return os;
}
int64_t n;
int64_t dist(int64_t k) { return 2 * k - (n - 1); }
int main() {
  cin >> n;
  vector<int64_t> a(n);
  for (int64_t i = 0; i < ((int64_t)(n)); ++i) cin >> a[i];
  vector<int64_t> rev = a;
  reverse((rev).begin(), (rev).end());
  int64_t lack = 0;
  int64_t odd_num = 0;
  unordered_map<int64_t, int64_t> required, cnt;
  int64_t l = 0, r = 0;
  vector<int64_t> must(n);
  for (int64_t i = 0; i < ((int64_t)(n)); ++i) must[i] = rev[i] != a[i];
  int64_t mini = (((int64_t)1) << ((int64_t)(50)));
  int64_t maxi = 0;
  for (int64_t i = 0; i < ((int64_t)(n)); ++i)
    if (must[i]) mini = min(mini, abs(dist(i)));
  for (int64_t i = 0; i < ((int64_t)(n)); ++i)
    if (must[i]) maxi = max(maxi, abs(dist(i)));
  vector<int64_t> rev_index(n);
  for (int64_t i = 0; i < ((int64_t)(n)); ++i) rev_index[i] = i;
  reverse((rev_index).begin(), (rev_index).end());
  int64_t odd_to_be = 0;
  int64_t ans = 0;
  for (int64_t l = 0, r = -1; true;) {
    while (true) {
      bool ok = true;
      do {
        if (r < l) {
          ok = false;
          break;
        }
        if (dist(r) < 0 || 0 < dist(l)) {
          if (mini < min(abs(dist(l)), abs(dist(r)))) {
            ok = false;
            break;
          }
        }
        if (maxi > max(abs(dist(l)), abs(dist(r)))) {
          ok = false;
          break;
        }
        if (0 < lack) {
          ok = false;
          break;
        }
        if (odd_num != odd_to_be) {
          ok = false;
          break;
        }
      } while (false);
      if (ok) break;
      ++r;
      if (r == n) break;
      if (rev_index[r] == r) {
        ++odd_to_be;
      } else if (l <= rev_index[r] && rev_index[r] <= r) {
        int64_t t = a[r];
        assert(1 <= required[t]);
        odd_num -= (cnt[t] - required[t]) % 2;
        lack -= max((int64_t)0, required[t] - cnt[t]);
        --required[t];
        odd_num += (cnt[t] - required[t]) % 2;
        lack += max((int64_t)0, required[t] - cnt[t]);
      } else {
        int64_t t = a[rev_index[r]];
        odd_num -= (cnt[t] - required[t]) % 2;
        lack -= max((int64_t)0, required[t] - cnt[t]);
        ++required[t];
        odd_num += (cnt[t] - required[t]) % 2;
        lack += max((int64_t)0, required[t] - cnt[t]);
      }
      int64_t t = a[r];
      odd_num -= (cnt[t] - required[t]) % 2;
      lack -= max((int64_t)0, required[t] - cnt[t]);
      ++cnt[t];
      odd_num += (cnt[t] - required[t]) % 2;
      lack += max((int64_t)0, required[t] - cnt[t]);
    }
    if (r == n) break;
    ans += (n - r);
    if (rev_index[l] == l) {
      --odd_to_be;
    } else if (l <= rev_index[l] && rev_index[l] <= r) {
      int64_t t = a[l];
      odd_num -= (cnt[t] - required[t]) % 2;
      lack -= max((int64_t)0, required[t] - cnt[t]);
      ++required[t];
      odd_num += (cnt[t] - required[t]) % 2;
      lack += max((int64_t)0, required[t] - cnt[t]);
    } else {
      int64_t t = a[rev_index[l]];
      assert(1 <= required[t]);
      odd_num -= (cnt[t] - required[t]) % 2;
      lack -= max((int64_t)0, required[t] - cnt[t]);
      --required[t];
      odd_num += (cnt[t] - required[t]) % 2;
      lack += max((int64_t)0, required[t] - cnt[t]);
    }
    int64_t t = a[l];
    odd_num -= (cnt[t] - required[t]) % 2;
    lack -= max((int64_t)0, required[t] - cnt[t]);
    --cnt[t];
    odd_num += (cnt[t] - required[t]) % 2;
    lack += max((int64_t)0, required[t] - cnt[t]);
    ++l;
    if (l == n) break;
  }
  cout << ans << endl;
}
