Section 161. Any city, except Boston, by vote of its city council, and any town by majority vote of the voters thereof present and voting thereon at a town meeting, may, from time to time, for the purpose of avoiding a reduction or discontinuance of service, enter into an agreement with a street railway company operating a street railway therein to pay any part or all of any excess of the cost of the service on the lines of the company operated in such city or town above the amount of the receipts from such lines arising from the rates and fares in effect thereon during the period covered by any such agreement; provided, that no contribution under said agreement shall in any year exceed in such a city the sum of one dollar, or in such a town the sum of two dollars, for each one thousand dollars of the assessed valuation of the year preceding the date of such agreement, and in no event shall it exceed one thousand dollars in any year unless the payment of any such excess is first approved by the department. The department shall, upon application of any city or town agreeing as aforesaid, determine any question relating to the character or extent of the service rendered or facilities furnished in such city or town in pursuance of said agreement, in the event of differences arising between the street railway company and such city or town in relation thereto. Any such city or town may raise by taxation such amounts as may be necessary to carry out the provisions of this section. This section shall not apply to the Boston Elevated Railway Company.