process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function minNumberOfMoves(n,a,b){ function createMovement(f,c,count){ return { 'f':f, 'c':c, 'count':count } } function addNextMovements(currentMovement){ var nextF,nextC; posibleMovements.forEach(function(futureCurrent){ nextF=currentMovement.f+futureCurrent[0]; nextC=currentMovement.c+futureCurrent[1]; if(allowedMovent(nextF,nextC) && matrix[nextF][nextC]==-1 && !containedInMovements(nextF,nextC)){ movements.push(createMovement(nextF,nextC,currentMovement.count+1)); } }) } function allowedMovent(f,c){ return f>=0 && f=0 && c0 } function initSquareMatrix(val){ var matrix = []; for(var i=0;i0){ current = movements.shift(); if(current.f==0 && current.c==0){ return current.count; } matrix[current.f][current.c]=current.count; addNextMovements(current); } return -1; } function minNumberOfMovesTotal(n){ for (var i=1;i