peterverebics/CodeNet_Python_118 huggingface dataset:
a,b,c,k = map(int,input().split())
z=k-a
if z>0:
    z=z-b
print(a+z*-1)
a = list(map(int, input().split()))
b = [1, 0, -1]
c = 0
s = 0
for i in range(a[3]):
  if a[s] == 0:
    s += 1
  a[s] -= 1
  c += b[s]
  if a[s] == 0:
    s += 1

print(c)
def main():
    A,B,C,K=map(int,input().split())
    if K == (A+B):
        print(A)
    else:
        print(A-(K-A-B))
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)))
elif(X[0]<X[3] and X[3]-X[0]>0 and X[3]-(X[0] + X[1])==0):
  print(X[0]*1)
else:
  print(X[0]*1)
A, B, C, K = list(map(int,input().split()))

out = []
for i in [A,B,C]:
    if(i <= K):
        out.append(i)
        K = (K - i) if (K - i) >= 0 else K
    else:
        out.append(((K - i) if (K - i) > 0 else K))

if len(out) < 3:
    for i in range(3 - len(out)):
        out.append(0)

print(1*out[0] + 0*out[1] + (-1)*out[2])
a, b, c, k = map(int, input().split())

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

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

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

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

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

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

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

k1 = K - A
if k1 <= 0:
  print(A)
else:
  k2 = k1 - B
  if k2 <= 0:
    print(A)
  else:
    print(A-k2)
A,B,C,K = map(int, input().split())

if A+B >= K:
	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(a - (k - a - b))
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
        if b>=k:
            return count
        else:
            k-=b
            b=0
            count-=k

        return count
print(function(a,b,c,k))
A, B, C, K = map(int, input().split())

sum =0

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

if a > 0:
    if a < k:
        total += a
        k -= a
    else:
        k = 0
        total += k
        print(total)

if b > 0 and k > 0:
    if b < k:
        k -= b
    else:
        k = 0
        print(total)

if c > 0 and k > 0:
    if c < k:
        total -= c
        print(total)
    else:
        total -= k
        print(total)
import sys

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

ans = 0
rest = K

if A >= K:
    print(K)
    sys.exit()

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

rest -= A
rest -= B

# print(rest)
if rest <= 0:
    print(A)
    sys.exit()

rest -= B

print(-(K-A-B))
a,b,c,k = map(int,input().split())

ans = 0
for _ in range(k):
    if b == 0 and c == 0:
        ans += a
        break
    elif a == 0 and c == 0:
        break
    elif b == 0 and a == 0:
        ans -= c
        break

    if a > 0:
        a -= 1
        ans += 1
    elif b > 0:
        b -= 1
    elif c > 0:
        c -= 1
        ans -= 1

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

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

    if a + b >= k:
        print(a)
    else:
        print(2 * a + b - k)
resolve()
if __name__ == "__main__":
    num = list(map(int, input().split()))

    if (num[3] == 0):
        print(0)
    else:
        print(num[0] - num[3] + num[0] + num[1])
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 :
      if K!=0 :
        K=C-K
        n-=C-K
      else :
        pass
  else :
    pass
else :
  K=A-K
  n+=K
def main(a, b, c, k):
    total = 0
    counts = 0
    while counts == k:
        counts += 1
        if a > 0:
            total += 1
            a -= 1
        elif b > 0:
            b -= 1
        else:
            total -= 1
            c -= 1
    return total


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

    sum = 0

    n = k-a
    if n <= 0:
        sum = k
        print(sum)
        exit()
    else:
        sum = a
    n =- b
    if n <= 0:
        print(sum)
        exit()
    
    n =- c
    if n <= 0:
        sum =- (k-a-b)
        print(sum)
        exit()

main()
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 if A<K else K
    b = (K-a) if (K-a)>=0 and (K-a)<B else B
    c = K-A-B
    print(a-c)


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))
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())
ans = 0
if K<=A:
    print(K)
elif K<=A+B:
    print(A)
elif A+B+C >=K:
    ans == A-(K-A+B)
    print(ans)
a, b, c, k = map(int, input().split())
if a >= k:
    cnt = a
else:
    if a + b >= k:
        cnt = a
    else:
        cnt = a - (k - (a + b))
print(cnt)
A, B, C, K = map(int, input().split())
count = 0
if A == K:
    print(A)
    quit()
D = K-A
if (D - B) <= 0:
    print(A)
elif (D-B) > 0:
    E = (D-B)-C
    print(E)
a,b,c,k = map(int, input().split())
rest = k - a
if rest > b:
	numb = b
	numc = rest - b
else:
	numb = rest
	numc = 0
print(a-numc)
import sys
import math

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

s=K
ans = 0

s-=A
ans+=A

if (s>0):
    s-=B
    if (s>0):
       ans -= s

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

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

if K-A-B-C<=0:
  ans = A-(K-A-B)
elif K-A-B<=0:
  ans = A
elif K-A <0:
  ans = K

print(ans)
# -*- coding: utf-8 -*-
inputs = list(map(int, input().split()))

if inputs[0]+inputs[1]>=inputs[3]:
  print(inputs[0])
else:
  print(inputs[0] - (inputs[3] - inputs[0]+inputs[1]))
a,b,c,k = map(int,input().split())
ans = 0
if k<=a:
    print(a)
elif a<k and k<=a+b:
    print(a)
else:
    print(a-min(k-a-b,c))
# 1 # 0 # -1 K
a, b, c, K = map(int, input().split())
sum = 0

if K > a:
  sum += a*1
  K = K - a
elif K != 0:
  sum += int(a-K)*1
  K = 0
  
if K >b:
  sum +=b*0
  K = K - b
elif K != 0:
  sum += int(b-K)*0
  K = 0
  
if K > c:
  sum +=c*-1
  K = K -c
elif K!=0:
  sum += int(c-K)*-1
  K = 0
print(sum)
a, b, c, k = map(int, input().split())
if k <= a+b:
    print(a)
else:
    print(2*a+b-k)
A,B,C,K = map(int,input().split())
tens = 0
if A >= K or A+C >= K :
    print(A)
    exit()
else:
    print(A+K-A-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 = map(int, input().split())

if a + b >= k:
    print(a)
elif k-a-b <= c:
    print(2*a + b - k)
else:
    print(a-c)
a,b,c,k=(int(x) for x in input().split())
a1 = a
tensuu = 0
count = 0
if k-a1 > 0:
   tensuu +=a1
   count = k-(a1+b)
   if k-a1-b > 0 :
    tensuu -=count

else:
    tensuu +=a1
    exit() 
print(tensuu)
A, B, C, K = map(int, input().split())

if A > K:
  print(K)
  
temp = K - A

if temp >= B:
  print(A)
  
temp = temp - B

print(A - C)
a,b,c,k = map(int,input().split())
sum = 0
sum += a
x = k-a-b
if x >= 1:
    sum -= x
print(sum)
S = list(map(int,input().split()))
A = S[0]
B = S[1]
C = S[2]
K = S[3]

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

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

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

    return a - (k - (a + b))


print(resolve())
a,b,c,d = map(lambda x: int(x), input().split())

if a + b >= d:
  print(a)
else:
  print(2*a-d+b)
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())

ans = a
if k > (a+b):
    ans -= (k-a-b)
    
print(ans)
A,B, C,K = input().split()
Q = int(0)
Y = int(0)
for Y in range(int(K)):
    X = int(A) - Y
    Z = int(B) -X
    W = int(C) -Z
    if X >=0:
        Q += 1
        if Z>=0:
            Q+=0
            if W>=0:
                Q -= 1
print(Q)
def main():
    A, B, C, K = map(int, input().split())
    if A + B >= K:
        print(A)
    else:
        ans = A - (K - (A + B))
        print(ans)



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

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

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

if a+b >= k:
    print(a)
else:
    print(a - (k-a-b))
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(a)
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())  #数字

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

ans=0
if k<a:
    print(a);exit()
if k>=a:
    ans+=a
    k-=a
    if k==0:
        print(ans);exit()
if k>=b:
    k-=b
    if k==0:
        print(ans);exit()
print(ans-k)
a,b,c,k = list(map(int, input().split()))

ans = 0

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

ans = 1*a + 0*b - 1*c
print(ans)
a,b,c,k = (int(x) for x in input().split())

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

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

print(m)
A = list(map(int,input().split()))

if A[3] <= A[0]:
    print(A[0])
elif A[0] < A[3] and A[3] <= A[0] + A[1]:
    print(A[0])
else:
    print(A[0] - (A[3] -A[0] -A[1]))
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(k-a == 0):
  print(a)
  exit()
elif(k-a < b): # k > a 
  print(a)
  exit()
elif(k-a == b):
  print(a)
  exit()
elif(k-a-b < c):
  x = (k - a - b)
  print(a-x)
  exit()
elif(k-a-b == c):
  print(a-c)
A, B, C, K = map(int, input().split())
ans = 0
k = K
ans += k if A >= k else A
k -= A + B
ans -= k
print(ans)
def a():
    s = input()
    t = input()
    if s == t[0:-1]:
        print('Yes')
    else:
        print('No')



def b():
    a, b, c, k = map(int, input().split())
    xa = min(k, a)
    k1 = k - xa
    xb = min(k1, b)
    k2 = k1 - xb
    print(xa - k2)
    

    print(sum)

# def c():

# def d():


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

def mysum(A, B, C, K):
  if K <= A:
    return(K)
  
  if K <= A+B:
    return(A)
  
  return(A+ -1*(A+B+C-K))
 
print(mysum(A, B, C, K))
a,b,c,k = map(int, input().split())
print(a if a>k or a+b>k>=a else 2*a+b-k)
A, B, C, K = input().split(" ")
A, B, C, K = int(A), int(B), int(C), int(K)

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

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

if a>=k:
  print(a*1)
else:
  if b>=k-a:
    print(a*1)
  else:
    if c>=k-a-b:
      print(a*1 + (k-a-b)*(-1))
    else:
      print(a*1 + c*(-1))
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())

# ans = [1] * a + [0] * b + [-1] * c
# print(sum(ans[:k]))

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

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

max = 0
for i in range(A):
    max+=1
    K-=1
    if K ==0:
        break
        

if not K==0:
    for j in range(B):
        max+=0
        K-=1
    
if not K==0:
    for k in range(C):
        max-=1
        K-=1
    
print(max)
a,b,c,k = map(int,input().split())
 
ans = 0
 
if 0< k <= a:
  ans = a
  print(ans)
elif a+1 <= k <= a+b:
  ans = a
  print(ans)
else:
  ans = a-(k-a-b)
  if ans < 0:
    ans = 0
  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 = list(map(int,input().split()))

sum = 0
a_3 = a[3]
a_0 = a[0]
a_1 = a[1]
a_2 = a[2]


if a_3 <= a_0:
    print (a_3)
    
elif a_3 > a_0 and a_3 <= (a_0 + a_1):
    print (a_0)
    
else:
    sum = a_0 - (a_2 - a_1)
    print(sum)
def resolve():
    A, B, C, K = list(map(int, input().split()))

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

    return


resolve()
l = list(map(int,input().split()))
res = 0
k = l[3]
r = -1 
for i in range (3) :
  
  if res + l[i] <= k :
    res += l[i]
  else: 
    r = i
    break
d = res - k
if r != 2:
  print(res)
else :
  print(res -d)
A, B, C, K = map(int, input().split())

sum = 0
sum += A * 1
if(A + B < K):
  sum += C * (-1)

print(sum)
import sys

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


one = a
zero = k -a 
min = k -a -b

if min < 0:
    min =0

ans = 1*one-1*min
print(ans)
r=input().split()
A=int(r[0])
B=int(r[1])
C=int(r[2])
K=int(r[3])
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())

count = 0

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

print(count)
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())
l = 0

if a >= k:
    print(a)

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

if K - A - B <= 0:
    print((1 * A) - (1 * C))

elif K - A >= 0 and K - A - B < 0:
    print((1 * A))

elif K - A >= 0:
    print(1 * K)
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(k)
def main():
  a, b, c, k = map(int, input().split())
  d = k-a-b
  
  print(a + d*(-1))
  
main()
arr = [int(char) for char in input().split(" ")]
a, b, c, k = arr[0], arr[1], arr[2], arr[3]
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(K)
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)
elif k <= a+b+c:
    print(a + (k-a-b)*(-1))
A,B,C,K=map(int,input().split())
print(A if A+B>=K else A-(K-A-B))
A, B, C ,K = map(int, input().split())
ans = 0
Acnt = 0
Bcnt = 0
Ccnt = 0

for i in range(K):
    Acnt += 1
    ans  += 1
    if i == A-1:
        break

K -= Acnt

for i in range(K):
    Bcnt +=1
    if i == B-1:
        break

K -= Bcnt

for i in range(K):
    Ccnt +=1
    ans -= 1
    if i == C-1:
        break

K -= Ccnt

print(ans)
l = list(map(int,input().split()))
a = l[0]
b = l[1]
c = l[2]
k = l[3]
x = 0
print(a+0*(k-a)+-1*(k-a-b))
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)
elif A + B + C >= K:
  print(A - (K -(A + B)))
elif K == 0:
  print(0)
import sys

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

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

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

print(total - k)
A,B,C,K = map(int,input().split())

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

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

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

if a+b >= k:
	print(a)
	exit(0)
else:
	print(a-(k-(a+b)))
	exit(0)
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 A + B >= K:
		print(A)
	else:
		print(2 * A + B - K)
	




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

if(A >= K):
  print(K)
if(A+B>=K):
  print(A)
else:
  print(A-(K-A-B))
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,c,k=map(int, input().split())
    l=[]
    if k<=a:
        print(k)
    elif a<k<=a+b:
        print(a)
    else:
        print(max(0,a-(k-(a+b))))
resolve()
def main():
    a,b,c,k = map(int,input().split())
    sum = 0

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

if __name__ == "__main__":
    main()
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 K<=A:
    print(K)
elif A+B>K:
    ans ==A
    print(ans+1)
else:
    ans += A - (A+B+C-K)
    print(ans+1)
a,b,c,k=map(int,input().split())
x=k-a
y=x-b

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

ans = 0

ans += min(a, k) - min(c, k-a-b)

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

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

if k:
    total_sum -= k

print(total_sum)
# B - Easy Linear Programming
def main():
    A, B, C, K = map(int, input().split())
    if A + B >= K:
        print(A)
    else:
        print(A - (K - A - B))


if __name__ == "__main__":
    main()
a, b, c, k = map(int, input().split())
if a >= k:
  print(k)
elif a + b >= k:
  print(a)
else:
  print(2*a-k)
a,b,c,k=map(int,raw_input().split())
if k<a:
	print a
else:
	ans=0
	if a<=k:
		ans+=a
		k-=a
	if k!=0:
		if b<=k:
			k-=b
		if k!=0:
			ans+=-1*k
	print ans
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
        if T>0:
            sum = sum - T
            print(int(sum))
        else:
            print(int(sum))

    else:
        print(int(sum))

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

if D-A <= 0:
    point = A
    D -= A
    if D-B <= 0:
        D -= B
        if D-C <= 0:
            point -= C
            print(point)
        else:
            point -= D
            print(point)
    else:
        print(point)
else:
    point = D
    print(point)
a, b, c, k = map(int, input().split())

if a == k or a > k:
    print(1 * a)
elif (a + b) == k or (a + b) > k:
    print(a * 1)

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

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