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: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

nokori = K - A - B

wa = 0
while True:
    if A >= K:
        wa += K
        break
    else:
        wa += A
    if C >= nokori:
        wa -= nokori
        break
    else:
        wa -= C
        break

print(wa)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


A, B, C, K = MI()
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(A - (K - (A + B)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,K= map(int, input().split())
x=K-a
y=x-b
if a>=K:
    i=1*K
    print(i)
if a<K:
    i=1*a
    if y<=0:
        print(i)
    if y>0:
        i=i-y
        print(i)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, K = [int(i) for i in input().split()]
if A + B >= K:
    if K < A:
        print(K)
    else:
        print(A)
else:
    tmp = K - A - B
    print(A - tmp)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

A,B,C,K=(int(x) for x in input().rstrip('\n').split())
res = A
if A<K:
  K-=A
  if B<K:
    K -= B
    res -= K
else:
  res =K
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

cnt = k - a
if cnt >= 0:
  ans += a
  cnt = cnt - b
else:
  ans += k
  print(ans)
  sys.exit()
if cnt >= 0:
  cnt = cnt - c
  pass
else:
  print(ans)
  sys.exit()
if cnt >= 0:
  ans -= c
  print(ans)
else:
  ans -= k - (a + b)
  print(ans)

Submission status: Accepted

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

mx  = 0
rk = K

if rk > 0:
  mx += 1*min(A,rk)
  rk = rk - A
  
if rk >0:
  rk = rk - B
  
if rk>0:
  mx += -1*min(C,rk)
  
print(mx)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


result = 0
if a >= k:
    result = k
elif a < k and a+b > k:
    result = a
else:
    result = a - (k-a-b)

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t=list(map(int,input().split(" ")))
a=t[0]
b=t[1]
c=t[2]
k=t[3]
flag=0
sum = 0
if(a>k):
    sum=sum+k
    flag=1
    k=0
else:
    k=k-a
    sum=sum+a
    flag=1
    # print(k,sum)
if(flag==1):
    if(k!=0):
        if(b>k):
            k=0
            flag=2
        else:
            k=k-b
            flag=2
if(flag==2):
    if(k!=0):
        if(c>k):
            sum=sum-k
        else:
            k=k-c
            sum=sum-c
print(sum)

Submission status: Accepted

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: Accepted

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: Accepted

Solution code:
def main():
    import sys
    A,B,C,K=list(map(int,sys.stdin.readline().split()))
    o=0
    if K>=A:
        K-=A
        o+=A
    else:
        print(K)
        return

    if K>=B:
        K-=B
    else:
        print(o)
        return
    
    print(o-K)

main()

Submission status: Accepted

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

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

j = k
ot = 0

if a:
    if a < k:
        ot += a
        j -= a
    elif a >= k:
        ot += k 
        j = 0
    

if b and j != 0:
    if b >= j:
        j = 0
    elif b < j:
        j -= b

if c and j != 0:
    if c >= j:
        ot -= j
        j = 0
    elif j > c:
        ot -= c
        j -= c

print(ot)

Submission status: Accepted

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

an = a if a <= k else k
ans = an
k = k - an
if k > 0:
  bn = b if b <= k else k
  k = k - bn
if k > 0:
  cn = k
  ans = ans - cn
print(ans)

Submission status: Accepted

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

su = 0
card = 0

if k >= a:
    su = a
    card = k-a
    if card > b:
        card = card - b
        su = su - card
elif k < a:
    su = k

print(str(su))

Submission status: Accepted

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

suma = 0


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

Submission status: Accepted

Solution code:
plus, zero, minus, selectMax = map(int, input().split())


if selectMax -plus <= 0:
    print(selectMax)

elif selectMax -plus-zero <= 0:
    print(plus)
    
else:
    print(plus-(selectMax -plus-zero))

Submission status: Accepted

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: Accepted

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: Accepted

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

Submission status: Accepted

Solution code:
inp = input().split(" ")

A = int(inp[0]); B = int(inp[1]); C = int(inp[2]); K = int(inp[3]);
point = 0

if (A > 0) & (K > 0):
  itr = min([A,K])
  point += (itr * 1)
  K -= itr

if (B > 0) & (K >0):
  itr = min([B,K])
  point += (itr * 0)
  K -= itr
  
if (C > 0) & (K >0):
  itr = min([C,K])
  point += (itr * -1)
  K -= itr

print(point)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:


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

print(min(a,k) - max(k-a-b,0))

Submission status: Accepted

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

if K <= A:
    print(K)
else:
    cards  = [A, B, C]
    points = [1, 0, -1]
    val = 0
    rem = K
    for i in range(3):
        rem -= cards[i]
        if rem <= 0:
            val += (cards[i] + rem) * points[i]
            break
        else:
            val += cards[i] * points[i]
    print(val)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if a>= k:
    print(k)
    exit()
else:
    k = k-a
    cnt +=a
if k >=b:
    k = k-b
if c >=k:
    cnt -=k
else:
    cnt -=c
print(cnt)

Submission status: Accepted

Solution code:
A, B, C, K = [int(_) for _ in input().split()]
print(min(K, A) - max(0, (K - A - B)))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
k = int(s[3])
total = 0

    
    
if a > 0 and k > 0 :
    
    if k > a :
        total = a
    elif k < a :
        total = k
    elif k == a :
        total = a
    k = k - a
        
# print(a)
        
if b > 0 and k > 0 :
    k = k - b

# print(k)
if c > 0  and k > 0 :
    # print(k)
    if k > c :
        total = total - c
    elif k < c :
        total = total - k
    elif k == c :
        total = total - c


print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K=(int(x) for x in input().split())
num=0
if A >= K:
  num=K
elif K-A <= B:
  num=K-B
else:
  num=A-(K-(A+B))

print(num)

Submission status: Accepted

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

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: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

A,B,C,K = LI()

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

Submission status: Accepted

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: Accepted

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

kt=k
sum=0

for i,card in enumerate([a,b,c]):
    if kt == 0:
        break
    if (kt - card) >= 0:
        if i == 0:
            sum+=card*1
        elif i == 1:
            sum+=card*0
        else:
            sum+=card*-1
        kt -= card            
    else:
        if i == 0:
            sum+=kt*1
        elif i == 1:
            sum+=kt*0
        else:
            sum+=kt*-1
        kt = 0

print(sum)

Submission status: Accepted

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-(K-A-B))

Submission status: Accepted

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

Submission status: Accepted

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

if s[3] == "0" :
    print(0)
    
elif ( int(s[0]) >= int(s[3]) ) :
    print(s[3])

elif ((int(s[3]) - int(s[0]) <= int(s[1]))):
    print(s[0])
elif int(s[3]) - int(s[0]) > int(s[1]) :
    print(int(s[0])- (int(s[3])-int(s[0])-int(s[1])))

Submission status: Accepted

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 a < 0:
    calc = int(input_list[3])
elif b <= 0 and a >=0:
  calc = int(input_list[0])
else:
  calc = int(input_list[0]) - b
print(calc)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = [int(i) for i in input().split()]
res = 0
if K <= A:
    res += K
    K = 0
elif K > A:
    res += A
    K -= A
K -= B
if K > 0:
    res -= K
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

cnt_a = 0
cnt_b = 0
cnt_c = 0

if (a > 0) & (a > k):
    cnt_a = k
    k = 0
else:
    cnt_a = a
    k = k - cnt_a

if (b > 0) & (b > k):
    cnt_b = k
    k = 0
else:
    cnt_b = b
    k = k - cnt_b

if c > 0:
    cnt_c = k

result = cnt_a * 1 + cnt_b * 0 + cnt_c * (-1)
print(result)

Submission status: Accepted

Solution code:
import sys

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

if k <= a:
    print(k)
    sys.exit()
k = k-a
if k <= b:
    print(a)
    sys.exit()
k = k-b
print(a - k)

Submission status: Accepted

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

score=0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,C,K = input().split(' ')
A = int(A) # 1
B = int(B) # 0
C = int(C) # -1
K = int(K)


# 1 x ?,  0 x ?,  -1 x ?
if (K <= A + B):
  if (A >= K):
    print(K)
  else:
    print(A)
else:
  print(A + ((K - (A + B)) * -1))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    A, B, C, K = mulinputs()
    # 出力
    if K < A:
        print(K)
        exit()
    if K <= A+B:
        print(A)
        exit()
    K -= (A+B)
    print(A-K)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)

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

A,B,C,K=acinput()


nA=min(K,A)
nB=min(K-nA,B)
nC=min(K-nA-nB,C)

print(nA-nC)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if K <= A:
    S = K
elif K <= A+B:
    S = A
else:
    S = A - (K-(A+B))

print(S)

Submission status: Accepted

Solution code:
L = list(map(int, input().split()))
n = [1, 0, -1]
maxres = 0

for i in range(3):
    if L[3] == 0:
        break
    maxres += L[i] * n[i]
    L[3] -= L[i]
    #print(L[3])
    if L[3] < 0:
        maxres -= abs(L[3]) * n[i]
        break
print(maxres)

Submission status: Accepted

Solution code:
a = input().rstrip().split(' ')
A,B,C,K = int(a[0]),int(a[1]),int(a[2]),int(a[3])
s = 0

if K - A <= 0:
    print(K)
else:
    K -= A
    if K - B <= 0:
        print(A)
    else:
        K -= B
        print(A-K)

Submission status: Accepted

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

ans = A
K -= A
if B >= K:
    print(ans)
    exit()
K -= B

if C >= K:
    print(ans - K)
else:
    print(ans - C)

Submission status: Accepted

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

if a>=k:
  ans=1*k
  
elif a+b>=k:
  ans=1*a

else:
  ans=a-(k-a-b)
      
print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
count = 0
if A == K:
    print(A)
    quit()
if K < A:
    print(K)
    quit()
D = K-A
print(A-(D-B))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0

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

print(sum)

Submission status: Accepted

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

big = 0
if A >= K:
    big = K
else:
    big = A
    K -= A
    # print(K)
    if B < K:
        K -= B
        # print(K)
        big -= K

print(big)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

def main():
    global K

    if A < K:
        ans = A
        K = K - A
    elif A == K:
        ans = K
        return ans
    else: # AのほうがKより多い
        ans = K
        return ans

    if B < K:
        K = K - B
    elif B == K:
        return ans
    else: # BのほうがKより多い
        return ans

    # マイナス
    return ans - K

result = main()

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if A <= K:
    ans += A*1
    K -= A
else:
    ans += K*1
    flg = False

if flg:
    if B <= K:
        ans += B*0
        K -= B
    else:
        ans += K*0
        flg = False

if flg:
    if C <= K:
        ans -= C*1
        K -= C
    else:
        ans -= K*1
        flg = False


print(ans)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
n = a[0]
m = a[1]
l = a[2]
k = a[3]

if 0 < k <= n:
    print(k)

elif n < k <= n + m:
    print(n)

elif n+m <= k < n+m+l:
    print(n -1*(k -n -m))

elif n+m+l <= k:
    print(n - l)
else:
    print(0)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split()) #A,B,C,Kの入力
total = 0

while K > 0:
    if A > 0:
        if K > A:
            total = total + A
            K = K - A
            A = 0;
        else:
            total = total + K
            K = 0
            A = A - K
    elif B > 0:
        if K > B:
            K = K - B
            B = 0;
        else:
            K = 0
            B = B - K
    elif C > 0:
        if K > C:
            total = total - C
            K = K - C
            C = 0;
        else:
            total = total - K
            K = 0
            C = C - K

print(total)

Submission status: Accepted

Solution code:
import sys

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

S = 0

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

if B >= K:
    K = 0
    print(S)
    sys.exit()
else:
    K = K - B

if C >= K:
    S = S + K * (-1)
    K = 0
    print(S)
    sys.exit()
else:
    S = S + C * 1
    print(S)

Submission status: Accepted

Solution code:
from sys import stdin


def get_result(data):
    A, B, C, K = data
    if (A + B) >= K:
        return K if A > K else A
    else:
        return A - (K-(A+B))


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Accepted

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

if k-a <= 0:
  count = k
elif k-a-b <= 0:
  count = a
else:
  count = 2*a + b - k

print(count)

Submission status: Accepted

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

left = k
sum = 0
cards = (a, b, c)

for i, card in enumerate(cards):
  if card <= left:
    sum += card * (1-i)
    left -= card
  elif left > 0:
    sum += left * (1-i)
    left = 0

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(A,B,C,K):
    card=K-A
    if card <= 0:
        return K
    card-=B
    if card <= 0:
        return A
    return A-card

if __name__ == "__main__":
    A,B,C,K=map(int,input().split())
    print(main(A,B,C,K))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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