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):
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))

def main(a,b,c,k):
    res = 0
    if k < a:
        res = k
    elif a <= k < a+b:
        res = a
    elif a+b <= k:
        res = a - (k - (a + b))
    return res

a,b,c,k = mi()
print(main(a,b,c,k))

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

    if _k > 0:
        r -= _k

    print(r)

Solution (Python):
import sys
import math
from  collections import defaultdict




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




if __name__ == "__main__":
	test_cases = 1
	for t in range(1, test_cases + 1):
		solve(t)

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

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

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

max_num()

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

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

print(res)

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

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

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

ans = 0

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

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 = [int(p) for p 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())
if A > K:
    ans = K
elif A+B >= K:
    ans = A
else:
    ans = A - (K-A-B)
print(ans)

Solution (Python):
import sys
import math
import itertools
import collections

def solve(A,B,C,K):
    ans = 0
    while K != 0:
        if( A != 0):
            if(K < A):
                ans += K
                break
            else:
                ans+=A
                K -= A
                A = 0
        elif(B != 0):
            if(K < B):
                break
            else:
                K -= B
                B = 0
        else:
            if(K < C):
                ans -= K
                break
            else:
                ans -= C
                K -= C
                C = 0
    return ans
def main():
    A,B,C,K =map(int,input().split())
    
    print(solve(A,B,C,K))

if __name__ == "__main__":
    main()

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

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(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*1)
    exit()
    
elif A < K and A+B >= K:
    print(A*1)
    exit()
    
elif A+B < K and A+B+C >= K:
    print(A*1 + (K-A-B)*(-1))

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

if A < K and K > 0:
    ans += A
    K -= A
elif A >= K and K > 0:
    ans += K
    K = 0

if B < K and K > 0:
    K -= B
elif B >= K and K > 0:
    K = 0

if C < K and K > 0:
    ans -= C
    K -= C
elif C >= K and K > 0:
    ans -= K
    K = 0

print(ans)

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

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

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

Solution (Python):
n = list(map(int,input().split()))
a = n[0]
b = n[1]
c = n[2]
k = n[3]
an = 0
if a>=k:
  an=k
elif a+b>=k:
  an=a
else:
  an=a-(k-a-b)
print(an)

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

Solution (Python):
import sys

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

ans += min(A, K)

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

K -= (A+B)

print(ans-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())
sum = 0

if K > A:
    K -= A
    sum = A
else:
    print(K)
    exit()

if K > B:
    K -= B
else:
    print(sum)
    exit()

sum -= K
print(sum)

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 = list(map(int, input().split()))
d = []
if k <= a:
    print(k)
elif a < k < b:
    print(a)
else:
    print(2 * a + b - k)

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

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

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

    print(ans)


resolve()

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

s = [a, a+b, a+b+c]
ans = [a, a, a-c]

if k <= a:
    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(A-(K-A-B))

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 = a-(k-a-b)


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

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

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

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

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

d = 0

if a > k:
  d += k
else:
  d += a
  k -= a
  if b > k:
    d += 0
  else:
    d += 0
    k -= b
    d -= k

print(d)

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

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

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

Solution (Python):
a, b, c, k = [int(i) for i in 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 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:
    print(k)
    exit()
else:
    ans += a
    k -= a

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

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

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

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

Solution (Python):
ABCK = list(map(int,input().split()))

A = ABCK[0]
B = ABCK[1]
C = ABCK[2]
K = ABCK[3]
sums = 0
if (K - A <= 0):
    sums += K
else:
    K = K-A
    sums += A
    if(K-B <= 0):
        sums += 0
    else:
        K = K-B
        sums += K*(-1)

print(sums)

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

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

Solution (Python):
A,B,C,K=map(int,input().split())
ans=0
ans=K
K-=A
def chk(k):
    if k>0:
        return True
    else:
        return False

if not chk(K):
    print(ans)
    exit()
ans=A
K-=B
if not chk(K):
    print(ans)
    exit()

ans=ans-K
print(ans)

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

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

Solution (Python):
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

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

Solution (Python):
import sys
input = sys.stdin.readline
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 logging

logging.basicConfig(level=logging.INFO, format="%(message)s")



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

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

    print(ans)

                
        
if __name__ == "__main__":
    main()

Solution (Python):
x=input().split(" ")
a=int(x[0])
b=int(x[1])
c=int(x[2])
number=int(x[3])
if number<=a:
    print(number)
elif number<=a+b:
    print(a)
else:
    print(2*a+b-number)

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

print (ans)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

INF = float("inf")

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

a,b,c,k = myinput()

if k<=a:
    ans = k
elif k>a and k<=(a+b):
    ans = a
elif k>(a+b) and k<=(a+b+c):
    m = k - (a+b)
    ans = a - m
else:
    ans = 0
print(ans)

Solution (Python):
a = list(map(int , input().split()))
ans = 0
if a[0] >= a[3]:
  ans = a[3]
if a[0] + a[1] <= a[3]:
  ans = a[0] + a[1]*0 + (a[3] - (a[0] + a[1]))*(-1)
print(ans)

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

if K - A <= 0:
  ans = K
elif K - A > 0:
  ans += A
  if K - 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:
    hiku = k - a - b
    print(a - hiku)

Solution (Python):
import sys
import os

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

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

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

    print(sum)

if __name__ == '__main__':
    main()

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







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






print(ans)

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

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

if a>=k:
  print(k)
elif a<k and 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 = A
    K=K-A
else:
    ans = K
    print(ans)
    exit()
if B <=K:
    K=K-B
else:
    print(ans)
    exit()
ans = ans - K
print(ans)

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

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

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

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

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

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

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

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

print(A + tmp)

Solution (Python):
import sys

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

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

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

max_num()

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

Solution (Python):
A, B, C, K = [int(n) for n in 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(k)
elif a < k <= a+b:
    print(a)
else:  
    print(a -(k-(a+b)))

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

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())
ans = 0

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

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

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

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]

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

print(ans)

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

if A > K:
    a = K
    b = 0
    c = 0
else:
    a = A
    if B > K - A:
        b = K - A
        c = 0
    else:
        b = B
        c = K - A - B

print(a - c)

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

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

print(ans)

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

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

    


resolve()

Solution (Python):
def main():
    a, b, c, k = [int(i) for i in input().split(" ", 4)]
    if k <= a:
        print(k)
        return
    elif k <= a+b:
        print(a)
        return
    else:
        k -= a + b
        print(a - k)


main()

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

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

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

ans = 0

if(K<=A):
    ans = K

if(K>A and K<=A+B):
    ans = A

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

Solution (Python):
x=input().split(" ")
a=int(x[0])
b=int(x[1])
c=int(x[2])
number=int(x[3])
if number<=a:
    print(number)
elif number<=a+b:
    print(a)
else:
    print(2*a+b-number)

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

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

Solution (Python):

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

if __name__ == "__main__":
    main()

Solution (Python):
if __name__=="__main__":
    a,b,c,k = map(int, input().split())
    picks = 0

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

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

Solution (Python):


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

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

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

X = K - A
Y = K - A - B
Z = 0

if X >= 0:
    Z += A
    if Y > 0:
        Z -= Y
else:
    Z += K

print(Z)

Solution (Python):
n_plus, n_zero, n_minus, n_cards = map(int, input().split())

if n_cards <= n_plus:
  print(min(n_plus, n_cards))
elif n_cards <= (n_plus + n_zero):
  print(n_plus)
else:
  print(n_plus - (n_cards - n_plus - n_zero))

Solution (Python):
import sys
import math
from collections import Counter
import itertools
import fractions



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")



a,b,c,k=MI()
ans=0

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

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

print(ans-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:
    print(k)
elif k<=a+b:
    print(a)
else:
    print(2*a+b-k)

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

NC = K - (A + B)

if NC >= 0:
    print(f"{A - NC}")
else:
    print(f"{min(A, K)}")

Solution (Python):


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


result = int()
if K <= A:
    result = K
elif A < K and K <= A + B:
    result = A
elif A + B < K and K <= A + B + C:
    result = 2*A + B - K


print(result)

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

ans=0

if a >= k:
    ans += k

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

print(ans)

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

sum = 0
end = False
if a < k:
    sum+=a
    k-=a
else:
    sum=k
    end=True

if end==False and b < k:
    k-=b
else:
    end=True

if end==False:
    sum-=k

print(sum)

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

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

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

ans += -1*k
print(ans)

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

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

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

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

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

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

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

print(ans)

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

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

Solution (Python):

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

result = 0

if 0 < k <= a:
    result += k
    k = 0
else:
    result += a
    k -= a

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

result -= k
k = 0

print(result)

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

a,b,c,k = MI()

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:
    r = k
elif a+b >= k:
    r = a
elif a+b+c >= k:
    r = a - (k-a-b)

print(r)

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

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

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

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

ans -= K-(A+B)
print(ans)

Solution (Python):
a, b, c, k = map(int, input().split())
s = 0
for i in [[a, 1], [b, 0], [c, -1]]:
    if k <= 0:
        break
    v = (i[0] if i[0] <= k else k)
    s += i[1] * v
    k -= v
print(s)

Solution (Python):

import sys

(A, B, C, K) = (int(i) for i in input().split())

ans = 0
left = K


ans = min(A, left)

left -= A

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


left -= B

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


ans -= min(C, left)

print(ans)

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

if k <= a+b:
    ans = min(a,k)
else:
    ans = 2*a+b-k
print(ans)

Solution (Python):





data = input().split()

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



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

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

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

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

print(sum - k)

Solution (Python):
from math import *
from collections import *
from itertools import *
from bisect import *
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')
MOD = 1000000007
MAX=2147483647
MIN=-2147483648
p=input

a,b,c,d=io()
s=0
s+=min(a,d)
d-=min(d,a)
d-=min(d,b)
s-=min(d,c)
print(s)

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

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

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

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

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

Solution (Python):
A,B,C,K=map(int,input().split())
if A>=K:
  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())

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

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

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

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

n = 0

if K >= A:
    n += A
    K -= A
    if K >= B:
        n -= (K-B)

else:
    n = K

print(n)

Solution (Python):
def main(A, B, C, K):
    if K - A <= 0:
        print(K)
    elif K - A > 0 and K - A - B <= 0:
        print(A)
    else:
        print(A - (K - A - B))

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

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

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

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

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

point = 0

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


print(point)

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

a = K - A
b = a - B
c = 0
if b > 0:
    c = K - b

if a < 0:
    print(K)
elif b > 0:
    print(A - b)
else:
    print(A)

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

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

print(ans - k)

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

if K >= A:
  K -= A
  point += A
  
  if K >= B:
    K -= B
    point -= K
    

else:
  point += K
  
print(point)

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

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