The office of mental health and the office for people with developmental disabilities shall provide the same education for patients in office of mental health hospitals and residents in office for people with developmental disabilities schools who are between the ages of five and twenty-one which they would otherwise be entitled to receive in their local school districts pursuant to article eighty-nine of the education law. The cost of such education shall be a charge upon and shall be paid by the office of mental health or the office for people with developmental disabilities when received within such a hospital or school by a patient or resident therein. Such education shall be adapted to the mental attainments of such children. Provided, however, that such children as can benefit therefrom shall be admitted to the schools of the school district in which such hospital or school is located in accordance with regulations of the commissioner of education developed in consultation with the commissioners of mental health and developmental disabilities. The cost of such instruction less the state aid attributed to such child, shall be a charge upon the school district in which the child resided at the time of admission to the state hospital or school, except in those cases as provided in paragraph c of subdivision five of section thirty-two hundred two of the education law.