Олимпиадный тренинг

Задача 37669. Metro


At some cross-platform metro stations (like Tretyakovskaya, for example), trains from different directions come to different sides of the platform. Tanya agreed to meet her friend at such a station, but since her friend arrived from another time zone, she overslept because of the jet lag, and Tanya had to wait a long time for her. Trains always run exactly on schedule, and Tanya knows that the train stops on the platform for exactly one minute, and the interval between trains (the time when there is no train at the platform) is a minutes for trains on the first track and b  minutes for trains on the second track. That is, a train arrives on the first track and stops for one minute, then for a minutes there is no train at the platform, then for one minute the next train stops at the platform, etc.

While Tanya was standing on the platform, she counted n trains on the first track and m trains on the second track. Determine the minimum and maximum time that Tanya could spend on the platform, or report that she definitely lost count.

All the trains that Tanya saw, she watched for the whole minute, that is, Tanya does not come and go from the platform in the middle of the minute when the train is on the platform.

Input
The first line of the input contains a number a - the interval between trains on the first track. The second line contains the number b - the interval between trains on the second track. The third line contains the number n - the number of trains on the first track that Tanya saw. Fourth line
contains the number m - the number of trains on the second track that Tanya saw. All numbers are integers,
from 1 to 1000.

Imprint
The program should display two numbers: the minimum and maximum time in minutes that Tanya could stand on the platform, or one number -1 if Tanya was definitely mistaken.
 
Input Output
1
3
3
2
5 7
1
5
1
2
-1

Note: In the first example, trains run on the first track in 1 minute. On the second - after 3. Standing on the platform for 5, 6 or 7 minutes, Tanya could count 3 trains on the first track and 2 on the second.