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

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

Solution (Python):
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    a, b, c, k = rl()
    if a >= k:
        print (k)
    elif a + b >= k:
        print (a)
    else:
        rem = k - a - b
        print (a - rem)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

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

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

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

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

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

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

prod = 0

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

print(prod)

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

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

Solution (Python):
import sys

a, b, c, k = map(int, sys.stdin.readline().split())
if a >= k:
  print(k)
elif a + b >= k:
  print(a)
else:
  
  print(a + a + b - k)

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

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

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

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

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

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

Solution (Python):
A,B,C,K=(int(x) for x in input().split())
remain_A = K-A
if remain_A<=0:
    print(K)
else:
    remain_B = remain_A - B
    if remain_B <= 0:
        print(A)
    else:
        ans = (A*1) + (B*0) + (remain_B * (-1))
        print(ans)

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

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

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,c,k = inpl()
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
elif K <= A + B:
  ans = A
else:
  ans = 2 * A - K + B
print(ans)

Solution (Python):
A, B, C, K = map(int, input().split())
total = 0
if A >= K:
    print(K)
    exit(0)
elif A != 0:
    K = K - A
    total = A

if B >= K:
    print(total)
    exit(0)
elif B != 0:
    K = K - B

print(total-K)

Solution (Python):
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
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)
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 + B >= K:
    print(A)
else:
    print(A - (K - A - B))

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a,b,c,k = readInts()
ans = 0
if a >= k:
    print(k)
    exit()
else: 
    k -= a
    ans += a
    if b >= k:
        print(ans)
        exit()
    else: 
        k -= b
        ans -= k
print(ans)

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

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

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

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

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())
print(min(k,a)-max(k-a-b,0))

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

if __name__ == "__main__":
    main()

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

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

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

print(ans)

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

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

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

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

while k > 0:
    if a <= k:
        sum += a
        k -= a
        if k <= 0:
            break
    else:
        sum += k
        break

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

    if  c <= k:
        sum -= c
        k -= c
        if k <= 0:
            break
    else:
        sum -= k
        break
    

print(sum)

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

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

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

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

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

nokori = k - a

if nokori <= 0:
    print(k)
    sys.exit()

nokori = nokori - b

if nokori <= 0:
    print(a)
    sys.exit()

print(a - nokori)

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

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

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

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

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

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

Solution (Python):
A,B,C,K = map(int, input().split())
a=min(A,K)
b=min(B,K-a)
c=min(C,K-a-b)
print(a-c)

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

ans = a - k

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

	else:
		ans = abs(ans)
		print(a-ans)

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

    while True:
        if (a < d):
            sum = a
            d -= a
        else:
            sum = d
            break

        if (b < d):
            d -= b
        else:
            break
        sum -= d
        break

    print(sum)


if __name__ == "__main__":
    main()

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

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

print(sum)

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

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

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

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

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

if k > 0:
    ans = ans + k*(-1)

print(ans)

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

Solution (Python):
A,B,C,K=[int(i) for i in input().split()]
if K<A:
    P=K
else:
    P=A
    if A+B<K:
        P-=(K-(A+B))
print(P)

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

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

total = 0
for target, point in [(a,1),(b,0),(c,-1)]:
    num = min(target, k)
    k -= num
    total += point * num
    if k <= 0:
        break

print(total)

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

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

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

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

Solution (Python):
def solve(A, B, C, K):
  card_counts = [A,B,C]
  card_points = [1,0,-1]
  card_remain = K
  max_point = 0
  
  for i in range(3):
    if card_remain > card_counts[i]:
      card_remain -= card_counts[i]
      max_point += card_counts[i] * card_points[i]
    else:
      max_point += card_remain * card_points[i]
      break
  return max_point

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

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

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

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

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

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

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

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

print(a-k)

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

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

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

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

    ans = 0
    if K <= A:
        ans = K
        return ans
    else:
        ans = A
        K -= A

    if K <= B:
        return ans
    else:
        K -= B

    ans += K*(-1)

    return ans

print(main())

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

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

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

elif K - A < 0:
    print(1 * K)

elif K - A - B <= 0:
    print(1 * A)

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

ans = 0

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

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

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

print(ans)

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


if K >= B:
    K = K-B


if K != 0:
    ans = ans-K


print(ans)

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

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

Solution (Python):
a,b,c,k = map(int, input().split())
if k<=a:
  print(k)
  exit()
if a+b>=k:
  print(a)
  exit()
else:
  minus=k-(a+b)
  ans=a-minus
  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 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 = []
numA = min([A, K])
numB = min([B, K - numA])
numC = K - numA - numB 

print(numA - numC)

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

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

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

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

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

Solution (Python):

list_all=list(map(int,input().split()))
if list_all[0]>=list_all[3]:
    print(list_all[3])
elif list_all[0]+list_all[1]>=list_all[3]:
    print(list_all[0])
else:
    print(list_all[0]-(list_all[3]-list_all[0]-list_all[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())
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())
res = 0
one = min(k, a)
res += one
k -= one

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

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

print(res)

Solution (Python):

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

    print(ans)
    return
    
main()

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

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

Solution (Python):

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

Solution (Python):


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

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

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

ans = 0

if k <= a:
  ans = k
elif a < k <= a+b:
  ans = a
elif k > a+b:
  ans = 2 * a - k + 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)
elif a+b < k:
    print(a - (k-a-b))

Solution (Python):
A, B, C, K = list(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):
import sys 
from collections import deque
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def Main():
    a,b,c,k = IL()
    ta = min(k,a)
    tb = min(k-ta,b)
    if tb<0:    tb = 0
    tc = k-ta-tb
    print(ta-tc)
    return

if __name__=='__main__':
    Main()

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

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

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







sum_num = []
card_num = [1,0,-1]
for i,card in enumerate(a[0:3]):
  if card > a[3]:
    sum_num.append(a[3] * card_num[i])
    a[3] -= a[3]
  else:
    sum_num.append(card * card_num[i])
    a[3] -= card
print(sum(sum_num))

Solution (Python):
def main():
    a, b, c, k = map(int, input().split())
    if k <= a: 
        return k
    if a < k <= a+b:
        return a
    if a+b < k <= a+b+c:
        return a + (k - a-b)*(-1)

print(main())

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


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

ans = 0

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

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

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


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

if __name__ == '__main__':
    main()

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

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

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

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

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

if K > A:
    print(2*A+B-K)
else:
    print(K)

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

if A >= K:
  print(K)

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

Solution (Python):

"""AtCoder Beginner Contest 167: B - Easy Linear Programming
https://atcoder.jp/contests/abc167/tasks/abc167_b
"""


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

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

    print((a * 1) + (b * 0) + (c * -1))


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

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

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

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

if a >= k:
    print(k)
elif (a+b) <= k:
    print(2*a + b - k)
elif (a+b) >= k and a <= k:
    print(a)

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

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

if 0 < 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 A < K:
    res = A
    K = K - A
elif K <= A:
    res = K
    K = 0
if 0 < K and B < K:
    K = K - B
elif 0 < K and K <= B:
    K = 0
if 0 < K:
    res = res - K 
print(res)

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

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

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

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

if __name__ == "__main__":
    main()

Solution (Python):
S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
K = int(S[3])
a = min(K, A)
if K >= A:
  a = a + min(K-A, B)*0
  if K-A >= B:
    a = a - min(K-A-B, C)
print(a)

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

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

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

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

print(ans)

Solution (Python):
a, b, c, k = map(int, input().split())
p = min(a,k)
k -= p
s = min(b,k)
k -=s
q = min(c,k)

print(p - q)

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

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

else:
    ans = k

print(ans)

Solution (Python):
A, B, C, K = map(int, input().split())
P = min(A, K)
Q = min(B, K-P)
R = K-P-Q
print(P-R)

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

ans = 0

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

else:
    ans += K

print(ans)

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

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

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

Solution (Python):
def Easy_Linear_Programming():
    cards_reguration = input()
    cards = cards_reguration.split()
    A = int(cards[0])
    B = int(cards[1])
    C = int(cards[2])
    K = int(cards[3])
    
    point = 0
    
    if A > 0:
        if A >= K:
            point = K
            print(point)
            return
        else:
            point = A
            K -= A
            if K <= 0:
                print(point)
                return
        
    if B > 0 and K > 0:
        K -= B
        if K <= 0:
            print(point)
            return
        
    if C >= 0 and K > 0:
        point -= K
        print(point)
        return
            
    
Easy_Linear_Programming()

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

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

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