Actually, the best way to avoid sex and stay sane is masturbation.
Pills and starving will not help your body.
If I were you, I would study, masturbate, and go to sleep. Three times a day is pretty normal for a man your age. The problem is that you are staying up too late, not that you are masturbating. If you feel that your relationship is interfering with your studies, perhaps you should break it off, or decide whether the relationship is more important than your education to you, right now. The real conflict, other than that you feel guilty about things sexual, is that your mind is telling you that it is time to educate yourself, and your body is telling you that it is time for sex. Masturbation can be a good compromise, as long as it doesn't interfere with your studies.