I think you should calculate len after reading `n` now.