If it’s a sudden weight gain, I discount the calories, because it’s sudden. If you are putting on 2lbs/week consistently and then, out of nowhere, your weight goes up by 100lbs, it’s probably not due to diet.
Of course, a proper maintenance diet will be part of it. However, if there are medical causes behind it, controlling the calories will not do the trick.
If one of us gains 100 lb, either in a week or a year, it comes from something..
Unless one can receive nourishment from suppositories, the energy/mass comes down the gullet.
The existing body cannot get heavier (retaining water not withstanding) without additional mass down the throat.