During a complete cycle, the gas returns to its original state of temperature, pressure and volume the energy added to the system must be offset by energy that leaves the system for the system to return to its original state.
During a complete cycle, the gas returns to its original state of temperature, pressure and volume, hence the energy change of the system (gas) is zero. As a result the energy added to the system must be offset by energy that leaves the system for the system to return to its original state.