Generating list of diagonals and calculating cost