AT_past18_c 信号
Description
There are two traffic lights, light $ 1 $ and light $ 2 $ . Light $ i $ $ (i=1,2) $ repeatedly shows green light for $ B_i $ seconds and red light for $ R_i $ seconds.
In other words, if light $ i $ turns from red to green at some point, it remains green for the next $ B_i $ seconds, and then remains red for the succeeding $ R_i $ seconds; this way, it alternates between green and red light indefinitely.
Now, the two lights have simultaneously turned from red to green.
Within the next $ T $ seconds, how many seconds do both light $ 1 $ and light $ 2 $ show green?
Input Format
The input is given from Standard Input in the following format:
> $ B_1 $ $ R_1 $ $ B_2 $ $ R_2 $ $ T $
Output Format
Print the duration, in seconds as an integer, for which both light $ 1 $ and light $ 2 $ show green within the $ T $ seconds right after the two lights simultaneously turn from red to green.
Explanation/Hint
### Sample Explanation 1
Within the $ 10 $ seconds right after the two traffic lights simultaneously turn from red to green, the lights transition as follows:
- From $ 0 $ to $ 2 $ seconds after the switch, both light $ 1 $ and light $ 2 $ are green.
- From $ 2 $ to $ 5 $ seconds after the switch, light $ 1 $ is red and light $ 2 $ is green.
- From $ 5 $ to $ 6 $ seconds after the switch, light $ 1 $ is green and light $ 2 $ is red.
- From $ 6 $ to $ 7 $ seconds after the switch, both light $ 1 $ and light $ 2 $ are green.
- From $ 7 $ to $ 10 $ seconds after the switch, light $ 1 $ is red and light $ 2 $ is green.
Therefore, both lights show green from $ 0 $ to $ 2 $ and from $ 6 $ to $ 7 $ seconds after the switch, for a total of $ 3 $ seconds.
### Sample Explanation 2
Both lights show green for $ 100 $ seconds, followed by red for $ 100 $ seconds; this sequence repeats indefinitely.
### Constraints
- $ 1\leq B_i,R_i\leq 100 $
- $ 1\leq T\leq 10^4 $
- All input values are integers.