Hide

Problem F
The Giant

Languages en ja sv

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 0x<N,0y<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 (x1,y1) and the coordinates for the giant’s left foot (x2,y2), finds a point with integer coordinates at which to place the bar of gold, so that the three points form a non-degenerate1 obtuse triangle.

Input

The first line of the input contains two integers N and M (1N,M109), the size of the cave.

The second line contains four integers x1, y1, x2 and y2 (0x1,x2<N, 0y1,y2<M), the coordinates for the giant’s two feets. These points will always be different.

Output

Print two integers x3,y3 (0x3<N, 0y3<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.

Group

Points

Constraints

1

30

1N1000 and 1M1000

2

25

1000N109 and 1000M109

3

15

x1x2 and y1y2

4

30

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

Sample Input 1 Sample Output 1
4 5
1 1 3 4
1 2
Sample Input 2 Sample Output 2
1000 1000
500 500 500 502
498 498
Sample Input 3 Sample Output 3
1000000000 1000000000
0 0 0 999999999
10 500000000

Footnotes

  1. A triangle is non-degenerate if its three vertices do not lie on the same line, https://en.wikipedia.org/wiki/Degeneracy_(mathematics)
Hide

Please log in to submit a solution to this problem

Log in