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

  1. 5 7 1 3 2 2

output

  1. 2

input

  1. 5 5 2 3 1 1

output

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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int n, m, sx, sy, a, b;
  7.  
  8. int main()
  9. {
  10. while(scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &a, &b) != EOF)
  11. {
  12. int ans;
  13. if((sx==&&sy==)||(sx==&&sy==m)||(sx==n&&sy==)||(sx==n&&sy==m))
  14. {
  15. printf("0\n");
  16. }else if((n-)<a || (m-)<b)
  17. printf("Poor Inna and pony!\n");
  18. else
  19. {
  20. int a1 = (sx-)/a;
  21. int a2 = (sy-)/b;
  22. int a3 = (m-sy)/b;
  23. int a4 = (n-sx)/a;
  24. bool fg = false;
  25. if(a1*a==(sx-) && a2*b==(sy-))
  26. {
  27. int tmp = abs(a1-a2);
  28. if(tmp%==)
  29. {
  30. ans = max(a1, a2);
  31. fg = true;
  32. }
  33. }
  34. if(a1*a==(sx-) && a3*b==(m-sy))
  35. {
  36. int tmp = abs(a1-a3);
  37. if(tmp%== && max(a1, a3) < ans)
  38. {
  39. ans = max(a1, a3);
  40. fg = true;
  41. }
  42. }
  43. if(a2*b==(sy-) && a4*a==(n-sx))
  44. {
  45. int tmp = abs(a4-a2);
  46. if(tmp%== && max(a4, a2) < ans)
  47. {
  48. ans = max(a4, a2);
  49. fg = true;
  50. }
  51. }
  52. if(a3*b==(m-sy) && a4*a==(n-sx))
  53. {
  54. int tmp = abs(a3-a4);
  55. if(tmp%== && max(a3, a4) < ans)
  56. {
  57. ans = max(a3, a4);
  58. fg = true;
  59. }
  60. }
  61. if(fg)printf("%d\n", ans);
  62. else printf("Poor Inna and pony!\n");
  63. }
  64. }
  65.  
  66. return ;
  67. }

Codeforces374A的更多相关文章

随机推荐

  1. WPF教程:依赖属性

    一.什么是依赖属性 依赖属性就是一种自己可以没有值,并且可以通过绑定从其他数据源获取值.依赖属性可支持WPF中的样式设置.数据绑定.继承.动画及默认值. 将所有的属性都设置为依赖属性并不总是正确的解决 ...

  2. JQuery操作DOM对象

    1.追加节点( 儿子关系) append()     $("已有元素").append("动态添加元素");  在已有元素的内部的后面追加一个元素 append ...

  3. hibernate和ibatis的区别

    通过别人的资料,进行自己关注的一些扼要点的整理 共同点: 1. 不同点:1. 自动化程度上,hibernate是全自动化的orm框架,提供了对象到数据库的完全映射和sql的内部自动生成,其对象映射是指 ...

  4. implemented loader.php

    http://stackoverflow.com/questions/11787176/manage-url-routes-in-own-php-framework This is how i imp ...

  5. Ubuntu和win10双系统Grup无法引导解决方案

    通常我们经常安装双系统, 但是有时候安装完系统无法正常引导, 以下就说明Ubuntu和win10双系统, win10在grub界面不断循环的解决方案 直接在win10启动项目上按e进入编辑模式 在文档 ...

  6. [iOS Animation]-CALayer 显示动画

    显式动画 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念.隐式动画是在iOS平台创建动态用户界面的一种直接方式,也是UIKit动画机制的基础,不过它并不能涵盖所有的动 ...

  7. Cdoefroces #354

    A题 题意:给定一些数,然后求一次交换以后最大的数和最小的数之间的最大距离 分析:找到最大数和最小数的位置,然后判断是把位置大的移到最后还是把位置小的移到开始位置即可 #include <ios ...

  8. Lambda表达式例子

    转 Lambda表达式例子 1.Java8 新特性介绍 写java的同学对java8肯定知道 那么java8到底有哪些特性呢,总结如下: Lambda表达式 函数式接口 Stream Optional ...

  9. STM32 驱动1602液晶

    利用STM32f103c8t6单片机驱动1602A液晶进行显示功能 上图即为写入信息后的效果图 本人用的是STM32的核心系统,无任何外设 库函数:3.5版本的库函数 驱动模式:采用4线驱动模式 供电 ...

  10. EclipseEE导入项目出现的那些问题

    1.显示.project文件丢失, 解决方法:在eclipse中删除和该项目相同的文件名,重新import即可 2.导入没有.classpath和.project文件的项目 解决方法:目前没遇到 3. ...