Square Running

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Runsberg citizens are keen on sports, especially running. Standard marathons bored them, so they decided to organize a marathon in Minecraft style. The event will be held on Runsberg's Central Square. Citizens believe that the most important in sports is not to win, but to participate, so the goal of the square running is not to win, but to take a beautiful photo of all participants.

The Runsberg's Central Square is a rectangular square divided into unit squares. Rows are enumerated from top to bottom starting from one, columns are enumerated from left to right starting from one. Each unit square has coordinates rr and cc --- row and column number, respectively.

There is a rectangular grass field on the Square. The sides of the grass field are parallel to the sides of the Square. The left top unit square of the grass field has coordinates (R_L,C_L)(R\_L, C\_L), and the right bottom unit square of the grass field has coordinates (R_R,C_R)(R\_R, C\_R). There are nn lanes for nn runners around the grass field. Lane ii is at the distance ii from the grass field's border, there is a runner with the number ii on lane ii. Runner ii starts from the unit square (r_i,c_i)(r\_i, c\_i). All runners start at the same time at the same speed: every second each athlete moves from the current square in his lane to the next square in his lane in a counterclockwise direction.

There is a photographer on the rectangular grass field. The photographer stays on the unit square with coordinates (R_p,C_p)(R\_p, C\_p). The photographer wants to take a beautiful photo. He tests an innovative dual-lens camera. This camera takes a photo in two opposite directions simultaneously. The photographer considers a photo beautiful if all the runners at the time he makes a photo are in the same row R_pR\_p or in the same column C_pC\_p. Thanks to the innovative camera, the runners can be in the same row with the photographer both to the right and to the left of him, or in the same column with the photographer both above and below him.

Your task is to find out what is the minimum number of seconds tt after the start of the marathon that the photographer will be able to take a beautiful photo or to find out that it is impossible to take a beautiful photo under these conditions.

입력

The first line contains integer nn (1n181 \le n \le 18) --- number of the runners. In the second line there are six integers R_LR\_L, C_LC\_L, R_RR\_R, C_RC\_R (n+1R_LR_R100nn + 1 \le R\_L \le R\_R \le 100 - n, n+1C_LC_R100nn + 1 \le C\_L \le C\_R \le 100 - n), R_pR\_p (R_LR_pR_RR\_L \le R\_p \le R\_R), C_pC\_p (C_LC_pC_RC\_L \le C\_p \le C\_R) --- the left top unit square coordinates, the right bottom unit square coordinates, the photographer's coordinates, respectively. It is guaranteed, that R_RR_L+C_RC_LR\_R - R\_L + C\_R - C\_L is divisible by 44.

In the next nn lines there are two integers r_ir\_i, c_ic\_i --- start coordinates of the runner ii. It is guaranteed, that the start coordinates of the runner ii are on the lane ii, there is only one runner on each lane and the lane ii is in the distance ii from the grass field's border.

출력

Output the minimum number of seconds tt after the start of the marathon that the photographer will be able to take a beautiful photo or 1-1, if it is impossible to take a beautiful photo under this conditions.

힌트

Staring positions of the runners.

Positions of the runners after 3 seconds. All runners are in the R_pR\_p. \\So the photographer is able to take a beautiful photo.