peterverebics/CodeNet_Python_118 huggingface dataset:
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+b:
    print(min(a,k))
else:
    c = k-a-b
    print(int(a-c))
A, B, C, K = map(int,input().split())
t = 0
if A < K:
    t += A
    if B < K-A:
        t -= K-A-B
else:
    t += K
print(t)
a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print(a-abs(a+b-k))
a,b,c,k = [int(e) for e in input().split(" ")[:4]]

if a < k:
	a_rest = k-a
	if b < a_rest:
		b_rest = a_rest-b
		print(a-b_rest)
	else:
		print(a)
else:
	print(k)
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

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

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

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

a = i[0]
b = i[1]
c = i[2]
d = i[3]

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

if K<=A:
  print(K)

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

ans = 0

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

print(ans)
import sys
a, b, c, k = map(int, input().split())
r = 0
x = min(a, k)
k -= x
r += x
if k==0:
    print(r)
    sys.exit()
k -= b
if k <= 0:
    print(r)
    sys.exit()
x = min(k, c)
r -= x
print(r)
a, b, c, k = map(int, input().split())

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

if k-a>=0:
  k=k-a
  count=a
  if k-b>=0:
    k=k-b
    count-=k
else:
  count=k

print(count)
a, b, c, k = [int(tmp) for tmp in 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()))
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())

s = K - A
m = 0
if s >= 0:
  m += A
else:
  print(K)
  exit()
if s - B >= 0:
  s -= B
else:
  print(m)
  exit()
if s - C >= 0:
  print(m + (-C))
else:
  print(m - s)
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(K)
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())

ans = 0
if a >= k:
  ans = k
  print(ans)
elif a + b >= k:
  ans = a
  print(ans)
else :
  ans = a + (-1)*(k - a - b)
  print(ans)
A,B,C,K = list(map(int,input().split()))
if A >= K:
    print(K)
    exit()
if A+B >= K:
    print(A)
    exit()
c = K-(A+B)
print(A-c)
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, C, K = LI()

ans = -mod
if A >= K:
    ans = K
elif A + B >= K:
    ans = A
else:
    ans = A - (K - A - B)
print(ans)
A,B,C,K = (int(x) for x in input().split())
if A >= K:
  print(K)
elif A < K and K <= A+B:
  print(A)
else:
  print(A-(K-(A+B)))
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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


if __name__ == "__main__":
    main()
X, Y, Z, K = map(int, input().split())
if X >= K:
    print(K)
elif X+Y >= K:
    print(X)
elif X+Y+Z >= K:
    print(X-(K-X-Y))
a, b, c, k = map(int, input().split())
# 1, 0, -1
if k <= a:
  print(k)
elif k <= a + b:
  print(a)
else:
  print(a - (k - a - b))
import io, os
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
R = lambda : map(int, input().split())
a, b, c, k = R()
ans = min(a, k)
if a > ans or k <= a + b:
    print(ans)
else :
    print(ans - min(c, k - a - b))
a, b, c, k = [int(i) for i in input().split()]
r = 0
if k <= a:
    r += k
    k = 0
else:
    r += a
    k -= a
if k <= b:
    k = 0
else:
    k -= b
if k != 0:
    r -= k
print(r)
A,B,C,K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)

if A>=K:
    print(1*K)
elif A+B>=K :
    print(K-B)
else:
    print((A*1)+(B*0)+((K-B-A)*(-1)))
def main():
    a,b,c,k = map(int, input().split())
    ans = 0
    if k > 0:
        ans += min(a,k)*1
        k -= min(a,k)
    if k > 0:
        k -= min(b,k)
    if k > 0:
        ans += min(c,k)*(-1)
        k -= min(c,k)
    print(ans)
if __name__ == "__main__":
    main()
a,b,c,k=map(int,input().split())
if k<a:
  ans=k
elif k<a+b:
  ans=a
else:
  d=k-a-b
  ans=a-d
print(ans)
def main():
    import sys
    
    a, b, c, k = tuple(map(int, sys.stdin.readline().split()))
    
    total = 0
    if(k>a):
        total += 1*a
        k -= a
        if(k>b):
            k -= b
            if(k>c):
                total += -1*c
            else:
                total += -1*k
    else:
        total = 1*k
    print(total)
    
if __name__ == "__main__":
    main()
line = input().split()
a = int(line[0])
b = int(line[1])
c = int(line[2])
k = int(line[3])

a_count = min(k, a)
score = a_count - max(0, k - a_count - b)

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

ans = 0

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

def main(A, B, C, K):
  point = 0
  if K<=A:
    return K
  point += A
  K -= A
  if K<=B:
    return point
  K -= B
  return point-K

print(main(A, B, C, 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())
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())
p = 0
if a >= k:
    p = k
elif a + b >= k:
    p = a
else:
     p = a - (k - a - b)
print(p)
from sys import stdin
A, B, C, K = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
if K <= A:
    ans = K
elif K <= A+B:
    ans = A
else:
    ans = A-K+A+B
print(ans)
a, b, c, k = map(int, input().split())
numA = min(a, k)
numB = min(b, k-numA)
numC = min(c, k-numA-numB)
print(numA - numC)
a,b,c,k =  list(map(int, input().split()))

r =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())
if K <= A:
    print(K)
    exit()

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

if K <= A+B+C:
    print(2*A-K+B)
    exit()

else:
    print(A-C)
    exit()
a,b,c,k= map(int,input().split())

if a+b>=k:
  print(min(a,k))
else:
  print(2*a+b-k)
one, zero, minus_one, choice = map(int, input().split())
tmpsum = 0

if one >= choice:
    print(choice)
else:
    tmpsum = one
    choice = choice - one

    if zero >= choice:
        print(tmpsum)
    else:
        choice = choice - zero
        print(tmpsum - choice)
A,B,C,K = map(int,input().split())


if K < A:
    print(K)
elif A <= K and K <= A + B:
    print(A)
else:
    print(A-(K-(A+B)))
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    res = 0

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

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

    if C >= K:
        res -= K
        K = 0
    else:
        res -= A
        K -= C

    print(res)


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

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

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

count = 0
if a < k:
    count += a
    if a+b < k:
        count -= k-a-b
else:
    count = k

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

print(min(A,K)-min(max(K-A-B,0),C))
A, B, C, K = [int(v) for v in input().strip().split(" ")]


if K <= A:
    result = K
elif K > A:
    K = K - A
    result = A
    if K <= B:
        result = result
    else:
        K = K - B
        result = result - K

print(result)
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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


if __name__ == '__main__':
    resolve()
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*2 - k + b)
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)
elif a<k<=a+b:
    print(a)
else:
    print(a - (k-a-b))
def 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)

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

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

print(ans)
A, B, C, K = map(int, input().split())
ans = 0
ans += 1 * min(A, K)
K = max(K-A-B, 0)
ans -= 1 * min(C, K)
print(ans)
abck = input().split(" ")
a = int(abck[0])
b = int(abck[1])
k = int(abck[3])

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


if(K <= A):
    print(K)
else:
    K -= A
    if(K <= B):
        print(A)
    else:
        K -=  B
        print(A - K)
A,B,C,K = map(int,input().split())
ans = 0
left = K
ans = min(A,K)
left -= A
if left > 0:
    left -= B
    if left > 0:
        ans -= left
print(ans)
def solve(A, B, C, K):
  card_counts = [A,B,C]
  card_points = [1,0,-1]
  card_remain = K
  max_point = 0
  
  for i in range(3):
    if card_remain > card_counts[i]:
      card_remain -= card_counts[i]
      max_point += card_counts[i] * card_points[i]
    else:
      max_point += card_remain * card_points[i]
      break
  return max_point

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

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

if A >= K:
    print(1 * K)

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

else:
    print(1 * A + -1 * (K - A - B))
a,b,c,k = map(int,input().split())
ans = 0
cur = min(k,a)
ans = ans + cur
k = k - cur
k = max(0,k)
cur = min(k,b)
k = k - cur
k = max(0,k)
cur = min(k,c)
ans = ans - cur

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

result = 0

if k <= a:
    result += k
else:
    result += a
k -= a
k -= b
if k > 0:
    result -= k
print(result)
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))
#coding: utf-8
A, B, C, K = map(int, input().split())
# li = [1 for _ in range(A)] + [0 for _ in range(B)] + [-1 for _ in range(C)]
ans = 0
li = [A, B, C]
ll = [1, 0, -1]
i = 0
while K > 0:
    if li[i] <= K:
        ans += ll[i] * li[i]
        K -= li[i]
    else:
        ans += ll[i] * K
        K = 0
    i += 1
print(ans)
a, b, c, k = list(map(int, input().split()))

ans = 0

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

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

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

res = min(a,k)
k -= a

if k>0:
    k -= b

if k>0:
    res -= min(c,k)

print(res)
A, B, C, K = map(int, input().split())
cnt = 0
if K - A < 0:
  print(K)
  exit()
cnt += A
K -= A
if K - B < 0:
  print(cnt)
  exit()
K -= B
if K - C < 0:
  print(cnt - K)
  exit()
cnt -= C
print(cnt)
import sys

a, b, c, k = map(int, sys.stdin.readline().split())

sumi = 0


sumi += min(a, k)
k -= min(a, k)
if k > 0:
  k -= min(b, k)
if k > 0:
  sumi -= min(c, k)
  k -= min(c, k)

print(sumi)
a = list(map(int, input().split()))

sum = 0

for i in range(3):
    if a[3] <= 0:
        break
    if a[i] >= a[3]:
        sum += (1 - i) * a[3]
    else:
        sum += (1 - i) * a[i]
    a[3] -= a[i]
        
print(sum)
a,b,c,k = map(int, input().split())
print(min(k,a) - (k-a-b if k-b>a else 0))
a, b, c, k = map(int, input().split())

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

ans = 0

if A > K:
    ans = 1 * K
else:
    ans = A
    K -= A
    if B > K:
        ans += 0 * B
    else:
        K -= B
        if C >= K:
            ans -= 1 * K
print(ans)
A,B,C,K = map(int,input().split())
if A < K:
    if A + B < K:
        print(A + (-1 * (K - A - B)))
    else:
        print(A)
else:
    print(K)
a, b, c, k = (int(x) for x in input().split())
if k <= a:
  max = k
elif k <= (a+b):
  max = a
else:
  max = k if k <= a else a-1*(k-(a+b))
print(max)
a,b,c,k = map(int,input().split())
print(min(k, a) - max(0, k-a-b))
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

a,b,c,k = inL()
cnt = 0
if k >= a:
    cnt += a
    k -= a
else:
    cnt += k
    print(cnt)
    exit()

k -= b

if k>0:
    cnt -= k

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

if K<A:
    print(1*K)
else:
    if K<A+B:
        print(A)
    else:
        if K<A+B+C:
            print(A-(K-(A+B)))
        else:
            print(A-C)
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)
from sys import stdin

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

x = 0

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

print(x)
A, B, C, K = map(int, input().split())
out = min(A, K) - max(K-A-B, 0)
print(out)
a, b, c, k = map(int, input().split())
# print(a)
# print(b)
# print(c)
# print(k)

# sum = (1) * (a) + (0) * (k-a) + (-1) * (k-a-b)

if k > a:
  sum = (1) * (a) + (-1) * (k-a-b)
elif k == a:
  sum = (1) * (a)
else:
  sum= sum = (1) * (k)

# if k-a <= b:
#   sum = sum + (0) * (k-a)
# else:
#   sum = sum + (0) * b

# sum = sum + (-1) * (k-a-b)

# print('sum')
print(sum)
a,b,c,k=map(int,input().split())
ans=0
ans+=min(k,a)
k-=min(k,a)
k-=min(k,b)
ans-=min(k,c)
print(ans)
a, b, c, k = list(map(int, input().split()))

left = k
sum = 0
cards = (a, b, c)

for i, card in enumerate(cards):
  if card <= left:
    sum += card * (1-i)
    left -= card
  elif left > 0:
    sum += left * (1-i)
    left = 0

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())

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

print(score)
import itertools
from collections import defaultdict
import collections
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

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))
a,b,c,k = (int(x) for x in input().split())

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

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

print(min(a,k)-max(0,k-a-b))
a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
else:
    print(a - ((k-a)-b))
a, b, c, k = map(int, input().split())
ans = 0
if k <= a:
  ans += k
elif k <= (a + b):
  ans += a
else:
  ans += a - (k - (a + b))
print(ans)
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))
inp = input()
inp = inp.split()
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
k = int(inp[3])
if k <= a:
    print(k)
else:
    sum = a
    k = k - a
    if k <= b:
        print(sum)
    else:
        k = k - b
        sum = sum - k
        print(sum)
a = input().split()

pura = int(a[0])     #1
zero = int(a[1])     #0
mai  = int(a[2])     #-1
num  = int(a[3])     #枚数
total = 0
k = num-pura-zero

if pura >= num:
    total = num
else:
    total = pura
    if zero >= num - pura:
        total = pura
    else:
        total = pura-(k)
print(total)
a, b, c, k = map(int, input().split())

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

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

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

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

if B < K:
    K -= B
else:
    print (ans)
    exit()

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

count = 0
x = 0

if K - A >= 0:
    x = K - A
    count = A * 1
else:
    count = K * 1

if x >= 0:
    x = x - B
    if x >= 0 and C != 0:
        C = K - A - B
        count = count + C * -1

print(count)
a,b,c,k = map(int,input().split())
if a >= k:
    print(k)
elif a < k <= a+b:
    print(a)
else:
    hami = k - a - b
    print(a - hami)
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)
elif k <= a + b :
  print(a)
else :
  print( a + ( k - a - b ) * (-1) )
a,b,c,k=map(int,input().split())
ans=min(a,k)
k=max(0,k-a)
if k==0:
    print(ans)
    exit()
k=max(0,k-b)
if k==0:
    print(ans)
    exit()
ans-=min(c,k)
k=max(0,k-c)
if k==0:
    print(ans)
    exit()
import sys

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

ans = 0
if k <= a:
    print(k)
elif a < k <= (a+b):
    print(a)
else:
    print(a - (k - a - b))
A, B, C, K = [int(i) for i in 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 + B >= K:
    print(A)
else:
    print(A - (K - A - B))
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

A, B, C, K = mapint_inp()
# 1, 0, -1

ans = 0
if A >= K:
    print(K)
else:
    K -= A
    if B >= K:
        print(A)
    else:
        K -= B
        print(A+(-1)*K)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

    if A >= K:
        print(K)
        return
    
    ans += A
    K -= A

    if B >= K:
        print(ans)
        return
    
    K -= B

    print(ans - K)

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

ans = 0
ans += 1 * min(a, k)
k -= a

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

if k > 0:
    ans += -1 * min(c, k)

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

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

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

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

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

if a < k:
  max += a
  if c < k-a-b:
    max -= c
  else:
    max -= (k-a-b)
else:
  max += k

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


if a>=k:
    Result=k
elif a+b>=k>a:
    Result=a
else:
    Result=2*a-k+b

print(Result)
*a, k = map(int, input().split())

s = 0
b = [1, 0, -1]
for i, j in enumerate(a):
    n = min(j, k)
    k -= n
    s = s + b[i]*n
    if k<=0:
        break
print(s)
#!/usr/bin/env python3
# coding: utf-8
def main():
    A, B, C, K = map(int, input().split())
    s = 0
    s += min(A, K) * 1
    K = max(K - A, 0)
    s += min(B, K) * 0
    K = max(K - B, 0)
    s += min(C, K) * -1
    print(s)
if __name__ == "__main__":
    main()
import numpy as np

A, B, C, K = map(int, input().split())
AB = A + B
if K < A:
  result = K
elif AB < K:
  result = A - (K - AB)
else:
  result = A
print(result)
#!/usr/bin/env python3
import sys

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

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

suma = 0


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

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