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

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

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

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

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

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

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

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

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

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

if K < A:
	print(K)
elif 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 -1*(k-a-b))

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

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

Solution (Python):
def main():
    a, b, c, k = (int(i) for i in input().split())
    ans = min(a, k)
    k -= a
    if k <= 0:
        print(ans)
        return
    k -= b
    if k <= 0:
        print(ans)
        return
    print(ans - k)


if __name__ == '__main__':
    main()

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

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

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

if __name__ == "__main__":
    solve()

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

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

print(max)

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

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

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

    if A >= K:
        print(K)

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


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

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

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

Solution (Python):


import math

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

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

    positive = min(k, a)
    zero = min(k - positive, b)
    negative = min(k - positive - zero, c)

    max = positive - negative
    print(max)


if __name__ == '__main__':
    main()

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

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

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

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

s = 0

mn = min(A, K)
s += mn 
K -= mn

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

mn = min(C, K)
s -=mn
K -= mn

print(s)

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

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

Solution (Python):
def main():
    s = list(map(int,input().strip().split()))
    k = s[3]
    r = 0
    if s[0] <= k:
        r += 1 * s[0]
        k -= s[0]
    else:
        r += 1 * k
        print(r)
        return
    
    if (k-s[1]) <=0:
        print(r)
        return
    
    if s[2] <= (k-s[1]):
        r += (-1)*s[2]
    else:
        r += (-1) * (k-s[1])
    
    print(r)
    return
    
    
main()

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

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

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

    ra = min(k, a)
    k -= ra
    k -= b
    rc = 0 if k <= 0 else -(min(k, c))
    print(ra + rc)


if __name__ == '__main__':
    Qb()

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

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

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

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

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

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

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


if __name__ == "__main__":
    resolve()

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

Solution (Python):
if __name__ == '__main__':
    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):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    a, b, c, k = map(int, input().split())
    r = min(k, a)
    k -= a
    if k > 0:
        k -= b
        if k > 0:
            r -= k
    print(r)

if __name__ == '__main__':
    main()

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

res = 0
if K <= A:
    res = K
elif K <= B:
    res = A
else:
    res = A - (K - A - B)

print(res)

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

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

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

Solution (Python):
A, B, C, K = [int(i) for i in input().split(' ')]
print(min(A, K) - max(K - B - A, 0))

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

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

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

ans+=(-1)*k
print(ans)

Solution (Python):
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

a, b, c, k = Is()

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

b = min(b, k)
k -= b

c = min(c, k)
k -= c

print(a-c)

Solution (Python):
*abc, k = map(int, input().split())
n = [0] * 3
for i, v in enumerate(abc):
    if k >= v:
        n[i] = v
        k -= v
    else:
        n[i] = k
        break

print(n[0] + n[2] * -1)

Solution (Python):
*abc, k = list(map(int, input().split()))
n = [0] * 3
ans = 0
for i, v in enumerate(abc):
    if k >= v:
        n[i] = v
        k -= v
    else:
        n[i] = k
        break

print(n[0] + n[1] * 0 + n[2] * -1)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

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

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

print(ans)

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

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

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

print(ans)

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

score = 0
if K <= A:
    score = K
    print(score)
    exit()

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

K -= B
print(score - K)

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

import sys

ans = 0
if a != 0 and a >= k:
    
    print(k)
    sys.exit()
elif a != 0:
    ans += a
    k -= a

if b != 0 and b >= k:
    print(ans)
    sys.exit()
elif b != 0:
    k -= b

ans += k * -1
print(ans)

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

Solution (Python):

def main():
    import sys

    input = sys.stdin.readline

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

Solution (Python):
A, B, C, K = list(map(lambda x : int(x), 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):
    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())
print(k if k<a else(a if a+b>=k else 2*a-k+b))

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

def some(a,b,c,k):
    x_a = min(k, a)
    k -= x_a
    x_b = min(k, b)
    k -= x_b
    x_c = k
    print(x_a*1+x_b*0+x_c*-1)

some(a,b,c,k)

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

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

cnt = 0
if k > a:
    cnt += a
    if k-a > b:
        if k-a-b > 0:
            cnt -= k-a-b
else:
    cnt += k

print(cnt)

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

Solution (Python):
IN = [i for i in map(int,input().split())]
K = IN[3]
A = min(IN[0],K)
B = min(IN[1], K -A)
C = min(IN[2],K -A- B)
print(A*1+B*0+C*(-1))

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

if a-k <= 0:
    a_ans = a
    k = k-a
else:
    a_ans = k
    k=0
if b-k <= 0 and k>0:
    b_ans = b
    k = k-b
else:
    b_ans = k
    k=0
if c-k <= 0 and k>0:
    c_ans = c
    k = k-b
else:
    c_ans = k
    
ans = a_ans*1 + b_ans*0 + c_ans*(-1)
print(ans)

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

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

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

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

Solution (Python):
score = list(map(int,input().split()))
answer = 0
if score[3] - score[0] <= 0:
    answer += score[3]
else:
    answer += score[0]
    if score[3] - score[0] - score[1] > 0:
        answer -= score[3] - score[0] - score[1]
print(answer)

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

    if K<A+B:
        if K<A:
            print(K)
            return
        print(A)
        return
    print(A-(K-A-B))
    return

score()

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

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


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

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

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

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

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

score = 0

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

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

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

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=map(int,input().split())
ans=0
if K>A:
    K-=A
    ans+=A
else:
    ans+=K
    print(ans)
    exit()
if K>B:
    K-=B
else:
    print(ans)
    exit()
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):
import sys
readline = sys.stdin.readline

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

print(min(a,K) - max(K - (a + b),0))

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

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

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


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

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

c = min(C, K)

print(1 * a + -1 * c)

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())
s0m = 0
x = max(0,A-K)
if x == 0 :
    s0m =+ A
    K = K-A
else :
    s0m =+ K
    K=0
if K==0 :
    print (s0m)
else :
    y = max (0 ,B-K)
    if y == 0 :
        K=K-B
    else :
        K = 0
    if K == 0:
        print (s0m)
    else:
        z = max (0,C-K)
        if z== 0 :
            s0m = s0m - C
        else :
            s0m -=K
        print (s0m)

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

print(k if k<a else a if a+b>k else a-(k-a-b))

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

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

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

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

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

print(ans)

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

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

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
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()


A, B, C, K = inpl()
xa = min(K, A)
K -= xa
xb = min(K, B)
K -= xb
xc = K
print(xa-xc)



end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Solution (Python):


def main():

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

    ans = 0

    if K <= A:
        ans = K

    else:
        if K <= A + B:
            ans = A

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

    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):













































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    
    A, B, C, K = list(map(int, lines[0].split()))
    
    
    
    
    
    
    
    

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

    return [result]



def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2 1 1 3']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['1 2 3 4']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['2000000000 0 0 2000000000']
        lines_export = [2000000000]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

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

a = min(A, K)
K -= a
b = min(B, K)
K -= b
c = min(C, K)

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

Solution (Python):


from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(A: int, B: int, C: int, K: int):
    return min(K, A) - max(K-A-B, 0)


def main():

    sys.setrecursionlimit(10 ** 6)

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


if __name__ == '__main__':
    main()

Solution (Python):




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

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

Solution (Python):
import sys
A,B,C,K=map(int, sys.stdin.readline().split())
ans=0
a_cards=min(K,A)
K-=a_cards
ans+=a_cards*1

b_cards=min(K,B)
K-=b_cards
ans+=b_cards*0

c_cards=min(K,C)
K-=c_cards
ans+=c_cards*-1

print ans

Solution (Python):
import sys

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

if not ( 0 <= A and 0 <= B and 0 <= C ): sys.exit()
if not ( 1 <= K <= A+B+C and A+B+C <= 2 * 10**9 ): sys.exit()

sum = 0
if A >= 1 and K <= A:
    print(K)
    sys.exit()
elif A >= 1 and K > A:
    sum += A
    K -= A
    A = 0

if B >= 1 and K <= B:
    print(sum)
    sys.exit()
elif B >= 1 and K > B:
    K -= B
    B = 0

if C >= 1 and K <= C:
    sum -= K
    C = 0
elif C >= 1 and K > C:
    sum -= C
    print(sum)
    sys.exit()

print(sum)

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

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

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

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

Solution (Python):
import sys

ans=0
A, B, C, K = (int(x) for x in input().split())

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

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

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

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

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

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

Solution (Python):
A,B,C,K = [int(x) for x in input().split()]
result = 0
if K > A:
    result += A
else:
    print(K)
    exit()

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

print(result - (K - A - B))

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

Solution (Python):
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

a, b, c, k = LI()




x = k - a
y = x - b
z = y - c

if x <= 0:
    print(k)
    sys.exit()
elif (x > 0) and (y <= 0):
    print(a)
    sys.exit()
elif (y > 0):
    print(a - y)
    sys.exit()

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

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

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

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

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

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

count = 0
if a < k:
    count += a
    if a+b < k:
        count -= k-a-b
else:
    count = k

print(count)

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


sum = 0
rest_k = k

if rest_k <= a:
    sum += rest_k
    rest_k = 0
else:
    sum += a
    rest_k -= a

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

sum -= rest_k

print(sum)

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