Works on input size of 400. Runs into runtime error on 400000.