Improved solution for count-serpinski