#t291. 人生起伏
人生起伏
Biorhythms
Problem Background
Special for beginners, ^_^
Problem Description
Human beings are born with three physiological cycles: the physical, emotional, and intellectual cycles, whose lengths are , , and days respectively. Each cycle has one peak day, on which a person performs exceptionally well in that aspect. Because the three cycles have different lengths, their peaks usually do not fall on the same day. For each person, we want to know when the three peaks coincide. For each cycle we are given the number of days from the first day of the current year to a peak day (not necessarily the first peak). Your task is: given a day counted from the first day of the year, output the number of days from to the next time all three peaks coincide (excluding itself). For example, if the given time is and the next triple-peak is at , output (note this is not ).
Input Format
One line containing four integers: , and , separated by single spaces. indicate the days on which the physical, emotional, and intellectual peaks occur (counted from the first day of the year). is the given day, which may be smaller than , or . All given days are non-negative and not greater than , and the answer sought is not greater than .
Output Format
One integer: the number of days from the given day to the next triple-peak.
Sample Input
4 5 6 7
Sample Output
16994
Constraints
Time limit: 1s, memory limit: 1024KiB for each test case.