I was trying to solve this problem on spoj http://www.spoj.com/problems/BOBERT/ can anybody please help me . Finding 20! arrangements and then a range minimum query would cause TLE so i dont know how to exactly approach the solution? I am looking for an initial approach and not the full solution.