He couldn’t buy his freedom — but he could buy vending machine snacks, the “friendship” of fellow inmates, and hours on end away from his cell meeting with lawyers.

Millionaire pedophile Jeffrey Epstein spread his wealth around as much as he could in the month before he committed suicide on Aug. 10 at the federal Manhattan Correctional Center, The New York Times reported Saturday.

Epstein deposited money in at least three other inmates’ commissary accounts in an attempt to ingratiate himself and possibly buy protection from the hardened criminals in the MCC’s Special Housing Unit, where he awaited trial on a massive underage sex trafficking indictment, outlet reported.

To escape the misery of his damp, mouse and roach infested cell, the disgraced money manager would pay a staff of lawyers to meet for up to 12 hours at a time in a private attorney-client meeting room.

His entourage would routinely empty the two adjacent vending machines of drinks and snacks.

“It was shift work, all designed by someone who had infinite resources to try and get as much comfort as possible,” a lawyer who was often in the jail visiting clients told the outlet.

At times, at least, the perks worked to lift his spirits.

A lawyer who met with Epstein in early August claimed he was “very very upbeat” — an account that jibes with what sources told The Post about his spirits in the days before he apparently killed himself.

Attorney David Schoen told paper he met with Epstein for roughly five hours, and had expected to join his legal team.

“One thing I can say for sure is when I left him he was very, very upbeat,” said Schoen, who was ultimately never hired.

But in the week before his death, Epstein appeared more and more haggard and unkempt, lawyers and prison staff told The Times.

“He’s deprived of communication with third parties, looked disheveled, sleeping on the floor sometimes,” one lawyer told the paper.

He spent his last day sitting for hours with his lawyers, and would have been well aware that a court had that day released a damaging trove of some 2,000 pages of documents from a prior defamation lawsuit by one of his accusers.

Then, back to the dankness and vermin of his cell, which The Times said was positioned so that a small window would have allowed Epstein to see if the guards tasked with monitoring him were awake or — as prison officials now charge — asleep.

The city Medical Examiner’s Office has concluded his death was a suicide.

On Saturday, Epstein’s former attorney Alan Dershowitz told The Post that despite the murder conspiracies swirling around the pedophile’s death, he is certain his former client just gave up. “I think he killed himself because he didn’t want to spend the rest of his life in prison,” Dershowitz said.

“He did a cost-benefit analysis, and thought he’d be better off dead.”

Additional reporting by Laura Italiano