Per IRS Publication 17, Tax Guide for Individuals, page 160:
If you are covered under social security (or if you are a government employee who paid Medicare tax), you are enrolled in Medicare A. The payroll tax paid for Medicare A is not a medical expense.
If you are not covered under social security (or were not a government employee who paid Medicare tax), you can voluntarily enroll in Medicare A. In this situation you can include the premiums you paid for Medicare A as a medical expense.
Medicare B is supplemental medical insurance. Premiums you pay for Medicare B are a medical expense. Check the information you received from the Social Security Administration to find out your premium.
Medicare D is a voluntary prescription drug insurance program for persons with Medicare A or B. You can include as medical expenses premiums you pay for Medicare D.
See IRS Publication 17 Your Federal Income Tax (For Individuals) for more information.
To enter or review information from Form SSA-1099, including Medicare Parts B and D premiums:
To enter Medicare Parts B and D premiums not reported on Form SSA-1099: