func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 5;   int t[N], n, a[N], f[N], b[N], k, x, mid;   vector<int> G[N];   long long ans;   bool O = 0;   int work() {     memset(f, 0, sizeof(f));     for (int i = k; i <= n - k + 1; i++) f[b[i]]++;     int o = 0;     for (int i = 1; i <= n; i++)       if (f[i] & 1) {         if (o) return n - k + 1;         o = i;       }     if (((n & 1) ^ (o > 0))) return n - k + 1;     memset(f, 0, sizeof(f));     for (int i = 1; i <= n; i++) G[i].clear();     for (int i = k; i <= n - k + 1; i++) {       x = b[i];       t[x]++;       G[x].push_back(i);     }     int mini = k;     if (o && o != b[mid]) mini = mid;     O = 1;     for (int i = n - k + 1; i >= mini; i--)       if (i > mid) {         f[x = b[i]]++;         if (f[x] > t[x] || G[x][f[x] - 1] >= i) return i - 1;         if (b[i] != b[n - i + 1]) mini = max(mini, G[x][f[x] - 1]);       } else if (b[i] != b[n - i + 1])         return i - 1;     return mini - 1;   }   int main() {     cin >> n;     mid = n / 2 + (n & 1);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (k = 1; k <= mid && a[k] == a[n - k + 1]; k++)       ;     if (k > mid) {       cout << (long long)n * (n + 1) / 2;       return 0;     }     for (int i = k; i <= n - k + 1; i++) b[i] = a[i];     ans = n - k + 1 - work();     for (int i = k; i <= n - k + 1; i++) b[n - i + 1] = a[i];     ans += n - k + 1 - work();     ans = ans * k;     if (ans) ans += (long long)(k - 1) * (k - 1);     if (O) ans--;     cout << ans;   }   