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

Solution (Python):

def input_from_console():
    a, b, c, k = map(int, input().split())
    return a, b, c, k


def solve(a, b, c, k):
    sum = 0
    if k < a:
        return k
    else:
        k = k - a
        sum = a
    if k < b:
        return sum
    else:
        k = k - b
    sum -= k
    return sum

def main():
    a, b, c, k = input_from_console()
    print(solve(a, b, c, k))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  
        check_cases()
    else:
        main()

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

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

total = 0

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

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

if K <= C:
    total -= K
else:
    total -= C

print(total)

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


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

else:
    sum = k

print(sum)

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

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

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

ans = 0

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

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

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

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

Total=()

if K<=A:
      print(K*1)
else:
      Total = A

K=K-A

if K<=B and K>0:
      print(Total)

K=K-B

if K<=C and K>0:
      Total = Total + (K*-1)
      print(Total)

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

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

else:
	k-=a
	sum+=a
	if k>0:
		k-=b
		sum=a
	else:
		print(sum)
	if k>0:
		k=abs(k-c)
		print(sum-c+k)
	else:
		print(sum)

Solution (Python):
A,B,C,K=map(int,input().split())
a=A;b=B;c=C;p=0

if K<=a:
  p=p+K
  print(p)
else:
  p=p+a
  if (K-a)<=b:
    p=p+(K-a)*0
    print(p)
  else:
    p=p+b*0
    if (K-a-b)<=c:
      p=p+(K-a-b)*-1
      print(p)
    else:
      p=p+c*-1

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

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

if S[0] >= S[3]:
  print(S[3])
elif S[0]+S[1] >= S[3]:
  print(S[0])
else:
  print(S[0]-(S[3]-S[0]-S[1]))

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




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

print(ans)

Solution (Python):

import sys
from collections import Counter
def main():
    a, b, c, k = map(int, input().split())
    r = 0
    if a >= k:
        print(k)
        sys.exit()
    else:
        r += a
        k -= a
    if b >= k:
        print(r)
        sys.exit()
    else:
        k -= b
    r -= min(k, c)
    print(r)


if __name__ == '__main__':
    main()

Solution (Python):
X=input().split(" ")
A=int(X[0])
B=int(X[1])
C=int(X[2])
K=int(X[3])
if K<=A:
  print(K)
elif K<=A+B:
  print(A)
else:
  print(2*A+B-K)

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

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

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

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

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

ans=0

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

Solution (Python):
if __name__ == '__main__':
    S = input().split()
    A = int(S[0])
    B = int(S[1])
    C = int(S[2])
    K = int(S[-1])

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

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

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

if K == 0:
    print(ans)
    exit()

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

if K == 0:
    print(ans)
    exit()


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

print(ans)

Solution (Python):
A,B,C,K = (int(x) for x in input().split())
if A >= K:
    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(2*A + B - K)

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

if A >= K:
  sum = K
else:
  sum = A
  if B >= K - A:
    pass
  else:
    if C >= K - A - B:
      sum -= K-A-B

print(sum)

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

print(sum)

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

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

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

Solution (Python):

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

max = 0

if a < k:
    max = a
    k -= a
    if 0 < k:
        k -= b
        if 0 < k:
            max -= k

else:
    max = k


print(max)

Solution (Python):
val = input()
val = val.split(" ")
val = [int(i) for i in val]  

ans = 0


if(val[0] > val[3]):
    ans = 1 * val[3]
    print(ans)
elif((val[0] >= val[3]) or (val[0]+val[1] >= val[3])):
    ans = 1 * val[0]
    print(ans)
else:
    ans = 1 * val[0] - 1*(val[3]-val[0]-val[1])
    print(ans)

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

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_rpw_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    a, b, c, k = i_map()

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

    k -= a

    k -= b

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

    print(a-k)


if __name__ == '__main__':
    main()

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

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

k-=a

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

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

if c<=k:
    ans-=c
else:
    ans-=k
print(ans)

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

suml = 0
while k > 0:
    if a > 0:
        tmpm = min(a, k)
        a -= tmpm
        k -= tmpm
        suml += tmpm
    elif b > 0:
        tmpm = min(b, k)
        b -= tmpm
        k -= tmpm
    else:
        tmpm = min(c, k)
        c -= tmpm
        k -= tmpm
        suml -= tmpm


print(suml)

Solution (Python):
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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


def main():
	A, B, C, K = getlist()
	if K < A:
		print(K)
	elif A + B >= K:
		print(A)
	else:
		print(2 * A + B - K)
	




if __name__ == '__main__':
	main()

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

goukei = 0

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

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

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

sum_value = 0
count = k

if count >= a:
    sum_value += (1 * a)
    count -= a
else:
    sum_value += (1 * count)
    count -= count
    
if count >= b:
    sum_value += (0 * b)
    count -= b
else:
    sum_value += (0 * count)
    count -= count
    
if count >= c:
    sum_value += (-1 * c)
    count -= c
else:
    sum_value += (-1 * count)
    count -= count
    
print(sum_value)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    a, b, c, k = MI()
    

    aa = min(a, k)
    
    k -= aa
    bb = min(b, k)
    
    k -=bb
    cc = min(c, k)
    
    print(aa - 1 * cc)


if __name__ == '__main__':
    solve()

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

weight = [1, 0, -1]

sumAns = 0

for i in range(3):
    sumAns += lNum[i] * weight[i] if lNum[i] <= lNum[3] else lNum[3] * weight[i]
    lNum[3] -= lNum[i]
    if(lNum[3] <= 0):
        break
    
print(sumAns)

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

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

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

ans = 0

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

print(ans)

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys

INF = 10 ** 17

def check(books, x, i, m, n):
    ab = [0 for i in range(m)]
    ret = 0
    for k in range(n):
        if i % 2 == 1:
            book = books[k]
            for tab, b in enumerate(book[1:]):
                ab[tab] += b
            ret += book[0]
        i //= 2
    
    for cab in ab:
        if cab < x:
            return INF

    return ret

def main():
    a,b,c,k  = getList()
    if k <= a:
        print(k)
        return

    elif k <= a + b:
        print(a)
        return

    else:
        print(a - (k - a - b))
        return
if __name__ == "__main__":
    main()

Solution (Python):

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

res=0

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

print(res)

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

d = k-a
if d == 0:
  print(a)
elif d < 0:
  print(k)
elif d > 0:
  if b >= d:
    print(a)
  else:
    i = d-b
    print(a-i)

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

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
A, B, C, K = map(int, readline().split())

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

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

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

elif a < k:
    if b >= k-a:
        total = a
    elif b < k-a:
        total = a - (k-a-b)
print(total)

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

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

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

Solution (Python):
a,b,c,k=list(map(int,input().split()))
if a>=k:
    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 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:
    ans = min(K, 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):
tmp = input().split()
A = int(tmp[0])
B = int(tmp[1])
C = int(tmp[2])
K = int(tmp[3])

remainCard = K

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

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

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())
num = K
score = 0
if A >= num:
    score = K
else:
    num -= A
    score += A
    if B >= num:
        pass
    else:
        num -= B
        score -= num
print(score)

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.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

ans = 0
if K <= A:
    print(K)
    quit()
K -= A
ans = A
if K <= B:
    print(ans)
    quit()
K -= B

ans -= (1 * K)
print(ans)

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

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

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

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

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

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

max_num = 0

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

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

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

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

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

number_of_A = min(A, K)
remainder = K - number_of_A

number_of_B = min(B, remainder)
remainder = remainder - number_of_B

number_of_C = remainder

total = (number_of_A * 1) + \
    (number_of_B * 0) + \
    (number_of_C * -1)

print(total)

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

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


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

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())
count=0
if a>=k:
  print(k)
else:
  n=k-a
  count=a
  if b>=n:
    print(a)
  else:
    m=n-b
    if c>=m:
      l=c-m
      p=k-a-b
      print(a-p)
    else:
      print(a-c)

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

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

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

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

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

if k>=a:
  tmp = k-a
  result = 1*a
else:
  result = 1*k
 
if tmp>=b:
  tmp = tmp-b

if tmp>=c:
  result += (-1)*c
else:
  result += (-1)*tmp
  
print(result)

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

def main(a,b,c,k):
    if(a>=k):
        return k
    k2=k-a
    if(b>=k2):
        return a
    k3=k2-b
    return a-k3
    

if __name__=='__main__':
    a,b,c,k=readinput()
    ans=main(a,b,c,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(k - b)
elif (k - a - b - c) == 0:
    print(a - c)
else:
    print(a - ( k - a - b))

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

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

Solution (Python):
*card, K = map(int, input().split())


v = [1, 0, -1]

total = 0
for idx, c in enumerate(card):
    if K == 0:
        break
    if c <= K:
        K -= c
        total += v[idx] * c
    else:
        total += K * v[idx]
        K = 0
print(total)

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

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

Solution (Python):
all = input()
A = int(all.split(' ')[0])
B = int(all.split(' ')[1])
K = int(all.split(' ')[3])
if K >= A+B:
	print(A*2+B-K)
else:
	print(K)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    a, b, c, k = map(int, readline().split())
    if (0 <= k) and (k <= a):
        print(k)
    elif (a < k) and (k <= a+b):
        print(a) 
    elif (a+b < k) and (k <= a+b+c):
        print(a-(k-(a+b)))
    else:
        print(a+c)
if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    a, b, c, k = MI()

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


if __name__ == "__main__":
    main()

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

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

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

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

print(str(min(A, K) * 1 + min(B, max(K - A, 0)) * 0 + min(C, max(K - A - B, 0)) * -1))

Solution (Python):


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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)


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


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Solution (Python):
A, B, C, K = (int(x) for x in input().split())
sum = 0
if A <= K:
    sum += A
else:
    sum += K

K = K - A
K = K - B
if K >= 0:
    sum -= K

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

Solution (Python):
import itertools
import math

def solve():
  a, b, c, k = map(int, input().split())
  hoge = [[a,1], [b,0], [c,-1]]
  if hoge[0][0] >= k:
    print(hoge[0][1]*k)
  elif (hoge[1][0]+hoge[0][0]) >= k:
    print(hoge[0][1]*hoge[0][0])
  else:
    print(hoge[0][1]*hoge[0][0]+(k-hoge[1][0]-hoge[0][0])*hoge[2][1])
  return 0

 
if __name__ == "__main__":
  solve()

Solution (Python):
a, b, c, k = map(int, input().split())
lis = [a, b, c]
ans = 0
for num, i in enumerate(lis):
    if i < k:
        if num == 0:
            ans += i
        elif num == 1:
            ans += 0
        else:
            ans -= i
        k -= i
    else:
        if num == 0:
            ans += k
        elif num == 1:
            ans += 0
        else:
            ans -= k
        break

print(ans)

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

if b < k:
    k-=b
else:
    print(maxim)
    exit()

print(maxim-k)

Solution (Python):
def resolve():
    import sys

    input = lambda: sys.stdin.readline().rstrip()

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

Solution (Python):
a,b,c,d = map(int,input().split())
x = min(a,d)
d = d-x
sumi = x
if d>0:
  d = d-b
  if d>0:
    sumi += -d
print(sumi)

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

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):
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    A,B,C,K = LMIIS()
    
    if A >= K:
        print(K)
        return 


    if A+B >= K:
        print(A)
        return
    

    m = K-(A+B)
    print(A-m)

    

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,C,K = LI()

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

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

ans = 0

if k < a:
  ans = k

elif k <= a+b:
  ans = a
else:
  ans = a - (1 * (k - a -b) )
  


print(ans)

Solution (Python):
x = [int(x) for x in input().split()]

a = x[0]
b = x[1]
c = x[2]
X = x[3]


if (a+b+c) == 0:
    print(0)
else:
    if (a+b) >= X:
        print(min([a,X]))
    else:
        extra = X-a-b
        print(a-extra)

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

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

ans = 0
if(A >= K):
 ans = 1*K

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

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

Solution (Python):
a,b,c,d=[int(x) for x in input().split()]
count=a
sum=a
if count>=d:
    print(d)
else:
    count=count+b
    if count<d:
        if d-count<=c:
          print(sum+((d-count)*-1))
        else:
            print(sum+(c*-1))
    else:
        print(sum)

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

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

Solution (Python):
nums = [int(e) for e in input().split()]

if nums[3] < nums[0]:
    M = nums[3]
elif nums[0] <= nums[3] <= nums[0] + nums[1]:
    M = nums[0]
elif nums[0] + nums[1] < nums[3]:
    M = nums[0] - (nums[3] - nums[0] - nums[1])

print(M)

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

print(m)

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