<doocs>0214.Shortest Palindrome_1.py
def shortestPalindrome( s: str) -> str:
    base = 131
    mod = 10**9 + 7
    n = len(s)
    prefix = suffix = 0
    mul = 1
    idx = 0
    for i, c in enumerate(s):
        prefix = (prefix * base + (ord(c) - ord('a') + 1)) % mod
        suffix = (suffix + (ord(c) - ord('a') + 1) * mul) % mod
        mul = (mul * base) % mod
        if prefix == suffix:
            idx = i + 1
    return s if idx == n else s[idx:][::-1] + s
def sample_funcname ( var_0 : str ) -> str :
    var_3 = 131
    var_7 = 10 ** 9 + 7
    var_9 = len ( var_0 )
    var_12 = var_10 = 0
    var_14 = 1
    var_15 = 0
    for var_17 , var_18 in enumerate ( var_0 ) :
        var_12 = ( var_12 * var_3 + ( ord ( var_18 ) - ord ( 'a' ) + 1 ) ) % var_7
        var_10 = ( var_10 + ( ord ( var_18 ) - ord ( 'a' ) + 1 ) * var_14 ) % var_7
        var_14 = ( var_14 * var_3 ) % var_7
        if var_12 == var_10 :
            var_15 = var_17 + 1
    return var_0 if var_15 == var_9 else var_0 [ var_15 : ] [ : : - 1 ] + var_0
