100 #ABC167B. [ABC167B] Easy Linear Programming

[ABC167B] Easy Linear Programming

Score : 200200 points

Problem Statement

We have AA cards, each of which has an integer 11 written on it. Similarly, we also have BB cards with 00s and CC cards with 1-1s.

We will pick up KK among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

  • All values in input are integers.
  • 0A,B,C0 \leq A, B, C
  • 1KA+B+C2×1091 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

AA BB CC KK

Output

Print the maximum possible sum of the numbers written on the cards chosen.

2 1 1 3
2

Consider picking up two cards with 11s and one card with a 00. In this case, the sum of the numbers written on the cards is 22, which is the maximum possible value.

1 2 3 4
0
2000000000 0 0 2000000000
2000000000