How should one handle peers, competition and other social pressure while studying theoretical CS/Maths? I'm currently a 20 year old undergrad studying CS at a reputed institute in my city. I'm one of the very few from my batch who's interested in studying theoretical CS and mathematics (about 10 students from a batch of 200) and want to pursue research as a career. 

Thing is, out of these 10 students, I'm the dumbest. I score the least in a graph theory exam, I cannot come up with creative solutions to problems in complexity theory as quick as they can (sometimes I keep on thinking for days, if not weeks, and still cannot come up with anything useful), I'm the student who the professor looks at and wonders: why are they here? To be very honest, I don't really like programming or web development. I like to spend time thinking about stuff, solving problems by hand, and learning fascinating things in logic and modern algebra. I'm weak at exams, true, but then I'm mostly clueless and disinterested in web development classes, where I can score easily but not learn something that I couldn't have learnt by watching tutorials on the Internet. I'm obviously looked down by my peers, too; and my grades are, well... not too great. In my current semester, I'm studying four theory courses (Complexity Theory, Graph Theory, Abstract Algebra and Cryptography) and one introductory CS security course. I'm going through the most difficult time of my academic curriculum so far; getting around 3-4 hours of sleep every day, with most of my day spent in attending classes and solving assignments. I'd like to drop a course from my current roster, but I'm afraid that since that'd show up in my transcript after I graduate, it might ruin my chances of getting into a respected grad school or landing a job. 

I was recently diagnosed with manic depression, and while there are a few personal problems I have (premature balding, asocial lifestyle etc.) that might have caused that, some amount of the aforementioned issue might have also contributed to the cause. Anyway, I'm not asking for any consolation.

What I'm asking is: if anyone who's been through similar experiences while pursuing academia, how did you cope up? Even if you weren't like me (chances are pretty high that you weren't like me, CS theory/Math students are usually very intelligent), what do you advice? Should I stop studying theoretical CS due to my frequent failures? I mean, I don't believe in that kind of stuff, but usually if you fail too much at a certain thing, maybe that's some sort of sign or something? I don't really have a lot of friends, and no one from my family has received as much education as I have (so far), so I don't really have anyone I can ask for advice.
First, slow != dumb (your words). In fact, these are two completely different cognitive processes. WISC, a widely used IQ test, measures IQ as a composite of four scores. Two of them are working memory and processing speed, which is your general ability to quickly solve problems. Another two scores are Verbal Comprehension index and Perceptual Reasoning Index, which measure loosely your problem solving skills and pattern recognition. Many score high on one, and not the other. 

Some problems are hard, and it is very difficult to learn how to solve them. But, after solving (or understanding solutions to) many, many of them, you develop the feel how to approach a new problem. If you are passionate about the field, so much so that you have enough discipline to practice and work hard day after day, the results will come.  

Last, take care of yourself. And you might want to read up on imposter syndrome, https://counseling.caltech.edu/general/InfoandResources/Impostor . A very common occurrence in academia, it is a mindset where people downplay their own successes, focus only on their struggle, fail to see others' struggles. For example, just from your post: you are more educated that the rest of your family, you have been admitted to a top school, are eager to tackle some of the most difficult problems, and have a very heavy class load. These are your successes. Give yourself credit for it. Focus on the struggle: you tend to call yourself names, and over-generalize several setbacks (bad grades), while seeing others in glorified way. A more constructive would be to look for a solution for your current struggle that takes an advantage of your strengths: maybe dropping a class, if you can, to give yourself more in-depth studying time.