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

else:
    print(K)

Solution (Python):

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

count = 0

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

print(count)

Solution (Python):
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce



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

num = 0

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

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

if b >= k:
    print(ans)
    quit()
else:
    k-=b
    ans += (-1*k)
    print(ans)

Solution (Python):
def main():
    A,B,C,K = list(map(int, input().split(' ')))
    
    out = 0
    if A > K:
        out = K
        return out
    else:
        nokori = K-A
        if nokori <= B:
            out = A
            return out
        elif nokori > B:
            nokonkori = K - A - B
            out = A - nokonkori
            return out
            
            
            
            
out = main()
print(out)

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

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

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

Solution (Python):
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


def input1():
	return int(input())


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


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

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets


def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	
	return fact(x+y)/fact(x)/fact(y)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp
		


a,b,c,k=input2()


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

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

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
if K >= A:
  ans += A
  K -= A
else:
  ans += K
  K = 0

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

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

print(ans)

Solution (Python):



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


ans = 0

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


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


ans -= 1 * nokori


print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
  main()

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



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

    ans = 0

    if A >= K:
        ans += K
        return ans
    else:
        ans += A
        K -= A

    if B >= K:
        return ans
    else:
        K -= B

    return ans-K


if __name__ == "__main__":
    print(main())

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

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

Solution (Python):
A, B, C, K = list(map(int, input().split()))
ret = 0
rK = A - K
if rK >= 0:
    ret += K        
else:
    ret += A
    if B - abs(rK) < 0:
        ret += B - abs(rK)
print(ret)

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

if K <= A:
    score = K
else:
    score = A
    K -= A
    if K <= B:
        score += 0
    else:
        score += 0
        K -= B
        score -= K

print(score)

Solution (Python):
















	
	
def fun(a,b,c,k):
	ans =0 
	if k<=a:
		return k
	else:
		ans = a
		k-=a
	if k<=b:
		return ans
	else:
		k-=b
	
	
	return ans-min(c,k)
a,b,c,k = [int(j) for j in input().split()]


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

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

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


if __name__ == "__main__":
    main()

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

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

t= 0

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

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

if k < c:
    t += k*-1
    k = 0
else:
    t += c*-1

print(t)

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

import sys

ans = 0

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

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

if k ==  c:
    ans += ((-1)*c)
else:
    ans += ((-1)*k)

print(ans)

Solution (Python):



from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

A, B, C, K= [int(_) for _ in input().split()]

ct = 0
k = K - A
if k >= 0:
    ct += A
else:
    ct += K

k = k - B
if k > 0:
    ct -= k
print(ct)

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

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

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

Solution (Python):
import sys

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

if a<=k:
  sum+=a
  k-=a
  
else:
  sum+=k
  print(sum)
  sys.exit()

k-=b

if k>0:
  sum+=-1*k
  
print(sum)

Solution (Python):









import os
import sys


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

if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):
A,B,C,K = [int(i) for i in 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())
sum=0
while k>0:
    if a>0:
        if k>=a:
            sum+=a
            k=k-a
            a=0
        else:
            sum+=k
            k=0

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

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

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

sum = 0
if k > a:
    sum += a
    k -= a
    if k > b:
        k -= b
        if k > c:
            sum -= c
        else:
            sum -= k      
else:
    sum += k

print(sum)

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

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

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


def solve(a, b, c, k):
    ca, cb, cc = 0, 0, 0
    ca = min(a, k)
    k -= ca
    cb = min(b, k)
    k -= cb
    cc = min(c, k)
    k -= cc
    ans = ca * 1 + cb * 0 + cc * (-1)
    return 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)
else:
    print(2*A+B-K)

Solution (Python):


import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	a, b, c, k = map(int, sys.stdin.readline().split())
	ans = 0
	if k <= a:
		print(k)
	elif k <= a + b:
		print(a)
	elif k <= a + b + c:
		print(a+(k-a-b)*-1)


main()

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

Solution (Python):
from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
a,b,c,k=map(int,input().split())
su=min(a,k)
k-=min(a,k)
k-=min(b,k)
su-=min(c,k)
print(su)

Solution (Python):
def main():
    A,B,C,K = [int(x) for x in input().split()]
    v = 0
    if A<K:
        K -= A
        v += A*1
    else:
        v += K*1
        print(v)
        return
    if B<K:
        K -= B
        v += B*0
    else:
        v += K*0
        print(v)
        return
    if C<K:
        K -= C
        v += C*(-1)
    else:
        v += K*(-1)
        print(v)

if __name__ == '__main__':
    main()

Solution (Python):
A,B,C,D = map(int,input().split())
AD = D - A
BD = D - A - B
CD = D - A -B - C 
if AD <= 0:
    print(min(A,D))
elif BD <= 0:
    print(A)
else:
    print(A-BD)

Solution (Python):
import sys

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

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




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

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


if __name__ == '__main__':
    main()

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

total = 0
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 K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    C_tmp = K - (A + B)
    print(A - C_tmp)

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):
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):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res

from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left


def main():
    a, b, c, k = MII()
    if k <= a:
        print(k)
    elif k <= a+b:
        print(a)
    elif k <= a+b+c:
        print(a-(k-(a+b)))

if __name__ == '__main__':
    main()

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

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


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

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

if k < a:
    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())

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

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

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

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

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

print(ans)

Solution (Python):
















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

num = K
ans = 0
if num - A <= 0:
    print(K)
    exit()
elif num - A - B <= 0:
    print(A)
    exit()
elif num - A -B -C <=0:
    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):
import sys;input=lambda:sys.stdin.readline().rstrip();ints=lambda:list(map(int,input().split()))
 
def main():
    a,b,c,k = ints()
    if k<=a:
        print(k)
    elif k<=a+b:
        print(a)
    elif k<=a+b+c:
        print(2*a+b-k)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


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

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

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

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

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

if(card_left >= 0):card_left -= b
if(card_left >= 0):ans -= card_left

print(ans)

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

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

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy





sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))




def main():
    a, b, c, k = ns()
    t1 = max(k - a - b, 0)
    t2 = min(k, a)

    print(-t1 + t2)


if __name__ == '__main__':
    main()

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

max_num = 0

is_finish = False
if A>=K:
    print(K)
else:
    max_num += A
    K -= A
    is_finish = True

if is_finish:
    if B>=K:
        print(max_num)
    else:
        print(max_num-(K-B))

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

def mysum(A, B, C, K):
  if K <= A:
    return(K)
  
  if K <= A+B:
    return(A)
  
  return(A + -1 * (K-A-B))
 
print(mysum(A, B, C, K))

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

Solution (Python):
def m():
    a, b, c, k = map(int, input().split())
    ans = 0
    if (k - a) <= 0:
        return k
    k = k - a
    ans = a
    if (k - b) <= 0:
        return ans
    k = k -b
    return ans - k


print(m())

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

ans = 0

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

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

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    A, B, C, K = LI()

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

if __name__ == '__main__':
    resolve()

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


ans=0

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

ans += a
k -= a

k -= b

ans -= min(c,max(0,k))

print(ans)

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

k2 = k-a
k3 = k2-b

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())
ans=0
if a < k:
    ans += 1 * a
    k -= a
    if b < k:
        k -= b
        if c < k:
            ans += -1 * (c - k)
        else:
            ans += -1 * k
else:
    ans+=1*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().strip().split())


def solve():
    global k

    total = 0
    num_a = min(k, a)

    total += num_a

    k -= num_a

    if k <= 0:
        return total

    num_b = min(k, b)

    if k <= 0:
        return total

    k -= num_b

    num_c = k
    total -= num_c

    return total

print(solve())

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

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

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

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

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

    ans -= (d)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 

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

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

a=A+B

b=K-a

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

Solution (Python):
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()

def main():
    A, B, C, K = MI()
    l = [A, B, C]; s = 0; i = 0; j = [1, 0, -1]
    while K>0:
        if K>l[i]:
            s += l[i]*j[i]
            K -= l[i]
        else:
            s += K*j[i]
            break
        i += 1
    print(s)

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

Solution (Python):
n=input().split(' ')

for i in range(len(n)):
  n[i]=int(n[i])

k=n[3]
sum=0
if k > n[0]:
  sum+=n[0]
  k-=n[0]
else:
  sum=k
  k=0
k-=n[1]
if 0 < k:
  sum-=k
print(sum)

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

Solution (Python):
def main():

    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)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys

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

A, B, C, K = IL()
maxim = 0
if A >= K:
	maxim = K
else:
	maxim = A
	K = K - A
	if B >= K:
		pass
	else:
		K = K - B
		maxim = maxim - K

print(maxim)

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())
k-=a
sum=a
if k<=0:
    sum-=abs(k)
    print(sum)
else:
    k-=b
    if k<=0:
        print(sum)
    else:
        
        sum-=k
        print(sum)

Solution (Python):
l = list(map(int, input().split(' ')))
a = l[0]
b = l[1]
c = l[2]
d = l[3]
count=0
s=0
if a>0:
    if d>=a:
        s+=a
        d-=a
    else:
        s+=d
        d-=d
if d>0:
    d-=b
if d>0:
    if d>=c:
        s-=c
        d-=c
    else:
        s-=d
print(s)

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+=min(A,K)
K-=min(A,K)
K-=min(B,K)
ans-=min(K,C)

print(ans)

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

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))
else:
  print(A-C)

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




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

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

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

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

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

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

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

print(ans)

Solution (Python):



A,B,C,D = map(int, input().split())
result = 0
if D-A>0:
    result +=A
    b = D-A
    if b-B > 0:
        result -=(b-B)
        print(result)
    else:
        print(result)
else:
    print(D)