Section 25. When any public way has been constructed or improved in whole, or in part, with money furnished by the commonwealth, and the way is not laid out as a state highway, the town in which the way lies shall thereafter keep and maintain in good repair and condition that part of the way which has been so constructed or improved; and the expense thereof shall be borne by the town or county, or both, as may be agreed upon at the time such construction or improvement is undertaken, except as otherwise provided in section twenty-six of this chapter and in paragraph 2(a) of section thirty-four of chapter ninety. If the department shall determine at any time that such way is not being maintained in proper condition, it shall so notify the mayor or selectmen having charge of the repairs of said way and the county commissioners, and shall specify in said notice what repairs and improvements are necessary; and the officials in charge of the way shall forthwith proceed to make the specified repairs and improvements. If said officials do not make such repairs or improvements within fifteen days from the receipt of such notice, or within such further time as the department may allow, the department may proceed to have the repairs or improvements made, and may pay for the same from any money which may be available for the repair and maintenance of state highways. The department shall annually, in January, certify to the state treasurer the amount of such expenditures during the preceding year. So much of the expenditures as by agreement are to be paid by the towns shall be made a part of the state tax for such towns; and so much of the expenditures as by agreement are to be paid by the counties shall be paid by the county treasurers to the state treasurer. The department may embody the provisions of this section in all contracts and agreements for work to be done in the construction or improvement of public ways, other than state highways, constructed or improved in whole, or in part, with money furnished by the commonwealth.