| ps | |
|---|---|
| 링크 | acmicpc.net/… | 
| 출처 | BOJ | 
| 문제 번호 | 15829 | 
| 문제명 | Hashing | 
| 레벨 | 브론즈 2 | 
| 분류 | 
 기초  | 
	
| 시간복잡도 | O(n) | 
| 인풋사이즈 | n<=50 | 
| 사용한 언어 | Python | 
| 제출기록 | 29200KB / 72ms | 
| 최고기록 | 56ms | 
| 해결날짜 | 2021/10/13 | 
"""Solution code for "BOJ 15829. Hashing".
- Problem link: https://www.acmicpc.net/problem/15829
- Solution link: http://www.teferi.net/ps/problems/boj/15829
"""
R = 31
M = 1234567891
def main():
    L = int(input())  # pylint: disable=unused-variable
    s = input()
    h = 0
    ch_map = {ch: i for i, ch in enumerate('abcdefghijklmnopqrstuvwxyz', 1)}
    for ch in reversed(s):
        h = (h * R + ch_map[ch]) % M
    print(h)
if __name__ == '__main__':
    main()