There are A red socks, B green socks and C Yellow socks in a dark room. Ashwin wants to find N pairs of matching colored socks from the dark room. Given all A, B and C are even and N ≤ (A+B+C)/2, write a program that outputs how many socks Ashwin would have to draw from the dark room in the worst case, to have exactly N pairs.

  1. Input Format

First line contains three space separated integers: A, B and C.

Second line contains the number of pairs Ashwin wants: N

  1. Output Format

Single line containing a single integer which is the count of socks needed to draw in the worst case

  1. Constraints

0 ≤ A,B,C ≤ 106
0 ≤ N ≤ (A + B + C)/2

  1. Example

Input 1:
2 4 4
1
Output 1:
4

Input 2:
2 4 4
4
Output 2:
9

Input 3:
2 4 4
5
Output 3:
10

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.