solution for spoj_TEST problem