added solution for http://www.spoj.com/problems/FCTRL2/