D is passed with recursive algotithm, I could't find bug in non-recursive implementation