much faster than bitmask 100ms 100%
\nclass Solution:\n    def maxProduct(self, s: str) -> int:\n        \n        @lru_cache(None)\n        def findBigPalLen(x): #O(n^2)\n            if len(x) <=
```\nclass Solution:\n    def maxProduct(self, s: str) -> int:\n        \n        @lru_cache(None)\n        def findBigPalLen(x): #O(n^2)\n            if len(x) <= 1: return len(x)\n            if x[0] == x[-1]: return 2 + findBigPalLen(x[1:-1])\n            return max(findBigPalLen(x[1:]), findBigPalLen(x[:-1]))\n        \n        @lru_cache(None)\n        def findAllPal(x): #Fast pruning\n            if len(x) == 0: \n                return [""], [x]\n            \n            Idx = defaultdict(list)\n            for i,l in enumerate(x): \n                Idx[l].append(i)\n            \n            X, Y = [""], [x]\n            for i in range(len(x)):\n                X.append(x[i])\n                Y.append(x[:i] + x[i + 1:])\n                for j in Idx[x[i]]:\n                    if j > i:\n                        X1, Y1 = findAllPal(x[i + 1 : j])\n                        for k in range(len(X1)):\n                            X.append(x[i] + X1[k] + x[j])\n                            Y.append(x[:i] + Y1[k] + x[j + 1:])\n            return X,Y\n        X, Y = findAllPal(s)\n        return max(len(X[i]) * findBigPalLen(Y[i]) for i in range(len(X)))\n```
['Python3']