WA on test #3.
Code for problem 27B.
Code for problem 28A.