Tom buys 20 shares of a stock that costs $3 each.  He sells 10 of those shares for $4 each.  The rest of the shares end up doubling in value.  How much profit does he make?
He spends 3*20=$
<gadget id="calculator">3*20</gadget>
<output>60</output>
60 on the shares.
He sells 10 for 10*4=$
<gadget id="calculator">10*4</gadget>
<output>40</output>
40.
He sells the other 20-10=
<gadget id="calculator">20-10</gadget>
<output>10</output>
10 for a higher valuation.
Their price was 3*2=$
<gadget id="calculator">3*2</gadget>
<output>6</output>
6.
So he got 10*6=$
<gadget id="calculator">10*6</gadget>
<output>60</output>
60 from those.
So in total, he got 60+40=$
<gadget id="calculator">60+40</gadget>
<output>100</output>
100.
So his profit was 100-60=$
<gadget id="calculator">100-60</gadget>
<output>40</output>
40.

<result>40</result>