#MTHA0000011. Số có số dư cho trước (Numbers with a Given Remainder)

Số có số dư cho trước (Numbers with a Given Remainder)

Numbers with a Given Remainder

Version: Phuoc Hung OJ Extended

Problem Statement

Given integers L,R,M,rL,R,M,r with L≤RL\le R and 0≤r<M0\le r<M, count the integers XX in [L,R][L,R] such that X≡r(modM)X\equiv r\pmod M.

Input

One line contains four integers LL, RR, MM, and rr.

Output

Print the number of integers satisfying the condition.

Subtasks

  • Subtask 1 (30 points):
    • 1≤L≤R≤1061 \le L \le R \le 10^6.
    • 1≤M≤10181 \le M \le 10^{18}.
    • 0≤r<M0 \le r < M.
  • Subtask 2 (70 points):
    • 1≤L≤R≤10181 \le L \le R \le 10^{18}.
    • 1≤M≤10181 \le M \le 10^{18}.
    • 0≤r<M0 \le r < M.

Examples

Example 1

Input

1 20 5 2

Output

4

Explanation

The integers with remainder 22 modulo 55 are 2,7,12,172,7,12,17, so the answer is 44.

Example 2

Input

1 20 5 0

Output

4

Explanation

Remainder 00 corresponds to multiples 5,10,15,205,10,15,20, giving 44 integers.

Example 3

Input

8 8 10 8

Output

1

Explanation

The interval contains only 88, and 8 mod 10=88\bmod10=8, so exactly one integer is valid.