Using modulo to go to the firs column after the last column
ans [ i ] [ j ] = arr [ j ] [ ( i + j ) % n ] NEW_LINE return ans NEW_LINE def show ( arr , n ) : NEW_LINE res = solve ( arr , n ) NEW_LINE for i in range ( n ) : NEW_LINE for j in range ( n ) : NEW_LINE print ( res [ i ] [ j ] , end = " ▁ " ) NEW_LINE print ( ) NEW_LINE