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

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

if k <=a:
  counter =+ k
else:
  counter+= a
  remants -= a
  if remants >b:
    remants -= b
    counter-=remants






print(counter)

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

cnt = 0

if k >= a:
    k = k - a 
    cnt = cnt + 1*a  

    if k >= b:
        k = k - b 

        if k >= c:
            cnt = cnt + -1*c
            k = k - c

        else:
            cnt = cnt + -1*k
            k = k - k
    
    else:
        k = k - k

else:
    cnt = cnt + 1*k
    k = k - k
    
print(cnt)

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


def f(A, B, C, K) :
    
    sum = 0

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

    if K <= 0 :
       return sum

    if K - B >= 0 :
        K = K - B
        sum = sum + (0 * B)
    else :
        sum = sum + (0 * K)
        K = 0

    if K <= 0 :
       return sum

    if K - C >= 0 :
        K = K - C
        sum = sum + (-1 * C)
    else :
        sum = sum + (-1 * K)
        K = 0

    if K <= 0 :
       return sum


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

Solution (Python):




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

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

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

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

count = 0

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


print(count)

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

print(ans)

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

sum = 0

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

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

if i [0] >= i[3]:
	saidai=1*i[3]
else:
	saidai=1*i[0]-1*(i[3]-i[0]-i[1])
print (saidai)

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

sum = 0
a_3 = a[3]
a_0 = a[0]
a_1 = a[1]
a_2 = a[2]


if a_3 <= a_0:
    print (a_3)
    
elif a_3 > a_0 and a_3 <= (a_0 + a_1):
    print (a_0)
    
else:
    sum = a_0 - (a_3 - a_0 - a_1)
    print(sum)

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

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

a_times = 0
b_times = 0
c_times = 0

if a <= k:
    a_times = a
    
    if a_times + b <= k:
        b_times = b
        
    else:
        b_times = k - a_times
        
    if a_times + b_times + c <= k:
        c_times = c
        
    else:
        c_times = k - a_times - b_times
        
else:
    a_times = k


print(a_times * 1 + b_times * 0 + c_times * -1)

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

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

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

if A >= K:
  print(K)
  exit()
else:
  K -= A
  if B >= K:
    print(A)
    exit()
  else:
    K -= B
    if K <= C:
      A -= 1*K
    
print(A)

Solution (Python):
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)

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

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

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

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

Solution (Python):
import sys

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

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

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

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

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

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

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())
Ts = 0
sA = K - A
if sA > 0:
    sB = sA - B
    if sB > 0:
        sC = sB - C
        if sC < 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
        elif sC == 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
    elif sB == 0:
        Ts = ((K - sA) * 1) + (sB * 0)
    else:
        Ts = ((K - sA) * 1) + ((sA - sB) * 0)
elif sA == 0:
    Ts = A * 1
else:
    Ts = K * 1
print(Ts)

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

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

Solution (Python):
input = input().split(" ")
a, b, c = int(input[0]), int(input[1]), int(input[2])
k = int(input[3])
totalnum = 0
for nuum in range(4):
    if a>=k: 
        totalnum+=k
        k=0
        break
    elif a<k and a!=0: 
        totalnum+=a 
        k-=a 
        a=0
    elif b>=k: 
        k=0
        break
    elif b<k and b!=0: 
        k-=b 
        b=0
    elif c>=k: 
        totalnum-=k
        break
print(totalnum)

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

count=K
point=0

if A>count:
    point+=count
    count=0
else:
    point+=A
    count-=A

if B>count:
    point+=count*0
    count=0
else:
    point+=B*0
    count-=B

if C>count:
    point+=count*(-1)
    count=0
else:
    point+=C*(-1)
    count-=C

print(point)

Solution (Python):

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

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

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

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

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

Solution (Python):
[a, b, c, k] = map(int, input().split())
a_b = a + b
minus_count = k - a_b if k >= a_b else 0
print((a - minus_count) if a < k else 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:
    print(A - (K - A - B))

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

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

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

print(ANS)

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

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

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








one_counts = int(nums[0])
zero_counts = int(nums[1])
mone_counts = int(nums[2])
top = int(nums[3])


if one_counts >= top:
    print(top)
else:
    if one_counts + zero_counts >= top:
        print(one_counts)
    else:
        print(one_counts - (top - (one_counts + zero_counts)))

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

Solution (Python):
x = [int(x) for x in input().split()]
ans=0
if x[0] <= x[3]:
    ans = x[0]
else:
    ans = x[3]
x[3] -= x[0] + x[1]
if x[3] > 0:
    ans -= x[3]

print(ans)

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

Solution (Python):
A,B,C,K = (int(x) for x in input().split())
s = 0
d = (2*(10**10))
while True:
    if A <= K:
        s += (1*A)
        K = K - A
        A = d
    elif A != d and A > K:
        s = 1*K
        break
    elif A == d and B <= K:
        s = s
        K = K - B
        B = d
    elif A == d and  B != d and B > K:
        pass
        break
    elif A == d and B == d and C <= K:
        s -= (1*C)
        C = d
        break
    elif A == d and B == d and C != d and C > K:
        s -= (1*K)
        break
print(s)

Solution (Python):



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

    ans = a
    num = a + b

    if k <= a:
        print(int(k))
        return
    elif num < k:
        ans -= k - num
    print(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):
def solve():
    num_one, num_zero, num_minus_one, num_select = map(int, input().split())
    if num_one == num_select:
        print(num_one)
        return
    if num_select < num_one:
        print(num_select)
        return

    if num_one + num_zero == num_select:
        print(num_one)
        return
    if num_select < num_one + num_zero:
        print(num_one)
        return

    if num_one + num_zero + num_minus_one < num_select:
        print(num_one - num_minus_one)
        return

    max_minus_one = num_select - (num_one + num_zero)
    if num_minus_one < max_minus_one:
        print(num_one - num_minus_one)
    else:
        print(num_one - max_minus_one)

solve()

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

Solution (Python):
def solve(a, b, c, k):
	sum = 0
	if a > 0:
		if a >= k:
			sum += k 
			print(sum)
			return None
		else:
			sum += a
			k -= a
	k -= b
	if k > 0:
		if c > k:
			sum -= k
			print(sum)
			return None
		else:
			sum -= c
			print(sum)
	else:
		print(sum)



a, b, c, d = [int(x) for x in input().split()]
solve(a, b, c, d)

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

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

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

Solution (Python):
we = str(input())
r = we.split(" ", -1)

A = r[0]
B = r[1]
C = r[2]
K = r[3]
A = int(A)
B = int(B)
C = int(C)
K = int(K)

def max_sum(A, B, C, K):
	if ((A and B and C and K) >= 0) and (A + B + C >= K):   
		if A >= K:
			print(K)
		elif A < K:
			R = K - A
			if B >= R:
				print(A)
			elif B < R:
				S = R - B
				print(A + S*(-1))
max_sum(A, B, C, K)

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

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

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

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

print(s)

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

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

print(ans)

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

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

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

Solution (Python):


import sys

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

g = 0
gc = d

if d - a > 0 and a > 0:
    g += a
    d -= a
elif a > 0:
    g += d
    print(str(g))
    sys.exit()

if d - b > 0 and b > 0:
    d -= b
elif b > 0:
    print(str(g))
    sys.exit()

if d == c and c > 0:
    g -= d
elif c > 0:
    g -= d

print(str(g))

Solution (Python):

a, b, c, k = map(int, input().split())
 
A = a
B = 0
C = -1 * c
 
if k - a >= 0:
    if k -a -b >= 0:
        print(a + (-1)*(k -a -b) )
    else:
        print(a)
else:
    print(k)

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

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


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

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

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

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

    else:
        print(ans)
else:
    print(K)

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

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

ans = 0

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

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

kk=k-a
for i in range(1):
    if kk<0:
        ans=k
        k=-1
        break
    else:
        ans = a
        k=k-a
    kk = k-b
    if kk<0:
        k=-1
        break
    else:
        k=k-b

    kk = k-c

    if kk<0:
        ans=ans-k
    elif kk>=0:
        ans=ans-c
print(ans)

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

if a >= k:
  ak = k
  print(ak)
  exit()
else:
  ak = a
  
ck = (k-a-b)*-1

print(ak+ck)

Solution (Python):
N = input()
n =[int(x) for x in N.split()]
A = n[0]
B = n[1]
C = n[2]
K = n[3]
if A>=K:
    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:
    print(k)
else:
    if k - a <= b:
        print(a)
    else:
        sa = k - a - b
        ans = a - sa
        print(ans)

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

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

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

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

if a >= d:
    print(d*1)
elif a < d:
    if d-(a+b) <= 0:
        print(a)
    elif d-(a+b+c) <= 0:
        print(a + (d-a-b)*(-1))

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

Solution (Python):
s = input().split()
n = int(s[3])
sum_=0
if int(s[0]) >= n:
    sum_=1*n
elif int(s[0])+int(s[1]) >= n:
    sum_=1*(n-int(s[1]))
elif int(s[0])+int(s[1])+int(s[2]) >= n:
    sum_=1*int(s[0])+(-1*(n-int(s[0])-int(s[1])))

print(sum_)

Solution (Python):
def xyz(a,b,c,k):
    if k==a:
        return(k)
    if a>k:
        return(k)
    sum1=a
    if a+b>=k:
        return(a)
    d=k-a-b
    sum1=sum1-d
    return(sum1)
    
    


a,b,c,k=list(map(int,input().split()))
d=xyz(a,b,c,k)
print(d)

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

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

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

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

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

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

Solution (Python):
lis = list(map(int, input().split()))
k,mmm,all_=lis[3],[1,0,-1],0
sum_=[0]*3
for i in range(3):
  
  if lis[i]<k:
    sum_[i]+=lis[i]
    k-=lis[i]
  elif lis[i]>=k:
    sum_[i]+=k
    k=0


for j in range(3):
  all_+=mmm[j]*sum_[j]
print(all_)

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

Solution (Python):
A,B,C,K = list(map(int,input().split(" ")))
r=0
if A>0:
  r+=min(K,A)
  K-=A
if B>0 and K>0:
  K-=B
if C>0 and K>0:
  r-=K
print(r)

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

ans=0

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

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

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

sums = 0

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

if (k <= b):
    print(sums)
    sys.exit()
else:
    k -= b

sums += -1 * k
print(sums)

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

Solution (Python):
def solve(a, b, c, k):
    point = min(a, k)
    more = k - a
    if more > 0:
        more -= b
    if more > 0:
        point -= more

    print(point)

a, b, c, k = map(int, open(0).read().split())
solve(a, b, c, 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)
elif k > a+b and k <= a+b+c:
    print(a - (k - (a+b)))

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

ans = a
cnt = k-a
if cnt <=0:
    print(min(ans,k))
    exit()

cnt = cnt -b
if cnt <= 0:
    print(ans)
    exit()

ans = ans-cnt

print(ans)

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

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

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

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

a1 = a
nokori = 0
nokori_1 = 0
nokori_2 = 0
tensuu = 0

if k-a1 > 0:
   tensuu +=a1
   nokori = k-a

if nokori > 0:
   tensuu +=0
   nokori2 =nokori - b
   if nokori2 > 0:
        tensuu -= nokori2
if k - a1 <= 0:
    tensuu = k
print(tensuu)

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

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

if __name__ == '__main__':
    main()

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







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









print(sum)

Solution (Python):
body_1,body_2,body_3,cards=map(int,input().split())
total=0
sa=cards-body_1-body_2
if body_1>=cards:
    total=cards
elif body_1<cards:
    if (body_1+body_2)>=cards:
        total=body_1*1
    else:
        total=body_1-sa

print(total)

Solution (Python):
def check(num, k):
    if(num == k):
        return True
    else:
        return False


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

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

    print(ans)
 
main()

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

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

Solution (Python):
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if K-A <= 0:
    print(K)
elif K-A > 0:
    if K-A-B <= 0:
        print(A)
    else:
        print(int(A+(K-A-B)*-1))

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

ans = a
cnt = k-a
if cnt <=0:
    print(min(ans,k))
    exit()

cnt = cnt -b
if cnt <= 0:
    print(ans)
    exit()

ans = ans-cnt

print(ans)

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

def solve(a,b,c,k):
  if a >= k:
    return k
  elif a + b >= k:
    return a
  else:
    return a-(k-a-b)
    
print(solve(A,B,C,K))

Solution (Python):
X = list(map(int,input().split()))
A = X[0]
B = X[1]
C = X[2]
K = X[3]
score=[1,0,-1]
max_score = 0
nums = []

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

if(A>K):
  max_score += 1*K
  
print(max_score)

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

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


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

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

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

print(ans)

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

sum=0

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

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

if C>K:
    sum -= K
    K = 0
else:
    sum -= C
    K = K-C

print(sum)

Solution (Python):
a,b,c,k = map(int,input().split())
s = k
d = k - a
k -= a
e = k - b
k -= b
f = k - c
n = 0 
if d == 0:
  print(a)
elif s < a:
  print(s)
elif e == 0 or e < 0:
  print(a)
elif f == 0 :
  print(a - c)
else:
  print(a - e)

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

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

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

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

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

sum = 0
num = 0
nm = [1,0,-1]
c = n[3]
cu =0


for i in n:
    if c == 0:
        break
    if i > c:
        sum+= nm[num]*c
        break
    if i <= c:
        sum += nm[num] * i
        c-=i
        num+=1




print(sum)

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

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

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

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

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

if K - A - B >= 0:
    ans += (K - A - B) * (-1)
else:
    ans += 0
    
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):
s=list(map(int,input().split()))
if s[3]<=s[0]:
  print(s[3])
else:
  if s[3]-s[0]<=s[1]:
    print(s[0])
  else:
    if s[3]-s[0]-s[1]<=s[2]:
      print(2*s[0]+s[1]-s[3])
    else:
      print(s[0]-s[2])

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

s = 0

if A >= K:
    s = s + K
    print(s)

else:
    s = A
    
    K = K - A
    

    if B >= K:
        s = s
        print(s)

    else:
        s = s
        
        K = K - B
        

        if C >= K:
            s = s - K
            print(s)
        else:
            s = s - C
            K = K - C
            print(s)

Solution (Python):
def main():
	inputList= list(map(int, input().split()))
	score =[1,0,-1]
	ans =0
	for i in range(len(inputList)-1):
		if inputList[3] >= inputList[i]:
			inputList[3] = inputList[3] - inputList[i]
			ans = ans + inputList[i]*score[i]
		else:
			ans = ans + inputList[3]*score[i]
			return ans
	return ans
     
if __name__ == '__main__':
	print(main())

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

Solution (Python):
arr = input().split(" ")

a = int(arr[0])
b = int(arr[1])
c = int(arr[2])
d = int(arr[3])

e=a+b

if a >= d:
    print(d)
elif e >= d:
    print(a)
else:
    print(a-(d-e))

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

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

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