402797: GYM100883 H tourists

Memory Limit:24 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. touriststime limit per test2 secondsmemory limit per test24 megabytesinputstandard inputoutputstandard output

On one of the Caribbean Islands there are N tourists and you want to move them from this island to another one.

There are only two boats on this island, the first one can hold n1 tourists and cost c1 to move exactly n1 tourists from one Island to another, and the second one can hold n2 and cost c2.

The boat will not sail unless it is fully booked. Moreover, you want to minimize the total cost of moving all tourists from one island to another. You can use any boat several times.

Input

The input may contain multiple test cases. Each test case begins with a line containing an integer N (1 ≤ N ≤ 2 * 109).

The second line contains c1 and n1, and the third line contains c2 and n2.

Here, c1, c2, n1 and n2 are all positive integers having values smaller than 2 * 109.

A test case containing a zero for N in the first line terminates the input.

Output

For each test case in the input, print a line containing the minimum cost solution: two non-negative integers m1 and m2, where m1 is the number of times to use the first boat, and m2 is the number of times to use the second boat) if one exists.

Print "failed" otherwise. If a solution exists, you may assume that it is unique.

ExamplesInput
43
1 3
2 4
40
5 9
5 12
0
Output
13 1
failed

加入题单

算法标签: