<div dir="ltr"><div class="gmail_extra">My first guesses would be that:</div><div class="gmail_extra">a) Your program is slowed down because lines from the file is read one line by one, i.e. there's lazy IO at work. Have you tried your code on a list that's loaded in the memory as a whole at once?</div><div class="gmail_extra">b) The cost of dereferencing the next link in a list overwhelms the cost of computing one answer. Have you tried using a tree instead?</div><div class="gmail_extra"><br></div><div class="gmail_extra">Best regards,</div><div class="gmail_extra">Marcin Mrotek</div></div>