According to Google you can stay in a hostel for about $350/2 weeks, which works about to about $10k a year. You'd probably be too broke to eat well, and have nothing left for activities.
With some more googling you can get an apartment for like 500-700€/month in madrid and if we say 700€ per month for living(should afford a relatively decent lifestyle in spain(apparently minimum wage there is ~1200€/month) so the ~30k€ after the flights and surgery seems reasonable to live for 2 years there.
Internet sources put the cost of living in spain to around 1000-1800€/month for one person
Fun fact, Did you know an entire American subculture of young people have grown up around the idea that they can fly to Spain to get their hip replaced? They don’t have a lot of money so they tend not to work and smoke a lot of weed they call themselves hippies because they plan to get their hips replaced in Spain.