you give rectangular matrix size n time m consist integer 1 2 cdot 105in choose element matrix change value integer 1 n cdot m inclusive column shift cell cyclically example cyclic shift a cyclic shift operation choose j 1 le j le m set a_1 j a_2 j a_2 j a_3 j dot a_n j a_1 j simultaneously Example cyclic shift column you want perform minimum number move matrix look like in word goal obtain matrix a_1 1 1 a_1 2 2 dot a_1 m m a_2 1 m 1 a_2 2 m 2 dot a_n m n cdot m ie a_i j 1 cdot m j minimum number move perform