루미 알고리즘

#1462플래티넘The Giant

PO 2019 결선코딩출제 Erik Amirell Eklöf영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

You have been captured by an evil giant. You are both in a N × M big cave consisting of all points with integer coordinates (x, y) such that 0 ≤ x < N, 0 ≤ y < M. The giant plans to eat you, so you must escape before it's too late! The giant is standing with his feet at two different points in the cave. To escape, you plan to put a bar of gold at a third point in the cave. The giant will then bend down to pick the bar up. If the positions for the giant's feet and the gold bar together form an obtuse triangle, the giant will lose his balance and fall down. In this case, you will get an opportunity to run.

Write a program that, given the size of the cave, the coordinates for the giant's right foot (x_1, y_1) and the coordinates for the giant's left foot (x_2, y_2), finds a point with integer coordinates at which to place the bar of gold, so that the three points form a non-degenerate (A triangle is non-degenerate if its three vertices do not lie on the same line, https://en.wikipedia.org/wiki/Degeneracy_(mathematics)) obtuse triangle.

Input

The first line of the input contains two integers N and M (1 ≤ N, M ≤ 10^9), the size of the cave.

The second line contains four integers x_1, y_1, x_2 and y_2 (0 ≤ x_1, x_2 < N, 0 ≤ y_1, y_2 < M), the coordinates for the giant's two feets. These points will always be different.

Output

Print two integers x_3, y_3 (0 ≤ x_3 < N, 0 ≤ y_3 < M) on the same line, so that the point with these coordinates together with the two points in the input forms a non-degenerate obtuse triangle. The input is constructed so that there is always at least one such point.

Scoring

Your solution will be tested on a set of test case groups. To get the points for a group, you need to pass all the test cases in the group.

GroupPointsConstraints
1301 ≤ N ≤ 1000 and 1 ≤ M ≤ 1000
2251000 ≤ N ≤ 10^9 and 1000 ≤ M ≤ 10^9
315x_1 ≠ x_2 and y_1 ≠ y_2
430No further constraints

Explanation of sample 1

In example 1, the points (1,1), (3,4) and (1,2) form an obtuse triangle, with the obtuse angle at (1,2). (1,2) is also within the cave.

The point (1,4) would not have been a correct answer, since that would form a right triangle rather than an obtuse triangle.

The point (5,7) would not have been a correct answer, since that would form a degenerate triangle, and (5,7) is also placed outside of the cave.

예제

예제 1

입력
4 5
1 1 3 4
출력
1 2

예제 2

입력
1000 1000
500 500 500 502
출력
499 499

예제 3

입력
1000000000 1000000000
0 0 0 999999999
출력
1 999999998

출처 표기

출처: Programmeringsolympiaden 2019년 결선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.