Mental clarity in software has extreme leverage, probably among the biggest of any human endeavor. Your effectiveness as a programmer is largely a function of how well you can model the software in your mind. Often seeing immediately how to do things correctly vs bumbling forward can be 4 hours of work vs 2 weeks of work. Actually inputting the code is not the thing that takes time. You could write 50,000 lines of code in a day if typing was the only bottleneck.
This is also in the context of a low-distraction environment where there are zero interruptions. If you're working in a busy office, staying late is usually a productivity boost because you finally get some quiet time to concentrate. Which, again, is good for clarity and hence productivity.