Hide

Problem K
Pairing

Two companies Alpha and Beta are preparing a joint large-scale operation. To conduct the operation, the joint board of directors needs to match all employees of two companies into pairs.

Each employee has a preference that is either to be paired with any of the colleagues from his company or to be paired with any of the employee from the other. If the employee is paired with an employee that is not suitable for his preference, then he will be uncomfortable.

Given the preferences of all employees, the joint board of directors wants to match the employees into pairs such that the number of uncomfortable employees is minimum.

Input

The input contains four integers $a$, $b$, $c$ and $d$ ($1 \leq a, b, c, d \leq 100$), where:

  • $a$ is the number of Alpha’s employees who want to be paired with any of the colleagues from their company;

  • $b$ is the number of Alpha’s employees who want to be paired with any of the employees from Beta;

  • $c$ is the number of Beta’s employees who want to be paired with any of the colleagues from their company;

  • $d$ is the number of Beta’s employees who want to be paired with any of the employees from Alpha.

It is guaranteed that $a + b + c + d$ is divisible by 2 (i.e. without remainder).

Output

Write out on one line the minimum number of uncomfortable employees.

Sample Input 1 Sample Output 1
1 1 1 1
2

Sample Input 2 Sample Output 2
2 1 2 1
0

Please log in to submit a solution to this problem

Log in