added keys to input, modified code to output n and d