Lets take a general situation:
Let a chain of mass M and length L is held on a frictionless table in such a way that
The portion hanging from the table is
Now,let Potential energy (U)
Potential energy initial
hanging portion from centre of mass]
For regularly shaped uniform bodies, P.E change can be calculated by considering their mass to be centered at the geometrical point.
Therefore required work done