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:
s = input().split()
n = int(s[3])
l1=[1]*int(s[0])
l2=[0]*int(s[1])
l3=[-1]*int(s[2])
l=l1+l2+l3
sum_=0
i=0
while i < n:
    sum_+=l[i]

    i += 1
print(sum_)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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[:a+b])))

Submission status: Runtime Error

Solution code:
def solve(A, B, C, K):
    num = K

    if K <= A:
        return 1 * A

    num -= A
    ans = 1 * A

    if num <= B:
        return ans

    num -= B

    if num < 0:
        return ans

    return ans - num


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

Submission status: Runtime Error

Solution code:

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

array = [1, 0, -1]

que = PriorityQueue()

ans = 0
for i in range(K):
    if(i<A):
        ans += array[0]
    elif(i<A+B):
        ans += array[1]
    else:
        ans += array[2]
print(ans)

Submission status: Runtime Error

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

l = [1]*a
bl = [0]*b
cl = [-1]*c

l.extend(bl)
l.extend(cl)

for i in l:
  ans = ans+i
  m=m+1
  if m==k:
    break

print(ans)

Submission status: Runtime Error

Solution code:
s = input().split()
n = int(s[3])

l1=[1]*int(s[0])
l2=[0]*int(s[1])
l3=[-1]*int(s[2])
l=l1+l2+l3
sum_=0
i=0
while i < n:
    sum_+=l[i]

    i += 1
print(sum_)

Submission status: Runtime Error

Solution code:
a, b, c, k = map(int, input().split())
if k <= a:
    k_pa, k_pb, k,pc = k , 0, 0 
elif k >= a and k-a <= b:
    k_pa, k_pb, k_pc = a, k-a, 0
elif k >= a and k-a >= b:
    k_pa, k_pb, k_pc = a, k-a, k-a-b
point = k_pa - (k-a-b)
print(point)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ancer = 0
for i in range(D):
    ancer += a[i]
    
print(ancer)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())
 
if A >= K or A + B == K:
  print(str(A))
elif A + B < K:
  num = A - (K - A - B)
  print(str(num))

Submission status: Runtime Error

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

if a>=k:
    Result=k
elif a+b>=k>a:
    Result=a
else:
    Result=2a-k+b

print(Result)

Submission status: Runtime Error

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

count = 0

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from itertools import combinations
 
A, B, C, K = map(int, input().split(" "))

a = -100
_sum = 0
for i in combinations([1] * A + [0] * B + [-1]*C, K):
  if (_sum := sum(i)) > a:
    a = _sum
print(a)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

sum = 0
li = [1] * A
Bli = [0] * B
Cli = [-1] * C

li.extend(Bli)
li.extend(Cli)

for k in range(K):
    sum = sum + li[k]

print(sum)

Submission status: Runtime Error

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

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

print(num)

Submission status: Runtime Error

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

if(k<=(a+b) and k>=1):
    print(a)
else if(k<=a+b+c):
    print(a-(k-(a+b)))

Submission status: Runtime Error

Solution code:
import collections
import numpy as np
import sys
sys.setrecursionlimit(10**8)
A,B,C,K=map(int,input().split())
if K<=A:
    print(K)
elif A<K<=A+B:
    print(A)
else: print(A-(K-(A+B)))


#N=int(input())

# h=np.array(list(map(int,input().split())))
# ans=0
# def sol(l,m,k):
#     global ans
#     if m==0:
#         return ans
#     elif m>0:
#         for i in range(N-m+1):
#             if not 0 in l[i:i+m]:
#                 ans+=np.amin(l[i:i+m])
#                 l[i:i+m]=l[i:i+m]-min(l[i:i+m])
#                 print(l)
#         sol(l,m-1,ans)
#     # else:
#     #     ans+=np.count_nonzero(h)
#     #     sol(l, m - 1, ans)
# n=0
# sol(h,N,ans)
# print(ans)

Submission status: Runtime Error

Solution code:
!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    ans=0
    sub=K
    if A>K:
        ans+=1*K
        sub-=K
    else:
        ans+=1*A
        sub-=A
    if sub!=0:
        if B>sub:
            sub=0
        else:
            sub-=B
    if sub!=0:
        ans-=sub
    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

la = [1]*a
lb = [0]*b
lc = [-1]*c
m = 0
l = la + lb + lc 

for i in range(k):
    m = m + l[i]
print(m)

Submission status: Runtime Error

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


if a>=k:
    Result=k
elif a+b>=k:
    Result=a
else:
    Result=2a-k+b

print(Result)

Submission status: Runtime Error

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

import numpy as np

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

print(sum(all))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

ans=0
if A[0]<A[3]:
  ans = A[0]
else:
  ans = A[3]
  print(ans)
  
print(ans-(A[3]-A[0]-A[1])

Submission status: Runtime Error

Solution code:
A, B, C, K = map(int, input().split()) 
import numpy as np
arr = np.concatenate([np.ones(A, int), np.zeros(B, int), np.ones(C, int)*-1])
print(arr[:K].sum())

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:
import numpy as np
A,B,C,K=map(int,input().split())
total=np.array([0]*(A+B+C))
total[0:A]=1

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A,B,C,K= map(int, input().split())
Z = [1,]*A + [0,]*B+[-1,]*C
ans = 0
for i in Z[0:K]:
    ans += i
print(ans)

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())
 
if A >= K:
  print(str(A))
else:
  if A + B == K:
    print(str(A))
  elif A + B < K:
    num = A - (K - A - B)
    print(str(num))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

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

def take_card(a,b,c,k,s=0):
  if k<=0:
    return s
  else:
    if a > 0:
      return take_card(a-1,b,c,k-1,s+1)
    elif b > 0:
      return take_card(a,b-1,c,k-1,s)
    else:
      return take_card(a,b,c-1,k-1,s-1)
    
print(take_card(A,B,C,K))

Submission status: Runtime Error

Solution code:
a,b,c,k = [int(i) for i in input().split()]
if k<=a:
  print(k)
else if k<=a+b and k>a:
  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:
    vis = [1]*a
elif a+b > k:
    vis=[1]*a+[0]*b
else:
    vis=[1]*a+[0]*b+[-1]*c
    
s = 0

sum(vis[0:k])
    
print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main(a,b,c,k):
    res = 0
    if k < a:
        res = k
    elif a <= k < a+b:
        res = a
    elif a+b <= k:
        res = a - (k - (a + b))
    return res

a,b,c,k = mi()
print(main(a,b,c,k))

Submission status: Runtime Error

Solution code:
def resolve():
    import sys

    input = lambda: sys.stdin.readline().rstrip()

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

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

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

resolve()

Submission status: Runtime Error

Solution code:
a, b, c, k = map(int, input().split())
list1 = [1] * a
list0 = [0] * b
list_m1 = [-1] * c

list1.extend(list0)
list1.extend(list_m1)

list1.sort(reverse=True)

ans = 0
for i in range(k):
    ans += list1[i]

print(ans)

Submission status: Runtime Error

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

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

ans = 0

AB = A + B

if AB > K:
  print(A)
else:
  print(A + (K - AB) * -1)

Submission status: Runtime Error

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


def solve(a, b, c, k):
    all_list = [1] * a + [0] * b + [-1] * c
    return sum(all_list[0:k])


def main():
    a, b, c, k = input_from_console()
    print(solve(a, b, c, k))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Runtime Error

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

if K<=A:
    ans=K
elif k<=A+B:
    ans=A
else:
    ans=2*A-K

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,k = [int(i) for i in input().split()]
if k<=a:
  print(k)
else if a<k<=a+b:
  print(a)
else:
  print(a-(k-a-b))

Submission status: Runtime Error

Solution code:
def resolve():
    import sys

    input = lambda: sys.stdin.readline().rstrip()

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

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

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

resolve()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:


import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# 一行に文字列が一個 * n行
s_lis=[readline().rstrip().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換
# 一行に文字列が一個 * n行で文字列をアルファベット順に変換
s_lis=["".join(sorted(readline().rstrip().decode())) for _ in range(n)]
# 一行に文字列が複数個 * n行
s_lis=[readline().rstrip().split().decode() for _ in range(n)] # .decodeはバイト列から文字列へ変換

# 一行に数値が一個 * n行
s_lis=[int(readline().rstrip()) for _ in range(n)] 
# 一行に数値が複数個 * n行
s_lis=[int(readline().rstrip().split()) for _ in range(n)]

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

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

if k<=a:
    print(k)

elif: k<=a+b:
    print(a)

else:
    print(a+b-c)

Submission status: Runtime Error

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

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

ans = s[:k]

print(sum(ans))

Submission status: Runtime Error

Solution code:
a,b,c,k=map(int,input().split())
vis=[1]*a + [0]*b + [-1]*c
s = 0

sum(vis[0:k])
    
print(s)

Submission status: Runtime Error

Solution code:
import heapq
a,b,c,k = map(int,input().split())
li = [1]*a + [0]*b + [-1]*c
print(sum(heapq.nlargest(k,li)))

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
A, B , C, K = map(int,input().split())
al = [1]* A
bl = [0] * B
cl = [-1]* C
l = al + bl + cl

ans = sum(l[:K])
print(ans)

Submission status: Runtime Error

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

a = [1] * A
b = [0] * B
c = [-1] * C

abc = a+ b +c

k = sum(abc[0:K])

print(k)

Submission status: Runtime Error

Solution code:
def resolve():
    import sys

    input = lambda: sys.stdin.readline().rstrip()

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

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

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

resolve()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,k=list(map(int,input().split()))
A=[1]*a
B=[0]*b
C=[-1]*c
s=A+B+C
ans=0
for i in range(k):
  ans+=s[i]
print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, C, K = [int(x) for x in input().strip().split()]
    if K <= A + B:
        print(min(K, A))
    else:
        print(A - (K - A - B)))
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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




cards = [1]*a + [0]*b + [-1]*c
res = 0
for i,card in enumerate(cards):
    if i == k: break
    else:res += card

print(res)

Submission status: Runtime Error

Solution code:
a,b,c,k=map(int,input().split())
vis=[1]*a + [0]*b + [-1]*c
s = 0

for i in vis[0:k]:
    s += i
    
print(s)

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

ans = []

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

print(sum(ans[:min(k, a+b+c)]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
a, b, c, k = map(int, input().split())
L = [1]*a+[0]*b+[-1]*c
cnt = 0
for i in range(k):
    cnt += L[i]
print(cnt)

Submission status: Runtime Error

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

print(sum(point[:K]))

Submission status: Runtime Error

Solution code:
a, b, c, k = map(int, input().split())
s = min(c, k)
k -= s
if k == 0:
	print(s)
else:
	d = min(k, b)
	k -= d:
	if k == 0:
		print(s)
	else:
		f = min(k, a)
		s -= f
		print(s)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

ll a,b,c,k;

int main(){
    cin >> a >> b >> c >> k;
    if(a >= k)
    {
        cout << k << endl;
    }
    else
    {
        if(a+b>=k)
        {
            cout << a << endl;
        }
        else
        {
            cout << (a-(k-(a+b))) << endl;
        }
        
    }
    
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

A,B,C,K = map(int,sys.stdin.readline().split())

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

print(sum(ALL[:K]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

J = sum(L[:K])

print(J)

Submission status: Runtime Error

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

ti = [1] * a
[ti.append(0) for _ in range(b)]
[ti.append(-1) for _ in range(c)]

res = 0
for i in range(k):
    res += ti[i]
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = []

ans += [1] * a
ans += [0] * a
ans += [-1] * a

print(sum(ans[:min(k, a+b+c)]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

s = 0
s += min(a, d)
if min(a, d) == d:
  print(s)
elif min(a+b, d) == d
  print(a)
else:
  d -= a + b
  print(a-min(c, d))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#b
a,b,c,k=map(int, input().split())
test = []
test += [1]*a
test += [0]*b
test += [-1]*c
print(sum(test[0:k]))

Submission status: Runtime Error

Solution code:
import math
sys.setrecursionlimit(10**9)

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

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

if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
# S = input()
# N = int(input())
# A, B = map(int, input().split(' '))
# A = list(map(int, input().split(' ')))

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

card = []
a = [1]*A
b = [0]*B
c = [-1]*C

card.extend(a)
card.extend(b)
card.extend(c)


card = sorted(card, reverse=True)

print(sum(card[:K]))

Submission status: Runtime Error

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

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

ans = 0

for i in range(K):
  ans += L[i]
  
print(ans)

Submission status: Runtime Error

Solution code:
2 1 1 3

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

sum = A + B + C

count = 0
for i in range(K):
    count += sum[i]

print(count)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,k = map(int, input().split())
A=[1]*a
B=[0]*b
C=[-1]*c
L=A+B+C
print(sum(L[:k]))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
A,B,C,K=map(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:
import sys
import os

def file_input():
    f = open('/input.txt', 'r')
    sys.stdin = f

def main():
    # file_input()
    # int(input())
    A,B,C,K=int(map(int, input().split()))

    sum=0
    for i in K:
        if A!=0:
            A-=1
            sum+=1
        elif B!=0:
            B-=1
        elif C!=0:
            C-=1
            sum-=1
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

if (A <= K):
    print(K)
elif (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()))
lis=[1]*a+[0]*b+[-1]*c
max=0
for i in range(k):
    max+=lis[i]
print(max)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

a,b,c,d = map(int,stdin.readline().rstrip().split())

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

print(sum(li[:d]))

Submission status: Runtime Error

Solution code:
def ZZ(): return list(map(int, input().split()))
def Z(): return int(input())

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