Difficult times
Due to recent layoffs in the IT sector, Petro decided to evaluate his productivity. Petro is a consistent worker who completes one task per day. However, he works a specific schedule, working days followed by days off (i.e. he works for consecutive working days and then takes days off).
Petro, who is a proponent of random rest theory, doesn't work every th day, regardless of whether it is a working day or a day off. However, to compensate for this, he works twice as effectively every th day (if he is working), meaning he completes two tasks per day instead of just one.
Evaluate Petro's monthly productivity (number of tasks he completes) assuming the month has days and starts on the first working day.
Input
The input consists of five integers and .
Output
Output a single integer - Petro's productivity.
Examples
Note
In the first example, Petro works for the first three days, but doesn't work on the third day because . The fourth day is scheduled as a day off and the fifth day is a working day for Petro. Since and there are only days in the month, Petro doesn't work twice as effectively for any day. Therefore, Petro works for three days at a regular pace, completing three tasks.
In the second example, Petro works for days and takes days off in a cycle, and takes an additional random day off. Since , all the days in the month are working days according to the cycle, as the month ends before there is a scheduled day off. We also know that , so every third day is a day of double efficiency. Petro works at a regular pace and completes two tasks on the first and second days, works twice as efficiently and completes two tasks on the third day, then works at a regular pace and completes two tasks on the fourth and fifth days. Therefore, Petro completes tasks this month.