Retirement tax questions

Thank you.  So in this example, If tuition was $25,000 and room and board was another $15,000 and I physically paid $25,000 and scholarship covered $15,000, how much is allowable toward avoiding the IRA penalty -- $25,000 or $40,000?