It's a bracket match problem and all given bracket is left bracket using dp f[i][j] first i character match j pair of bracket
if s[i]=='?' then it can match a new pair so f[i][k]=f[i-1][k]+f[i-1][k-1] (0=<k<=i/2 && if s[i]=='?') else f[i][j]=f[i-1][j] (0<=j<=i/2)
at last remember multiply 25 if '?' match '?'
though it it n^2 but it really fast data that is 100000 '?' using around 4 second so it can pass the testdata
(but I feel it can be optimized because this dp's transfer is very special maybe lazy lag or something else)