working algorithm with correct score on TOY input file