Well, oh great one, I know the addicting nature of success. It's always a great feeling to get rewarded for whatever one has put some time and effort into it - especially if that is well earned. Still, one of the most intricate revelations one has to have in life is that there will always be someone who is better than you in every regard possible; smarter, happier and more accomplished. Always. Because let's face it: the probability of you being the top dog was always insignificant from the start.
However....that was never a reason to despair in the first place. Find accomplishment in the little things. Even if you are just mediocre, haven't you learned so much already? Haven't you faced adversity upon adversity and still pulled through? Didn't you do things that you always wanted to do? Haven't you affected people positively? Don't you now know so many things of beauty that you never knew existed before? You never needed so much success in the first place - there are so many other things abound that can make you happy instead. You just need to find the right balance...
Aside from that, if I read you correctly, you just entered university, right? In this case I'll also wager that you will get better with time as you get more used to the difficulty level and general way that things work at uni. It took me about two semesters to develop a workable system that allowed me to learn better and get much better grades; hence, finding something like that in time will likely mitigate those feelings you have a bit and push your grades up a bit. I'm confident that it will happen sooner or later. Just don't expect to be top dog