The last moments before one of the biggest competitive upsets in recent U.S. history wound down in a hotel atrium in Chiang Mai, Thailand, with children compulsively refreshing a blank web page.

Across town at an entirely different hotel, Po-Shen Loh, Carnegie Mellon math professor and head coach of the U.S. team at the 2015 International Mathematical Olympiad, was running late.

“One of the benefits of running behind, the gossip has already been spread around,” Loh tells Inverse. “And I’m hearing, ‘The U.S. is in the lead,’ which is a rare thing since we’re usually running second and third, not far behind, but there’s a gap. I mean, China has four times as many people so if they’re trying to field a team of six kids it’s a lot easier.”

The annual Olympiad is a two-day contest bringing together students from more than 100 countries to attempt to unravel just three problems, some of the most difficult a student could confront pre-college. Just cracking one would qualify you as a genius of calculation. It takes three days of discussion among the coaches and observers afterwards to be sure the myriad languages are being deciphered correctly (ideally, there are are more than a few people handy with a solid grasp of Arabic). At least the judging, Loh says, allows the luxury of time.

Once the scores are ranked, the results are released by posting to the Olympiad site, where everyone can see them simultaneously. Loh knew there was a winner when the screaming started.

“Just people going crazy around me, and I’m not even with the kids,” Loh says. “The way I was told, they were screaming so loud they heard them all the way up on the eleventh floor of their hotel.”

The U.S. team’s gold score was 185 points. China took second with 181 points; South Korea nailed third with 161 points. It was the fifth-ever victory for the United States; China (19), the U.S.S.R. (14) and Hungary (six) are the only countries with more.

The victory was a rebuke to conventional wisdom that U.S. students lag behind their foreign counterparts in algebra and geometry, so much so that media rushed to anoint it the academic equivalent of the U.S. Hockey Team’s 1980 “Miracle on Ice.”

“The win was all over the Chinese news. ‘We lost to the Americans?!” What happened here? How could they beat us?’” Loh says. “And, really, the thing is this is kind of an American ideal of going out and pursuing what makes you happy. Because, we’re in this day and age where if you really want to do something there are so many ways to learn about it. There’s a kid from South Carolina, a kid from Kansas, a New Jersey kid, a Connecticut kid. These aren’t the product of some elite education system; it’s people who are really really interested in math.

“The future of all education is not just the classroom component but the online component that’s going to strap rocket engines on. It’s not just that anyone can watch a Harvard lecture, it’s the peer-to-peer communication. These kids are training each other.”

None of the students on this year’s championship team responded to interview requests. But here’s how the American Dream Team came together.

According to competition organizer and Director of the Center for Mathematical Talent at Courant Mark Saul, the whittling down process begins with a series of regional math competitions across the nation. Out of an initial pool of approximately 180,000 students, the pool is narrowed over a series of increasingly difficult exams until finally only 500 are invited to the U.S. Junior Math Olympiad. Of those prodigies, just the top six will be invited to take a seat on the Olympiad’s team.

“They’re all-American kids,” Saul says. “Articulate, smart. But they’re kids. They eat at McDonalds, learn to drive at 17, and they call themselves dude. That’s what they have in common most. The other thing is that they love math. You don’t need to be mature to have insight in math.

“A typical summer program, they’re all meeting each other and the icebreaker is math. I’ve worked with a lot of gifted kids. Being a nerd is a defense they sometimes crawl into because they’re singled out by other kids. Minority kids and girls, they don’t want to stand out. When they get together with kids like them, they shed that very quickly. They come in and try and boast to each other about what they’ve achieved. And whatever they’ve achieved, someone’s achieved more. You can see the defenses in their faces just drop away. Like ‘Oh, I can just be a kid.’”

A training program for the final team runs more than three weeks, but after there are months of waiting around for the competition to start. They retreat to schools of varying quality, but keep honing each other and finding ways to study online. If this were a sports movie, this would be the montage of late nights crushing Mountain Dew cans as they crumple up pages scrawled with equation after equation.

When the team finally arrived in Thailand, Loh says he was told the questions were particularly hard this year. The best thing he could do was try not to stress the team. Loh’s biggest challenge is navigating the scoring process.

“Everyone’s very civil. If you aren’t civil to some people they won’t be civil to you. At the end of the day, I agree on a score and we sign off on it,” he says. “Sometimes people want to get into it over scores they think are too low. It’s hard to be specific about it without dumping a huge pile of context. It’s like any other negotiation. I use the line, ‘Look, we’re not trying to buy a used car here, we’re doing math.’”