Problem Description available HERE
unlike what's said in the original problem, there may be MORE THAN 5 testcases in the input. Please beware.
Migrated from old NTUJ.
Regional Hsinchu 2010