More importantly, you are comparing all the services consumed by mentally ill homeless people in NYC with the homeless budget of the city of SF alone. Look at table 17 in the study [1]. Here is where those $40k came from:
$12,520 NY State Office of Mental Health
$11,596 Medicaid (inpatient)
$2,613 Medicaid (outpatient)
$6,229 NYC Health and Hospitals Corporation
$4,658 NYC Department of Homeless Services
$1,822 US Department of Veteran Affairs
$645 Department of corrections (city)
$368 Department of corrections (state)
Of these, only $11,532 came from the city.[1] http://repository.upenn.edu/cgi/viewcontent.cgi?article=1067...