Solved ACM problem code