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

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split())
if a>=k:
    print(a)
else:
    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())
m=0

if K<=A:
  m=A
else:
  if K-A <=B:
    m=A
  else:
    if K-A-B <=C:
      m = 2*A-K+B

print(m)

Submission status: Wrong Answer

Solution code:
i = input().split()
a = int(i[3])-int(i[0])
b = int(i[3])-int(i[0])-int(i[1])

if i[3] <= i[0]:
  print(i[0])
elif a <= int(i[1]):
  print(i[0])
else:
  print(int(i[0])*2 + int(i[1]) - int(i[3]))

Submission status: Wrong Answer

Solution code:
# B - Easy Linear Programming
def main():
    
    a, b, _, k = map(int, input().split())
    ans = a
    if k > a:
        k = k - a
        if k > b:
            k = k - b
            if  k > 0:
                ans -= k
                print(ans)
            else:
                print(ans)
        else:
            print(ans)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


hash_table = {
    1: a,
    0: b,
    - 1: c,
}
ans = 0
for ele in hash_table:
    k = k - hash_table[ele]
    if k >= 0:
        ans += hash_table[ele] * ele
    else:
        ans += (hash_table[ele]-(-k)) * ele
print(ans)

Submission status: Wrong Answer

Solution code:
A,B, C,K = input().split()
a = int(A)
b= int(B)
c =int(C)
k=int(K)
if k-a-b-c==0:
    print(a-c)
elif k-a-b>0 and k-a-c-b<0:
    print(2*a-k+b)
elif k-a>=0 and k-a-b<=0:
    print(a)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

a_times = 0
b_times = 0
c_times = 0

if a <= k:
    a_times = a
    # print('a_times = ', a_times)
if a_times + b <= k:
    b_times = b
    # print('b_times = ', b_times)
else:
    b_times = k - a_times - b
    # print('b_times = ', b_times)
if a_times + b_times + c <= k:
    c_times = c
    # print('c_times = ', c_times)
else:
    c_times = k - a_times - b_times
    # print('c_times = ', c_times)

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

Submission status: Wrong Answer

Solution code:
L = list(map(int, input().split()))
n = [1, 0, -1]
maxres = 0

for i in range(3):
    if L[3] == 0:
        break
    maxres += L[i] * n[i]
    L[3] -= L[i]
    print(L[3])
    if L[3] < 0:
        maxres -= abs(L[3]) * n[i]
        break
print(maxres)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
while K > 0:
    M = A * 1
    K = K - A
    M = M + K * 0
    K = K - B
    M = M + K * -1

print(M)

Submission status: Wrong Answer

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

ans = A
K -= A
if B >= K:
    print(ans)
    exit()
K -= B

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

Submission status: Wrong Answer

Solution code:
import sys
a, b, c, d = map(int, sys.stdin.readline().split())
if a+b <= d:
  print(a-d+a+b)
else:
  print(a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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:
a, b, c, k = [int(tmp) for tmp in input().split()]
ans = 0
while(k>0) :
	if k>=a and a != 0 :
		k-=a
		ans = ans + 1*a
	if k>=b and b != 0:
		k-=b
	elif k<b :
		k = 0
	if k <= c :
		ans -= k
		k = 0
	if k > a+b+c :
		ans = 0
		k = 0
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
k = int(s[3])
total = 0

    
    
if a > 0 and k > 0 :
    k = k - a
    if k > 0 :
        total = a
    elif k < 0 :
        total = k
    elif k == 0 :
        total = k
        
# print(a)
        
if b > 0 and k > 0 :
    k = k - b

# print(k)
if c > 0  and k > 0 :
    lastk = k
    k = k - c
    # print(k)
    if k > 0 :
        total = total - c
    elif k < 0 :
        total = total - lastk
    elif k == 0 :
        total = total - c


print(total)

Submission status: Wrong Answer

Solution code:
s = input().split()

if s[3] == "0" :
    print(0)
    
elif ( int(s[0]) >= int(s[3]) ) or ((int(s[3]) - int(s[0]) <= int(s[1]))) :
    print(s[3])
elif int(s[3]) - int(s[0]) > int(s[1]) :
    print(int(s[0])- (int(s[3])-int(s[0])-int(s[1])))

Submission status: Wrong Answer

Solution code:
A,B, C,K = input().split()
a = int(A)
b= int(B)
c =int(C)
k=int(K)
if k-a-b-c==0:
    print(a-c)
elif k-a-b>0 and k-a-c-b<0:
    print(2*a-k+b)
elif k-a>=0 and k-a-b<0:
    print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
inputs = list(map(int, input().split()))

if inputs[0]+inputs[1]>=inputs[3]:
  print(inputs[0])
else:
  print(inputs[0] - (inputs[3] - (inputs[0]+inputs[1])))

Submission status: Wrong Answer

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

if K <= A+B:#KがA+Bより小さければ最大値はK
    max = A + (K-A)*0
else:
    max = A + (K-A)*0 + (K-A-B)*-1

print(max)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input_list = input().split(" ")
a = int(input_list[0])
b = int(input_list[1])
c = int(input_list[2])
k = int(input_list[3])
total = a + b + c
if k >= 1 and k <= total and total <= 2000000000:
    temp = a + b
    if a >= k and temp >= c:
        print(a - (k -a))
    elif c >= a:
        print(0)
    elif temp == k:
        print(a)
    else:
        aa = k - a
        ab = aa - b
        ac = ab - c
        if ac < 0 and temp >= c:
            aa = k - temp
            ab = c - aa
            print(temp - ab)
        elif ac < 0 and temp <= c:
            print(0)
        else:
            print(a - c)
else:
    print()

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
 
a = A
b = min(K-A, B)
c = min(b-C, C)

ans = 1*a + 0*b - 1*c
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
card    = list(map(int, input().split()))
count  = card[3] - card[0] - card[1]
answer = card[0]

if count <= 0:
    pass
else:
    answer = answer - (count * -1)

print(answer)

Submission status: Wrong Answer

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

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

    else:
        print(int(sum))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
n = a[0]
m = a[1]
l = a[2]
k = a[3]

if 0 < k <= n:
    print(k)

elif n < k <= n + m:
    print(n)

elif n+m <= k < n+m+l:
    print(n -1*(k -n -m))

elif n+m+l < k :
    print(n - l)
else:
    print(0)

Submission status: Wrong Answer

Solution code:

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

backup = K
AB = A + B
ans = 0
if A <= K:
    K = K - A
    ans = ans + (A * 1)

if B <= K:
    K = K - B

if K > 0:
    ans = ans + (-1) * (backup - AB)


print(ans)

Submission status: Wrong Answer

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

print(n)

Submission status: Wrong Answer

Solution code:
def solve(A, B, C, K):
    if K <= A:
        return 1 * A

    num = K - A
    ans = 1 * A

    if num <= B:
        return ans

    num -= B

    if num < 0:
        return ans

    return ans - num


A, B, C, K = map(int, input().split())
# print(solve(A, B, C, K))
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*1)
elif (K<=A+B):
    print((K-B)*1)
elif (K<=A+B+C):
    print((K-(B+C))*1+(K-(A+B)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# B - Easy Linear Programming
def main():
    
    a, b, _, k = map(int, input().split())
    ans = a
    if k > a:
        k = k - a
        if k > b:
            k = k - b
            if  k > 0:
                ans -= k
                print(ans)
        else:
            print(ans)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
k = int(s[3])
total = 0

    
    
if a > 0 and k > 0 :
    k = k - a
    if k > 0 :
        total = a
    elif k < 0 :
        total = k
    elif k == 0 :
        total = a
        
# print(a)
        
if b > 0 and k > 0 :
    k = k - b

# print(k)
if c > 0  and k > 0 :
    lastk = k
    k = k - c
    # print(k)
    if k > 0 :
        total = total - lastk
    elif k < 0 :
        total = total - lastk
    elif k == 0 :
        total = total - c


print(total)

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

sum = 0

if K - A >= 0:
  K -= A
  sum += A
else:
  print(sum)
  exit

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

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

print (sum)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
n = a[0]
m = a[1]
l = a[2]
k = a[3]

if 0 < k <= n:
    print(k)

elif n < k <= n + m:
    print(n)

elif n+m <= k < n+m+l:
    print(n -1*(k - (n+m)))

elif n+m+l < k :
    print(n - l)
else:
    print(0)

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
if K - A >= 0:
    next_b = K - A
else:
    next_b = 0
if next_b - B >= 0:
    next_c = next_b - B
else:
    next_c = 0
value = 1 * A + 0 * next_b + (-1) * next_c
print(value)

Submission status: Wrong Answer

Solution code:
A, B, C, K= map(int, input().split())
count = 0
if K>A:
    count=A
    if K-A-B>=C:
        count=count-C
        print(count)
    else:
        for i in range(C):
            if K-A-B==i:
                print(count-i)
elif A==K:
    print(A)

Submission status: Wrong Answer

Solution code:
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:
	K = K - B
else:
	K = 0
if K >= C and K >= 1:
	sum = sum - C
else:
	sum = sum - K

if sum >= 1:
	print(sum)
else:
	print(0)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

ans = []

if A > C and A == K:
    print(K * 1)
if A > C and A < K:
    print(A*1 + (K-A)*0)
else:
    for i in range(0,A+1):
        for k in range(0,C+1):
            j = K-(i+k)
            if i + k +j== K:
                ans.append(i*1 + k*-1)
            else:
                 continue

    print(max(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
a, b, c, k = [int(tmp) for tmp in input().split()]
ans = 0
while(k>0) :
	if k>=a and a != 0 :
		k-=a
		ans = ans + 1*a
	if k>=b and b != 0:
		k-=b
	elif k<b :
		k = 0
	if k <= c :
		ans -= k
		k = 0
print(ans)

Submission status: Wrong Answer

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


if c > a:
    print("0")
else:
    print(a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def choice2(a,b,c,k):
    if a >= k and a +b < k:
        print(a)
    elif a + b >= k and a + b + c <k:
        print(a)
    else:
        print(a-(k-c))

choice2(a,b,c,k)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

Submission status: Wrong Answer

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

result = 0

if k-a>0:
    result += a
    # print(1,result)
elif a > 1:
    result += a
    # print(2,result)
if k-a-b>0:
    result += 0
    # print(3,result)
if k-a-b-c >0:
    result += (k-c)*-1
    # print(4,result)
elif k-a-b>0 and c > 0:
    result += (k-c)*-1
    # print(5,result)

print(result)

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = [int(i) for i in input().split(" ")]
N = [A, B, C]
for i in range(len(N)):
    K -= N[i]
    if K == 0:
        if i == 0:
            N[i+1] = 0
            N[i+2] = 0
        elif i == 1:
            N[i+1] = 0
        break
    elif K < 0:
        if i == 0:
            N[i+1] = 0
            N[i+2] = 0
        elif i == 1:
            N[i+1] = 0
        N[i-1] += K
        break
print(1 * N[0] -1 * N[2])

Submission status: Wrong Answer

Solution code:
card    = list(map(int, input().split()))
count  = card[3] - card[0] - card[1]
answer = card[0]

if count <= 0:
    print(answer)
else:
    answer = answer + (count * -1)
    print(answer)

Submission status: Wrong Answer

Solution code:
num = input().split()
A = int(num[0]) #1
B = int(num[1])  #0
C = int(num[2]) #-1
K = int(num[3]) #選ぶ個数

count = 0
kai = 0
if K < A:
    print(A)
if K >= A:
    kai = A
    count = A

    
    if count < K:
        if K >= A+B:
            kai = A
            count = A+B
            
            if count < K:
               kai = A + (K - count)*(-1)
               
print(kai)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A,B,C,K = input().split(' ')
A = int(A) # 1
B = int(B) # 0
C = int(C) # -1
K = int(K)


# 1 x ?,  0 x ?,  -1 x ?
if (K <= A + B):
  print(K)
else:
  print(A + ((K - (A + B)) * -1))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
k = int(s[3])
total = 0

    
    
if a > 0 and k > 0 :
    k = k - a
    if k > 0 :
        total = a
    elif k < 0 :
        total = a
    elif k == 0 :
        total = a
        
# print(a)
        
if b > 0 and k > 0 :
    k = k - b

# print(k)
if c > 0  and k > 0 :
    lastk = k
    k = k - c
    # print(k)
    if k > 0 :
        total = total - lastk
    elif k < 0 :
        total = total - lastk
    elif k == 0 :
        total = total - c


print(total)

Submission status: Wrong Answer

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

count = 0

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

print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys

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

total = a
k = k - a
if k <= 0:
    print(total)
    sys.exit()

k = k - b
if k <= 0:
    print(total)
    sys.exit()

print(total - k)

Submission status: Wrong Answer

Solution code:
a,b,c,k=(int(x) for x in input().split())
a1 = a
tensuu = 0
count = 0
if k-a1 > 0:
   tensuu +=a1
   count = k-(a1+b)
   if k-a1-b > 0 :
    tensuu -=count

else:
    tensuu +=k
    exit() 
print(tensuu)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
n = a[0]
m = a[1]
l = a[2]
k = a[3]

if 0 < k <= n:
    print(k)

elif n < k <= n + m:
    print(n)

elif n+m <= k < n+m+l:
    print(n -1*(k-l))

elif n+m+l < k :
    print(n - l)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
A,B,C,K=input().split()
res=0
if int(K) < int(A):
  		res=1*int(A)
elif int(K)-int(A)-int(B)>0:
      	res-=1*(int(K)-int(A)-int(B))     

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input_list=list(input().split(" "))
#2000000000 0 0 2000000000
#A,B,C,K
a = int(input_list[3]) - int(input_list[0])
b = int(input_list[3]) - int(input_list[1])- int(input_list[0])
c = int(input_list[3]) - int(input_list[2])- int(input_list[1])- int(input_list[0])
if b <= 0:
  calc = int(input_list[0])
else:
  calc = int(input_list[0]) - b
print(calc)

Submission status: Wrong Answer

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

# sum = (1) * (a) + (0) * (k-a) + (-1) * (k-a-b)

sum = (1) * (a) + (0)

if k-a <= b:
  sum = sum + (0) * (k-a)
else:
  sum = sum + (0) * b

sum = sum + (-1) * (k-a-b)

# print('sum')
print(sum)

Submission status: Wrong Answer

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

def choice2(a,b,c,k):
    if a >= k:
        print(a)
    elif a + b >= k:
        print(a)
    else:
        print(a-(k-c))

choice2(a,b,c,k)

Submission status: Wrong Answer

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

print(n)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

countC = k - (a + b)
ans = (a * 1) + (countC * (-1))
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
L = list(map(int, input().split()))
maxres = 0

for i in range(3):
    if L[3] == 0:
        break
    n = [1, 0, -1]
    maxres += L[i] * n[i]
    L[3] -= L[i]
    if L[3] < 0:
        maxres -= abs(L[3]) * n[i]
print(maxres)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
if A >= K:
  ans = 1*A

elif A + B >= K:
  ans = 1*A + 0* (K-A) 

elif A + B + C >= K:
  ans = 1*A + 0*B + (-1*(K-A-B))
print(ans)

Submission status: Wrong Answer

Solution code:
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

# --- fetch input ---
inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---
a, b, c, k = map(int, inputs[0].split())

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

Submission status: Wrong Answer

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
A, B, C, K = map(int, stdin.readline().rstrip().split())
#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]

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

Submission status: Wrong Answer

Solution code:
num = input().split()
A = int(num[0]) #1
B = int(num[1])  #0
C = int(num[2]) #-1
K = int(num[3]) #選ぶ個数

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a > k:
  a = k
  b = 0
  c = 0
if a < k and a+b > k:
  c = 0
if a+b < k:
  c = k - a - b
  
sum_a = 1 * a
sum_c = -1 * c
  
print(sum_a + sum_c)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
n = a[0]
m = a[1]
l = a[2]
k = a[3]

if 0 < k <= n:
    print(n)

elif n < k <= n + m:
    print(n)

elif n+m <= k < n+m+l:
    print(n -1*(k-l))

elif n+m+l < k :
    print(n - l)
else:
    print(0)

Submission status: Wrong Answer

Solution code:

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

backup = K
AB = A + B
ans = 0
if A <= K:
    K = K - A
    ans = ans + (A * 1)

if B <= K:
    K = K - B

if C >= K:
    K = K - C
    ans = ans + (-1) * (backup - AB)


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k=(int(x) for x in input().split())
a1 = a
tensuu = 0
count = 0
if k-a1 > 0:
   tensuu +=a1
   count = k-(a1+b)
   if k-a1-b > 0 :
    tensuu -=count

else:
    tensuu +=a1
    exit() 
print(tensuu)

Submission status: Wrong Answer

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


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

    print(a-k+a+b)
else: pass

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum =0

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

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:
def actual(A, B, C, K):
    if K <= A:  # いきなり解決パターン
        return A

    score = 0

    if K > A:  # 「1」だけでは埋めきれないとき
        score += A
        K -= A

    if K <= B:
        return score

    if K > B:
        K -= B

    # ここからは K <= C が確定している
    # 残りの選択回数分だけ減らせばよい
    score -= K

    return score

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

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

Submission status: Wrong Answer

Solution code:
import os

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

if __name__ == "__main__":
	main()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
card    = list(map(int, input().split()))
count  = card[3] - card[0] - (card[1])
answer = card[0]

if count <= 0:
    print(answer)
else:
    answer -= count * -1
    print(answer)