after removing printf statement after each inner iteration the program completed in pretty much 10 seconds