Deductions & credits

Thanks much!! and just to understand it better, the "gains" means the benefit (sale price - buying price) or gains means whatever price I sold the house for?

Also, I had to sell it because of the visa status as I couldn't stay in United States. and I don't see any clause of that anywhere?