SPOJ problem solutions