Problem:
 Score : 200 points    Problem Statement We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0 s and C cards with -1 s.  We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?      Constraints  All values in input are integers.  0 \leq A, B, C  1 \leq K \leq A + B + C \leq 2 \times 10^9         Input Input is given from Standard Input in the following format:  A  B  C  K       Output Print the maximum possible sum of the numbers written on the cards chosen.        Sample Input 1 2 1 1 3      Sample Output 1 2  Consider picking up two cards with 1 s and one card with a 0 .
In this case, the sum of the numbers written on the cards is 2 , which is the maximum possible value.       Sample Input 2 1 2 3 4      Sample Output 2 0       Sample Input 3 2000000000 0 0 2000000000      Sample Output 3 2000000000

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

Solution (Python):
import sys
 
 
def solve(A: int, B: int, C: int, K: int):
    if (K <= A):
        print(K)
    else:
        if (K <= (A+B)):
            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())

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

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

if k>0:
    total -= k 



print(total)

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

Solution (Python):
a,b,c,k =  [int(i) for i in input().split()]
if k<=a:
    print(k)
elif a<k and k<=a+b:
    s = a
    print(s)
elif a+b<k<=a+b+c:
    s = 2*a+b-k
    print(s)

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

Solution (Python):
def abc():
    arr=input()
    num=[int(n) for n in arr.split()]
    sum=0
    if(num[3]<=num[0]):
        sum=num[3]
    elif(num[3]>num[0] and num[3]<=num[1]):
        sum=num[0]
    elif(num[3]>num[1]):
        sum=num[0]-(num[3]-num[0]-num[1])
    print(sum)
abc()

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

if A >= K:
    print(1 * K)

elif A + B >= K:
    print(1 * A)

else:
    print(1 * A + -1 * (K - A - B))

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

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

c = 0


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

print(ans)

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

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

if K <= B:
    print(res)
    exit( )
else:
    K = K-B

if K <= C:
    res -= K
    print(res)
    exit( )
else:
    res += C
    print(res)

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

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

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

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

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

if K <= A+B:
    print(A)
    exit()

if K <= A+B+C:
    print(2*A-K+B)
    exit()

else:
    print(A-C)
    exit()

Solution (Python):
import sys

readline = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    A, B, C, K = map(int, readline().split())
    if A + B >= K:
        print(min(A,K))
    else:
        tmp = K - A - B
        print(A-tmp)

if __name__ == "__main__":
    main()

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

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

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

count = 0

if K >= A:
    count += A
    K -= A
else:
    count = K
    K = 0

if K != 0:
    if K>=B:
        K -= B
    else:
        K= 0
if K != 0:
    count -= K

print(count)

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

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

Solution (Python):


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

ans = 0
while(K!=0):
    
    
    if A!=0:
        if A <= K:
            ans += A*1
            K -= A
            A = 0
        else:
            ans += K*1
            A -= K
            K = 0
    elif B!=0:
        if B <= K:
            ans += B*0
            K -= B
            B = 0
        else:
            ans += K*0
            B -= K
            K = 0
    elif C!=0:
        if C <= K:
            ans += C*-1
            K -= C
            C = 0
        else:
            ans += K*-1
            C -= K
            K = 0

    if A==0 and B==0 and C==0:
        break
print(ans)

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

Solution (Python):
A,B,C,K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)
if (0<=A)and(0<=B)and(0<=C)and(1<=K<=A+B+C<=2*10**9):
    if K<=A:
        print(K)
    if A<K<=A+B:
        print(A)
    if A+B<K<=A+B+C:
        a=A-(K-A-B)
        print(a)

Solution (Python):

num_list = list(map(int, input().split())) 
if num_list[0]>=num_list[3]:
    print(num_list[3])
    exit()
num=num_list[3]-num_list[0]
sum=num_list[0]

if num_list[1]>=num:
    print(sum)
    exit()
num=num-num_list[1]
sum=sum-num
print(sum)

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

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

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

    print(A - t)

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

if A >= K:
    total = K
elif B >= (K-A):
    total = A
elif C >= (K-A-B):
    total = A-(K-A-B)

print(total)

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

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


if K-A >= 0:
    sum = sum + A
    K = K-A
    
    if K-B >= 0:
        K = K-B
        
        if K - C >=0 :
            sum = sum - C
            
        else:
            sum = sum - K
            
    else:
        pass
    
else:
    sum = sum + K
    


print(sum)

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

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

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

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

import sys


def solve(A: int, B: int, C: int, K: int):
    ans = 0
    ans += min(A, K)
    if K >= A + B:
        ans += min(K - (A + B), C) * -1
    print(ans)
    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())
count = k
ans = 0
if a < count:
    ans += a
    count -= a
else:
    ans += count
    print(ans)
    exit()
if b < count:
    count -= b
else:
    print(ans)
    exit()
if c < count:
    ans -= c
    print(ans)
    exit()
else:
    ans -= count
    print(ans)
    exit()

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

Solution (Python):

MOD = 10 ** 9 + 7
RLIMIT = 1000
DEBUG = 1

def main():
    for _ in inputt(1):
        a, b, c, k = inputi()
        t = k
        if k > a:
            t -= k - a
        if k > a + b:
            t -= k - a - b

        print(t)







from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(RLIMIT)





BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    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(b"\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()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    if args:
        sys.stdout.write(str(args[0]))
        split = kwargs.pop("split", " ")
        for arg in args[1:]:
            sys.stdout.write(split)
            sys.stdout.write(str(arg))
    sys.stdout.write(kwargs.pop("end", "\n"))
def debug(*args, **kwargs):
    if DEBUG and not __debug__:
        print("debug", *args, **kwargs)
        sys.stdout.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda k = int: map(k, inputs())
inputl = lambda t = 0, k = lambda: list(inputi()): [k() for _ in range(t)] if t else list(k())





def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError






class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass





class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        if n <= self._list[-1]: return
        maxbase = int(n ** 0.5) + 1
        self.extend(maxbase)
        begin = self._list[-1] + 1
        newsieve = [i for i in range(begin, n + 1)]
        for p in self.primerange(2, maxbase):
            for i in range(-begin % p, len(newsieve), p):
                newsieve[i] = 0
        self._list.extend([x for x in newsieve if x])
    def extend_to_no(self, i):
        while len(self._list) < i: 
            self.extend(int(self._list[-1] * 1.5))
    def primerange(self, a, b):
        a = max(2, a)
        if a >= b: return
        self.extend(b)
        i = self.search(a)[1]
        maxi = len(self._list) + 1
        while i < maxi:
            p = self._list[i - 1]
            if p < b:
                yield p
                i += 1
            else: return
    def search(self, n):
        if n < 2: raise ValueError
        if n > self._list[-1]: self.extend(n)
        b = bisect(self._list, n)
        if self._list[b - 1] == n: return b, b
        else: return b, b + 1
    def __contains__(self, n):
        if n < 2: raise ValueError
        if not n % 2: return n == 2
        a, b = self.search(n)
        return a == b
    def __getitem__(self, n):
        if isinstance(n, slice):
            self.extend_to_no(n.stop + 1)
            return self._list[n.start: n.stop: n.step]
        else:
            self.extend_to_no(n + 1)
            return self._list[n]
sieve = Sieve()
def isprime(n):
    if n <= sieve._list[-1]:
        return n in sieve
    for i in sieve:
        if not n % i: return False
        if n < i * i: return True
prime = sieve.__getitem__
primerange = lambda a, b = 0: sieve.primerange(a, b) if b else sieve.primerange(2, a)
def factorint(n):
    factors = []
    for i in sieve:
        if n < i * i: break
        while not n % i:
            factors.append(i)
            n //= i
    if n != 1: factors.append(n)
    return factors
factordict = lambda n: Counter(factorint(n))





if __name__ == "__main__":
    main()

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

Solution (Python):
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    a, b, c, n = map(int, sys.stdin.readline().split())
    s = 0
    if n <= a:
        s += n * 1
    elif n <= a + b:
        s += a * 1 + (n - a) * 0
    else:
        s += a*1+b*0 + (n-a-b)*-1
    print(s)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Solution (Python):



import sys


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


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

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



if __name__ == "__main__":
    resolve()

Solution (Python):
class A:

    def solve(self):
        s1 = input()
        s2 = input()
        print("Yes" if s1 == s2[:-1] else "No")

class B:

    def solve(self):
        A, B, C, K = tuple(map(int, input().split(" ")))
        sum = min(A, K)
        K -= A
        K -= B
        sum -= max(min(K, C), 0)
        print(sum)

B().solve()

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

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

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

Solution (Python):
from math import *
from copy import *
from string import *				
from random import *
from sys import stdin
from sys import maxsize
from operator import *				
from itertools import *
from collections import Counter		
import math
import math
import time

def bin1(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=k**mid
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin1(mid+1,r,k,t,b,val,ans)
		else:
			return bin1(l,mid-1,k,t,b,val,ans)
		
def bin2(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=t*(k**mid)+b*(mid)
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin2(l,mid-1,k,t,b,val,ans)
		else:
			return bin2(mid+1,r,k,t,b,val,ans)

def SieveOfEratosthenes(n): 
      
    
    
    
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
          
        
        if (prime[p] == True): 
              
            
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    l=[]
    for i in range(2,n+1):
    	if(prime[i]):
    		l.append(i)
    return l
def bin(l,r,ll,val):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		if(val>=ll[mid][0] and val<=ll[mid][1]):
			return mid
		elif(val<ll[mid][0]):
			return bin(l,mid-1,ll,val)
		else:
			return bin(mid+1,r,ll,val)
def deci(n):
	s=""
	while(n!=0):
		if(n%2==0):
			n=n//2
			s="0"+s
		else:
			n=n//2
			s="1"+s
	return s
def diff(s1,s2):
	if(len(s1)<len(s2)):
		v=len(s1)
		while(v!=len(s2)):
			s1="0"+s1
			v=v+1
	else:
		v=len(s2)
		while(v!=len(s1)):
			s2="0"+s2
			v=v+1
	c=0
	for i in range(len(s1)):
		if(s1[i:i+1]!=s2[i:i+1]):
			c=c+1
	return c
from sys import stdin, stdout 
def fac(a,b):
	v=a
	while(a!=b):
		v*=a-1
		a=a-1
	return v
def bino(l,r,n):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		val1=math.log((n/mid)+1,2)
		val2=int(val1)
		if(val1==val2):
			return val1
		elif(val1<1.0):
			return bino(l,mid-1,n)
		else:
			return bino(mid+1,r,n)

def binary(l,r,val,ans):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		v=val**5-mid**5
		print(v)
		if(v==ans):
			print("HOHOHOH")
			return mid
		elif(v<ans):
			return binary(mid+1,r,val,ans)
		else:
			return binary(l,mid-1,val,ans)
def check(n):
	v=1
	while(n!=0):
		if(n%10==0 or n%10==1):
			n=n//10
		else:
			v=0
			break
	return v
def stairs(n,m,val,c,l):
	if(val>n):
		return 100000
	elif(val==n):
		if(l[val]!=-1):
			return l[val]
		elif(c%m==0):
			l[val]=c
			return l[val];
		else:
			l[val]=100000
			return l[val]
	else:
		
		
		
		l[val]=min(stairs(n,m,val+1,c+1,l),stairs(n,m,val+2,c+1,l))
		return l[val]
def fact(n):
	if(n==0 or n==1):
		return 1
	else:
		return n*fact(n-1)

def some(n):
	s=0
	while(n!=0):
		s+=fact(n%10)
		n//=10
	return s
def bin(l,r,val,ll):
    if(l>r):
        return -1
    else:
        mid=(l+r)//2
        if(ll[mid]==val):
            return mid
        elif(ll[mid]>val):
            return bin(l,mid-1,val,ll)
        else:
            return bin(mid+1,r,val,ll)

if __name__ == '__main__':
	a,b,c,k=map(int,input().split())
	total=0
	if(a>=k):
		print(k)
	else:
		total+=a
		k-=a
		if(b>=k):
			print(total)
		else:
			k-=b
			total+=(-1)*k
			print(total)

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

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

use_A = min(A, K)

sumv += use_A
remain = K - use_A
use_B = min(B, remain)
use_C = remain - use_B
sumv += (-1* use_C)
print(sumv)

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

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

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

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

Solution (Python):
a,b,c,k = (int(x) for x in input().split())
total=0
total += min(a,k)
k -= min(a,k)
if k==0:
    print(total)
    exit()

if k>0:
    k -= min(b,k)
    if k==0:
        print(total)
        exit()

    if k>0:
        total -= min(c,k)
        print(total)

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

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

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


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

print(Result)

Solution (Python):
A,B,C,K = map(int, input().split())
cnt=0
res=0
if A >= K:
  print(K)
  exit(0)

cnt=A
res = K-A

if B >= res:
  print(cnt)
  exit(0)
res=res-B
print(res*-1+cnt)

Solution (Python):
def j():
    a,b,c,k=map(int,input().split())
    o=0
    x=k
    if a!=0:
        o+=a
        k-=a
        if k==0:
            return a
        elif k<0:
            return x
    if b!=0:
        k-=b
        if k<=0:
            return a
    if c!=0:
        k-=c
        o-=c
        if k==0:
            return o
        elif k<0:
            return o-k
print(j())

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 += a
    k -= a
else:
    ans += k

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

ans -= k

print(ans)

Solution (Python):


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

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

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

Solution (Python):
from sys import stdin

a, b, c, k = [int(_) for _ in stdin.readline().rstrip().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())
def pick(a,b,c,k):
    result = 0
    if (a >= k ):return k
    k -= a
    result += a
    if (b >= k):return result
    k -= b
    return result - k 
print(pick(a,b,c,k))

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

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


try:
    sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
    sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
    pass


def solve():
    a, b, c, k = list(map(int, input().split()))

    if 1 <= k <= a + b:
        return min(a, k)
    
    if k > a + b:
        diff = k - a - b
        return a - diff

print(solve())

Solution (Python):
import sys
a, b, c, num = map(int, input().split())

total = 0

if a >= num:
    print(num)
    sys.exit()

total += a
num -= a

if b >= num:
    print(a)
    sys.exit()

num -= b
    
print(a-num)

Solution (Python):


from collections import Counter
import math
mod = 10**9+7

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

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

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

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

total = 0

if A >= K:
    total = K
    print(total)
    exit()
else:
    total = A
    K -= A

if B >= K:
    print(total)
    exit()
else:
    K -= B

total -= K
print(total)

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

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

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

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

print(count)

Solution (Python):
from collections import defaultdict as dd

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


res = 0
if K <= a:
    res = K
elif K <= a+b:
    res = a
elif K <= a+b+c:
    res = a-(K-a-b)
print(res)

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

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

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c,k = LI()
    if k <= a+b:
        print(min(k,a))
    else:
        print(a-(k-a-b))
    return


if __name__ == "__main__":
    solve()

Solution (Python):
a, b, c, k = map(int, input().split())
if a>=k:
    print(k)
else :
    kk = k-a%k
    A = a%k
    if b>=kk:
        print(a%k)
    else :
        kkk = kk-b%kk
        B = b%kk
        if c >= kkk:
            print(a%k-1*(k-A-B))

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

Solution (Python):
def main():
    A, B, C, D = map(int, input().split())
    K = D
    D -= A
    if D <= 0:
        print(min(A, K))
        exit()

    D -= B
    if D <= 0:
        print(A)
    else:
        print(A - D)
    

if __name__ == "__main__":
    main()

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

ans = 0
a = min(A, K)
ans += a

K -= a
b = min(B, K)
K -= b

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

print(ans)

Solution (Python):
def resolve():
	a, b, c, k = map(int, input().split())
	s = [a, b, c]
	n = [1, 0, -1]
	ans = 0
	for i in range(3):
		if k - s[i] < 0:
			ans += n[i] * k
			print(ans)
			return
		k -= s[i]
		ans += s[i] * n[i]
	print(ans)
resolve()

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


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

Solution (Python):
A,B,C,K=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()))
answer = 0
if A >= K:
    answer = K
elif B >= K-A:
    answer = A
else:
    answer = A-(K-A-B)
print(answer)

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

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

if k-a <= 0:
    print(k)

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

elif k-(a+b)>0:
  print(a-(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)
elif a+b < k <= a+b+c:
    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 = (int(x) for x in input().split())

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