now the program is faster because it remembers the middle nodes during the computation