few solutions from spoj.com