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

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

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

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

print(s)

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

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

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

Solution (Python):

import numpy as np
from collections import deque
import collections

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

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

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

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

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

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

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

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

print(ans)

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

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

a,b,c,d = map(int,stdin.readline().rstrip().split())

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

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

ans = 0

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

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

print(ans)

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

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

if((A < K) & (K <= A + B)):
    print(A)

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

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

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools










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

print(ans)

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

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

if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print("{}".format(2*A+B-K))

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

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

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

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

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

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

Solution (Python):
def main():
    a, b, c, k = [int(v) for v in input().split(' ')]

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


if __name__ == '__main__':
    main()

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

print(ans)

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

if k <= a:
    print(k)

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

else:
    print(a - (k - a - b))

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

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

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

ans = 0
num_of_cards = K

if A <= num_of_cards:
    ans += 1*A
    num_of_cards -= A
    if B <= num_of_cards:
        ans += 0
        num_of_cards -= B
        if C <= num_of_cards:
            ans += -1*C
        else:
            ans += -1*num_of_cards
    else:
        ans += 0
else:
    ans += 1*num_of_cards

print(ans)

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

Solution (Python):

GBN_DEBUG = False

def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')


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

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

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

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

Solution (Python):
import sys
A,B,C,K=map(int,input().split())
rest = K
cnt = 0
if rest > A:
  cnt += A
  rest -= A
else:
  cnt += rest
  print(cnt)
  sys.exit()
if rest > B:
  rest -= B
else:
  print(cnt)
  sys.exit()
print(cnt-rest)

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):
def main():
    a,b,c,k = map(int,input().split())
    cnt = 0
    res = 0
    if a <= (k-cnt):
        res += a
        cnt += a
    else:
        res += (k-cnt)
        cnt += (k-cnt)
    if b <= (k-cnt):
        cnt += b
    else:
        cnt += (k-cnt)
    if c <= (k-cnt):
        cnt += c
        res -= c
    else:
        res -= (k-cnt)
        cnt += (k-cnt)
    print(res)

if __name__ == '__main__':
    main()

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

Solution (Python):




if(__name__ == '__main__'):
    
    a, b, c, k = map(int, input().split(" "))

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

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

print(ans - k)

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

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

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

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

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

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

Solution (Python):
import math

if __name__ == '__main__':
    a, b, c, k = map(int, input().split())

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

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

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

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

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

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

Solution (Python):
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
A,B,C,K=map(int,input().split())
value=0
if A>=K:
    value+=K
    K=0
else:
    value+=A
    K-=A

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

value-=K
print(value)

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

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

print(ans)

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

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

if k > 0:
  k -= b

if k > 0:
  ans -= k

print(ans)

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

print(sum)

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, input().split(' '))

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

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

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

a = int(abck[0])
b = int(abck[1])
c = int(abck[2])
k = int(abck[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())
ans = 0
if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print(1 * a - 1 * (k - a - b))

Solution (Python):
def b():
    ones, zeros, negatives, K = map(int, input().split())
    sum = 0
    if K > ones:
        sum += ones
        K -= ones
    else:
        sum += K
        K = 0
    if K > zeros:
        K -= zeros
    else:
        K = 0
    if K > negatives:
        sum -= negatives
        K -= negatives
    else:
        sum -= K

    print(sum)



if __name__ == "__main__":
    b()

Solution (Python):
a, b, c, k = list(map(int, input().split()))
def solve(a,b, c, k):
    ans = 0
    one = min(a, k)
    ans += one
    k -= one
    if k>= 0:
        zero = min(k, b)
        k -= zero
        if k >=0:
            neg_one = min(k, c)
            ans -= neg_one
    return ans
print(solve(a,b, c, k))

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

Solution (Python):
import sys

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

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

k-=b

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

Solution (Python):


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

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

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

print(ans)

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

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

Solution (Python):
from sys import stdin

def main():

    input = stdin.readline

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

    sum_num = 0
    ans_num = 0

    if A >= K:
        ans_num += K
    else:
        sum_num += A
        ans_num += A
        if B >= K + sum_num:
            pass
        else:
            ans_num -= (K - A - B)
        
    print(ans_num)

if __name__ == "__main__":
    main()

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

ans = min(A, K)
K -= A
if K <= 0:
    print(ans)
    sys.exit()

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

ans -= K

print(ans)

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

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

Solution (Python):

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

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

Solution (Python):
def solve(A, B, C, K):
    if K < A:
        return K
    if K < A + B:
        return A
    return A - (K - A - B)

if __name__ == '__main__':
    A, B, C, K = map(int, input().split())
    print(solve(A, B, C, K))

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

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys
input = sys.stdin.buffer.readline
def I(): return(list(map(int,input().split())))
def sieve(n):
	a=[1]*n
	for i in range(2,n):
	    if a[i]:
	        for j in range(i*i,n,i):
	            a[j]=0
	return a

a,b,c,k=I()
print(min(a-(k-(a+b)),k))

Solution (Python):
import sys



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

Solution (Python):
s = input().split()

A = int(s[0])
B = int(s[1])
C = int(s[2])
K = int(s[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:
  print(k)
elif k <= a+b:
  print(a)
else:
  print(a-(k-a-b))

Solution (Python):
if __name__ == "__main__":
    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):
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, C, K = [int(x) for x in input().strip().split()]
    if K <= A + B:
        print(min(K, A))
    else:
        print(A - (K - A - B))
    
if __name__ == '__main__':
    main()

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

ans = 0

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

print(ans)

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

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

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

print(ans)

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

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    ans = 0
    if A <= K:
        ans += A
        K -= A
        if K > 0:
            if B <= K:
                K -= B
                if K > 0:
                    if C <= K:
                        ans -= C
                        K -= C
                    else:
                        ans -= K

    else:
        ans += K
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    K = int(next(tokens))  
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

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

Solution (Python):
def readInt():
    return list(map(int,input().split()))

a,b,c,k = readInt()
m = k-(a+b)
if a>=k:
    print(k)
elif a+b>=k:
    print(a)
else:
    print(a-m)

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

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

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

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

print(ans)

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


def read():
    A, B, C, K = map(int, input().strip().split())
    return A, B, C, K


def solve(A, B, C, K):
    score = 0
    if K <= A:
        return K
    score = A
    K -= A
    if K <= B:
        return A
    K -= B
    return score - K


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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:
    ans += A
    K -= A
else:
    ans += K
    K = 0

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

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

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



if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
one,zero,m1,n_remain_picks = [int(s) for s in input().split()]
result = 0
if n_remain_picks <= one:
    result = n_remain_picks
    n_remain_picks = 0
else:
    result = one
    n_remain_picks -= one
    if n_remain_picks > zero:
        n_remain_picks -= zero
        result -= min(n_remain_picks, m1)
        n_remain_picks -= min(n_remain_picks, m1)

print(result)

Solution (Python):
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce
import bisect

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

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

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

print(ans)

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

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

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

a_count = min(k, a)
score = a_count - max(0, k - a_count - b)

print(score)

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

Solution (Python):

import sys

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

if K <= A:
    print(K)
    sys.exit()
elif K <= A + B:
    print(A)
    sys.exit()
else:
    numB = K - (A + B)
    print(A - numB)
    sys.exit()

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

ans += min(a, k) - min(c, max(0, 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())

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

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

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

ans=0

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

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

print(ans)

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

    if A >= K:
        V += K
        K = 0
    else:
        V += A
        K -= A

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

    if C >= K:
        V -= K
        K = 0
    else:
        V -= C
        K -= C

    print(V)

if __name__ == "__main__":
    main()

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

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

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


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

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

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

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

K = K - A
ans = A

if B >= K:
    print(ans)
    exit()

K = K - B
print(ans-K)

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

    Kk = K - A
    vc = 0
    vb = 0
    if Kk > 0 :
        Kkk = Kk - B
        if Kkk > 0 :
            vc = (-1) * Kkk
        vb = 0
        print(A + vc)
    else :
        print(K)



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

Solution (Python):
a, b, c, k = map(int, input().split())
num = (1, 0, -1)
ans = 0
for n, m in zip(num, (a,b,c)):
  if m >= k:
    ans += k*n
    break
  else:
    ans += m*n
    k -= m
print(ans)

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

N = K - (A+B)

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

Solution (Python):


import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int, C: int, K: int):
    ret = 0
    ret += min(A, K)
    K = max(K - A, 0)
    if K > 0:
        K = max(K - B, 0)
        if K > 0:
            ret -= K
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    K = int(next(tokens))  
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, K = MAP()

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

Solution (Python):
import sys
input = sys.stdin.readline
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())

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

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

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

print(ans)

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




ans=0

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


print(ans)

Solution (Python):
s = input()
temp = [int(comp) for comp in s.split()]
[a, b, c, k] = temp
val = [1, 0, -1]
ans = 0
for i in range(3):
    memo = min(temp[i], k)
    ans += val[i] * memo
    k -= memo
    if (k <= 0):
        break
print(ans)

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




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

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

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

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

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



c=0
if K<=A:
    print(K)
elif K <= A+B:
    print(A)
elif K <= A+B+C:
    non=A+B+C-K
    min=C-non
    print(A-min)

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()))
k = K
t = 0

t += min(k, A)
k -= min(k, A)


if k > 0 and B > 0:
    k -= min(k, B)

if k > 0 and C > 0:
    t -= min(k, C)
    k -= min(k, C)

ans = t
print(ans)

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

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

ans=0

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

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

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

if a < count:
    a_n = a
else:
    a_n = count    
count -= a_n

if b < count:
    b_n = b
else:
    b_n = count
count -= b_n

if c < count:
    c_n = c
else:
    c_n = count
count -= c_n

print(a_n-c_n)