input brute-force solution to problem 5