YAKAWLANG, Afghanistan — The girls began appearing about seven in the morning. Seen from a distance, they made up thin blue lines snaking across the barren tan mountainside along narrow trails traced in the dirt, converging from several directions on the little school in the bottom of the valley.
Wearing powder blue school uniforms and white head scarves, many of the girls, ages 7 to 18, had already been walking for an hour or more by the time they arrived at the school. There were smaller groups of boys, too, mostly out of uniform, walking apart from the girls.
By 7:45, they were all gathered for assembly in the yard of the Rustam School, in a remote corner of Afghanistan’s Yakawlang District. It is the area’s only high school, years 1 through 12, and has an enrollment of 330 girls and 146 boys — astonishing in a country where normally only a third of girls attend school.
The principal, Mohammad Sadiq Nasiri, 49, gave his daily pep talk: Getting into university is going to be harder than ever this year, so they are going to have to do better than ever.
Rustam may seem an unlikely place to encourage collegiate dreams. With seven crude stone classrooms, supplemented by six big tents, there are so many students that they are divided into morning and afternoon sessions only four hours long.
There is no electricity, heat, working computers or copy machines. Many school materials are written out in longhand by teachers. Foreign aid once helped but has dried up. One teacher said she has fewer books than students.
Only 5 percent of the students have parents who can read and write, Mr. Nasiri said. Most are the children of subsistence farmers.
Yet Rustam’s 2017 graduating class saw 60 of 65 graduates accepted to Afghanistan’s public universities, a 92 percent college entrance rate. Two-thirds of those accepted were girls. A couple of years earlier, 97 percent of the graduates went to college.
Unlike most Afghan schools, Rustam mixes boys and girls in its classrooms. “Men and women are equal,” the principal said. “They have the same brains and the same bodies.”
He added, “We tell these boys and girls, there is no difference between you guys, and you will all be together when you go to college, so you need to learn how to respect one another.”
One day late in the spring term, Badan Joya, one of five female teachers among the school’s 12, was teaching a fourth-grade math class in one of the overflow tents. A piece of cardboard painted black served as a chalkboard, with simple algebra formulas scribbled on it. She asked her students, nearly all girls, to name their favorite subject. They chorused: “Math.”
That is not surprising at Rustam; 40 percent of questions on the college entrance exams cover mathematics, more than any other subject. And the girls excel.
The head student in 11th-grade math, based on test scores, is Shahrbano Hakimi, 17. Ms. Hakimi is also head student in her computer class, where, on that recent day, the girls were studying the Windows operating system, from books. Only one of the 60 students had a computer at home.
“The thing I wish for most in the world,” Ms. Hakimi said, “is a laptop.”
When the Taliban ruled Afghanistan, girls’ education was banned and women were mostly confined to their homes, especially in rural areas like this one in Bamiyan Province.
The local passion for education, especially among girls, is a reaction to that era, their teachers said. The fourth-grade math teacher, Ms. Joya, who is 28, did not begin school herself until the Taliban fell when she was 11; she could not read or write, and her only schooling had been sewing class.
“I had to start from zero,” she said. “We tell them about the Taliban and what they did to us, and say, ‘You have an opportunity now, you should take it,’” she said. “They’re listening. They hear about it at home, too, from their mothers and aunts.”
The area around Rustam is now free of Taliban and little touched by violence. In other places, families are reluctant to send girls to school, especially over long distances in rural parts.
The girls at Rustam are highly motivated. “Honestly, girls are better than boys, they are more serious,” Mr. Nasiri said. “These kids all know that you can’t make a slave out of someone who is educated.”
Except in Islamic studies, nearly all head students are girls.
Amina, “nearly 18,” who uses one name, is head girl of the entire school. She is fortunate, she said, because her father is educated, though her mother is illiterate.
She will be the first of eight siblings to finish high school and hopes to go to Mawoud Academy in Kabul, a college preparatory school, even though she knows that 40 students were killed there recently by a suicide bomber.
Amina’s favorite subject is math; she hopes to become a doctor.
Ms. Hakimi also dreams of becoming a doctor, in part because her mother suffers vision problems and her father is nearly deaf at age 65. Both are illiterate.
Outside their mud-walled home, a water wheel on a nearby irrigation ditch turns a small generator, just enough to power lights at night, for studying.
“I’m not educated,” said her father, Ghulam Hussein. “I’m just a farm laborer. I don’t want them to have the same life.” Of his 11 children, a son and two daughters have already reached college.
“I am so proud of them,” said Zenat, Ms. Hakimi’s mother.
Their family is also an example of why fewer boys are in school. Their son Ali, 9, stays home to help his parents, while their son Reza, 12, works in the fields. “Ali wants so badly to go to school,” Zenat said. “Maybe next year.” All the daughters, though, are in school.
One day Mr. Nasiri, the principal, noticed one of his students, 13-year-old Friba, hiding behind other girls during assembly because she was out of uniform. Her family was too poor to buy one. So he bought a swatch of blue cotton in the nearest bazaar; Ms. Joya, the math teacher, sewed a tunic from it, using her Taliban-era skills.
Mr. Nasiri borrowed the money for the cotton. He earns less than $200 a month.
In addition to running Rustam the past six years, Mr. Nasiri supported four daughters and two sons with his wife, Roya, 45. They married during Taliban times; he taught his wife to read and write.
“We discussed it and decided she should go to school,” he said. “Children will do better when their mom is educated.”
Their eldest daughter finished high school four years before her mother. This year Roya graduated from high school, and next year will take the college entrance exams, Mr. Nasiri said proudly. “She raised six children,” he said. “Now she raises herself.”
Hundreds of feet up a rocky mountainside opposite Rustam, sheep grazed, watched by shepherds. One of the shepherds wore a blue dress, much like a school uniform, but covered in dust. Her name is Nikbakht, she said; she is 13. She carried a pen and a workbook for the Pashto language.
“I love school, but no one else was home so I had to work with the animals.”
Pashto, a required subject, is not her favorite, Nikbakht said. Math is.