Data Transfer#172

Data Transfer

2 seconds
64 megabytes
Hard

There are two computers. You need to transfer megabytes of data from one computer to the other. Two USB drives are available, with capacities V_1 and V_2 megabytes. The reading and writing speeds for each drive are R_1, R_2 and W_1, W_2 megabytes per second, respectively.

Each drive has the following property: reading or writing operations take an integer number of seconds. In particular, even if the remaining data to process at the source or destination is less than what can be handled in one second, the operation still takes one whole second. Each computer has only one USB port, so at any moment, you can either copy data from the computer to one of the drives or read data from a drive and write it to the computer. Swapping drives takes zero time. Find the minimum time required to transfer all the data from one computer to the other.

Input

The first line of the input contains a single integer — the volume of data to transfer.

The next two lines each contain three integers, describing the parameters of each drive in the order: V_1, R_1, W_1 for the first, and V_2, R_2, W_2 for the second.

All numbers are integers between and , inclusive.

Output

Output a single integer — the minimum number of seconds required to transfer the specified volume of data.

Examples

Example 1

Loading
Loading