Just kidding, why wait and commit tomorrow when you can fix stuff today? Here's the slightly better version that handles multiple N input but still fails some test cases =(