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

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

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

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:
A, B, C, K = map(int, input().split())
res = 0
total = 0
p = 0
l = 0
Z = 0
S = K - A
if S > 0:
    Z = S - B
if Z > 0:
    l = 1
    s = 0
    for c in range(1, C+1):
        if Z > 0:
            Z = Z - l
            s += 1
            if s > 1:
                l += 1
        else:
            break
total = A*1 + B*0 + l*-1
print(total)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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


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

    ans = a
    num = a
    if num < k:
        num += b
    if num < k:
        ans -= k - num
    print(ans)


if __name__ == "__main__":
    main()

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



# # https://atcoder.jp/contests/abs/tasks/abc081_b

# N = int(input())
# A = map(int, input().split())

# min_count = 1000000000000

# for a in A:
#     pow_count = 0

#     while a % 2 == 0:
#         pow_count += 1
#         a /= 2
#     # print(a, pow_count)

#     if pow_count < min_count:
#         min_count = pow_count

# print(min_count)

Submission status: Wrong Answer

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

Cn, ans = 0, 0
if K - A > 0 & K - A - B > 0:
    Cn = K - A - B
    ans = A - Cn
elif K - A - B == 0:
    ans = A
elif K - A == 0:
    Cn = 0
    ans = A - Cn
print(ans)

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 

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

Submission status: Wrong Answer

Solution code:
def a():
    s = input()
    t = input()
    if s == t[0:-1]:
        print('Yes')
    else:
        print('No')


def b():
    a, b, c, k = map(int, input().split())
    sum = 0
    k -= a
    if k <= 0:
        sum = k
    else:
        sum = a
    k -= b
    if k >= 1:
        sum -= k
    print(sum)

# def c():

# def d():


b()

Submission status: Wrong Answer

Solution code:
line1 = input().split()
a = int(line1[0])
b = int(line1[1])
c = int(line1[2])
k = int(line1[3])
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())

sum = 0

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

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

if C > 0:
  if K >= C:
    K -= C
    sum += -1 * C
  else:
    sum += -1 * K
    #print(sum)
    exit

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
elif A == 0:
  sum = -K
else:
  sum = A - (K - A - B)
print(sum)

Submission status: Wrong Answer

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


if A or C == 0:
    if A == 0:
        K = K-B
        ans = -(C-K)
        print(ans)
        exit()
    else:
        print(A)
        exit()
elif B == 0:
    K = K-A
    C = C-K
    ans = A-C
    print(ans)
    exit()

cnt = 0

if A+B >= K:
    if A<=K:
        print(A)
        exit()
    print(K-A)
    exit()
else:
    K = K-(A+B)
    ans = A
    cnt = C-K
    ans = ans-cnt
    print(ans)
    exit()

Submission status: Wrong Answer

Solution code:
def solve(a, b, c, k):
    point = a
    more = k - a
    if more > 0:
        more -= b
    if more > 0:
        point -= more

    print(point)

a, b, c, k = map(int, open(0).read().split())
solve(a, b, c, k)

Submission status: Wrong Answer

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

print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x = k - a
y = x - b
z = y - c

if x <= 0:
    print(k)
elif y <= 0:
    print(a)
else:
    print(a-(c-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]

count = 0

if (A + B) >= K:
    count = 1 * A
else:
    if B == C:
        count = 1 * A + (-1) * (C -B + 1)
    else:
        count = 1 * A + (-1) * (C - B)


print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if(a > k): # a > k
  print(1*(a-k))
  exit()
elif(k-a == 0):
  print(1*a)
  exit()
elif(k > a and k-a < b): # k > a 
  print(a)
  exit()
elif((k-a)-b == 0):
  print(a)
  exit()
elif(k-a-b <= c):
  x = (k - a - b)
  print(a-x)
  exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

K -= 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())
L=[]
for i in range(a):
  L.append(1)
for i in range(b):
  L.append(0)
for i in range(a):
  L.append(-1)
  
print(sum(L[:k]))

Submission status: Wrong Answer

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

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])
c = np.array([0,B,D-B])
if A>=1:
    print(sum(a*b))

if A==0 and B==0:
    print("-1")  

if A==0 and B>=1:
    print(sum(a*c))

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

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

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

ans -= k

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
we = str(input())
r = we.split(" ", -1)

A = r[0]
B = r[1]
C = r[2]
K = r[3]
A = int(A)
B = int(B)
C = int(C)
K = int(K)

def max_sum(A, B, C, K):
    if A >= K:
        print(A)
    elif A < K:
        R = K - A
        if B >= R:
            print(A)
        elif B < R:
            S = R - B
            print(A + S*(-1))
max_sum(A, B, C, K)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

Submission status: Wrong Answer

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

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

g = 0

if d - a > 0 and a > 0:
    # if a > 0:
    g += a
    d -= a
elif a > 0:
    g += d
    d -= a

if d - b > 0 and a > 0:
    d -= b
elif b > 0:
    d -= b

if d - c > 0 and c > 0:
    g -= d
elif c > 0:
    g -= d

print(str(g))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def actual(A, B, C, K):
    if A >= K:
        return A

    score = 0
    
    if A < K:
        score += A
        K -= A

    if B >= K:
        return score

    if B < K:
        K -= B

    if C >= K:
        score -= K

    # ここまできて C < K は ありえないはず

    return score

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

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

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
Z = S - B
if Z > 0:
    l = 1
    s = 0
    for c in range(1, C+1):
        if Z > 0:
            Z = Z - l
            s += 1
            if s > 1:
                l += 1
        else:
            break
total = A*1 + B*0 + l*-1
print(total)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 1*a + 0*b - 1*c

print(int(ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

x2 = A+B
x3 = A+B+C

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

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

A, B, C, K = map(int, input().split(" "))
data = [1 for _ in range(A)] + [0 for _ in range(B)] + [-1 for _ in range(C)]

sums = [sum(conb) for conb in itertools.combinations_with_replacement(data, K)]
print(max(sums))

Submission status: Wrong Answer

Solution code:
######ANSDEFINE##########
#unnecessary			#
#########################

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

if A <= K: #AがKより小さい
  
  if A + B >= K: #A+BがKより大きい
    print(A * 1)
    
  elif A + B <= K: #A+BがKより小さい
    if B >= 1: #Bが1枚以上
      if A+B >= C:#A+BがCより小さい
        print((A+B) - C)
      else:#それ以外
        print((A+B) - C)
    else: #それ以外
      print(A - C)
     
	
elif A >= K: #AがKより大きい
  print(K * 1)

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 + c
if sum > 0:
    print(a)
else:
    print(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 0

if k > a:
  if k > b:
    for i in range(a):
      ans += 1
      k = k - 1
    for i in range(b):
      ans += 0
      k = k - 1
    for i in range(k):
      ans += -1
      print(ans)
  elif k <= b:
      for i in range(k):
        ans += 0
      print(ans)
elif k <= a:
  for i in range(k):
    ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys

# print('input >>')
A, B, C, K = map(int,(input().split()))

ans = 0
rest = K

if A >= K:
    print(K)
    sys.exit()

if K <= A:
    print(A)
    sys.exit()

rest -= A
rest -= B

# print(rest)
if rest <= 0:
    print(A)
    sys.exit()

rest -= B

print(-(K-A-B))

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)
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:
    print(sum)
    if c == 0:
        break
    if i > c:
        sum+= nm[num]*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=(int(x) for x in input().split())

a1 = a
nokori = 0
nokori_1 = 0
nokori_2 = 0
tensuu = 0

if k-a1 > 0:
   tensuu +=a1
   nokori = k-a


if nokori > 0:
   tensuu +=0
   nokori2 =nokori - b
   if nokori2 > 0:
        tensuu -= nokori2

print(tensuu)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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*cards
elif body_1<cards:
    if (body_1+body_2)>=cards:
        total=body_1*1
    else:
        total=body_1*1-(sa*(-1))

print(total)

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]) - int(i[2]))
else:
  print(int(i[3]) - int(i[1])- int(i[2]))

Submission status: Wrong Answer

Solution code:
line1 = input().split()
a = int(line1[0])
b = int(line1[1])
c = int(line1[2])
k = int(line1[3])
if a >= k:
  print(a)
elif a + b >= k:
  print(a)
else:
  num_c = k - (a + b)
  print(a - num_c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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


def linear_search(a, b, c, k):
    A = a
    B = 0
    C = -1 * c
    ans_list = []
    
    for i in range(a +1):
        if i == k:
            return i
        for j in range(b +1):
            if i + j == k:
                ans_list.append(i)
                
    if len(ans_list) != 0:
        return max(ans_list)
    
    for h in range(c +1):
        if a + b + h == k:
            ans_list.append(a+ (-1)*h)
                    
    return max(ans_list)


if a == k:
    print(a)
elif b == k:
    print(0)
elif c == k:
    print((-1)*c)
else:
    print(linear_search(a, b, c, k))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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:
    if count < card[2]:
        answer = answer + (count * -1)
        print(answer)
    else:
        count = count - card[2]
        answer = answer + (count * -1)
        print(answer)
else:
    print(answer)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# cook your dish here
a,b,c,k=map(int,input().split(" "))
sum=0
if k<=a:
    sum=a
elif k<=(a+b):
    sum=a
else:
    sum=a
    k=k-a
    sum=sum-k
    if(sum<=0):
        sum=0
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if (a + b >= k or a == k) or (a == 0 and c == 0) or (c == 0 and b == 0):
    print(a)
else:
    print(a + ((a+b) - k))

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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
if k<=a:
  s = s+k
elif k>a:
  s = s+a
k = k-s
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())
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 >= 1:
	sum = sum - K
	K = K - K

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input()

S=S.split()

A=int(S[0])
B=int(S[1])
C=int(S[2])
K=int(S[3])

result=0

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if(a > k): # a > k
  print(1*(a-k))
  exit()
elif(k-a == 0):
  print(1*a)
  exit()
elif(k > a and k-a < b): # k > a 
  print(a)
  exit()
elif((k-a)-b == 0):
  print(a)
  exit()
elif(k-a-b < c):
  x = (k - a - b)
  print(a-x)
  exit()
elif((k-a)-b >= c):
  print(a-c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if A <= K:
  ans += min([A,K])

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

print(ans)

Submission status: Wrong Answer

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

Cn = 0
if K - A > 0:
    Cn = K - A - B
elif K - A == 0:
    Cn = 0
ans = A - Cn
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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())
ans = 0
if a <= k:
    ans = 1 * min(a, k)
    k = k - min(a, k)
if k > 0:
    k = k - b
if k > 0:
    ans = ans - k
print(ans)

Submission status: Wrong Answer

Solution code:
"""
# スペース区切りの整数の入力
b, c = map(int, input().split())
"""

a,b,c,k = map(int,input().split())
result = 0
if a <= k:
    result += a
    k = k-a
    a = 0
if b <= k:
    k = k-b
    b = 0

while k > 0:
    if a > 0:
        result+=1
        a-=1
        k-=1
        continue
    elif b > 0:
        b-=1
        k-=1
        continue
    else:
        result-=1
        c-=1
        k-=1
        continue

print(result)

Submission status: Wrong Answer

Solution code:
line1 = input().split()
a = int(line1[0])
b = int(line1[1])
c = int(line1[2])
k = int(line1[3])
if a >= k:
  print(a)
elif a + b >= k:
  print(a)
else:
  print(a - (k - (a + b)))

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])
c = np.array([0,B,D-B])
if A>=1:
    print(sum(a*b))
if A==0:
    print(sum(a*c))
if A==0 and B==0:
    print("-1")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools

A, B, C, K = map(int, input().split(" "))
data = [1 for _ in range(A)] + [0 for _ in range(B)] + [-1 for _ in range(C)]

conbs = list(itertools.combinations_with_replacement(data, K))
sums = [sum(conb) for conb in conbs]
print(max(sums))

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


print(count)

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

print(int(A+(K-A-B)*-1))

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:
    if count > card[2]:
        answer = answer + (count * -1)
        print(answer)
    else:
        answer = answer + (card[2] * -1)
        print(answer)
else:
    print(answer)

Submission status: Wrong Answer

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

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

if(a > k): # a > k
  print(1*(a-k))
  exit()
elif(k-a == 0):
  print(1*a)
  exit()
elif(k > a and k-a < b): # k > a 
  print(a)
  exit()
elif((k-a)-b == 0):
  print(a)
  exit()
elif(k-a-b < c):
  x = (k - a - b)
  print(a-x)
  exit()
elif((k-a)-b > c):
  print(a-c)

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

print(ans)

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(z)
    print((1 * a) + (-1 * z))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

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[3]) - int(i[1])- int(i[2]))

Submission status: Wrong Answer

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

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

print(ans)