#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e18;   const long long MOD = (long long)1e9 + 7;   long long n, r[200000], a[200000], bad, brd, odd, ll, rr, cnt[200000],       cntl[200000], i, j, ans;   int main() {     scanf( %d , &n);     for (i = 0; i < n; ++i) scanf( %d , &r[i]), ++cnt[r[i]];     for (i = 0; i < 200000; ++i)       if (cnt[i] % 2LL) ++odd;     if (odd > 1) {       printf( %d n , 0);       return 0;     }     for (i = 0; i < 200000; ++i) cnt[i] = 0;     for (i = 0; i < n / 2LL && r[i] == r[n - i - 1]; ++i) ++brd;     for (i = brd; i < n - brd; ++i) a[i - brd] = r[i], ++cnt[r[i]];     if (n - 2LL * brd <= 1LL) {       printf( %lld n , (n * (n + 1LL)) / 2LL);       return 0;     }     n -= 2LL * brd;     if (n % 2LL) {       long long gmid = 0;       if (cnt[a[n / 2LL]] % 2LL) {         while (a[n / 2 - gmid] == a[n / 2 + gmid]) ++gmid;       }       for (i = n / 2 - gmid + 1; i <= n / 2 + gmid - 1; ++i) --cnt[a[i]];       long long minl, minr;       bad = 0;       for (i = 0; i < 200000; ++i)         if (cnt[i]) ++bad;       for (i = 0; i < 200000; ++i) cntl[i] = 0;       for (i = 0; i < n; ++i) {         ++cntl[a[i]];         if (i >= n / 2 - gmid + 1 && i <= n / 2 + gmid - 1) --cntl[a[i]];         if (cntl[a[i]] && cntl[a[i]] == (cnt[a[i]] + 1) / 2LL) --bad;         if (i == n / 2 + gmid - 1) {           for (j = n / 2 - gmid + 1; j <= n / 2 + gmid - 1; ++j) {             ++cntl[a[j]];             ++cnt[a[j]];           }           for (j = n / 2 - gmid + 1; j <= n / 2 + gmid - 1; ++j)             if (cntl[a[j]] == (cnt[a[j]] + 1) / 2LL) --bad;         }         if (!bad) {           minl = i;           break;         }       }       gmid = 0;       if (cnt[a[n / 2LL]] % 2LL) {         while (a[n / 2 - gmid] == a[n / 2 + gmid]) ++gmid;       }       for (i = n / 2 - gmid + 1; i <= n / 2 + gmid - 1; ++i) --cnt[a[i]];       bad = 0;       for (i = 0; i < 200000; ++i)         if (cnt[i]) ++bad;       for (i = 0; i < 200000; ++i) cntl[i] = 0;       for (i = n - 1; i >= 0; --i) {         ++cntl[a[i]];         if (i >= n / 2 - gmid + 1 && i <= n / 2 + gmid - 1) --cntl[a[i]];         if (cntl[a[i]] && cntl[a[i]] == (cnt[a[i]] + 1) / 2LL) --bad;         if (i == n / 2 - gmid + 1) {           for (j = n / 2 - gmid + 1; j <= n / 2 + gmid - 1; ++j) {             ++cntl[a[j]];             ++cnt[a[j]];           }           for (j = n / 2 - gmid + 1; j <= n / 2 + gmid - 1; ++j)             if (cntl[a[j]] == (cnt[a[j]] + 1) / 2LL) --bad;         }         if (!bad) {           minr = i;           break;         }       }       printf( %lld n , (brd + 1LL) * (brd + (n - minl)) +                            (brd + 1LL) * (brd + (minr + 1LL)) -                            (brd + 1LL) * (brd + 1LL));     } else {       long long gmid = 0;       while (a[n / 2 - gmid - 1] == a[n / 2 + gmid]) ++gmid;       for (i = n / 2 - gmid; i <= n / 2 + gmid - 1; ++i) --cnt[a[i]];       long long minl, minr;       bad = 0;       for (i = 0; i < 200000; ++i)         if (cnt[i]) ++bad;       for (i = 0; i < 200000; ++i) cntl[i] = 0;       for (i = 0; i < n; ++i) {         ++cntl[a[i]];         if (i >= n / 2 - gmid && i <= n / 2 + gmid - 1) --cntl[a[i]];         if (cntl[a[i]] == cnt[a[i]] / 2LL) --bad;         if (i == n / 2 + gmid - 1)           for (j = n / 2 - gmid; j <= n / 2 + gmid - 1; ++j) {             ++cntl[a[j]];             if (cntl[a[j]] == cnt[a[j]] / 2LL) --bad;           }         if (!bad) {           minl = i;           break;         }       }       bad = 0;       for (i = 0; i < 200000; ++i)         if (cnt[i]) ++bad;       for (i = 0; i < 200000; ++i) cntl[i] = 0;       for (i = n - 1; i >= 0; --i) {         ++cntl[a[i]];         if (i >= n / 2 - gmid && i <= n / 2 + gmid - 1) --cntl[a[i]];         if (cntl[a[i]] == cnt[a[i]] / 2LL) --bad;         if (i == n / 2 - gmid)           for (j = n / 2 - gmid; j <= n / 2 + gmid - 1; ++j) {             ++cntl[a[j]];             if (cntl[a[j]] == cnt[a[j]] / 2LL) --bad;           }         if (!bad) {           minr = i;           break;         }       }       printf( %lld n , (brd + 1LL) * (brd + (n - minl)) +                            (brd + 1LL) * (brd + (minr + 1LL)) -                            (brd + 1LL) * (brd + 1LL));     }   }