Community Health Systems agreed on Tuesday to buy Health Management Associates for about $3.6 billion in cash and stock, in a long-expected union of two for-profit hospital systems. Under the terms of the deal, Community Health will pay $10.50 a share in cash and 0.06942 of a share for each share of H.M.A. That values the takeover bid at about $13.78 a share, based on Monday's closing stock prices. Including the assumption of debt, the merger is valued at about $7.6 billion. H.M.A. shareholders will also receive what is known as a contingent value right, which could be worth up to $1 a share if the company manages to resolve certain legal disputes it faces.