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

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

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

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

Solution (Python):
import sys

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

cnt=0


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

if k<=(a+b):
  print(a)
  sys.exit()


k-=(a+b)
print(a-k)

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

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

ans = 0

nokori = K

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

else:
    ans += A
    nokori = K - A

    if B >= nokori:
        print(ans)
        exit()
    
    else:
        nokori = nokori - B
        ans = ans - nokori
        print(ans)

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

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

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


if __name__ == '__main__':

    ABC_167_B()

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

if A >= K:
    ans = K
elif A + B >= K:
    ans = A
else:
    ans = 2*A + B - K

print(ans)

Solution (Python):
A,B,C,K = (int(x) for x 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())
l = max(0, k - a)
m = max(0, l - b)
print(min(k, a) - m)

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

result = 0

if K <= A:
    result = K
else:
    result = A
    K = K - A
    if K <= B:
        pass
    else:
        result -= K - B

print(result)

Solution (Python):
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    a,b,c,k=MI()
    ans =0
    if k>=a:
        ans+=a
        k-=a
    elif k<a:
        ans+=k
        k=0
    if k>=b:
        ans+=0
        k-=b
    elif k<b:
        ans+=0
        k=0
    
    if k>=c:
        ans-=c
        k-=c
    elif k<c:
        ans-=k
        k=0
    print(ans)

if __name__ == "__main__":
    main()

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

ANS += min([A,K])
K -= A
K -= B

if K<1:
    print(ANS)
    exit()
ANS -= min([C,K])
print(ANS)

Solution (Python):
def main():
    a, b, c, k = [int(x) for x in input().split()]
    ans = 0
    
    if a >= k:
        ans += k
        k -= k
    else:
        ans += a
        k -= a
    
    if b >= k:
        k -= k
    else:
        k -= b
    
    ans -= k
    return ans


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

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

    rest = K
    total = 0

    if(rest - A >= 0):
        rest = max(0, rest - A) 
        total += 1 * A
    else:
        total += 1 * rest

    rest = max(0, rest - B) 

    
    total += -1 * rest

    print(total)

if __name__ == "__main__":
    main()

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

count=min(a,d)
d-=a
d-=b
if d<=0:
    print(count)
else:
    print(count-d)

Solution (Python):


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


A, B, C, K = LI()


def main():
    a = min(A, K)
    k = K - a
    b = min(B, k)
    k -= b
    c = min(C, k)
    ans = a - c
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def linear(a, b, c, k):
  count = 0
  if(k>a):
    count+=a
    k-=a
    if(k>b):
      k-=b
      if(k>c):
        count-=c
      else:
        count-=k
    return count
  else:
    return k

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

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


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

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

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

Solution (Python):
import numpy as np
import math
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):
A, B, C, D = map(int, input().split())
ans = min(A, D)
D -= ans
if D > 0:
    D -= min(B, D)
if D > 0:
    ans -= min(C, D)
print(ans)

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

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

Solution (Python):
if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    sum = 0

    if a[0] >= a[3] :
        sum = a[3]
        a[3] = 0
    else:
        sum = a[0]
        a[3] =a[3]-a[0]
    if a[3] > 0:
        a[3] = a[3]-a[1]
    if a[3] >0:

        sum =sum -a[3]


    print(sum)

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

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

print(result)

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

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

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

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

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

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

print(ans)

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

s = 0

if k <= a :
    s = 1 * k
else :
    if k <= (a+b):
        s = 1 * a
    else :
        s = 1 * a + (-1) * (k-a-b)

print(s)

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

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

print(d)

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

ans = 0

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

K -= B

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

print(ans)

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:
    ans-=c
    k-=c
else:
    ans-=k
    k=0
print(ans)

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

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

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

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

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

Solution (Python):
import sys

input = sys.stdin.readline

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce


MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def main():
    a, b, c, k = [int(x) for x in stdin.readline().rstrip().split()]
    if a >= k:
        print(k)
    elif a + b >= k:
        print(a)
    else:
        nokori = k - (a + b)
        print(a - nokori)

main()

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

def intinp():
    return int(input())

A, B, C, K = mapint_inp()


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

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

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

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

if left > 0:
   if left < c:
      print(ans - left)
   else:
      print(ans - c)

Solution (Python):
import numpy as np

ABCK=np.array(input().split(" "),dtype=np.int64)

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

total=0
cnt=1

if(A<=K):
    total+=1*A
    K=K-A
    if(B<=K):
        K=K-B
        if(0<K):
            total+=-1*K
        else:
            pass
    else:
        pass
else:
    total+=1*K

print(total)

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

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

Solution (Python):
import sys

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

left=K
sum=0
if K<=A:
    print(K)
    sys.exit()
else:
    sum+=A
    left-=A
    if left<=B:
        print(sum)
        sys.exit()
    else:
        left-=B
        sum-=left
        print(sum)
        sys.exit()

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

if K <= A:
  max = K

if A < K <= A + B:
  max = A

if A + B < K:
  max = A - (K - A - B)

print(max)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

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

Solution (Python):

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

Solution (Python):

import sys
import numpy as np


def solve(A: int, B: int, C: int, K: int):
    if K<=A:
        print(K)
        return
    elif K<=A+B:
        print(A)
        return
    elif K<=A+B+C:
        print(A-(K-A-B))
        return
    else:
        print(A-C)
    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 = (int(x) for x in input().split())
count = 0
if a >= k:
    count += k;
    k = 0
else:
    count += a
    k -= a

if b >= k:
    count += 0;
    k = 0
else:
    count += 0
    k -= b


if c >= k:
    count -= k;
    k = 0
else:
    count -= a
    k -= a
print(count)

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

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

def calculate(a,b,c,k):
    if k<= a+b:
        if k <= a:
            print(k)
        else:
            print(a)
    else:
        print(a - (k - (a+b)))

calculate(A,B,C,K)

Solution (Python):
def main():
    a, b, c, k = input_list()

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

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

    ans = a
    nokori = k - a
    if nokori <= b:
        print(ans)
    else:
        nokori -= b
        ans += nokori * -1
        print(ans)

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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










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

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,c,k = readInts()
    if a >= k:
        print(k)
    else:
        if a + b >= k:
            print(a)
        else:
            print(a - (k - (a + b)))
if __name__ == '__main__':
  main()

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

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


ans = min(a, k)*1 - x
print(ans)

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

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

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

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

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

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

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

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

print(d)

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

result = 0

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

print(result)

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

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    A, B, C, K=MI() 

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

    


if __name__ == "__main__":
	main()

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

    if A<K:
        sums += A
        K = K-A
    else:
        sums=K
        print(sums)
        return
    if B<K:
        K = K-B
    else:
        print(sums)
        return
    if C<K:
        sums -=C
        print(sums)
        return
    else:
        sums -=K
        print(sums)
        return


if __name__ == '__main__':
    main()

Solution (Python):
a, b, c , k = [int(x) for x in input().split()]
aa = min(a, k)
bb = min(b, k - aa)
cc = min(c, k - aa - bb)
maxs = aa * 1 + bb * 0 + cc * -1
print(maxs)

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

Solution (Python):
if __name__=="__main__":
    a,b,c,k = map(int, input().split())
    picks = 0

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

Solution (Python):
nums = [int(e) for e in input().split()]
a = nums[0]
b = nums[1]
c = nums[2]
k = nums[3]
total = 0

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

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

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

c1 = A+B
c2 = A+B+C

if K<A: num = K
elif K>c1 and K<=c2:num = A - (K-A-B)
else:num = A

print(num)

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

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

if c > k:
    ans += -1*k
    print(ans)
    exit()
else:
    ans += -1*c

print(ans)

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

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

Solution (Python):

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

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

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

Solution (Python):

s = list(map(int,input().split()))
a=s[0]
b=s[1]
c=s[2]
k=s[3]
if a+b<k:
    print(a-(k-a-b))
else:
    if a>k:
        print(k)
    else:
        print(a)

Solution (Python):
s = input("")
L = s.split(" ")
a,b,c,k = int(L[0]),int(L[1]),int(L[2]),int(L[3])
if (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)))

Solution (Python):
a,b,c,k=list(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 and K<=A+B:
    print(A)
elif K>A+B:
    print(A-(K-(A+B)))

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

val=0

if k<=a:
    val+=k
else:
    val+=a

if k-a-b>0:
    val-=k-a-b

print(val)

Solution (Python):
A,B,C,K=[int(x) for x in input().rstrip().split()]
num=A+B
if K<=A:
  print(K*1)
elif K<=A+B:
  print(A*1)
else:
  print((A)*1+(K-(A+B))*-1)

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

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

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

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

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

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

sum = 0
cnt = K
if A>=cnt:
	sum += cnt*1
else:
	sum += A*1
	cnt = cnt-A
	if B >= cnt:
		sum+= cnt*0
	else:
		sum += B*0
		cnt = cnt-B
		if C >= cnt:
			sum += cnt*(-1)
		else:
			sum += C*(-1)
print(sum)

Solution (Python):


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

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

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

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

Solution (Python):
def resolve():
    A, B, C, K = map(int, input().split())
    AC = min(K, A)
    BC = min(K - AC, B)
    CC = min(K - AC - BC, C)
    print(1*AC+0*BC+(-1)*CC)

if __name__ == '__main__':
    resolve()

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

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

Solution (Python):

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

total = min(A, K)
K -= (A + B)
if 0 < K:
    total -= min(C, K)

print(total)

Solution (Python):
t=[int(x) for x in input().split()]
a=t[0]
b=t[1]
c=t[2]
k=t[3]
if k<=a:
    print(k)
else:
    ans=a
    rem=k-a
    if rem<=b:
        print(ans)
    else:
        rem=rem-b
        val=-1*rem
        ans=ans+val
        print(ans)

Solution (Python):
import sys

import math
input = sys.stdin.readline
A,B,C,K = map(int,input().split())
    
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else :
    F = K - (A+B)
    print (A - F )

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

  if A >= K:
    print(K)
    return True

  result = 0
  K = K - A
  result = A

  if B >= K:
    print(result)
    return True

  K = K - B

  print(result - K)

if __name__ == "__main__":
    resolve()

Solution (Python):
def cal():

    a, b, c, k = input().split(" ")
    a = int(a)
    b = int(b)
    c = int(c)
    k = int(k)
    ans = 0
    if k <= a:
        ans = k
    elif a < k <= (a+b):
        ans = a
    elif k > (a+b):
        ans = a - (k - (a+b))
    print(ans)



cal()

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

Solution (Python):
if __name__ == "__main__":
    a, b, c, k = map(int, input().split())
    result = 0

    result += min(k, a)
    k -= min(k, a)
    k -= min(k, b)
    result -= min(k, c)

    print(result)

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

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

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

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

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

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

Solution (Python):
A, B, C, K = map(int,input().split())
result = 0
List = []
if A >= K:
  result = K
elif A + B >= K:
  result = A
elif A + B + C >= K:
  result = A + (K - A - B )*(-1)
  

print(result)

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


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

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

x = 0
if K >= A:
    x += A
    K = K - A
    
    if K >= B:
        K = K - B
        
        if K >= C:
            x += -1 * C
        else:
            x += -1 * K
    else:
        pass
else:
    x += K
print(x)

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

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

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

if cnt <= B:
    print(sum_)
    exit()
else:
    cnt -= B

print(sum_ - min(cnt, C))

Solution (Python):


def main():
    ABCK = list(map(int,input().split()))

    AB = ABCK[0] + ABCK[1]


    if ABCK[0] > ABCK[3]:
        print(ABCK[3])

    elif ABCK[3] > AB:
        kk = ABCK[3]-AB

        

        print(ABCK[0]-(kk))

    else:
        print(ABCK[0])


if __name__ == '__main__':
    main()

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

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

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

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

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

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

if a >= k:
    ans = k

elif a + b >= k:
    ans = a

else:
    buf = k - (a + b)
    ans = a - buf

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

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

if a >= k:
    print(k)
elif a < k 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())
if K > A:
  a = A
  if K >= A+B:
    c = K - A -B
    print(A-c)
  else:
    print(A)
else:
  a = K
  print(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 = [ int(i) for i in input().strip().split(' ') ]
n_a = min(A, K)
n_b = min(B, K-n_a)
n_c = min(C, K-n_a-n_b)
print(n_a-n_c)

Solution (Python):
from typing import NoReturn


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


if __name__ == '__main__':
    main()

Solution (Python):
A, B, C, K = (int(x) for x in input().split())
max = 0
if K <= A:
    print(K)
else:
    Kb = K - A
    if Kb <= B:
        print(A)
    else:
        Kc = Kb - B
        print(A-Kc)

Solution (Python):


def main():

    n = [int(x) for x in input().split(' ')]
    a = n[0]
    b = n[1]
    c = n[2]
    k = n[3]

    point = 0
    count = k

    a_ = a
    a_b = a + b
    if k <= a:
        point = k
    elif k >= a and k <= a+b:
        point = a
    else:
        take_c = k - (a + b)
        point = a - take_c

    
    print(point)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7

a, b, c, k = MAP()
k -= a
res = a
if k <0:
    res += k
if k>0:
    k -= b
    
if k>0:
    k -= c
    res -=c
    if k<0:
        res -=k
print(res)

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

ans = 0

nokori = K


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


K = K - B


if K > 0:
  ans = ans - min(C, K)

print(ans)

Solution (Python):
data = input().split(" ")
A = int(data[0])
B = int(data[1])
C = int(data[2])
K = int(data[3])
ans = 0
if A >= K:
    ans = K
else:
    K -= A
    ans += A
    if B >= K:
        pass
    else:
        K -= B
        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)
elif A+B < K <A+B+C:
    print(A - (K - (A+B)))
else:
    print(A-C)

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

Solution (Python):


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

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

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

K -= B
print(score - K)

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