You are given two integer arrays of size 2: d = [d1, d2] and r = [r1, r2].

Two delivery drones are tasked with completing a specific number of deliveries. Drone i must complete di deliveries.

Each delivery takes exactly one hour and only one drone can make a delivery at any given hour.

Additionally, both drones require recharging at specific intervals during which they cannot make deliveries. Drone i must recharge every ri hours (i.e. at hours that are multiples of ri).

Return an integer denoting the minimum total time (in hours) required to complete all deliveries.

 

Example 1:

Input: d = [3,1], r = [2,3]

Output: 5

Explanation:

Example 2:

Input: d = [1,3], r = [2,2]

Output: 7

Explanation:

Example 3:

Input: d = [2,1], r = [3,4]

Output: 3

Explanation:

 

Constraints: