Time limit
2s
Memory limit
128 MB
Rock Dongho is choosing songs for a new album. Each song has a starting tempo and an ending tempo, and each tempo is either fast (F) or slow (S). There are FF songs that start fast and end fast, FS songs that start fast and end slow, SF songs that start slow and end fast, and SS songs that start slow and end slow.
Each selected song may appear on the album at most once. The order of songs must satisfy the following conditions.
Find the maximum number of songs Dongho can put on the album while satisfying all conditions.
The first line contains four integers FF FS SF SS in that order. Each integer is between 0 and 1,000 inclusive, and at least one of them is positive.
Print the maximum number of songs Dongho can put on the album while satisfying the conditions.