An octopus has 8 tentacles and 1 head. A jellyfish has 20 tentacles and no head. A cow has 4 legs and 1 head. Farmer Brown, who only raises octopi, jellyfish and cows on her farm, has animals with a total of 17 heads, 196 tentacles and 40 legs. How many animals does she have?