A group of inmates in a Brazilian high-security jail, clad in red prison uniforms, pedal furiously on stationary exercise bikes.

Guards watch over them as they eat up the virtual kilometres.

The prisoners are not just cycling to keep fit: they are doing the local community a good turn, and by doing so get to reduce their sentences.

How? As they pedal, the inmates generate electricity which helps light the town at night.

Ronaldo da Silva is serving a five-and-a-half year term for holding up a bakery.

“Here, by cycling, we feel more important and more useful,” he says. “You feel better day-to-day.”

The scheme was the idea of a local judge. Businesses and police helped make it work.

“With our project, the idea is that they can now exercise, lose weight and at the same time it also benefits them because after every three days of work, their sentence shortens by one day,” said Prison Director Gilson Rafael Silva.

Each night the charged battery is used to light up the riverside promenade at Santa Rita do Sapucai in the mountains north of Sao Paulo. Long abandoned after dark, the area has been brought back to life.