eolymp
bolt
Try our new interface for solving problems
Problems

Fractional tricks

Fractional tricks

Boy Sergei really wants to learn how to juggle and do tricks. Recently, his friend showed him a trick - asked Sergei think a certain positive fraction, and then call it the denominator and the two fractions p1 / q1 and p2 / q2, such that p1 / q1 < a / b < p2 / q2, while among smaller fractions with the same denominator as that of the fractions, conceived Sergei. After that Seryozhin each guessed numerator ends, the hidden Sergei fractions.

Serge now he wants to learn to show this trick. Help him in this - write a program that finds the numerator ends, the hidden fraction.

Serge now he wants to learn to show this trick. Help him in this - write a program that finds the numerator ends, the hidden fraction.

Input

In separate lines three fractions are given in format numerator / denominator (p1 / q1, a / b, p2 / q2, where instead of a the question mark "?" is given. All numerators and denominators are positive integers and do not exceed 1000.

Output

Print the minimum number a / b, such that p1 / q1 < a / b < p2 / q2. If such fraction does not exist, output "-1" (without the quotes).

Time limit 1 second
Memory limit 128 MiB
Input example #1
1/2
?/8
3/4
Output example #1
5/8
Input example #2
3/20
?/2
4/10
Output example #2
-1
Source 2009 Цикл интернет-олимпиад для школьников. First olympiad, base level, September 19, Problem D