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

A,B,C,K = MI()

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

sum = 0

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

K -= B
result(K)

sum -= K

print(sum)

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

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

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

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

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

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):
read = input().split()
x = int(read[3]) - int(read[0]) - int(read[1])
if int(read[3]) < int(read[0]):
    print(int(read[3]))
elif x <= 0:
    print(int(read[0]))
else:
    print(int(read[0]) - x)

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):
read = input().split()
num = [int(s) for s in read]
if num[3] <= num[0] : print(num[3])
elif num[3] <= (num[0] + num[1]) : print(num[0])
else : print(2 * num[0] + num[1] - num[3])

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

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

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

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

ans=0

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

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

if n[0] >= n[3]:
    print(n[3])
elif n[0]+n[1] >= n[3]:
    print(n[0])
else:
    print(n[0] - (n[3]-(n[0]+n[1])))

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

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

Solution (Python):

from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil, factorial, log,tan,pi,cos,sin,radians
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
from fractions import Fraction
from functools import reduce
import string
import sys
import os
import re
inf = float('inf')
mod_ = int(1e9) + 7
mod = 998244353

def factors(n):
    from functools import reduce
    return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sieve(m):
    n=1
    primes = {}
    arr=set([])
    for i in range(2, int(m ** 0.5) + 1):
        a = n // i
        b = m // i
        for k in range(max(2, a), b + 1):
            c = i * k
            primes[c] = 1

    for i in range(max(n, 2), m + 1):
        if i not in primes:
            arr.add(i)

    return arr


class DisjointSetUnion:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
 
    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a
 
    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a != b:
            if self.size[a] < self.size[b]:
                a, b = b, a
 
            self.num_sets -= 1
            self.parent[b] = a
            self.size[a] += self.size[b]
 
    def set_size(self, a):
        return self.size[self.find(a)]
 
    def __len__(self):
        return self.num_sets

def isprime(t):
    for i in range(2,int(t**0.5)+1):
        if t%i==0:
            return False
    return True
def semiprime(x):
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            if isprime(i) and isprime(x//i) and i!=x//i:
                return True
    return False



def main():

    a,b,c,k=map(int,input().split())
    ans=0
    ans+=min(k,a)
    k-=min(k,a)
    a-=min(k,a)
    
    ans+=0*min(k,b)
    k-=min(k,b)
    b-=min(k,b)
    ans-=min(k,c)
    k-=min(k,c)
    
    print(ans)
        

        
    




    





BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
A,B,C,K=input().split(" ")
A=int(A);B=int(B);C=int(C);K=int(K)
SUM=0
if A <= K :
    SUM= 1 * A
    K=K-A
    if B <= K:
        K=K-B
        SUM=SUM + -1*K
        print(SUM)
    else:
        print(SUM)
else:
    print(1*K)

Solution (Python):
a, b, c, k = map(int, input().rstrip().split())
k1 = min(a, k)
k0 = min(b, k - k1)
km = min(c, k - k1 - k0)

r = k1 - km
print(r)

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

sum = 0

if k-a >= 0:
    sum += a
    k = k-a
else:
    sum += k
    print(sum)
    exit(0)

if k-b >= 0:
    k = k-b
else:
    print(sum)
    exit(0)


if k-c >= 0:
    sum -= c
else:
    sum -= k
    print(sum)
    exit(0)

print(sum)

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

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

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

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

total = min(a, k) * 1
k = max(k - a - b, 0)

total += min(c, k) * (-1)

print(total)

Solution (Python):
import sys
from io import StringIO
import unittest


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



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 1 1 3"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2000000000 0 0 2000000000"""
        output = """2000000000"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

if K >= A:
    Anum = A
    N = K - A
else:
    Anum = K
    N = 0

if N >= B:
    Bnum = B
    N = N - B
else:
    Bnum = N
    N = 0

Cnum = N

Total = Anum * 1 + Bnum * 0 + Cnum * (-1)

print(Total)

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

tot += min(a, k)
mini = min(a,k)
a -= mini
k -= mini

if(k > 0):
    mini = min(b,k)
    b -= mini
    k -= mini
if(k > 0):
    tot -= min(c,k)

print(tot)

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

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

if(a >= k):
    print(k, end="")
else:
    k2 = k - a
    if(b >= k2):
        print(a, end="")
    else:
        k2 -= b
        print(a-k2, end="")

Solution (Python):


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

    if A >= K:
        print(K)
        return

    total = A
    K -= A

    if B >= K:
        print(total)
        return

    K -= B

    total += -K

    print(total)


if __name__ == "__main__":
    solve()

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

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

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

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

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

def one_int():
    return int(input())

def one_str():
    return input()

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

A,B,C,K = input_int()

sums=0
if A<K:
    K-=A
    sums = A
    if B<K:
        K-=B
        if C<K:
            sums -= C
        else:
            sums -= K
    else:
        pass

else:
    sums += K


print(sums)

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

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

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

if c<k:
    ans-=c
    k-=c
else:
    ans-=k
    k = 0

print(ans)

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

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

k = k -b

if k > 0:
    if k > c:
        ans = ans - c
    else:
        ans = 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:
    r = k - a - b
    print(a-r)

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

score = 0


if K <= A+B:
    score = min(A,K)
else:
    score = A - min(C, (K - (A+B)))


print(score)

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

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

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

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

ka = k - a
kb = ka - b

if ka > 0:
    if kb > 0:
        ans = a
        ans += kb * -1
    else:
        ans = a
else:
    ans = k * 1

print(ans)

Solution (Python):
a, b, c, k = (int(i) for i in input().split())  
tmp_cnt = k
tmp_sum = 0
if a <= k:
  tmp_sum = a
else:
  tmp_sum += k
tmp_cnt -= a
tmp_cnt -= b
if tmp_cnt>0:
  tmp_sum += tmp_cnt*(-1)
print(tmp_sum)

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

Solution (Python):
x = input().split()
A = int(x[0])
B = int(x[1])
C = int(x[2])
K = int(x[3])
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(1*k)
if a<k and a+b>=k:
    print(1*(k-b))
if a<k and a+b<k and a+b+c>=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:
    print(a-(k-a-b))

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

max = 0
if(a >= k):
  max = k
else:
  max = a
  k -= a
  if(b >= k):
    pass
  else:
    k -= b
    max -= k

print(max)

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

ans = 0

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

Solution (Python):
one, zero, minus_one, choice = map(int, input().split())
tmpsum = 0

if one >= choice:
    print(choice)
else:
    tmpsum = one
    choice = choice - one

    if zero >= choice:
        print(tmpsum)
    else:
        choice = choice - zero
        print(tmpsum - choice)

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

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

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

if k>c:
    ans = ans -c
elif 0<k:
    ans = ans -k

print(ans)

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

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

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


if __name__ == '__main__':
    main()

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

def max_check():
    if (A >= K):
        return(K)
    elif(A+B >= K):
        return(A)
    else:
        return(A - (K-A-B))

print(max_check())

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

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

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

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

Solution (Python):
N=input("")
l_str=N.split()
l=[int(s) for s in l_str]


max;


if l[0]>=l[3]:
    max=1*l[3]
elif l[0]+l[1]>=l[3]:
    max=1*l[0]
else:
    max=1*l[0]-1*(l[3]-(l[0]+l[1]))

print(max)

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

Solution (Python):
import sys

def ISI(): return map(int, sys.stdin.readline().rstrip().split())

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

Solution (Python):
def main():
    A, B, _, K = map(int, input().split())
    if A > K:
        print(K)
        quit()
    print(A - max([0, K - A - B]))


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

a = min(K, A)  
G = K - a
b = min(G,B)
F = G - b
c = min(F,C)
D = F - c
print(a+(-1*c))

Solution (Python):
one,zero,ng_one,card = map(int, input().split())

if card < one:
    print(card)
elif card <= one+zero:
    print(one)
else:
    print(one - (card - one - zero))

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

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

max = 0

if(K >= A):
    max += A
    K -= A
else:
    max += K

K -= B

if(K > 0):
    max -= K

print(max)

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

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

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

print(ans)

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

if __name__ == '__main__':
    main()

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

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

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

print(max)

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

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

    if k <= a:
        print(k)
        return

    if k <= b + a:
        print(a)
        return

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

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

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

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

Solution (Python):
import sys
readmi = lambda: map(int, sys.stdin.readline().split())

A, B, C, K = readmi()

max_sum = 0


max_sum = min(A, K)
K = K - max_sum


if K > 0:
  K = K - min(B, K)


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

print(max_sum)

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

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

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

Solution (Python):
def main():
    import sys
    
    a, b, c, k = tuple(map(int, sys.stdin.readline().split()))
    
    total = 0
    if(k>a):
        total += 1*a
        k -= a
        if(k>b):
            k -= b
            if(k>c):
                total += -1*c
            else:
                total += -1*k
    else:
        total = 1*k
    print(total)
    
if __name__ == "__main__":
    main()

Solution (Python):

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

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

ans = 0

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

if b > k:
    ans += 0*k
    k = 0
else:
    ans += 0*b
    k -= b

if c > k:
    ans += -1*k
    k = 0
else:
    ans += -1*c
    k -= c


print(ans)

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

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

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

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):
l = [int(i) for i in input().split()]
num = [1,0,-1]
c = 0
s = 0
k = l[-1]
for i in range(3):
    
    if c + l[i] > k:
        s += num[i] *(k-c)
        break
    else:
        s += l[i] * num[i]
        c+=l[i]
   
print(s)

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

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

Solution (Python):
nums = [int(e) for e in input().split()]

if nums[0]<nums[3]:
    max=nums[0]
    if nums[0]+nums[1]<nums[3]:
        max -= (nums[3]- (nums[0]+nums[1]))
else:
    max=nums[3]

print(max)

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

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

Solution (Python):
def solve(string):
    a, b, c, k = map(int, string.split())
    if k <= a:
        return str(k)
    if k <= a + b:
        return str(a)
    return str(a - (k - a - b))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

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

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

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

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

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

ans = min(A,K)
K = K-A-B
if K <= 0:
  print(ans)
  exit(0)

ans = ans - min(C,K)
print(ans)

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

Solution (Python):


def max_sum(A, B, C, K):
    if K < A: return K
    elif K < A+B :  return A
    else: return A - (K-(A+B))

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

if __name__ == "__main__":
    main()

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

count = K
score = 0

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 = input().split()
A = int(a)
B = int(b)
C = int(c)
K = int(k)

ans = 0

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

K = K - A - B

if (K > 0):
  ans = ans - K

print (ans)

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


if __name__ == "__main__":
    main()

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

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

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

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

    print(point)

if __name__ == '__main__':
    main()

Solution (Python):
if __name__ == "__main__":
	a, b, c, k = map(int, input().strip().split(' '))
	s, i = 0, 0
	if k <= a:
		s = k
	elif k > a:
		s = a
		k -= a
		if k > b:
			k -= b
			s -= k
	print(s)

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

total = 0
plus_num = 0
per_num = 0
minus_num = 0

if a < k:
  plus_num = a
  k -= a
else:
  plus_num = k
  k = 0

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

if c < k:
  minus_num = c
  k -= c
else:
  minus_num = k
  k = 0



total = plus_num - minus_num
    
print(total)

Solution (Python):
a, b, c, k=map(int, input().split())
l=[a,b,c]
v=[1,0,-1]
ans=0
for i in range(3):
    ans+=min(l[i], k)*v[i]
    k-=min(k,l[i])
    if k==0: break
print(ans)

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

k = K
a = 0
b = 0
c = 0

if A <= k:
  a = A
  k -= a
else:
  a = k
  k = 0

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

if C <= k:
  c = C
  k -= C
else:
  c = k
  k = 0

print(a-c)

Solution (Python):
import sys
a, b, c, k = map(int,sys.stdin.readline().rstrip().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 = map(int, input().split())
if a >= k:
    print(k)
elif (a+b)>=k:
    print(a)
else:
    minus = k-(a+b)
    print(a-minus)

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

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

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