AFTER half an hour of pencil-chewing Lizeka Rantsan’s class lines up at her desk to hand in its maths tests. The teacher at Oranjekloof primary school in Cape Town thanks the 11- and 12-year-olds and flicks through the papers. Ms Rantsan sighs, unimpressed. Pulling one sheet of errant scribbles from the pile she asks: “How are we supposed to help these children?”

It is a question that South Africa is failing to answer. In a league table of education systems drawn up in 2015 by the OECD club of mainly rich countries, South Africa ranks 75th out of 76. In November the latest Trends in International Mathematics and Science Study (TIMSS), a quadrennial test sat by 580,000 pupils in 57 countries, had South Africa at or near the bottom of its various rankings (see chart), though its scores had improved since 2011. Its children are behind those in poorer parts of the continent. A shocking 27% of pupils who have attended school for six years cannot read, compared with 4% in Tanzania and 19% in Zimbabwe. After five years of school about half cannot work out that 24 divided by three is eight. Only 37% of children starting school go on to pass the matriculation exam; just 4% earn a degree.

South Africa has the most unequal school system in the world, says Nic Spaull of the University of Stellenbosch. The gap in test scores between the top 20% of schools and the rest is wider than in almost every other country. Of 200 black pupils who start school just one can expect to do well enough to study engineering. Ten white kids can expect the same result. Many of the problems have their roots in apartheid. The Bantu Education Act of 1953 set out to ensure that whites received a better education than blacks, who were, according to Hendrik Verwoerd, the future prime minister then in charge of education, to be educated only enough to be “hewers of wood and drawers of water”. Black pupils received about a fifth of the funding of white peers. They were taught almost no maths or science. Most independent church-run schools that provided a good education in black areas were shut. After Nelson Mandela became president in 1994 his government expanded access to schooling. It also replaced a school system segregated by race with one divided by wealth. Schools in poorer areas receive more state funding. But schools in richer areas can charge fees on top. In theory these schools must admit pupils even if their parents cannot afford the fees. In practice they are fortresses of privilege. There are still about 500 schools built from mud, mainly in the Eastern Cape. The Western Cape has some of the largest campuses in the southern hemisphere, with cricket pitches as smooth as croquet lawns.

And yet money is not the reason for the malaise. Few countries spend as much to so little effect. In South Africa public spending on education is 6.4% of GDP; the average share in EU countries is 4.8%. More important than money are a lack of accountability and the abysmal quality of most teachers. Central to both failures is the South African Democratic Teachers Union (SADTU), which is allied to the ruling African National Congress (ANC).

The role of SADTU was laid bare in a report published in May 2016 by a team led by John Volmink, an academic. It found “widespread” corruption and abuse. This included teachers paying union officials for plum jobs, and female teachers being told they would be given jobs only in exchange for sex. The government has done little in response. Perhaps this is unsurprising; all six of the senior civil servants running education are SADTU members.

The union’s influence within government belies its claim that officials are to blame for woeful schools. Last year it successfully lobbied for the cancellation of standardised tests. It has ensured that inspectors must give schools a year’s notice before showing up (less than 24 hours is the norm in England). And although parent-led school governing bodies are meant to hold teachers to account, they are more often controlled by the union, or in some cases by gangs.

But even if there were better oversight most teachers would struggle to shape up. In one study in 2007 maths teachers of 11- and 12-year-olds sat tests similar to those taken by their class; questions included simple calculations of fractions and ratios. A scandalous 79% of teachers scored below the level expected of the pupils. The average 14-year-old in Singapore and South Korea performs much better.

It does not have to be this way. Spark School Bramley in Johannesburg is a low-cost private school, spending roughly as much per pupil as the average state school. And it is everything state schools are not. Its 360 pupils begin learning at 7.30am and end around 3pm-4pm; most state schools close at 1.30pm. At the start of the day pupils gather for mindfulness exercises, maths questions, pledges to work hard—and a blood-pumping rendition of Katy Perry’s “Firework”. “We have an emotional curriculum as well as an academic one,” says Bailey Thomson, a Spark director.

Pupils attend maths lessons based on Singapore’s curriculum; literacy classes draw on how England teaches phonics. Crucially, teachers are not members of SADTU. But they receive 250 hours of professional development per year, about as much as the average state-school teacher gets in a decade.

Early results show that its pupils are on average a year ahead of their peers. Spark runs eight schools and plans to have 20 by 2019. Other operators, such as Future Nation, co-founded by Sizwe Nxasana, a former banker, are also expanding. “We are never going to have a larger footprint than [the] government but we can influence it,” hopes Stacey Brewer, Spark’s founder.

Another promising scheme is the “collaboration schools” pilot in the Western Cape, based on academies in England and charter schools in America. The five collaboration schools are funded by the state but run by independent operators. In what Helen Zille, the premier of the Western Cape, calls “a seminal moment”, the parents of Oranjekloof pupils petitioned to keep the school in the collaboration programme when unions tried to oppose it. Ms Zille wants to open a “critical mass” of collaboration schools to inject competition into the public system.

Spark and the collaboration schools suggest that South African education need not be doomed. But together they account for a tiny fraction of the country’s more than 25,000 schools. Widespread improvement will require loosening the grip of SADTU. In local polls in August the ruling party saw its worst results since the end of apartheid. This may force it to review vested interests. More likely it will continue to fail children. “The desire to learn has been eroded,” says Angus Duffett, the head of Silikamva High, a collaboration school. “That is the deeper sickness.”