Inequality

Time limit1sMemory limit128 MB

Summary
Count integer triples X, Y, Z with fixed denominators B, C, D that keep a chain of four strict fraction inequalities between two given bounds true.
Level

Medium4 of 10

Topics
Math, Brute force, Implementation
Solved
No attempts yet

Problem

Choose three positive integers X, Y, and Z for the question marks so that all parts of the inequality hold.

A1A2<XB<YC<ZD<E1E2\frac{A_1}{A_2} < \frac{X}{B} < \frac{Y}{C} < \frac{Z}{D} < \frac{E_1}{E_2}

Find the number of ordered triples (X, Y, Z) that satisfy the inequality.

Input

The first line contains B, C, and D. (1 <= B, C, D <= 1000)

The second line contains A1 and A2. (1 <= A1, A2 <= 1000)

The third line contains E1 and E2. (1 <= E1, E2 <= 1000)

Output

Print the number of ordered triples (X, Y, Z) of positive integers that satisfy the inequality.

Hint

Every inequality is strict. A choice where two neighboring fractions have the same value does not satisfy the condition.

Examples3

  1. Example 1

    Input
    3 2 4
    2 7
    4 5
    
    Expected output
    1
    
  2. Example 2

    Input
    5 5 5
    999 1
    1000 1
    
    Expected output
    4
    
  3. Example 3

    Input
    1 9 7
    14 5
    10 3
    
    Expected output
    3