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 = map(int, input().split())

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



if B >= bullet:
    print(score)
    exit()
else:
    bullet -= B
    pass
  
if C >= bullet:
    print(score - bullet)
    exit()
else:
    exit()

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

if a <= k:
    if b <= (k-a) :
        total = a - (k-a-b)
    else:
        total = k
else:
    total = k

print(total)

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

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007



def main():
	
	a, b, c, k= IN()
	
	if k <= a:
		return k
	elif k <= a+b:
		return a
	else:
		m = k - a - b
		return a - m
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import sys
A,B,C,K = map(int,input().split())
ans = K-A
if ans<= 0:
    print(K)
    sys.exit(0)
ans -= B
if ans<= 0:
    print(A)
    sys.exit(0)
print(A-(K-A-B))

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

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
        else:
            ans-=k
else:
    ans+= k

print(ans)

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

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

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

Solution (Python):


def main():
    A, B, C, K = map(int, open(0).read().split())

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


main()

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

if a >= k:
    print(k * 1)
    sys.exit()
elif k > a:
    if a + b >= k:
        print(a * 1)
        sys.exit()
    elif k > a + b:
        print(a * 1 + (k - a - b)* -1)
        sys.exit()

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

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

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

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

print(ans)

Solution (Python):
A_1, B_0, C_minus1, K = map(int, input().split(' '))

max_total = 0

if(K <= A_1):
  max_total = K
elif(K > A_1 and K <= (A_1 + B_0)):
  max_total = A_1
else:
  left = K - (A_1 + B_0)
  if(left <= C_minus1):
    max_total = A_1 - left
  else:
    max_total = A_1 - C_minus1
  
print(max_total)

Solution (Python):
if __name__=="__main__":
    num_plus_one, num_zero, num_minus_one, total_num = map(int, input().split(' '))

    if total_num <= num_plus_one:
        counter = total_num
    elif total_num <= num_plus_one + num_zero:
        counter = num_plus_one
    elif total_num <= num_plus_one + num_zero + num_minus_one:
        counter = num_plus_one - (total_num - num_plus_one - num_zero)
    else:
        counter = num_plus_one - num_minus_one

    print(counter)

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

R = 0
if A >= K:
  R = K
  K = 0
else:
  R = A
  K -= A

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

if C >= K:
  R -= K
else:
  R -= C

print(R)

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

Solution (Python):


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

Solution (Python):
l = list(map(lambda x:int(x), input().split(" ")))
a = l[0]
b = l[1]
c = l[2]
k = l[3]
if a >= k:
    print(k)
elif a < k:
    if b >= k-a:
        print(a)
    elif b < k-a:
        print(a-(k-a-b))

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

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-K+B)

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

if K <= A:
    value = K
else:
    value = A + B*0
cnt = A + B

if cnt >= K:
    print(value)
else:
    value -= K - cnt
    print(value)

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,N = map(int,input().split())
sum_card = [A,B,C]
for i in range(2):
    sum_card[i+1] += sum_card[i]
if(N<A):
    print(N)
elif(N-sum_card[1]<=0):
    print(A)
elif(N-sum_card[1]>0 and C - (N-sum_card[1])>0):
    print((N-sum_card[1])*(-1)+A)
elif(N>=sum_card[2]):
    print(A-C)

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):
s  = input().split(" ")
a  = int(s[0])
b  = int(s[1])
c  = int(s[2])
k  = int(s[3])
 
t = 0
if a >= k:
  print(k)
else:
  t += a
  if b >= (k - a):
    print(a)
  else:
    if c <= (k - a -b): 
    	t -=  c
    else:
      	t -= (k - a -b)
    print(t)

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-k+b)

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

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, raw_input().split())

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

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

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

k -= a+b
if k <= 0:
    print(sum)
    exit()

if k >= c:
    sum -= c
else:
    sum -= k

print(sum)

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

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

if 0 < K:
    ans = ans + 0 * B
    K = K - B

if 0 < K:
    ans = ans + (-1) * K

print(ans)

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

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

Solution (Python):


def main():
    A, B, C, K = [int(x) for x in input().split()]
    if K > A+B:
        print(A - (K-(A+B)))
    elif K < A:
        print(K)
    else:
        print(A)

if __name__ == '__main__':
    main()

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

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


AA = 0
BB = 0
CC = 0
Nokori = K 
if Nokori >= A:
    AA = A
    Nokori = Nokori - A
elif Nokori == 0:
    pass
else:
    AA = Nokori
    Nokori = 0
if Nokori >= B:
    BB = B
    Nokori = Nokori - B
elif Nokori == 0:
    pass
else:
    BB = Nokori
    Nokori = 0
if Nokori >= C:
    CC = C
elif Nokori == 0:
  pass
else:
    CC = Nokori
print(AA*1+BB*0+CC*(-1))

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

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

Solution (Python):
def linear(A, B, C, K):
    s = 0
    if K <= A:
        return K

    s += A
    K -= A


    if K <= B:
        return s

    K -= B

    return s - K

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

Solution (Python):

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

if K >= A:
    a = A
else:
    print(K)
    exit()
if A == 0 and C == 0:
    print(0)
    exit()

if A == 0 and B == 0:
    print(-1*K)
    exit()

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

print(a+c)

Solution (Python):
A, B, C, K = map(int, input().split())
result = min([A, K])
K -= result
if K != 0:
  K -= min([B, K])
if K != 0:
  result -= min([C, K])
print(result)

Solution (Python):
a, b, c, k = map(int, input().split())
if k <= a:
    k_pa, k_pb, k_pc = k , 0, 0 
elif k > a and k-a <= b:
    k_pa, k_pb, k_pc = a, b, 0
elif k > a and k-a > b:
    k_pa, k_pb, k_pc = a, b, k-a-b
point = k_pa - (k-k_pa-k_pb)
print(point)

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

Solution (Python):

import numpy as np
import math
from collections import Counter
import sys

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

total = 0

if a >= k:
    print(k)
    sys.exit()
else:
    if a+b >= k:
        print(a)
        sys.exit()
    else:
        if k-(a+b) <= c:
            total = a - (k- (a+b))
            print(total)
            sys.exit()
        else:
            total = a - c
            print(total)

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

ans = 0

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

print(ans)

Solution (Python):
def create_union_answer(a, b, c, k):
    if a >= k:
        return k
    if a + b >= k:
        return a
    
    can_c = k - (a + b)
    if can_c > c :
        can_c = c
    return a - can_c

values = input().split()

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

answer = create_union_answer(a, b, c, k)
print(answer)

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

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

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

cnt = 0
idx = 0

if k >= a :
  k -= a
  cnt += a
else:
  cnt += k
  k = 0

if k != 0:
  if k >= b:
    k -= b
  else:
    k = 0

if k != 0:
  if k >= c:
    cnt -= c
    k -= c
  else:
    cnt -= k
    k = 0

print(cnt)

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

Solution (Python):
temp = input()
temp = temp.split()
A = int(temp[0])
B = int(temp[1])
C = int(temp[2])
K = int(temp[3])

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

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

Solution (Python):
a, b, c, k = [int(e) for e in input().split()]

count=0

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

print(count)

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

ans = 0

if k > a:
    ans += a
else:
    ans += k
    print(ans)
    exit()

k = k-a

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


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

print(ans)

Solution (Python):
def solve(a, b, c, k):
    if k <= a:
        return k
    elif k <= a + b:
        return a
    else:
        return a - (k - (a + b))

if __name__ == '__main__':
    a, b, c, k = [int(arg) for arg in input().split()]
    print(solve(a, b, c, k))

Solution (Python):
a, b, c, k = map(int, input().split())
box = []
result = 0

if k <= a:
    print(k)
    quit()
else:
    k = k - a
    result = a
    if k <= b:
        print(result)
        quit()
    else:
        k = k - b
        if k <= c:
            result = result - k
            print(result)
            quit()
        else:
            result = result -c
            print(result)
            quit()

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

if a - k < 0:
    sc = a
    k = abs(a - k)
else:
    print(k)
    exit()

if b - k < 0:
    k = abs(b - k)
else:
    print(sc)
    exit()

if c - k < 0:
    sc-=c
else:
    sc-=k
print(sc)

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

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

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

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

Solution (Python):
x = list(map(int, input().split()))
A = x[0]
B = x[1]
C = x[2]
K = x[3]
ans = 0
if K >= A:
    ans += A * 1
    K += - A
else:
    ans += K * 1
    K += - A
    
if K <= 0:
    print(ans)
    exit()
else:
    if K >= B:
        ans += B * 0
        K += - B
    else:
        ans += K * 0
        K += - B

if K <= 0:
    print(ans)
    exit()
else:
    if K >= C:
        ans += C * -1
        K += K - C
    else:
        ans += K * -1
        K += K - C
    print(ans)

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

if K<=A:
  ans=K
elif  A<K and K<=A+B:
  ans=A
elif  K>A+B and 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(K)
elif A<K<=A+B:
    print(A)
else:
    print(2*A-K+B)

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

sum =0 

flg = False

if K-A > 0:
    sum+= A
    K = K- A
else:
    sum += K
    flg = True

    
if flg ==False:
    if K-B > 0:
        K= K-B
    else:
        flg = True
        
if flg ==False:
    if K-C >0:
        sum = sum - C
    else:
        sum = sum - K
        
        
print(sum)

Solution (Python):
a, b, c, z = (int(i) for i in input().split())

res = min(a, z) - max(0, z - a - b)

print(res)

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

ans = 0

ans = A
K = K - A

if K < 0:
  ans = ans + K
  print(ans)
  sys.exit(0)

if K > 0:
  K = K - B

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

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

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

ans = 0

while True:
    if (K <= A):
        ans += K * 1
        break
    elif (K > A):
        K -= A
        ans += A * 1
    
    if (K <= B):
        break
    elif (K > B):
        K -= B

    if (K <= C):
        ans -= K * 1
        break
    else:
        ans -= C * 1

    break

print(ans)

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

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

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

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

if(K <= A):
    print(K)
elif((K > A) & (K <= (A + B))):
    print(A + (A - B) * 0)
else:
    print(A + ((A - B) * 0) - (K - (A + B)))

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

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

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

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

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):
z = input().split()
a = int(z[0])
b = int(z[1])
c = int(z[2])
k = int(z[3])
if(1 <= k <= a+b+c <= 2*(10**9)):
    if(k <= a):
        print(k)
    elif(k <= a+b):
        print(a)
    else:
        print(a - (k-(a+b)))
else:
    print('err')

Solution (Python):
s = input().split();
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
k = int(s[3]);
max = 0;
x = a;
if( (a - k) >= 0 ):
    max = k;
elif((a + b - k) >= 0):
    max = a;
else:
    k = k - (a + b);
    max = -k;
    max = max + a;

print(max);

Solution (Python):
a,b,c,k=[int(i) for i in input().split()]
score=0

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

        
print(score)

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

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

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

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

print(ans)

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

if a>0 and k>0 and a<=k:
  k=k-a
  ans=ans+a
elif a>0 and k>0 and a>k:
  ans=ans+k
  k=0

if b>0 and k>0 and b<=k:
  k=k-b
elif b>0 and k>0 and b>k:
  k=0
  
if c>0 and k>0 and c<=k:
  k=k-c
  ans=ans-c
elif c>0 and c>0 and c>k:
  ans=ans-k
  k=0

  
print(ans)

Solution (Python):








import sys,collections

A,B,C,K = map(int,sys.stdin.readline().split())



print(1*min(A,K)+0*min(B,max(K-A,0))-1*min(C,max(K-A-B,0)))

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

count = 0


if a > 0 and a <= k and k > 0:
  count = count + a
  k = k - a
elif a > 0 and a > k and k > 0:
  count = k
  k = 0

if b > 0 and b <= k and k > 0:
  k = k - b
elif b > 0 and b > k and k > 0:
  k = 0
  
if c > 0 and c <= k and k > 0:
  count = count - c
  k = k - c
elif c > 0 and c > k and k > 0:
  count = count - k
  k = 0
    
print(count)

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

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

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

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

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

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

if a > 0:
    if a <= k:
        res += a
        k -= a
    elif a > k:
        res += k
        k = 0

if k > 0 and b > 0:
    if b <= k:
        k -= b
    elif b > k:
        k = 0

if k > 0 and c > 0:
    if c <= k:
        res -= c
        k -= c
    elif c > k:
        res -= k
        k = 0

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

tmp = K
maxSum = 0
i = 0
if(tmp>A):
  maxSum+=A
  tmp-=A
else:
  maxSum+=K
  tmp = 0


if(tmp>B):
  tmp-=B
else:
  tmp = 0


if(tmp>C):
  maxSum-=C
  tmp-=C
else:
  maxSum-=tmp
  tmp = 0


print(maxSum)

Solution (Python):

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

    ans = 0
    cnt = min(K, A)
    ans += cnt * 1
    K -= cnt
    if K < 1:
        return print(ans)

    cnt = min(K, B)
    ans += cnt * 0
    K -= cnt
    if K < 1:
        return print(ans)

    ans += K * -1

    print(ans)

if __name__ == "__main__":
    resolve()

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

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

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


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

Solution (Python):

import sys

info = input().split(' ')
card_one = int(info[0])
card_zero = int(info[1])
card_minus = int(info[2])
number = int(info[3])

sumnum = 0

if (number >= card_one):
    number = number - card_one
    sumnum = sumnum + card_one
else:
    print(number)
    sys.exit()

if (number >= card_zero):
    number = number - card_zero
else:
    print(sumnum)
    sys.exit()

if (number >= card_minus):
    sumnum = sumnum - card_minus
    print(sumnum)
else:
    sumnum = sumnum - number
    print(sumnum)

Solution (Python):
a, b, c, k = map(int, input().split())
x=min(a,k)
y = min(b, k - a)
print(x+(k-a-y)*-1)

Solution (Python):
def main(a: int, b: int, c: int, k: int):
    ans = 0

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

    if b >= k:
        print(ans)
        return

    _b = min(b, k)
    k -= _b

    _c = min(c, k)
    ans -= _c

    print(ans)


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

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

print(sum_num)

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

    


def check(a,b,c,k):
    resutlt = 0
    if a > k:
        result = k
        return result
    else:
        k -=a
        result = a
        if b>k:
            return result 
        else:
            k -= b
            result  -= k
            return result 

print(check(a,b,c,k))

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


print(num-k)

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

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

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

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

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

Solution (Python):
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

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

    a = K if A>=K else A
    b = (K-a) if B>=(K-a) else B
    c = K-a-b if C>=(K-a-b) else C
    print(a-c)


main()

Solution (Python):

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

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

Solution (Python):


def main():

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

    if K > A:
        num += A
        K -= A
        if K > B:
            K -= B
            num -= K
    else:
        num+=K

    print(num)

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

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

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

print(sum)

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

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 > A+B:
    print(A-K+A+B)

Solution (Python):
import math
from functools import reduce
import itertools
A,B,C,K = map(int,input().split())

count=0
if A>=K:
    ans=K
else:
    count+=A
    if A+B>=K:
        ans=A

    else:
        count-=(K-(A+B))
        ans=count

print(ans)

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

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

max  = 0

if(a > k):
  max += k
  k = 0
else:
  max += a
  k -= a 
  
if(k != 0)and(b > k):
  k = 0
elif k != 0:
  k -= b
  
if(c > k):
  max -= k
elif k != 0:
  max -= c

print(max)

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

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

x=0

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

Solution (Python):


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

number = 0
count = 0
if (k <= a):
    count = count + k
    print(count)
    exit()

if (k > a):
    number = number + a
    count = count + a

kk = k - number

if (kk <= b):
    print(count)
    exit()

if (kk > b):
    number = number + b

kkk = k - number

if (kkk <= c):
    count = count - kkk
    print(count)
    exit()

if (kkk > c):
    count = count - c

print(count)

Solution (Python):
a1,a0,am,n = map(int, input().split())

print(min(a1,n) - min(am,max(0,n-a1-a0)))

Solution (Python):
a = list(map(int,input().split()))
A = a[0]
B = a[1]
C = a[2]
K = a[3]
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)
if a < k <= a + b:
    print(a)
if a + b < k:
    d = 2*a + b - k
    print(d)

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

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 k <= a + b:
    print(min(a, k))
    exit(0)

print(a - (k - (a + b)))

Solution (Python):

import sys
sys.setrecursionlimit(10**7)


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

ans = 0
array = [(A, 1), (B, 0), (C, -1)]

for k, v in array:
    if K > 0:
        n = min(k, K)
        ans += n * v
        K = K - n

print(ans)

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

if(K <= A+B):
  print(min(K,A))
else:
  M = A+B+C
  M = M-K
  M = C-M
  print(A-M)

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

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

Solution (Python):

import sys
input = sys.stdin.readline
A,B,C,K = list(map(int, input().split()))
a=1
b=0
c=-1
count =K
point =0
if A< K:
    point +=A
    count -=A
    K -=A
else:
    point +=K
    count =0
    print(point)
    exit()

if B < count:
    point +=0
    count -=B
    K -=B
else:
    point +=0
    count =0
    print(point)
    exit()    

if C <= count:
    point -=C
else:
    point -=count
    count =0
    
print(point)

Solution (Python):
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:
    ans += k
    print(ans)
    exit()
if c <= k:
    ans -= c
    k -= c
else:
    ans -= k
    print(ans)
    exit()
print(ans)

Solution (Python):
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

a,b,c,k = NextInts()

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

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

hoge = max(K - A - B, 0)

print(min(A, K) - hoge)

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