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 0s and C cards with -1s.

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 1s 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



Sample input:
2 1 1 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
A, B, C, K = tuple(int(c) for c in input().split(' '))

if A >= K:
    print(A)
    exit()
else:
    bc = K - A  # A < K なのでbc >= 1
    assert bc >= 1
    if B >= bc:
        print(A)
        exit()
    else:
        # B < bc
        cc = bc - B
        assert cc >= 1
        print("{:.0f}".format(A - cc))
        exit()

Submission status: Wrong Answer

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

r = 0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

if 0 <= (k - a):
    ans += a
    k = k - a
    if 0 <= (k - b):
        k = k - b
        if 1 <= k:
            ans -= k
    else:
        pass
else:
    ans += k - a

print(ans)

Submission status: Wrong Answer

Solution code:
#S = str(input())
A, B, C, K = map(int,input().split())

a = A

if B <= K-a:
    b = B
else:
    b = K-a

c = K - a - b

ans = a - c
print(ans)

Submission status: Wrong Answer

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

if k-a-b <= 0:
  count = a
else:
  count = 2*a + b - k

print(count)

Submission status: Wrong Answer

Solution code:
A,B,C,K= map(int, input().split())
a=0
c=0
if A<=K:
    a=A
if A>K:
    a=K
if C<=K-A-B:
    c=C*-1
if C>K-A-B:
    c=(K-A-B)*-1
print(a+c)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
plus, zero, minus, number = map(int, input().split(" "))

if(plus + zero >= number):
  print(plus)
else:
  print(plus + max(plus + zero - number, (-1)*minus))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A = list(map(int, input().split()))

if( A[0] >= A[3] ):
  print(A[0])
elif( A[0] + A[1] >= A[3] ):
  print(A[0])
else:
  p = A[0]
  m = A[2] - (A[0]+A[1])
  print(m)

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split())
ans=0
finished=False
if a<=k:
  ans+=a
  k-=a
else:
  ans+=k
  f=True

if not finished:
  if b<=k:
    k-=b
  else:
    f=True

if not finished:
  ans-=k
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
A,B,C,K=map(int, raw_input().split())
L=[0]
L.append(L[-1]+A)
L.append(L[-1]+B)
L.append(L[-1]+C)
if bisect_right(L,K)==1:
    print K
elif bisect_right(L,K)==2:
    print A
elif bisect_right(L,K)==3:
    print A-(K-A-B)
elif bisect_right(L,K)==4:
    print A-B

Submission status: Wrong Answer

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

ans = 0

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

k = k-b

if k >= c:
    ans -= k
else:
    ans -= c

print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int,input().split())
if K==0:
	print(0)

elif K <= A:
	print(A)
	#　すべてAが取れる場合
else:
	if K <= A+B:
		print(A)
		# AとBの合計よりも取る枚数が少ない場合は-1のCを取らないのでAの総数と同じ値になる
	else:
		x = K - A -B
		#　合計値KからAとBの値を取り除いた値
		# この数値*-1をAをすべて取った値に足す
		print(A-x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0

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

Submission status: Wrong Answer

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

max  = 0

if(a > k):
  max += k
  k = 0
else:
  max += a
  k -= a 
  
if(not k == 0)and(b > k):
  k = 0
else:
  k -= b
  
if(c > k):
  max -= k
else:
  max -= c

print(max)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
A, B, C, K = map(int, input().split())

ans = 0
end_flag = False

if K > A:
    ans += A

else:
    ans = K
    end_flag = True

if end_flag == False and K - A > B:
    ans += 0

else:
    ans += 0
    end_flag = True

if end_flag == False and K - A - B > C:
    ans += -C

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
cnt_a, cnt_b, cnt_c, cnt = map(int, input().split())
if cnt_a + cnt_b >= cnt:
    print(cnt_a)
else:
    print(cnt_a - (cnt - cnt_a - cnt_b))

Submission status: Wrong Answer

Solution code:
a,b,c,k=(int(x) for x in input().split())
if a>k:
    print(a*1)
else:
    if a+b>=k:
        print(a*1)
    else:
        print(a*1-(k-a-b)*1)

Submission status: Wrong Answer

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

def maxK(A,B,C,K):
  s=0
  if K-A<0:
    return A
  else:
    s+=A
    K-=A
  if K-B<0:
    return s
  else:
    K-=B
  return s-K

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k = input().split()
a,b,c,k = int(a),int(b),int(c),int(k)
s = 0
k = k-a
s = s+a
if k>0:
    k = k-b
if k>0:
    z  = k-c
    s = s+(a*-1)
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a = [int(x) for x in input().split()]
count1=0
count0=0
count2=0
if a[3]>a[1]:
   count1=a[0]
if a[3]<a[1]:
    count1=a[3]   
if a[3]-a[1]-a[0]>0:
    count2=-(a[3]-a[1]-a[0])
print(count1+count2)

Submission status: Wrong Answer

Solution code:
A_1, B_0, C_minus1, K = map(int, input().split(' '))

max_total = 0

if(K <= (A_1 + B_0)):
  max_total = A_1
else:
  left = K - (A_1 + B_0)
  if(left <= C_minus1):
    max_total = A_1 - left
  else:
    max_total = A_1 - C_minus1
  
print(max_total)

Submission status: Wrong Answer

Solution code:
A,B,C,K=map(int, input().split())
num_list=[]
for i in range(A):
    num_list.append(1)
for j in range(B):
    num_list.append(0)
for k in range(C):
    num_list.append(-1)

print(sum(num_list[0:K-1]))

Submission status: Wrong Answer

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


if A+B>K:
    ans = A
else:
    ans += A
    count = A+B
    if count < K:
        while count != K:
            #残り枚数全て引き算
            ans-=1
            count+=1
        
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

Solution code:
def main():
    a, b, c, k = map(int, input().split())
    if a >= k:
        print(k)
    else:
        res = 0
        for i in range(1, a+1):
            for j in range(1, b+1):
                l = k - i - j
                if i + j == k:
                    res = max(res, i)
                if l > 0:
                    res = max(res, i-j)

        print(res)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

z=0

if a !=0 and k !=0:
    z +=1*a
    k -=a

if b!= 0 and k>0:
    k-=b

if k>0 and c !=0:
    z = z -1*(k)
    
print(z)

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
if k <= a:
    k_pa, k_pb, k_pc = k , 0, 0 
elif k >= a and k-a <= b:
    k_pa, k_pb, k_pc = a, k-a, 0
elif k >= a and k-a >= b:
    k_pa, k_pb, k_pc = a, k-a, k-a-b
point = k_pa - (k-k_pa-k_pb)
print(point)

Submission status: Wrong Answer

Solution code:
A = list(map(int,input().split()))

if A[3] <= A[0]:
    print(A[0])
elif A[0] < A[3] and A[3] <= A[0] + A[1]:
    print(A[0])
else:
    print(A[0] - (A[3] -A[0] -A[1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum=0

if K>A:
    sum=A

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

else:
    sum=A
    print(int(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
abcd = list(map(int,input().split()))
x = []
for i in range(abcd[0]):
    x.append(1)
for i in range(abcd[1]):
    x.append(0)
for i in range(abcd[2]):
    x.append(-1)
num = 0
for i in range(abcd[3]):
    num += x[i]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    A,B,C,K = map(int,input().split())
    abc = [A,B,C]
    ans = 0

    a = A if A<K else K
    b = (K-a) if (K-a)>=0 and (K-a)<B else B
    c = K-A-B
    print(a-c)


main()

Submission status: Wrong Answer

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

if a>0 and k>0 and a<=k:
  k=k-a
  ans=ans+a
elif a>0 and k>0 and a>k:
  k=0
  ans=ans+k

while b>0 and k>0:
  b+=-1
  k+=-1

while c>0 and k>0:
  ans+=-1
  c+=-1
  k+=-1
  
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 0

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

print(result)

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
#print(A,B,C,K)
if K <= A+B:
  ans = A
else:
  ans = 2*A+B-K
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = [int(x) for x in input().split()]

ans = x[0]
x[3] -= x[0] + x[1]
if x[3] >= 0:
    ans -= x[3]

print(ans)

Submission status: Wrong Answer

Solution code:
x = [x for x in map(int,input().split())]
A = x[0] # A = 1,B = 0,C = -1 ,k
B = x[1]
C = x[2]
K = x[3]
print(x)
sum = 0
sum += A # sum = 2
left = abs(A - K) # left = 1
if B < left:
    left -= B # left = 3 - 2 = 1
else:
    left -= B
sum -= left
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, k = map( int, input().split())
s = k-a-b

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if b > 0 and k > 0:
    if b < k:
        k -= b
    else:
        k = 0
        print(total)

if c > 0 and k > 0:
    if c < k:
        total -= c
        print(total)
    else:
        total -= k
        print(total)

Submission status: Wrong Answer

Solution code:
a,b,c,k = map(int,input().split())
if k == 0:
    print(0)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if K <= A:
	print(A)
	#　すべてAが取れる場合
else:
	if K <= A+B:
		print(A)
		# AとBの合計よりも取る枚数が少ない場合は-1のCを取らないのでAの総数と同じ値になる
	else:
		x = K - A -B
		#　合計値KからAとBの値を取り除いた値
		# この数値*-1をAをすべて取った値に足す
		print(A-x)

Submission status: Wrong Answer

Solution code:
S = list(map(int, input().split()))
Sum = 0
if S[0] > S[3]:
  Sum = S[0]
elif S[0] + S[1] > S[3]:
  Sum = S[0]
else:
  Sum = S[0]*2 - S[3] + S[1]
print(Sum)

Submission status: Wrong Answer

Solution code:

import numpy as np
import math
from collections import Counter
import sys

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

total = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

info = input().split(' ')
card_one = int(info[0])
card_zero = int(info[1])
card_minus = int(info[2])
number = int(info[3])

sumnum = 0

if (number >= card_one):
    number = number - card_one
    sumnum = sumnum + card_one
else:
    print(card_one)
    sys.exit()

if (number >= card_zero):
    number = number - card_zero
else:
    print(sumnum)
    sys.exit()

if (number >= card_minus):
    sumnum = sumnum - card_minus
    print(sumnum)

while(number>0):
    number = number - 1
    sumnum = sumnum - 1

print(sumnum)

Submission status: Wrong Answer

Solution code:
class abc_167:
    
    def __init__(self):
        pass
    
    def A(self):
        S=input()
        T=input()
        if S==T[:len(S)]:print("Yes")
        else:print("No")
    
    def B(self):
        ABCK=list(map(int,input().split()))
        sum_num=0
        
        if ABCK[3]<=ABCK[0]+ABCK[1]:sum_num=ABCK[0]
        else:sum_num=ABCK[0]-(ABCK[3]-ABCK[0]-ABCK[1])
        
        print(sum_num)
            
    def C(self):
        pass
    
    def D(self):
        pass
    
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_167()
    obj.B()

Submission status: Wrong Answer

Solution code:
#S = str(input())
A, B, C, K = map(int,input().split())

a = A

if B <= K-a:
    b = B
else:
    b = K-a

if C <= K-a-b:
    c = C
else:
    c = K-a-b
ans = a - c
print(ans)

Submission status: Wrong Answer

Solution code:
#--Easy Linear Programming

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

number = 0
count = 0
if (k <= a):
    count = count + a
    print(count)

    exit()

if (k > a):
    number = number + a
    count = count + a

kk = k - number

if (kk <= b):
    print(count)
    exit()

if (kk > b):
    number = number + b

kkk = k - number
#print(kkk)
if (kkk <= c):
    count = count - kkk
    print(count)
    exit()

if (kkk > c):
    count = count - c

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    A, B, C, K = map(int, input().split())
    l = []

    if K-A<0:
        out = K
    if K-A>=0:
        l.append(A)
        K = K-A
    if K-B>=0:
        K = K-B
    if K>0:
        m = K * -1
        l.append(m)
    out = sum(l)
    print(out)
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    num_plus_one, num_zero, num_minus_one, total_num = map(int, input().split(' '))
    counter = 0

    if total_num < num_plus_one + num_zero:
        counter = num_plus_one
    else:
        counter = num_plus_one - (total_num - num_plus_one - num_zero)

    print(counter)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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

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

ans -= k
print(ans)

Submission status: Wrong Answer

Solution code:
def main(a: int, b: int, c: int, k: int):
    ans = 0

    if k <= a + b:
        print(a)
        return

    for _ in range(k):
        if a != 0:
            ans += 1
            a -= 1
        elif b != 0:
            b -= 1
        elif c != 1:
            ans -= 1
            c -= 1

    print(ans)


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if a >= k:
  an = k
  bn = 0
  cn = 0
elif a+b >= k:
  an = a
  bn = k - (a)
  cn = 0
else:
  an = a
  bn = b
  cn = k - (a+b+c)
  
print(an-cn)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
l = list(map(lambda x:int(x), input().split(" ")))
a = l[0]
b = l[1]
c = l[2]
k = l[3]
if a >= k:
    print(a)
elif a < k:
    if b >= k-a:
        print(a)
    elif b < k-a:
        print(a-(k-a-b))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

t = inpl()
cnt = 0

if t[3] >= t[0]:
    t[3] -= t[0]
    cnt = t[0]
    if t[3] > t[1]:
        t[3] -= t[1]
        cnt -= t[3]
    else:
        pass
else:
    cnt = t[0]

print(cnt)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
if a== d:
    print(a)
elif a<d:
    if a%2 == 0:
        print(a)
    else:
        print(a-1)

Submission status: Wrong Answer

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

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

print(score)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input().split()
a = int(S[0])
b = int(S[1])
c = int(S[2])
k = int(S[3])

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

Submission status: Wrong Answer

Solution code:
I = list(map(int,input().split()))
A = I[0]
B = I[1]
C = I[2]
K = I[3]

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

print(S)

Submission status: Wrong Answer

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

tmpk = 0

tmp = 0
flg = True

if a > k:
    print(k)
    flg = False
else:
    tmp = a
    tmpk = k - a

if b > tmpk and flg:
    print(tmp)
    flg = False
else:
    tmpk -= b
    if tmpk <= 0:
        print(tmp)
        flg = False

if flg:
    tmp -= tmpk
    print(tmp)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
a, b, c, k = map(int, input().split())
if (a + b) >= k:
    print(a)
else:
    print(a - (k - a - b))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, k = map(int, input().split())
print((1*a)+(k-(a+b))*-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
chk1 = k-a
chk2 = k-a-b
if chk1 < 0:
    ans = a

else:
    if chk2 > 0:
        ans = a -1*chk2
    else:
        ans = a
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k = map(int,input().split())
if k == 0:
    print(0)

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

Submission status: Wrong Answer

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

res = a * 1
k -= a

if k == 0:
  print(res)
else:
  if k <= b:
    res += k * 0
    print(res)
  else:
    res += b * 0
    k -= b
    res += k * -1
    print(res)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())

ancer = 1 * A + 0 * (D - B) + (-1 *(D - A - B))
print(ancer)

Submission status: Wrong Answer

Solution code:
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
ans=0
K-=A
ans+=A
if K<=0:
    print(ans)
    exit()
K-=B
if K<=0:
    print(ans)
    exit()
ans-=K
print(ans)

Submission status: Wrong Answer

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

count = 0

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

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

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

if A>=K:
    sum = A
else:
    if A+B>=K:
        sum = A
    else:
        sum = 2*A-K+B

print(sum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    A,B,C,K = map(int,input().split())
    abc = [A,B,C]
    ans = 0

    a = A
    b = (K-a) if (K-a)>=0 and (K-a)<B else B
    c = K-A-B
    print(a-c)


main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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