#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <class T>
int size(T &&x) {
  return int(x.size());
}
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <class T>
auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
  out << '{';
  for (auto it = x.begin(); it != x.end(); ++it)
    out << *it << (it == prev(x.end()) ? "" : ", ");
  return out << '}';
}
void dump() {}
template <class T, class... Args>
void dump(T &&x, Args... args) {
  cerr << x << ";  ";
  dump(args...);
}
mt19937_64 rng(0);
int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &ai : a) {
    cin >> ai;
    --ai;
  }
  vector<int> delta(n);
  int cnt_nprz = 0, cnt_negative = 0, cnt_nonequal = 0;
  int L = 0, R = -1;
  auto inside = [&](int i) { return L <= i and i <= R; };
  auto consider = [&](int i, bool to_add) {
    0 && cerr;
    if (i < 0 or i >= n) return;
    int j = n - 1 - i;
    int sign_to_add = (to_add ? 1 : -1);
    if (not inside(i) and not inside(j)) {
      if (a[i] != a[j]) cnt_nonequal += sign_to_add;
      return;
    }
    auto consider_delta = [&](int k) {
      if (delta[a[k]] < 0) --cnt_negative;
      if (delta[a[k]] % 2 == 1) --cnt_nprz;
      delta[a[k]] += (inside(k) ? 1 : -1) * sign_to_add;
      if (delta[a[k]] < 0) ++cnt_negative;
      if (delta[a[k]] % 2 == 1) ++cnt_nprz;
    };
    consider_delta(i);
    if (i != j) consider_delta(j);
  };
  auto is_good = [&] {
    return cnt_nonequal == 0 and cnt_negative == 0 and cnt_nprz <= 1;
  };
  auto print_state = [&] { 0 && cerr; };
  for (int i = (0); i <= (((n + 1) / 2) - 1); ++i) consider(i, true);
  print_state();
  auto move_R_right = [&] {
    consider(R + 1, false);
    consider(++R, true);
  };
  auto move_L_right = [&] {
    consider(L, false);
    ++L;
    consider(L - 1, true);
  };
  LL answer = 0;
  for (; L != n; move_L_right()) {
    if (R < L) move_R_right();
    while (R != n and not is_good()) {
      move_R_right();
      print_state();
    }
    0 && cerr;
    answer += n - R;
  }
  cout << answer << '\n';
}
