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. 如何使用UDP进行跨网段广播(转)

    源:http://blog.chinaunix.net/uid-22670933-id-3716646.html 广播域首先我们来了解一下广播域的概念.广播域是网络中能接收任一台主机发出的广播帧的所有 ...

  2. javascript 基础 onclick(this)用法介绍

    http://www.5idev.com/p-javascript_events_onclick.shtml --------------------------------------------- ...

  3. Struts2的整体回顾(Action, 拦截器, 值栈, OGNL表示式, ModelDriven)

    ValueStack里有map(request, session, attr, parameters)和对象栈. Map调用的方法: ActionContext.getContext().put(k, ...

  4. 路过Haxe

    刚才在看Nape的时候,看到Haxe的代码,意外的感觉到亲切. 因为之前写过as2代码,最近学习了python,所以对haxe看起来很亲切,于是路过一下写了个HelloWorld. 另外,估计很长时间 ...

  5. 51nod1138(math)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1138 题意:中文题诶- 思路:假设 x=a1+(a1+1)+ ...

  6. layer 的一些知识

    layer类似于ps的图层,如果把一个uiview看做图片的画,layer就像是图层.一个图片是由很多个大小不同的有层次的图层构成的,uiview也是. 1. 一个view有一个underlying ...

  7. Ubuntu Nginx安装

    1.先更新ubuntu系统 更新命令 sudo apt-get update sudo apt-get upgrade 2 添加ubuntu nginx更新源镜像 cd /etc/apt/ sudo ...

  8. LPC1788的LCD接口驱动真彩屏

    #ifndef __LCD_H_ #define __LCD_H_ #include "common.h" #include "debugserial.h" # ...

  9. Android之布局大全

    Android布局方式可以归类为ViewGroup的5个类别,即ViewGroup的5个直接子类.其它的一些布局都扩展自这5个类. 上结构图: 转自:http://www.cnblogs.com/de ...

  10. Oracle行转列的3种方法

    测试表为A3 , 有5个字段:ID1, ID2, ID3, ID4, ID5 测试数据如下: ID1 ID2 ID3 ID4 ID5 1 2 3 4 5 11 22 33 44 55 111 222 ...