MLE '19 Contest 4 P7 - Desperate

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 256M

Problem type

A string S consisting of N lowercase latin characters is hashed using the following method:

\displaystyle hash(S) = \displaystyle \left( \sum_{i=1}^N S_i \times B^i \right) \bmod P

S_i is the ASCII value of the i^\text{th} (one-indexed) character of string S. B and P are values given to you.

Given a string S, and integers B and P, can you calculate hash(S)?

Input Specification

The first line will contain the integer N (1 \le N \le 10^5).

The second line will contain the string S of length N. S will only contain lowercase latin characters.

The third line will contain the integers B and P (1 \le B, P \le 10^9).

Output Specification

Output hash(S).

Sample Input

2 1

Sample Output



There are no comments at the moment.