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())
ans = 0


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

if K > 0:
    if B >= K:
        print(ans)
        quit()
    else:
        K -= B

    if C >= K:
        ans -= K
        print(ans)
    else:
        ans -= C
        print(ans)

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

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

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

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

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

print(ans)

Solution (Python):

"""
Created on Sun May 10 20:50:47 2020
"""

import sys


sys.setrecursionlimit(10 ** 9)


mod = 10**9+7

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

elif a > k:
    ans += k
    k -= k

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

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

print(ans)

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

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

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

    print(ans)


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

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

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

n = K
ans = 0

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

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

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

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

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

if a>=k:

    total=1*k

else:
    total+=1*a

    k=k-a-b

    if k >0:

        total+=(-1)*k


print(total)

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

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

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

result=0

if A >= K:
    result = 1 * K

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

    else:
        result = (1 * A) + (0 * B) + (-1 * (K - A - B))

print(result)

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

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

print(solve())

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

S = 0
k = K


S += 1 * min(A, k)
k = max(k - A, 0)

k = max(k - B, 0)

S -= 1 * min(C, k)

print(S)

Solution (Python):
import numpy as np
import math
import scipy as sp
import queue
import collections

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

def main(kwargs):
    a = kwargs["a"]
    b = kwargs["b"]
    c = kwargs["c"]
    k = kwargs["k"]

    if k <= a:
        res = k
    elif k <= a + b:
        res = a
    else:
        res = 2 * a - k + b

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["a"], kwargs["b"], kwargs["c"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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

ans = 0
s = k - a

if s <= 0:
    print(1*k)
    exit()

ans = 1*a
s -= b

if s <= 0:
    print(ans)
    exit()

print(ans - s)

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

Solution (Python):


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





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

print(ans)

Solution (Python):
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions

t = [int(s) for s in stdin.readline().rstrip().split()]

if t[3] <= t[0]:
    print(t[3])
else:
    if t[3] <= t[0] + t[1]:
        print(t[0])
    else:
        if t[3] <= t[0] + t[1] + t[2]:
            print(t[0]-(t[3]-t[1]-t[0]))

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

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

Solution (Python):


def main():
    a, b, c, k = map(int, input().split())
    ret = 0

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

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

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

Solution (Python):
A,B,C,K=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 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(2*A + B - K)

Solution (Python):
import math

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

s = [(a, 1), (b, 0), (c, -1)]

ans = 0
for (i, v) in s:
    if k - i < 0:
        i = k
    ans += i * v

    k = k - i

    if k == 0:
        break

print(ans)

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

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

k-=b

ans-=max(0,k)


print(ans)

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

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

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

ret = min( A, K )
K -= A + B
if K > 0:
  ret -= min( K, C )

print( ret )

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

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

Solution (Python):
inputs = input().split(' ')
cnt_1 = int(inputs[0])
cnt_0 = int(inputs[1])
cnt_m1 = int(inputs[2])
cnts = int(inputs[3])

sum_card = 0
if cnt_1 >= cnts:
    sum_card = cnts
elif cnt_1 + cnt_0 >= cnts:
    sum_card = cnt_1
else:
    sum_card = cnt_1 - (cnts - cnt_1 - cnt_0)

print(sum_card)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a,b,c,k = m()



ans = 0

if a <= k:
    ans += a
    k -= a
    if b <= k:
        k -= b
        if k >= 0:
            ans -= k

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):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    A,B,C,K = LI()

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

    print(ans)

if __name__ == '__main__':
    main()

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

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

print(ans)

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

Solution (Python):





import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string


BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = 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(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")


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

def main():
    abck=list(map(int,input().split()))
    a,b,c,k=abck[0],abck[1],abck[2],abck[3]
    if k<=a+b:
        if k<=a:
            print (k)
        else:
            print (a)
    else:
        x=k-(a+b)
        print (a-x)
if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
import collections

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


ans=0

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

ans+=a
k-=a

if k<=b:
    print(ans)
    exit()

k-=b
ans-=k


print(ans)

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

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

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

print(ans)

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

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

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    if K <= A:
        print(K)
    elif A < K <= A+B:
        print(A)
    elif A+B < K:
        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):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    A, B, C, K = read_ints()
    if A >= K:
        return K
    K -= A
    if B >= K:
        return A
    K -= B
    return A-K


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

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

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

Solution (Python):

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

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

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

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

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

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

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


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

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


print(ans)

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

Solution (Python):
lis = list(map(int,input().split()))
Anum = min(lis[0],lis[3])
Bnum = max(min(lis[1],lis[3]-Anum),0)
Cnum = max(min(lis[2],lis[3]-Anum-Bnum),0)
print(Anum - Cnum)

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

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

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

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

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

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

Solution (Python):
import sys

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

if K <= A:
    print(K)
elif A < K <= A + B:
    print(A)
else:
    minus = A + B - K
    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 = list(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(1 * k)
elif k > a and k <= a + b:
  print(a * 1)
else:
  print(a * 1 + ((k - a - b) * -1))

Solution (Python):
INT_MAX=10**19+7
MOD=10**12+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]

a,b,c,k=INPUT()
ans=0
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 k <= a:
    print(k)
elif a < k <= a+b:
    print(a)
else:
    print(a-(k-a-b))

Solution (Python):
inpt = input()
inpts = inpt.split()
a = int(inpts[0])
b = int(inpts[1])
c = int(inpts[2])
k = int(inpts[3])

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

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

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

print(ans)

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

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

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

print(ans)

Solution (Python):
i = list(map(int, input().split()))
a = i[0]
b = i[1]
c = i[2]
k = i[3]
if k<=a:
    print(k)
elif a < k<=a+b:
    print(a)
elif a+b < k<=a+b+c:
    d = k - (a+b)
    print(a-d)
else:
    print(a-c)

Solution (Python):
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    A,B,C,K=map(int,input().split())
    if K<=A:
        print(K)
    else:
        if (K-A)<=B:
            print(A)
        else:
            print(2*A+B-K)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

import sys
input = sys.stdin.readline

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

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

else:
    c_no = k-(a+b)
    print(a-c_no)

Solution (Python):

"""
Created on Sun May 10 20:54:25 2020

@author: Kanaru Sato
"""

a,b,c,k = list(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) = tuple(map(int, input().split(" ")))
print(min(a, k) - max(0, k - b - a))

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 = [int(n) for n in input().split()]

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

print(ans)

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

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

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

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

print(ans)

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

result = 0
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=list(map(int,input().split()))
li=[[1,0,-1],[a,b,c]]
ans=0
for i,l in enumerate(li[1]):
  if k < l:
    ans += li[0][i]*k
    break
  ans += li[0][i]*l
  k -= l
  
print(ans)

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

x=0
y=0
if(a>=k):
    x=k
    k=0
else:
    x=a
    k=k-a
if(b>=k):
    k=0
else:
    k=k-b
if(c>=k):
    y=k
    k=0
print(x-y)

Solution (Python):
def b167(a, b, c, k):

    ans = 0

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

if __name__ == '__main__':
    main()

Solution (Python):
A,B,C,K = list(map(int , input().split()))
nokori = K 
WA = 0
if K <= A:
    WA = K
elif K > A:
    nokori -=A
    WA += A
    if nokori >B:
        nokori -= B
        WA -=nokori

print(WA)

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

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

x = 0
if K < A:
  x += K
if K >= A:
  x += A
if K-A-B >= 0:
  x -= K - A - B
print(x)

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

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

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

ans = 0

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

print(ans)

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

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

sum = 0

if K >= A:
    sum += A
    K -= A
else:
    sum += K

K -= B

if K >= 0:
    sum += K * -1

print(sum)

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

Solution (Python):




def main():

    
    first_input = list(map(lambda x:int(x), input().split(" ")))
    

    
    
    

    
    

    A = first_input[0]
    B = first_input[1]
    C = first_input[2]
    K = first_input[3]

    nokori_K = K

    if A>=nokori_K:
        print(nokori_K)
        return
    else:
        if B>=(nokori_K-A):
            print(A)
            return
        else:
            print(A-(nokori_K-A-B))
            return


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys

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

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

Solution (Python):
*a, k = map(int, input().split())
res = 0
i = 1
for x in a:
	c = min(k, x)
	k -= c
	res += c * i
	i -= 1

print(res)

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

m = a if a < k else k
m -= max(k - (a + b), 0)

print(m)

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

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

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

Solution (Python):
pi = 3.1415926


def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))

a,b,c,k = invr()
ans = 0
if k > a:
    ans += a
    k -= a
    if k > b:
        k -= b
        ans += -1*(k)
        print(ans)
    else:
        print(ans)
        
else:
    print(k)

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

Solution (Python):
import numpy as np
import sys
import math

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

counter = 1
ans = 0

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

Solution (Python):

import collections
import itertools as it
import math

 


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
else:
    print(ans - k)
    exit()

print(ans)

Solution (Python):

"""
@author: H_Hoshigi
"""
def main():
    A, B, C, K = map(int, input().split())
    answer = 0
    if K <= A:
        answer = K
    elif K <= A+B:
        answer = A
    else:
        answer = A - (K -A -B)
    print(answer)

if __name__ == "__main__":
    main()

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


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

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

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