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 initGrid(n, s) { // init grid var c = 0; var grid = []; while(c0 && grid[0][0] == 0){ tmp = teste; teste = checkRanges(tmp,rook,n); if(teste.length>0) {obj = makeMoves(grid,teste,c,1);grid = obj.grid;teste = obj.arr;} tmp = testy; testy = checkRanges(tmp,rook,n); if(testy.length>0) {obj = makeMoves(grid,testy,c,-1);grid = obj.grid;testy = obj.arr;} moves = teste.length + testy.length; c++; // console.log("teste is "); // console.log(teste); // console.log("testy is "); // console.log(testy); tater++; if(tater==1000){moves = 0;} } if(grid[0][0] == 0){grid[0][0]=-1;} // prettyGrid(grid); // console.log("tater is "); // console.log(tater); return grid[0][0]; } function checkRanges(arr,rook,n) { var res = []; var i = 0; while(i0 && d==-1){ c += grid[x][y]; grid[0][0] = c; i = arr.length; } } i++; } return {grid:grid, arr:res}; } function pretty(grid) { var i = 0; var i0 = 0; var r = ""; while(ii){res[i0-1][i-1]=res[i-1][i0-1]} } i0++; } i++; } pretty(res); }