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: Runtime Error

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

m=[1,0,-1]

c = list(itertools.combinations_with_replacement(m,int(K)));
sum=[]
for i in range(len(c)):
    if c[i].count(1)<=int(A) and c[i].count(0)<=int(B) and c[i].count(-1)<=int(C):
        sum.append(c[i].count(1)+c[i].count(-1))
print(max(sum))

Submission status: Runtime Error

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

  
import itertools
m = 0
if A == K:
  print(K)
else:
  l=[1]*A+[0]*B+[-1]*C
  print(l)
  for i in itertools.combinations(l,K):
    if sum(i) > m:
      m=sum(i)
  print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
a, b, c, d = map(int, sys.stdin.readline().split())
li = [1]*a + [0]*b + [-1]*c
print(sum(li[0:d]))

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())
S = A + B + C

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

Submission status: Runtime Error

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

  
import itertools
m = 0
if A <= K:
  print(K)
else:
  l=[1]*A+[0]*B+[-1]*C
  for i in itertools.combinations(l,K):
    if sum(i) > m:
      m=sum(i)
  print(m)

Submission status: Runtime Error

Solution code:
sum = 0
if K>0:
    if A>0:
        if A>K:
            sum = sum + K
        else:
            sum = sum + A
    K = K - A
if K > 0:
    if B>0:
        K = K - B
if K > 0:
    if C>0:
        sum = sum + K * (-1)
print(sum)

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())
S = A + B + C

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

Submission status: Runtime Error

Solution code:
import numpy as np
S=np.array([0]*4)
S=input().split()
A=int(S[0])
B=int(S[1])
C=int(S[2])
K=int(S[3])
if(K<=A+B):
    M=A
    print(M)
else:
    M=1*A+(-1)*(K-A-B)
    print(M)

Submission status: Runtime Error

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

res = [1] * a
res.extend([0]*b)
res.extend([-1]*c)
res.sort(reverse=True)

print(sum(res[:k]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A = input('')
B = input('')
C = input('')
K = input('')

if int(K) <= int(A) + int(B):
    print(A)

else:
    print(int(A) - (int(K) - int(A) - int(B)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A=input()
B=input()
C=input()
K=input()
maxi=2A-K+B
print(maxi)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import math
if K <= A:
  print(K)
if A < K <= A + B:
  print(A)
if A + B < K <= A + B + C:
  print(A * 2 + B - K)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

nokori = K - A - B

wa = 0
wa += A

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

print(wa)

Submission status: Runtime Error

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

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


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




print(sum)

Submission status: Runtime Error

Solution code:
from sys import maxsize
a, b, c, k = map(int, input().split())
l1 = [1] * a
l2 = [0] * b
l3 = [-1] * c
list = []
for h in l1:
    list.append(h)
for i in l2:
    list.append(i)
for j in l3:
    list.append(j)
max_so_far = -maxsize - 1
max_ending_here = 0
start = 0
end = 0
s = 0
for l in range(0,k+1): 
    max_ending_here += list[l]  
    if max_so_far < max_ending_here: 
        max_so_far = max_ending_here 
        start = s 
        end = l  
    if max_ending_here < 0: 
        max_so_far = 0
        s = l+1
print(max_so_far)

Submission status: Runtime Error

Solution code:
import os
import random
import re
import sys

def solution(a,b,c,k):
    max=0
    while(k>0):
        while(a>0 and k>0):
            max+=1
            a-=1
            k-=1
        if(k<=0):
            return max
            break
        while(b>0 and k>0):
            b-=1
            k-=1
        if(k<=0):
            return max
            break
        while(c>0 and k>0):
            max-=1
            c-=1
            k-=1
        return max
            
                
if __name__ == '__main__':
    fptr = sys.stdout
    a=int(input())
    b=int(input())
    c=int(input())
    k=int(input())
    result = solution(a,b,c,k)

    fptr.write(str(result) + '\n')


fptr.close()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if K <= A:
  print(K)
if A < K <= A + B:
  print(A)
if A + B < K <= A + B + C:
  print(A * 2 + B - K)

Submission status: Runtime Error

Solution code:
import numpy as np
S=np.array([0]*4)
S=input().split()
A=int(S[0])
B=int(S[1])
C=int(S[2])
K=int(S[3])
if(K<=A+B):
    M=A
    print(M)
else:
    M=1*A+(-1)*(K-A-B)
    print(M)

Submission status: Runtime Error

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

ls = [1] * A + [0] * B + [-1] * C

print(sum(ls[:K]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import maxsize
a, b, c, k = map(int, input().split())
l1 = [1] * a
l2 = [0] * b
l3 = [-1] * c
list = []
for h in l1:
    list.append(h)
for i in l2:
    list.append(i)
for j in l3:
    list.append(j)
max_so_far = -maxsize - 1
max_ending_here = 0
start = 0
end = 0
s = 0
for l in range(0,k+1): 
  
    max_ending_here += list[l] 
  
    if max_so_far < max_ending_here: 
        max_so_far = max_ending_here 
        start = s 
        end = l
  
    if max_ending_here < 0: 
        max_so_far = 0
        s = l+1
print(max_so_far)

Submission status: Runtime Error

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

list1=[1]*A
list2=[0]*B
list3=[-1]*C

num_list.extend(list1)
num_list.extend(list2)
num_list.extend(list3)

print(sum(num_list[0:K]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())
if K <= A + B:
  print(K)
else:
  print(A * 2 + B - K)

Submission status: Runtime Error

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

result = 0

for i in k:
    if a != 0:
        result = result + 1
        a = a - 1
    elif a == 0 and b != 0:
        #result変わらず
        b = b - 1
    elif a == 0 and b == 0 and c != 0:
        result = result - 1
        c = c  - 1
    else:
        break

print(result)

Submission status: Runtime Error

Solution code:
A, B, C, K = map(int, input().split())
ABC_total = 0
A_list = [1,] * A
B_list = [0,] * B
C_list = [-1,] * C
ABC_list = A_list + B_list + C_list
for i in range(K):
  ABC_total += ABC_list[i]
print(ABC_total)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
int(input())
if K <= A + B:
  print(K)
else:
  print(A * 2 + B - K)

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
a, b, c, k = map(int, input().split())
l1 = [1] * a
l2 = [0] * b
l3 = [-1] * c
list = []
for h in l1:
    list.append(h)
for i in l2:
    list.append(i)
for j in l3:
    list.append(j)
max_so_far = 0
max_ending_here = 0
      
for l in range(0, k): 
    max_ending_here = max_ending_here + list[l] 
    if max_ending_here < 0: 
        max_ending_here = 0
    elif (max_so_far < max_ending_here): 
        max_so_far = max_ending_here
print(max_so_far)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input()
if K <= A + B:
  print(K)
else:
  print(A * 2 + B - K)

Submission status: Runtime Error

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


ka = k - a
if ka > 0:
    kb = ka - b
print(a*1+ka*0+kb*-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

n = [1]*a + [0]*b + [-1]*c

print(sum(n[:k]))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

ans = 0
if K-A>0:
    ans += A*1
    K -= A
    judge = 1
elif K-A==0:
    #ここで終わり
    ans += A*1
    judge = 0



judgeB=1
if judge==1 and K-B>0:
    K -= B
    
elif judge==1 and K-B<=0:
    K-=B
    judgeB = 0
    


if judgeB==1:
    ans += -1*K

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a_1, b_0, c_m1, k = map(int, input().split())

def dfs(n, a_n, b_n, c_n, max_):
	#print(n, a_n, b_n, c_n, max_)
	#print(type(n), type(a_n), type(b_n), type(c_n), type(max_))
	if (a_n > a_1 or b_n > b_0 or c_n > c_m1):
		return max_
	if (n == 0):
		max__ = int(a_n) - int(c_n) 
		if (max__ > max_):
	#		print(max__, type(max__), "***")
			return max__
		else:
			return max_
	m1 = dfs(n-1, a_n+1, b_n, c_n, max_)
	#print(m1, type(m1), "+++")
	m2 = dfs(n-1, a_n, b_n+1, c_n, m1)
	m3 = dfs(n-1, a_n, b_n, c_n+1, m2)
	return m3
            
max_ = dfs(k, 0, 0, 0, -99999)
print(max_)

Submission status: Runtime Error

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

print(n)

Submission status: Runtime Error

Solution code:
A,B,C,D = map(int,input().split())
# a = [1] * A + [0] * B + [-1] * C
if (A+B+C) == D:
    
    a = 1 * A + 0 * B + (-1 * C)
    
elif (B >= (D-A)) and (C >= (D-A+B)):
    a = 1 * A + 0 * B + (-1 * (D-A+B))
    
elif A >= D:
    a = 1 * D
    
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if K <= A:
    print(K)

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

else:
  print(A+B-c)

Submission status: Runtime Error

Solution code:
if K <= A + B:
  print(K)
else:
  print(A * 2 + B - K)

Submission status: Runtime Error

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

S = K - (A+B+C)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def maximum(A, B, C, K):
  maxi=2A-K+B
  print(maxi)

Submission status: Runtime Error

Solution code:
import sys

a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
    sys.exit()
elif a + b >= k:
    print(a)
    sys.exit()

ones = [1] * a
zeros = [0] * b
negas = [-1] * c

totals = []
totals.extend(ones)
totals.extend(zeros)
totals.extend(negas)

totals = totals[0:k]
print(sum(totals))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()
T = input()

Slen = len(S)
Tx = T[0:Slen]

if S == Tx:print("Yes")
else: print("No")

Submission status: Runtime Error

Solution code:
input_list=list(input())

#A,B,C,K
a = int(input_list[3]) - int(input_list[0])
b = int(input_list[3]) - int(input_list[1])- int(input_list[0])
c = int(input_list[3]) - int(input_list[2])- int(input_list[1])- int(input_list[0])
if b <= 0:
  calc = input_list[0]
else:
  calc = input_list[0] - input_list[2]

Submission status: Runtime Error

Solution code:
abcd = list(map(int,input().split()))
x = []
y = []
z = []
x = [1] * abcd[0]
y = [0] * abcd[1]
z = [-1] * abcd[2]
x.extend(y)
x.extend(z)
print(sum(x[:abcd[3]]))

Submission status: Runtime Error

Solution code:
A, B, C, K = list(map(int, input().split())) 
l = []
l+=([1]*A)+([0]*B)+([-1]*C)
  
import itertools
m = 0
for i in itertools.combinations(l,K):
  if sum(i) > m:
    m=sum(i)
    
print(m)

Submission status: Runtime Error

Solution code:
input_list=list(input())

#A,B,C,K
a = int(list[3]) - int(list[0])
b = int(list[3]) - int(list[1])- int(list[0])
c = int(list[3]) - int(list[2])- int(list[1])- int(list[0])
if b <= 0:
  calc = list[0]
else:
  calc = list[0] - list[2]

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,d = (int(x) for x in input().split())
if d - a >= 0:
  ans = 1 * a
  count = d - a

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

Submission status: Runtime Error

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

list=[]+[1]*a+[0]*b+[-1]*c
ans=0
for i in range(k):
    ans+=list[i]

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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
elif (c > k) and (k > 0):
    sum += -1 * k

print(sum)

Submission status: Runtime Error

Solution code:
abcd = list(map(int,input().split()))
x = []
y = []
z = []
x = [1] * abcd[0]
y = [0] * abcd[1]
z = [-1] * abcd[2]
x.extend(y)
x.extend(z)
num = 0
for i in range(abcd[3]):
    num += x[i]
print(num)

Submission status: Runtime Error

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

sums = 0

alist = [1] * a
blist = [0] * b
clist = [-1] * c

ll = alist + blist + clist

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
a, b, c, k = map(int, input().split())
aa = [1]*a
bb = [0]*b
cc = [-1]*c
nn = aa + bb + cc
su = 0
for i in range(0,k):
    su = su + nn[i]
print(su)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input_list=list(input())

#A,B,C,K
a = int(list[3]) - int(list[0])
b = int(list[3]) - int(list[1])
c = int(list[3]) - int(list[2])

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

print(calc)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

while True:
    nokori=K
    if A<=nokori:
        maisu1=A
        nokori=nokori-maisu1
    else:
        maisu1=nokori
        break

    if B<=nokori:
        maisu2=B
        nokori=nokori-maisu2
    else:
        maisu2=nokori
        break
    
    if C<=nokori:
        maisu3=A
        nokori=nokori-maisu3
        break
    else:
        maisu3=nokori
        break

print(maisu1-maisu3)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(n)

Submission status: Runtime Error

Solution code:
a,b,c,d = (int(x) for x in input().split())
if d >= a:
  ans = 1 * a
  count = d - a

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

Submission status: Runtime Error

Solution code:
a, b, c, k = map(int, input().split())
ones = [1] * a
zeros = [0] * b
negas = [-1] * c

totals = []
totals.extend(ones)
totals.extend(zeros)
totals.extend(negas)

totals = totals[0:k]
print(sum(totals))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

li_a = [1] * a
li_b = [0] * b
li_c = [-1] * c

li_a.extend(li_b)
li_a.extend(li_c)
li_k = li_a.copy()

print(sum(li_k[:k]))

Submission status: Runtime Error

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)
    break
elif D>=0:
    print(D)
    break
else:
    for i in range(0,C):
        D=D+-1
        
print(D)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from itertools import combinations
A,B,C,K=map(int,input().split())
n=[1]*A+[0]*B+[-1]*C
base = list(combinations(n,K))

ans=0
for i in range(len(base)):
    max_b=sum(base[i])
    if ans <max_b:
        ans=max_b
print(ans)

Submission status: Runtime Error

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

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

while b>0 and k>0:
  b+=-1
  k+=-1

while c>0 and k>0:
  ans+=-1
  c+=-1
  k+=-1
  
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A = input()
B = input()
C = input()
K = input()

result = 0

for i in K:
    if A != 0:
        result = result - 1;
        A = A - 1;
    elif A == 0 and B != 0:
        #result変わらず
        B = B - 1;
    elif A == 0 and B == 0:
        result = result - 1;
        C = C - 1;
    else:
        break

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

cards = [1]*a + [0]*b + [-1]*c
print(sum(cards[:k]))

Submission status: Runtime Error

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


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

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
A = a[0]
B = a[1]
C = a[2]
K = a[3]
if A > k :
    print(A)
elif (A + B) > K:
    print(A)
else:
    print(A-(K-A-B))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A,B,C,K=map(int,input())
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: Runtime Error

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

Submission status: Runtime Error

Solution code:
if n > k:
    print(n)
elif n + m > k:
    print(n)
else:
    print(n - l)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())
c = int(input())
k = int(input())

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

Submission status: Runtime Error

Solution code:
def main():
  a, b, c, k = map(int, input().split())
  
  if b != 0 and c != 0:
    for i in range(a+1):
      for j in range(b+1):
        for s in range(c+1):
          ans = [1*i + j*0 + s*(-1)]
          if k == i+j+s:
            n = max(ans)
          break
    print(n)
  elif b != 0 and c == 0:
    print(a)
  elif b == 0 and c != 0:
    g = a + c*(-1)
    hui = max(g)
    print(hui)
  else:
    print(a)
    
  
main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

cards = [1]*A + [0]*B + [-1]*C
print(sum(cards[:K]))

Submission status: Runtime Error

Solution code:
A, B,C,K = map(int, input().split())
K_list = [0]*K

for i in range(K):
  if(i+1<=A):
    K_list[i] = 1
  elif(i+1<=A+B):
     K_list[i] = 0
  elif(i+1<=A+B+C):
     K_list[i] = -1
  
        
        


sun = sum(K_list)
print(sun)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x = []
for i in range(abcd[0]):
    x.append(1)
for i in range(abcd[1]):
    x.append(0)
for i in range(abcd[2]):
    x.append(-1)
num = 0
for i in range(abcd[3]):
    num += x[i]

Submission status: Runtime Error

Solution code:
a = input()
b = input()
c = input()
k = input()

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if A == K:
    print(A)
    quit()
List1 = [1]*A
List2 = [0]*A
List3 = [-1]*A
List = List1+List2+List3
print(sum(List[:K]))

Submission status: Runtime Error

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

import numpy as np

all = np.zeros(a+b+c)
all[:a] +=1
all[-c:] -=1

print(int(sum(all[:k])))

Submission status: Runtime Error

Solution code:
from sys import maxint
a, b, c, k = map(int, input().split())
l1 = [1] * a
l2 = [0] * b
l3 = [-1] * c
list = []
for h, i, j in l1, l2, l3:
  list.append(h, i, j)
msf = -maxint - 1
meh = 0
for l in range(0, k):
  meh = meh + list[l]
  if meh < 0:
    meh = 0
  elif (msf < meh):
    msf = meh
print msf

Submission status: Runtime Error

Solution code:
import itertools
A, B, C, D = map(int, input().split())
l = A*[1] + B*[0] + C*[-1]
max_val = -1*C
for v in itertools.combinations(l, D):
    sum_v = sum(v)
    if max_val < sum_v:
        max_val = sum_v

print(max_val)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def main():
    A, B, C, K = map(int, input().split())
    nums = [1] * A + [0] * B + [-1] * C
    nums.sort(reverse=True)
    print(sum(nums[:K]))
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
a,b,c,d = (int(x) for x in input().split())
if d >= a:
  ans = 1 * a
  count = d - a

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

Submission status: Runtime Error

Solution code:
a, b, c, d= input().split()
for k in a,b,c,d:
  if k <a,b,c,d:
    print(a+b+c+d)
  else:
    print(0)

Submission status: Runtime Error

Solution code:
a, b, c, d = map(str,input().split())
if a== d:
    print(a)
elif a<d:
    if a%2 == 0:
        print(a)
    else:
        print(a-1)

Submission status: Runtime Error

Solution code:
text_list = input().split()
n = 0
for i in range(str(text_list[3])):
  if i >= int(text_list[0]):
    n += 1
  elif i >= int(text_list[0]) + int(text_list[1]):
    pass
  elif i >= int(test_list[0]) + int(text_list[1]) + int(text_list[2]):
    n -= 1
    
print(n)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
a, b, c, k = map(int, input().split())
A = [1] * a
B = [0] * b
C = [-1] * c
A.extend(B)
A.extend(C)
print(sum(A[:k]))

Submission status: Runtime Error

Solution code:
import itertools
A, B, C, D = map(int, input().split())
l = A*[1] + B*[0] + C*[-1]
max_val = -1*C
if A > B:

for v in itertools.combinations(l, D):
    sum_v = sum(v)
    if max_val < sum_v:
        max_val = sum_v

print(max_val)

Submission status: Runtime Error

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

ab = a+b
abc = a+b+c

if k <= a:
  print(k)
elif k<= ab:
  print(k):
else:
  print(a-(k-ab))

Submission status: Runtime Error

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

if k <= A:
    print(K)
if A < K <= A + B:
    print(A)
if A + B < K <= A + B + C:
    print(2*A + B - K)