Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};

int MDT[N2][N2];

struct puzzle {
  int f[N2],space,MD;
};
puzzle state;
int limit=100;
int path[100];

int getallmd(puzzle pz){
  int sum=0;
  rep(i,N2){
    if(pz.f[i]==N2)continue;
    sum+=MDT[i][pz.f[i]-1];
  }
  return sum;
}
bool isSolved(){
  rep(i,N2)if(state.f[i]!=i+1)return 0;
  return 1;
}
bool dfs(int depth,int prev){
  if(state.MD==0){
    return 1;
  }
  if(depth+state.MD>limit)return 0;
  int sx=state.space/N;
  int sy=state.space%N;
  puzzle tmp;
  rep(r,4){
    int tx=sx+dx[r];
    int ty=sy+dy[r];
    if(tx<0||ty<0||tx>=N||ty>=N)continue;
    if(max(prev,r)-min(prev,r)==2)continue;
    tmp=state;
    state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
    state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
    swap(state.f[tx*N+ty],state.f[sx*N+sy]);
    state.space = tx*N+ty;
    if(dfs(depth+1,r)){
      path[depth]=r;
      return 1;
    }
    state=tmp;
  }
  return 0;
}

int iterative_deeping(puzzle in){
  in.MD=getallmd(in);
  for(limit=in.MD;limit<=LIMIT;limit++){
    state=in;
    if(dfs(0,-100)){
      int ans=0;
      rep(i,limit)ans+=1;
      return ans;
    }
  }
  return -1;
}



int main(){
  rep(i,N2)rep(j,N2)MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
  puzzle in;
  rep(i,N2){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
   int ans = iterative_deeping(in);
  cout<<ans<<endl;
  return 0;
}