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. c语言基本数据类型short、int、long、char、float、double

    C 语言包含的数据类型如下图所示: 一.数据类型与“模子”short.int.long.char.float.double 这六个关键字代表C 语言里的六种基本数据类型. 怎么去理解它们呢? 举个例子 ...

  2. 前端教程&开发模块化/规范化/工程化/优化&工具/调试&值得关注的博客/Git&面试-资源汇总

    内容精简 资源这么多,多看看多学习再总结肯定是好的.多读读就算看重了不算浪费时间,毕竟一千个读者就有一千个林黛玉,还有温故而知新,说不定多读一些内容,就发现惊喜了呢.不过,在此也精简一些内容,就1~2 ...

  3. ASP.NET AJAX注册命名空间

    AJAX库支持命名空间的概念. 类可以分组到不同的命名空间.AJAX库会自动创建在此层次中不存在的任何级别的命名空间. <%@ Page Language="C#" Auto ...

  4. Lumen 配置、重写、404错误等

    1.权限是否有设置为777: 2.app key是否有设置: 3.apache下是否有开启重写,a2enmod: 4.nginx下server的location是否配置正确,重写规则有没添加,rout ...

  5. mysql面试

    第一方面:30种mysql优化sql语句查询的方法 避免全表扫描: 1.where 及 order by 上建立索引.2.避免在 where 子句中使用!=或<>操作符3. select ...

  6. 信息指纹(Fingerprint)及其应用

    1.应用:      i.网页地址去重           网页地址有100个字符,存储5000亿个网址本身需要50T的容量,而Hash表的存储效率只有50%,所有存储爬虫已经爬过的网址需要100T的 ...

  7. CentOS6.x升级MySQL版本5.1到5.6

    CentOS6.x升级MySQL版本5.1到5.6 分类: Web MySQL 2014-08-04 11:22 2813人阅读 评论(1) 收藏 举报 mysql云服务器升级centos6 有一些虚 ...

  8. 解决word启动时报找不到mathpage.wll错误

    按下面的网址进行操作即可: http://www.mathtype.cn/wenti/word-jianrong.html

  9. IOS开发中Xcode常用插件安装与管理(转)

    XCode中插件管理工具:Alcatraz    转自http://www.cocoachina.com/industry/20140506/8325.html 苹果现在的成绩得益于其始终如一的坚持. ...

  10. web 前端routine

    HTML:check CSS : check Javascript: struggling 框架:—— SQL:—— http://www.cnblogs.com/kzang/tag/SQL/ web ...