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>
#include <map>
#include <queue>
#include <vector>
#define N 4
#define N2 16
using namespace std;

vector<int> move_list[N2];
int dist[N2][N2];

class Game{
public:
  char board[N2];
  char w;
  vector<char> route;
  char mnh;

  bool operator < (const Game &other) const{
    return route.size()+mnh > other.route.size()+other.mnh;
  }
};
Game start;

vector<char> search(){
  priority_queue<Game> q;
  q.push(start);
  
  while(!q.empty()){
    Game g=q.top();q.pop();
    if(g.mnh==0) return g.route;

    for(int move:move_list[g.w]){
      if(g.route.size()>0 && g.route.back()==-move) continue;
      Game h=g;
      int to=h.w+move;
      h.mnh -= dist[to][h.board[to]-1];
      h.mnh += dist[h.w][h.board[to]-1];
      swap(h.board[h.w],h.board[to]);
      h.w = to;
      h.route.push_back(move);
      q.push(h); 
    }
  }
}

int solve(){
  vector<char> route=search();
  return route.size();
}

void initialize(){
  for(int i=0;i<N2;i++){
    if(i%N<N-1) move_list[i].push_back(1);
    if(i%N>0  ) move_list[i].push_back(-1);
    if(i/N<N-1) move_list[i].push_back(N);
    if(i/N>0  ) move_list[i].push_back(-N);
  }

  //i=board,j=piece-1
  for(int i=0;i<N2;i++){
    for(int j=0;j<N2;j++){
      dist[i][j] = abs(j%N-i%N) + abs(j/N-i/N);
    }
  }

  start.mnh=0;
  for(int i=0;i<N2;i++){
    if(i==start.w) continue;
    start.mnh += dist[i][start.board[i]-1];
  }
}
 
int main(){
  int tmp;
  for(int i=0;i<N2;i++){
    cin>>tmp;
    if(tmp==0){
      start.board[i]=N2;
      start.w=i;
    }else{
      start.board[i]=tmp;
    }
  }
  initialize();
  cout<<solve()<<endl;
}
