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

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

Submission status: Wrong Answer

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

sum =0

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if K <= A:
    print(K)

elif A < K <= A + B:
    print(A)

else:
  print(A+B-C)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

if K <= A:
    ans = A

elif K <= A + B:
    ans = A

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

A,B,C,K=(int(x) for x in input().rstrip('\n').split())
res = A
les = A+B
if K>les:
  los = K-les
  res -= los
print(int(res))

Submission status: Wrong Answer

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

wa = 0
wa += A
wa -= C * (K - A -B)

print(wa)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

S = K - (A+B+C)

if S < 0:
    print(2*A+B-K)
else:
    print(A-C)

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:
import sys
input = sys.stdin.readline
#read=sys.stdin.buffer.read
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
a, b, c, k = map(int, input().split())
x = 0
y = k

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

Submission status: Wrong Answer

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

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) = list(map(int, input().split()))
items = [
    (A, 1),
    (B, 0),
    (C, -1)
]

_sum = 0
k = K
for num_cards, val in items:
    if num_cards <= k:
        num = num_cards
        k -= num_cards
    else:
        num = k
    _sum += (val * num)
    if k == 0:
        break

print(_sum)

Submission status: Wrong Answer

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

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

    print(ans)

Submission status: Wrong Answer

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

ans = 0

if a == 0:
    print(0)
if a == 0 and b == 0:
    print(0)

ans = a*1
k -= a
if k > 0:
    k -= b
    if k > 0:
        for _ in range(c):
            if k == 0:
                break
            ans += (1)
            k -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
a = input().rstrip().split(' ')
A,B,C,K = int(a[0]),int(a[1]),int(a[2]),int(a[3])
s = 0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
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 + A
    else :
        K = A - K
        sum = sum + K

    if K <= 0 :
       return sum

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

    if K <= 0 :
       return sum

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

    if K <= 0 :
       return sum

print(f(A, B, C, 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:
  b = k - a
  c = 0
if a+b < k:
  c = k - a - b

li_card = []

for i in range(a):
  li_card.append(1)
for i in range(b):
  li_card.append(0)
for i in range(c):
  li_card.append(-1)


print(sum(li_card))

Submission status: Wrong Answer

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

ans = 0

if d == 0:
    ans = 0
elif a >= d:
    ans = d
elif (a + b) >= d:
    ans = d
elif (a + b - c) <= 0:
    ans = 0
else:
    ans = a - c

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if k-a1 >0:
    count = k-(a1+b)

else:exit()

if k-a1-b > 0 :
    tensuu -=count

print(tensuu)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if a - k >= 0: #全部１
    print(1 * a)
elif a - k < 0 and a + b - k >= 0:
    print(1 * a)
else:
    print(1 * a - 1 * (k - a - b))

Submission status: Wrong Answer

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

sum =0

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

Submission status: Wrong Answer

Solution code:
import sys
a,b,c,k = map(int,input().split())
sumcheck = 0
count = 0
for i in range(0,a):
    sumcheck += 1
    count += 1
    if count >= k:
        sys.exit()
for i in range(0, b):
    count += 1
    if count >= k:
        sys.exit()
for i in range(0, c):
    sumcheck -= 1
    count += 1
    if count >= k:
        sys.exit()

print(sumcheck)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

#M=K-(A+B)

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

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

if int(A) >= int(K):
    Answer = 1*int(A)
    print(Answer)
else:
    if int(B) >= int(K)-int(A):
        Answer = 1*int(A)
        print(Answer)
    else:
        Answer = 1*int(A)-1*(int(K)-int(A)-int(B))
        print(Answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=input().split()
pl1=int(a[0])
pl0=int(a[1])
pl_1=int(a[2])
draw=int(a[3])
#print(pl1,pl0,pl_1,draw)
if(pl1>=draw):
  print(draw)
elif(pl1+pl0>=draw):
  print(pl1)
else:
  all_card=pl1+pl0+pl_1
  #print(all_card)
  draw_pl_1=all_card-draw
  #print(draw_pl_1)
  print(pl1-draw_pl_1)

Submission status: Wrong Answer

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

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 < n < k:
    print(n)
    
elif n >= k:
    print(n)
elif n + m >= k:
    print(n)
elif n + m + l >= k:
    print(n -1*(k-l))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = 0

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

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

elif K < A + B:
    ans = A

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

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a, b, c, k = map(int, input().split())

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

total=0
total+=a

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

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

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

if (K != 0) and (C <= K):
    K -= C
    K -= C
else:
    ans -= K
    K -= K

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

sum = 0
if K >= A:
    for i in range(A):
        sum += 1
else:
    for i in range(K):
        sum += 1
        break

if (K-A) >= B:
    for i in range(B):
        sum += 0
else:
    for i in range(K-A):
        sum += 0
        break

if (K-(A+B)) >= C:
    for i in range(C):
        sum += -1
else:
    for i in range(K-(A+B)):
        sum += -1
        break

print(sum)

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
ans = 0
count = 0
# for i in range(A):
#     ans += 1
#     if i 

# while count != K:
#     if count <= A:
#         ans +=1
#         count+=1
#     elif count <= B:
#         count+=1
#     else:
#         ans -= 1
#         count+=1

if A+B>=K:
    ans = A
else:
    ans += A
    
    count = K-(A+B) # 残り枚数
    if count > 0:
        ans-=count
        
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    a,b,c,k = I2()
    l = k-a-b
    print(l)
    if k <= a:print(k)
    elif a+b >= k:print(a)
    elif l <= c:print(a-l)

Submission status: Wrong Answer

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

ans = 0

ans = a*1
k -= a
if k > 0:
    k -= b
    if k > 0:
        for _ in range(c):
            if k == 0:
                break
            ans += (1)
            k -= 1
print(ans)

Submission status: Wrong Answer

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

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:
A,B, C,K = input().split()
Q = int(0)
Y = int(1)
for Y in range(int(K)):
    X = int(A) - Y
    Z = int(B) -X
    W = int(C) -Z
    if X >0 and Z >0 and W >=0:
        print(int(K)-int(A)-int(C))
    elif X >=0and Z ==0:
        print(int(A))

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
res = 0
if K < A:
    res = A * 1
    print(res)
else:
    res = A * 1
    K -= A
    if K < B:
        print(res)
    else:
        K -= B
        for _ in range(K):
            res += -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+c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

# for i in range(K):
# 	if A > 0:
# 		sum += 1
# 		A -= 1
# 	elif B > 0:
# 		B -= 1
# 	else:
# 		sum -= 1
# 		C -= 1

# print(sum)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 1 * a
count = d - a

if count - b >= 0:
  ans = ans + 0 * b
  count = count - b
  
if count - c >= 0:
  ans = ans -1 * c
  
print(ans)

Submission status: Wrong Answer

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

max = 0
if K!=0:
    for i in range(A):
         for j in range(B):
                for k in range(C):
                    max+=1
                    K-=1
                    if K==0:
                        break
        
    
print(max)

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

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(num_list)
print(sum(num_list[0:K]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

A,B,C,K=(int(x) for x in input().rstrip('\n').split())
res = A
if K>(A+B):
  los = K-B-A
  res -= los
print(res)

Submission status: Wrong Answer

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

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

if(k > 0):
  ans = a
  k = k - a
if(k > 0):
  k = k - b
if(k > 0):
  ans = ans - k

print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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)

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
lis = []
if k >= a:
    lis.append(a)
elif k >= a + b:
    lis.append(0*(b-a))
elif k >= a+b+c:
    lis.append(-1*(c-b-a))
print(sum(lis))

Submission status: Wrong Answer

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

n_sum = 0
if a >= k:
  n_sum += k
  print(n_sum)
  sys.exit()
else:
  n_sum += a
  k -= a

k -= b

if k <=0:
  print(n_sum)
  sys.exit()
if c >= k:
  n_sum -= c
  print(n_sum)
  sys.exit()
else:
  n_sum -= k
  print(n_sum)
  sys.exit()

Submission status: Wrong Answer

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

if k>=c:
    k=k-c
    s=s+c*(-1)
else:
    
    s=s+k*(-1)
    sys.exit()
    
print(s)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
S = list(map(int, input().split()))
Sum = 0
if S[0] > S[3]:
  Sum = S[3]
if 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:
a,b,c,k = map(int,input().split())
if k <= a+b:
  print(a)
else:
  c = a - (k-a-b)
  print(c)

Submission status: Wrong Answer

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

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

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 n >= k:
    print(n)
elif n + m >= k:
    print(n)
elif n + m + l >= k:
    print(n -1*(k-l))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 * A
else:
    if (A + B) >= K:
        count = 1 * A
    else:
        if B < C:
            count = 1 * A + (-1) * (C - B)
        else:
            count = 1 * A + (-1) * C


print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a, b, c, k = map(int, input().split())
t = a + b
if t < k:
    print(a-(k-t))
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)
elif (c+b+a) <= k:
    print(a+b+c)
elif (a+b) < k < (a+b+c):
    print(a-(k-(a+b)))

Submission status: Wrong Answer

Solution code:
a, b, c, counts = map(int, input().split())
x = a - counts
if x < 0:
    y = b + x
    if y < 0:
        z = c + y
print(1 * a + -1 * (-(b + x)))

Submission status: Wrong Answer

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

ans += min(K,A)
K = K -A
if K >0:
    for i in range(B):
        K = K-1

if K>0:
    ans= ans -1
    K = K-1

print(ans)

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

Submission status: Wrong Answer

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

score=0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
result = A * 1
# Aを使った後の残が0より大きい
if K - A > 0:
    # Bを使った後の残が0より大きい
    if K - A - B > 0:
        result -= (K - A - B)
        print(result)
    # Bを使った後の残が0以下
    else:
        print(result)
# Aを使った後の残が0以下
else:
    print(result)

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*-1
else:
    ans+=n*-1
print(ans)

Submission status: Wrong Answer

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

if int(A) >= int(K):
    Answer = 1*int(A)
    print(Answer)

else:
    if int(B) >= int(K)-int(A):
        Answer = 1*int(A)
        print(Answer)

    else:
            Answer = 1*int(A)-1*int(C)
            print(Answer)

Submission status: Wrong Answer

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

print (A, B, C, K)

sum = 0
for _ in range(K):

  if A - 1 >= 0:
    A -= 1
    sum += 1
    continue

  if B - 1 >= 0:
    B -= 1
    sum += 0
    continue

  if C - 1 >= 0:
    C -= 1
    sum += -1

print (sum)

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:
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:
    sum -= (left * 1)
else:
    sum = sum
print(sum)

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

Submission status: Wrong Answer

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

tmp = k -(a+b)


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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