Under construction

Still being built. Things may change

Number of solutions

Time limit1sMemory limit256 MB

Summary
Count the integer pairs (x, y) inside the given x and y ranges that satisfy Ax + By + C = 0.
Level

Medium5 of 10

Topics
Number theory, Math
Solved
No attempts yet

Problem

Write a program that counts the integer solutions of the equation Ax+By+C=0Ax + By + C = 0.

AA, BB, CC, xx, and yy are all integers. Count the integer pairs (x,y)(x, y) that satisfy the equation with x1≤x≤x2x_1 \le x \le x_2 and y1≤y≤y2y_1 \le y \le y_2.

If AA, BB, and CC are all 00, every integer pair inside the given ranges is a solution.

Input

The first line contains AA, BB, CC, x1x_1, x2x_2, y1y_1, y2y_2, separated by spaces. Every value is an integer between −108-10^8 and 10810^8, and x1≤x2x_1 \le x_2, y1≤y2y_1 \le y_2.

Output

Print the number of solutions on the first line. The count can exceed the range of a 32-bit integer.

Examples4

  1. Example 1

    Input
    1 1 1 -20 20 -30 30
    
    Expected output
    41
    
  2. Example 2

    Input
    20 30 40 50 60 70 80
    
    Expected output
    0
    
  3. Example 3

    Input
    -100 20 300 -100 200 -2000 3000
    
    Expected output
    301
    
  4. Example 4

    Input
    -10 8 4 -100 100 -200 300
    
    Expected output
    50