UVa 151: brute force