refactored with input argument for codeeval.com