Solution for Pi 2012 task