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

ans = 0

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

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

ans += k*(-1)

print(ans)

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

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

    a_len = a if k > a else k
    b_len = b if (k-a_len) > b else (k-a_len)
    c_len = c if (k-a_len-b_len) > c else (k-a_len-b_len)

    max = 1 * a_len + 0 * b_len + (-1) * c_len

    print(max)

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

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)





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

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 a >= k :
    max = k

elif a+b >= k :
    max = a

elif( a+b <= k ):
    max = a - ( k - a - b )


print(max)

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

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

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

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

if k > 0:
  ans -= k

print(ans)

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

Solution (Python):
n = [int(x) for x in input().split()]
k = n[-1]
a = n[0]
b = n[1]
c = n[2]
if (k <= a):
    print(k)
elif (k <= a+b):
    print(a)
else:
    print(a-(k-a-b))

Solution (Python):
a, b, c, k = map(int, input().split())
s = 0
for _ in zip([a, b, c], [+1, 0, -1]):
    if k > 0:
        x = min(k, _[0])
        k -= x
        s += x * _[1]
    else:
        break
print(s)

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

n = nums[3]
ans = 0
add_num = 1
i = 0
while n > 0:
    if n > nums[i]:
        ans += (add_num * nums[i])
        n -= nums[i]
    else:
        ans += (n * add_num)
        break
    add_num -= 1
    if i == 2:
        break
    i += 1

print(ans)

Solution (Python):



def get_input() -> tuple:
    """標準入力の取得

    Returns:
        tuple -- 標準入力
    """
    A, B, C, K = list(map(int, input().split()))
    return A, B, C, K


def main(A: int, B: int, C: int, K: int) -> None:
    """求解処理.
    Kの値で場合分けする.

    Arguments:
        A {int} -- 整数
        B {int} -- 整数
        C {int} -- 整数
        K {int} -- 整数
    """
    result = int()
    if K <= A:
        result = K
    elif A < K and K <= A + B:
        result = A
    elif A + B < K and K <= A + B + C:
        result = 2*A + B - K

    
    print(result)


if __name__ == "__main__":
    A, B, C, K = get_input()
    main(A, B, C, K)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

a, b, c, k = readmi()
s = min(a, k)
k -= a
if k <= 0:
    print(s)
    exit()
k -= b
if k <= 0:
    print(s)
    exit()
s -= k
print(s)

Solution (Python):
A, B, C, K = list(map(int,input().split()))
count = 0
s = 0
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())

S = A+B+C
result = 0

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

print(result)

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

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

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

Solution (Python):
l = list(map(int,input().split(' ')))
x_1 = l[0]
x_0 = l[1]
x_neg = l[2]
K = l[3]
if (K<=x_1):
  print(K)
elif (K-x_1<=x_0):
  print(x_1)
else :
  print(x_1 -(K-x_1-x_0))

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

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

Solution (Python):
a, b, c, k = [int(i) for i in 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 = [int(i) for i in 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):
inputs = list(map(lambda x: int(x), input().split()))

max = 0
v = 1

for i in inputs[0:3]:
    if i > inputs[3]:
        i = inputs[3]
    max += v * i
    inputs[3] -= i
    v -= 1
    if inputs[3] <= 0:
        break

print(max)

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


if __name__ == "__main__":
    main()

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

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

    if b >= k:
        print(point)
    else:
        k -= b
        point -= k
        print(point)

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

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

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

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

point = min(a, k)
k -= min(a, k)
k -= min(b,k)
point -= min(c,k)
print(point)

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

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

print(result)

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

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

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

Solution (Python):
input_line = input().split()
plus = int(input_line[0])
zero = int(input_line[1])
minus = int(input_line[2])
maisu = int(input_line[3])

if plus >= maisu:
    print(maisu)
elif plus + zero >= maisu:
    print(plus)
else:
    minus_num = maisu - (plus + zero)
    print(plus - minus_num)

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

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

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

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

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

Solution (Python):



def calc(a, b, c, k):
  if k <= a:
    return k
  if k <= a + b:
    return a
  return a - k + b + a


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

print(calc(a, b, c, k))

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):
import sys

a, b, c, k = map(int, sys.stdin.readline().strip().split())

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

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


print(str(ans))

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

print(main())

Solution (Python):
src = list(map(lambda x : int(x), input().split(' ')))
dst = 0
k = src[3]
dst += (src[0] if src[0] <= k else k)
k -= dst
if k != 0:
  k -= (src[1] if src[1] <= k else k)
if k != 0:
  dst -= (src[2] if src[2] <= k else k)
  
print(dst)

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

Solution (Python):
i= [int(i) for i in input().split()]
A = i[0]
B = i[1]
C = i[2]
K = i[3]
m = 0
if K>=A:
    m += A*1
    K -= A
else:
    m +=K*1
    K=0
if K>=B:
    m += B*0
    K -= B
else:
    m +=K*0
    K=0
if K>=C:
    m += C*-1
    K -= C
else:
    m +=K*-1
    K=0
print(m)

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

Solution (Python):
n = input().split()
n = [int(i) for i in n]
count = 0

a = n[0]*1
b = n[1] 
c = n[2]*-1
while n[-1] > 0:
    if n[0] >= n[-1] and n[0] != 0:
        count = n[-1]*1
        n[-1] = 0
    elif n[0] < n[-1] and n[0] != 0:
        count += n[0]
        tmp = n[0]+n[1]
        n[-1] -= tmp
        n[0] = 0
    elif n[2] >= n[-1]:
        count += n[-1]*-1
        n[-1] = 0
    elif n[2] < n[-1]:
        count += c
        n[-1] = 0

print(count)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, C, K = LI()

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

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

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

if t <= b:
    print(cnt)
    exit()
else:
    t -= b

cnt -= t
print(cnt)

Solution (Python):
num = [int(i) for i in input().split()]
res = 0
a = num[0]
b = num[1]
c = num[2]
k = num[3]

if a < k:
    res = a
    k -= a
elif a >= k:
    res = k
    print(res)
    exit()

if b < k:
    k -= b
elif b >= k:
    print(res)
    exit()

if c <= k:
    res -= c
elif k > 0:
    res -= k
print(res)

Solution (Python):


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

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

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

def f():
    if K <= A:
        return K
    elif K <= A + B:
        return A
    else:
        
        return A - (K - A - B)

print(f())

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

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

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

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

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

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


def verify_sum(a,b,c,k):
    if k == a:
        print(a)
        return

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

verify_sum(a,b,c,k)

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

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

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

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

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

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

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

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

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

points=0

if K<=A:
    points=K
elif K<=A+B:
    points=A
else:
    points=2*A+B-K

print(points)

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

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

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

Solution (Python):
data=list(map(int,input().split()))
goukei=0
num=data[3]
for i in range(0,len(data)-1):
    if data[i]<=num:
        if i==0:
            goukei=goukei+data[i]
        elif i==2:
            goukei=goukei-data[i]
        num=num-data[i]
    else:
        if i==0:
            goukei=goukei+num
        elif i==2:
            goukei=goukei-num
        num=0
print(goukei)

Solution (Python):
data=list(map(int,input().split()))
goukei=0
num=data[3]
for i in range(0,len(data)-1):
    if data[i]<=num:
        if i==0:
            goukei=goukei+data[i]
        elif i==2:
            goukei=goukei-data[i]
        num=num-data[i]
    else:
        if i==0:
            goukei=goukei+num
        elif i==2:
            goukei=goukei-num
        num=0
print(goukei)

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 = [int(x) for x in input().split()]
res = 0
i = 0
t = [a, b, c]
j = [1, 0, -1]
while k > 0:
  m = min(k, t[i])
  k -= m
  res += j[i] * m
  i += 1
print(res)

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

Solution (Python):
i = input()
j = i.split(" ")

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

s = 0

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

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

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

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

Solution (Python):
if __name__ == "__main__":
    num = list(map(int, input().split()))

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

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

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

card = [A, B, C]
cardnumber = [1, 0, -1]

sum = 0
for i in range(0, 3):
	if card[i] > K:
		sum += K*cardnumber[i]
		break
	else:
		sum += card[i]*cardnumber[i]
		K -= card[i]

print(sum)

Solution (Python):
A, B, C, K = input().split(" ")
A, B, C, K = int(A), int(B), int(C), int(K)
 
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:
    print(K)
elif K>A and K<=A+B:
    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
else:
  if K > A and 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)
else:
  s=k-a
  if b>=s:
    print(a)
  else:
    t=k-a-b
    print(a-t)

Solution (Python):



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

"""
k < a -> a
k <= a + b -> a
k > a + b -> a - (k - (a + b))
"""

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

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):
from sys import stdin
 
a=stdin.readline().split()
A=int(a[0]) 
B=int(a[1]) 
C=int(a[2]) 
K=int(a[3])
 
if K<=A:
  print(K)
elif K<A<=A+B:
  print(A)
else:
  print(2*A+B-K)

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):
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())
sum = 0

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

if 0 < k:
    if b < k:
        k -= b
    else:
        k = 0

if 0 < k:
    sum -= k
    k = 0

print(sum - k)

Solution (Python):
A, B, C, K = (int(x) for x in input().split())
if A >= K:
    ans = K
else:
    ans = A
    tmp = K - A
    if B >= tmp:
        pass
    else:
        tmp = tmp - B
        ans += tmp * (-1)
print(ans)

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

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

Solution (Python):
oneCard, zeroCard, miniusOneCard, getCardNum = map(int, input().split())

if oneCard >= getCardNum: print(getCardNum)
elif oneCard + zeroCard >= getCardNum: print(oneCard)
else: print(oneCard - (getCardNum - oneCard - zeroCard))

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

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

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

if A >= K:
    result = K
    K = 0
else:
    result = A
    K -= A

K -= B

if C >= K and K > 0:
    result -= C - (C - K)

print(result)

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

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

Solution (Python):
def solve(a, b, c, k):
    if k <= a + b:
        return min(k, a)
    else:
        return 2*a + b - k

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

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

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

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

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

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


"""
print(a)
print(b)
print(c)
print(k)
"""
if a >= k:
    print(k)

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

else:
    print(a - (k - a - b))

Solution (Python):
from sys import stdin
input = stdin.readline

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

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

print(ans)

Solution (Python):

"""
Created on Fri May 15 00:35:24 2020

@author: Kanaru Sato
"""

a,b,c,k = list(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())
print(min(K, A) - max(K - A - B, 0))

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

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

for e in l:
    if K >= e[0]:
        K -= e[0]
        res += e[1] * e[0]
    else:
        res += e[1] * K
        break

print(res)

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):
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 1000000007



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

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

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

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

Solution (Python):

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


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

print(ans)

Solution (Python):
if __name__ == '__main__':
    A =[]
    B = input()
    A = B.split()

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

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

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

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

print(max)

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

if a >= k: 
    sum = k

elif a + b >=k:
    sum = a
else:
    sum = 2*a + b -k

print(sum)

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

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

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

    print(a - (k - a - b))

if __name__ == "__main__":
    main()

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

Solution (Python):
s = input().split(" ")

k = int(s[3])

sum = 0

if k >= int(s[0]) :
    sum += int(s[0])
    k -= int(s[0])
else :
    sum += k
    k =0

if k >= int(s[1]) :
    k -= int(s[1])
else :
    k =0

if k :
    sum -= k

print(sum)

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

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

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

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

Solution (Python):

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

count = 0

if K <= A:
    count += K

elif K <= A + B:
    count += A

else:
    count += 2*A + B - K

print(count)

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

Solution (Python):
arr = [int(char) for char in input().split(" ")]
a, b, c, k = arr[0], arr[1], arr[2], arr[3]
if k<=a:
  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+b):
    print(a-(k-(a+b)))
elif k<=a:
    print(k)
else:
    print(a)

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

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

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

a = 0
b = 0
c = 0

if A <= K:
    a = A
    if A + B <= K:
        b = B
        if A + B + C <= K:
            c = C
        else:
            c = K - A - B
    else:
        b = K - A
        
else:
    a = K

print(a-c)

Solution (Python):
def resolve():
    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__":
    resolve()

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

Solution (Python):
def main():
  a,b,c,k = [int(x) for x in input().split()]
  out = 0
  
  for (num, count) in zip([1, 0, -1], [a, b, c]):
    if k <= 0:
      break
    pick = min(k, count)
    k -= pick
    out += (num*pick)
  print(out)
main()

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

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

Solution (Python):
import sys
from collections import deque
import copy
def main():
    a, b, c, K = map(int, input().split())
    ans = 0
    ans += min(K, a)
    K -= a
    if K > 0:
        K -= b
    if K > 0:
        ans -= K
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
a,b,c,k = input().split(None, 4)
A = int(a)
B = int(b)
C = int(c)
K = int(k)
X = K - A - B
if K <= A:
    print(K)
elif A < K <= A + B:
    print(A)
else:
    print(A - X)

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

ans = 0

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

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

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

Solution (Python):
S = list(map(int,input().split()))
A = S[0]
B = S[1]
C = S[2]
K = S[3]

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

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

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

print(s)

Solution (Python):
card = list(map(int, input().split()))
list = list()
result = 0

if card[3] <= card[0]:
  result = card[3]
elif card[0] < card[3] and card[3] <= card[1]:
  result = card[0]
else:
  result = card[0] - (card[3] - (card[0] + card[1]))

print(result)

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

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

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

c = k- a- b

if c < 0 :
    c = 0
if a > k:
    a = k


print(a -c)

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

if a > k:
    cnt += k
else:
    cnt += a
    k -= a
if k != 0:
    if b > k:
        k -= k
    else:
        k -= b
    if k != 0:
        if c > k:
            cnt -= k
        else:
            cnt -= c

print(cnt)