PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000396. Nhìn qua khu rừng (Forest for the Trees)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Nhìn qua khu rừng (Forest for the Trees)

Forest for the Trees

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

You and Belle play hide-and-seek in a forest. Initially every point with two positive integer coordinates (x,y)(x,y) contains a tree, treated as a point. A logging company removes all trees in an axis-aligned rectangle, including its boundary. You stand at (0,0)(0,0) and Belle at (xb,yb)(x_b,y_b). Belle is visible exactly when no remaining tree lies strictly between you on the connecting segment. If a tree stands at her location, she stands on its side facing you, so it does not block the view. Determine whether she is visible and, if not, find the nearest blocking tree.

Example of the cleared region

Input

The first line contains integers xb,ybx_b,y_b. The second line contains integers x1,y1,x2,y2x_1,y_1,x_2,y_2, the opposite corners of the cleared rectangle.

Output

If Belle is visible, print Yes. Otherwise print No on the first line and the two integer coordinates of the nearest blocking tree on the second line.

Subtasks

  • Subtask 1 (20 points): 1≤xb,yb≤10121\le x_b,y_b\le10^{12}; 1≤x1≤x2≤10121\le x_1\le x_2\le10^{12}; 1≤y1≤y2≤10121\le y_1\le y_2\le10^{12}. max⁡(xb,yb,x1,y1,x2,y2)≤1000\max(x_b,y_b,x_1,y_1,x_2,y_2)\le1000; gcd⁡(xb,yb)≤100000\gcd(x_b,y_b)\le100000.
  • Subtask 2 (30 points): 1≤xb,yb≤10121\le x_b,y_b\le10^{12}; 1≤x1≤x2≤10121\le x_1\le x_2\le10^{12}; 1≤y1≤y2≤10121\le y_1\le y_2\le10^{12}. gcd⁡(xb,yb)≤100000\gcd(x_b,y_b)\le100000.
  • Subtask 3 (50 points): 1≤xb,yb≤10121\le x_b,y_b\le10^{12}; 1≤x1≤x2≤10121\le x_1\le x_2\le10^{12}; 1≤y1≤y2≤10121\le y_1\le y_2\le10^{12}.

Examples

Input

2 6
1 1 5 4

Output

Yes

Explanation

The only intermediate positive lattice point is (1,3)(1,3). It is inside the cleared rectangle, so Belle is visible.

Input

2 6
3 5 5 7

Output

No
1 3

Explanation

The tree at (1,3)(1,3) is outside the cleared region and blocks the view. No positive lattice point lies closer on the segment.

Input

6 9
2 3 2 3

Output

No
4 6

Explanation

The intermediate trees are (2,3)(2,3) and (4,6)(4,6). Only the first is removed; the second is the closest blocker.

Input

830844890448 39710592053
821266 42860 402207107926 423171345006

Output

No
402207964848 19223704203

Explanation

The gcd is 663979663979, so consecutive lattice points differ by (1251312,59807)(1251312,59807). The first point is inside the cleared rectangle. Point 321428321428 has x-coordinate 402206713536402206713536, within the right boundary 402207107926402207107926. All these points satisfy the vertical bounds. Point 321429321429 is (402207964848,19223704203)(402207964848,19223704203), beyond the right boundary and before Belle. It is the first blocking tree.