python heap solution for problem 22