301970: CF374A. Inna and Pink Pony

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Inna and Pink Pony

题意翻译

已知一块 n×m 的棋盘和两个数字 a 和 b。有一块放在棋盘上的位置(i,j)上的糖果。你需要把糖果移动到棋盘的一个角,只能能进行以下类型的操作: 1. 将糖果的位置(x,y)移动到位置(x-a,y-b); 1. 将糖果的位置(x,y)移动到位置(x+a,y-b); 1. 将糖果的位置(x,y)移动到位置(x-a,y+b); 1. 将糖果的位置(x,y)移动到位置(x+a,y+b)。 同时也不允许把糖果移到棋盘边界之外。 求糖果从初始位置(i,j)移动到棋盘的一个角所需执行的最小允许操作数。

题目描述

Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an $ n×m $ chessboard, a very tasty candy and two numbers $ a $ and $ b $ . Dima put the chessboard in front of Inna and placed the candy in position $ (i,j) $ on the board. The boy said he would give the candy if it reaches one of the corner cells of the board. He's got one more condition. There can only be actions of the following types: - move the candy from position $ (x,y) $ on the board to position $ (x-a,y-b) $ ; - move the candy from position $ (x,y) $ on the board to position $ (x+a,y-b) $ ; - move the candy from position $ (x,y) $ on the board to position $ (x-a,y+b) $ ; - move the candy from position $ (x,y) $ on the board to position $ (x+a,y+b) $ . Naturally, Dima doesn't allow to move the candy beyond the chessboard borders. Inna and the pony started shifting the candy around the board. They wonder what is the minimum number of allowed actions that they need to perform to move the candy from the initial position $ (i,j) $ to one of the chessboard corners. Help them cope with the task!

输入输出格式

输入格式


The first line of the input contains six integers $ n,m,i,j,a,b $ $ (1<=n,m<=10^{6}; 1<=i<=n; 1<=j<=m; 1<=a,b<=10^{6}) $ . You can assume that the chessboard rows are numbered from 1 to $ n $ from top to bottom and the columns are numbered from 1 to $ m $ from left to right. Position $ (i,j) $ in the statement is a chessboard cell on the intersection of the $ i $ -th row and the $ j $ -th column. You can consider that the corners are: $ (1,m) $ , $ (n,1) $ , $ (n,m) $ , $ (1,1) $ .

输出格式


In a single line print a single integer — the minimum number of moves needed to get the candy. If Inna and the pony cannot get the candy playing by Dima's rules, print on a single line "Poor Inna and pony!" without the quotes.

输入输出样例

输入样例 #1

5 7 1 3 2 2

输出样例 #1

2

输入样例 #2

5 5 2 3 1 1

输出样例 #2

Poor Inna and pony!

说明

Note to sample 1: Inna and the pony can move the candy to position $ (1+2,3+2)=(3,5) $ , from there they can move it to positions $ (3-2,5+2)=(1,7) $ and $ (3+2,5+2)=(5,7) $ . These positions correspond to the corner squares of the chess board. Thus, the answer to the test sample equals two.

Input

题意翻译

已知一块 n×m 的棋盘和两个数字 a 和 b。有一块放在棋盘上的位置(i,j)上的糖果。你需要把糖果移动到棋盘的一个角,只能能进行以下类型的操作: 1. 将糖果的位置(x,y)移动到位置(x-a,y-b); 1. 将糖果的位置(x,y)移动到位置(x+a,y-b); 1. 将糖果的位置(x,y)移动到位置(x-a,y+b); 1. 将糖果的位置(x,y)移动到位置(x+a,y+b)。 同时也不允许把糖果移到棋盘边界之外。 求糖果从初始位置(i,j)移动到棋盘的一个角所需执行的最小允许操作数。

加入题单

上一题 下一题 算法标签: