derp, just realized that this isn't the same. passes all the test cases, though, so that merits looking into