Олимпиадный тренинг

Задача 38258. Stew


Summer was approaching, and Igor, Gena and Denis decided to go camping together, just like last year. Almost all issues have already been resolved: the route has already been worked out, train tickets have been bought, a four-seater tent has been found in Denis’s closet, and under Igor’s bed — axe. It remains only to solve the issue with the products.

Last year, the guys honestly admitted that they did not know how much food they needed, and asked their classmate Nastya to help, who made a shopping list for them. But this year, asking her again is somehow undignified. One could look at how much they bought last year and take the same amount, but none of the guys had any receipts or a grocery list.

But they still have correspondence on the social network, where they argued over who would carry how many cans of stew. In this correspondence, Igor first suggested dividing the whole canned meat in relation to a: b: c, so that Igor himself would bear the first part, the second — Gena, and the third — Denis. But Denis did not like it, and he suggested changing the ratio to d: e: f.

After some more thinking, the guys realized that they still wouldn’t cut the cans of stew, and, therefore, both ratios were chosen so that each in both cases got an integer number of cans.

Given two ratios a: b: c and d: e: f, calculate how many cans of stew the guys bought for last year's trip. From all possible answers print the minimum. The guys remember that they definitely had at least one can of stew.

Input
The first line contains three positive integers a, b, c separated by spaces. The second line contains three positive integers d, e, f, also separated by spaces.

All numbers are less than 1000.

Imprint
Print a positive integer — number of cans of stew.
 
Examples
# Input Output Explanations
1 10 3 7
3 1 1
20 When dividing the stew between the guys in a ratio of 10:3:7, Igor will incur 10 cans, Gena — 3 cans, and Denis — 7 cans. And in the case of a ratio of 3:1:1, Igor will get 12 cans, and Genya and Denis will get 4 each.