This is a second attempt where a formulated the same problem in completely different language ( using rooks of chess) and the code ran correctly without bugs and produced the correct results. BTW, this problem original and does not exist in any coding competition site. chatGPT