def parse_reaction(line):
    """Parse line to tuple of product, amount of product and requirements."""
    required, producing = line.split(' => ')
    amount, product = [int(part) if part.isdigit() else part
                       for part in producing.split()]
    requirements = {}
    for requirement in required.split(', '):
        needed, chemical = [int(part) if part.isdigit() else part
                            for part in requirement.split()]
        requirements[chemical] = needed
    return product, amount, requirements