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

total = 0

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

print("{}".format(total))

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

resolve()

Solution (Python):

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

if k <= a:
    point += k
elif k > a and (k - a) <= b:
    point += a
elif k > a and (k - a) > b:
    point = a + (-1) * (k - a - b)

print(point)

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

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

print(sum)

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

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

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

count = 0

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

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

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

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

a_tmp = A - K
ans = 0


if a_tmp <= 0:
    ans += A
    
    b_tmp = B + a_tmp

    if b_tmp < 0:

        ans += b_tmp
        
else:
    ans += K


print(ans)

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

if a>=k:
    print(1*k)
    
if a<k and b>=k-a:
    print(a)

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

Solution (Python):
def check(a,b,c,k):
    sum1=0
    sum1+=min(a,k)
    k-=min(a,k)
    if(k==0):
        return sum1
    else:
        k-=min(b,k)
        if(k==0):
            return sum1
        else:
            val=min(k,c)
            sum1=sum1-val
            return sum1
l=list(map(int,input().strip().split()))[:4]
a,b,c,k=l[0],l[1],l[2],l[3]
sum1=0
ans=check(a,b,c,k)
print(ans)

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

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

Solution (Python):


a, b, c, k = [0] * 4

def format_input(filename = None):
	global a, b, c, k
	if filename == None:
		a, b, c, k = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		a = rng(0, 2 * 10**9)
		b = rng(0, 2 * 10**9 - a)
		c = rng(max(0, 1-a-b), 2 * 10**9 - a - b)
		k = rng(1, a + b + c)
		print(a, b, c, k)

def get_answer():
	answer = 0

	if a >= k:
		answer = k
	elif a + b >= k:
		answer = a
	else:
		answer = 2 * a + b - k

	return answer

if __name__ == '__main__':
	format_input()

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

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

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

Solution (Python):
s = input().split()
numOfA = int(s[0])
numOfB = int(s[1])
numOfC = int(s[2])
pickNum = int(s[3])
maxOutcome = 0

if pickNum < numOfA:
    maxOutcome = pickNum
elif pickNum >= numOfA and pickNum <= (numOfA + numOfB):
    maxOutcome = numOfA
elif pickNum >numOfA +numOfB:
    maxOutcome = numOfA - (pickNum - numOfA - numOfB)

print(maxOutcome)

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

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

ans = 0
count = 0

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

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

if C >= (K-count):
    ans -= (K-count)
    print(ans)
    exit()

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


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

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

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

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

Solution (Python):
a, b, c, k = list(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:
    print(a-((a+b)-k)*-1)

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

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

ans = 0

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

print(ans)

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

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

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

ans = 0

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

if B >= K:
    print(ans)
    sys.exit()
else:
    K -=B

ans -= K
print(ans)

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

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

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

else:
    cnt += K

print(cnt)

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

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

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

print(ans)

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

print(ans)

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

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

Solution (Python):
import itertools
import math
import fractions
import functools

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

sum = 0

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

if k <= b:
    print(sum)
    quit()
elif k > b:
    k = k - b
    sum -= k * 1

print(sum)

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

Solution (Python):

lst = list(map(int, input().split()))

K = lst[3]
c = 0
a = 0

for i in range(3):
    if K > 0:
        a = min(lst[i], K)
        K = K - a
        if i == 0:
            c += a * 1
        elif i == 2:
            c += a * (-1)
    else:
        break
print(c)

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

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

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

ans = 0
ans += min(K, A) * 1
K -= A

ans += max(0, min(K, B)) * 0
K -= B

ans += max(0, min(K, C)) * -1
print(ans)

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

ans = 0

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

k -=min(k, b)
ans +=  (-1)* min(k, c)

print(ans)

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

if K < A:
    print(K)

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

else:
    print(A - (K - A - B))

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

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

cntb = k - a
cntc = cntb - b

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

Solution (Python):

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


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

k = k-a
ans = 1*a


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


print(ans+k*(-1))

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

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

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

score = 0
rest = k

rest -= a
if (rest <= 0):
    print(k)
else:
    rest -= b
    if (rest <= 0):
        print(a)
    else:
        print(a-1*rest)

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(1,0),(-1,0),(0,1),(0,-1)];EightNb=[(1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('EWNS',FourNb))
l_alp=string.ascii_lowercase

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

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return

    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return

    def __str__(self):
        return  str(self.edges)

    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v

    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]

class SparseTable: 
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1

        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    
    def query(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][r-(1<<N)])
    
    
    def query_id(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][r-(1<<N)]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][r-(1<<N)]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])

    def print(self):
        for i in self.table:
            print(*i)


show_flg=False
show_flg=True
ans=0

a,b,c,k=LI()
x=0
if a>=k:
    x=k
    print(x)
    exit()
else:
    x+=a
    k-=a
    if b>=k:
        print(x)
        exit()
    else:
        k-=b
        x-=k
        print(x)

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

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

Solution (Python):
import sys

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

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

Solution (Python):
a = [int(i) for i in input().split()]
k = a.pop()
ans = 0
for i in range(3):
    if i==0:
        if k<=a[i]:
            ans = k
            break
        else:
            ans += a[i]
            k -= a[i]
    elif i==1:
        if k<a[i]:
            break
        else:
            k -= a[i]
            continue
    else:
        if k<=a[i]:
            ans += (-1)*k
            
print(ans)

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

a_b = a+b
a_b_c = a+b+c

if k < a:
  print(k)
elif k < a_b:
  print(a)
elif k < a_b_c:
  print(a - c + (a_b_c-k))
else:
  print(a-c)

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

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

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



i = k - a
if i <= 0:
    print(k)
    exit()
else:
    j= i - b
    if j <= 0:
        print(a)
        exit()
    else:
        print(a - j)

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

t = A-(K-A-B)

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

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

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

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

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

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

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

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

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

n=0

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

Solution (Python):

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

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

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

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:
        print(ans)
        exit()
    else:
        K -= B
        if C >= K:
            ans -= K
            print(ans)
        else:
            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):
def my_clip(value, max):
    if value <= max:
        return value
    return max

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

restK = K
sum = 0

clipA = my_clip(A, restK)
sum += clipA
restK -= clipA

if restK > 0:
    clipB = my_clip(B, restK)
    restK -= clipB

sum -= restK

print(sum)

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

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())
print(1*min(A,K) + (-1)*max(0, 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 + (-1) * (k-a-b)

print(ans)

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

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

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

if K < A:
  print(K)
elif K >= A and A+B >= K:
  print(A)
elif K > A+B:
  print(-K+2*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):
abck = [int(n) for n in input().split()]
if abck[0] >= abck[3]:
    print(abck[3])
elif abck[0] + abck[1] >= abck[3]:
    print(abck[0])
else:
    print(abck[0] * 2 - abck[3] + abck[1])

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

ans = 0

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

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

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

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

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

Ac = min(K, A)
K -= Ac
Bc = min(K, B)
K -= Bc
Cc = min(K, C)

count = 0
count += max(Ac, 0)
count -= max(Cc, 0)
print(count)

Solution (Python):
import sys
a,b,c,k = 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()
if c <= k:
    ans -= c
    print(ans)
else:
    print(ans - k)

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

Solution (Python):

"""
Created on Sun May 10 21:09:01 2020

@author: Kei
"""


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

if a - k >= 0:
    _max = k
else:
    _max = a
    k -= a
    if b - k < 0:
        k -= b
        _max -= k

print(_max)

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

print(ans)

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

if __name__ == "__main__":
  main()

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

if k_a-b>0:
  sum-=(k_a-b)

print(sum)

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

num += A
D -= A
if D < 0:
    num += D

if D > 0:
    D -= B

if D > 0:
    num -= C
    D -= C
    if D < 0:
      num -= D

print(num)

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

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

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

Solution (Python):
import random
import math
import sys
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()

a,b,c,k = MI()
ans = 0
ans+=min(a,k)
k-=min(a,k)
if k>0:
	k-=min(b,k)
if k>0:
	ans-=min(c,k)
print(ans)

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

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

Solution (Python):
N = [int(e) for e in input().split()]
if(N[3] - N[0] > 0):
    N[3] -= N[0]
    if(N[3] - N[1] > 0):
        N[3] -= N[1]
        ans = N[0] - N[3]
    else:
        ans = N[0]
else:
    ans = N[3]
print(ans)

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

if K <= A  :
    Maximum = K
elif K <= A + B :
    Maximum = A 
else :
    Slash = K - A -B 
    Maximum = A - Slash

print(Maximum)

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

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

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

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

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

      ans += 0 * ( b )
      count -= b

      if count <= c:
        ans -= 1 * count
      else:
        ans -= 1 * c

      print(ans)
      return

if __name__ == "__main__":
  main()

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

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

cnt=0
left=k


if a > k:
    left=0
    cnt=k
else:
    left=k-a
    cnt=a

if left>0:
    left-=b

if left>0:
    cnt-=left

print(cnt)

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

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

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

if A >= K:
    ans = K
elif (A+B) >= K:
    ans = A
elif (A+B) < K:
    ans = A - (K-(A+B))
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):
import itertools as iter
import math as m

def main():
    X = list(map(int, input().split()))
    res = 0
    if X[3] - X[0] > 0:
        res += X[0]
        X[3] -= X[0]
    else:
        res += X[3]
        X[3] = 0

    if X[3] - X[1] > 0:
        X[3] -= X[1]
    else:
        X[3] = 0

    if X[3] - X[2] > 0:
        res -= X[2]
    else:
        res -= X[3]

    print(res)

if __name__ == '__main__':
    main()

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

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)