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

#SP0000219. Đếm số nguyên tố từ mẫu chữ số (Counting dhprime)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm số nguyên tố từ mẫu chữ số (Counting dhprime)

Counting dhprime

Source: LQDOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Turtle has a string SS containing digits 0 through 9 and the wildcard ?. Each occurrence of ? can be replaced independently with any decimal digit, while every fixed digit is preserved.

After all replacements, the resulting string must represent a valid integer: the first character cannot be 0. Count the replacements that produce a prime number. The positions and order of characters remain unchanged.

Input

One line containing the string SS, consisting only of digits 0 through 9 and ?.

Output

Print one integer: the number of wildcard replacements producing a valid prime number.

Subtasks

  • Subtask 1 (20 points): 1≤∣S∣≤31\le |S|\le3; every character of SS is in {0,1,…,9,?}\{0,1,\ldots,9,?\}.

  • Subtask 2 (30 points): 1≤∣S∣≤51\le |S|\le5; every character of SS is in {0,1,…,9,?}\{0,1,\ldots,9,?\}.

  • Subtask 3 (50 points): 1≤∣S∣≤71\le |S|\le7; every character of SS is in {0,1,…,9,?}\{0,1,\ldots,9,?\}.

Examples

Input

1?

Output

4

Explanation

Replacing the second character by digits 00 to 99 produces 10,11,12,13,14,15,16,17,18,1910,11,12,13,14,15,16,17,18,19. Exactly 1111, 1313, 1717 and 1919 are prime. The first digit is always 1, so all four prime-valued replacements are valid. Thus the answer is 44.