favorite We need a little bit of your help to keep things running, click on this banner to learn more

Competitors’ quantity of olimpia

Competitors’ quantity of olimpia

How we know for question how many pupils he has Greek scientist Pifagor answer: “One half of my pupils learn math, the fourth parts learns nature, the seventh part spend time in thinking, the last part is three girls”.
For question “How many competitors’ quantity of olimpiad from computer science registered?”. The secretary of olimpiad answer like Pifagor: "K part of boys start solves first problem, M part – start solves sec-ond problem and N part – start solves third problem. In that time D competitors’ decide a problem: "How to start?". Your task is find the competitors’ quantity of olimpiad S, or write -1, if secretary wrongs in his message.


In a single line through the gap in the number of K, N, M, D. 1K, N, M, D1000.


Output the number of participants Olympiad S, or -1 if the Secretary was mistaken in his report.

Time limit 1 seconds
Memory limit 64 MiB
Input example #1
2 4 7 3
Output example #1
Author Prysiazhnyuk A.