CSES - Hash function

Consider the following hash function:

(c0An1+c1An2+cn1A0)modM (c_0 A^{n-1} + c_1 A^{n-2} \cdots + c_{n-1} A^0) \bmod M

The function computes a hash value of a string consisting of the characters c0,c1,,cn1c_0,c_1,\dots,c_{n-1}. Each character is in the range az, and the characters have been coded so that a is 00, b is 11 etc.. The function involves two constants with the values A=23A=23 and M=232M=2^{32}.

For example, when the string is kissa, the function evaluates to

(10234+8233+18232+18231+0230)mod232=2905682. (10 \cdot 23^4 + 8 \cdot 23^3 + 18 \cdot 23^2 + 18 \cdot 23^1 + 0 \cdot 23^0) \bmod 2^{32} = 2905682.

In a file hashing.py, implement the function hash_value that returns the hash value of the string given as a parameter.

def hash_value(string):
    # TODO

if __name__ == "__main__":
    print(hash_value("abc")) # 25
    print(hash_value("kissa")) # 2905682
    print(hash_value("aybabtu")) # 154753059
    print(hash_value("tira")) # 235796
    print(hash_value("zzzzzzzzzz")) # 2739360440