#abc167b. [abc167_b]Easy Linear Programming

[abc167_b]Easy Linear Programming

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.
  • 0leqA,B,C0 \\leq A, B, C
  • 1leqKleqA+B+Cleq2times1091 \\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.


Sample Input 1

2 1 1 3

Sample Output 1

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.


Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000