When the switch is in position 1, the combination has C and C0 in parallel and C in series for which the equivalent capacitance is
Ceq=C(C+C0)2C+C0
The total charge on the combination is
Q=ECeq=EC(C+C0)2C+C0
The total charge on the three capacitors can be obtained as
q3=ECeq=EC(C+C0)2C+C0
q2=EC(C+C0)C0(2C+C0)(C+C0)=ECC2C+C0
q1=EC(C+C0)C(2C+C0)(C+C0)=EC22C+C0
When the switch is in position 2, the charge distribution on the three capacitors is obtained as
q′3=EC22C+C0,q′2=q2 and q′1=EC(C+C0)2C+C0
Now, heat produced = loss in stored electrical energy + extra energy drawn from the battery. Since the equivalent capacitance Ceq remains unchanged in both the position of the key, the loss in stored energy is zero.
Hence, Heat produced = energy drawn from the battery
=E.Δq=E(q′1−q′1)=E(q3−q′3)
=E[EC(C+C0)2C+C0−EC22C+C0]=E2CC02C+C0.