Bits Generator

No attempts yetTime limit3sMemory limit64 MB

Problem

A pseudorandom bit generator keeps an integer state zz with 0z<m0 \le z < m. When the machine is switched on, the state is set to some integer in [0,m1][0, m-1]; this starting value is called the seed. Each time a bit is requested, the generator first updates its state and then returns a bit, using three fixed integer constants aa, cc, and kk:

z := floor((z * a + c) / k) mod m
if z < floor(m / 2):
    return 0
else:
    return 1

The generator was queried nn times, producing a bit sequence b1,b2,,bnb_1, b_2, \ldots, b_n. Given the constants and this sequence, determine how many of the possible seeds could have produced exactly this sequence.

Input

The first line contains five integers aa, cc, kk, mm, and nn, with 0a,c<m0 \le a, c < m, 1k<m1 \le k < m, 2m1062 \le m \le 10^6, and 1n1051 \le n \le 10^5.

The second line contains a string of exactly nn characters, each 0 or 1; the ii-th character is the bit bib_i.

Output

Print a single integer: the number of seeds zz with 0z<m0 \le z < m that could have been the initial state, i.e. that produce exactly the given bit sequence.