1065_D. Three Pieces
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily 8 × 8, but it still is N × N. Each square has some number written on it, all the numbers are from 1 to N^2 and all the numbers are pairwise distinct. The j-th square in the i-th row has a number A_{ij} written on it.

In your chess set you have only three pieces: a knight, a bishop and a rook. At first, you put one of them on the square with the number 1 (you can choose which one). Then you want to reach square 2 (possibly passing through some other squares in process), then square 3 and so on until you reach square N^2. In one step you are allowed to either make a valid move with the current piece or replace it with some other piece. Each square can be visited arbitrary number of times.

A knight can move to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. A bishop moves diagonally. A rook moves horizontally or vertically. The move should be performed to a different square from the one a piece is currently standing on.

You want to minimize the number of steps of the whole traversal. Among all the paths to have the same number of steps you want to choose the one with the lowest number of piece replacements.

What is the path you should take to satisfy all conditions?

Input

The first line contains a single integer N (3 ≤ N ≤ 10) — the size of the chessboard.

Each of the next N lines contains N integers A_{i1}, A_{i2}, ..., A_{iN} (1 ≤ A_{ij} ≤ N^2) — the numbers written on the squares of the i-th row of the board.

It is guaranteed that all A_{ij} are pairwise distinct.

Output

The only line should contain two integers — the number of steps in the best answer and the number of replacement moves in it.

Example

Input

3
1 9 3
8 6 7
4 2 5


Output

12 1

Note

Here are the steps for the first example (the starting piece is a knight):

  1. Move to (3, 2) 
  2. Move to (1, 3) 
  3. Move to (3, 2) 
  4. Replace the knight with a rook 
  5. Move to (3, 1) 
  6. Move to (3, 3) 
  7. Move to (3, 2) 
  8. Move to (2, 2) 
  9. Move to (2, 3) 
  10. Move to (2, 1) 
  11. Move to (1, 1) 
  12. Move to (1, 2) 
```python
import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

n = int(minp())
m = [None]*n
k = [None]*3
dp = [None]*3
dp[0] = [None]*(n*n)
dp[1] = [None]*(n*n)
dp[2] = [None]*(n*n)
path = [None]*(n*n)
for i in range(n):
	m[i] = list(map(int, minp().split()))
	for j in range(n):
		path[m[i][j]-1] = (i,j)
for z in range(3):
	k_ = [None]*n
	for i in range(n):
		kk = [None]*n
		for j in range(n):
			kkk_ = [None]*3
			for zz in range(3):
				kkk = [None]*n
				for w in range(n):
					kkk[w] = [(1000000,0)]*n
				kkk_[zz] = kkk
			kk[j] = kkk_
		k_[i] = kk
	k[z] = k_

q = [0]*(10*n*n)
qr = 0
km = [(1,2),(1,-2),(-1,2),(-1,-2),(2,1),(2,-1),(-2,1),(-2,-1)]
sm = [(1,1),(1,-1),(-1,1),(-1,-1)]
lm = [(0,1),(0,-1),(-1,0),(1,0)]
mm = [km,sm,lm]
for z in range(3):
	for i in range(n):
		for j in range(n):
			#print('========')
			ql = 0
			qr = 1
			q[0] = (z, i, j, (0,0))
			kc = k[z][i][j]
			kc[z][i][j] = (0, 0)
			while ql < qr:
				t, x, y, dd = q[ql]
				#print(t,x,y,dd)
				d = kc[t][x][y]
				ql += 1
				if d != dd:
					continue
				dd = (d[0]+1, d[1]+1)
				for tt in range(3):
					if t != tt and kc[tt][x][y] > dd:
						kc[tt][x][y] = dd
						q[qr] = (tt,x,y,dd)
						qr += 1
				dd = (d[0]+1,d[1])
				if t == 0:
					for w in mm[t]:
						xx,yy = w[0]+x,w[1]+y
						if xx >= 0 and xx < n and yy >= 0 and yy < n:
							if kc[t][xx][yy] > dd:
								kc[t][xx][yy] = dd
								q[qr] = (t,xx,yy,dd)
								qr += 1
				else:
					for w in mm[t]:
						for hm in range(n*2):
							xx,yy = w[0]*hm+x,w[1]*hm+y
							if xx >= 0 and xx < n and yy >= 0 and yy < n:
								if kc[t][xx][yy] > dd:
									kc[t][xx][yy] = dd
									q[qr] = (t,xx,yy,dd)
									qr += 1
							else:
								break
dp[0][0] = (0,0)
dp[1][0] = (0,0)
dp[2][0] = (0,0)
for i in range(0,n*n-1):
	x,y = path[i]
	xx,yy = path[i+1]
	for z in range(3):
		for j in range(3):
			dist = k[j][x][y][z][xx][yy]
			if dp[j][i] != None:
				nd = (dp[j][i][0]+dist[0],dp[j][i][1]+dist[1])
				if dp[z][i+1] == None:
					dp[z][i+1] = nd
				else:
					dp[z][i+1] = min(dp[z][i+1],nd)
for j in range(n*n-1,n*n):
	qq = [dp[i][j] if dp[i][j] != None else (1000000,0) for i in range(3)]
	qm = min(qq)
	#print(j,qm)
	print(qm[0], qm[1])
```