l = input() Hash = 0 ri = 1 M = 1234567891 for c in input() : Hash = (Hash + ((((ord(c) - ord('a') + 1)%M)*ri)%M))%M ri = ri*31%M print(Hash)