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

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

print(ans167(A,B,C,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 = map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, K = list(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 k <= a:
  print(k)
elif a < k <= a + b:
  print(a)
else:
  print(a - (k - a - b))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
a,b,c,k =list(map(int,readline().rstrip().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:
a,b,c,k = map(int,input().split())
ans=0
if a>=k:
    ans=ｋ
else:
    k-=a
    if b>=k:
        ans=a
    else:
        k-=b
        ans=a-k
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

j1 = A - K
j2 = A + B - K
if j2 >0: # K < A + B
    if j1 < 0: #A > K
        print(A)
    else:
        print(K)
else:
    print(A + j2)

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())
# 1:A枚, 0:B枚, -1:C枚, K枚を選ぶ
A = min(A, K)
B = min(K - A, B)
C = min(K - A - B, C)
assert A + B + C >= K
#print(A, B, C)
print(A - C)

Submission status: Accepted

Solution code:
if __name__ == '__main__':

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

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

    print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

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 k <= a :
    print(k)
else :
    m = min(k,a)
    k -= a

    if k <= b :
        print(a)
    else :
        n = min(k,b)
        k -= b
        l = k
        print(1*m+(-1)*l)

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

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')



def main():
	a,b,c,k=MI()
	ans=min(a,k)
	ans-=max(k-a-b,0)
	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)
elif A + B + C >= K:
    print(A + (-1) *(K - A - B))
else:
    print(A - B)

Submission status: Accepted

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

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 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(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
if a<=k:
  ans += a
  k -=a
else:
  print(k)
  exit()

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

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

Submission status: Accepted

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

ans = 0
if K >= A:
    ans += A
    K -= A
    if K >= B:
        K -= B
        ans -= K
else:
    ans += 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:
cards=input()
new=cards.split()
a=int(new[0])
b=int(new[1])
c=int(new[2])
k=int(new[3])
if a>k:
    print(k)
else:
    if a+b>k:
        print(a)
    else:
        sum=a+(k-(a+b))*(-1)
        print(sum)

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

Submission status: Accepted

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

    result = A if K >= A else K
    K -= A
    if K <= 0:
        print(result)
        return

    K -= B
    if K <= 0:
        print(result)
        return

    result -= K
    print(result)

main()

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

result = min(a, k)
k -= a
if k > 0:
  k -= b

if k > 0:
  result -= min(c, k)
print(result)

Submission status: Accepted

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

s = []
x = 0

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

Submission status: Accepted

Solution code:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

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

k -= b

if k>0:
    cnt -= k

print(cnt)

Submission status: Accepted

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

max_val = 0
if k <= a:
    max_val += k
else:
    max_val += a
    k -= a
    if k <= b:
        pass
        # break
    else:
        k -= b
        max_val -= k

print(max_val)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

point = 0

if A <= K:
    point += A
    K -= A
else:
    point += K
    K = 0

if B <= K:
    K -= B
else:
    K = 0

point -= K

print(point)

Submission status: Accepted

Solution code:
#ABC167B
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 = list(map(int, input().split()))

ans = 0
if A > K:
  print(K)
elif A == K:
  print(A)
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())
R=A+B
if K<A:
    print(K)
elif K<=R:
    print(A)
else:
    T=K-R
    print(A-T)

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 = list(map(int, input().split()))
count = 0
if a >= k:
  count += min(a, k)
elif a+b >= k:
  count += a
else:
  count += (a-(k-a-b))
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if k<=a:
    ans=k
elif a<k<=b:
    ans=a
else :
    ans=a-(k-a-b)
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:
A,B,C,K = map(int, input().split())
sum = 0
x = K - A
if x > 0:
	sum += A
else:
	sum += K
x = x - B
if x > 0 :
	sum -= x
print(sum)

Submission status: Accepted

Solution code:
[A, B, C, K] = map(int, list(input().split(' ')))
left = K
ans = 0
# A
left = K - A
if(left >= 0):
    ans += A
else:
    ans += K
# B .. do nothing as diff would be 0
left = left - B
# C .. no need to subtract the left anymore
if(left > 0):
    ans -= left

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 167 B
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())

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())
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)
  exit()
  
temp = K - A

if B >= temp:
  print(A)
  exit()
  
temp = temp - B

print(A - temp)

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 = [int(x) for x in input().split()]
ans = 0
if k <= a:
  ans += k
elif k <= a + b:
  ans += a
else:
  ans += a - (k - a - b)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

a,b,c,k = map(int,input().split())
ans = min(a,k)
k -= ans
if k == 0:
    print(ans)
    exit(0)
k -= min(b,k)
if k == 0:
    print(ans)
    exit(0)
ans -= min(c,k)
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:
a, b, c, k = map(int, input().split())
print(min(a, k) - max(0, k-a-b))

Submission status: Accepted

Solution code:

def main():
    a, b, c, k = map(int, input().split(" "))
    ans = 0
    ans += min(a,k)
    k = max(k-a-b,0)
    ans -= k
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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


if k - a <= 0:
    print(k)
elif k - a > 0 and k - a - b <= 0:
    print(a)
else:
    s = k - a - b
    print(a - s)

Submission status: Accepted

Solution code:
l = input().split()
n1 = int(l[0])
n0 = int(l[1])
n = int(l[2])
k = int(l[3])

ans = 0

if k >= n1:
    ans += n1

else:
    ans += k

k -= n1

k -= n0

if k > 0:
    ans -= k

print(ans)

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

easyLinearProgramming()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(A, B, C, K):
    """
    a = [1 for _ in range(A)]
    b = [0 for _ in range(B)]
    c = [-1 for _ in range(C)]
    k = a + b + c
    ans = sum(k[:K])
    """
    if K <= A:
        return K
    if A <= K <= A+B:
        return A
    else:
        return A - (K-A-B)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0

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())
ans = 0
rem = K
if A >= K:
  ans = K
else:
  ans += A
  rem -= A
  if B > rem:
    ans += 0
  else:
    rem -= B
    ans -= rem
print(ans)

Submission status: Accepted

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

cnt=0

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

Submission status: Accepted

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

for numberOfCards, point in [(A, 1), (B, 0), (C, -1)]:
  if K >= numberOfCards:
    K -= numberOfCards
    ret += numberOfCards * point
  else:
    ret += K * point
    break
    
print(ret)

Submission status: Accepted

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

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




main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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 a + b >= k:
  print(a)

else:
  d = k - (a + b)
  print(a - d)

Submission status: Accepted

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

s = 0
while K:
    if A and K:
        if K >= A:
            K -= A
            s += A
            A -= A
        else:
            s += K
            K -= K
    if B and K:
        if K >= B:
            K -= B
        else:
            K -= K
    
    if C and K:
        if K >= C:
            K -= C
            s -= C
            C -= C
        else:
            s -= K
            K -= K

        
print(s)

Submission status: Accepted

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

def solve(A: int, B: int, C: int, K: int):
    if A >= K:
        return K
    K -= A
    if B >= K:
        return A
    K -= B
    return A - K


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
ans=0
if(a>=k):
    ans+=k
  #print(k)
elif(a<k):
    ans+=a
    if(k-a<=b):
        ans+=(k-a)*0
    elif(k-a>b):
        ans+=b*0
        ans-=k-a-b
    #print(ans)
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())
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:
def main():
    abck = [int(_x) for _x in input().split()]
    a = abck[0]
    b = abck[1]
    c = abck[2]
    k = abck[3]

    kk = k

    total = 0
    if kk >= a:
        kk = kk - a
        total += a
    else:
        print(kk)
        return

    if kk >= b:
        kk = kk - b
    else:
        print(total)
        return

    total = total - kk
    print(total)


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, K = input().split()
IA = int(A)
IB = int(B)
IC = int(C)
IK = int(K)
ALL = IA + IB + IC
cn = 0

if IA <= IK:
    cn = cn + IA
    D = IK - IA
    if IB <= D:
        E = D - IB
        cn = cn - E
        print(cn)
    else:
        print(cn)
else:
    print(IK)

Submission status: Accepted

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

ans = 0

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

ans += 0
K = max(K - B, 0)

ans -= K

print(ans)

Submission status: Accepted

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

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
a,b,c,k=[int(i) for i in 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
if k>a:
    ans+=a
    k-=a
    if k>=b:
        k-=b
        if k>=c:
            ans-=c
            print(ans)
        else:
            ans-=k
            print(ans)
else:
    ans+=k
    print(ans)

Submission status: Accepted

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

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

print(m)

Submission status: Accepted

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

koa = 0
if A<K:
  koa = A
else :
  koa = K
kob = 0
if B<K-koa:
  kob = B
else :
  kob = K-koa
#print (koa)
#print (kob)
sum = koa+0*kob+(K-(koa+kob))*-1
print (sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0
if A > K:
  ans += 1*K
else:
  ans += 1*A
  K = K - A
  if B > K: 
    ans += 0*K
  else:
    ans += 0*B
    K = K - B
    if C > K:
      ans += -1*K
    else:
      ans += -1*C

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
    ans = k
    k = 0
else:
    k -= a
    ans = a
k -= b
if k > 0:
    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(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*2 - k + 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:
#B
A, B, C, K=map(int, input().split())
if K <= A:
    ans = K
elif K <= A + B:
    ans = A
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(A + (-1 * (K - A - B)))

Submission status: Accepted

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

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

k -= min(b,k)

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(Ans)

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

Submission status: Accepted

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

if A<=K:
    b=A

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import exit

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

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:
r=input().split()
A=int(r[0])
B=int(r[1])
C=int(r[2])
K=int(r[3])
if K<=A:
    print(K)
elif K<=A+B:
    print(A)
else:
    print(2*A-K+B)

Submission status: Accepted

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

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

Submission status: Accepted

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

point = 0 

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin,stdout
one,zero,neg1,k=list(map(int,stdin.readline().split()))
o1=o0=o3=0
o1=min(k,one)
left=k-o1
o2=min(zero,left)
left-=o2
o3=max(0,min(left,neg1))
print(o1-o3)

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

Submission status: Accepted

Solution code:
a, b, c, k = (int(i) for i in input().split())
res = 1 * min(a, k) + 0 * min(b, max(0, k - a)) + -1 * min(c, max(0, k - a - b))
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)
else:
    print(A-(K-A-B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, k = [int(x) for x in input().split()]
print(min(2*a + b-k, a, 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(2*A - K + B)