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

count = 0

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

Solution (Python):



"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""


"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""

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

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

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

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

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

Solution (Python):
x = list(map(int, input().split()))
a = x[0]
b = x[1]
c = x[2]
k = x[3]
count = 0
ka = k-a
if ka >= 0:
  count += a*1
else:
  count += k*1
if ka > 0:
  kb = ka-b
  kc = kb-c
  if kb > 0:
    count += kb*-1
print(count)

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

ANS = 0

if A-K <= 0:
    ANS = ANS + A
    num = K - A
    if B - num <= 0:
        Num = num -B
        ANS = ANS - Num 
else:
    ANS = K

print(ANS)

Solution (Python):
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
a,b,c,d=get_ints()
if a<d:
    ans1=a 
    d=d-a 
    if b<d:
        ans2=b 
        d=d-b
        if c<d:
            ans3=c 
            d=d-c 
            ans=ans1+ans2-ans3
        else:
            ans=ans1-d
    elif b>=d:
        ans=ans1
elif a>=d:
    ans=d
print(ans)

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

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

n = [A,B,C]
result = 0
j = 1
for i in n:
    if K <= i:
        print(result + K*j)
        break
    else:
        result += j*i
        K = K - i 
        j = j - 1

Solution (Python):
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    a,b,c,k=L()
    if k<a:
        print(k)
    elif a+b>=k:
        print(a)
    else:
        tmp=k-(a+b)
        print(a-tmp)
    
if __name__ == '__main__':
    main()

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

def maxK(A,B,C,K):
  s=0
  if K<A:
    return K
  else:
    s+=A
    K-=A
  if K<B:
    return s
  else:
    K-=B
  return s-K

print(maxK(A,B,C,K))

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>0:
    if k>b:
        k-=b
    else:
        k=0
if k>0:
    if k>c:
        ans-=c
    else:
        ans -= k

print(ans)

Solution (Python):
N = list(map(int, input().split()))
K = N.pop()
l = [0] * 3
for i in range(3):
    l[i] = min(N[i], K)
    K -= l[i]
print(sum(a * b for a, b in zip(l, range(1, -2, -1))))

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

a,b,c,k=LI()
ans=0

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

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def print_ans(B):
    for b in B:
        b.sort(key=lambda l: int(l))
        print(" ".join(b))



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


if __name__ == "__main__":
    main()

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

if a>=k:
    print(k)

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

Solution (Python):
A, B, C, K = tuple(int(c) for c in input().split(' '))

if A >= K:
    print(K)
    exit()
else:
    bc = K - A  
    assert bc >= 1
    if B >= bc:
        print(A)
        exit()
    else:
        
        cc = bc - B
        assert cc >= 1
        print("{:.0f}".format(A - cc))
        exit()

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

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

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

s = 0

s += min(a,k)
k -=a
if k<0:
  print(s)
  exit()
k -=b
if k<0:
  print(s)
  exit()
s -= min(c,k)
print(s)

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

Solution (Python):

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

if A <= K:
    a = A
else:
    a = K

if B <= K-a:
    b = B
else:
    b = K-a

c = K - a - b

ans = a - c
print(ans)

Solution (Python):
a,b,c,k = [int(i) for i in input().split(' ')]
ret = [a,b,c]
A = 1*a
B = 0
C = -1*c

if a >= k:
    print(1*k)
elif sum(ret[:2]) >= k:
    print(A)
elif sum(ret) > k:
    tmp = k - a - b 
    print(A+(tmp* -1))
else:
    
    print(A+B+C)

Solution (Python):
a, b, c, k = list(map(int, input().split()))
na = 0
nb = 0
nc = 0
if k < a:
    na = k
else:
    na = a
    k -= a
    if k < b:
        nb = k
    else:
        nb = b
        k -= b
        nc = k
point = na - nc
print('{}'.format(point))

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

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

Solution (Python):
import sys
def main():
    A, B, C, K = map(int, input().split())
    l = []

    if K-A<0:
        out = K
        print(out)
        sys.exit()
        
    if K-A>=0:
        l.append(A)
        K = K-A
    if K-B>=0:
        K = K-B
    if K>0:
        m = K * -1
        l.append(m)
    out = sum(l)
    print(out)
main()

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

tmpk = 0

tmp = 0
flg = True

if a > k:
    print(k)
    flg = False
else:
    tmp = a
    tmpk = k - a
    if tmpk <= 0:
        print(tmp)
        flg = False

if b > tmpk and flg:
    print(tmp)
    flg = False
elif flg:
    tmpk -= b
    if tmpk <= 0:
        print(tmp)
        flg = False

if flg:
    tmp -= tmpk
    print(tmp)

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

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

Solution (Python):
cnt_a, cnt_b, cnt_c, cnt = map(int, input().split())
if cnt_a >= cnt:
    print(cnt)
elif cnt_a + cnt_b >= cnt:
    print(cnt_a)
else:
    print(cnt_a - (cnt - cnt_a - cnt_b))

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

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

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

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):
a1,b0,cn1,d=map(int,input().split())
Output = 0

if a1 < d:
    Output = a1
    if a1+b0 < d:
      c = d-a1-b0
      Output = Output - c
    elif a1 + b0 >= d:
      pass
elif a1 >= d:
    Output = d
else:
  print("weird")
print(Output)

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

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

print(ans)

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

Solution (Python):
a,b,c,k=map(int,input().split())
'''l=[]
for _ in range(a):
    l.append(1)
for _ in range(b):
    l.append(0)
for _ in range(c):
    l.append(-1)
print(sum(l[:k]))'''
su=0
if a>=k:
    print(k)
else:
    su=su+a
    tem=k-a
    if b>=tem:
        print(su)
    else:
        tem1=tem-b
        print(su-tem1)

Solution (Python):
import sys

read = sys.stdin.buffer.read


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

ans = 0

i = min(a, k)
k = max(k-i, 0)
j = min(b, k)
k = max(k-j, 0)
l = min(c, k)

print(i+j*0-l)

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

ans = 0

if K <= A:
    ans = K
elif A < K <= (A+B):
    ans = A
else:
    ans = A + (-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(a-(k-a-b))

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

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

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

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


if a >= k:
    print(k)
elif ab >= k:
    print(a)
else:
    print(a - k_ab)

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

if K>=A:
    K-=A
    sum+=A
elif K<A:
    sum+=K
    K=0

if K>=B:
    K-=B
elif K<B:
    K=0

if K>=C:
    K-=C
    sum-=C
elif K<C:
    sum-=K
    K=0

print(sum)

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

if a>k:
    print(1*k)
elif (k-a) < b:
    print(1*a)
elif (k-a-b) < c:
    print(1*a-1*(k-a-b))
else:
    print(1*a-1*c)

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

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

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

s = min(a,k)
k -= min(a,k)
k -= min(b,k)
s -= min(c,k)

print(s)

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

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

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

Solution (Python):
    

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

    ans = 0

    k1 = k - a
    k1 = max(0, k1)
    ans += k - k1
    k = k1

    if k > 0:
        k1 = k - b
        k1 = max(0, k1)
        k = k1

        if k > 0:
            k1 = k - c
            k1 = max(0, k1)
            ans -= k - k1
            k = k1

    print(f'{ans}\n')

if __name__ == '__main__':
    main()

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

n_a = 0
n_b = 0
n_c = 0


if K > 0:
  
  if K >= A:
    n_a = A
    K = K - A
  else:
    n_a = K
    K = K - A

else:
  n_a = 0


if K > 0:

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

else:
  n_b = 0

if K > 0:

  if K >= C:
    n_c = C
    K = K - C
  else:
    n_c = K
    K = K - C

else:
  n_c = 0

ans = (n_a * 1) + (n_b * 0) + (n_c * (-1))
print(ans)

Solution (Python):
from sys import stdin

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

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

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

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

if a <= k:
    count += a
else:
    count += k
    print(count)
    exit()
k -= a

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


count -= k

print(count)

Solution (Python):
A, B, C, K = [int(i) for i in input().split()]

sum_ = 0
a = min(A, K)
b = max(min(K - A, B), 0)
c = max(K - (B + A), 0)
print(a - c)

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

print(ans)

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

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

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

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

R = K-(A+B)
if R <= 0 :
    R = 0
elif R >= C :
    R = C

S = A - R
if A > K :
    S = K

print(S)

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

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


if __name__ == "__main__":
    main()

Solution (Python):

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

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

if __name__ == '__main__':
    main()

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

if a >= k:
  an = k
  bn = 0
  cn = 0
elif a+b >= k:
  an = a
  bn = k - (a)
  cn = 0
else:
  an = a
  bn = b
  cn = k - (a+b)
  
print(an-cn)

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

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

    res += 1 * min(a, k)
    k -= a
    if k > 0:
        k -= b
    if k > 0:
        res += (-1 * min(c, k))
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
a = [int(x) for x in input().split()]
count1=0
count0=0
count2=0
if a[3]>a[1]:
   count1=a[0]
if a[3]<=a[1]:
    count1=a[3]
if a[3]-a[1]-a[0]>0:
    count2=-(a[3]-a[1]-a[0])
print(count1+count2)

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())
total = 0
for i, n in zip([1, 0, -1], [a, b, c]):
    k -= (p := min(n, k))
    total += i * p
print(total)

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

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

print(cnt)

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

if k < a:
    result = k
elif k <= a + b:
    result = a
else:
    result = 2 * a + b - k

print(result)

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


if __name__ == '__main__':
    main()

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

x = min(a,k)
ans = x
if x < k:
    k -= x
    x = min(b, k)
    if x < k:
        k -= x
        ans -= min(c, k)

print(ans)

Solution (Python):
from sys import stdin
input = stdin.readline
def main():
  num_list = list(map(int, input().split()))
  A=num_list[0]
  B=num_list[1]
  C=num_list[2]
  K=num_list[3]
  sum_count=0
  sFlag=True
  i=0
  if(A>=K):
    sum_count=K
    sNum=0
  else:
    sNum=K-A
    sum_count=sum_count+A
  if(B>=sNum):
    sNum=0
  else:
    sNum=sNum-B
  if(sNum!=0):
    sum_count=sum_count-sNum
  else:
    if(C>=sNum):
      sum_count=sum_count-sNum
    else:
      sum_count=sum_count-C
  print(sum_count)

if __name__ == '__main__':
    main()

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

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

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

if k != 0 and k - b > 0:
  print(a-(k-b))
else:
  print(a)

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

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

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

Solution (Python):

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

if int(K) < int(A):
    ans=int(K)

if int(K) >= int(A) and int(K) <= int(A)+int(B):
    ans=int(A)

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

print(ans)

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

if a <= k:
    count += a
else:
    count += k
    print(count)
    exit()
k -= a

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


count -= k

print(count)

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

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

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

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

    ans = 0
    diff = a - k
    if diff >= 0:
        print(k)
        return

    diffb = b - (-diff)
    if diffb >= 0:
        print(k-(-diff))
        return
    k = k-(-diff)

    print(k-(-diffb))

solution()

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

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

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

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 > 0 and B > 0:
    if K >= B:
        K -= B
    else:
        K = 0

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

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

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

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

total = 0

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

if b > 0 and k > 0:
    if b < k:
        k -= b
    else:
        print(total)
        k = 0

if c > 0 and k > 0:
    if c < k:
        total -= c
        print(total)
    else:
        total -= k
        print(total)

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

sum_card=0
if A<K:
    sum_card=A
    K-=A
else:
    sum_card=K
    K-=K
if B<K:
    K-=B
else:
    K-=K
sum_card-=K

print(sum_card)

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

if k<=a:
	amount=k

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

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

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

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

k -= b
print(a-k)

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

x = K - A
if x == 0:
    print(A)
elif x < 0:
    print(K)
elif x > 0:
    y = x - B
    if y == 0:
        print(A)
    elif y < 0:
        print(A)
    elif y > 0:
        print(A - y)

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

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

if __name__ == '__main__':
    main()

Solution (Python):

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

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

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

ans -= k
print(ans)

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

if a>k:
  ans=k
else:
  ans=a  

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

print(ans)

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

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

print(result)

Solution (Python):
a, b, c, k = [int(i) for i in input().split()]
ans = 0
if a > k:
    ans += k
    print(ans)
    exit()

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

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

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

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

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

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

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

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

Solution (Python):
A=list(map(int,input().split()))
ans = 0
if A[0] >= A[3]:
    ans = A[3]
else:
    A[3] = A[3]-A[0]
    ans = A[0]
    A[3] = A[3] -A[1]
    if A[3] > 0:
        ans = ans - A[3]
print(ans)

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

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


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

    if A > K:
        a, b, c = K, 0, 0
    else:
        a = A

        if B > K - A:
            b, c = K - A, 0
        else:
            b, c = B, K - A - B

    print(a - c)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

a,b,c,k=(int(i) for i in input().split())



if a > k:
    one = k
    k = 0
else :
    one = a
min =0
nokori = k-a
if nokori > 0:
    zero = b
    nokori= nokori -b

if nokori > 0:
    min = nokori

ans = 1*one-1*min
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=map(int,input().split())
if(a>k):
  print(k)
elif(a+b>k):
  print(a)
else:
  print(a+(a+b-k))

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

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

Solution (Python):
import sys


def solve(A: int, B: int, C: int, K: int):
    ans  = 0
    card = 0
    if K<=A:
        print(K)
    elif K <= A+B:
        print(A)
    else:
        print(A-K+A+B)
    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())

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

Solution (Python):
a,b,c,k = map(int,input().split())
res = 0
p = 1
for i in(a,b,c):
  if i>k:
    i = k
  k-=i
  res+=i*p
  p-=1
print(res)

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

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

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

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

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

s= 0

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

Solution (Python):


import bisect, collections, copy, heapq, itertools, math, numpy, string
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())


def main():
    a, b, c, k = LI()
    sum = 0
    
    if a >= k:
        sum = sum + k
        k = 0
    else:
        sum = sum + a
        k = k - a
    
    if k > 0:
        if b >= k:
            k = 0
        else:
            k = k - b
    
    if k > 0:
        if c >= k:
            sum = sum - k
            k = 0
        else:
            sum = sum - c
            k = k - c
    
    print(sum)


main()

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

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


a, b, c, k = LI()
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())
ans = 0
if A+B>=K:
    if A <= K:
        print(A)
    else:
        print(K)
else:
    ans = A
    K -=A+B
    print(ans-K)

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