Implement mapAccumRWithKey