adding needle in a haystack problem for spoj