Fixed issues with reading inputs twice. Prolog is a horrible language that deserves to die in a fire.