final output case
implemented final output case of counting routes up to maximum distance, including cyclic paths