It sounds like your DM is playing favorites
As much as I hate to accuse anyone of favoritism, the way you've posed the question makes it sound like your DM is playing favorites in the party. That's never fun for the players stuck on the outside.
I've written about dealing with feeling left out in a party before and I think a lot of the advice I had there applies here as well. For background, I DM for a small group and was unintentionally favoring one player over another. She pointed out the issue and I made a real effort to correct my behavior. The following is extrapolated from what worked for our group.
Talk to your DM about your concerns
The first place to bring this up is going to be with your DM. Have a private, one-on-one meeting outside of your normal gaming time. You want to prevent putting the DM on the spot as that just tends to make people defensive.
Lay out your concerns in a non-accusatory manner. Sure, it's entirely possible that your DM is intentionally favoring these two players, but you want to give them the benefit of the doubt so you don't burn any bridges. It's possible they don't realize, like I didn't, that their actions aren't making the game fun for everyone.
You mentioned in comments that you weren't sure if the DM had ever DM'd before. New DMs can - and will - make a lot of mistakes, and sometimes just pointing out the issue will correct the behavior.
I would particularly bring up the party splitting. Although it's mechanically possible in D&D, it's not great for party dynamics, as you've clearly experienced. In general in my games I try to keep splits geographically small and for limited durations of time. The most I'll allow my party to split is to let them run mundane errands alone (B goes to the armorer to sell armor, C goes to the general store to buy rope, and I narrate in a B - C - B - C pattern) or investigate separate rooms in a house/dungeon alone (B takes the left-hand room, C the right). Any longer and you end up with players sitting around bored while other people have all the fun, which is no good.
If your DM seems receptive to your complaints then you have a good chance of this group working out for you. The next step once they agree that there's a problem is to talk to the rest of the group as a whole and all get on the same page. I'll talk about that later in this answer.
If, however, your DM doesn't see the problem with their session structuring and their own behavior, you might be out of luck, which is where my next point comes in.
Talk to the other party members
It might help to check in and see how everyone else in the party feels. It sounds from your comments like there's a core group of about five of you, including the two favored players.
I would talk to all the players, not with the DM there, and see if they also feel like some players are being favored over others. Similar to talking to your DM, make sure this isn't accusatory. The idea isn't to blame the favored guys, but just to see if everyone feels the same imbalance you do, and most importantly, see if everyone's having fun.
You may want to speak with just the non-favored players as presumably the favored ones are having fun. I would caution against having the talk devolve into DM-bashing, but it might give you a chance to see if they're willing to stand with you about being treated un-equally.
If you're the only one not having fun then you might need to either deal with it (not great) or leave the game (also not great). However, you may find that you're not the only frustrated one.
If multiple people agree with you that's good evidence to bring to your DM. Maybe you need to start a new campaign with everyone on the level, or maybe you even need to find a different DM and those of you who aren't happy can start your own game.
If the group's going to work out
If you've talked to your DM and the other players and everyone agrees there's a problem and wants to fix it, this is a great time to try the same page tool during a Session 0.
Basically, have an interlude session where you can all make sure you're playing the game for the same reasons and establish some boundaries such as Don't Split The Party. You can then start over with a blank slate and hopefully have a much better game.
If the group isn't going to work out
If instead the DM didn't see any issues with the current setup and some of the players were totally happy with the game you have three options.
Option One: Stay
If everyone else is happy with the current setup, you could stay with them.
I would recommend this one the least, to be honest. Unsurprisingly, it's not fun to stay in a group where you aren't having fun. But if you really want to play, can't find or start another group and are willing to put up with the behavior this is technically an option.
Option Two: Leave
If one or two people expressed dissatisfaction but nothing is changing, leave.
There's no sense staying in an activity you aren't enjoying. However, that doesn't mean you have to stop playing! Maybe there's another group you can join with a friend or two, or an Adventurers League you can join.
Option Three: Start your own game
If several people aren't happy with the game, you can always start your own!
If you don't have someone immediately willing to be the DM there are plenty of groups that do rotating DMs so no one person has to be the DM all of the time. Start your own group and play D&D the way you want to play it. You can always schedule it at a different time than the other game so players can be in both if they want to.
In Conclusion
Not every group is going to be a good fit for you as a player. It's okay to leave if you aren't having fun, but I would encourage you to talk to your DM and other players first. It's totally possible that this group is salvageable with a little legwork and patience. Either way, don't get discouraged from playing D&D and other tabletop RPGs!
Additional food for thought
Knowing that your DM is a teacher in your school and still seems to be favoring specific players, I'd like to offer the following personal experience.
When I was somewhere in the 11-12 range I joined an after school board game group at my school that was run/hosted by one of the 6th grade teachers. The participants were mostly a mix of misfits looking for an after school activity to keep them occupied, and then there was "Neal". Neal was a huge troublemaker in class and constantly getting scolded for behavior and academic shortcomings. He was loud, jittery and had trouble keeping his attention and his limbs to himself. He got pulled out of class a lot for academic help and didn't have any friends.
In the game group his behavior wasn't much better; he talked over people and had trouble remembering when it was his turn. The teacher didn't do more than the bare minimum to rein him in; Neal often got first pick of games and I even remember him turning a blind eye to Neal accidentally cheating now and again.
I remember going home to my mom and complaining that Neal was getting unfair treatment. My mom wisely pointed out that Neal was having a hard time socially, and that this game group sounded like somewhere he could have fun and be included in things. She cautioned me that maybe the game group was the only place he could fit in and that I should try to be more welcoming.
Obviously I know nothing about the favored players in your group, but there's a chance this might be a similar situation and the teacher is intentionally favoring those kids to give them a positive social experience. It might be worth thinking about when you broach this topic with your DM and the other players.