The sum-product theorem and applications