Can't comment on the maths.
But as an example, say the Gov get 50% of the cost of each packet (£5) in tax.
So if I start smoking 20 a day at 16 and die at 65, this is approx £45K in tax the Gov get off me.
But some treatments for cancer are very expensive I'm sure, so I would say the tax they get wouldn't cover the cost of treatment.
But then again not all smokers die of cancer related illness. Some are hit by buses or die of other things!!
But as you say, we all have to die of something. And that something is likely to involve expensive treatment whether you smoke or don't. It is just a question of when.
You smoke, get cancer, get expensive treatment and die in your sixties. Your productive years were mostly behind you and you are no longer a burden to the state. Plucking numbers out of the air, say that it costs £100 - 150 grand to go through motions of treating you minus your smoking tax contributions £50k+. The state is £50k to £100k in the hole.
You don't smoke, you live to 85-90, state pension expenses, state-funded retirement home expenses, debilitating illness or cancer costs as above but with no ciggie tax contribution. It seems to me that the state would be substantially deeper in the hole.
I don't know the math either, but the second scenario would seem more expensive. When Bismark cynically set the retirement age at 65 it was because German working men died on average well below that. Now we get to sit in God's waiting room for another 20+ years. Surely the government doesn't want us to linger around for too long, so why all this encouragement to stop smoking?