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:
# from collections import defaultdict

# N, K = [int(i) for i in input().split()]
# A = [int(i) for i in input().split()]

# d = defaultdict(lambda: -1)
# d[1] = 0
# L = [1]
# i = 0
# k = i
# while i<N:
#     if d[A[k]]==-1:
#         d[A[k]] = i+1
#         L.append(A[k])
#         k = A[k]-1
#     else:
#         p = d[A[k]]
#         q = i+1
#         break
#     i += 1

# L = L[p:]
# print(L[(K-p)%(q-p)])

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

if (A+B >= K):
    if(A >= K):
        print(max(0, K))
        quit()
    else:
        print(A)
        quit()

else:
    if((K-A-B) <= C):
        print(max(0, A-K))
        quit()
    else:
        print(max(0, A-C))
        quit()

Submission status: Wrong Answer

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

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

print(a, k)
s = 0
b = [1, 0, -1]
for i, j in enumerate(a):
    n = min(j, k)
    k -= n
    s = s + b[i]*n
    if k<=0:
        break
print(s)

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

print(ans)

Submission status: Wrong Answer

Solution code:
#-*- utf-8 -*-

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

sum_mux = 0

least_A, least_B, least_C = A, B, C
least_K = K

while 0 !=  least_K:
    print(least_K)
    if 0 != least_A:
        if least_K >= least_A:
            sum_mux += least_A
            least_K -= least_A
            least_A = 0
        else :
            sum_mux += least_K
            least_A -= least_K
            least_K = 0
    elif 0 != least_B:
        if least_K >= least_B:
            sum_mux += 0
            least_K -= least_B
            least_B = 0
        else :
            sum_mux += 0
            least_B -=least_K
            least_K = 0
    else:
        if least_K >= least_C:
            sum_mux -= least_C
            least_K -= least_C
            least_C = 0
        else :
            sum_mux -= least_K
            least_C -=least_K
            least_K = 0

print(sum_mux)

Submission status: Wrong Answer

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

nmax = -1 * K 

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

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

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

Submission status: Wrong Answer

Solution code:
A,B,C,K=input().split()
res=0
cnt=0
if int(K) > int(A):
  	for _ in range(int(A)):
  		res+=1
else:
    for _ in range(int(K)-int(A)):
        res+=1
if int(K)-int(A)-int(B)>0:
     for _ in range(int(K)-int(A)-int(B)):
      	res-=1     

print(res)

Submission status: Wrong Answer

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

t = inpl()
cnt = 0
if t[3] == t[0] + t[1] + t[2]:
    cnt = t[0] + t[1] - t[2]
if t[3] < t[0] + t[1] + t[2] and t[3] >= t[0] + t[1]:
    cnt = t[0] - (t[3] - (t[0] + t[1]))
if t[3] < t[0] + t[1] and t[3] >= t[1]:
    cnt = t[0]
if t[3] < t[0]:
    cnt = t[3]
print(cnt)

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+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:
from sys import stdin

A, B, C, K = map(int, stdin.readline().rstrip().split())
res = int(0)

def f(p, n, k, res):
    if (k - n) >= 0:
        return k - n, p * (k - n) + res
    else:
        return 0, p * k + res


K, res = f(1, A, K, res)
K, res = f(0, B, K, res)
_, res = f(-1, C, K, res)
print(res)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n_a = 0
n_b = 0
n_c = 0

if K > A:
  n_a = A

  if K-A > B:
    n_b = B
    n_c = K-A-B
  
  if K-A == 0:
    n_b = B
    n_c = 0
  
  if K-A < B:
    n_b = K-A
    n_c = 0 

if K == A:
  n_a == K
if K < A:
  n_a == K
  
print(n_a+(-1)*n_c)

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
    if k - c <= 0:
      print(total-k)
    else:
      print(total-c)

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

Submission status: Wrong Answer

Solution code:
a,b,c,k=(int(n) for n in input().split())
sum = 0
if a >= k:
    sum = a
elif b+a >= k:
    sum = a
else:
    sum = a-k+c

print(sum)

Submission status: Wrong Answer

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

print(a, k)
s = 0
b = [1, 0, -1]
for i, j in enumerate(a):
    n = min(j, k)
    k -= n
    s = s + b[i]*n
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = a

minus = k - (a + b)

if minus > 0:
    ans -= minus

print(ans)

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)
else:
    print(n -1*(k-l))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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:
body_1,body_2,body_3,cards=map(int,input().split())
total=0
sa=cards-body_1-body_2
if body_1>=cards:
    total=body_1
elif body_1<cards:
    if (body_1+body_2)>=cards:
        total=body_1
    else:
        total=body_1-sa

print(total)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def q2():
    A, B, C, K = (int(i) for i in input().split())
    ans = 0

    if K <= A:
        ans += A
        return ans
    else:
        K -= A
        ans += A

    if K <= B:
        return ans
    else:
        K -= B

    if K <= C:
        ans -= K
        return ans
    else:
        ans -= C
        return ans


if __name__ == '__main__':
    print(q2())

Submission status: Wrong Answer

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

while A >= 1 and K >= 1:
	sum = sum + 1
	A = A - 1
	K = K - 1
while B >= 1 and K >= 1:
	B = B - 1
	K = K - 1
while C >= 1 and K >= 1:
	sum = sum -1
	C = C - 1
	K = K - 1

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

Submission status: Wrong Answer

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

ans = a

minus = k - (a + b)

if minus:
    ans -= minus

print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, K = list(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 = [int (x) for x in (input().split())]

count = 0

if K - A != 0:
    K = K - A
    count = A * 1
    if K != 0:
        K = K - B
        if K != 0:
            count = count + K * -1

print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

nmax = -1 * K 

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a>k:
  ak=k-a
  ans=ans-ak
if a+b<k:
  ans=ans-(k-(a+b))

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,k = map(int,(input().split()))
ans = a
while True:
    k = k - a
    if k <= 0:
        break
    else:
        k = k - b
        if k <= 0:
            break
        else:
            ans = ans - k


print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:

if __name__ == "__main__":
    A, B, C, K = map(int, input().split())
    cnt = 0
    if A - K <= 0:
        cnt = cnt + A * 1
        K = K - A
        if B - K < 0:
            K = K - B
            cnt = cnt + (K * -1)
        else:
            pass
    else:
        cnt = cnt + (A - K) * 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
text_list = input().split()
n = 0
a = int(text_list[0])
b = a + int(text_list[1])
c = b + int(text_list[2])
for i in range(int(text_list[3])):
    if i < int(text_list[0]) + int(text_list[1]):
        continue
    elif i < int(text_list[0]):
        n += 1
    elif i < int(text_list[0]) + int(text_list[1]) + int(text_list[2]):
        n -= 1

print(n)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
num = []
ans = 0
ans += 1*min(A,K)
K -= A
ans += 0*min(B,K)
K -= B
ans += -1*min(C,K)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

One = A + C
Zero = B

if K >= One:
    print(One)
elif 0 < K < One:
    print(K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

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

total = 0

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
lst = []
sum = 0
if A <= K:
    sum += 1 * A
else:
    sum += 1 * K

k = K - (A + B)

if C <= k and k > 0:
    sum += -1 * C
else:
    sum += -1 * k

print(sum)

Submission status: Wrong Answer

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


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

d={}

d[1]=a
d[0]=b
d[-1]=c

ans = 0
cnt =0
for i,j in d.items():
    cnt+=j
    ans +=i*j

    if cnt>k:
        ans +=-i*(cnt-k)

print(ans)

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)

Submission status: Wrong Answer

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

    return a - (k - (a + b))


print(resolve())

Submission status: Wrong Answer

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

for i in card[1:2]:
    if count == 0:
        break
    for j in range(i):
        if count == 0:
            break
        
        count -=1
        
        if i == 0:
            continue
        elif j == -1:
            answer -= 1
            
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k=list(map(int,input().split()))
if 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:
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 = list(map(int, input().split())) 
max = 0
for x in range(0,a[0]):
  if x <= a[3]:
    for y in range(0,a[1]):
      if x + y <= a[3]:
        for z in range(0,a[2]):
          if x + y + z == a[3]:
            if max <= x -z:
              max = x-z
              
print(max)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
A, B, C, K = map(int, input().split())

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

Submission status: Wrong Answer

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

n_a = 0
n_b = 0
n_c = 0

n_a = A

if K-A > B:
  n_b = B
  n_c = K-A-B
  
if K-A == 0:
  n_b = B
  n_c = 0
  
if K-A < B:
  n_b = K-A
  n_c = 0
  
print(n_a+(-1)*n_c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l.append(1*a)
kb = k-a
l.append(0)
kc = kb-b
l.append(-1*kc)

print(sum(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def function(a,b,c,k):
    count =0
    if a>=k:
        return a
    else:
        count =a

        k =k-a
        a=0

        while(k>0):
            if b>0:
                b-=1

            elif c>0:
                c-=1
                count-=1



            k-=1

        return count
print(function(a,b,c,k))

Submission status: Wrong Answer

Solution code:
def linear(A, B, C, K):
    s = 0
    if K <= A:
        return K

    s += A
    K -= A

    if K <= B:
        return s

    return s - C

if __name__ == "__main__":
    A, B, C, K = map(int, input().split())
    print(linear(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 < k:
    if a + b >= k:
        print(a)
    else:
        d = k -(a + b)
        print(a-d)

Submission status: Wrong Answer

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

an = 0
if a == k:
    an = a
    print(an)
    sys.exit()
else:
    an = a
    k -= a
if b == k:
    print(an)
    sys.exit()
else:
    k -= b
an -= k
print(an)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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


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


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


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


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


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

A, B, C, K = map(int, stdin.readline().rstrip().split())
res = int(0)

def f(p, n, k, res):
    if (k - n) > 0:
        return k - n, p * (k - n) + res
    else:
        return 0, p * k + res


K, res = f(1, A, K, res)
K, res = f(0, B, K, res)
_, res = f(-1, C, K, res)
print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

while B>0:
    if check == K:
        break
    sum = sum + 0
    B = B -1
    check = check + 1

while C>0:
    if check == K:
        break
    sum = sum - 1
    C = C -1
    check = check + 1

print(sum)

Submission status: Wrong Answer

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

if K == 0:
    print(0)
    sys.exit()
cnt = A + B
value = A + B*0
if cnt >= K:
    print(value)
else:
    value -= K - cnt
    print(value)

Submission status: Wrong Answer

Solution code:
A,B,C,N = map(int,input().split())
sum_card = [A,B,C]
for i in range(2):
    sum_card[i+1] += sum_card[i]
if(N-sum_card[1]<=0):
    print(A)
elif(N-sum_card[1]>0 and C - (N-sum_card[1])>0):
    print((N-sum_card[1])*(-1)+A)
elif(N>=sum_card[2]):
    print(A-C)

Submission status: Wrong Answer

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

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 - c
  k = k - c

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    print(counter)

Submission status: Wrong Answer

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

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

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

nmax = -1 * K 

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

if k > 0:
    if c >= k:
        ans -=k
        print(ans)
    else:
        k -=c
        print(ans)

Submission status: Wrong Answer

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

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

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 0

ans = A
K = K - A

if K < 0:
  ans = ans + K
  print(ans)
  sys.exit(0)

if K > 0:
  K = K - B

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def create_union_answer(a, b, c, k):
    if a >= k:
        return a
    if a + b >= k:
        return a
    # can select type[c] card numbers.
    can_c = k - (a + b)
    if can_c > c :
        can_c = c
    return a - can_c

values = input().split()

a = int(values[0])
b = int(values[1])
c = int(values[2])
k = int(values[3])

answer = create_union_answer(a, b, c, k)
print(answer)

Submission status: Wrong Answer

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

if kk > 0:
    if kk > a:
        ans += a * 1
    else:
        ans += kk * 1
    kk = kk - a

if kk > 0:
    if kk > b:
        ans += b * 1
    else:
        ans += kk * 1
    kk = kk - b

if kk > 0:
    if kk > c:
        ans += c * 1
    else:
        ans += kk * 1

print(ans)

Submission status: Wrong Answer

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

if k>=a:
    score=a
    k=k-a
    if k>=b:
        k=k-b
        if k>0:
            score-=1
else:
    score=k

        
print(score)

Submission status: Wrong Answer

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

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

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

if(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=(int(x) for x in input().split())
if a+b>=k:
    print(a)
else:
    print(k-b-2*c)

Submission status: Wrong Answer

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

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

print(ans)