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



def solve(*args: str) -> str:
    a, b, c, k = map(int, args[0].split())

    ret = min(a, k)
    k -= ret
    k = max(0, k-b)
    ret -= k

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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

a1 = min(k, a)
k = max(0, k-a1)
b1 = min(k, b)
k = max(0, k-b1)


print(a1 + (k * -1))

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

Solution (Python):

A, B, C, K = map(int, input().split())
cnt = K
ans = 0
if A <= K:
    cnt -= A
    ans += A
    if B <= cnt:
        cnt -= B
        if C <= cnt:
            ans += (-1) * cnt
        else:
            ans += (-1) * cnt
    else:
        ans += 0
else:
    ans += K
print(ans)

Solution (Python):
import numpy as np
import math

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

ans=0
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:
  Ans += K
else:
  Ans += A
  K -= A
  if K >= B:
    K -= B
    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(a-(k-a-b))

Solution (Python):

import sys


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

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    K = int(next(tokens))  
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

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

Solution (Python):


import sys

class BEasyLinearProgramming:
    def solve(self, tc=0):
        a, b, c, k = [int(_) for _ in input().split()]
        print(min(a - max(0, k - a - b), k))


solver = BEasyLinearProgramming()
input = sys.stdin.readline

solver.solve()

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

if A >= K:
    print(K)
    exit()
    
c = A
K -= A
if B >= K:
    print(c)
    exit()
    
K -= B
c -= K
print(c)

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

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

print(ans)

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

else:
    ans += a
    temp = k - a
    if (temp <= b):
        pass
    else:
        temp -= b
        ans -= temp

print(ans)

Solution (Python):
if __name__ == '__main__':
    from sys import stdin
    
    
    
    
    
    input = stdin.readline


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

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

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

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

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

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

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

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

if K >= A:
    ans += A
else:
    ans += K
K -= A
if  K <= 0:
    print(ans)
    sys.exit()
K -= B
if K > 0:
    if K >= C:
        ans += (-1*C)
    else:
        ans += (-1*K)
print(ans)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *
































def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007




def main():
	A,B,C,K = inputMap()

	ans = 0
	for i in range(K):
		if A > 0:
			if A >= K:
				print(K)
				sys.exit()
			else:
				K -= A
				ans += A
				A = 0
				
		elif B > 0:
			if B >= K:
				print(ans)
				sys.exit()
			else:
				K -= B
				B = 0
		else:
			print(ans-K)
			sys.exit()

	print(ans)






def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)




def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv



def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)



if __name__ == "__main__":
	main()

Solution (Python):
a,b,c,k= list(map(int,input().split()))
ans=0
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):
import sys

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

total = 0

if A>=K:
    total = total + 1*K
    print(total)
else:
    total = total + 1*A
    if K-A==0:
        print(total)
        sys.exit()
    else:
        if (K-A)<=B:
            total = total + 0*(K-A)
            print(total)
            sys.exit()
        else:
            if (K-A-B)<=C:
                total = total + (K-A-B)*(-1)
                print(total)
                sys.exit()
            else:
                total = total + C*(-1)
                print(total)
                sys.exit()

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

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

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

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

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

Solution (Python):
def ZZ(): return list(map(int, input().split()))
def Z(): return int(input())

A, B, C, K = ZZ()
ans = 1 * min(A, K)
K -= min(A, K)
ans += 0 * min(B, K)
K -= min(B, K)
ans += -1 * min(C, K)
print(ans)

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

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

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

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

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

t = 0
ans = 0

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

    if b >= t:
        print(a)
    else:
        
        s = t - b

        print(a-s)

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

ans=0
if k<a:
    print(k);exit()
if k>=a:
    ans+=a
    k-=a
    if k==0:
        print(ans);exit()
if k>=b:
    k-=b
    if k==0:
        print(ans);exit()
print(ans-k)

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

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

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

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

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

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

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

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

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

Solution (Python):
def main():
    a,b,c,k = map(int, input().split())
    ans = 0
    if k > 0:
        ans += min(a,k)*1
        k -= min(a,k)
    if k > 0:
        k -= min(b,k)
    if k > 0:
        ans += min(c,k)*(-1)
        k -= min(c,k)
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
import sys

input = lambda: sys.stdin.readline()


def cin_int_list():
    return [int(x) for x in input().split()]


def cin_int_iter():
    return (int(x) for x in input().split())


def cin_int():
    return int(input())


def cout_int_iter(a):
    print(' '.join(map(str, a)))


def iota(n, start=0):
    return list(range(start, n))


def cin_digits_list():
    return [ord(x) - ord('0') for x in input()]


def main():
    a, b, c, k = cin_int_iter()

    ret = 0

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

    if k == 0:
        print(ret)
        return

    k -= min(b, k)

    if k == 0:
        print(ret)
        return

    ret -= min(c, k)
    k -= min(c, k)

    print(ret)


main()

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

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

resolve()

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

Solution (Python):
import math

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

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 sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B, C, K = lr()
answer = min(A, K)
K -= min(A, K)
if K > 0:
    K -= min(B, K)
    if K > 0:
        answer -= min(C, K)
print(answer)

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):
import sys
input = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Solution (Python):
nums=input().split()
A=int(nums[0])
B=int(nums[1])
C=int(nums[2])
K=int(nums[3])
if K<=A:
    maxsum=K
elif K<=A+B:
    maxsum=A
else:
    maxsum=A-(K-A-B)
print(maxsum)

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

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

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

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

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A, B, C, K = map(int, input().split())

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


main()

Solution (Python):


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

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

if B <= K:
    K -= B
else:
    ans += K * 0
    print(ans)
    quit()
print(ans - K)

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

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

print(ans)

Solution (Python):
import numpy as np
if __name__ == "__main__":
    A, B, C, K = map(int, input().split())
    ans = 0
    loop = min(A, K)
    K = K - loop
    ans += loop
    loop = min(B, K)
    K = K - loop
    
    loop = min(C, K)
    K = K - loop
    ans -= loop
    print(ans)

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

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

Solution (Python):
a, b, c, k = map(int, input().split())
numA = min(a, k)
numB = min(b, k-numA)
numC = min(c, k-numA-numB)
print(numA - numC)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,c,k = mi()

ima = k

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

ima = k - a

if b >= ima:
    print(a)
    exit()

ima = ima - b

nokori = min(c,ima)
print(a-nokori)

Solution (Python):
a, b, c, k = map(int, input().split())
s = min(a, k)
k = k - s
t = min(b, k)
k = k - t
u = min(c, k)
print(s-u)

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):
from sys import stdin
def main():
    A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
    if K <= A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A-(K-A-B))      
    
main()

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

Solution (Python):
def main():
    a,b,c,k = map(int,input().split())
    plus_one = min(a,k)
    k -= plus_one
    zero = min(b,k)
    k -= zero
    minus_one = min(c,k)
    print(plus_one * 1 + zero * 0 + minus_one * (-1))



if __name__ == '__main__':
    main()

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

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

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

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):






"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(a: int, b: int, _c: int, k: int) -> int:
    if k <= a + b:
        return min(k, a)
    return a - (k - a - b)


def do_job():
    "Do the work"
    LOG.debug("Start working")
    
    A, B, C, K = map(int, input().split())
    result = solve(A, B, C, K)
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case 
    
    


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None

if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            
            
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)

Solution (Python):
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 += -1 * k
print(ans)

Solution (Python):
a,b,c,k=map(int,input().split())
ans=0
if(k>0 and a!=0):
    k1=k-min(k,a) 
    ans+=min(k,a) 
    k=k1
if(k>0 and b!=0):
    k=k-min(k,b) 
if(k>0 and c!=0):
    ans=ans-min(k,c)
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(2*a + b - k)

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())
print((a if a<k else k)*1+max(k-a-b,0)*(-1))

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

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

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

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

print(main())

Solution (Python):
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def main():
    a,b,c,k = ints()
    if k<=a:
        print(k)
    elif k<=a+b:
        print(a)
    elif k<=a+b+c:
        print(2*a+b-k)


if __name__ == '__main__':
    main()

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

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

print(sum)

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

ans = 0

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

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

print(ans)

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 - min(k - (a + b), c))

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

kotae = 0

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

print(kotae)

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

remaining = K
ans = 0
if A <= remaining:
    ans += A
    remaining -= A
else:
    ans += remaining
    remaining = 0

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

ans -= remaining

print(ans)

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

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

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

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

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

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

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

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

diff=K-(A+B)
if diff>0:
    print(A-diff)
else:
    print(min(K,A))

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):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]





A, B, C, K = mi()

if A+B < K:
    print(A-(K-A-B))
else:
    print(min(A, K))

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

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

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

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

sum_card = 0
sum_n = 0

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

s = 0
s += min(A, K)
K -= A

if K > 0:
    K -= B

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

print(s)

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

ans=min(k,a)
k=k-ans 
ans1=min(k,b)
k=k-ans1
ans3=min(k,c)
k=k-ans3
print(ans-ans3)

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):
def main():
    from builtins import int, map, list, print, min
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    A,B,C,K = input_number_list()
    ans = min(A,K)
    K -= A+B
    if K>0:
        ans -= min(C,K)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
A, B, C, K = list(map(int, input().strip().split()))
ans = 0
tmp = min(A, K)
ans += tmp
K -= tmp
if K <= 0:
  pass
else:
  tmp = min(B, K)
  K -= tmp
  if K <= 0:
    pass
  else:
    tmp = min(C, K)
    ans -= tmp
print(ans)

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

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

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

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

Solution (Python):
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))

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

result = 0

m = [1, 0, -1]
options = [a, b, c]

idx = 0
while k > 0:
    get = min(k, options[idx])
    result += get*m[idx]

    idx += 1
    k -= get
print(result)

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

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

s = 0
s += min(a, d)
if min(a, d) == d:
  print(s)
elif min(a+b, d) == d:
  print(a)
else:
  d -= a + b
  print(a-min(c, d))

Solution (Python):

def main():
  a, b, _, k = map(int, input().split())

  ans = 0

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

  if k < 0:
    print(ans)
    return

  k -= min(b, k)

  if k < 0:
    print(ans)
    return

  ans -= k

  print(ans)


main()

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    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))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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)