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

Submission status: Accepted

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

print(min(A,K)-max(0,K-A-B))

Submission status: Accepted

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

Submission status: Accepted

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


if K-A <=0:
  ans = K

elif K-A-B<=0:
  ans = A

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

Submission status: Accepted

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

if A+B<K:
  print(A-(K-A-B))
else:
  print(min(A, K))

Submission status: Accepted

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

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

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

Submission status: Accepted

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 >= C and K >= 1:
	sum = sum - C
else:
	sum = sum - K

print(sum)

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())
r=min(A,K)
K-=r
A-=r
ans=r
K -= min(B,K)
r=min(K,C)
ans-=r
print(ans)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
xa = min(a,k)
k -= xa
xb = min(b,k)
k -= xb
xc = k
ans = xa -xc
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    A, B, C, K = list(map(int, input().split()))
    if A > K:
        print(K)
    else:
        if A + B > K:
            print(A)
        else:
            print(A - (K - A - B))
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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


xa = min(k,a)
xb = min(k-xa,b)
xc = k- xa - xb

print(xa - xc)

Submission status: Accepted

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

a = min(A, K)
K -= a
b = min(B, K)
K -= b
c = K

print(a-c)

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)*-1)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, k = map(int, read().split())
print(min(a, k) if a + b >= k else 2 * a + b - k)

Submission status: Accepted

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

print(min(K, A - max(0, K - A - B)))

Submission status: Accepted

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

if K-A-B>=0:
    c = min(abs(K-A-B), C)
else:
    c = 0

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
xa=min(a,k)
k-=xa
xb=min(b,k)
k-=xb
xc=k
ans=xa-xc
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

count = 0

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

print(count)

Submission status: Accepted

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

xa = min(a,k)
k1 = k-xa
xb = min(b,k1)
k2 = k1-xb
xc = k2

print(xa-xc)

Submission status: Accepted

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

if a>=d:
  print(d)
elif a+b>=d:
  print(a)
else:
  print(a-(d-(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 solve(a,b,c,k):
    ans =0 
    if(a>=k):
        return k
        
    ans+=a
    k-=a
    
    if(b>=k):
        return ans
    
    k-=b
    
    if(c>=k):
        return ans-k
        
    ans-=c
    return ans
    
a, b, c, k = map(int, input().split())

#chosing from a
#how much we choose a 
print(solve(a,b,c,k))

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:
def actual(a, b, c, k):
    x_a = min(a, k)

    k -= x_a

    x_b = min(b, k)
    k -= x_b

    x_c = k  # min(c, k)

    score = x_a - x_c

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
abcx = input().split(" ")
a = int(abcx[0])
b = int(abcx[1])
x = int(abcx[3])
if x <= a:
    print(x)
elif x <= a + b:
    print(a)
else:
    print(2 * a + b - x)

Submission status: Accepted

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

xa = min(a,k)
k -= xa
xb = min(b, k)
k -= xb
xc = k
print(xa-xc)

Submission status: Accepted

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

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

Submission status: Accepted

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

S = int()

if K >= A:
    S = S + A
    K = K - A

    if K >= B:
        K = K - B

        if K > 0:
            S = S - K
            print(S)
        else:
            print(S)

    else:
        print(S)

else:
    S = S + K
    print(S)

Submission status: Accepted

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

if A+B >= K:
    print(min(A,K))
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 K <= A+B:
    print(A)
else:
    print(A - (K-(A+B)))

Submission status: Accepted

Solution code:
(a, b, c, k) = list(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())

xa = min(A, K)
K -= xa
xb = min(B, K)
K -= xb
xc = min(C, K)
ans = xa-xc
print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
ans = 0
for i, x in enumerate([a, b, c]):
    t = min(k, x)
    ans += (1 - i) * t
    k -= t

print(ans)

Submission status: Accepted

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

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

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-B-A)*-1))

Submission status: Accepted

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

Submission status: Accepted

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

    ans = 0

    # A
    if A >= 1:
        if K >= A:
            ans = A
        else:
            ans = K

    # C
    tmp = K - A - B
    if tmp >= 1:
        ans -= tmp

    print(f'{ans}')

if __name__ == '__main__':
    main()

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())
ans = 0
cur = min(k,a)
ans = ans + cur
k = k - cur
k = max(0,k)
cur = min(k,b)
k = k - cur
k = max(0,k)
cur = min(k,c)
ans = ans - cur

print(ans)

Submission status: Accepted

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

d = k - a

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

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)

elif A + B < K:
    c = -1 * (K-(A+B))
    #print(c)
    #print(A)
    cc = A + c
    print(cc)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math

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

s=K
ans = 0

s-=min(A,K)
ans+=min(A,K)

if (s>0):
    s-=B
    if (s>0):
       ans -= s

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
if A>=K:
    print(K)
    exit()
if A+B>=K:
    print(A)
    exit()
K=K-(A+B)
print(A+(K*-1))
exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#B
i = input()
a = int(i.split()[0])
b = int(i.split()[1])
c = int(i.split()[2])
k = int(i.split()[3])

count = 0

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]
 
sys.setrecursionlimit(1000000)
mod = 1000000007
 
def solve():
    a,b,c,k = map(int,input().split())
    ans = 0
    if a+b >= k:
        print(min(k,a))
    else: 
        print(a-(k-a-b))
    return
 
#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#B
a,b,c,k = list(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())
ans = 0
if A<K:
    ans += A
    K -= A
else:
    print(K)
    K = 0
if not K:
    pass
elif B<K:
    K -= B
else:
    print(ans)
    K = 0
if not K:
    pass
else:
    print(ans-K)

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:
#!/usr/bin/env python3
a, b, c, k = map(int, input().split())
if a + b <= k:
    print(a - (k - (a + b)))
elif a <= k:
    print(a)
else:
    print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#code
A, B, C, K = map(int, input().split())
if A >= K:
    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 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 = list(map(int, input().split()))
if K < A:
    print(K)
elif K <= A+B:
    print(A)
else:
    K = K-A-B
    ans = A - K
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if a >= k:
    print(1*k)
else:
    n = k-a

    if n <= b:
        print(1*a)
    else:
        o = n-b
        print(a-o)

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, Y, Z, K = map(int, input().split())
if X >= K:
    print(K)
elif X+Y >= K:
    print(X)
elif X+Y+Z >= K:
    print(X-(K-X-Y))

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int,input().split())
# 1 2 3 4
card = K#4
# 取れるカードの数
result = 0
# 得点は0
if card < A: # 4 < 1 false
	print(card)
	# Aのカードを取るだけで済むパターン
else:
	card -= A # 4 - 1
	# print("カード残り",card)
	# Aのカードを取り切ってもまだとれるカードの数
	if card < B:
		print(A)
	else:
		card -= B # 3 - 2
		#print("カード残り", card)
		x = card * -1
		#print("X",x)
		print(A+x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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-c)
        else:
            print(a-(k-(a+b)))

Submission status: Accepted

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

if k <=a:
  counter =+ k
else:
  counter+= a
  remants -= a
  if remants >b:
    remants -= b
    counter-=remants






print(counter)

Submission status: Accepted

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

cnt = 0

if k >= a:
    k = k - a #3
    cnt = cnt + 1*a  #1

    if k >= b:
        k = k - b #1

        if k >= c:
            cnt = cnt + -1*c
            k = k - c

        else:
            cnt = cnt + -1*k
            k = k - k
    
    else:
        k = k - k

else:
    cnt = cnt + 1*k
    k = k - k
    
print(cnt)

Submission status: Accepted

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


def f(A, B, C, K) :
    
    sum = 0

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

    if K <= 0 :
       return sum

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

    if K <= 0 :
       return sum

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

    if K <= 0 :
       return sum


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

A = ABCK[0]
B = ABCK[1]
C = ABCK[2]
K = ABCK[3]

count = 0

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


print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

sum = 0

if (a+b) >= k:
    sum += min(a,k)
    print(sum)
else:
    sum = a * 1
    sum += -1 * (k-a-b)
    print(sum)

Submission status: Accepted

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

if i [0] >= i[3]:
	saidai=1*i[3]
else:
	saidai=1*i[0]-1*(i[3]-i[0]-i[1])
print (saidai)

Submission status: Accepted

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

sum = 0
a_3 = a[3]
a_0 = a[0]
a_1 = a[1]
a_2 = a[2]


if a_3 <= a_0:
    print (a_3)
    
elif a_3 > a_0 and a_3 <= (a_0 + a_1):
    print (a_0)
    
else:
    sum = a_0 - (a_3 - a_0 - a_1)
    print(sum)

Submission status: Accepted

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

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

a_times = 0
b_times = 0
c_times = 0

if a <= k:
    a_times = a
    # print('a_times = ', a_times)
    if a_times + b <= k:
        b_times = b
        # print('if - b_times = ', b_times)
    else:
        b_times = k - a_times
        # print('else - b_times = ', b_times)
    if a_times + b_times + c <= k:
        c_times = c
        # print('if - c_times = ', c_times)
    else:
        c_times = k - a_times - b_times
        # print('else - c_times = ', c_times)
else:
    a_times = k


print(a_times * 1 + b_times * 0 + c_times * -1)

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

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

Submission status: Accepted

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

if A >= K:
  print(K)
  exit()
else:
  K -= A
  if B >= K:
    print(A)
    exit()
  else:
    K -= B
    if K <= C:
      A -= 1*K
    
print(A)

Submission status: Accepted

Solution code:
from sys import stdin
A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if (A >= K):
    print(K)
else:
    if (B >= (K - A)):
        print(A)
    else:
        print(2*A + B - K)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

if K > A:
    ans = ans + A
    K = K - A
    if K > B:
        K = K - B
        ans = ans - K
        print(ans)
        sys.exit()
    else:
        print(ans)
        sys.exit()
else:
    print(K)
    sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(answer)

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())
Ts = 0
sA = K - A
if sA > 0:
    sB = sA - B
    if sB > 0:
        sC = sB - C
        if sC < 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
        elif sC == 0:
            Ts = ((K - sA) * 1) + ((sA - sB) * 0) + (sB * -1)
    elif sB == 0:
        Ts = ((K - sA) * 1) + (sB * 0)
    else:
        Ts = ((K - sA) * 1) + ((sA - sB) * 0)
elif sA == 0:
    Ts = A * 1
else:
    Ts = K * 1
print(Ts)

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

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

Submission status: Accepted

Solution code:
input = input().split(" ")
a, b, c = int(input[0]), int(input[1]), int(input[2])
k = int(input[3])
totalnum = 0
for nuum in range(4):
    if a>=k: #もしaの枚数がkを上回っていたら
        totalnum+=k
        k=0
        break
    elif a<k and a!=0: #もしaの枚数がkを下回っていたら
        totalnum+=a #totalnumをa分足して
        k-=a #kからaの枚数分引く
        a=0
    elif b>=k: #もしbの枚数がkを上回っていたら
        k=0
        break
    elif b<k and b!=0: #もしbの枚数がkを下回っていたら
        k-=b #bの枚数分だけkから引く。
        b=0
    elif c>=k: #もしcのところまで来たら
        totalnum-=k
        break
print(totalnum)

Submission status: Accepted

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

count=K
point=0

if A>count:
    point+=count
    count=0
else:
    point+=A
    count-=A

if B>count:
    point+=count*0
    count=0
else:
    point+=B*0
    count-=B

if C>count:
    point+=count*(-1)
    count=0
else:
    point+=C*(-1)
    count-=C

print(point)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ANS)

Submission status: Accepted

Solution code:
A,B,C,K = list(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:
nums = input().split(' ')
# values = []
# for i in range(int(nums[0])):
#     values.append(1)
# for i in range(int(nums[1])):
#     values.append(0)
# for i in range(int(nums[2])):
#     values.append(-1)

one_counts = int(nums[0])
zero_counts = int(nums[1])
mone_counts = int(nums[2])
top = int(nums[3])


if one_counts >= top:
    print(top)
else:
    if one_counts + zero_counts >= top:
        print(one_counts)
    else:
        print(one_counts - (top - (one_counts + zero_counts)))

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K = (int(x) for x in input().split())
s = 0
d = (2*(10**10))
while True:
    if A <= K:
        s += (1*A)
        K = K - A
        A = d
    elif A != d and A > K:
        s = 1*K
        break
    elif A == d and B <= K:
        s = s
        K = K - B
        B = d
    elif A == d and  B != d and B > K:
        pass
        break
    elif A == d and B == d and C <= K:
        s -= (1*C)
        C = d
        break
    elif A == d and B == d and C != d and C > K:
        s -= (1*K)
        break
print(s)

Submission status: Accepted

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


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

    ans = a
    num = a + b

    if k <= a:
        print(int(k))
        return
    elif num < k:
        ans -= k - num
    print(ans)


if __name__ == "__main__":
    main()

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 solve():
    num_one, num_zero, num_minus_one, num_select = map(int, input().split())
    if num_one == num_select:
        print(num_one)
        return
    if num_select < num_one:
        print(num_select)
        return

    if num_one + num_zero == num_select:
        print(num_one)
        return
    if num_select < num_one + num_zero:
        print(num_one)
        return

    if num_one + num_zero + num_minus_one < num_select:
        print(num_one - num_minus_one)
        return

    max_minus_one = num_select - (num_one + num_zero)
    if num_minus_one < max_minus_one:
        print(num_one - num_minus_one)
    else:
        print(num_one - max_minus_one)

solve()

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

Submission status: Accepted

Solution code:
def solve(a, b, c, k):
	sum = 0
	if a > 0:
		if a >= k:
			sum += k 
			print(sum)
			return None
		else:
			sum += a
			k -= a
	k -= b
	if k > 0:
		if c > k:
			sum -= k
			print(sum)
			return None
		else:
			sum -= c
			print(sum)
	else:
		print(sum)



a, b, c, d = [int(x) for x in input().split()]
solve(a, b, c, d)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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