New species P76309


Statement
 

pdf   zip

thehtml

Two new animal species, X and Y, have just been discovered in a remote place. Although all those animals can survive by only eating vegetables, it has been found that some of them also like eating X, or Y, or both. Several individuals have been captured, and they must be transported for their study. Knowing the food habits of every individual, how many cages are needed to separate the animals so that no animal eats another animal?

Input

Input consists of several cases, each one with eight integers X00, X01, X10, X11, Y00, Y01, Y10 and Y11 in this order. They are, respectively, the number of X that do not eat X nor Y, the number of X that do not eat X but eat Y, …, the number of Y that eat X but do not eat Y, and the number of Y that eat both X and Y. Asume that all numbers are between 0 and 108.

Output

For every case, print the minimum number of (arbitrarily large) cages needed to separate the animals so that no animal eats another animal.

Public test cases
  • Input

    0 0 0 1 5 0 0 0
    1 2 1 0 0 2 1 0
    0 0 0 0 1 1 1 1
    

    Output

    2
    4
    3
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python