#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9;
const int MAXN = 200010;
int n;
int ar[MAXN];
int S[MAXN];
set<int> T;
set<int> N;
int odd;
void clear() {
  odd = 0;
  memset(S, 0, sizeof(S));
  T.clear();
  N.clear();
}
void rem(int a) {
  S[a]--;
  if (S[a] < 0)
    N.insert(a);
  else if (S[a] % 2)
    T.insert(a);
  else {
    if (T.find(a) != T.end()) T.erase(T.find(a));
    if (N.find(a) != N.end()) N.erase(N.find(a));
  }
  odd = ((int)(T).size()) + ((int)(N).size()) * 100;
}
void add(int a) {
  S[a]++;
  if (S[a] < 0)
    N.insert(a);
  else if (S[a] % 2)
    T.insert(a);
  else {
    if (T.find(a) != T.end()) T.erase(T.find(a));
    if (N.find(a) != N.end()) N.erase(N.find(a));
  }
  odd = ((int)(T).size()) + ((int)(N).size()) * 100;
}
int main() {
  scanf(" %d", &n);
  for (int(i) = (1); (i) <= (n); (i)++) scanf(" %d", ar + i);
  if (n % 2 == 0) {
    int mid = 1 + n;
    mid /= 2;
    int count = 0;
    while (mid - count > 0 && ar[mid - count] == ar[mid + count + 1]) count++;
    count *= 2;
    int beg = 1, end = n;
    while (end > 0 && ar[beg] == ar[end]) beg++, end--;
    if (beg == n + 1 && end == 0) {
      cout << ((long long)n * (long long)(n + 1)) / 2 << endl;
      return 0;
    }
    pair<int, int> L = pair<int, int>(-1, -1), R = pair<int, int>(-1, -1);
    clear();
    for (int i = beg, j = end; i < j; i++, j--) {
      add(ar[i]);
      rem(ar[j]);
      if (odd == 0 && count >= j - i - 1) {
        L = pair<int, int>(beg, i);
        break;
      }
    }
    if (L == pair<int, int>(-1, -1)) {
      for (int i = mid + 1, j = mid; i <= n; i++, j--) {
        add(ar[i]);
        add(ar[i]);
        if (odd == 0) {
          L = pair<int, int>(beg, i);
          break;
        }
      }
    }
    clear();
    for (int i = beg, j = end; i < j; i++, j--) {
      add(ar[j]);
      rem(ar[i]);
      if (odd == 0 && count >= j - i - 1) {
        R = pair<int, int>(j, end);
        break;
      }
    }
    if (R == pair<int, int>(-1, -1)) {
      for (int i = mid + 1, j = mid; i <= n; i++, j--) {
        add(ar[j]);
        add(ar[j]);
        if (odd == 0) {
          R = pair<int, int>(j, end);
          break;
        }
      }
    }
    long long rev = (long long)L.first * (long long)(n - L.second + 1) +
                    (long long)R.first * (long long)(n - R.second + 1) -
                    (long long)min(L.first, R.first) *
                        (long long)(n - max(L.second, R.second) + 1);
    if (L.first == -1 || R.first == -1) rev = 0;
    cout << rev << endl;
  } else {
    int mid = 1 + n;
    mid /= 2;
    int count = 1;
    while (mid - count > 0 && ar[mid - count] == ar[mid + count]) count++;
    count *= 2;
    count -= 1;
    int beg = 1, end = n;
    while (end > 0 && ar[beg] == ar[end]) beg++, end--;
    if (beg == n + 1 && end == 0) {
      cout << ((long long)n * (long long)(n + 1)) / 2 << endl;
      return 0;
    }
    pair<int, int> L = pair<int, int>(-1, -1), R = pair<int, int>(-1, -1);
    clear();
    for (int i = beg, j = end; i < j; i++, j--) {
      add(ar[i]);
      rem(ar[j]);
      if (odd == 0 && count >= j - i - 1) {
        L = pair<int, int>(beg, i);
        break;
      }
    }
    add(ar[mid]);
    if (odd == 1 && L == pair<int, int>(-1, -1)) L = pair<int, int>(beg, mid);
    if (L == pair<int, int>(-1, -1)) {
      for (int i = mid + 1, j = mid - 1; i <= n; i++, j--) {
        add(ar[i]);
        add(ar[i]);
        if (odd == 1) {
          L = pair<int, int>(beg, i);
          break;
        }
      }
    }
    clear();
    for (int i = beg, j = end; i < j; i++, j--) {
      add(ar[j]);
      rem(ar[i]);
      if (odd == 0 && count >= j - i - 1) {
        R = pair<int, int>(j, end);
        break;
      }
    }
    add(ar[mid]);
    if (odd == 1 && R == pair<int, int>(-1, -1)) R = pair<int, int>(mid, end);
    if (R == pair<int, int>(-1, -1)) {
      for (int i = mid + 1, j = mid - 1; i <= n; i++, j--) {
        add(ar[j]);
        add(ar[j]);
        if (odd == 1) {
          R = pair<int, int>(j, end);
          break;
        }
      }
    }
    long long rev = (long long)L.first * (long long)(n - L.second + 1) +
                    (long long)R.first * (long long)(n - R.second + 1) -
                    (long long)min(L.first, R.first) *
                        (long long)(n - max(L.second, R.second) + 1);
    if (L.first == -1 || R.first == -1) rev = 0;
    cout << rev << endl;
  }
  return 0;
}
