Some of the energy a weight generates as it falls is going to be consumed to overcome the inertia of the structure holding it along with other weights in addition to frictions. Do you consider that work (overcoming inertia and friction) to be part of the equation?
Congratulations. You've just stumbled upon one reason why perpetual motion is impossible. Parasitic losses due to things like friction.