Problem:
 Score : 200 points    Problem Statement We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0 s and C cards with -1 s.  We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?      Constraints  All values in input are integers.  0 \leq A, B, C  1 \leq K \leq A + B + C \leq 2 \times 10^9         Input Input is given from Standard Input in the following format:  A  B  C  K       Output Print the maximum possible sum of the numbers written on the cards chosen.        Sample Input 1 2 1 1 3      Sample Output 1 2  Consider picking up two cards with 1 s and one card with a 0 .
In this case, the sum of the numbers written on the cards is 2 , which is the maximum possible value.       Sample Input 2 1 2 3 4      Sample Output 2 0       Sample Input 3 2000000000 0 0 2000000000      Sample Output 3 2000000000

Solution (Python):
A, B, C, K = [int(i) for i in input().split()]

import sys

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

r1 = K - A
cnt = A

if B >= r1:
  print(cnt)
  sys.exit()

r2 = r1 - B
print(cnt - r2)

Solution (Python):
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)

Solution (Python):
A, B, C, K = (int(x) for x in input().split())
AB = A + B
if K < A:
    print(K)
elif AB < K:
    print(A - (K-AB))
else:
    print(A)

Solution (Python):
a,b,c,k = list(map(int,input().split()))
ans = 0
for x, y in zip([a,b,c], [1,0,-1]):
  if k <= 0:
    break
  ans += min(x,k) * y
  k -= min(x,k)

print(ans)

Solution (Python):

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

Solution (Python):
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) * (-1))

print(ans)

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

Solution (Python):
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)

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

Solution (Python):
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 = n-b
    if n <= 0:
        print(sum)
        exit()
    
    n = n-c
    if n <= 0:
        sum = sum - (k-(a+b))
        print(sum)
        exit()

main()

Solution (Python):
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

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

tmp = 0
res = 0

if k <= a:
    res = k
elif k <= a + b:
    res = a
else:
    res = 2 * a + b - k

print(res)

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

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

print(ans)

Solution (Python):
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))

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

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

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

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

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

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

Solution (Python):
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))

Solution (Python):
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))

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

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

Solution (Python):
a,b,c,k=map(int,input().split());count=0
if k<=a: print(k)
elif k<=a+b: print(a)
else: print(a-(k-a-b))

Solution (Python):
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))

Solution (Python):
N = list(map(int,input().split()))
if(N[0] >= N[3]):print(N[3])
else:
  if(N[1] >= (N[3]-N[0])):print(N[0])
  else:print(N[0]-(N[3]-N[0]-N[1]))

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

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

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

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

Solution (Python):
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))

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
a,b,c,k =list(map(int,readline().rstrip().split()))
if k <= a:
  print(k)
elif k > a and k <= a + b:
  print(a)
else:
  print(a -(k-(a+b)))

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

Solution (Python):
a,b,c,d = map(int,input().split())
cnt = d-a
if cnt > 0:
    num = 1*a
    cnt -=b
    if cnt > 0:
        num = a + (d-a-b)*(-1) 
else:
    num = 1*d
print(num)

Solution (Python):
a,b,c,k = list(map(int,input().split()))
ans = min(a,k)
k = max(0,k-a-b)
ans -= k
print(ans)

Solution (Python):
[A, B, C, K] = [int(i) for i in input().split()]

j1 = A - K
j2 = A + B - K
if j2 >0: 
    if j1 < 0: 
        print(A)
    else:
        print(K)
else:
    print(A + j2)

Solution (Python):
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)))

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

A = min(A, K)
B = min(K - A, B)
C = min(K - A - B, C)
assert A + B + C >= K

print(A - C)

Solution (Python):
if __name__ == '__main__':

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

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

    print(ans)

Solution (Python):
def main() -> None:
    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))
    return


if __name__ == '__main__':
    main()

Solution (Python):
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)

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

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

ans = min(A, K) - max(0, K - (A + B))

print(ans)

Solution (Python):
a, b, c,k = map(int, input().split())
score = 0
remain = k

if a >= k:
    score = k
elif a < k and k <= a + b:
    score = a
else:
    score = a - (k-a-b)
print(score)

Solution (Python):
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))

Solution (Python):
a,b,c,k = map(int,input().split())
if k <= a :
    print(k)
else :
    m = min(k,a)
    k -= a

    if k <= b :
        print(a)
    else :
        n = min(k,b)
        k -= b
        l = k
        print(1*m+(-1)*l)

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
import sys

input=sys.stdin.buffer.readline





def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))






def main():
	a,b,c,k=MI()
	ans=min(a,k)
	ans-=max(k-a-b,0)
	print(ans)







if __name__=="__main__":
	main()

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

if A >= K:
    print(K)
elif A + B >= K:
    print(A)
elif A + B + C >= K:
    print(A + (-1) *(K - A - B))
else:
    print(A - B)

Solution (Python):
def easy_linear_programming():
    A, B, C, K = map(int, input().split())
    if K <= A:
        print(K)
    elif K - A <= B:
        print(A)
    else:
        k = K - A - B
        print(A - k)
        
easy_linear_programming()

Solution (Python):
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)))

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

Solution (Python):
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))

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

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

if c<=k:
  ans -=c
else:
  ans -= k
print(ans)

Solution (Python):
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)

Solution (Python):
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(2*A+B-K)

Solution (Python):
cards=input()
new=cards.split()
a=int(new[0])
b=int(new[1])
c=int(new[2])
k=int(new[3])
if a>k:
    print(k)
else:
    if a+b>k:
        print(a)
    else:
        sum=a+(k-(a+b))*(-1)
        print(sum)

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

ans = 0

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

k -= min(b, k)

ans -= min(c, k)

print(ans)

Solution (Python):
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))

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

    result = A if K >= A else K
    K -= A
    if K <= 0:
        print(result)
        return

    K -= B
    if K <= 0:
        print(result)
        return

    result -= K
    print(result)

main()

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

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

Solution (Python):
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))

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

result = min(a, k)
k -= a
if k > 0:
  k -= b

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

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

s = []
x = 0

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
elif k <= a + b + c:
    print(2 * a + b - k)
else:
    print(a - c)

Solution (Python):
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)

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

max_val = 0
if k <= a:
    max_val += k
else:
    max_val += a
    k -= a
    if k <= b:
        pass
        
    else:
        k -= b
        max_val -= k

print(max_val)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

point = 0

if A <= K:
    point += A
    K -= A
else:
    point += K
    K = 0

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

point -= K

print(point)

Solution (Python):

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

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

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

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

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

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

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

Solution (Python):
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))

Solution (Python):
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)

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

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

Solution (Python):
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)

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

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

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

Solution (Python):
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))

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

Solution (Python):
[A, B, C, K] = map(int, list(input().split(' ')))
left = K
ans = 0

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

left = left - B

if(left > 0):
    ans -= left

print(ans)

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

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

Solution (Python):

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

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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))

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

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

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

print(A - temp)

Solution (Python):
a,b,c,k=map(int,input().split());print(min(a,k)-max(k-a-b,0))

Solution (Python):
a,b,c,k = [int(x) for x in input().split()]
ans = 0
if k <= a:
  ans += k
elif k <= a + b:
  ans += a
else:
  ans += a - (k - a - b)
print(ans)

Solution (Python):
a, b, c, k = map(int,input().split())
ans = min(k, a) - max(0, k - a - b)
print(ans)

Solution (Python):

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

Solution (Python):
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))

Solution (Python):
a, b, c, k = map(int, input().split())
print(min(a, k) - max(0, k-a-b))

Solution (Python):

def main():
    a, b, c, k = map(int, input().split(" "))
    ans = 0
    ans += min(a,k)
    k = max(k-a-b,0)
    ans -= k
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
A, B, C, K = map(int, input().split())
ans = min(A, K) - max(0, K - A - B)
print(ans)

Solution (Python):
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 - b
    print(a - s)

Solution (Python):
l = input().split()
n1 = int(l[0])
n0 = int(l[1])
n = int(l[2])
k = int(l[3])

ans = 0

if k >= n1:
    ans += n1

else:
    ans += k

k -= n1

k -= n0

if k > 0:
    ans -= k

print(ans)

Solution (Python):
a,b,c,k = map(int,input().split())
s = 0

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

print(s)

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

Solution (Python):
def easyLinearProgramming():
  A, B, C, K = map(int, input().split())
  if K <= A:
    print(K)
    return
  if K <= A + B:
    print(A)
    return
  print(2 * A + B - K)

easyLinearProgramming()

Solution (Python):
A, B, C, K = map(int, input().split())
ans = max(0, min(K, A)) - max(0, K-A-B)
print(ans)

Solution (Python):
def main(A, B, C, K):
    """
    a = [1 for _ in range(A)]
    b = [0 for _ in range(B)]
    c = [-1 for _ in range(C)]
    k = a + b + c
    ans = sum(k[:K])
    """
    if K <= A:
        return K
    if A <= K <= A+B:
        return A
    else:
        return A - (K-A-B)

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

Solution (Python):
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))

Solution (Python):
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(a-(k-a-b))

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

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

Solution (Python):
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))

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

ans = 0

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

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

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

cnt=0

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

Solution (Python):
A, B, C, K = map(int, input().split())
ret = 0

for numberOfCards, point in [(A, 1), (B, 0), (C, -1)]:
  if K >= numberOfCards:
    K -= numberOfCards
    ret += numberOfCards * point
  else:
    ret += K * point
    break
    
print(ret)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    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 )




main()

Solution (Python):


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

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

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

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

else:
  d = k - (a + b)
  print(a - d)

Solution (Python):
A, B, C, K = [int(v) for v in input().split()]

s = 0
while K:
    if A and K:
        if K >= A:
            K -= A
            s += A
            A -= A
        else:
            s += K
            K -= K
    if B and K:
        if K >= B:
            K -= B
        else:
            K -= K
    
    if C and K:
        if K >= C:
            K -= C
            s -= C
            C -= C
        else:
            s -= K
            K -= K

        
print(s)

Solution (Python):


def solve(A: int, B: int, C: int, K: int):
    if A >= K:
        return K
    K -= A
    if B >= K:
        return A
    K -= B
    return A - K


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


if __name__ == "__main__":
    main()

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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
def main():
    abck = [int(_x) for _x in input().split()]
    a = abck[0]
    b = abck[1]
    c = abck[2]
    k = abck[3]

    kk = k

    total = 0
    if kk >= a:
        kk = kk - a
        total += a
    else:
        print(kk)
        return

    if kk >= b:
        kk = kk - b
    else:
        print(total)
        return

    total = total - kk
    print(total)


main()

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

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

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

Solution (Python):
A,B,C,K=map(int,input().split())
x =K-A
y =x-B
if x<=0:
    print(K)
else:
    if y<=0:
        print(A)
    else:
        print(A-y)

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

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

Solution (Python):
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)

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

ans = 0

ans += min(K, A)
K = max(K - A, 0)

ans += 0
K = max(K - B, 0)

ans -= K

print(ans)

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

if '__main__' == __name__:
    resolve()

Solution (Python):
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))

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

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

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

print(m)

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

koa = 0
if A<K:
  koa = A
else :
  koa = K
kob = 0
if B<K-koa:
  kob = B
else :
  kob = K-koa


sum = koa+0*kob+(K-(koa+kob))*-1
print (sum)

Solution (Python):
A,B,C,K=map(int,input().split())
print(min(A,K)-max(min(C,K-A-B),0))

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

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

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

print(ans)

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

ans = 0
if A > K:
  ans += 1*K
else:
  ans += 1*A
  K = K - A
  if B > K: 
    ans += 0*K
  else:
    ans += 0*B
    K = K - B
    if C > K:
      ans += -1*K
    else:
      ans += -1*C

print(ans)

Solution (Python):
a, b, c, k = (int(x) for x in input().split())
ans = 0

if k < a: ans += k * 1
elif a <= k <= a + b: ans += a * 1
elif a + b < k <= a + b + c: ans += a * 1 + (k - (a + b)) * (-1)
print(ans)

Solution (Python):
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()

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

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):

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)

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

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

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

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

k -= min(b,k)

ans -= k
print(ans)

Solution (Python):
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))

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

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

ans = 0
if k < a:
    ans = k
else:
    ans += a
    k = k - a
    if k < b:
        ans = ans
    else:
        ans = ans
        k = k - b
        if k < c:
            ans -= k
        else:
            ans = a - c

print(ans)

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

Solution (Python):
a,b,c,d=map(int, input().split())

if d<a:
  print(d)
elif d<b:
  print(a)
else:
  print(2*a-d+b)

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

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

Solution (Python):
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)

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

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

print(Ans)

Solution (Python):
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))

Solution (Python):
A,B,C,K=map(int,input().split())
b=0

if A<=K:
    b=A

elif A>K:
    b=K
    
if A+B<K:
    b+=-(K-A-B)
print(b)

Solution (Python):
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)

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


if 0 < K <= A:
    print(K)
elif A < K < A + B:
    print(A)
else:
    C_num = K - (A + B)
    print(A - C_num)

Solution (Python):
d = input()
d = d.split()
a = int(d[0])
b = int(d[1])
c = int(d[2])
k = int(d[3])
f = 0
if a < k:
    f = f + a
    k = k - a
    if b < k:
        k = k - b
        f = f - k
    else:
        f = f
else:
    f = k
print(f)

Solution (Python):
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)

Solution (Python):
from sys import exit

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

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

Solution (Python):
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)

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

if A >= K:
	print(K)
elif B >= K - A:
	print(A)
elif C >= K - A - B:
	print(A - (K - A - B))

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

if A > K:
    print(K)
elif A + B > K:
    print(A)
else:
    print(A + (-1) * (K - (A + B)))

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

point = 0 

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

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

Solution (Python):
from sys import stdin,stdout
one,zero,neg1,k=list(map(int,stdin.readline().split()))
o1=o0=o3=0
o1=min(k,one)
left=k-o1
o2=min(zero,left)
left-=o2
o3=max(0,min(left,neg1))
print(o1-o3)

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

Solution (Python):
a, b, c, k = (int(i) for i in input().split())
res = 1 * min(a, k) + 0 * min(b, max(0, k - a)) + -1 * min(c, max(0, k - a - b))
print(res)

Solution (Python):
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))

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

Solution (Python):
a, b, c, k = [int(x) for x in input().split()]
print(min(2*a + b-k, a, k))

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

Solution (Python):
A, B, C, K = map(int, input().split())
k = K
a = min(A, k)
k -= a
b = min(B, k)
k -= b
c = min(C, k)
print(a-c)

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

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

Solution (Python):
x,y,z,k=map(int,input().split())
s=min(k,x)
k=k-s
if(k>0):
    k=k-min(k,y)
if(k>0):
    f=min(k,z)
    s=s-f
print(s)

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