#include <bits/stdc++.h>
using namespace std;
int fun(string x){
int n = x.size();
vector<vector<int>> dp(n,vector<int>(n,0));
for(int i=0;i<n;i++){
dp[i][i] = 1;
}
for(int k=1;k<n;k++){
for(int i=0;i<n-k;i++){
int j = i + k;
if(x[i]==x[j]){
dp[i][j] = 2 + dp[i+1][j-1];
} else{
dp[i][j] = max(dp[i][j-1],dp[i+1][j]);
}
}
}
int maxProd = 0;
for(int i=0;i<n;i++){
for(int j=0;j<n-1;j++){
maxProd = max(maxProd,dp[i][j]*dp[j+1][n-1]);
}
}
return maxProd;
}
int main() {
// your code goes here
cout<<fun("accbcac");
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBmdW4oc3RyaW5nIHgpewppbnQgbiA9IHguc2l6ZSgpOwp2ZWN0b3I8dmVjdG9yPGludD4+IGRwKG4sdmVjdG9yPGludD4obiwwKSk7CmZvcihpbnQgaT0wO2k8bjtpKyspewogICAgZHBbaV1baV0gPSAxOwp9CmZvcihpbnQgaz0xO2s8bjtrKyspewpmb3IoaW50IGk9MDtpPG4taztpKyspewogICAgICAgIGludCBqID0gaSArIGs7CiAgICAgICAgICAgIGlmKHhbaV09PXhbal0pewogICAgICAgICAgICAgICAgZHBbaV1bal0gPSAyICsgZHBbaSsxXVtqLTFdOwogICAgICAgICAgICB9IGVsc2V7CiAgICAgICAgICAgICAgICBkcFtpXVtqXSA9IG1heChkcFtpXVtqLTFdLGRwW2krMV1bal0pOwogICAgICAgICAgICB9CiAgIH0KfQppbnQgbWF4UHJvZCA9IDA7CmZvcihpbnQgaT0wO2k8bjtpKyspewogICAgZm9yKGludCBqPTA7ajxuLTE7aisrKXsKICAgICAgICBtYXhQcm9kID0gbWF4KG1heFByb2QsZHBbaV1bal0qZHBbaisxXVtuLTFdKTsKICAgICAgfQogICB9CnJldHVybiBtYXhQcm9kOwp9CmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJY291dDw8ZnVuKCJhY2NiY2FjIik7CglyZXR1cm4gMDsKfQ==