peterverebics/CodeNet_Python_118 huggingface dataset:
a, b, c, k = map(int, input().split())

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

if A+B >= K:
    print(A)
else:
    print(A-(K-A-B))
import numpy as np
n=input().split()
A=int(n[0])
B=int(n[1])
C=int(n[2])
D=int(n[3])
a = np.array([1,0,-1])
b = np.array([A,D-A,D-A-B])
c = np.array([0,B,D-B])
if A>=1:
    print(sum(a*b))

if A==0 and B==0:
    print("-1")  

if A==0 and B>=1:
    print(sum(a*c))
x = list(map(int, input().split()))

a = x[0]
b = x[1]
c = x[2]
k = x[3]

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

ans = 0

if A + B >= K:
    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(max(A + B - C, -1 * K))
# coding: utf-8
a, b, c, k = map(int, input().split())
x = 0

x += a
k -= a
if k <= b:
    print(x)
else:
    k -= b
    x -= k
    print(x)
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 A >= K:
    print(A)
    

elif A + B >= K:
    print(A)

elif A + B < K:
    c = -1 * (K-(A+B))
    #print(c)
    #print(A)
    cc = A + c
    print(cc)
from sys import stdin


def get_result(data):
    A, B, C, K = data
    if (A + B) >= K:
        return A
    else:
        return A - (K-(A+B))


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)
a, b, c, k = map(int, input().split());
num = a;

if k >= a + b:
  num -= k - (a + b);
  
print(num)
abck = input().split()

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


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

    if A < K:
        if B < (K-A):
            print(A - (K-A-B))
        else:
            print(A)
    else:
        print(A)

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

total=0
total+=a

if k - a == 0:
  print(total)
elif k - a < 0:
  print(total-k)
else:
  k-=a
  if k - b <= 0:
    print(total)
  else:
    k-=b
    print(total-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)))
we = str(input())
r = we.split(" ", -1)

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

def max_sum(A, B, C, K):
	if (A and B and C and K) >= 0:   
		if A >= K:
			print(A)
		elif A < K:
			R = K - A
			if B >= R:
				print(A)
			elif B < R:
				S = R - B
				print(A + S*(-1))
max_sum(A, B, C, K)
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())
ans=0
if a>=k:
    ans=a
else:
    k-=a
    if b>=k:
        ans=a
    else:
        k-=b
        ans=a-k
print(ans)
def main():
    a,b,c,k = map(int, input().split())

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


if __name__ == '__main__':
    main()
a,b,c,k=map(int,input().split())
if k<=a+b:
    print(a)
else:
    print(a-(k-(a+b)))
n=input().split()
if (int(n[3])<=int(n[0])+int(n[1])):
  print(int(n[0]))
else:
  print((int(n[0]))-(int(n[3])-int(n[0])-int(n[1])))
A, B, C, K = map(int,input().split())

if K <= A:
	print(A)
	#　すべてAが取れる場合
else:
	if K <= A+B:
		print(A)
		# AとBの合計よりも取る枚数が少ない場合は-1のCを取らないのでAの総数と同じ値になる
	else:
		x = K - A -B
		#　合計値KからAとBの値を取り除いた値
		# この数値*-1をAをすべて取った値に足す
		print(A-x)
a,b,c,d= map(int,input().split())
if a+b >=d or  (b==0 and c == 0) :
    print(a)
    exit()
while d>0 :
  d = d-1
  if a != 0:
   a = a-1
  elif a == 0:
    b = b-1
  elif b == 0 :
    c = c-1
print(d)
a , b ,c , k = map(int, input().split())


tmp = k - a # k比a的張數多
tmp2 = k -a-b

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


if k - a <= 0:
    print(k)
elif k - a > 0 and k - a - b <= 0:
    print(a)
else:
    s = k - a
    print(s - c)
def main():
    a, b, c, k = map(int, input().split())
    if a + b >= k:
        print(max(a, k))
    else:
        x = k - a - b
        print(a - x)


main()
N = input().split()

a =int(N[0])
b =int(N[1])
c =int(N[2])
d =int(N[3])

A = min(a,d)


    
    
q = d - a

if b < q:
    print(A)
else:
    print(A - d - a -b)
a,b,c,k = map(int, input().split())

if a >= k:
  an = k
  bn = 0
  cn = 0
elif a+b >= k:
  an = a
  bn = k - (a)
  cn = 0
else:
  an = a
  bn = b
  cn = k - (a+b+c)
  
print(an-cn)
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 = map(int, input().split())
    
if(k-a<=0):
    print(1*a)
elif(k-a-b<=0):
    print(1*a - 0*b)
else :
    print(1*a+0*b-1*(k-a-b))
a,b,c,k=map(int,input().split())
print(a-max(k-a-b,0))
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
else :
  K=A-K
  n+=K

print(n)
a, b, c, d = map(int, input().split())

ans = 0

if d > a:
    ans += a
else:
    ans += d

if d-a-b > c:
    ans -= c
else:
    ans -= d-a-b

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

d=A
if K-A-B>0:
    d=d-(K-A-B)
print(d)
card    = list(map(int, input().split()))
count  = card[3] - card[0] - (card[1])
answer = card[0]

if count <= 0:
    print(answer)
else:
    count -= card[2]
    answer -= count * -1
    print(answer)
a,b,c,k = map(int,input().split())

if k <= a + b:
    print(a)
else:
    print(2*a - k + b)
a,b,c,k=(int(x) for x in input().split())
if a+b > k:
  print(a)
else:
  print(a+(c-k))
a, b, c, k = map(int, input().split())
s = 0
if  a + b >= k:
    s = a
elif a < k:
    s = a - k
else:
    s = a - (c - b) 
print(s)
a,b,c,k = map(int,input().split())
if a >= k:
    print(a)
elif a < k and b >= k-a:
    print(a)
else:
    print(a-(k-a-b))
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    A,B,C,K = map(int,input().split())
    abc = [A,B,C]
    ans = 0

    a = A
    b = (K-a) if (K-a)>=0 and (K-a)<B else B
    c = K-A-B
    print(a-c)


main()
i = input().split()
a = int(i[3])-int(i[0])
b = int(i[3])-int(i[0])-int(i[1])

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

if ans <= 0:
    ans = 0
print(ans)
x = [int(x) for x in input().split()]

ans = x[0]
x[3] -= x[0] + x[1]
if x[3] >= 0:
    ans -= x[3]

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

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


def function(a,b,c,k):
    count =0
    if a>=k:
        return a
    else:
        count =a

        k =k-a
        a=0

        while(k>0):
            if b>0:
                b-=1

            elif c>0:
                c-=1
                count-=1



            k-=1

        return count
print(function(a,b,c,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 a <= k:
    ans += a
else:
    print(a)
    exit()
k = k - a
if b <= k:
    ans += 0
else:
    print(ans)
    exit()
k = k - b
ans += k*-1
print(ans)
A, B, C, K = map(int, input().split())
score = 0

if K - (A + B) > 0:
    # C を取る
    score = A - (K - (A + B))
else:
    # C を取らない
    score = A

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

if(k-a-b<=0):
    print(1*a+0*(k-a))
else :
    print(1*a+0*(k-a)-1*(k-a-b))
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
if A+B>=K:print(A)
else:print(A+(K-(A+B)*(-1)))
import math

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

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

if A[0]>=A[3]:
  print(A[0])
else:
  if A[0]+A[1]>=A[3]:
    print(A[0])
  else:
    if A[0]+A[1]+A[2]>=A[3]:
      print(A[0]-A[3]+A[0]+A[1])
    else:
      print(A[0]-A[2])
a=input().split()
pl1=int(a[0])
pl0=int(a[1])
pl_1=int(a[2])
draw=int(a[3])
#print(pl1,pl0,pl_1,draw)

if(pl1+pl0>=draw):
  print(pl1)
else:
  all_card=pl1+pl0+pl_1
  #print(all_card)
  draw_pl_1=all_card-draw
  #print(draw_pl_1)
  print(pl1-draw_pl_1)
A, B, C, K = map(int, input().split())

print (A, B, C, K)

sum = 0

if K - A >= 0:
  K -= A
  sum += A
else:
  print(sum)
  exit

if K - B >= 0:
  K -= B
  sum += 0
else:
  sum += 0
  print(sum)
  exit

if K - C >= 0:
  K -= C
  sum += -C
else:
  sum += -1 * K

print (sum)
A,B,C,K = map(int,input().split())
print(A,B,C,K)
res = 0
if A>=K:
  res= 1*A
else:
  for b in range(K-A,B+1):
    c = K-A-b
    if c >= 0:
      ans = 1*A + 0*b + (-1)*c
      res = max(res,ans)
    else:
      break
print(res)
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))
x = input().split()

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

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

ans = a
cnt = k-a
if cnt <=0:
    print(a)
    exit()
cnt = cnt -b
if cnt <= 0:
    print(a)
    exit()
ans = ans-cnt

print(ans)
A,B,C,K=map(int,input().split())
if K>A+B:
	K=K-(A+B)
	ans=A-K
else:
	ans=A
print(ans)
a, b, c, k = list(map(int, input().split()))
if k<=b:
  print(k)
elif b<k<=b+a:
  print(b)
else:
  print(2*b-k+a)
a,b,c,k = list(map(int, input().split()))
if a + b >= k:
  print(a)
else:
  print(2 * a + b - k)
A,B, C,K = input().split()
a = int(A)
b= int(B)
c =int(C)
k=int(K)
if k-a-b-c==0:
    print(a-c)
elif k-a-b>0 and k-a-c-b<0:
    print(2*a-k+b)
else:
    print(a)
A, B, C, K = map(int,input().split())
# 1 0 -1 Num
result = 0
if K <= A + B:
	print(A)
else:
	x = K-A-B
	print(A-x)
# coding: utf-8
# Your code here!

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

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

if K <= A+B:
    print(A)
elif A+B < K <= A+B+C:
    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))
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 = map(int,input().split())

print(a-(1*(k-a-b)))
A,B,C,K=map(int,input().split())
maxC=K-(A+B)

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

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

t = K - A
if t <= 0 or t <= B:
    print(A)
else:
    print(A - (t - B))
a, b, c, k = map(int, input().split())
sum = 0
if k > a:
    sum = a
    if k-a <= b:
        sum = a
    else:
        sum = 2*a+b-k
print(sum)
def Qb():
    a, b, c, k = map(int, input().split())

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

    print(ans)


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

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

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

if a >= k:
    print (a)
elif a+b>= k:
    print (a)
else:
    print (a - s)
a, b, c, k = map(int, input().split())
if(k <= a + b):
    print(a)
else:
    print(a - (k - (a + b)))
l = list(map(int,input().split()))
a = l[0]
b = l[1]
c = l[2]
k = l[3]
x = 0
print(a+0*max(0,k-a)+-1*max(0,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 = list(map(int,input().split()))
if k <= a + b:
    print(a)
else:
    print(2*a+b-k)
a,b,c,k = map(int,input().split())

if a+b >= k:
    print(a)
else:
    print(a + ((k-(a+b)) * -1))
import numpy as np
n=input().split()
A=int(n[0])
B=int(n[1])
C=int(n[2])
D=int(n[3])
a = np.array([1,0,-1])
b = np.array([A,D-A,D-A-B])
if A>=1:
    print(sum(a*b))
def main():
    A, B, C, K = map(int, input().split())

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

if __name__ == '__main__':
    main()
abck = list(map(int, input().split()))

a = abck[0]
b = abck[1]
c = abck[2]
k = abck[3]

if a + b >= k:
    print(1 * a)
else:
    z = (k - a - b)
    print(a-z)
#B
ABCK = input().split(' ')
A = int(ABCK[0]) ; B = int(ABCK[1]) ; C = int(ABCK[2])
K = int(ABCK[3])
if K <= (A + B):
    print(K)
else:
    print(A - (K - A - B))
a, b, c, k = map(int, input().split())
count = 0

if k-a-b <= 0:
  count = a
else:
  count = a - (k-a-b)

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

minus_a = k - a
if minus_a == 0 :
    print(a)
elif minus_a < b :
    print(a)
else:
    minus_c = minus_a - b
    print(a - minus_c)
a,b,c,k = map(int,input().split())
z=k-min(k,a)
z=k-min(k,b)
print(a-z)
s = input().split()

if s[3] == "0" :
    print(0)
    
elif ( int(s[0]) >= int(s[3]) ) or ((int(s[3]) - int(s[0]) <= int(s[1]))) :
    print(s[3])
elif int(s[3]) - int(s[0]) > int(s[1]) :
    print(int(s[0])- (int(s[3])-int(s[0])-int(s[1])))
a, b, c, k = map(int, input().split())

if a + b >= k:
    print(a)
else:
    d = k - a - b
    print(a - d)
a, b, c, k = (int(x) for x in input().split())
sum = k if k < a else a-1*(k-(a+b))
print(sum)
a, b, c, k = map(int, input().split())
print(a if a+b>=k else a-(k-a-b))
import sys
input = sys.stdin.readline

def main():
    A, B, C, K = map(int, input().split())
    print(2*A+B-K)


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

if a + b >= k:
    print(a)
else:
    print(a - (k - (a + b)))
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(a,b,c,k):
    res = 0
    if k <= a:
        res = k
    if a < k <= a+b:
        res = a
    else:
        res = a - (k - (a+b))
    return res

a,b,c,k = mi()
print(main(a,b,c,k))
a,b,c,k=map(int,input().split());count=0
if k<=a: print(k)
elif k<=a+b: print(a)
else: print(a-1*c)
if __name__ == '__main__':
    a, b, c, k = map(int, input().split())

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

b_cards=min(K,B)
K-=b_cards
ans+=b_cards*0

c_cards=min(K,B)
K-=c_cards
ans+=c_cards*-1

print ans
A,B,C,K = map(int,input().split())
res = 0
if A>=K:
  res= 1*A
else:
  for b in range(K-A,B+1):
    c = K-A-b
    if c >=0:
      ans = 1*A + 0*b + (-1)*c
      res = max(res,ans)
print(res)
i = input().split()
a = int(i[3])-int(i[0])
b = int(i[3])-int(i[0])-int(i[1])

if i[3] <= i[0]:
  print(i[3])
elif a == int(i[1]):
  print(int(i[3]) - int(i[1]))
elif a < int(i[1]):
  print(int(i[0]) - int(i[3]))
elif b == int(i[2]):
  print(int(i[0]) - int(i[2]))
else:
  print(int(i[0])*2 + int(i[1]) - int(i[3]))
a,b,c,k=map(int,input().split())
ans=0
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())
i = 0
K = K - A
while K > i :
    if B > 0 :
        K = K-B
        B = B -B
    elif C > 0 :
        A = A - 1
        K = K - 1
print(A)
# B - Easy Linear Programming
def main():
    
    a, b, _, k = map(int, input().split())
    ans = a
    if k > a:
        k = k - a
        if k > b:
            k = k - b
            if  ans - k < 0:
                print(0)
            else:
                print(ans - k)
        else:
            print(ans)
    else:
        print(ans)

if __name__ == '__main__':
    main()
import sys
input = sys.stdin.readline

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

ans = 0

if k <= a + b:
    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(2*a+b-k)
A,B,C,K = map(int,input().split())
ans = 0

if A <= K:
    ans += A
    if B <= K:
        ans += 0
        if C <= K:
            ans -= K-A-B
    else:
        ans += 0
else:
    ans += K
print(ans)
a,b,c,k=map(int,input().split());count=0
if k<=a or k<=a+b: print(a)
elif k<c: print(a+b+-1*k)
else: print(a+b+-1*c)
import sys
a, b, c, k = map(int, input().split())
if a >= k:
    print(a)
    sys.exit()
else:
    if b >= k-a:
        print(a)
    else:
        print(a-(k-a-b))
        sys.exit()
def actual(A, B, C, K):
    score = 0

    if A >= K:
        return A
    else:
        score += A

        if B >= (K - A):
            return score
        else:
            if C >= (K - A - B):
                score -= (K - A - B)
                return score
            else:
                raise Exception()
                
A, B, C, K = [int(x) for x in input().split()]

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

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

s += a
k -=a
k -=b
s -= max(k , 0)
print(s % ( 10**9 + 7 ) )
a,b,c,k = (int(x) for x in input().split())
if a >= k:
    print(a)
elif a + b >= k:
    print(a)
else:
    print(a - (k - (a + b)))
    pass
a,b,c,k = map(int,input().split())
if k == 0:
    print("0")
elif a < k:
    print(a-k)
elif a+b > k:
    print(a)
else:
    ab = a+b
    ans = a - (k-ab)
    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())
if k <= a + b:
    print(a)
elif k <= a + b + c:
    print(a - (k - a - b))
A,B,C,K = map(int,input().split())
if A+B >= K:
  print(A)
else:
  print(A-(K-A-B))
s  = input().split(" ")
a  = int(s[0])
b  = int(s[1])
c  = int(s[2])
k  = int(s[3])

t = 0
if a >= k:
  print(a)
else:
  t += a
  if b >= (k - a):
    print(a)
  else:
    t -=  (k - a -b)
    print(t)
import sys

ans=0
A, B, C, K = (int(x) for x in input().split())

if A>K:
  print(K)
  sys.exit(0)
else:
  K-=A
  ans+=A
  
if B>K:
  print(K)
  sys.exit(0)
else:K-=B

if C>K:
  print(ans-K)
  sys.exit()
else:
  ans-=C
  print(ans)
A, B, C, K = map(int, input().split())

ans = 0
if (A + B) >= K:
    ans = A
else:
    K -= A + B
    ans = A - K

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


if a <=k  and k <= a+b:
    print(a)
elif a + b < k and k <= a  + b + c:
    print(a-k+a+b)
else: 
    print(0)
a, b, c, k = map(int, input().split())
ans = 0
while k > 0:
    if a > 0 and b == 0 and c == 0:
        ans = a
        break
    elif a == 0 and b > 0 and c == 0:
        ans = 0
        break
    elif a == 0 and b == 0 and c > 0:
        ans = -c
        break
    elif a > 0:
        ans += 1
        a -= 1
    elif b > 0:
        ans += 0
        b -= 1
    elif c > 0:
        ans += -1
        c -= 1
    k -= 1
print(ans)
abck = [int(n) for n in input().split()]
if abck[0] + abck[1] >= abck[3]:
    print(abck[3])
else:
    print(abck[0] * 2 - abck[3] + abck[1])
card    = list(map(int, input().split()))
count  = card[3] - card[0] - card[1]
answer = card[0]

if count > 0:
    if count < card[2]:
        answer = answer + (count * -1)
        print(answer)
    else:
        count = count - card[2]
        answer = answer + (count * -1)
        print(answer)
else:
    print(answer)
A,B,C,K= list(map(int, input().split()))

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


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

ans = 0



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

if b <= k:
    k -= b

ans -= k


print(ans)