A. Inna and Pink Pony

time limit per test1 second
memory limit per test

256 megabytes

input

standard input

output

standard output

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!

Input

The first line of the input contains six integers n, m, i, j, a, b (1 ≤ n, m ≤ 106; 1 ≤ i ≤ n; 1 ≤ j ≤ m; 1 ≤ a, b ≤ 106).

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).

Output

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.

Examples

input

5 7 1 3 2 2

output

2

input

5 5 2 3 1 1

output

Poor Inna and pony!

Note

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.

 #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; int n, m, sx, sy, a, b; int main()
{
while(scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &a, &b) != EOF)
{
int ans;
if((sx==&&sy==)||(sx==&&sy==m)||(sx==n&&sy==)||(sx==n&&sy==m))
{
printf("0\n");
}else if((n-)<a || (m-)<b)
printf("Poor Inna and pony!\n");
else
{
int a1 = (sx-)/a;
int a2 = (sy-)/b;
int a3 = (m-sy)/b;
int a4 = (n-sx)/a;
bool fg = false;
if(a1*a==(sx-) && a2*b==(sy-))
{
int tmp = abs(a1-a2);
if(tmp%==)
{
ans = max(a1, a2);
fg = true;
}
}
if(a1*a==(sx-) && a3*b==(m-sy))
{
int tmp = abs(a1-a3);
if(tmp%== && max(a1, a3) < ans)
{
ans = max(a1, a3);
fg = true;
}
}
if(a2*b==(sy-) && a4*a==(n-sx))
{
int tmp = abs(a4-a2);
if(tmp%== && max(a4, a2) < ans)
{
ans = max(a4, a2);
fg = true;
}
}
if(a3*b==(m-sy) && a4*a==(n-sx))
{
int tmp = abs(a3-a4);
if(tmp%== && max(a3, a4) < ans)
{
ans = max(a3, a4);
fg = true;
}
}
if(fg)printf("%d\n", ans);
else printf("Poor Inna and pony!\n");
}
} return ;
}

Codeforces374A的更多相关文章

随机推荐

  1. Java基本数据类型和关键字

    变量名第一个字母小写,后面大写. 自动类型转换: 容量小的类型自动转换成容量大的数据类型 byte,short,int->float->long->double byte,short ...

  2. 向datagridview 添加行

    datagridview 已经绑定数据源且控件的AllowUserToAddRows设置为false时. ((DataTable)dataGridView1.DataSource).Rows.Add( ...

  3. Python tab 命令补全,以及 vim 补全

    在python 命令行中,使用补全 python 查看 packages 的目录 可用 sys.path 查看. /usr/lib/python2.7/site-packages vim tab.py ...

  4. DEDECMS整站复制

    1. 登录你的网站(织梦系统DedeCMS)后台,到“系统”–“系统设置”–“数据库备份/还原”,点击“数据备份选择”下面的“提交”: 2.拷贝备份的数据库文件到根目录/data/backupdata ...

  5. 安卓 Android题目大全

    安卓001个人事务管理系统(单端) 安卓002手机订餐系统 安卓003无线点菜 安卓004酒店房间预定系统 安卓005个人相册管理系统(单端) 安卓006计算器(单端) 安卓007英语学习(单端) ...

  6. nexus 中央仓库

    nexus 中央仓库 下载地址:http://www.sonatype.org/nexus/archived 下载最新版本 mkdir -p /opt/local/nexus tar zxvf nex ...

  7. php --with-mysql=mysqlnd

    1.什么是mysqlnd驱动? PHP手册上的描述: MySQL Native Driver is a replacement for the MySQL Client Library (libmys ...

  8. 数据分析与R语言-概念点(一)

    一.数据分析 1.数据分析的多层模型 常用的统计量 常用的算法 常用的数据分析工具 常见的报表 二.R语言 1.什么是R语言?     R是用于统计分析.绘图的语言和操作环境.R是属于GNU系统的一个 ...

  9. SSL证书指令

    转自:http://blog.csdn.net/madding/article/details/26717963 生成Self Signed证书 # 生成一个key,你的私钥,openssl会提示你输 ...

  10. Android SQLite 加密模块实现入门

    安卓的安全性那是众所周知,最近学习安卓apk反编译,发现某些即时通讯软件都封装了自己独立使用的数据库模块(从framework java/C++ 一直到底层的SQLite的C库), 为了防止被root ...