[email protected] High School Programming Competition 2019

Start

2019-04-13 08:00 AKDT

[email protected] High School Programming Competition 2019

End

2019-04-13 12:30 AKDT
The end is near!
Contest is over.
Not yet started.
Contest is starting in -1133 days 17:54:00

Time elapsed

4:30:00

Time remaining

0:00:00

Problem C
Classrooms and Calculators

You’re trying to organize a group of yourself and $3$ friends to play a campaign of your favorite tabletop game, Classrooms & Calculators. Your schedule is free every day, but your friends all have some scheduling conflicts. Let today be day $0$, tomorrow be day $1$, etc. Your first friend can’t play today or every $d_1$ days after today, your second friend can’t play today or every $d_2$ days after today, and your third friend can’t play today or every $d_3$ days after today. You can only play on a day if nobody has a conflict, and you always play on days with no conflicts. For example, if $d_1 = 3$, $d_2 = 4$, and $d_3 = 5$, in the first $10$ days you would play on days $1$, $2$, and $7$, but not on days $0$, $3$, $4$, $5$, $6$, $8$, $9$, and $10$.

Your campaign’s Classroom Teacher has told you that it will take $n$ days of playing to complete the campaign; can you determine the number of the day you finish the campaign?

Input

The first line of the input contains the values of $d_1, d_2$, and $d_3$ (each between $2$ and $50$, inclusive), each separated by a single space, describing your friends’ schedule conflicts. The second line contains $n$, the number of days you will need to play on to complete the campaign $(1 \le n \le 5\cdot 10^8)$.

You are guaranteed that the values of $d_1$, $d_2$, and $d_3$ are such that you can complete the campaign in finite time.

Output

You should output a single number, the number of the day on which you finish the campaign.

Sample Input 1 Sample Output 1
5 7 9
1
1
Sample Input 2 Sample Output 2
2 3 4
7
19