#include using namespace std; int64_t a[1000000], n; bool isPalindrom(int i, int j) { while (i < j) { if (a[i] != a[j])return false; i++, j--; } return true; } int main() { ifstream cin ("split.in"); ofstream cout("split.out"); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int64_t i, j, sum1 = 0, sum2 = 0, maxInd = 0; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { maxInd = i; for (j = i+1; j < n; j++) { if (isPalindrom(i, j))maxInd = j; } sum1 += (maxInd-i+1)*(maxInd-i+1); i = maxInd; } for (i = n-1; i >= 0; i--) { maxInd = i; for (j = i-1; j >= 0; j--) { if (isPalindrom(j, i))maxInd = j; } sum2 += (i-maxInd+1)*(i-maxInd+1); i = maxInd; } cout << max(sum1, sum2) << '\n'; return 0; } /* 10 1 1 1 1 1 1 2 2 1 1 */