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

#BS0000426. Thoát khỏi vùng địch (Escape from Enemy Territory)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Thoát khỏi vùng địch (Escape from Enemy Territory)

Escape from Enemy Territory

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A group of soldiers has finished its mission and must travel from its current location to a rendezvous point. The map shows every enemy base in the area. The group wants to stay as far from these bases as possible throughout the journey.

The map is a rectangular grid with XX positions along the xx-axis and YY positions along the yy-axis. Each cell has integer coordinates (x,y)(x,y), where 0≤x<X0\le x<X and 0≤y<Y0\le y<Y. A step moves to a horizontally or vertically adjacent cell without leaving the grid.

The Manhattan distance between cells (x1,y1)(x_1,y_1) and (x2,y2)(x_2,y_2) is

d=∣x1−x2∣+∣y1−y2∣.d=|x_1-x_2|+|y_1-y_2|.

The safety of a route is the minimum distance between any cell on the route, including both endpoints, and any enemy base. Its length is the number of steps. Base cells are not removed from the grid; visiting one makes the route's safety 00.

Find the greatest achievable safety, then the shortest route length among all routes achieving that safety.

Input

The first line contains three integers N,X,YN,X,Y: the number of bases and the two grid dimensions.

The second line contains four integers xi,yi,xr,yrx_i,y_i,x_r,y_r, specifying the start (xi,yi)(x_i,y_i) and the rendezvous point (xr,yr)(x_r,y_r).

Each of the next NN lines contains two integers xj,yjx_j,y_j, the location of base jj (1≤j≤N1\le j\le N).

Output

Print two integers on one line, separated by a space: the maximum achievable safety and the minimum route length attaining that safety, in that order.

Subtasks

  • Subtask 1 (20 points): 1≤N≤100001\le N\le 10000; 1≤X,Y≤251\le X,Y\le 25; 0≤xi,xr,xj<X0\le x_i,x_r,x_j<X; 0≤yi,yr,yj<Y0\le y_i,y_r,y_j<Y for every 1≤j≤N1\le j\le N. All N+2N+2 coordinate pairs are distinct.
  • Subtask 2 (30 points): 1≤N≤100001\le N\le 10000; 1≤X,Y≤1501\le X,Y\le 150; 0≤xi,xr,xj<X0\le x_i,x_r,x_j<X; 0≤yi,yr,yj<Y0\le y_i,y_r,y_j<Y for every 1≤j≤N1\le j\le N. All N+2N+2 coordinate pairs are distinct.
  • Subtask 3 (50 points): 1≤N≤100001\le N\le 10000; 1≤X,Y≤10001\le X,Y\le 1000; 0≤xi,xr,xj<X0\le x_i,x_r,x_j<X; 0≤yi,yr,yj<Y0\le y_i,y_r,y_j<Y for every 1≤j≤N1\le j\le N. All N+2N+2 coordinate pairs are distinct.

Examples

Input

1 2 2
0 0 1 1
0 1

Output

1 2

Explanation

The 2×22\times2 grid has one base at (0,1)(0,1). The route from (0,0)(0,0) through (1,0)(1,0) to (1,1)(1,1) has distances 11, 22, and 11 from that base. The start is only one unit from the base, so no route can have safety greater than 11. The endpoints have Manhattan distance 22, making two steps optimal.

Input

2 5 6
0 0 4 0
2 1
2 3

Output

2 14

Explanation

The bases are at (2,1)(2,1) and (2,3)(2,3). Every route from (0,0)(0,0) to (4,0)(4,0) must visit a cell with x=2x=2. At this coordinate, the nearest-base distances for y=0,1,2,3,4,5y=0,1,2,3,4,5 are 1,0,1,0,1,21,0,1,0,1,2, respectively. Hence safety cannot exceed 22.

Travel to (0,5)(0,5) in five steps, then to (4,5)(4,5) in four steps, and finally to (4,0)(4,0) in five steps. Every visited cell is at least two units from each base. The total is 5+4+5=145+4+5=14 steps.

Any route with safety 22 must visit (2,5)(2,5). Increasing yy from zero to five and returning to zero takes at least ten steps, while increasing xx from zero to four requires at least four more. Thus no equally safe route can use fewer than fourteen steps.