A piston of mass M is hung from a massless spring whose restoring force law goes as , where k is the spring constant of appropriate dimension. The piston separates the vertical chamber into two parts, where the bottom part is filled with 'n' moles of an ideal gas. An external work is done on the gas isothermally (at a constant temperature T) with the help of a heating filament (with negligible volume) mounted in lower part of the chamber, so that the piston goes up from a height to , the total energy delivered by the filament is (Assume spring to be in its natural length before heating)

Since the gas is heated isothermally,
(for ideal gas internal energy depends only on temperature)
So heat supplied by filament equals work done by gas:
Total work done by gas has two parts:
At equilibrium initially,
where A is piston area.
Gas expands from height to
Change in volume:
Work against piston weight:
Spring force law:
Initially spring is natural length, so initial extension
x=0
Final extension:
Work stored in spring:
Also because process is reversible isothermal,
with
so
This is the expansion work of ideal gas.
Hence total energy supplied by filament
Tagged Zeroth and first law of thermodynamics. Machine-assigned, so read it as a strong shortlist rather than a verdict.