Amplification of terahertz radiation in quantum cascade structures