Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

D. Two Arithmetic Progressions

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given two arithmetic progressions: *a*_{1}*k* + *b*_{1} and *a*_{2}*l* + *b*_{2}. Find the number of integers *x* such that *L* ≤ *x* ≤ *R* and *x* = *a*_{1}*k*' + *b*_{1} = *a*_{2}*l*' + *b*_{2}, for some integers *k*', *l*' ≥ 0.

Input

The only line contains six integers *a*_{1}, *b*_{1}, *a*_{2}, *b*_{2}, *L*, *R* (0 < *a*_{1}, *a*_{2} ≤ 2·10^{9}, - 2·10^{9} ≤ *b*_{1}, *b*_{2}, *L*, *R* ≤ 2·10^{9}, *L* ≤ *R*).

Output

Print the desired number of integers *x*.

Examples

Input

2 0 3 3 5 21

Output

3

Input

2 4 3 0 6 17

Output

2

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/23/2017 21:06:05 (c3).

Desktop version, switch to mobile version.

User lists

Name |
---|