PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000147. Đếm chuỗi con chia hết (Divisible Substring)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm chuỗi con chia hết (Divisible Substring)

Divisible Substring

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Takahashi has a decimal digit string SS of length NN and a prime number PP. For each pair 1≤L≤R≤N1\le L\le R\le N, consider the contiguous substring SL…SRS_L\ldots S_R as a base-10 integer.

Count the pairs (L,R)(L,R) whose integer value is divisible by PP. Leading zeros are allowed. Substrings at different positions count separately, even if they have the same contents or numeric value.

Input

The first line contains N,PN,P. The next line contains exactly NN characters of S, each a digit from 0 to 9.

Output

Print the number of qualifying contiguous substrings.

Subtasks

  • Subtask 1 (20 points): 1≤N≤601 \le N \le 60; 2≤P≤1002 \le P \le 100; PP is prime.
  • Subtask 2 (30 points): 1≤N≤50001 \le N \le 5000; 2≤P≤9972 \le P \le 997; PP is prime.
  • Subtask 3 (50 points): 1≤N≤2⋅1051 \le N \le 2\cdot 10^5; 2≤P≤1042 \le P \le 10^4; PP is prime.

Examples

Input

4 3
3543

Output

6

Explanation

The ten nonempty substrings are 3, 35, 354, 3543, 5, 54, 543, 4, 43, 3. Exactly six are divisible by 33: the first 3, 354, 3543, 54, 543, and the last 3.