peterverebics/CodeNet_Python_118 huggingface dataset:
a, b, c, k = list(map(int, input().split()))
if k <= a:
    ans = k
elif k <= a+b:
    ans = a
else:
    ans = a - (k - a - b)
    
print(ans)
A, B, C, K =map(int, input().split())

ans = 0

if A <= K:
    ans = ans + A
    K = K-A
    if B <= K:
        K = K-B
        if C >= K:
            ans = ans - K
            print(ans)
    else:
        print(ans)
else:
    print(K)
A,B,C,K=map(int,input().split())
if A>=K:
    print(K)
elif A<K and A+B >= K:
    print(A)
else:
    print(1*A +(-1*(K-A-B)))
a, b, c, k = list(map(int, input().split()))

s = 0
if k <= a+b:
    s = min(k, a)
else:
    s = a - (k-a-b)

print(s)
a,b,c,k = map(int,input().split())
if a+b>=k:
    print(min(k,a))
else:
    print(a-(k-a-b))
a,b,c,k=map(int,input().split())
if a>=k:
	print(k)
elif a+b>=k:
	print(a)
else:
	k-=(a+b)
	print(a-k)
a,b,c,k = map(int,input().split())
print(min(a,k)-min(max(k-a-b,0),c))
A, B, C, K = [int(x) for x in input().split()]
print(min(K, A) - (min(K - A - B, C) if K - A - B > 0 else 0))
A,B,C,K=map(int,input().split())

if K<A:
    ans=K
elif A<=K and K<=A+B:
    ans=A
else:
    ans=2*A+B-K

print(ans)
A,B,C,K = map(int,input().split())

out = min(A,K) - max(0,K-A-B)
print(out)
# ABC167 B

def main():
    a, b, c, k = map(int, input().split())
    total = 0

    if a >= k:
        print(k)
    elif a+b >= k:
        print(a)
    else:
        print(a - (k - a - b))

if __name__ == '__main__':
    main()
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

a, b, c, k = map(int, input().split())

if k <= a:
    print(k)
    sys.exit(0)

ans = a
k = k - a

if k <= b:
    print(ans)
    sys.exit(0)

k = k - b
ans = ans - k
print(ans)
A, B, C, K = map(int,input().split())
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(2*A + B - K)
def calc(K,d,p):
    sum = 0
    if(K > d):
        sum = p * d
    else:
        sum = p * K
    
    return sum,d


def resolve():
    data = [int(i) for i in input().split()]
    sum = 0
    K = data[3]
    for i in range(3):
        add,count= calc(K,data[i],1 - i)
        sum += add
        K -= count
        if(K <= 0):
            break    
    print(sum)
resolve()
# coding: utf-8
# Your code here!

A,B,C,K=map(int,input().split())

ans=0

ans+=min(A,K)
K-=min(A,K)
K-=min(B,K)
ans-=min(K,C)

print(ans)
a, b, c, k = map(int, input().split())

if k <= a:
  print(k)
else:
  k -= a
  if k <= b:
    print(a)
  else:
    k -= b
    print(a + k * (-1))
def main():
    (A,B,C,K) = list(map(int, input().split(' ')))

    if K <= A:
        print(K)
    elif K <= A+B:
        print(A)
    elif K <= A+B+C:
        print(A-(K-A-B))
    else:
        print(A-C)

if __name__ == '__main__':
    main()
a, b, c, k = map(int, input().split())

if k < a:
  print(k)
elif k <= a + b:
  print(a)
else:
  print(a - (k - a - b))
a,b,c,k = map(int,input().split())

if a >= k:
    print(k)
elif a+b >= k:
    print(a)
else:
    k -= (a+b)
    print(a-k)
N = [int(e) for e in input().split()]
if(N[3] - N[0] > 0):
    N[3] -= N[0]
    if(N[3] - N[1] > 0):
        N[3] -= N[1]
        ans = N[0] - N[3]
    else:
        ans = N[0]
else:
    ans = N[3]
print(ans)
a, b, c, k = map(int, input().split())

if k <= a:
    print(k)
elif a < k <= (a + b):
    print(a)
else:
    print(2*a-k+b)
A, B, C, K = map(int, input().split(" "))

if K <= A:
    print(1*K)
elif K <= B:
    print(1*A + 0*(K-A))
else:
    print(1*A + 0*B + (-1)*(K-A-B))
a, b, c, k = map(int, input().split())

sum = 0
if k > a:
    sum += a
    k -= a
    if k > b:
        k -= b
        if k > c:
            sum -= c
        else:
            sum -= k      
else:
    sum += k

print(sum)
A,B,C,K=[int(i) for i in input().split()]
if K<A:
    P=K
else:
    P=A
    if A+B<K:
        P-=(K-(A+B))
print(P)
# B
a, b, c, k = map(int, input().split())

if a >= k:
    print(k)
elif a+b >= k:
    print(a)
else:
    print(a - (k-a-b))
A, B, C, K = map(int, input().split())

if K <= A:
    print(K)
else:
    ans = A
    if K <= A + B:
        print(ans)
    else:
        ans = ans - (K - A - B)
        print(ans)
A, B, C, K = map(int, input().split())
if A >= K:
    print(K)
elif A+B >= K:
    print(A)
else:
    print(A - (K-A-B))
A,B,C,K=(int(x) for x in input().split())
if K<=A:print(K)
elif K<=A+B:print(A)
else: print(A-(K-B-A))
a , b , c , k = map(int, input().split())
 
if  a > k:
  print(k)
elif a + b >= k:
  print(a)
else:
  print(2*a - k + b)
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    A, B, C, K=MI() 

    if K<=A:
        print(K)
    elif K>A and K<= A+B:
        print(A)
    elif K >= A + B:
        print(A -(K-A-B))

    


if __name__ == "__main__":
	main()
# -*- coding: utf-8 -*-

def main():

    A, B, C, K = map(int, input().split())

    ans = 0

    if K <= A:
        ans = K

    else:
        if K <= A + B:
            ans = A

        else:
            ans = A + (-1 * (K - A - B))

    print(ans)


if __name__ == "__main__":
    main()
a, b, c, k = map(int, input().split())

print(min(k, a) - max(k - a - b, 0))
a, b, c ,k = map(int, input().split())

ak = min(a, k)
k -= ak
if k == 0:
    ans = ak
    print (ans)
else:
    bk = min(b, k)
    k -= bk
    if k == 0:
        ans = ak
        print (ans)
    else:
        ck = k
        ans = ak- ck
        print (ans)
A, B, C, K = map(int, input().split())
S = min(A, K) - max(0, K-A-B)
print(S)
a,b,c,K=map(int,input().split())
print(K if a>=K else a if b+a>=K else a-(K-a-b))
a, b, c, k = map(int, input().split())
if k <= a:
    print(k)
elif a < k <= a + b:
    print(a)
else:
    print(a - (k - (a + b)))
A,B,C,K = map(int, input().split())
if A+B<K<=A+B+C:
  ans = A-(K-B-A)
elif A<K<=A+B:
  ans = A
else:
  ans = K
print(ans)
A,B,C,K = map(int,input().split())

if A >= K:
    print(K)
elif A+B >= K:
    print(A)
else:
    print(A-(K-A-B))
a, b, c ,k = map(int, input().split())
fromA = a if k > a else k
fromB = 0
fromC = 0
k = k - fromA
if k > 0:
    fromB = b if k > b else k
    k = k - fromB
if k > 0:
    fromC = c if k > c else k
    k = k - fromC
total = (fromA * 1) + (fromB * 0) + (fromC * -1)
print(total)
a,b,c,k = map(int, input().split())
if a>=k:
    print(k)
elif a<k and a+b>=k:
    print(a)
else :
    print(2*a+b-k)
a, b, c, k = map(int, input().split())

xa = min(a, k)
k -= xa
xb = min(b, k)
k -= xb
xc = k
ans = xa - xc

print(ans)
a,b,c,k=map(int,input().split())
ans=0
if(a>=k):
  ans=k
  k=0
else:
  ans=a
  k=k-a
if(b>=k):
  k=0
else:
  k=k-b
ans=ans-k
print(ans)
s = input().split()
numOfA = int(s[0])
numOfB = int(s[1])
numOfC = int(s[2])
pickNum = int(s[3])
maxOutcome = 0

if pickNum < numOfA:
    maxOutcome = pickNum
elif pickNum >= numOfA and pickNum <= (numOfA + numOfB):
    maxOutcome = numOfA
elif pickNum >numOfA +numOfB:
    maxOutcome = numOfA - (pickNum - numOfA - numOfB)

print(maxOutcome)
import sys

def solve():
    input = sys.stdin.readline
    A, B, C, K = map(int, input().split())
    sumL = 0
    if K <= A: 
        sumL += K
        K = 0
    else:
        sumL += A
        K -= A
    if K > B:
        K -= B
    else: K = 0
    if K > 0: sumL -= K
    print(sumL)

    return  0

if __name__ == "__main__":
    solve()
a, b, c, k = map(int, input().split())

if k <= a+b:
    print(min(a, k))
else:
    print(a-(k-a-b))
def main():
  A,B,C,K = map(int, input().split())
  
  sum = 0
  
  if K > A:
    sum += 1 * A
  elif K <= A:
    sum += 1 * K
  
  if K > A + B:
    sum += -1 * (K - (A + B))
  
  print(sum)
  
main()
a,b,c,k = map(int,input().split())

if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    d = k - a - b
    print(a  -d)
a,b,c,k = map(int, input().split())

total = 0
for target, point in [(a,1),(b,0),(c,-1)]:
    num = min(target, k)
    k -= num
    total += point * num
    if k <= 0:
        break

print(total)
import sys
readline = sys.stdin.buffer.readline
a,b,c,k =list(map(int,readline().rstrip().split()))
if k <= a:
  print(k)
elif k > a and k <= a + b:
  print(a)
else:
  print(a -(k-(a+b)))
a, b, c, k = map(int, input().split())
if k <= a:
    print(k)
elif a < k <= (a+b):
    print(a)
else:
    num = k-a-b
    print(a-num)
a,b,c,k = map(int, input().split())
if k <= a:
    print(k)
else:
    ans = a
    k = k-a
    if k <= b:
        print(ans)
    else:
        k = k-b
        print(ans-k)
A,B,C,K = map(int,input().split())
if  A>=K:
  print(K)
elif A+B>=K:
  print(A)
else:
  print(A-(K-A-B))
a,b,c,d=map(int,input().split())
ans=0
if not a<d:
  print(d)
else:
  if not a+b<d:
    print(a)
  else:
    print(2*a+b-d)
a, b, c, k = map(int, input().split())

ans = a
if k < a:
    ans = k
    
if k > a + b:
    ans = ans - (k - (a+b))

print(ans)
a, b, c, k = list(map(int, input().split()))

if a>=k:
    print(k)
elif a<k<=(a+b):
    print(a)
else:
    print(a-(k-a-b))
a,b,c,k=map(int,input().split())
sum=0
if k>=a:
    sum=a
    rem=k-a
else:
    sum=k
    rem=0
if rem==0:
    print(sum)
else:
    if rem>=b:
        rem=rem-b
    else:
        rem=0
        print(sum)
    if rem!=0:
        sum=sum-rem
        print(sum)
    else:
        print(sum)
a,b,c,k = map(int,input().split())
if(a>=k):
  print(k)
else:
  if(a+b>=k):
    print(a)
  else:
    print(a-(k-(a+b)))
A,B,C,K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)
if (0<=A)and(0<=B)and(0<=C)and(1<=K<=A+B+C<=2*10**9):
    if K<=A:
        print(K)
    if A<K<=A+B:
        print(A)
    if A+B<K<=A+B+C:
        a=A-(K-A-B)
        print(a)
A, B, C, K = map(int, input().split())

if A >= K:
    nmax = K
elif B >= K-A:
    nmax = A
else:
    nmax = A-(K-A-B)
            
print(nmax)
def main():
  A, B, C, K = map(int, input().split())
  if A > K:
    print(K)
  elif A + B >= K:
    print(A)
  else:
  	print(A - (K - A - B))
main()
a,b,c,k=map(int,input().split())
'''l=[]
for _ in range(a):
    l.append(1)
for _ in range(b):
    l.append(0)
for _ in range(c):
    l.append(-1)
print(sum(l[:k]))'''
su=0
if a>=k:
    print(k)
else:
    su=su+a
    tem=k-a
    if b>=tem:
        print(su)
    else:
        tem1=tem-b
        print(su-tem1)
a, b, c, k = map(int, input().split())

if k <= a :
    print(k)
elif k <= a+b:
    print(a)
else:
    print(a+a+b-k)
A,B,C,K = map(int ,input().split())

if A >= K:
    print(K)
elif B >= K-A:
    print(A)
else:
    print(A-(K-(A+B)))
A,B,C,K=map(int,input().split())
ans=0
if A>K:
    ans=K
elif A+B>=K:
    ans=A
else:
    ans=A-(K-A-B)
print(ans)
def q2():
    A, B, C, K =  [int(i) for i in input().split(" ")]
    if K <= A:
        print(K)
        return
    if K <= A + B:
        print(A)
        return
    print(A+(K-(A+B))*-1)
    

q2()
a,b,c,k=map(int,input().split())
if a >= k:
  print(k)
elif a+b>=k:
  print(a)
else:
  print(2*a+b-k)
a, b, c, k = map(int, input().split())

if a > k:
  print(k)
elif a+b > k:
  print(k)
else:
  print(a -(k-a-b))
a,b,c,k=map(int,input().split())
ans=0
if k<a:
    ans+=k
elif k<a+b:
    ans+=a
elif k<=a+b+c:
    ans=ans+a-(k-a-b)
print(ans)
a,b,c,k=map(int,input().split())
if k<=a:
    print(k)
elif k<=(a+b):
    print(a)
else:
    print(a-(k-(a+b)))
A, B, C, K =map(int, input().split())

ans = 0
ans = min(A, K)
K -= ans
K -= min(B,K)
ans -= min(C, K)

print(ans)
a,b,c,k=map(int,input().split())
if a>=k:
    print(k)
elif b>=k-a:
    print(a)
else:
    print(a-(k-a-b))
A,B,C,K=map(int,input().split())
if A>=K:
  print(K)
elif A+B>=K:
  print(A)
else:
  print(A-(K-A-B))
a,b,c,k=map(int,input().split())
if(k<=a):
  print(k)
else:
  print(a-(k-a-b))
A,B,C,K=map(int,input().split())
r=min(A,K)
K-=r
A-=r
ans=r
K -= min(B,K)
r=min(K,C)
ans-=r
print(ans)
A,B,C,K=list(map(int,input().split()))
if A+B>=K:
    if A>K:
        print(K)
    else:
        print(A)
else:
    F=K-(A+B)
    print(A-F)
a,b,c,d=map(int,input().split())
if a+1+b>d:
  print(min(a,d))
else:
  print(a-(d-a-b))
def main():
    A, B, C, K = map(int, input().split())

    if A > K:
        return print(K)

    if A + B >= K:
        return print(A)
    else:
        C = K - A - B
        return print(A-C)

if __name__ == '__main__':
    main()
one,zero,minus,k = map(int,input().split())
result = 0
if one > k:
    print(k)
else:
    result += one
    k -= one
    if zero > k:
        print(result)
    else:
        k -= zero
        if k > 0:
            result -= k
        print(result)
A,B,C,D=list(map(int,input().split()))
ans = 0
if D-A>0:
    ans+=A
    D-=A
else:
    print(D)
    exit()
if D-B>0:
    D-=B
else:
    print(ans)
    exit()
print(ans-D)
A, B, C, K = map(int, input().split())

count = 0

if K >= A:
    count += A
    K -= A
else:
    count = K
    K = 0

if K != 0:
    if K>=B:
        K -= B
    else:
        K= 0
if K != 0:
    count -= K

print(count)
a,b,c,k=map(int,input().split())

if k<=a:
    print(k)
elif k<=b:
    print(a)
else:
    print(2*a-k+b)
A, B, C, K = map(int, input().split())

if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(A - (K - A - B))
a,b,c,k=map(int, input().split())
ans=0
if a>=k:
    print(k)
    exit()
if b>=k-a:
    print(a)
    exit()
else:
    print(a-(k-b-a))
    exit()
a,b,c,k=map(int,input().split())
ans=a
if a>k: ans=k
if a+b<k: ans-=(k-(a+b))
print(ans)
#!/usr/bin/env python3

A, B, C, K = map(int, input().split())
if K <= A:
    print(K)
elif K <= (A+B):
    print(A)
else:
    print(2*A-K+B)
A, B, C, K = map(int, input().split())

# 1 2 3 4

s = 0
if A < K:
    s += A
    if A + B < K:
        s += (K - (A + B)) * -1
else:
    s += K

print(s)
a, b, c, k = [int(i) for i in input().split()]
if a >= k:
	ans = k
elif (a+b) >= k:
	ans = a
else:
	ans = a - (k-a-b)

print(ans)
#B

A,B,C,K=map(int,input().split())

if K<=A:
    Sum=K
elif K<=A+B:
    Sum=A
else:
    Sum=A-(K-A-B)
    
print(Sum)
A,B,C,K = input().split()
a = int(A)
b = int(B)
c = int(C)
k = int(K)

B_number = 0
C_number = 0

A_number = min(a,k)
k1 = k - a
if k1 > 0:
    B_number = min(b,k1)
    k2 = k1 - b
    if k2 > 0:
        C_number = min(c,k2)

print(A_number-C_number)
# B - Easy Linear Programming

a, b, c, k = map(int, input().split())
print(min(k, a, a + a + b - k))
a,b,c,k = map(int,input().split())

ans = 0
ans += min(a, k)
k -= a
k -= b
ans -= max( k, 0)

print(ans)
A, B, C, K = map(int, input().split())
if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(A-(K-A-B))
a,b,c,k = map(int,input().split())

if a >= k:
    print(k)
elif (a+b) >= k:
    print(a)
else:
    print(a-(k-a-b))
def main():
	inputList= list(map(int, input().split()))
	score =[1,0,-1]
	ans =0
	for i in range(len(inputList)-1):
		if inputList[3] >= inputList[i]:
			inputList[3] = inputList[3] - inputList[i]
			ans = ans + inputList[i]*score[i]
		else:
			ans = ans + inputList[3]*score[i]
			return ans
	return ans
     
if __name__ == '__main__':
	print(main())
a,b,c,k = map(int,input().split())


if k<=a :
 print(k)
elif  k< a+b:
 print(a)
else:
 print(2*a+b-k)
a,b,c,k=map(int,input().split())
if k<=a:
    print(k)
elif k<=(a+b):
    print(a)
elif k<=(a+b+c):
    print(a-(k-a-b))
a,b,c,k=map(int,input().split())
if k<=a:
  print(k)
elif a<k<=a+b:
  print(a)
else:
  print(a-(k-a-b))
if __name__ == '__main__':
    A =[]
    B = input()
    A = B.split()

    a = int(A[0])
    b = int(A[1])
    c = int(A[2])
    k = int(A[3])

    if a > k:
        print(k)
    elif (a+b) > k:
        print(a)
    else:
        ans = 2*a-k+b
        print(ans)
a,b,c,k=map(int,input().split())
if k<=a:
  ans=k
elif k<=a+b:
  ans=a
else:
  ans=a-(k-a-b)
print(ans)
a, b, c, k = input().split()
count = 0
if int(a) <= int(k):
  count += int(a)
  if int(k)-int(a) >= int(b):
    count -= int(k)-int(a)-int(b)
else:
  count = int(k)
print(count)
A, B, C, K = map(int, input().split())

if K < A:
    print(K)
elif K < A + B:
    print(A)
else:
    print(A - (K - A - B))
n_plus, n_zero, n_minus, n_cards = map(int, input().split())

if n_cards <= n_plus:
  print(min(n_plus, n_cards))
elif n_cards <= (n_plus + n_zero):
  print(n_plus)
else:
  print(n_plus - (n_cards - n_plus - n_zero))
A, B, C, K = map(int, input().split())

if A >= K:
    print(K)
elif A + B >= K:
    print(A)
else:
    D = K-A-B
    print(A-D)
A, B, C, K = map(int, input().split())
num_A = min(A, K)
num_B = min(B, K - num_A)
num_C = K - num_A - num_B
ans = num_A - num_C
print(ans)
import sys
s = input()
a, b, c, k = s.split()

a = int(a)
b = int(b)
c = int(c)
k = int(k)


ans = 0
if k <= a:
	print(k)
	sys.exit()
ans += a
k -= a

if k <= b:
	print(ans)
	sys.exit()
k -= b

print(ans - k)
a,b,c,k = map(int,input().split())

ans = 0

if k >= a:
    k -= a
    ans += a
    if k >= b:
        k -= b
        if k > 0:
            ans -= k
    print(ans)
else:
    ans = k
    print(ans)
a, b, c, k = map(int, input().split(" "))

if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print(a - (k-(a+b)))
import sys
input = sys.stdin.readline

a, b, c, k = map(int, input().split())
if a >= k: print(k)
else:
    # Continue
    res = a
    k -= a
    if b >= k: print(res)
    else:
        # Continue
        k -= b
        print(res - k)
A, B, C, K = map(int, input().split())
 
if K <= A:
    print(K)
elif A < K <= A+B:
    print(A)
else:
    K -= (A+B)
    print(A-K)
A, B, C, K = map(int, input().split())
a = min(K,A)
K-=a
b = min(K,B)
K-=b
c = K
print(a-c)
A,B,C,K = map(int,input().split())

if A >= K:
  print(K*1)
else:
  K -= A
  if B >= K:
    print(A*1)
  else:
    K -= B
    print(A*1 + K*(-1))
a,b,c,k = map(int,input().split())

ans = 0
if a<k:
    ans+=a
    k-=a
else:
    ans+=k
    k = 0

if b<k:
    k-=b
else:
    k = 0

if c<k:
    ans-=c
    k-=c
else:
    ans-=k
    k = 0

print(ans)
a, b, c, k = map(int, input().split())

if a + b >= k:
	if a >= k:
		print(k)
	else:
		print(a)
else:
	print(a - (k - a - b))
A, B, C, K = map(int, input().split(" "))
if A + B >= K:
	if K <= A:
		print(K)
	else:
		print(A)
else:
	print(A-(K-A-B))
if __name__ == '__main__':
    A, B, C, K = map(int, input().split())

    if K <= A:
        print(K)
    elif A < K <= A + B:
        print(A)
    else:
        print(A - (K - A - B))
a,b,c,k = map(int,input().split())

if k<=a:
    print(k)
elif a<k<=a+b:
    print(a)
else:
    print(a-(k-(a+b)))
a,b,c,k = map(int,input().split())
ans = 0
if a >= k:
    ans += k
    print(ans)
    quit()
else:
    ans += a
    k -= a

if b >= k:
    print(ans)
    quit()
else:
    k-=b
    ans += (-1*k)
    print(ans)
a, b, c, k = map(int, input().split())
if a>=k:
  print(k)
elif a+b>=k>a:
  print(a)
elif k>a+b:
  print(a-(k-a-b))
a,b,c,k=map(int,open(0).read().split())

if k<=a+b:
    print(min(a,k))
else:
    cntc=k-a-b
    print(a-cntc)
a,b,c,k = list(map(int,input().split(' ')))

if a >= k:
    print(k)
elif a+b >= k:
    print(a)
else:
    print(a-(k-(a+b)))
a, b, c, k = list(map(int, input().split()))

if k <= a+b:
    ans = min(a,k)
else:
    ans = 2*a+b-k
print(ans)
A,B,C,K = map(int,input().split())
ans = 0
if A >= K:
    print(K)
elif A<K and A+B>K:
    print(A)
else:
    print(2*A+B-K)
import sys

A, B, C, K = map(int, input().split())

S = 0

if A >= K:
    S = S + K * 1
    K = 0
    print(S)
    sys.exit()
else:
    S = S + A * 1
    K = K - A

if B >= K:
    K = 0
    print(S)
    sys.exit()
else:
    K = K - B

if C >= K:
    S = S + K * (-1)
    K = 0
    print(S)
    sys.exit()
else:
    S = S + C * 1
    print(S)
a, b, c, k = list(map(int, input().split()))
if k<=a:
  print(k)
elif a<k<=b+a:
  print(a)
else:
  print(2*a-k+b)
a, b, c, k = map(int, input().split())
if k <= a:
    print(k)
elif k <= a + b:
    print(a)
else:
    print(a-(k - a - b))
a,b,c,k=map(int, input().split())
print(k if a>=k else a if a+b>k>a else 2*a+b-k)
A, B, C, K = map(int, input().split())

if A <= K:
    ans = 1 * A
    K = K - A
else:
    ans = K
    print(ans)
    exit(0)

if 0 < K:
    ans = ans + 0 * B
    K = K - B

if 0 < K:
    ans = ans + (-1) * K

print(ans)
import sys
input = sys.stdin.readline
def calc(A, B, C, K):
    sum = 0
    if K>A:
        sum += A
        K = K-A
    else:
        sum = K
        return sum
    if K>B:
        K = K - B
    else:
        return sum
    sum = sum - K
    return sum


def main():
    A, B, C, K = map(int, input().split())
    sum = calc(A,B,C,K)
    print(sum)

    

if __name__ == '__main__':
    main()
A , B, C, K = map(int, input().split())

if K >= A:
    result = A
    K -= A
else:
    result = K
    K = 0

if K >= B:
    K -= B

if K > 0:
    result -=K
print(result)
A,B,C,K = map(int,input().split())
nList = [A,B,C]
pList = [1,0,-1]

ans = 0
for i in range(len(nList)):
  if nList[i] <= K:
    ans += nList[i]*pList[i]
    K -= nList[i]
  else:
    ans += K*pList[i]
    break
    
print(ans)
A,B,C,K=map(int,input().split())

tot=0
all=K

if K-A>=0:
    tot+=A*1
    all-=A
    if all-B>=0:
        tot+=B*0
        all-=B
        if all-C>=0:
            tot+=-1*C
        else:
            tot+=-1*all
    else:
        tot+=0*all
else:
    tot+=1*all
print(tot)
a, b, c, k = map(int, input().split())
if a > k:
    print(k)
elif a+b >k:
    print(a)
else:
    print(a-(k-(a+b)))
a,b,c,k = map(int,input().split())

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
else:
    print(a-(k-a-b))
A, B, C, K = map(int,input().split())

sum = 0

if A >= K:
  sum = K
elif (A + B) >= K:
  sum = A
else:
  sum = A - (K - A - B)

print(sum)
A,B,C,K = map(int,input().split())
ans = 0

if A >= K:
    ans = 1*K
else:
    ans += 1*A
    K = K - A
    if B >= K:
        ans += 0*K
    else:
        ans += 0*B
        K = K - B
        ans += (-1)*K
        
print(ans)
a,b,c,d=map(int, input().split())

if d<a:
  print(d)
elif d<b:
  print(a)
else:
  print(2*a-d+b)
a,b,c,k=map(int,input().split())

if a>=k:
  print(k)
elif a+b>=k:
  print(a)
else:
  d=k-a-b
  print(a-d)
A, B, C, K = map(int,input().split())

res = min(K, A) - max(K-A-B, 0)
print(res)
a,b,c,k = map(int,input().split())
ans = 0
if k < a:
    print(k)
elif k < a+b:
    print(a)
else:
    print(a-(k-(a+b)))
A, B, C, K = map(int, input().split())
# デフォルトは0
result = 0
# k分のAとって
t = min(A, K)
#    0 ←　A　たす
result += t
#K →　t　引かれる
K -= t
t = min(B, K)
# 0だからresultは変動なしkは引かれる
K -= t
t = min(C, K)
# resultは引かれる　kはもうない
result -= t
print(result)
a,b,c,k=map(int,input().split())
if k<=a:
    print(k)
elif k<=b:
    print(a)
else:
    print(a-(k-a-b))
*abc, k = map(int, input().split())
n = [0] * 3
for i, v in enumerate(abc):
    if k >= v:
        n[i] = v
        k -= v
    else:
        n[i] = k
        break

print(n[0] + n[2] * -1)
A, B, C, K = map(int,input().split())

if K <= A:
    print(K)
elif K<=A+B:
    print(A)
else:
    print(A+(K-(A+B))*(-1))
a, b, c, d = map(int, input().split())
if d <= a:
  print(d)
elif d <= a + b:
  print(a)
else:
  print(a-(d-(a+b)))
A,B,C,K = list(map(int,input().split()))
print(max(min(K,A),0) - max(min(K-(A+B),C),0))
a, b, c, k = map(int, input().split())

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
else:
    print(a - (k - (a + b)))
a, b, c, k = list(map(int ,input().split()))

total = 0
plus_num = 0
per_num = 0
minus_num = 0

if a < k:
  plus_num = a
  k -= a
else:
  plus_num = k
  k = 0

if b < k:
  per_num = b
  k -= b
else:
  per_num = k
  k = 0

if c < k:
  minus_num = c
  k -= c
else:
  minus_num = k
  k = 0

# print(plus_num, per_num, minus_num)

total = plus_num - minus_num
    
print(total)
A,B,C,K = input().split(' ')
A = int(A) # 1
B = int(B) # 0
C = int(C) # -1
K = int(K)


# 1 x ?,  0 x ?,  -1 x ?
if (K <= A + B):
  if (A >= K):
    print(K)
  else:
    print(A)
else:
  print(A + ((K - (A + B)) * -1))
a,b,c,k=map(int,input().split())
if k<=a:
    print(k)
    exit()
k-=a
if k<=b:
    print(a)
    exit()
k-=b
print(a-k)
A,B,C,K=map(int,input().split())
if K<=A:
    print(K)
elif K<=A+B:
    print(A)
else:
    print(A-(K-A-B))
a, b, c, k = map(int, input().split())
print(min(a, k) - max(k - a - b, 0))
# -*- coding: utf-8 -*-

A,B,C,K = map(int, input().split())

if K<=A:
  score = K
elif K<=A+B:
  score = A
else:
  score = A-(K-A-B)

print(score)
a,b,c,k = map(int,input().split())
print(min([a,k])-max([0,k-a-b]))
a, b, c, k = map(int, input().split())
s = 0
for _ in zip([a, b, c], [+1, 0, -1]):
    if k > 0:
        x = min(k, _[0])
        k -= x
        s += x * _[1]
    else:
        break
print(s)