somehow the brute force seems to giving wrong answer...
may be my understanding of the problem is incorrect.