There are 112 students in the fourth grade who took the Chinese and Mathematics exams, and each of them got an A in at least one subject. Among them, 65 people got A in Chinese, and 87 people got A in Mathematics. How many people got A in both subjects?
四年级有112人参加语文、数学考试，每人至少有1门功课得优，其中语文得优的有65人，数学得优的有87人，那么两门功课都得优的有多少人？
<gadget id="calculator">87 - 112</gadget>
<output>-25</output>

<gadget id="calculator">65 + (-25)</gadget>
<output>40</output>

<result>40</result>