Let m gram of ice is added. From principal of calorimeter heat gained (by ice) = heat lost (by water) $\begin{array}{l}
\therefore 20 \times 2.1 \times \mathrm{m}+(\mathrm{m}-20) \times 334 \
=50 \times 4.2 \times 40 \
376 \mathrm{~m}=8400+6680 \
\mathrm{~m}=40.1
\end{array}$