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:
Num = list(map(int,input().split()))
A = Num[0]
B = Num[1]
C = Num[2]
K = Num[3]

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

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:
#python 3.7.1

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

k=d

if(a-k>0):

  print(k)

else:

  k=d-a

  if(b-k>0):

    print(a)

    

  else:

    k=d-a-b

    print(a-k)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

sum = xa * (1) + xb * (0) + xc * (-1)
print(sum)

Submission status: Accepted

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

cards = 0
ans = 0

if A >= K:
    ans = K
else:
    ans += A
    cards += A
    if cards + B >= K:
        pass
    else:
        cards += B
        ans +=  -1 * (K - cards)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
abck = input().split(" ")
a = int(abck[0])
b = int(abck[1])
k = int(abck[3])

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

Submission status: Accepted

Solution code:
abck = [int(s) for s in input().split()]
a, b, c, k = abck[0], abck[1], abck[2], abck[3]
if k <= a+b:
    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(1*K)

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

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
p = min(a, k)
s = p
k -= p
 
q = min(b, k)
k -= q
s -= k
 
r = min(c, k)
k -= r
s -= k
print(s)

Submission status: Accepted

Solution code:
def test():
    A, B, C, K = map(int, input().split())
    A_K_MIN = min(A, K)
    ans = A_K_MIN
    K -= A_K_MIN

    B_K_MIN = min(B, K)
    K -= B_K_MIN

    ans -= K
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Accepted

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

if a>=k:
	print(k)
else:
	if b >= k-a:
		print(a)
	else:
		if c >= k-a-b:
			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(int, input().split())

ans = 0
mn = min(A,K)
K -= mn
ans += mn

mn = min(B,K)
K -= mn

mn = min(C,K)
K -= mn
ans -= mn
print(ans)

Submission status: Accepted

Solution code:
#Solver:Rute
a,b,c,k = map(int,input().split())
if 0<=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 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())
list1 = [a,b,c]
ans=0

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

print("{}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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
ans = 1*xa + 0*xb + (-1)*xc
print(ans)

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
def main():
    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)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

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:
    a = min(C, K-A-B)
    ans = A- a
    print(ans)

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

Submission status: Accepted

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

A, B, C, K=map(int, input().split())
if A>K:
    print("{}".format(K))
else:
    if A+B>=K:
        print("{}".format(A))
    else:
        print("{}".format(A-(K-A-B)))

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:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, k = map(int, input().split())
ans = 0
if a <= k:
    ans += a*1
if a > k:
    ans += k*1
    print(ans)
    exit()
if b <= (k-a):
    ans += b*0
if b > (k-a):
    ans += 0*(k-a)
    print(ans)
    exit()
if c <= (k-a-b):
    ans += c*(-1)
    print(ans)

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

Submission status: Accepted

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

count = 0

count = min(A, K)
max = count
K -= count
#print(K)
count = min(B, K)
K -= count
#print(K)
max += K * (-1)
print (max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

ans = 0
tmp = k
if a < k:
    ans += a
    tmp -= a
else:
    ans += k
    print(ans)
    sys.exit()

if b < tmp:
    tmp -= b
else:
    print(ans)
    sys.exit()

if c < tmp:
    ans -= c
else:
    ans -= tmp
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if k < a:
	print(k)

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

elif a + b < k <= a + b + c:
	print(a - d)

Submission status: Accepted

Solution code:
A,B,C,K = input().split()
a = int(A)
b = int(B)
c = int(C)
k = int(K)

B_number = 0
C_number = 0

A_number = min(a,k)
k1 = k - a
if k1 > 0:
    B_number = min(b,k1)
    k2 = k1 - b
    if k2 > 0:
        C_number = min(c,k2)

print(A_number-C_number)

Submission status: Accepted

Solution code:
inp = input()
inp = inp.split()
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
k = int(inp[3])
if k <= a:
    print(k)
else:
    sum = a
    k = k - a
    if k <= b:
        print(sum)
    else:
        k = k - b
        sum = sum - k
        print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getls():
    return [ipt for ipt in input().split()]
def getlsi():
    return [int(ipt) for ipt in input().split()]

[a,b,c,k] = getlsi()
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) <= 0:
  print(K)
else:
  if (K - A - B) <= 0:
    print(A)
  else:
    print(2*A - K + B)

Submission status: Accepted

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

t=0
for c,v in [[A,1],[B,0],[C,-1]]:
  if k>c:
    t+=c*v
    k-=c
  else:
    t+=k*v
    break

print(t)

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

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
res = xa - xc
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


plus, zero, minus, getNum = map(int, input().split())

ans = 0

if getNum <= plus:
    ans += getNum
    print(ans)
    quit()
else:
    ans += plus
    getNum -= plus

if getNum <= zero:
    print(ans)
    quit()
else:
    getNum -= zero

if getNum <= minus:
    ans -= getNum
else:
    ans -= minus
print(ans)

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())
print(min(a,k)-max(k-a-b,0))

Submission status: Accepted

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

score = 0

if K >= A:
  score += A
  K -= A
else:
  score += K
  print(score)
  exit()

if K >= B:
  K -= B
else:
  print(score)
  exit()

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

Submission status: Accepted

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



def b():
    a, b, c, k = map(int, input().split())
    xa = min(k, a)
    k1 = k - xa
    xb = min(k1, b)
    k2 = k1 - xb
    print(xa - k2)

# def c():

# def 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(-1 * ((k - a) - b) + a)
else:
    print(a)

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

Submission status: Accepted

Solution code:
t=list(map(int,input().split()))
l=[1,0,-1]
k=t[3]
s=0
i=0
while(k!=0):
  if(k>t[i]):
    s+=l[i]*t[i]
    k-=t[i]
  else:
    s+=l[i]*k
    k=0
  i+=1
print(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
ans += min(a, k)

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
import sys,math,random
#sys.setrecursionlimit(100000000)
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

a,b,c,k=invr()

ans=0
if k:
	ans+=min(a,k)
	k-=min(a,k)
if k:
	ans+=0*(min(b,k))
	k-=min(k,b)
if k:
	ans-=min(c,k)
	k-=c

print(ans)

Submission status: Accepted

Solution code:
a,b,c,x=map(int,input().split())
 
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())
if a>=k:
  print(k)
elif a<k<=a+b:
  print(a)
else:
  print(2*a+b-k)

Submission status: Accepted

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

if K<=A:
    print(K)

elif A<K and K<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:
    print(A-(K-A-B))

Submission status: Accepted

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

ans = 0
if k >= a:
    ans = a
    k -= a
else:
    print(k)
    exit()

if k >= b:
    k -= b
else:
    print(ans)
    exit()

if k >= c:
    ans -= c
    print(ans)
else:
    ans -= k
    print(ans)

Submission status: Accepted

Solution code:
#n=int(input())
a,b,c,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

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

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())
nList = [A,B,C]
pList = [1,0,-1]

ans = 0
for i in range(len(nList)):
  if nList[i] <= K:
    ans += nList[i]*pList[i]
    K -= nList[i]
  else:
    ans += K*pList[i]
    break
    
print(ans)

Submission status: Accepted

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

ka = min(a,k)
k -= ka
kb = min(b,k)
k -= kb
kc = min(c,k)
k -= kc

ans = ka - kc
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(A-(K-(A+B)))

Submission status: Accepted

Solution code:
A, B, C, K = [int(i) for i in 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))
else:
    print(A - C)

Submission status: Accepted

Solution code:
a,b,c,k=[int(i) for i 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:
arr = [int(x) for x in input().split(' ')]
a, b, c, k = arr
ans = 0
mn = min(a, k)
ans += mn
k-=mn
mn = min(b, k)
k-=mn
mn = min(c, k)
ans -= mn

print(ans)

Submission status: Accepted

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

if a >= k:
	print(k)
	sys.exit()

if a + b >= k:
	print(a)
	sys.exit()
else:
	sum = a - (k - a - b)
	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(2*a + b - k)

Submission status: Accepted

Solution code:
a, b, c, k = [int(x) for x in input().split()]
a_x = min(a, k)
k -= a_x
b_x = min(b, k)
k -= b_x
c_x = min(c, k)
ans = a_x - c_x
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

a, b, c, k = [int(x) for x in stdin.readline().rstrip().split()]

x = 0

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

print(x)

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

xa = min(A,K)
K1 = K -xa
if K1 == 0:
  print(K)
else:
	xb = min(B,K1)
	K2 = K1 -xb
	if K2 == 0:
  		print(A)
	else:
   		print(A-K2)

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

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()))
"""
for n in range(1):
    n = list(map(int,input().split()))
    L.append(n)
"""

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

Submission status: Accepted

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

ans = 0

ans += min(a, k)
k -= min(a,k)

ans += min(b, k) * 0
k -= min(b,k)

ans += min(c,k) * -1
k -= min(c,k)

print(ans)

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

Submission status: Accepted

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

ans = 0
n = min(A, K)
ans += n
K -= n

n = min(B, K)
K -= n

n = min(C, K)
ans -= n

print(ans)

Submission status: Accepted

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

res = 0

res += min(K, A)
K -= A

if K > 0:
    K -= B
if K > 0:
    res -= min(K, C)

print(res)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
l = [int(x) for x in input().split()]
A, B, C, K = l[0], l[1], l[2], l[3]
ans = 0
while K > 0:
    if A > 0:
        if A > K:
            ans += K
            K = 0
        else:
            ans += A
            K -= A
            A = 0
    elif B > 0:
        if B > K:
            K = 0
        else:
            K -= B
            B = 0
    else:
        ans -= K
        K = 0
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int,input().split()))
def inpm():
    return map(int,input().split())

a,b,c,k = inpm()

print(min(min(k,a),2*a+b-k))

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
p = 0
xa = min(l[0], l[3])
l[3] -= xa
xb = min(l[1], l[3])
l[3] -= xb
xc = l[3]
p = xa - xc
print(p)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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

    result = min(A, K)
    K -= (A + B)
    result -= max(0, K)

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

class abc_167:
    
    def __init__(self):
        pass
    
    def A(self):
        S=input()
        T=input()
        if S==T[:len(S)]:print("Yes")
        else:print("No")
    
    def B(self):
        ABCK=list(map(int,input().split()))
        sum_num=0
        
        if ABCK[3]<=ABCK[0]:sum_num=ABCK[3]
        elif ABCK[3]<=ABCK[0]+ABCK[1]:sum_num=ABCK[0]
        else:sum_num=ABCK[0]-(ABCK[3]-ABCK[0]-ABCK[1])
        
        print(sum_num)
            
    def C(self):
        pass
            
    def D(self):
        
        NK=list(map(int,input().split()))
        A=list(map(int,input().split()))
        stack=[]
        A_memo=[0]*(NK[0]+1)
        flag=False
        
        
        count=0
        stack.append(A[count])
        count+=1
        A_memo[1]=count
        
        max_data = NK[0]+1 if NK[0]<=NK[1] else NK[1]
        
        while(count<max_data):
            data=stack.pop()
            stack.append(A[data-1])
            count+=1
            
            if A_memo[A[data-1]]==0:
                A_memo[A[data-1]]=count
            else:
                loop_val=A[data-1]
                flag=True
                break
            
        #a=count-A[loop_val]
        #b=NK[1]-A[loop_val]
        #print(count-A[loop_val])
        #print(NK[1]-A[loop_val])
        #print((b%a)+A[loop_val]-1)
        ans_stack=[]
        ans_stack.append(A[0])
            
        if flag==True:
            ans=((NK[1]-A[loop_val])%(count-A[loop_val]))+(A[loop_val]-1)
            for i in range(ans):
                ans_data=ans_stack.pop()
                ans_stack.append(A[ans_data-1])
            end=ans_stack.pop()
            print(end)
        else:
            ans=count
            for i in range(ans):
                ans_data=ans_stack.pop()
                ans_stack.append(A[ans_data-1])
            end=ans_stack.pop()
            print(end)
            
            
           
            
    
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_167()
    obj.B()

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

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

if K<=A:
  print(K*1)
elif A<K<=B:
  print(A*1)
else:
  print(A*1+(-1*(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 = k
ans = xa - xc

print(ans)

Submission status: Accepted

Solution code:
z=input().split(' ')

a=int(z[0])
b=int(z[1])
c=int(z[2])
d=int(z[3])

count=0
if d-a>0:
    count+=a
else:
    count=d

x=d-a
#print(count)
#print(x)

if x-b>0:
    y=x-b
    #print(y)
    if y-c>0:
        count-=c
    else:
        count-=y
else:
    pass

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

    ans = 0
    used = min(k,a)
    ans += used * 1
    k -= used
    used = min(k, b)
    k -= used
    ans += k*(-1)
    print(ans)


if __name__ == "__main__":
    resolve()

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 = list(map(int, input().split()))
D = 0
if K <= A:
    print(K)
else:
    D += A
    K -= A
    if K > B:
        K -= B
        if K >= C:
            D -= C
            print(D)
        else:
            D -= K
            print(D)
    else:
        print(D)

Submission status: Accepted

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

xa = min(A, K)
K = K - xa
xb = min(B, K)
K = K - xb
xc = min(C, K)
total = xa*1 + xb*0 + xc*-1
print(total)

Submission status: Accepted

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

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:
# coding: utf-8
# Your code here!

def main():
    number_of_A,number_of_B,number_of_C,nubmer_of_take_cards = map(int,input().split())
  
    result = 0
    if number_of_A >= nubmer_of_take_cards:
        result = nubmer_of_take_cards
    else:
        result += number_of_A
        nubmer_of_take_cards = nubmer_of_take_cards - number_of_A
        
        if number_of_B < nubmer_of_take_cards:
            nubmer_of_take_cards = nubmer_of_take_cards - number_of_B
            result = result - nubmer_of_take_cards
    
    print(result)
            
if __name__ == "__main__":
    main()

Submission status: Accepted

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

if 1 <= 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: Accepted

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


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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:
        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 = k
ans = xa - xc
print(ans)

Submission status: Accepted

Solution code:
def main():
    inp = input()
    data = inp.split(" ")
    data = [int(i) for i in data]
    a = data[0]
    b = data[1]
    c = data[2]
    k = data[3]

    if a > k:
        print(k)
        return

    r = k - a
    score = a

    if b > r:
        print(score)
        return

    r = r - b

    if c > r:
        score -= r
    else:
        score -= c

    print(score)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

# Aの枚数
X_A = min(A, K)
# Aを選んだ後の枚数
K_A = K - X_A

# Bの枚数
X_B = min(B, K_A)
K_B = K_A - X_B

# Cの枚数
X_C = min(C, K_B)

print(X_A - X_C)

Submission status: Accepted

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

ans = 0
ans += min(A, K)
K -= min(A, K)
K -= min(B, K)
ans -= min(C, K)

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=min(c,k)
print(xa-xc)

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:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

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