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

Solution (Python):
a=input()
b=a.split()

x1=int(b[0]) 
x2=int(b[1]) 
x3=int(b[2]) 
x4=int(b[3]) 

if x4 <= x1:
	print(x4)

elif x4 <= x1+x2:
	print(x1)

else:
	print(x1-(x4-x1-x2))

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

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

if 0 <= A and 0 <= B and 0 <= C:
    if 1 <= K and K <= A + B + C <= 2 * (10 ** 9):
        if min(A, K) == A:
            result = A
            K -= A
        else:
            result = K
            K = 0
        if K > 0:
            K -= B
        if K > 0:
            result -= K

print(result)

Solution (Python):







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

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

Solution (Python):
if __name__ == '__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))

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


if __name__ == "__main__":
    main()

Solution (Python):
import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


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


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


def nu():
    return int(input())


def find_gcd(x, y):
    while (y):
        x, y = y, x % y
    return x


def lcm(x, y):
    gg = find_gcd(x, y)
    return (x * y // gg)


mm = 1000000007

def solve():
    t = 1
    for tt in range(t):
        a,b,c,d=num()
        if(a+b>=d):
            print(min(a,d))
        else:
            z=d-a-b
            print(a-z)

                 


if __name__ == "__main__":
    solve()

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

ans = min(a, k)
k -= a
k -= b
ans -= k if k > 0 else 0

print(ans)

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

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

print(ans)

Solution (Python):
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def int_input():
    return int(input())


def print_ans(string):
    print(string)
    exit()

def yes():
    print("Yes")
    exit()

def no():
    print("No")
    exit()

A,B,C,K=input_int_list()

if K<=A:
    print_ans(K)
else:
    if K<=A+B:
        print_ans(A)
    else:
        print_ans(2*A-K+B)

Solution (Python):
import sys
import math
import bisect

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

if __name__ == "__main__":
    main()

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

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

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

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

print(ans)

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

xa = min(K,A)
K -= xa
xb = min(K,B)
K -= xb


ans = xa - K
print(ans)

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


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

rest = K

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

xa = min(A,K)
K -= xa
xb = min(B,K)
K -= xb
xc = min(C,K)

print(xa-xc)

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

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

Solution (Python):




num_line = input().split()


num_one = int(num_line[0])
num_zero = int(num_line[1])
num_mini = int(num_line[2])
num_amount = int(num_line[3])


if num_one >= num_amount:
    print(num_amount)
elif num_one + num_zero >= num_amount:
    print(num_one)
else:
    
    minus_count = num_amount - (num_one + num_zero)
    print(num_one - minus_count)

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

Solution (Python):
a,b,c,k = map(int,input().split())
sum1 = 0
while(k>0):
    if(k>=a and a!=0):
        k = k-a
        sum1+=a
        a=0
    elif(k<a):
        a = a - k
        sum1 += k
        k = k-k
    
    elif(k>=b and b!=0):
        k = k-b
        b=0
    elif(k<b):
        b = b - k
        k = k-k
    
    elif(k>=c and c!=0):
        k = k-c
        sum1 = sum1 - c
        c=0
    elif(k<c):
        c  = c-k
        sum1 = sum1 - k
        k = k-k

print(sum1)

Solution (Python):
a,b,c,k = map(int,input().split())
sum1 = 0
while(k>0):
    if(k>=a and a!=0):
        k = k-a
        sum1+=a
        a=0
    elif(k<a):
        a = a - k
        sum1 += k
        k = k-k
    
    elif(k>=b and b!=0):
        k = k-b
        b=0
    elif(k<b):
        b = b - k
        k = k-k
    
    elif(k>=c and c!=0):
        k = k-c
        sum1 = sum1 - c
        c=0
    elif(k<c):
        c  = c-k
        sum1 = sum1 - k
        k = k-k

print(sum1)

Solution (Python):
a,b,c,k = map(int,input().split())
xa = min(a,k)
k -= xa
xb = min(b, k)
k -= xb
xc = k
print(xa-xc)

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

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 = list(map(int,input().split()))
one = a[0]
zero = a[1]
mone = a[2]
num = a[3]
 
ans = 0
if one >= num:
    print(num)
else:
    ans += one
    num -= one
    if zero >= num:
        print(ans)
    else:
        num -= zero
        print(one - num)

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

    a_k_min = min(a, k)
    total += a_k_min
    k -= a_k_min

    if k == 0:
        return total

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

    if k == 0:
        return total

    c_k_min = min(c, k)
    return total - c_k_min


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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

x = 0
n = min(A,K)
K -= n
x += n
n = min(B,K)
K -= n
x -= K

print(x)

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

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

if (a>=k):
  s=k
else:
  if ((a+b)>=k):
    s=a
  else:
    s=a-(k-a-b)
  
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 = [int(x) for x 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 a >= k:
    print(k)
    exit()
if b >= k-a:
    print(a)
    exit()
if c >= k-a-b:
    print(a-(k-a-b))
    exit()

print(a-c)

Solution (Python):
a = input().split()

pura = int(a[0])     
zero = int(a[1])     
mai  = int(a[2])     
num  = int(a[3])     
total = 0
k = num-pura-zero

if pura >= num:
    total = num
else:
    total = pura
    if zero >= num - pura:
        total = pura
    else:
        total = pura-(k)
print(total)

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    if K <= A+B:
        print(min(A,K))
    else:
        print(A - (K - (A+B)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    K = int(next(tokens))  
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

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

if a >= k:
    print(k)
    exit()

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

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

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

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

if S[0] + S[1] + S[2] > 2 * 10 ** 9:
    print('Error')
elif S[0] >= S[3]:
    print(S[3])
elif S[3] > S[0] and S[3] <= S[0] + S[1]:
    print(S[0])
elif S[3] > S[0] + S[1] and S[3] <= S[0] + S[1] + S[2]:
    print(-1 * (S[3] - S[0] - S[1]) + S[0])
else:
    print('Error')

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

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

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

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



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

print(s)

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

if k <= a:
    print( k )

elif k > a:
    if b == 0:
        nc = k - a
        print( a - nc )
    elif b != 0:
        nb = k - a
        if nb <= b:
            print( a )
        elif nb > b:
            nc = nb - b
            print( a - nc )

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):
X = input().split()
A = int(X[0])
B = int(X[1])
C = int(X[2])
K = int(X[3])

d = 0

if K < A:
	d = K

elif K <= A + B:
	d = A

else:
	K = K - A - B
	d = A - K

print(d)

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

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

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

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

Solution (Python):
a,b,c,k = map(int,input().split())
xa = min(a,k)
k-=xa
xb=min(b,k)
k-=xb
xc=k
print(xa-xc)

Solution (Python):
p,z,n,k = map(int,input().split())
print(min(k,p) if k<=(p+z) else p-(k - (p+z)))

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


if __name__ == '__main__':
    solve()

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())
print(min(K,A) - max(0,K-A-B))

Solution (Python):
from math import sqrt

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

Solution (Python):
def main():
    a, b, c, k = (int(i) for i in input().split())
    xa = min(a, k)
    k -= xa
    xb = min(b, k)
    k -= xb
    xc = k
    ans = xa - xc
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
paramA, paramB, paramC, paramK = list(map(lambda x: int(x), input().split(' ')))

result = min(paramA, paramK)
paramK -= paramA
paramK -= paramB
if paramK > 0:
    result -= min(paramC, paramK)

print(result)

Solution (Python):
one, zero, dif_one,num = map(int,input().split())
if num <= one:
  print(num)
elif num <= one + zero:
  print(one)
else:
  print(one-(num-one-zero))

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

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

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

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


if __name__ == '__main__':
    main()

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

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

A = tmp[0]
B = tmp[1]
C = tmp[2]
K = tmp[3]

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

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

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  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 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())
sum=0
f=True
if(k>a):
    sum+=a
    k-=a
else:
    sum=k
    f=False
if (f):    
    k=k-b
    if(k<0):
        f=False
    if (f):
        sum-=(min(k,c))
print(sum)

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

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

aa = min(a,k)
bb = min(b,k - aa)
cc = min(c,k - aa - bb)

print(aa - cc)

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

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

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

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

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

print(min(A,K)-max(0,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+b-k)

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


if K-A <=0:
  ans = K

elif K-A-B<=0:
  ans = A

elif K-A-B-C<=0:
  ans = A-(K-A-B)
  
print(ans)

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

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

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

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

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

if K >= A:
	sum = A
	K = K - A
else:
	sum = K
	K = 0
if K >= B and K >= 1:
	K = K - B
else:
	K = 0
if K >= C and K >= 1:
	sum = sum - C
else:
	sum = sum - K

print(sum)

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

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

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

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


xa = min(k,a)
xb = min(k-xa,b)
xc = k- xa - xb

print(xa - xc)

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

a = min(A, K)
K -= a
b = min(B, K)
K -= b
c = K

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, k = map(int, read().split())
print(min(a, k) if a + b >= k else 2 * a + b - k)

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

    if count > 0:
        if count < card[2]:
            answer = answer + (count * -1)
            print(answer)
        else:
            answer = answer + (card[2] * -1)
            print(answer)
    else:
        print(answer)

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(K, A - max(0, K - A - B)))

Solution (Python):
A,B,C,K = map(float,input().split())
 
a = min(A, K)
if K-A>=0:
    b = min(abs(K-A), B)
else:
    b = 0
    c = 0

if K-A-B>=0:
    c = min(abs(K-A-B), C)
else:
    c = 0

ans = 1*a + 0*b - 1*c

print(int(ans))

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

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

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(x) for x in input().split())

count = 0

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

print(count)

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

xa = min(a,k)
k1 = k-xa
xb = min(b,k1)
k2 = k1-xb
xc = k2

print(xa-xc)

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

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

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

ans += min(b, k) * 0
k -= min(b, k)

ans += min(c, k) * -1
k -= min(c, k)

print(ans)

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



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

Solution (Python):
def actual(a, b, c, k):
    x_a = min(a, k)

    k -= x_a

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

    x_c = k  

    score = x_a - x_c

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

print(actual(A, B, C, K))

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

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

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

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

xa = min(a,k)
k -= xa
xb = min(b, k)
k -= xb
xc = k
print(xa-xc)

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

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

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

S = int()

if K >= A:
    S = S + A
    K = K - A

    if K >= B:
        K = K - B

        if K > 0:
            S = S - K
            print(S)
        else:
            print(S)

    else:
        print(S)

else:
    S = S + K
    print(S)

Solution (Python):

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

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

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

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

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

xa = min(A, K)
K -= xa
xb = min(B, K)
K -= xb
xc = min(C, K)
ans = xa-xc
print(ans)

Solution (Python):
a, b, c, k = map(int, input().split())
ans = 0
for i, x in enumerate([a, b, c]):
    t = min(k, x)
    ans += (1 - i) * t
    k -= t

print(ans)

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

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

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

    ans = 0

    
    if A >= 1:
        if K >= A:
            ans = A
        else:
            ans = K

    
    tmp = K - A - B
    if tmp >= 1:
        ans -= tmp

    print(f'{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(A-(K-A-B))

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

print(ans)

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

d = k - a

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

elif A + B < K:
    c = -1 * (K-(A+B))
    
    
    cc = A + c
    print(cc)

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

Solution (Python):
import sys
import math

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

s=K
ans = 0

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

if (s>0):
    s-=B
    if (s>0):
       ans -= s

print(ans)

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

Solution (Python):
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
if A>=K:
    print(K)
    exit()
if A+B>=K:
    print(A)
    exit()
K=K-(A+B)
print(A+(K*-1))
exit()

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

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

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

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

Solution (Python):

i = input()
a = int(i.split()[0])
b = int(i.split()[1])
c = int(i.split()[2])
k = int(i.split()[3])

count = 0

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

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]
 
sys.setrecursionlimit(1000000)
mod = 1000000007
 
def solve():
    a,b,c,k = map(int,input().split())
    ans = 0
    if a+b >= k:
        print(min(k,a))
    else: 
        print(a-(k-a-b))
    return
 

if __name__ == "__main__":
    solve()

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

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

Solution (Python):

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

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

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

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

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

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

if a >= k:
    print(1*k)
else:
    n = k-a

    if n <= b:
        print(1*a)
    else:
        o = n-b
        print(a-o)

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

count = 0

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

print(count)

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

Solution (Python):
X, Y, Z, K = map(int, input().split())
if X >= K:
    print(K)
elif X+Y >= K:
    print(X)
elif X+Y+Z >= K:
    print(X-(K-X-Y))

Solution (Python):

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

if __name__ == '__main__':
    main()

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

ans = 0

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

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

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

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

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

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

card = K

result = 0

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

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