talk to your accountant but my understanding is the losses needs to be deducted from the gross gain before you reduce the gain by 50%.