I used to drink a lot of very strong coffee when I was studying until one evening after we treated outseoves to a 2.2 litre flask. I filled the coffee maker with exceptionally strong stuff so the flask was full and took it into my study and drank the lot. My OH came upstairs and told me I really ought to think about bed as it was midnight and I had a 9am lecture the next morning. I felt wide awake but thought I ought to get some sleep so took a Nytol tablet.
Then lay in bed while my head did somersaults with the caffeine fighting the sleeping tablet until around 3am (maybe later) when the Nytol won. Why I hadn't thought about the caffeine, I do not know, but I learned my lesson when I drove the 45 minute trip into uni then tried to stay awake during the 1 1/2 hour lecture while still half asleep. Last time I drank coffee at night.
These days I drink coffee only rarely(I have a Bodum that makes just one cup) and don't drink tea at all. I just drink either hot or cold water or the occasional hot chocolate.