The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells where one of the cells is empty space.

In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 15 as shown below.


1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15


You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps).


1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0


Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle.

Constraints

* The given puzzle is solvable in at most 45 steps.

Input

The $4 \times 4$ integers denoting the pieces or space are given.

Output

Print the fewest steps in a line.

Example

Input

1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15


Output

8
#include<iostream>
using namespace std;
#include<cstdio>
#include<cmath>  // use "abs" function.

// non-recursive algorithm.
#define N 4
#define N2 16

int main()
{
	int MDT[N2][N2];   // Manhattan Distance Table.
	int dx[4] = {0, -1, 0, 1};  // move.
	int dy[4] = {1, 0, -1, 0};

	int i, j;
	for(i = 0; i < N2; i++){
		for(j = 0; j < N2; j++){
			MDT[i][j] = abs((i / N) - (j / N)) + abs((i % N) - (j % N));
		}
	}
	int pre_f[N2], f[N2], pre_space, space, pre_MD, MD, depth;
	for(i = 0; i < N2; i++){
		scanf("%d", &pre_f[i]);
		if(pre_f[i] == 0) pre_space = i;
	}

	pre_MD = 0;
	for(i = 0; i < N2; i++){
		if(pre_f[i] != 0){
			pre_MD += MDT[i][pre_f[i] - 1];
		}
	}

	int level, sx, sy, tx, ty, diff, trail[101], s, r, rev_sp;

	for(level = pre_MD; level < 50; level++, level++){  // DFS.
		for(i = 0; i < N2; i++) f[i] = pre_f[i];
		space = pre_space;
		MD = pre_MD;
		depth = 0;
		trail[0] = 4;
		s = 0;

		while(depth >= 0 && MD > 0)
		{
			sx = space / N;
			sy = space % N;
			for(r = s; r < 4; r++){
				if((trail[depth] ^ r) == 2) continue;  // go forward.
				tx = sx + dx[r];
				ty = sy + dy[r];

				if(tx < 0 || tx >= N || ty < 0 || ty >= N) continue;
				diff = MDT[sx * N + sy][f[tx * N + ty] - 1] - MDT[tx * N + ty][f[tx * N + ty] - 1];
				if(depth + 1 + MD + diff > level) continue;  // branch cut.

				break;
			}
			if(r < 4){  // next direction.
				swap(f[sx * N + sy], f[tx * N + ty]);
				space = tx * N + ty;
				MD += diff;
				depth++;
				trail[depth] = r;
				s = 0;
			}else{
				// back-track.
				r = trail[depth] ^ 2;
				s = trail[depth] + 1;
				depth--;
				if(depth >= 0){
					rev_sp = space + N * dx[r] + dy[r];
					MD += MDT[space][f[rev_sp] - 1] - MDT[rev_sp][f[rev_sp] - 1];
					swap(f[space], f[rev_sp]);
					space = rev_sp;
				}
			}
		};
		if(depth >= 0) break;
	}
	printf("%d\n", depth);

	return 0;
}