Time

12:37:51
23 May 2012
Version for print

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.


Specifications

   Input

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

   
Output

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


Problem information

Time Limit: 0.1 seconds
Memory Limit: 64 MB
Balls for the passed test: 10
Complexity: 23% 582/760
Autor: Prysiazhnyuk A.
Classes: Number theory

Example

Example input

2 4 7 3

Example output

28


← Green spot Problems The number of units →