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

#SP0000207. Chữ số 0 cuối của tổ hợp nhân lũy thừa (Trailing Zeroes (II))

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chữ số 0 cuối của tổ hợp nhân lũy thừa (Trailing Zeroes (II))

Trailing Zeroes (II)

Source: LightOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given positive integers n,r,p,qn,r,p,q with r≤nr\le n, consider

$$A=C(n,r)\cdot p^q,\qquad C(n,r)=\frac{n!}{r!(n-r)!}.$$

Find the number of trailing zero digits in the decimal representation of AA. The integer AA may be too large to store directly; only its trailing-zero count is required.

Input

The only line contains four integers n,r,p,qn,r,p,q in that order.

Output

Print one integer: the number of trailing zeros of AA.

Subtasks

  • Subtask 1 (20 points): 1≤r≤n≤1001\le r\le n\le 100; 1≤p,q≤1001\le p,q\le 100.
  • Subtask 2 (30 points): 1≤r≤n≤1041\le r\le n\le 10^4; 1≤p,q≤1041\le p,q\le 10^4.
  • Subtask 3 (50 points): 1≤r≤n≤1061\le r\le n\le 10^6; 1≤p,q≤1061\le p,q\le 10^6.

Examples

Input

10 4 1 1

Output

1

Explanation

C(10,4)=210C(10,4)=210 and 11=11^1=1, so A=210A=210. Its decimal representation has one trailing zero. Equivalently, C(10,4)C(10,4) provides at least one factor 22 and exactly one factor 55, while 111^1 adds no prime factors.