{"raw_statement":[{"iden":"statement","content":"On one of the Caribbean Islands there are N tourists and you want to move them from this island to another one. \n\nThere 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. \n\nThe 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.\n\nThe input may contain multiple test cases. Each test case begins with a line containing an integer N (1 ≤ N ≤ 2 * 109). \n\n The second line contains c1 and n1, and the third line contains c2 and n2. \n\nHere, c1, c2, n1 and n2 are all positive integers having values smaller than 2 * 109. \n\nA test case containing a zero for N in the first line terminates the input.\n\nFor 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. \n\nPrint \"failed\" otherwise. If a solution exists, you may assume that it is unique.\n\n"},{"iden":"input","content":"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."},{"iden":"output","content":"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."},{"iden":"examples","content":"Input431 32 4405 95 120Output13 1failed"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ N \\in \\mathbb{Z} $ be the number of vertices of a convex polygon, and $ Q \\in \\mathbb{Z} $ the number of queries.  \nLet $ P = (p_0, p_1, \\dots, p_{N-1}) $ be the sequence of polygon vertices in counter-clockwise order, where $ p_i = (x_i, y_i) \\in \\mathbb{R}^2 $.  \nFor each query $ q \\in \\{1, \\dots, Q\\} $, let $ (l, k) \\in \\{0, \\dots, N-1\\} \\times \\mathbb{Z}^+ $ denote:  \n- $ l $: index of the left endpoint of the magical base edge,  \n- $ r = (l + 1) \\bmod N $: index of the right endpoint (since edges are consecutive in CCW order),  \n- $ k $: horizontal distance from the origin along the magical base (x-axis after rotation) where the vertical wand is initially placed.\n\n**Constraints**  \n1. $ 3 \\leq N \\leq 10^5 $, $ 1 \\leq Q \\leq 10^5 $  \n2. $ -10^9 \\leq x_i, y_i \\leq 10^9 $ for all $ i \\in \\{0, \\dots, N-1\\} $  \n3. $ 1 \\leq k \\leq 10^9 $ for each query  \n4. For each query, $ k > x' $, where $ x' $ is the maximum x-coordinate of any vertex **after rotating the polygon so that edge $ (p_l, p_r) $ lies on the positive x-axis with $ p_l $ at the origin**.\n\n**Objective**  \nFor each query $ (l, k) $:  \n1. Rotate the polygon such that:  \n   - $ p_l \\mapsto (0, 0) $,  \n   - $ p_r \\mapsto (d, 0) $ for some $ d > 0 $,  \n   - The entire polygon is rotated rigidly around $ p_l $ to align edge $ (p_l, p_r) $ with the positive x-axis.  \n2. Place a vertical wand at $ x = k $ in this rotated coordinate system.  \n3. Find all polygon edges intersected by the line $ x = k $.  \n4. Output the indices (in original polygon indexing) of:  \n   - The single vertex if the wand hits a vertex (i.e., $ k $ aligns with a rotated x-coordinate of a vertex),  \n   - Or the two endpoints of the edge intersected (in CCW order: lower-indexed vertex first, then next in CCW order).  \n\n**Note**: The wand falls counter-clockwise — meaning it sweeps upward from the base — but since it is vertical and fixed at $ x = k $, the intersection is static. The phrase \"falls counter-clockwise\" implies the wand is aligned perpendicular to the base and extends upward from the base; we seek its first intersection with the polygon above the base. However, given $ k > x' $, and the polygon is convex, the wand intersects exactly one edge (or possibly a vertex) above the base. The problem states the wand hits the polygon — we assume it means the first (lowest) intersection point(s) along the vertical line $ x = k $ in the rotated frame.\n\nThus, after rotation, compute the intersection of the vertical line $ x = k $ with the polygon boundary, and return the original indices of the intersected point(s).","simple_statement":"A convex polygon has N points in counter-clockwise order. For each festival, one edge (pl, pr) is placed on the x-axis with pl at origin and pr to the right. A vertical wand at distance k from origin (k > all x-coordinates) falls counter-clockwise until it hits the polygon. Find the point(s) where the wand hits. Output the index of the hit point if it hits a vertex, or the two indices of the edge if it hits along an edge.","has_page_source":false}