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 0 s and C cards with -1 s.  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 1 s 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

Solution (Python):

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

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

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

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


wa = 0

res = k


if res > 0:
    wa += min(res, a)
    res -= min(res, a)

if res > 0:
    res -= min(res, b)
    
if res > 0:
    wa -= res

print(wa)

Solution (Python):
a, b, c, k = map(int, input().split())
ans = min(a, k)
k -= a
if k > 0:
    k -= b
if k > 0:
    ans -= k

print(ans)

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

Solution (Python):
A,B,C,K=map(int, input().split())
cuntA=A
cntK=K

ans=0
if A<=K:
    ans+=A
if A>K and A!=0:
    ans+=K
    
cntK-=A+B
if cntK>0:
    ans-=cntK
print(ans)

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

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

Solution (Python):
a, b, c, n = list(map(int, input().split()))
ans = 0

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

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





ans = 0
if k <= a:
    ans += k
else:
    ans += a
    k -= a
    if k <= b:
        ans += k*0
    else:
        k -= b
        if k <= c:
            ans -= k
        else:
            k -= c
            ans -= k

print(ans)

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

if __name__ == "__main__":
    A, B, C, K = MI()
    tmp = K
    result = 0
    if K > A:
        tmp -= A
        result += A
    else:
        print(K)
        exit()
    if tmp > B:
        tmp -= B
    else:
        print(result)
        exit()
    print(result - tmp)

Solution (Python):
A, B, C, K = [int(x) for x in input().split()]
print(min(K, A) - (min(K - A - B, C) if K - A - B > 0 else 0))

Solution (Python):
def point(A, B, C, K):
    S = 0
    if K <= A:
        S = K
        return S

    S = A
    K = K - A
    if K <= B:
        return S

    K = K - B
    return S - K


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

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

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

print(ans)

Solution (Python):
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)

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

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

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

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

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

if a + b >= k:
    print(a)
    exit()

if a + b < k:
    print(a - (k - a - b))

Solution (Python):
import numpy as np
A, B, C, K = list(map(int, input().split()))

ans = 0

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

print(ans)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

if A > K:
    print(K)

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

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

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

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

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

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

Solution (Python):
if __name__ == '__main__':
    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))

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

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






def solve():
    sum = 0
    if A >= K:
        sum += K
        return sum
    else:
        sum += A

    if A + B >= K:
        return sum
    else:
        sum -= K - A - B
    
    return sum

print(solve())

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


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

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

k = K

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

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

output = 0

left_after_a = k - a

if left_after_a <= 0:
    output = k
else :
    output += a
    
left_after_b = left_after_a - b

if left_after_b <= 0:
    pass
else :
    left_after_c = left_after_b - c
    if left_after_c <= 0:
        output -= left_after_b
    else :
        output -= c
        
print(output)

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

count = 0

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

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

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

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

Solution (Python):
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))

Solution (Python):
lists = list(map(int, input().split()))
a = lists[0]
b = lists[1]
c = lists[2]
k = lists[3]

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

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

cnt = 0
ret = 0

cnt += a
ret += a
if(cnt > k):
  ret -= cnt-k
if(cnt < k):
  cnt += b
if(cnt < k):
  cnt += c
  ret -= c
  if(cnt > k):
    ret += cnt-k

print(ret)

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

solve()

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

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

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

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

Solution (Python):
x = list(map(int, input().split()))

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

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

Solution (Python):
A,B,C,k=map(int,input().split())
if A>=k:
    print(k)
elif A<k and B>=(k-A):
    print(A)
elif A<k and B<(k-A):
    print(A-(k-A-B))

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

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

Solution (Python):
import itertools
import numpy as np
A,B,C,K = map(int,input().split())
if A+B>=K:
    print(min(A,K))
else:
    print(A-(K-A-B))

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

result = 0

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

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

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

Solution (Python):
import sys
A,B,C,K = map(int,(input().split()))
point = 0

if(K<=A):
  point=K
  print(point)
  sys.exit()
else:
  point+=A
  K-=A

if(K<=B):
  print(point)
  sys.exit()
else:
  K-=B
  point-=K
  print(point)

Solution (Python):







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






result = 0

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

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

Solution (Python):
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)

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

ans = 0
cards = [a, b, c]
nums =  [1, 0, -1]

i = 0

while k>0:
    if cards[i] <= k:
        ans += cards[i] * nums[i]
        k -= cards[i]
    else:
        ans += nums[i] * k
        break
    i += 1

print(ans)

Solution (Python):

import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter





j=0
k=0
n=3
r=1
a=[0]






"1行1つの整数を入力を取得し、整数と取得する"




"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''


'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


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

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


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  

'''

def factorial(x, mod=10**9+7):
    
    
    
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''











def main():

    w=1
    j=0
    k=0
    
    a,b,c,k=map(int, input().split(" "))
    if a>k:
        print(k)
        sys.exit()

    if a+b>=k:
        print(a)
        sys.exit()
    
    
    
    print(2*a-k+b)
    
    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    
        
        
    
    
        
        
    


    "1行1つの整数を入力を取得し、整数と取得する"
    
    
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    
    


    
    
    
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]
    

    ls = ["a", "b", "c", "d", "e"]


    
    

    
    

    
    
    
    
    
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Solution (Python):
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))

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

if K <= A:
    point = K
else:
    point = A
    if K - A - B >= 0:
        point = 2*A+B-K

print(point)

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

print(sum)

Solution (Python):

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

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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
in1 = input()
ins = in1.split()
oneNum = int(ins[0])
zeroNum = int(ins[1])
enoNum = int(ins[2])
num = int(ins[3])


if oneNum >= num:
  print(num)
else:
  sum = oneNum
  num -= oneNum
  num -= zeroNum
  if num <= 0:
    print(sum)
  else:
    sum -= num
    print(sum)

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

total = 0
if K <= A:
    total = K*1
elif A < K and K <= A+B:
    total = A*1 + (K - A)*0
else:
    total = A*1 + B*0 + (K - A - B)*(-1)

print(total)

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

for i in range(3):
    if i == 0:
        if k <= a:
            print(k)
            break
        else:
            k -= a

    elif i == 1:
        if k <= b:
            print(a)
            break
        else:
            k -= b

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

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


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

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

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

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

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string,decimal
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,C,K = II()

ans = 0

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

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

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

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

Solution (Python):
A , B , C , K = map ( int  ,input().strip().split(" ") ) 
l = [ 1 , 0 , -1 ] ;
t = 0 

for ( c,r ) in zip ( l , ( A, B , C ) ) :

	if r >= K :
		t += K * c ;
		break ;
	else :
		K -= r ;
		t += r * c ;
print ( t ) ;

Solution (Python):
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))

Solution (Python):
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)*(-1))

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

while True :
    if k-a <= 0 :
        print(k)
        break
    k -= a
    if k-b <=0 :
        print(a)
        break
    k -= b
    print(a-k)
    break

Solution (Python):
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)

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

ans = 0

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

Solution (Python):
A,B,C,K = map(int,input().split())
result = 0
if K<=A:
	result = K
elif K<=B:
	result = A
else: result = 2*A+B-K
print(result)

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



if A >= K:
    ans = K
elif A + B >= K:
    ans = A    
else:
    ans = 2*A+B-K

print(ans)

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

ans = 0

if a <= k:
    ans += a
    k -= a
else:
    ans += k
    k = 0

k -= b

if k > 0:
    ans -= k

print(ans)

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

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

Solution (Python):
def main():
    abck = list(map(int, input().split()))
    count = abck[3]
    r = 0
    
    r += min(abck[0], count)
    count -= min(abck[0], count)
    count -= min(abck[1], count)
    r -= min(abck[2], count)
    count -= min(abck[2], count)

    print(r)

if __name__ == '__main__':
    main()

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

Solution (Python):
A,B,C,K=map(int,input().split())
ans=0
sub=K
if A>K:
    ans+=1*K
    sub-=K
else:
    ans+=1*A
    sub-=A
if sub!=0:
    if B>sub:
        sub=0
    else:
        sub-=B
if sub!=0:
    ans-=sub
print(ans)

Solution (Python):
A,B,C,D = map(int,input().split())
count = 0
point = 0

if D-A >= 0:
    point = A
    D -= A
    if D-B >= 0:
        D -= B
        if D-C >= 0:
            point -= C
            print(point)
        else:
            point -= D
            print(point)
    else:
        print(point)
else:
    point = D
    print(point)

Solution (Python):
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)

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

Solution (Python):
line = input()
a, b, c, k = line.split(" ")
a, b, c, k = int(a), int(b), int(c), int(k)

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

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

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

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

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

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

if k!=0:
	x = min(k, b)
	k = max(k-x, 0)

if k!=0:
	x = min(k, c)
	ans += (-1*x)

print(ans)

Solution (Python):


def relu(a, b):
    if(a <= b):
        return 0
    else:
        return a - b

def main():
    args = input().rstrip().split(' ')
    A, B, C, K = int(args[0]),int(args[1]),int(args[2]),int(args[3])
    
    if(A >= K):
        print(K)
    else:
        print(A - relu(K, A+B))
    
if __name__ == "__main__":
    main()

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

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

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

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

if a>=k:
  print(k)
  exit()
else:
  t=a
  r=k-a

if b>=r:
  print(t)
  exit()
else:
  r-=b

t-=r
print(t)

Solution (Python):
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)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





a,b,c,k=mii()


ans=0

for i,abc in [[a,"a"],[b,"b"],[c,"c"]]:
    if k<i:
        if abc=="a":
            ans+=k
            k=0
        elif abc=="b":
            ans+=0
            k=0
        else:
            ans-=k
            k=0
    else:
        if abc=="a":
            ans+=a
            k-=a
        elif abc=="b":
            ans+=0
            k-=b
        else:
            ans-=c
            k-=c
    if k==0:
        print(ans)
        exit()
print(ans)

Solution (Python):
a,b,c,k = map(int,input().split())
ans=min(a,k)
k-=ans
k-=min(b,k)
if k>0:
    ans-=k

print(ans)

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

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


res = 0


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

Solution (Python):





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

if A < K:
  result += A
  K -= A
else:
  result = K
  K -= A

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

if K > 0:
  if C < K:
    result -= C
    K -= C
  else:
    result -= K

print(result)

Solution (Python):

def main():
    (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(A-(K-A-B))
    else:
        print(A-C)

if __name__ == '__main__':
    main()

Solution (Python):

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

card0 = 0
card_1 = 0

if k <= a:
    card1 = k
else:
    card1 = a
    if k-a <= b:
        card0 = k-b 
    else:
        card0 = b
        if k-a-b <= c:
            card_1 = k-a-b
        else:
            card_1 = c

print((card1)*1 + (card0)*0 + (card_1)*(-1))

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

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

Solution (Python):
import numpy as np
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)))

Solution (Python):
paramA, paramB, paramC, paramK = list(map(lambda x: int(x), input().split(' ')))

result = min(paramA, paramK)
paramK -= paramA
if paramK > 0:
    paramK -= paramB
    if paramK > 0:
        result -= min(paramC, paramK)

print(result)

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

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

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

A = 0
B = 0
C = 0
K = 0

if a >= k:
    A = k
else:
    A = a
    K = k - a
    if b >= K:
        B = K
    else:
        B = b
        K -= b
        C = K
print(A-C)

Solution (Python):
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))

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

ans=0

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

print(ans)

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

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

Solution (Python):


import sys






















def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    a, b, c, k = mi()
    if k <= a + b:
        print(min(a, k))
    else:
        print(a - (k - (a + b)))


if __name__ == "__main__":
    main()

Solution (Python):
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 + (-1) * (K - (A + B)))

Solution (Python):
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,B,C,K = LI()
ans = min(A,K)
if A+B<K:
    ans -= K-(A+B)
print(ans)

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

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

    if A > K:
        return print(K)

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

if __name__ == '__main__':
    main()

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

Solution (Python):

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

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

Solution (Python):


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]
mp = lambda :map(int,input().split())

a,b,c,k = mp()
if k >= a:
    ans = k - (k-a)
    k -= a
    if k >= b:
        k -= b
        ans -= k
    print(ans)
else:
    print(k)

Solution (Python):
a, b, c, k = map(int, input().split())
counter = 0
if k <= a:
  counter = k
elif k <= a + b:
  counter = a
else:
  counter = a - (k - a - b)

print(counter)

Solution (Python):
def main():
    a, b, c, k = (int(x) for x in input().split())
    ans = 0
    if k <= a:
        ans += k
    elif a + b < k and k > a:
        ans += 2 * a + b - k
    elif a + b >= k and k > a:
        ans += a

    print(ans)


if __name__ == "__main__":
    main()

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

ans = 0
if K - A >= 0:
    ans += A
    K -= A
elif K < A:
    ans += K
    K = 0

if K - B >= 0:
    K -= B
elif K < B:
    K = 0

if K > 0:
    ans -= K

print(ans)

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