{"raw_statement":[{"iden":"statement","content":"Consider a [billiard table](https://en.wikipedia.org/wiki/Billiard_table) of rectangular size $n \\times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture).\n\n<center>![image](https://espresso.codeforces.com/1278b0652a516f7e5e847d16eb4c972c985b645f.png)</center>There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $45^{\\circ}$ angle with them. We will assume that:\n\n1.  the angles between the directions of the ball before and after a collision with a side are equal,\n2.  the ball moves indefinitely long, it only stops when it falls into a pocket,\n3.  the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets,\n4.  initially the ball is not in a pocket.\n\nNote that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side.\n\nYour task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be."},{"iden":"input","content":"The only line contains $6$ integers $n$, $m$, $x$, $y$, $v_x$, $v_y$ ($1 \\leq n, m \\leq 10^9$, $0 \\leq x \\leq n$; $0 \\leq y \\leq m$; $-1 \\leq v_x, v_y \\leq 1$; $(v_x, v_y) \\neq (0, 0)$) — the width of the table, the length of the table, the $x$\\-coordinate of the initial position of the ball, the $y$\\-coordinate of the initial position of the ball, the $x$\\-component of its initial speed and the $y$\\-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket."},{"iden":"output","content":"Print the coordinates of the pocket the ball will fall into, or $-1$ if the ball will move indefinitely."},{"iden":"examples","content":"Input\n\n4 3 2 2 -1 1\n\nOutput\n\n0 0\n\nInput\n\n4 4 2 0 1 1\n\nOutput\n\n\\-1\n\nInput\n\n10 10 10 1 -1 0\n\nOutput\n\n\\-1"},{"iden":"note","content":"The first sample:\n\n<center>![image](https://espresso.codeforces.com/262698bb300f5e7673bc42c11b1a19d34eef6158.png)</center>The second sample:\n\n<center>![image](https://espresso.codeforces.com/1e952f6306dff68d2e4a97cc46c55ccf856d044d.png)</center>In the third sample the ball will never change its $y$ coordinate, so the ball will never fall into a pocket."}],"translated_statement":[{"iden":"statement","content":"考虑一个尺寸为 $n \\times m$ 的矩形台球桌，有四个袋口。我们建立一个坐标系，原点位于左下角（见图）。 \n\n当前有一个球位于点 $(x, y)$。Max 来到台球桌并击打该球，球开始沿平行于坐标轴或与坐标轴成 $45^\\circ$ 角的直线运动。我们假设：\n\n注意，如果球沿某条边运动，则球将直接落入该边末端的袋口中。\n\n你的任务是确定球是否最终会落入某个袋口，如果会，是哪一个袋口。\n\n输入仅一行包含 $6$ 个整数 $n$, $m$, $x$, $y$, $v_x$, $v_y$（$1 \\leq n, m \\leq 10^9$，$0 \\leq x \\leq n$；$0 \\leq y \\leq m$；$-1 \\leq v_x, v_y \\leq 1$；$(v_x, v_y) \\neq (0, 0)$）——分别表示台球桌的宽度、长度、球的初始位置的 $x$ 坐标、$y$ 坐标、初始速度的 $x$ 分量和 $y$ 分量。保证球初始时不在袋口中。\n\n请输出球将落入的袋口的坐标，若球将无限运动则输出 $-1$。\n\n第一个样例： \n\n第二个样例： \n\n在第三个样例中，球的 $y$ 坐标永远不会改变，因此球将永远不会落入袋口。\n\n"},{"iden":"input","content":"The only line contains $6$ integers $n$, $m$, $x$, $y$, $v_x$, $v_y$ ($1 \\leq n, m \\leq 10^9$, $0 \\leq x \\leq n$; $0 \\leq y \\leq m$; $-1 \\leq v_x, v_y \\leq 1$; $(v_x, v_y) \\neq (0, 0)$) — the width of the table, the length of the table, the $x$-coordinate of the initial position of the ball, the $y$-coordinate of the initial position of the ball, the $x$-component of its initial speed and the $y$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket."},{"iden":"output","content":"Print the coordinates of the pocket the ball will fall into, or $-1$ if the ball will move indefinitely."},{"iden":"examples","content":"输入\n4 3 2 2 -1 1\n输出\n0 0\n\n输入\n4 4 2 0 1 1\n输出\n-1\n\n输入\n10 10 10 1 -1 0\n输出\n-1"},{"iden":"note","content":"第一个样例：   第二个样例：   在第三个样例中，球的 $y$ 坐标永远不会改变，因此球将永远不会落入袋口。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ denote the width and height of the rectangular billiard table.  \nLet $ (x, y) \\in [0, n] \\times [0, m] $ denote the initial position of the ball, with $ (x, y) \\notin \\{(0,0), (0,m), (n,0), (n,m)\\} $.  \nLet $ (v_x, v_y) \\in \\{-1, 0, 1\\}^2 \\setminus \\{(0,0)\\} $ denote the initial velocity vector, with components restricted to $ \\{-1, 0, 1\\} $.\n\nThe four pockets are located at:  \n- $ P_1 = (0, 0) $ — bottom-left  \n- $ P_2 = (n, 0) $ — bottom-right  \n- $ P_3 = (0, m) $ — top-left  \n- $ P_4 = (n, m) $ — top-right  \n\n**Constraints**  \n1. $ 1 \\leq n, m \\leq 10^9 $  \n2. $ 0 \\leq x \\leq n $, $ 0 \\leq y \\leq m $  \n3. $ v_x, v_y \\in \\{-1, 0, 1\\} $, $ (v_x, v_y) \\neq (0, 0) $  \n4. The ball is not initially in a pocket.\n\n**Objective**  \nDetermine whether the ball, moving with constant velocity $ (v_x, v_y) $ and reflecting elastically off the walls (i.e., reversing the appropriate velocity component upon hitting a wall), eventually falls into one of the four pockets.  \n\nIf yes, output the coordinates of the pocket $ (p_x, p_y) \\in \\{ (0,0), (n,0), (0,m), (n,m) \\} $ it enters.  \nIf the ball moves indefinitely without entering any pocket, output $ -1 $.\n\n**Key Insight**  \nThe motion is constrained to discrete directions: horizontal, vertical, or diagonal ($ \\pm 45^\\circ $).  \n- If $ v_x = 0 $ and $ v_y \\neq 0 $: ball moves vertically — falls into pocket only if $ x = 0 $ or $ x = n $ (but initial position is not in pocket, so never).  \n- If $ v_y = 0 $ and $ v_x \\neq 0 $: ball moves horizontally — falls into pocket only if $ y = 0 $ or $ y = m $ (again, initial position not in pocket, so never).  \n- If $ |v_x| = |v_y| = 1 $: ball moves diagonally — use unfolding method: simulate reflections by tiling the plane with mirrored tables. The ball falls into a pocket iff there exists $ t > 0 $ such that:  \n  $$\n  x + v_x t = a n, \\quad y + v_y t = b m\n  $$\n  for some integers $ a, b \\in \\{0, 1\\} $, corresponding to pocket coordinates.  \n  Solve for $ t $:  \n  $$\n  t = \\frac{a n - x}{v_x} = \\frac{b m - y}{v_y}\n  $$\n  and check if a common positive $ t $ exists with $ a \\in \\{0,1\\}, b \\in \\{0,1\\} $, and the resulting point is a pocket.  \n  Since $ v_x, v_y = \\pm 1 $, this reduces to checking 4 possible combinations of $ a, b \\in \\{0,1\\} $ for consistency.","simple_statement":null,"has_page_source":false}