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 = map(int,input().split())
d = k - a
k -= a
e = k - b
k -= b
f = k - c
n = 0 
if d == 0:
  print(a)
elif e == 0 or e < 0:
  print(a)
elif f == 0:
  print(a + c)
elif k < a:
  print(k)
else:
  print(a - e)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

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

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
n = 0 
if d == 0:
  print(a)
elif e == 0 and e < 0:
  print(a)
elif f == 0:
  print(a + c)
elif k < a:
  print(k)
else:
  print(a - e)

Submission status: Wrong Answer

Solution code:
text_list = input().split()
n = 0
count = 0
a = int(text_list[0])
b = int(text_list[1])
c = int(text_list[2])
max = int(text_list[3])

if max <= a + b:
    n = a
elif max <= a + b + c:
    d = max - a + b
    n = a - d
else:
    n = a - c

print(n)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


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




print(sum)

Submission status: Wrong Answer

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

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

if ans <= 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 1 # 0 # -1 K
a, b, c, K = map(int, input().split())
sum = 0

if K > a:
  sum += a*1
  K = K - a
elif K != 0:
  sum += int(a-K)*1
  K = 0
  
if K >b:
  sum +=b*0
  K = K - b
elif K != 0:
  sum += int(b-K)*0
  K = 0
  
if K > c:
  sum +=c*-1
  K = K -c
elif K!=0:
  sum += int(c-K)*-1
  K = 0
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = k - a
m = l - b
n = m - c

ans = 0

if l >= 0:
    ans += a
    if l == 0:
        print(ans)
    else:
        if m >= 0:
            if n > 0:
                ans -= n
                print(ans)
            else:
                ans -= m
                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)
else:
    print(A-(K-A-B))

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
    if K >= C:
      print(A - C)
    else:
      print(A - K)
  else:
    print(A)
else:
  print(A)

Submission status: Wrong Answer

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

if a - c <= 0:
    print("0")
else:
    print(a)

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)
else:
    a_times = k
if a_times + b <= k:
    b_times = b
    # print('if - b_times = ', b_times)
else:
    b_times = k - a_times - b
    # print('else - b_times = ', b_times)
if a_times + b_times + c <= k:
    c_times = c
    # print('if - c_times = ', c_times)
else:
    c_times = k - a_times - b_times
    # print('else - c_times = ', c_times)

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

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 += 2*B
if (K-A-B>0):
  max_score += (-1)*(K-A-B)
print(max_score)

Submission status: Wrong Answer

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

a = abck[0]
b = abck[1]
c = abck[2]
k = abck[3]



#numbers = list()
if a + b <= k:
    print(1 * a)
else:
    z = (k - (a + b))
    print((1 * a) + (-1 * z))

Submission status: Wrong Answer

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

if k-a<0:
    ans=k

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

print(ans)

Submission status: Wrong Answer

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

print(choice2(a,b,c,k))

Submission status: Wrong Answer

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

Cn = K - A - B

ans = A - Cn
print(ans)

Submission status: Wrong Answer

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

if(K <= A + B):
    sum = A
else:
    sum = (A) - min((K - (A + B)), C)

print(sum)

Submission status: Wrong Answer

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

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

if ans <= 0:
    ans = 0
print(ans)

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

Submission status: Wrong Answer

Solution code:
def main():
  a, b, c, k = map(int, input().split())
  d = k-a-b
  
  print(a + d*(-1))
  
main()

Submission status: Wrong Answer

Solution code:
a,b,c,k = map(int,input().split())
ans = a
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())
if A >= K:
    x = A
else:
    if A + B >= K:
        x = A
    else:
        x = 2 * A + B - K

print(x)

Submission status: Wrong Answer

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

ans = 0
co = d[3]

for i in range(3):
    a = co - d[i]
    if a >= 0 and i == 0:
        ans += d[i] * 1
    elif a >= 0 and i == 1:
        ans += d[i] * 0
    elif a >= 0 and i == 2:
        ans += d[i] * -1
    elif a < 0 and i == 0:
        ans += co * 1
    elif a < 0 and i == 1:
        ans += co * 0
    elif a < 0 and i == 2:
        ans += co * -1
    
    co -= d[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
 
count = k - (a + b + c)
countC = c - abs(count)
ans = (a * 1) + (countC * (-1))
print(ans)

Submission status: Wrong Answer

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

sum = 0

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

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

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

print (sum)

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
res = 0
total = 0
p = 0
l = 0
S = K - A
if S > 0:
    p = 1
    s = 0
    for b in range(1, B+1):
        if S > 0:
            S = S - p
            s += 1
            if s > 1:
                p += 1
if S > 0:
    l = 1
    s = 0
    for c in range(1, C+1):
        if S > 0:
            S = S - l
            s += 1
            if s > 1:
                l += 1
total = A*1 + p*0 + l*-1
print(total)

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 += 1 * ele
    if k == 0:
        break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


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




print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=input().split()
A=int(n[0])
B=int(n[1])
C=int(n[2])
D=int(n[3])
a = np.array([1,0,-1])
b = np.array([A,D-A,D-A-B])
if A>=1:
    print(sum(a*b))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if inputs[0] > inputs[3]:
	sumAns = sumAns + inputs[3]
	inputs[3] = 0
else:
	sumAns = sumAns + inputs[0]
	inputs[3] = inputs[3] - inputs[0]

if inputs[1] > inputs[3]:
	inputs[3] = 0
else:
	inputs[3] = inputs[3] - inputs[1]

if inputs[2] > inputs[3]:
	sumAns = sumAns - inputs[3]
	inputs[3] = 0
else:
	inputs[3] = inputs[3] - inputs[2]
	
print(sumAns)

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]) #選ぶ個数

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

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

Submission status: Wrong Answer

Solution code:
text_list = input().split()
n = 0
count = 0
a = int(text_list[0])
b = int(text_list[1])
c = int(text_list[2])
max = int(text_list[3])

if max <= a + b:
    n = a
else:
    d = max - a + b
    n = a - d

print(n)

Submission status: Wrong Answer

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

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


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


print(ans-k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if k-a<0:
    ans=a

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

print(ans)

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
n = 0 
if d == 0:
  print(a)
elif e == 0:
  print(a)
elif f == 0:
  print(a + c)
elif k < a:
  print(k)
else:
  print(a - e)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout  
  
def main(): 
	a, b, c, k = [int(x) for x in stdin.readline().split()] 
	ans = 0
	if a > 0:
		if k < a:
			a = k
		ans +=a
		k-=a
	if b > 0:
		if k < b:
			b = k
		k-=b
	if c > 0:
		if k < c:
			c = k
		ans -=c
		k-=c
	if ans < 0:
		ans = 0 
	stdout.write(str(ans)+'\n')
if __name__ == "__main__": 
	main()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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])
elif b == int(i[2]):
  print(int(i[0])*2 + int(i[1]) - int(i[3]))
else:
  print(int(i[0]) - int(i[2]))

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
else:
    ans = a - c

if ans <= 0:
    ans = 0
print(ans)

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:
        return a
    elif a + b >= k and a + b + c <k:
        return a
    else:
        return (a-(k-(a+b)))

print(choice2(a,b,c,k))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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
n = 0 
if d == 0:
  print(a)
elif e == 0:
  print(a)
elif f == 0:
  print(a + c)
else:
  print(a - e)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input().split()
n = int(s[3])
sum_=0
if int(s[0])+int(s[1]) >= n:
    sum_=1*(n-int(s[1]))
else:
    sum_=1*int(s[0])+(-1*(n-int(s[0])-int(s[1])))
print(sum_)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
text_list = input().split()
n = 0
count = 0
a = int(text_list[0])
b = int(text_list[1])
c = int(text_list[2])
max = int(text_list[3])

if max <= a + b:
    n = a
else:
    n = a - c

print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

if k-a<0:
    ans=a

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

print(ans)

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

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

if ans <= 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
print(A,B,C,K)
res = 0
if A>=K:
  res= 1*A
else:
  for b in range(K-A,B+1):
    c = K-A-b
    if c >= 0:
      ans = 1*A + 0*b + (-1)*c
      res = max(res,ans)
    else:
      break
print(res)

Submission status: Wrong Answer

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

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

if ans >= 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
text_list = input().split()
n = 0
count = 0
a = int(text_list[0])
b = a + int(text_list[1])
c = b + int(text_list[2])
max = int(text_list[3])

if max <= b:
    n = a
else:
    n = a - c

print(n)

Submission status: Wrong Answer

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

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

if K > 0:
  judge = A - K
else:
    judge = A
    
print(judge)

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

choice2(a,b,c,k)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

max_sum = 0

if a+b >= k:
    max_sum = a
else:
    max_sum = a*2+b-k

print(max_sum)

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) 

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

Submission status: Wrong Answer

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

nokori = K - A - B

wa = 0
wa += A

if nokori == 0:
    pass
elif C >= nokori:
    wa -= nokori
else:
    wa -= C

print(wa)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 0
if k > a:
    ans += a*1
    k = k - a
elif a >= k:
    k = 0
    ans = k*1

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

if k > 0 and k > c:
    ans = ans - 1*c
    k = 0
elif k > 0 and c >= k:
    ans = ans - 1*k
    k = 0

print(ans)

Submission status: Wrong Answer

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

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

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

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

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 -= K - C
  sum += -K
else:
  sum += -1 * K

print (sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
text_list = input().split()
n = 0
count = 0
a = int(text_list[0])
b = a + int(text_list[1])
c = b + int(text_list[2])
max = int(text_list[3])

if max < b:
    n = a
else:
    n = a - c

print(n)

Submission status: Wrong Answer

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

a = abck[0]
b = abck[1]
c = abck[2]
k = abck[3]

numbers = list()

for i in range(a):
    numbers.append(1)

if not k >= a + b:
    if not c == 0:
        for i in range(c):
            numbers.append(-1)
        for i in range(b):
            numbers.append(0)
    else:
        pass
else:
    pass

print(sum(numbers[0 : k]))

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

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

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

Submission status: Wrong Answer

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

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

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 > 0:
  ans = ans + 0 * count
count = count - b  
if count > 0:
  ans = ans - 1 * count 
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(sum)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

if b < k and k:
    k -= b
else:
    k = 0

if k:
    total_sum -= k

print(total_sum)

Submission status: Wrong Answer

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

if a == k:
	print(a)
else:
	if a == 1 and k > a:
		print(0)
	else:
		print(min(a,k))

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)