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:
from numba import njit
 
@njit(cache=True)
def convolve(a, b):
    def poww(aa, bb, mm):
        ss = 1
        tt = aa
        while bb:
            if bb % 2:
                ss = ss * tt % mm
                bb -= 1
            tt = tt * tt % mm
            bb //= 2
        return ss
    def fft(n, p, g, w, invw, f):
        d = n // 2
        v = w
        while d >= 1:
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * v % p
            v = v * v % p
            d //= 2
 
    def ifft(n, p, g, w, invw, f):
        d = 1
        while d < n:
            v = poww(invw, n // (2 * d), p)
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j+d] *= u
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * v % p
            d *= 2
 
    p = 1107296257
    g = 5
    n0, n1 = len(a), len(b)
    n = 1
    while n < max(n0, n1) * 2:
        n *= 2
    a = a + [0] * (n-n0)
    b = b + [0] * (n-n1)

    w = poww(g, (p - 1) // n, p)
    invw = poww(w, p-2, p)
    fft(n, p, g, w, invw, a), fft(n, p, g, w, invw, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(n, p, g, w, invw, a)
    invn = poww(n, p - 2, p)
    for i in range(n0 + n1 - 1):
        a[i] = a[i] * invn % p
    return a[:n0 + n1 - 1]

N = 100000
A = []
B = []
s = 0
for i in range(N):
    s = (s * 3 + i * 7) % 100
    a = s
    b = (s * 3 + a * 11) % 100
    A.append(a)
    B.append(b)

AB = convolve(A, B)


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a = int(a)
b = int(b)
c = int(c)
k = int(k)


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

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

print(ans - k)

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
A, B, C, K = map(int, input().split())
sum = 0
if K >= A+B:
  sum = A - (K-A-B)
else:
  sum = K
    
print(sum)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

u = min(A, K)
v = max(0, K - A - B)
print(u - v)

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
a = min(A, K)
b = min(K- a, B)
c = K- a- b
ans = a- c

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

#"ありうる値"の最大値なので、K枚選択時はa,b,cの順に選択する

card_num = 0 #カード枚数
card_sum = 0 #値の合計

#1card*k
if k <= a:
    card_sum = k
#1card*a + 0card*(k-a)
elif k <= a + b:
    card_sum = a
#1card*a + 0card*b + -1card*(k-a-b)
else:
    card_sum = a - (k-a-b)

print(card_sum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#B
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(A-(K-A-B))
else:
    print(A-C)

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

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
ans += min(K, A) * 1
K -= A
ans += max(0, min(K, B)) * 0
K -= B
ans += max(0, min(K, C)) * -1
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(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(2*a - k + 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())

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

Submission status: Accepted

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

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

K = max(0, K-B)
result -= K

print(result)

Submission status: Accepted

Solution code:
# ABC167B => Easy Linear Programming
# https://atcoder.jp/contests/abc167/tasks/abc167_b

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

# 最大値を求めたいので、A->B->Cの順に選んでいく
if K - A >= 0 :
  sum = A
  K = K - A
  if K - B >= 0:
    K = K - B
    sum -= K
else :
  sum = K
  
print(sum)

Submission status: Accepted

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

if A >= K:
    s += K
    K -= K
else:
    s += A
    K -= A

if B >= K:
    K -= K
else:
    K -= B

if C >= K:
    s -= K
    K -= K
else:
    s += C
    K -= C

print(s)

Submission status: Accepted

Solution code:
a,b,c,k = (int(x) for x in input().split())
answer = 0
answer += min(a,k)
k = k - min(a,k)
k = k - min(b,k)
answer -= min(c,k)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = int(a)
b = int(b)
c = int(c)
k = int(k)

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

Submission status: Accepted

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

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




##A
#S = input()
#T = input()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from numba import njit
import numpy as np


def main(A, B, C, K):
    if K < A:
        return K
    if K > A+B:
        return A-(K-A-B)
    else:
        return A


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

Submission status: Accepted

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

result = 0

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

print(result)

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

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


main()

Submission status: Accepted

Solution code:

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



if k <= a:      #aのほうがｋ（カードを引く回数より）大きかった時
    ans = k     #ｋの回数分＝最大値
else:           #aよりｋのほうが大きかった時
    y = k - a   #引く回数 - a = 残りの引ける数
    if y <= b:  #ｂより残り引ける数が小さければ
        ans = a
    else :
        y -= b
        ans = a - y
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(2*a + b - k)

Submission status: Accepted

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

if k <= a:
    ans = k
else:
    count = k - a
    
    if count <= b:
        ans = a
    
    else:
        count -= b
        ans = a - count

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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 = map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k > a :
  k = k-a
  if k > b :
    k = k-b
    if k < c :
      c = k
  else:
    c = 0
else:
  a = k
  c = 0

print(a-c)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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


def main():
    a, b, c, k = map(int, open(0).read().split())

    if k <= a:
        ans = k
    elif k <= a + b:
        ans = a
    else:
        # ans = a + -1 * (k - a - b)
        ans = 2 * a + b - k

    print(ans)
    return(str(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
s, f = 0, 0
while k > 0:
    s += min(a, k)
    k -= s
    if k > 0:
        f = min(b, k)
        k -= f
    if k > 0:
        s -= min(c, k)
        k -= s
    break
print(s)

Submission status: Accepted

Solution code:
import sys                                                          
a,b,c,k = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
s = 0                                                               
if k > 0:                                                           
    s += min(k, a)                                                  
    k -= a                                                          
if k > 0:                                                           
    k -= b                                                          
if k > 0:                                                           
    s -= k                                                          
print(s)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if In[3]-In[0] <= 0:
  print(In[3])
elif In[3] - (In[0]+In[1]) <= 0:
  print(In[0])
else:
  print(In[0]-(In[3]-In[0]-In[1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if K < A:
    res = K
else:
    res = A
    K -= A
    if K > B:
        K -= B
        if K > 0:
            res -= K

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-A-B))
else :
    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))

Submission status: Accepted

Solution code:
a, b, c, k = list(map(int, input().split(' ')))
result = 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 = list(map(int, input().split(' ')))
result = 0

if a > k:
    result += k
    k -= k
else:
    result += a
    k -= a

if k > 0:
    if b > k:
        k -= k
    else:
        k -= b
    if c > k:
        result -= k
        k -= k
    else:
        result -= c
        k -= c

print(result)

Submission status: Accepted

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

nokori = K
num_1 = min(A, nokori)
nokori -= num_1
ans = num_1

nokori -= min(B, nokori)

num_minus = min(C, nokori)
ans -= num_minus

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:
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True

a,b,c,k=input2()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

result = 0
t = min(A, K)
result += t
K -= t
t = min(B, K)
K -= t
t = min(C, K)
result -= t
print(result)

Submission status: Accepted

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

A,B,C,K = MI()

def result(K):
   if K <= 0:
    print(sum)
    exit()

sum = 0

if K <= A:
    sum += K
    print(sum)
    exit()
else:
    sum += A
    K -= A

K -= B
result(K)

sum -= K

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
line = list(map(lambda x: int(x), input().split(" ")))
a, b, c, k = line[0], line[1], line[2], line[3]
 
if a >= k:
  print(k)
  sys.exit(0)
 
tmp = k - a
if b >= tmp:
  print(a)
  sys.exit(0)
 
print(a - (k - a -b))

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)
elif K <= A + B + C:
    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:
    N = K - A - B
    an = A - N
    print(an)

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

Submission status: Accepted

Solution code:
read = input().split()
x = int(read[3]) - int(read[0]) - int(read[1])
if int(read[3]) < int(read[0]):
    print(int(read[3]))
elif x <= 0:
    print(int(read[0]))
else:
    print(int(read[0]) - x)

Submission status: Accepted

Solution code:
read = input().split()
num = [int(s) for s in read]
if num[3] <= num[0] : print(num[3])
elif num[3] <= (num[0] + num[1]) : print(num[0])
else : print(2 * num[0] + num[1] - num[3])

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(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:
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 = map(int, input().split())

if a >= k:
  ans = k
elif a < k and a + b >= k:
  ans = a
elif a + b < k and a + b + c >= k:
  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 A > K:
    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())

ans=0

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

print(ans)

Submission status: Accepted

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

if n[0] >= n[3]:
    print(n[3])
elif n[0]+n[1] >= n[3]:
    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 K <= A:
  print(K)
elif A < K <= A + B:
  print(A)
else:
  print(A - (K - A - B))

Submission status: Accepted

Solution code:
a=1
b=0
c=-1
A,B,C,K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)
test=0
if K>=A:
    a=a*A
    test=test+a
    K=K-A
elif K<=A:
    a=a*K
    test=test+a
    c=0
if K>=B:
    b=b*B
    test=test+b
    K=K-B
elif K<=B: 
    b=b*K
    test=test+b
    c=0
    
if K>=C:
    c=c*C
    test=test+c
    K=K-C
elif K<=C:
    c=c*K
    test=test+c
    
    
print(test)

Submission status: Accepted

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