<doocs>0730.Count Different Palindromic Subsequences_1.py
def countPalindromicSubsequences( s: str) -> int:
    mod = 10**9 + 7
    n = len(s)
    dp = [[[0] * 4 for _ in range(n)] for _ in range(n)]
    for i, c in enumerate(s):
        dp[i][i][ord(c) - ord('a')] = 1
    for l in range(2, n + 1):
        for i in range(n - l + 1):
            j = i + l - 1
            for c in 'abcd':
                k = ord(c) - ord('a')
                if s[i] == s[j] == c:
                    dp[i][j][k] = 2 + sum(dp[i + 1][j - 1])
                elif s[i] == c:
                    dp[i][j][k] = dp[i][j - 1][k]
                elif s[j] == c:
                    dp[i][j][k] = dp[i + 1][j][k]
                else:
                    dp[i][j][k] = dp[i + 1][j - 1][k]
    return sum(dp[0][-1]) % mod
def sample_funcname ( var_0 : str ) -> int :
    var_6 = 10 ** 9 + 7
    var_8 = len ( var_0 )
    var_13 = [ [ [ 0 ] * 4 for var_11 in range ( var_8 ) ] for var_11 in range ( var_8 ) ]
    for var_15 , var_16 in enumerate ( var_0 ) :
        var_13 [ var_15 ] [ var_15 ] [ ord ( var_16 ) - ord ( 'a' ) ] = 1
    for var_21 in range ( 2 , var_8 + 1 ) :
        for var_15 in range ( var_8 - var_21 + 1 ) :
            var_22 = var_15 + var_21 - 1
            for var_16 in 'abcd' :
                var_24 = ord ( var_16 ) - ord ( 'a' )
                if var_0 [ var_15 ] == var_0 [ var_22 ] == var_16 :
                    var_13 [ var_15 ] [ var_22 ] [ var_24 ] = 2 + sum ( var_13 [ var_15 + 1 ] [ var_22 - 1 ] )
                elif var_0 [ var_15 ] == var_16 :
                    var_13 [ var_15 ] [ var_22 ] [ var_24 ] = var_13 [ var_15 ] [ var_22 - 1 ] [ var_24 ]
                elif var_0 [ var_22 ] == var_16 :
                    var_13 [ var_15 ] [ var_22 ] [ var_24 ] = var_13 [ var_15 + 1 ] [ var_22 ] [ var_24 ]
                else :
                    var_13 [ var_15 ] [ var_22 ] [ var_24 ] = var_13 [ var_15 + 1 ] [ var_22 - 1 ] [ var_24 ]
    return sum ( var_13 [ 0 ] [ - 1 ] ) % var_6
