peterverebics/CodeNet_Python_118 huggingface dataset:
a, b, c, k = map(int,input().split())
if a <= k <= a + b:
  print(a)
elif 0 <= k < a:
  print(k)
else:
  print(2 * a + b - k)
a, b, c, k = map(int, input().split())

if k-a <= 0:
    print(k)

elif k-(a+b)<= 0:
    print(a)

elif k-(a+b)>0:
  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())
ans = 0
now = 0
if a > k:
    print(k)
    exit()
else:
    ans += a
    k -= a

if b > k:
    print(ans)
    exit()
else:
    k -= b

if c > k:
    ans += -1*k
    print(ans)
    exit()
else:
    ans += -1*c

print(ans)
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

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

nokori = K - A - B

wa = 0
while True:
    if A >= K:
        wa += K
        break
    else:
        wa += A
    if C >= nokori:
        wa -= nokori
        break
    else:
        wa -= C
        break

print(wa)
import sys
readmi = lambda: map(int, sys.stdin.readline().split())

A, B, C, K = readmi()
# result var
max_sum = 0

# check 1
max_sum = min(A, K)
K = K - max_sum

# check 0
if K > 0:
  K = K - min(B, K)

# check - 1
if K > 0:
  max_sum = max_sum - min(K, C)
# print result
print(max_sum)
def main():
    A, B, C, K = map(int, input().split())
    if K <= A+B:
        print(K) if K < A else print(A)
    else:
        num = K - A - B
        print(A - num)


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

score = 0
if K <= A:
    score = K
    print(score)
    exit()

score += A
K -= A
if K <= B:
    print(score)
    exit()

K -= B
print(score - K)
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18
#
A, B, C, K = map(int, input().split())

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

k -= a
if b >= k:
  print(a)
  exit()

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

R = K-(A+B)
if R <= 0 :
    R = 0
elif R >= C :
    R = C

S = A - R
if A > K :
    S = K

print(S)
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))
# coding: utf-8
import sys
# sys.exit()
a,b,c,k = map(int, input().split())
# sum = 0
if k <= a:
    sum = k
    print(sum)
    sys.exit()
else:
    sum = a
    k = k - a
if k <= b:
    print(sum)
    sys.exit()
else:
    k = k - b
    sum = sum - k
    print(sum)
a, b, c, k = map(int, input().split())
ans = 0
if k > a:
    k -= a
    if k > b:
        k -= b
        ans = a - k
    else:
        ans = a
else:
    ans = k
print(ans)
a, b, c, m =map(int,input().split())
i = m
ans = 0
ans += (min(a,i))
i -= a
if i <= 0:
  print(ans)
else :
  i -= b
  if i <= 0:
    print(ans)
  else:
    ans -= i
    print(ans)
A,B,C,K = map(int, input().split())
ans = 0
if K - A>=0:
    ans += A
    if K-A-B<=0:
        pass
    else:
        ans -= (K-A-B)
else:
    ans += K
print(ans)
a,b,c,k=map(int,input().split())
max=0
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)
else:
  print(A - (K - (A + B)))
a, b, c, k = map(int, input().split())

total = 0
if(a < k):
    total = a
    k = k - a
    if(b < k):
        k = k - b
        if(c < k):
            total += c * -1
        else:
            total += k * -1
    else:
        pass
else:
    total = k

print(total)
import sys
import os

def file_input():
    f = open('ABC167/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    A,B,C,K=map(int, input().split())

    sum=0
    if K>A:
        sum+=A
        K-=A
        if K>B:
            K-=B
            sum-=K        
    else:
        sum+=K

    print(sum)

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

if k <= a:
    print(k)
elif a < k <= a+b:
    print(a)
elif a+b < k <= a+b+c:
    print(a+((k-(a+b))*(-1)))
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
  ans = k
else:
  ans += a
  k -= a
  if b < k:
    k -= b
    ans -= k
print(ans)
a,b,c,k=map(int,raw_input().split())
ans=0
if a<=k:
	ans+=a
	k-=a
else:
	ans=k
	k=0
if k!=0:
	if b<=k:
		k-=b
	else:
		k=0
if k!=0:
	if c<=k:
		ans-=c
	else:
		ans-=k
print ans
a,b,c,K= map(int, input().split())
x=K-a
y=x-b
if a>=K:
    i=1*K
    print(i)
if a<K:
    i=1*a
    if y<=0:
        print(i)
    if y>0:
        i=i-y
        print(i)
a, b, c, k = [int(i) for i in input().split()]
if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print(a - (k - a - b))
def abc():
    arr=input()
    num=[int(n) for n in arr.split()]
    sum=0
    if(num[3]<=num[0]):
        sum=num[3]
    elif(num[3]>num[0] and num[3]<=num[1]):
        sum=num[0]
    elif(num[3]>num[1]):
        sum=num[0]-(num[3]-num[0]-num[1])
    print(sum)
abc()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
a,b,c,k = map(int, input().split())

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

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

Ka = max(0, min(K, A))
Kb = max(0, min(B, K-Ka))
Kc = max(0, min(C, K-Ka-Kb))

output = 1*Ka + 0*Kb + (-1)*Kc
print(output)
a, b, c, k = map(int, input().split())
ans = 0
if k <= a:
    print(k)
else:
    k -= a
    ans += a
    if k <= b:
        print(ans)
    else:
        k -= b
        ans += -1 * k
        print(ans)
a,b,c,d=map(int,input().split())
# print(a[:-1])
count=min(a,d)
d-=a
d-=b
if d<=0:
    print(count)
else:
    print(count-d)
A,B,C,K = list(map(int,input().split()))
if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(A-(K-A-B))
def resolve():
    '''
    code here
    '''
    A, B, C, K = [int(item) for item in input().split()]

    A_max = min(A, K)
    B_max = min(B, K - A_max)
    C_max = K - A_max - B_max

    print(A_max - C_max)

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

if A >= K:
    print(K)
else:
    if B >= K-A:
        print(A)
    else:
        print(A-(K-A-B))
ABCK = list(map(int, input().split()))
A = ABCK[0]; B = ABCK[1]; C = ABCK[2]; K = ABCK[3];

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)
else:
    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 += A
    K -= A
    if K >= B:
        K -= B
        ans -= K
else:
    ans += K

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

if k <= a:
    print(k)
elif (a < k) & (k <= a + b):
    print(a)
else:
    print(a-1*(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 K >= A:
    sum += A
    K -= A
else:
    sum += K

K -= B

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

print(sum)
def main():
    A,B,C,K=map(int,input().split())
    print(min(A, K) - max(0, K-A-B))
    return

if __name__=='__main__':
    main()
A, B, C, K = map(int, input().split())
if (K - A) <= 0:
    print(K)
else:
    if (K - A - B) <= 0:
        print(A)
    else:
        c = (K - A - B)
        print(A - c)
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 A >= K:
    print(K)
    exit()
    
c = A
K -= A
if B >= K:
    print(c)
    exit()
    
K -= B
c -= K
print(c)
A, B, C, K = map(int, input().split(' '))
s = 0
s += min(A, K)
K -= A
K -= B
if K > 0:
    s -= min(C, K)

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

ans = 0

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

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

d = 0

if K < A:
	d = K

elif K <= A + B:
	d = A

else:
	K = K - A - B
	d = A - K

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

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

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

    print(ans)


if __name__ == "__main__":
    main()
a, b, c, k = map(int, input().split())
    
if(k-a<=0):
    print(k)
elif(k-a-b<=0):
    print(1*a - 0*(k-a))
else :
    print(1*a+0*b-1*(k-a-b))
a,b,c,k=map(int,input().split())
 
if a>=k:
  print(k)
  exit()
else:
  if k-a<=b:
    print(a)
    exit()
  else:
    c=k-a-b
    print(a-c)
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,B,C,K = LI()
ans = min(A,K)
if A+B<K:
    ans -= K-(A+B)
print(ans)
ans = 0
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 = input().split()
IA = int(A)
IB = int(B)
IC = int(C)
IK = int(K)
ALL = IA + IB + IC
cn = 0

if IA <= IK:
    cn = cn + IA
    D = IK - IA
    if IB <= D:
        E = D - IB
        cn = cn - E
        print(cn)
    else:
        print(cn)
else:
    print(IK)
a, b, c, k = map(int, input().split())

ans = 0
num = min(a, k)
ans += num
k -= num

if k == 0:
    print(ans)

else:
    k -= b
    if k <= 0:
        print(ans)
    else:
        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))
def main():
    a, b, c, k = map(int, input().split())
    ans = min(a, k)
    k = max(k-a, 0)
    if k == 0:
        print(ans)
        return
    k = max(k-b, 0)
    if k == 0:
        print(ans)
        return
    print(ans - k)
    return


if __name__ == "__main__":
    main()
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	A, B, C, K = getlist()
	if K < A:
		print(K)
	elif A + B >= K:
		print(A)
	else:
		print(2 * A + B - K)
	




if __name__ == '__main__':
	main()
A, B, C, K = list(map(int,input().split()))
if A >= K:
  print(K)
elif A+B>=K and A<K:
  print(A)
elif A+B+C>=K and A+B<K:
  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())
 
if K <= A:
    print(str(K))
elif K <= A + B:
    print(str(A))
else:
    print(str(A - (C - (A + B + C - K))))
a,b,c,k = map(int,input().split())
print(min(a,k) if k <= a+b 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(2*A + B - K)
A,B,C,K = map(int, input().split())
 
if(A - K < 0):
    if(A + B - K < 0):
        print(2 * A - K + B)
    else:
        print(A)
else:
    print(K)
a,b,v,k = map(int,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(a-(k-a-b))
import numpy as np
import math

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

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

kotae = 0

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

print(kotae)
a,b,c,k= map(int, input().split())
tmp=0
if k <=a:
	print(k)
elif k<=a+b:
	print(a)
else:
	tmp=k-a-b
	print(a-tmp)
a,b,c,k = map(int,input().split())
if k <= a:
    print(k)
elif a < 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)
else:
    print(a+(-1)*(k-a-b))
a, b, c, k = map(int, input().split())

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

if K<=A:
	print(1*K)
elif A<K<=A+B:
	print(1*A)
else:
	print(1*A-1*(K-A-B))
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    A,B,C,K = LI()

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

    print(ans)

if __name__ == '__main__':
    main()
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+b-k)
A,B,C,K=map(int,input().split())

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

print(ans167(A,B,C,K))
a,b,c,k=map(int,input().split())
aa=0
if(k<=a):
    aa+=k
if(k>a):
    aa+=a
    k=k-a
if(k<=b and k>0):
    k=0
if(k>b):
    k=k-b
if(k<=c and k>0):
    aa=aa-k
if(k>c and k>0):
    aa=aa-c
print(aa)
def main():
    a,b,c, k = map(int, input().split())
    if a >= k:
        return k
    if a + b >= k:
        return a
    return 2*a + b - k
print(main())
A, B, C, K = list(map(int, input().split()))
if A + B >= K:
  print(min(A, K))
else:
  print(A - (K - A - B))
A,B,C,K=map(int,input().split(' '))
print(min(K,A)-max(0,K-(A+B)))
a,b,c,k = map(int,input().split())
cnt = 0
if a < k:
    cnt += a
    k -= a
else:
    cnt += k
    print(cnt)
    exit()
if b < k:
    cnt += 0
    k -= b
else:
    print(cnt)
    exit()
if c < k:
    cnt -= c
    k -= c
else:
    cnt -= k
    print(cnt)
    exit()
if __name__=="__main__":
    a,b,c,k = map(int, input().split())
    picks = 0

    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())
dif = K - (A + B)
ans = 1 * A

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


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

print(xa - xc)
def resolve():
    A, B, C, K = list(map(int, input().split()))
    print(min(A, K) - max(0, K-(A+B)))

if '__main__' == __name__:
    resolve()
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 k-a >= 0:
    sum += a
    k = k-a
else:
    sum += k
    print(sum)
    exit(0)

if k-b >= 0:
    k = k-b
else:
    print(sum)
    exit(0)


if k-c >= 0:
    sum -= c
else:
    sum -= k
    print(sum)
    exit(0)

print(sum)
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

if K < A:
    print(K)
elif A <= K <= (A+B):
    print(A)
elif (A+B) < K:
    print(A-(K-A-B))
import sys

import math
input = sys.stdin.readline
A,B,C,K = map(int,input().split())
    
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else :
    F = K - (A+B)
    print (A - F )
a,b,c,k=map(int,input().split())
if a>=k:
    print(k)
elif a<k and 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 A+B < K:
    print(A-(K-A-B))
else:
    print(A)
A,B,C,K = map(int,input().split())

if K <= A:
    print(K)
    exit()

if A < K and K <= A + B:
    print(A)
    exit()

if A+B < K:
    print(A - (K - A - B))
A,B,C,K = list(map(int,input().split()))
if A >= K:
    S = K
else:
    if B >= (K-A):
        S = A 
    else:
        S = A - (K-A-B)
print(S)
A, B, C, K = tuple(int(c) for c in input().split(' '))

if A >= K:
    print(K)
    exit()
else:
    bc = K - A  # A < K なのでbc >= 1
    assert bc >= 1
    if B >= bc:
        print(A)
        exit()
    else:
        # B < bc
        cc = bc - B
        assert cc >= 1
        print("{:.0f}".format(A - cc))
        exit()
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 + b >= k:
    print(min(a, k))
else:
    print(a - (k - a - b))
def main():
    a, b, c, k = map(int, input().split())
    if k <= a:
        print(k)
    elif k >a and k <= a+b:
        print(a)
    elif k > a+b:
        print(2*a-k+b)
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 A < 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 -= min(a, k)

ans += min(b, k) * 0
k -= min(b, k)

ans += min(c, k) * -1
k -= min(c, k)

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

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

ans = 0

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

if a >= k:
  ans = k
elif a + b >= k:
  ans = a
else:
  ans = a + (-1) * (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(2*a+b-k)
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
    ans += 1 * k
    k = 0
else:
    ans += 1 * a
    k -= a
if b >= k:
    k = 0
else:
    k -= b
    ans -= k
print(ans)
a,b,c,k= (int(x) for x in input().split())

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

A = 0
if (a<d):
  if (0 < (d-a-b)):
    A = a-(d-a-b)
  else:
  	A = a
else:
  A = d
print(A)
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] = [int(s) for s in input().rstrip().split(' ')]
ans = 0
if K <= A:
    ans = K
else:
    ans += A
    if K > A+B:
        ans -= K-A-B
print(ans)
a,b,c,k = map(int, input().split())


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

a,b,c,k=list(map(int,input().split()))
sum=0
if(a>=k):
    print(k)
    sys.exit()
else:
    sum=a
if(b>=k-a):
    print(a)
    sys.exit()
else:
    sum=sum-(k-a-b)
    print(sum)
from itertools import combinations
def main():
    a,b,c,k=map(int,input().split())
    if k<=a:
        print(k)
        return
    if k<=a+b:
        print(a)
        return
    print(a-(k-a-b))

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

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

card_left = k
ans += min(a, k)
card_left -= a
#print(card_left)
if(card_left >= 0):card_left -= b
if(card_left >= 0):ans -= card_left

print(ans)
# -*- coding: utf-8 -*-

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

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

ans = 0

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

print(a - max(0, (k - a - b)))
A,B,C,K=map(int,input().split())
print(A,B,C,K)
if A+B>=K:
    print(A)
else:
    print(A-C)
a, b, c, k = map(int, input().split())
if k <= a:
  print(k)
elif a < k and k - a <= b:
  print(a)
elif a == 0 and b ==0:
  print(-k)
elif k == 0:
  print(0)
else:
  print(k-c)
text_list = input().split()
n = 0
a = int(text_list[0])
b = a + int(text_list[1])
c = b + int(text_list[2])
for i in range(int(text_list[3])):
    if i < int(text_list[0]) + int(text_list[1]):
        continue
    elif i < int(text_list[0]):
        n += 1
    elif i < int(text_list[0]) + int(text_list[1]) + int(text_list[2]):
        n -= 1

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

if K >= A:
	sum = sum + A
	K = K - A
else:
	sum = sum + K
	K = 0
if K >= B and K >= 1:
	K = K - B
else:
	K = 0
if K >= 1:
	sum = sum - K
	K = K - C

if sum >= 1:
	print(sum)
else:
	print(0)
A,B,C,K = list(map(int,input().split()))
print(min(K,A) - min(K-(A+B),C))
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(K - B)
else:
  print(A + B - C)