peterverebics/CodeNet_Python_118 huggingface dataset:
a, b, c, k = map(int, input().split())
if k > a:
    af = k - a
    if af >= b:
        ab = af - b
        print(a-ab)
    else:
        ab = abs(af-b)
        print(a-ab)
else:
    print(a)
a,b,c,k = map(int, input().split())

if k <= a:
  print(k)
elif k > a and k <= (a+b):
  print(a)
else:
  print(2*a - k - b)
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[0]
print(ans)
import sys
import math

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

A = a
B = 0
C = -1 * c

if k - a > 0:
    if k -a -b > 0:
        print(a + b -(k -a - b))
        sys.exit()
    else:
        print(a)
else:
    print(a)
a, b, c, k = map(int, input().split())
if (a + b) < k <= (a + b + c):
    print(a - (k - (a + b)))
else:
    print(a)
l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
k = int(l[3])

r = 0

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

if a>=k:
    cnt += a
else:
    k -= a
    cnt += a
    if k!=0:
        k -= b
        if k!=0:
            cnt -= k

print(cnt)
a,b,c,k = map(int, input().split())
if a>=k:
  print(a)
elif a+b>=k:
  print(a)
else:
  l = k-a-b
  print(a - (c*l))
A, B, C, K = input().strip().split()
A, B, C, K = [int(A), int(B), int(C), int(K)]
summary = A
minus = K - A - B
if minus > 0:
  answer = summary - minus
else:
  answer = summary
print(str(answer))
A,B,C,K = map(int,input().split())
 
if K <= (A+B):
  print(K)
elif (A+B)<K and K<=(A+B+C):
  print(A-(K-(A+B)))
else:
  print(A-C)
a,b,c,k=map(int,input().split())
if k<=a+b:
  print(a)
elif k<=a+b+c:
  print(2*a-k+b)
else:
  print(a-c)
a,b,c,k= map(int,input().split())
if k>a:
    if k>a+b:
        print(a-k+a+b)
    else:
        print(a)
else:
    print(a)
n = list(map(int,input().split()))

sum = 0
num = 0
nm = [1,0,-1]
c = n[3]
cu =0


for i in n:
    if c == 0:
        break
    if i <= c:
        sum += nm[num] * i
        c-=i
        num+=1




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

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

if a > k and b == 0 and c == 0:
    print(k)
elif (a + b >= k or a == k) or (a == 0 and c == 0) or (c == 0 and b == 0):
    print(a)
else:
    print(a + ((a+b) - k))
import sys
a, b, c, d = map(int, sys.stdin.readline().split())
if a+b < d:
  print(a-(d-a-b))
else:
  print(a)
a, b, c, k = list(map(int, input().split()))

c = k- a- b

if c < 0 :
    c = 0

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

ans = 0
if k >= a:
    ans += a*1
    k = k - a
elif k < a:
    k = 0
    ans = k

if k > 0 and k >= b:
    k = k - b
elif k > 0 and k < b:
    k = 0

if k > 0 and k >= c:
    ans -= c*1
    k = k - c
elif k > 0 and k < c:
    ans = ans - 1*k
    k = 0

print(ans)
X = list(map(int,input().split()))
A = X[0]
B = X[1]
C = X[2]
K = X[3]
score=[1,0,-1]
max_score = 0
nums = []

if (K>=A):
  max_score += 1*A
if (K-A<=B):
  max_score += 2*B
if (K-A-B>0):
  max_score += (-1)*(K-A-B)
print(max_score)
def main():
    A, B, _, K = map(int, input().split())
    print(A - max([0, K - A - B]))


if __name__ == "__main__":
    main()
X = list(map(int, input().split()))

if(X[0]<X[3] and X[3]-(X[0] + X[1])>0):
  print(X[0]*1+((X[3]-X[0] - X[1])*(-1)))
else:
  print(X[0]*1)
A,B,C,K=map(int,input().split())

ans=0

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

l = k - a
m = l - b
n = m - c

ans = 0

if l >= 0:
    ans += a
    if l == 0:
        print(ans)
    else:
        if m >= 0:
            if n > 0:
                ans -= n
                print(ans)
            else:
                ans -= m
                print(ans)
        else:
            print(ans)
card    = list(map(int, input().split()))
count  = card[3] - card[0]
answer = card[0]

for i in card[1:2]:
    if count == 0:
        break
    for j in range(i):
        if count == 0:
            break
        
        count -=1
        
        if i == 0:
            continue
        elif j == -1:
            answer -= 1
            
print(answer)
# S = input()
# N = int(input())
# A, B = map(int, input().split(' '))
# A = list(map(int, input().split(' ')))

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

if A < K:
  result += A
  K -= A
else:
  result = A
  
if B < K:
  K -= B
else:
  K -= B

if K > 0:
  if C < K:
    result -= C
    K -= C
  else:
    result -= K

print(result)
a,b,c,k=list(map(int,input().split()))
if k<=a and b==0 and c==0:
    print(k)
elif k<a:
    print(k-a)
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)
if k <=(a+b):
    print(a)
if k < a+b+c:
    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,d=[int(x) for x in input().split()]
count=a
sum=a
if count==d:
    print(a)
else:
    count=count+b
    if count<d:
        if d-count<=c:
          print(sum+((d-count)*-1))
        else:
            print(sum+(c*-1))
    else:
        print(sum)
import sys
input = sys.stdin.readline

A,B,C,K=(int(x) for x in input().rstrip('\n').split())
res = A
if K>(A+B):
  los = K-B-A
  res -= los
print(res)
A, B, C, K = map(int, input().split())

x = 0
if K >= A:
  x += A

if K >= A + B:
  x -= K - A - B
print(x)
A, B, C, K = map(int, input().split())

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

max = a
if a >= k:
    print(max)
else:
    k -= a
    if b >= k:
        print(max)
    else:
        k -= b
        print(max - k)
# -*- coding: utf-8 -*-

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

if A+B>=K:
    print("{}".format(A))
else:
    print("{}".format(2*A-K+B))
A, B, C, K = map(int, input().split())
ret = 0

for numberOfCards, point in [(A, 1), (B, 0), (C, -1)]:
  if K >= numberOfCards:
    K -= numberOfCards
    ret += numberOfCards * point
  else:
    ret += numberOfCards * point
    break
    
print(ret)
if __name__ == "__main__":
    num = list(map(int, input().split()))
    
    if (num[3] <= num[0] + num[1]):
        print(num[0])
    else:
        print(num[0] - num[3] + num[0] + num[1])
A,B,C,K = map(int,input().split())
if K-A < 0:
    print(str(A))
else:
    if K-A-B < 0:
        print(str(A))
    else:
        print(str(A+(-1)*(K-A-B)))
a,b,c,k = map(int,input().split())

ans = 0
num = k

if num < a:
  ans += num
  exit()
else:
  ans += a
  num -= a

if num < b:
  ans += 0
  exit()
else:
  ans += 0
  num -= b

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

print(n)
a,b,c,k=map(int,input().split())
if k<=a:
    print(a)
elif k<=a+b:
    print(a)
else:
    print(2*a+b-4)
# -*- coding: utf-8 -*-
a, b, c, k = map(int, input().split())
t = a + b
if t < k:
    print(a-(k-t))
else:
    print(a)
A,B,C,K=map(int,input().split())
maxC=K-(A+B)

if A > K:
	max=A
else:
	if maxC <0 :
		max = A 
	elif maxC >= 0:
		max = A - maxC

print(max)
A,B,C,K=map(int,input().split())
if A>=K:
    print(K)
    exit()
elif A+B>=K:
    print(A)
    exit()
else:
    print(A+(K-A-B))
    exit()
A = list(map(int, input().split()))

if A[0]+A[1]+A[2]>=A[3]:
  print(A[0]-(A[3]-A[0]-A[1]))
else:
  print(A[0]-A[2])
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

ans = 0

if K <= A:
    print(A)
elif K <= A + B:
    print(A)
else:
    print(A - K + A + B)
# -*- coding: utf-8 -*-

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

if A>=K:
    print("{}".format(A))
else:
    if K<=A+B:
        print("{}".format(A))
    else:
        print("{}".format(2*A-K+B))
import sys

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

cnt=0


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

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


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

sum=0
T=K
if T>A:
    sum=A
    T=T-A
    if T > B:
        T = T - B
        sum = sum - T
        print(int(sum))

    else:
        print(int(sum))

else:
    sum=A
    print(int(sum))
#
from collections import Counter

k = list(map(int,input().split()))
pick = k[3]
maxi = 0
for i in range(len(k)):
    if(i<k[0]-1):
        maxi = max(maxi,maxi+1)
        pick = pick-1
    elif k[1]<(pick-k[i]):
        maxi = max(maxi,maxi+0)
        pick=pick-1
    elif k[2]<(pick-k[i]):
        maxi = max(maxi,maxi-0)
        pick = pick-1


print(maxi+1)
A,B,C,K = input().split()
a = int(A)
b = int(B)
k = int(K)

if a >= k:
    Answer = a
    print(Answer)
else:
    if a+b >= k:
        Answer = a
        print(Answer)
    else:
        Answer = a - (k-(a+b))
        print(Answer)
a,b,c,k=map(int,input().split())
ct=k
result = 0
if ct>0 and a>0:
  result=1*a
  ct=k-a
if ct>0 and b>0:
  ct=ct-b
if ct>0 and c>0:
  result=result+(-1*ct)  
print(result)
a, b, c, k = map(int, input().split())
ans = 0
if a > 0:
    ans = min(a, k)
    k = k - min(a, k)
if k > 0:
    k = k - b
if k > 0:
    ans = ans - k
a, b, c, k =map(int, input().split())
if k<=a+b:
  print(a)
else:
  print(a-(k-(a+b)))
a,b,c,k = map(int, input().split())
ans=0
if k-a <= 0:
    ans = a
elif k-(a+b) <= 0:
    ans = a
else:
    ans = a-(k-(a+b))
print(ans)
a,b,c,k = map(int,input().split())
ans = 0
if a+b >= k:
    print(a)
else:
    print(a-(min(k-(a+b),c)))
a,b,c,k = map(int,input().split())

ans = 0

if a == 0:
    print(0)
if a == 0 and b == 0:
    print(0)

ans = a*1
k -= a
if k > 0:
    k -= b
    if k > 0:
        for _ in range(c):
            if k == 0:
                break
            ans += (1)
            k -= 1
print(ans)
a,b,c,k=map(int,input().split())
#sum=a*1+b*0-c*1
if a>=k:
    print(a)
if a<k and a+b>=k:
    print(a)
if a<k and a+b<k and a+b+c>=k:
    print(a-(k-a-b))
A,B,C,K = map(int,input().split())
if A>=K:
    print(A)
elif (A+B)>=K:
    print(A)
else:
    S = K-(A+B)
    print(A-S)
a, b, c, k = list(map(int, input().split()))


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

x2 = A+B
x3 = A+B+C

if K<=x2:
  ans = A
else:
  ans = A-(K-(A+B))

print(ans)
A, B, C, K = map(int, input().split())  # a 1 b 0 c -1

if K <= A:
    print(K)

else:
    maxvalue = A
    K -= A
    if B >= 0:
        if K > 0:
            K = K - B
            if K <= 0:
                print(maxvalue)
    maxvalue -= K * -1
    print(maxvalue)
a, b, c, k = map(int, input().split())
chk1 = k-a
chk2 = k-a-b
if chk1 <= 0:
    ans = a

else:
    if chk2 > 0:
        ans = a -1*chk2
    else:
        ans = a
print(ans)
# coding: utf-8
import sys

info = input().split(' ')
card_one = int(info[0])
card_zero = int(info[1])
card_minus = int(info[2])
number = int(info[3])

sumnum = 0

if (number >= card_one):
    number = number - card_one
    sumnum = sumnum + card_one
else:
    print(card_one)
    sys.exit()

if (number >= card_zero):
    number = number - card_zero
else:
    print(sumnum)
    sys.exit()

if (number >= card_minus):
    sumnum = sumnum - card_minus
    print(sumnum)

while(number>0):
    number = number - 1
    sumnum = sumnum - 1

print(sumnum)
a,b,c,k=map(int,input().split())
s=0
for i in range(k-1):
    if a!=0:
        s+=1
        a-=1
        continue
    elif b != 0:
        b-=1
        continue
    elif c!=0:
        s-=1
        c-=1
        continue

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

if( A + B >= K ):
    print(A)
else:
    print(+1*A -1*(K-(A+B)))
import sys
import math
a,b,c,k=map(int,input().split())
if a>=k:
    print(a)
    sys.exit()
elif a+b>=k:
    print(a)
    sys.exit()
else:
    s=k-(a+b)
    print(a+(s*(-1)))
    sys.exit()
A , B, C, K = map(int, input().split())

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

if K >= B:
    K -= B

if K > 0:
    result -=K
print(result)
a,b,c,k=map(int,input().split())
 
if a>=k:
  print(a)
  exit()
else:
  if k-a<b:
    print(a)
    exit()
  else:
    c=k-a-b
    print(a-c)
read = input().split()
x = int(read[3]) - int(read[0]) - int(read[1])
if x <= 0:
    print(int(read[0]))
else:
    print(int(read[0]) - x)
a, b, c, k = map(int, input().split())

if k <= a: print( k )
elif k < a+b: print( a )
elif k > k-(a+b): print(a - (k-a-b))
#a,b=(int(x) for x in input().split()) #数値の時




#a,b=(x for x in input().split()) 
a,b,c,k=(int(x) for x in input().split())

if(k<=a):
  print(a*k)
else:
  sum=a
  t=k-a
  if(t<=b):
    print(sum)
    
  else:
    t-=b
    
    
    print(sum-t)
a,b,c,k= map(int,input().split())

if a+b>=k:
  print(a)
else:
  print(2*a+b-k)
a,b,c,k=map(int,input().split())
if a + b >=k:
    print(a)
else:
    ans = a - (k - a - b)
    print(ans)
a,b,c,k=map(int,input().split())
t=0
if(a!=0):
    t=t+a
if(b!=0):
    t=t
if(k>a-b):
    t=t-(k-a-b)
print(t)
a, b, c, k = map(int, input().split())
total = 0
if a <= k:
  total += a
  k -= a
  if b <= k:
    k -= b
    if c <= k:
      total -= k
print(total)
a, b, c, k = map(int, input().split())

ans = 0

if k >= a:
    ans += a
else :
    ans += k
k = k-a-b

if k <= 0:
    ans += k
    print(ans)
    exit()

ans -= k

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

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

n_sum = 0
if a >= k:
  n_sum = a
  print(n_sum)
  sys.exit()
  
n_sum += a
k -= a
k -= b
if k <=0:
  print(n_sum)
  sys.exit()
if k >= c:
  n_sum -= c
  print(n_sum)
  sys.exit()
else:
  n_sum -= k
       
print(n_sum)
# abc167 b
a, b, c, k = [int(i) for i in input().split()]
ans = 0
if k < a:
    ans = 0
elif k < a + b:
    ans = a
else:
    ans = a - (k-(a+b))
a, b, c, k = map(int, input().split())
lis = []
if k >= a:
    lis.append(a)
elif k >= a+b:
    lis.append(0)
elif k >= a+b+c:
    lis.append(-1*c(b-a))
print(sum(lis))
A, B, C, K = map(int,input().split())
sum = 0
n = 0
if K - A > 0:
    sum = A*1
    n = K - A
    if B > n:
        n = n - B
        sum = C * n
else:
    sum = A*1
print(sum)
A,B,C,K=(int(x) for x in input().split())

if K <= A+B:
    print(A)
elif K > A+B and A!=0:
    print(A+(K-A-B)*-1)
else:
    print((K-(A+B))*-1)
A, B, C, K = map(int, input().split())
D = A + B
if D >= K:
    print(A)
else:
    K -= D
    print(A-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, K= map(int, input().split())
count = 0
if K>A:
    count=A
    if K-A-B>=C:
        count=count-C
        print(count)
    else:
        for i in range(C):
            if K-A-B==i:
                print(count-i)
elif A==K:
    print(A)
s = input().split()

A = int(s[0])
B = int(s[1])
C = int(s[2])
K = int(s[3])

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


"""
print(a)
print(b)
print(c)
print(k)
"""
if a >= k:
    print(a)

elif (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(A>=K):
  print(A)
elif(K<=A+B):
  print(A)
else:
  print(A-(K-A-B))
a,b,c,k = map(int,input().split())

if k <= a+b:
    print(a)
else:
    print(a-(k-(a+b)))
a,b,c,k=map(int,input().split())
if k<=a+b:
  print(a)
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
else:
    ans = (a-(k-a-b))

if ans >= 0:
    print(ans)
else:
    print(0)
a,b,c,k=map(int,input().split())
if(a+b>=k):
    print(a)
else:
    print(a-(k-(a+b)))
inputs = [int(x) for x in input().split()]
sumAns = 0

if inputs[0] > inputs[3]:
	sumAns = sumAns + inputs[3]
	inputs[3] = 0
else:
	sumAns = sumAns + inputs[0]
	inputs[3] = inputs[3] - inputs[0]

if inputs[1] > inputs[3]:
	inputs[3] = 0
else:
	inputs[3] = inputs[3] - inputs[1]

if inputs[2] > inputs[3]:
	sumAns = sumAns - inputs[3]
	inputs[3] = 0
else:
	inputs[3] = inputs[3] - inputs[2]
	
print(sumAns)
a = input()
 
A, B, C, K = map(int, a.split())
 
if A >= K:
  print(A)
elif A + B >= K > A:
  print(A)
else:
  print(2*A + B + C -K)
a,b,c,k=map(int,input().split())
total=0
if a < k:
    total += a
    k -= a
else:
    print(a)
    exit()
if b < k:
    k -= b
else:
    print(a)
    exit()
print(total-k)
a,b,c,k=map(int,input().split())
print(a)
s=[]
ans=0
for i in range (a):
    s.append(1)
for i in range (b):
    s.append(0)
for i in range (c):
    s.append(-1)
for i in range (k):
    ans+=s[i]
print(ans)
A, B, C, K = map(int, input().split())
 
if K <= A:
  print(K)
elif K <= A + B:
  print(A)
else:
  print(K - B)
A,B,C,K = map(int,input().split())

S = K - (A+B+C)

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

b = K - A - B #Bのカードで水増しした後

if b >= 0:
    print(A + b*(-1))
if b < 0:
    print(A)
a, b, c, k = map(int, input().split())
n = 0
for i in range(k):
  if a != 0:
    n += 1
    a -= 1
  elif b != 0:
    b -= 0
  else:
    n -= 1
    
print(n)
#-*-coding:utf-8-*-
a,b,c,k = map(int, input().split())
sum = 0

if a > k:
  sum = a 
elif (a + b) < k:
  sum = a 
else:
  sum = a + b - (k - a - b)
  
print(sum)
A,B,C,K=list(map(int,input().split()))
if (A+B)>=K and A<=K:
    print(A)
elif (A+B)>=K and A>=K:
    print(K)
elif (A+B)<K:
    t=A-(K-A-B)
    if t<=0:
        print("0")
    else:
        print(t)
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())
ans = 0

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

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

sum = 0

if (a+b) >= k:
    sum = (k -a) * 1
    print(sum)
else:
    sum = a * 1
    sum += -1 * (k-a-b)
    print(sum)
a,b,c,k = map(int , input().split())
maxans = 0
flag = 1
if(k <= a):
    print(a)
    flag = 0
if(k >= a):
    maxans += a
    k -= a
    #print(maxans,k)
if (k != 0 and k >= b):
    k -= b
    #print(maxans,k)
if (k != 0):
    maxans -= (k)
if(flag):
    print(maxans)
A,B,C,K=(int(x) for x in input().split())

if K <= A+B:
    print(A)
elif K > A+B:
    print((K-(A+B))*-1)
abck = input('')
a = int(abck.split(' ')[0])
b = int(abck.split(' ')[1])
c = int(abck.split(' ')[2])
k = int(abck.split(' ')[3])

cnt=0
left=k

#A
if a > k:
    left=0
    cnt=a
else:
    left-=a
    cnt+=a

if left>0:
    left-=b

if left>0:
    cnt-=left
        
print(cnt)
a,b,c,k=map(int,input().split())
xa=min(k,a)
k-=xa
xb=min(k,b)
k-=xb
if k==a:print(a)
else:print(a-k)
A, B,C,K = map(int, input().split())


ans = A
if(K-A<=0):
    print(ans)
elif(K-A-B<=0):
    print(ans)
else:
    ans = ans + (K-A-B)*-1
    print(ans)
#
from collections import Counter

k = list(map(int,input().split()))
pick = k[3]
maxi = 0
while pick>0:
        maxi = max(maxi,maxi+k[0]*(1))
        pick = pick-k[0]
        maxi = max(maxi,maxi+k[1]*(0))
        pick = pick-k[1]
        maxi = max(maxi,maxi+k[2]*(-1))
        pick = pick-k[2]


print(maxi)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

if a + b >= k:
    print(a)
elif c >= k - (a + b):
    print(a - (k - (a + b)))
else:
    print(a - c)
a, b, c, k = map(int, input().split())
if a + b >= k: print(a)
else: print(a - (k - (a + b)))
#a,b=(int(x) for x in input().split()) #数値の時




#a,b=(x for x in input().split()) 
a,b,c,k=(int(x) for x in input().split())

if(k<=a):
  print(a*k)
else:
  sum=a
  t=k-a
  if(t<=b):
    print(sum)
  else:
    
    
    t2=t-c
    print(sum-c)
A,B,C,K = map(int,input().split())
dif = K - (A + B)
ans = 1 * A

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

if k <= a + b:
  ans = a
else:
  ans = 2 * a + b - k
  
print(ans)
arr = list(input().split())
A=int(arr[0])
B=int(arr[1])
C=int(arr[2])
K=int(arr[3])


sum=0
#print('K : ' + str(K) + '   SUM : ' + str(sum))

if K > A :
	sum+=A
else:
	sum+=K
K-=A
#print('K : ' + str(K) + '   SUM : ' + str(sum))
if K > 0:
	if K > B :
		sum+=B
	else:
		sum+=K

	K-=B
	#print('K : ' + str(K) + '   SUM : ' + str(sum))

	if K > 0:
		sum-=K
		#print('K : ' + str(K) + '   SUM : ' + str(sum))

print(sum)
A,B,C,K=(int(x) for x in input().split())

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

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

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

x=k-a-b
y=a-x
if x<=0:
    print(a)
else:
    print(y)
ABCK = list(map(int,input().split()))

A = ABCK[0]
B = ABCK[1]
C = ABCK[2]
K = ABCK[3]

count = 0

if (A + B) >= K:
    count = 1 * A
else:
    count = 1 * A + 0 * B + (-1) * (K - C)


print(count)
a, b, c, k = map(int, input().split())
n = (a + b) - c
print(n)
a, b, c, k = map(int, input().split())
if a + b >= k:
    print(max(a, k))
else:
    print(a - (k - a - b))
a, b, c, k = map(int, input().split())
sum = 0
for i in range(a+1):
    for j in range(b+1):
        if sum <= (1*i) + (-1*(k - i - j)):
            sum = (1*i) + (-1*(k - i - j))
print(sum)
A,B,C,K=map(int,input().split())
if(A>=K):
  print(A)
elif(A<K and A+B>=K):
  print(A)
else:
  print(A-(K-(A+B)))
a,b,c,x=map(int,input().split())

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

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

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