If a public way where the tracks of a company have been located for a period of five years is altered, or if the grade thereof is changed under chapter eighty or eighty-two, the company shall pay such proportionate share of the expense thereof, including therein the necessary cost of changing its railway to conform to such alteration or change of grade, as may be assessed upon it, provided that, if betterments are assessed, no such assessment on the company shall exceed the aggregate amount of all the betterments assessed upon real estate, and that in no case shall such assessment exceed one quarter of the total cost of such alteration or change of grade.
Mass. Gen. Laws ch. 161, § 79