#P3589. [POI 2015 R2] 快速阅读课程 Speed reading course

[POI 2015 R2] 快速阅读课程 Speed reading course

Description

Given n,a,b,pn,a,b,p, where nn and aa are coprime.

Define a binary string c0c1cn1c_0 c_1 \cdots c_{n-1} of length nn, where cic_i equals 00 if and only if (ai+b)modn<p(ai+b) \bmod n < p.

Given a binary string of length mm, count how many times the small string appears in the big string.

Input Format

The first line contains integers n,a,b,p,mn,a,b,p,m (2n1092\leq n\leq 10^9, 1p,a,b,m<n1\le p,a,b,m<n, 1m1061\le m\le 10^6). It is guaranteed that nn and aa are coprime.

The second line contains a binary string of length mm.

Output Format

Output a single integer, the number of occurrences of the small string in the big string.

9 5 6 4 3
101

3

Hint

Bold Sample Explanation


Original title: Kurs szybkiego czytania.

Translated by ChatGPT 5