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())
ans, k = min(a, k), k-min(a, k)
k -= min(b, k)
ans -= min(c,k)
print(ans)

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

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

print(score)

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

if k <= a:
    print(1 * k)
elif k <= a + b:
    print(1 * 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):
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
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

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

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

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

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

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

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

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())
def max():
  a_0=1
  b_0=-1

  if a>=k:
    print(a_0 * k)
    return
  
  else :
    if k-a<b:
      return

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

max()

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

Solution (Python):

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

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

out = min(A,K) - max(0,K-A-B)
print(out)

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

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

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

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

print(p)

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

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

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

print(ans-K)

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

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

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

ans = 0

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

print(ans)

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

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

Solution (Python):
import sys
def main():
    a,b,c,k=tuple(map(int,sys.stdin.readline().split()))
    print(k) if k<=a else print(a) if k<=a+b else print(2*a+b-k)
if __name__=='__main__':main()

Solution (Python):
import sys
def main():
    a,b,c,k=tuple(map(int,sys.stdin.readline().split()))
    if k<=a:
        print(k)
    else:
        if k<=a+b:
            print(a)
        else:
            print(2*a+b-k)
if __name__=='__main__':main()

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

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

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


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

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

print(s)

Solution (Python):
import sys
readline = sys.stdin.readline
A, B, C, K = map(int,readline().split())
count = 0

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

while(K>0):
	if A != 0:
		count += A
		K -= A
		A = 0
	elif B != 0:
		K -= B
		B = 0
	else:
		count -= K
		K = 0
			
print(count)

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

total = 0

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

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

out = min(a,k) - max(0,k-a-b)
print(out)

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

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

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

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

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


ans -= K

print(ans)

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

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


if __name__ == '__main__':
    solve()

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

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

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

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

li = list(map(int,input().split())) 

counter_1=li[0]
counter_0=li[1]
counter_m1=li[2]
counter_choice=li[3]

if counter_choice > counter_1:
    sumpoint=1*counter_1
    counter_choice = counter_choice - counter_1
else:
    sumpoint=1*counter_choice
    print(sumpoint)
    counter_choice=-999

if counter_choice != -999:
    if counter_choice > counter_0:
        sumpoint = sumpoint + 0*counter_0
        counter_choice = counter_choice - counter_0
    else:
        sumpoint = sumpoint + 0*counter_choice
        print(sumpoint)
        counter_choice=-999

if counter_choice != -999:
    if counter_choice > counter_m1:
        sumpoint = sumpoint + (-1)*counter_m1
        counter_choice = counter_choice - counter_m1
    else:
        sumpoint = sumpoint + (-1)*counter_choice
        print(sumpoint)
        counter_choice=-999

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

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

Solution (Python):
[a, b, c, k] = [int(t) for t in open(0).read().split()]
array = [(a, 1), (b, 0), (c, -1)]
ans = 0
while k > 0 and array:
    tmp = array.pop(0)
    ans += tmp[1] * min(tmp[0], k)
    k -= min(tmp[0], k)
print(ans)

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

if k > 0:
    if a > k:
        ret = k
    else:
        ret = a
    k = k - a

k = k - b

if k > 0:
    if c > k:
        ret = ret - k
    else:
        ret = ret - c

print("{}".format(ret))

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

Solution (Python):
[A,B,C,K] = [int(s) for s in input().rstrip().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 = map(int, input().split())

ans = 0

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

if k > 0:
    k -= b

if k > 0:
    ans -= min(c, 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+b-k)

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

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

  
  

  
  
  
  if 'get_ipython' in globals(): 
    
    a, b, c, k = 2, 1, 1, 3

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

main()

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

ans = min(A,K)
K -= A

K -= B

ans -= max(min(C,K),0)

print(ans)

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

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

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


def actual(a, b, c, k):
    if a >= k:
        return k
    else:
        k -= a

    if b >= k:
        return a
    else:
        k -= b

    return a - k


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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline

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

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

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

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

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

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

print(score)

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:
    k -= b
    ans -= k
print(ans)

Solution (Python):

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

if __name__ == "__main__":
    main()

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

Solution (Python):
def solve():
    a,b,c,k=map(int,input().split())
    sum=0
    if(a>=k):
        sum+=k*1
        return sum
    else:
        sum+=a*1
        k-=a
    if(b>=k):
        sum+=k*0
        return sum
    else:
        sum+=b*0
        k-=b
    sum+=k*(-1)
    return sum

def main():
    print(solve())

main()

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

total_card = 0
sum = 0
if a <= k:
    total_card = a
    sum = a
else:
    total_card = k
    sum = k
    print(sum)
    exit()

if b <= k - total_card:
    total_card += b
else:
    print(sum)
    exit()

sum += -1 * (k - total_card )
print(sum)

Solution (Python):
A, B, C, K = map(int,input().split())
step1 = K-A
step2 = step1 - B
step3 = step2 - C
if step1 <= 0:
    print(K)
elif step2 <= 0:
    print(A)
else:
    print(A-step2)

Solution (Python):


"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()



def solve():
    a,b,c,d = invr()
    ONLINE_JUDGE_SOLUTION = Codeforces.Solutions(a,b,c,d,"1361","A","GET","POST")
    print(ONLINE_JUDGE_SOLUTION)
                


 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
    sys.stdout.close()
    

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 

def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

class Codeforces():
    def Solutions(a,b,c,d,id,question,get,post):
        q = min(a,d)
        w = min(b,d - q)
        qw = min(d - q - w,c)
        return(q - qw)
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

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

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

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

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

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

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
a,b,c,k=map(int,input().split())
if k<=a+b:
  print(min(k,a))
else:
  print(a-(k-a-b))

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

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

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

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

Solution (Python):
import sys


def main():
    read = lambda: sys.stdin.readline().rstrip()
    
    
    A, B, C, K = map(int,read().split())
    print(K if A >= K else A if K-A <= B else A-(K-A-B))
    
    
    

 
if __name__ == "__main__":
    main()

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

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

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

flag_A=False
flag_B=False
flag_C=False

if K<=A:
  flag_A=True
elif A<K and K<=A+B:
  flag_B=True
elif A+B<K and K<=A+B+C:
  flag_C=True
  
if flag_A==True:
  print(K)
elif flag_B==True:
  print(A)
elif flag_C==True:
  print(A-(K-A-B))

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

Solution (Python):
def main():
    [A, B, C, K] = map(int, input().split())
    output = 0
    if A > K:
        return K
    else:
        K -= A

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

    return A - K


print(main())

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

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

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

if a>k:
    print(k)
    exit()
elif a+b>=k:
    print(a)
else:
    print(a-max(0,(k-a-b)))

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

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

result = 0

t = min(A, K)

result += t

K -= t
t = min(B, K)

K -= t
t = min(C, K)

result -= t
print(result)

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 - K + 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())
ret = min(a, k)
ret -= min(c,max(k-a-b,0))
print(ret)

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

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

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

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

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

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

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

Solution (Python):
line = input().split()
num = int(line[3])
a = int(line[0])
b = int(line[1])
c = int(line[2])

if a < num:
  maxi = a
elif a >= num:
  maxi = num

if a + b < num:
  maxi = a -  (num - (a + b))
  
print(maxi)

Solution (Python):
def main():
    a, b, c, k = map(int, input().split())
    res = 0
    if k-a >= 0:
        res += a
    else:
        res += k
    
    
    if k-a-b > 0:
        res += (k-a-b)*-1
    print(res)
                
if __name__ == '__main__':
    main()

Solution (Python):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy

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

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

if __name__ == "__main__":
    main()

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

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

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

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

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

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

Solution (Python):
import sys
a,b,c,k = (int(x) for x in input().split())
if k<=a:
    print(k)
    sys.exit()
elif k<=(a+b):
    print(a)
    sys.exit()
elif k>a+b:
    print(a-(k-a-b))

Solution (Python):
import sys


def estimate(A, B, C, K):
    N_A = A
    if(N_A >=K):
        N_A = K
        N_B = 0
        N_C = 0
        return N_A
    N_B = B
    if(N_A+N_B >= K):
        return N_A
    N_C = K- (N_A+N_B)
    return N_A-N_C



if(__name__ == "__main__"):
    ABCK = input().split()

    A= int(ABCK[0].strip())
    B= int(ABCK[1].strip())
    C= int(ABCK[2].strip())
    K= int(ABCK[3].strip())

    
    value = estimate(A, B, C, K)
    print(value)

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

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

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

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

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

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

def max_point(A,B,C,K):
    if K <= A:
        return K
    elif K-A <= B:
        return A
    else:
        return A-(K-A-B)
print(max_point(A,B,C,K))

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

print(min(k, a)-max(k-a-b, 0))

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

Solution (Python):

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

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

Max = -100000000000000

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

print(Max)

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

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

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

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


A_C = min(A,K)
K -= A_C
B_C = min(B,K)
K -= B_C
C_C = min(C,K)

print(A_C-C_C)

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

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

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

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


s = max(min(a, k), 0)
k -= a


k -= b


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

print(s)

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

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

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

Solution (Python):
def calc(K,d,p):
    sum = 0
    if(K > d):
        sum = p * d
    else:
        sum = p * K
    
    return sum,d


def resolve():
    data = [int(i) for i in input().split()]
    sum = 0
    K = data[3]
    for i in range(3):
        add,count= calc(K,data[i],1 - i)
        sum += add
        K -= count
        if(K <= 0):
            break    
    print(sum)
resolve()

Solution (Python):
a, b, c, k = map(int, input().split())
print(min(k, a) - max(0,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())
print(min(A, K) + min(0, (A + B) - K ))

Solution (Python):
def main():

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


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

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

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

Solution (Python):
line_1= input().split(' ')
a= int(line_1[0])
b= int(line_1[1])
c= int(line_1[2])
k= int(line_1[3])

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

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

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

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

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

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

def picknum(res, num_abc):
    if res < num_abc:
        return res
    else:
        return num_abc

nums = []
res = abck.pop()
for el in abck:
    if res > 0:
        num = picknum(res, el)
    else:
        num = 0
    nums.append(num)
    res = res - num

total = nums[0] - nums[2]
print(total)

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