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(" ")))
ans=0
if(k>0):
	ans+=min(a,k)
	k-=min(a,k)
if(k>0):
	
	k-=min(b,k)
if(k>0):
	ans-=min(c,k)
	k-=min(c,k)
print(ans)

Solution (Python):
def solve(A, B, C, K):
    count = 0
    a = min(A, K)
    count += a
    K -= a
    b = min(B, K)
    K -= b
    c = min(C, K)
    count -= c
    K -= a
    return count

if __name__ == "__main__":
    A, B, C, K = tuple(map(int, input().split(" ")))

    print(solve(A, B, C, 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):
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a, b, c, K = MAP()

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

ans = 0
ans += 1 * min(k, a)

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

Solution (Python):
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

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

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

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

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

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    ans = 0
    for x, y in ((1, A), (0, B), (-1, C)):
        z = min(y, K)
        ans += x * z
        K -= z
    return ans




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))  
    print(solve(A, B, C, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):

import sys

buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, C, K):
    ans = 0
    na = min(A, K)
    K -= na
    ans += na
    nb = min(B, K)
    K -= nb
    nc = min(C, K)
    ans -= nc

    return ans


def main():
    A, B, C, K = read_int_n()
    print(slv(A, B, C, K))


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

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

ret = 0

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

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

print(ret)

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

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a,b,c,k=MI()
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:
    print(A + (K - A - B) * -1)

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

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

ans = 0

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

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

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

print(ans)

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

if K > 0:
	if B >= K:
		K = 0
	else:
		K -= B
if K > 0:
	ans -= K

print(ans)

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

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

print(ans)

Solution (Python):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Solution (Python):
[A,B,C,K] = list(map(int,input().split()))
out = 0
X = min(K,A)
Y = min(K-X,B)
Z = min(K-X-Y,C)
print(1*X-1*Z)

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

Solution (Python):
def printend(t):
    print(t)
    exit()

A,B,C,K = [int(hoge) for hoge in input().split()]
if A>K:
    printend(K)
elif A+B>K:
    printend(A)
else:
    printend(A - (K-A-B))

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

left = k
ret = 0

if a >= k:
    ret = k
else:
    ret = a
    left = k - a
    if b < left:
        ret -= (left - b)

print(ret)

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

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

Solution (Python):
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq

a, b, c, k = map(int, sys.stdin.readline().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<=a+b:
    print(a)
else:
    print(a-(k-(a+b)))

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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    A, B, C, K = map(int, readline().split())
    if K<=A:
        print(K)
    elif A<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())

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

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

Solution (Python):
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

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

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

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


a, b, c, k = sp()
answer = min(a, k)
k -= min(a, k)
if k > 0:
    k -= min(b, k)
    if k > 0:
        answer -= k
out(answer)

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

Solution (Python):

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

Solution (Python):






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

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

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

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

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

Solution (Python):




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

  if K > 0:
    c -= K

  print(c)


if __name__ == '__main__':
  main()

Solution (Python):
'''بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ'''

gi = lambda : list(map(int,input().split()))
a, b, c, k = gi()
ans = min(a, k)
k -= min(a, k)
k -= min(b, k)
ans -= min(c, k)
print(ans)

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

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

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

ans = 0
ans = min(A, K)
K -= A
if K > 0:
    K -= B
    if K > 0:
        ans += -1 * K

print(ans)

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

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

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

Solution (Python):
a,b,c,d=map(int,input().split())
if a+1+b>d:
  print(min(a,d))
else:
  print(a-(d-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())

li = [a, b, c]

ans = 0
for i, e in enumerate(li):
    cnt = min(k, e)

    ans += (1 - i) * cnt
    k -= cnt

print(ans)

Solution (Python):
import sys

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

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

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

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

ans = 0
mn =  min(A,K)
K -= mn
ans += mn

mn =  min(B,K)
K -= mn

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

Solution (Python):
import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c,k=INTM()
    if a>=k:
        print(k)
    elif a<=k<=a+b:
        print(a)
    else:
        print(a-(k-(a+b)))
    
if __name__ == '__main__':
    do()

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

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


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

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

Solution (Python):
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
rl = sys.stdin.readline

A,B,C,K  =Ints()

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

ans = 0

k = min(K, A)
ans += k
K -= k

k = min(K, B)
K -= k

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

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):
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):
a, b, c, k = list(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 = [int(i) for i in input().split(' ')]
if k <= a:
  print(1 * k)
elif k <= a + b:
  print(1 * a)
else:
  print(1 * a + (k - a - b) * -1)

Solution (Python):
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

a,b,c,k=l_in()

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

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

a, b, c, k = [int(x) for x in 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):
import sys
input = sys.stdin.readline
A, B, C, K = map(int, input().split())
res = 0
if A <= K:
  res += A
  K -= A
else:
  res += K
  K = 0

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

res -= K
print(res)

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

main()

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

print(ans)

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

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

ans = 0

a1 = min(a, d)
d = max(d-a, 0)

ans += a1

if(d > 0):
    d = max(d-b, 0)
    if (d > 0):
        ans -= d


print(ans)

Solution (Python):
a, b, c, k = [int(i) for i in 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):
def main():
    A, B, C, K = (int(_) for _ in input().split())
    if K <= A:
        return K
    elif K <= A + B:
        return A
    else:
        return A - (K - A - B)

if __name__ == '__main__':
    print(main())

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

if __name__=='__main__':
    main()

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

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

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

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

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

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

remain = k

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

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 a>=k:
  print(k)
  exit()

ans=a
k-=a
k-=b

if k>0:
  ans-=k

print(ans)

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

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

ans = 0

ans += min(A, K)

K -= (A + B)

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

print(ans)

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

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

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

Solution (Python):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter

from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

a, b, c, k = inpl()
ans = 0
if k < a:
    print(k)
    exit()
if k < a + b:
    print(a)
    exit()
print(a-(k-a-b))

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

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

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

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

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

ans = 0

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

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

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

print(ans)

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

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

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

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

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

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

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(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(min(a,k)-max(0,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().strip().split())
ans = 0
if k>0:
    ans += min(k,a)
    k -= min(k,a)
if k>0:
    k -= min(k,b)
if k>0:
    ans -= min(k,c)
    k -= min(k,c)
print(ans)

Solution (Python):
a,b,c,k=map(int,input().split())
if a>=k:
    print(k)
elif a+b>=k:
    print(a)
else:
    print(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
import math  
import bisect  
import queue  


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


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

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

    print(res)


if __name__ == '__main__':
    main()

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

Solution (Python):

import collections


def solve(a, b, c, k):
    ans = 0
    ans += min(a, k)
    k -= min(a, k)

    if k == 0:
        return ans

    k -= min(b, k)

    if k == 0:
        return ans

    return ans - k


[a, b, c, k] = list(map(int, input().strip().split()))
print(solve(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= list(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+B):
  print(min(A,K))
else:
  print(A-(K-A-B))

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

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

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

Solution (Python):


from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

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


yes = "Yes"
no = "No"

def main():
    a,b,c,k = mi()
    ans = 0
    ans+=min(a,k)
    k-=a
    if k<=0:
        print(ans)
        exit()
    k-=b
    if k<=0:
        print(ans)
        exit()
    print(ans-k)





main()

Solution (Python):
def main():

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

if __name__ == '__main__':
    print(main())

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


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

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

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

k -= b

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

print(ans)

Solution (Python):

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

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

ans =0

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