>>1558437>>1558442In the case of San Francisco, all those houses could be upzoned and built much larger. In the case of Manhattan, it still has managed to fit nearly 2 million people on a single island, dwarfing San Francisco.
The demand is high, so the price is going to be high as well. That's why you need housing that's not subject to market forces, like public housing.