Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if C == 0:
    print(A)
else:
    resultList = [ A - c for c in range(C + 1 // 2) if c == K - A - B]
    print(max(resultList))


Fixed submission:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
resultList = [ A - c for c in range(C + 1) if c == K - A - B]
print(max(resultList))


Fixed submission:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
temp = None
for c in range(C + 1):
    if (c == K - A - B):
        if (temp is None):
            temp = A - c
        else:
            if (temp < A - c):
                temp = A - c
print(temp)


Fixed submission:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
temp = None
for a in range(A + 1):
        for c in range(C + 1):
            if (a + c == K - B):
                if (temp is None):
                    temp = a - c
                else:
                    if (temp < a - c):
                        temp = a - c
print(temp)

Fixed submission:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
temp = None
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if (a + b + c == K):
                if (temp is None):
                    temp = a - c
                else:
                    if (temp < a - c):
                        temp = a - c
print(temp)


Fixed submission:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
resultList = []
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if (a + b + c == K):
                resultList.append(a - c)
print(max(resultList))


Fixed submission:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)