프로그램 명: ncpc_connect
제한시간: 1 초

When constructing electric circuits one has to connect pairs of points using wire, preferable as short as possible. In this problem we have an empty circuit board of size N * M where we want to connect the two points A1 and A2 with each other using one wire, and the two points B1 and B2 with each other using another wire.

The wires must go along the horizontal and vertical edges of the grid (see figure), and the two wires may not share a common vertex. Determine the minimum length of wire needed to do so. The wire may not go outside the circuit board.

입력

출력

A single line containing the minimum length of wire needed to connect the points, or "IMPOSSIBLE" if it's not possible to do so.

입출력 예

입력

6 6
2 1
5 4
4 0
4 5

출력

15

입력

6 3
2 3
4 0
0 2
6 1

출력

IMPOSSIBLE
출처:ncpc/2010/Problem B

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]