Finish the Problem A of ACM 2011. Not checked yet