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

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

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

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

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

count=0

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

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 + B >= K:
  print(min(A, K))
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:
    num = k-a-b
    print(a-num)

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

Solution (Python):


iim = lambda: map(int, input().rstrip().split())

def resolve():
    A, B, C, K = iim()

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

if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
    main()

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

Solution (Python):
a,b,c,k=[int(i)for i 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 K <= A:
  print(K)
elif A < K <= A + B:
  print(A)
else:
  print(A - (K - A - B))

Solution (Python):















mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

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

def main():
    a,b,c,k = readInt()
    ans = 0
    if a>k:
        print(k)
        return
    else:
        ans += a
        k -= a
    if b>k:
        print(ans)
        return
    else:
        k -= b
    if c>k:
        ans -= k
    else:
        ans -= c
    print(ans)
    return

if __name__=='__main__':
    main()

Solution (Python):

"""
Created on Sun May 10 20:59:16 2020

@author: shinba
"""
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 =  [int(i) for i in input().split()]

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

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 = [int(i) for i in input().split()]
ans = min([A,K])
K -= A + B
if K < 1:
    print(ans)
    exit()
ans -= K
print(ans)

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

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

Solution (Python):

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

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

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

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

Solution (Python):
from sys import stdin


def main():
    A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
    a = min(A, K)
    b = min(B, K - a)
    c = min(C, K - a - b)
    print(a - c)


if __name__ == "__main__":
    main()

Solution (Python):
import sys, random
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
    inf = 10 ** 20


    
    t = 1
    
    
    for _ in range(1, t+1):
        
        
        a, b, c, k = map(int, input().split())
        ans = 0
        if(k):
            ans += min(k, a)
            k -= min(k, a)
        if(k):
            k -= min(k, b)
        if(k):
            ans -= k
        
        print(ans)
        
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))

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

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

total = 0

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

total = a
k = k - a

if b >= k:
    print(total)
    exit()

k = k - b
print(total - k)

Solution (Python):


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

takeA = min(a, k)
takeB = min(b, k - takeA)
takeC = min(c, k - takeB - takeA)

print(takeA - takeC)

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

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

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

Solution (Python):
from sys import stdin
A,B,C,K = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
ans += min(K,A)
if K - A - B > 0:
    ans -= (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)
else:
    print(a-(k-a-b))

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


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):
import sys
from collections import defaultdict,Counter

sys.setrecursionlimit(10**7)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    a,b,c,k=mis()
    ans=0
    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())

ans = 0

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

print(ans)

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

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

ans = 0

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

    print(ans - K)

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

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

Solution (Python):


import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

A, B, C, K = LI()

ans = 0

if A >= K:
    ans = K
else:
    ans = A
    K -= A

    if B >= K:
        pass
    else:
        K -= B

        ans -= K

print(ans)

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

print(ans)

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

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

Solution (Python):
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()



A, B, C, K = In.ints()

res = 0

res += min(K, A)

K-=A

if K>0:
    K-=B

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

Out.int(res)
 


if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

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

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

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

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

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

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

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

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

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

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

ans = 0
if K <= (A + B):
    ans = min(K, A)
else:
    ans = A - (K - A - B)

print(ans)

Solution (Python):



def main() -> None:
    A, B, C, K = rmi()
    sum_ = 0
    if A < K:
        sum_ += A
        K -= A
    else:
        sum_ += K
        K = 0
    if B < K:
        K -= B
    else:
        K = 0
    if 0 < K:
        sum_ -= K
    w(sum_)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> tuple:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(*data, delim: str = ' ') -> None:
    print(delim.join(map(str, data)))


if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10 ** 9)
    main()

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

a, b, c, k = na()
ans = 0
if a >= k:
    print(k)
else:
    res = k - a
    ans += a
    if b >= res:
        print(ans)
    else:
        print(ans - (res - b))

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline 


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

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

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

if a < k:
    ans = a
    k -= a
    if b < k:
        k -= b
        if c < k:
            ans -= c
        else:
            ans -= k
else:
    ans = k

print(ans)

Solution (Python):
a,b,c,k=[int(_) for _ in input().split()]
d=min(a,k)
point=d
k-=d
if k>0:
    e=min(b,k)
    k-=e
    if k>0:
        f=min(c,k)
        point-=f
print(point)

Solution (Python):
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

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

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

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

Solution (Python):
import sys
l = sys.stdin.readline().strip()
A, B, C, K = map(int, l.split())

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

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

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

Solution (Python):
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy




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

if __name__ == '__main__':
    main()

Solution (Python):


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

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


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

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

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

if A >= K:
    print(K)
    exit()

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

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

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

print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



class UnionFindEx:
    def __init__(self, size):
        
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    A,B,C,K = mis()
    ans = min(A,K)
    K -= min(A,K)
    if K>0:
        K -= min(B,K)
        if K>0:
            ans -= K
    print(ans)


main()

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

Solution (Python):



a,b,c,k=[int(x) for x in input().split()]
ans=0
if k<=a:
	ans+=k
	k=0
elif k>a:
	ans+=a
	k-=a
if k<=b:
	k=0
elif k>b:
	k-=b
if k<=c:
	ans-=k
	k=0
print(ans)

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

if k <= a:
    print(k)
    sys.exit()
    
if k <= a + b:
    print(a)
    sys.exit()
    
num = k - a - b
print(a - num)

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")











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

Solution (Python):

MOD = 10 ** 9 + 7
INFI = 10**10

import math

import itertools
import heapq


import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default




def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    a,b,c,k=map(int,input().split())
    ans=0
    while True:
        if a>=k:
            ans=k
            break
        else:
            ans+=a
            k-=a
        if b>=k:
            break
        else:
            k-=b
        ans-=k
        break
    print(ans)







if __name__ == "__main__":

    main()

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

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

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):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

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

if k>0 and c>0:
    ans-=k

print(ans)

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

Solution (Python):



def compute(a, b, c, k):
    res = 0
    num_a = min(k, a)
    res += num_a
    k -= num_a
    num_b = min(k, b)
    k -= num_b
    num_c = min(k, c)
    res -= num_c
    return res


def main():
    a, b, c, k = (int(z) for z in input().split())
    res = compute(a, b, c, k)
    print(res)


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

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

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

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

Solution (Python):

def q2():
    A, B, C, K =  [int(i) for i in input().split(" ")]
    if K <= A:
        print(K)
        return
    if K <= A + B:
        print(A)
        return
    print(A+(K-(A+B))*-1)
    

q2()

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

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

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

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

print(ans-k)

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

Solution (Python):
a, b, c, k = 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
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
 
a,b,c,k = LI()

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

print(result)

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

print( min(a,k)+min(0,a+b-k))

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

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

Solution (Python):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

A, B, C, K = rl()

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

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

print(count)

Solution (Python):
import math
import fractions
import collections
import itertools
A,B,C,K=map(int,input().split())

print(1*min(A,K)+0*min(B,max(0,K-A))+(-1)*min(C,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:
  k-= b+a
  print(a-k)

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

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

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

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

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=map(int,input().split())
if k<=a:
    print(k)
elif a<k<=a+b:
    print(a)
else:
    n=k-a-b
    print(a-n)

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

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

A_ = min(A, K)
K -= A_
B_ = min(B, K)
K -= B_
C_ = min(C, K)

print(A_ * 1 + B_ * 0 + C_ * -1)

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

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

Solution (Python):



def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    

    def dump(*args):
        sys.stderr.write(str(args))

    a, b, c, k = map(int, input().split())
    at = min(a, k)
    nk = k-at
    bt = min(b, nk)
    nk = nk-bt
    ct = min(c, nk)
    print(at - ct)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

sumi = 0


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

print(sumi)

Solution (Python):
A, B, C, K = [int(x) for x in input().split()]
ans = 0
if K <= A:
    ans = K
elif K <= A + B:
    ans = A
else:
    ans = A - (K - A - B)

print(ans)

Solution (Python):

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect




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

ans = 0
ans += min(k, a)
k -= a
if k <= 0:
    print(ans)
    sys.exit()

k -= b
if k <= 0:
    print(ans)
    sys.exit()

ans -= k
print(ans)

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

if a + b >= k:
    saidai = min(a, k)
else:
    saidai = a - (k - (a + b))





print(saidai)

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

rest = K

a = min(A, rest)
rest = rest - a

b = min(B, rest)
rest = rest - b

c = min(C, rest)
rest = rest - c

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

res = min(a,k)
k -= a

if k>0:
    k -= b

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

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

print(ans)

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

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

print(cnt)

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

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