This is the answer for Aizu Online Judge problem.