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

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

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

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

k = k - b
  
if k > 0:
  ans -= k

print(ans)

Solution (Python):

import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
a,b,c,k = MI()
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):
    print(K)
elif (A+B>K):
    print(A)
else:
    print(A-(K-(A+B)))

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

num_one_cards = min(a, k)
num_zero_cards = min(b, k - num_one_cards)
num_minus_one_cards = k - num_one_cards - num_zero_cards

score = 1 * num_one_cards + 0 * num_zero_cards + (-1) * num_minus_one_cards

print(score)

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

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

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 = map(int, input().split())
l = {1: a, 0: b, -1: c}
ans = 0
for i, j in l.items():
    if k >= j:
        ans += j * i
        k -= j
    else:
        ans += k * i
        break
print(ans)

Solution (Python):
a = list(map(int, input().split()))
if a[3] <= a[0]:
  print(a[3])
elif a[3] <= a[0] + a[1]:
  print(a[0])
else:
  print(a[0] - (a[3] - a[0] -a[1]))

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

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

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

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

Solution (Python):
tmp = input().split()
a = int(tmp[0])
b = int(tmp[1])
c = int(tmp[2])
k = int(tmp[3])
if(a>=k):
  print(k)
elif(a+b>=k):
  print(a)
else:
  print(a-(k-a-b))

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

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

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

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


def main():
    solve()


if __name__ == '__main__':
    main()

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

if a >= k:
    print(k)

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

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

Solution (Python):
a, b, c, x = map(int, input().split())
total = 0
lst = {1:a, 0:b, -1:c}
for k, v in lst.items():
    if x:
        if x == v:
            total += k * v
            x -= v
        elif x > v:
            total += k * v
            x -= v
        else:
            total += k * x
            x -= x

print(total)

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

Solution (Python):
"""
    Satwik_Tiwari ;) .
    12th july , 2020  - Sunday
"""



from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

from itertools import *
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  
from itertools import combinations as comb 
from itertools import permutations as permutate
from bisect import bisect_left as bl


from bisect import bisect_right as br
from bisect import bisect





BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)






mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") 
def out(var): sys.stdout.write(str(var))  
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())

def zerolist(n): return [0]*n
def nextline(): out("\n")  
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : 
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True



def bfs(g,st,lcatable,level):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                level[i] = level[s]+1
                lcatable[i][0] = s
                visited[i] = 1
                queue.append(i)

    return new

def lcatable(g,n,level): 
    mx = 0
    while(2**(mx) <=n):
        mx+=1
    
    lcatable = [[-1]*mx for i in range(n+1)]
    bfs(g,1,lcatable,level)

    for j in range(1,mx):
        for i in range(1,n+1):
            if(lcatable[i][j-1] != -1):
                lcatable[i][j] = lcatable[lcatable[i][j-1]][j-1]

    return lcatable

def dist(x0,y0,x1,y1):
    return (abs(x0-x1) + abs(y0-y1))

def djkistra(g,st,dist): 
    pq = []
    dist[st] = 0
    pq.append([0,st])
    while(len(pq) != 0):
        curr = heappop(pq)[1]
        for i in range(0,len(g[curr])):
            b = g[curr][i][0]
            w = g[curr][i][1]
            if(dist[b] > dist[curr] + w):
                dist[b] = dist[curr]+w
                pq.append([dist[b],b])
    return dist


def solve():
    a,b,c,k = sep()
    ans = 0
    if(k>a):
        ans+=a
        k-=a
        if(k>b):
            k-=b
            ans-=k
    else:
        ans +=k
    print(ans)

testcase(1)

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

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

ans = 0
if k <= a:
  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())

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

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

ans = 0

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

if K > 0:
    ans += min(K, B) * 0
    K -= B

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

print(ans)

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

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

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

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

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

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

ans = 0

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

k -= a
ans += a

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

k -= b
print(ans - k)

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

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

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


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

print(ans)

Solution (Python):
import sys
def main():
  a ,b ,c ,k = list(map(int,input().split()))
  if k > a:
    ans = a*1
    k-= a
  else:
    ans = (k)*1
    k = 0

  if k > b:
    k-= b
  else:
    k = 0

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

 
  
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())
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):
S = input().split( ) 
a=int(S[0]) 
b=int(S[1])
c=int(S[2])
k=int(S[3])
t=2*a+b-k
if k <= a:
  print(str(k))
elif a < k <= a + b:
  print(str(a))
else: print(str(t))

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

Xa = min(K,A)
K2 = K - Xa
Xb = min(K2,B)
Xc = K2 - Xb

print(Xa - Xc)

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_A = 0
count_B = 0
count_C = 0
count = 0
if A >= K:
    count_A += K
else:   
    K -= A
    count_A += A
    if B >= K:
        count_B += K
    else:
        K -= B
        count_B += B
        count_C += K

print(count_A - count_C)

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

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

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

ans = 0

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

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

if __name__ == "__main__":
    main()

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

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

re = k
na = min(a, re)
re -= na
nb = min(b, re)
re -= nb
nc = min(c, re)

print(na - nc)

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



ans = 0

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

K -= B

if K > 0:
    ans -= K

print(ans)

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

a,b,c,k = list(map(int,input().split()))
if k<a:
    print(k)

elif 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:
    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())
ans=min(a,k)
k=k-min(a,k)
k=k-min(b,k)
ans-=min(c,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 = list(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

ans -=k

print(ans)

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

cnt=0

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

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


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())
while True:
    ans = 0
    ans += min(A,K)
    K -= min(A,K)
    if K<=0:
        break
    K -= B
    if K<=0:
        break
    ans -= K
    break
print(ans)

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

ans = a

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

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

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

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

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


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

print(ans)

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

if a > k:
  _sum += k
else:
  k -= a
  _sum += a
  if b > k:
    b = 0
  else:
    k -= b
    if c > k:
      _sum -= k
    else:
      _sum -= c

print (_sum)

Solution (Python):






def main():
    A,B,C,K = map(int, input().split())
    print(min(A,K)-max(0,min(C, K-A-B)))

main()

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

if __name__ == "__main__":
    main()

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

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

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

X = A + 0 * Y + (-1) * Z
print(X)

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

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

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

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

Solution (Python):
A, B, C, K = [int(_) for _ in input().split()]
print(K if K <= A else A if K <= A + B else 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 - 1 * (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)

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

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

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

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

print(num)

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

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

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

Solution (Python):

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

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

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

Solution (Python):
import sys
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
 
a,b,c,k = Mi()
if k <= a:
  print(k)
  exit(0)
ans = a
k -= a
if k > b:
  ans -= k-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):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

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

if __name__ == "__main__":
    main()

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

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

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

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

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

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

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

Solution (Python):

import sys

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


sum_num = 0

for num,cnt in [(1,A), (0,B), (-1,C)]:
    if cnt <= K:
        K -= cnt
        sum_num += num*cnt
    else:
        print( sum_num + num*K )
        sys.exit()


print(sum_num)

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

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

Solution (Python):
from sys import exit
A, B, C, K = [int(x) for x in input().split()]

if A + B >= K:
    print(min(A, K))
    exit()

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

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

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

Solution (Python):
def maximum():
    A,B,C,K = map(int,input().split())
    num = 0
    max = 0
    if A <= K:
        max = A
        num = K - A
        if B <= num:
            num = num - B
            max -= num
            print(max)
            return
        else:
            print(max)
            return
    else:
        print(K)
        return
maximum()

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

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

Solution (Python):
a,b,c,k = map(int, raw_input().split())
t = [a,b,c]
s = 0
h = {0:1, 1:0, 2:-1}
for i,e in enumerate(t): 
	s += min(k, e) * h[i]
	k-= min(e,k)
print s

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

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

    print(A-(K - A - B))

    return


resolve()

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

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())
ret = min( A, K )
if A < K:
  ret -= max( 0, K - A - B )
print( ret )

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

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

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

Solution (Python):
a, b, c, k = map(int, input().split()); s,t=0,0;
while(True):
    s=a
    if s>=k:
        t = k;    break
    else:
        t=a;    s += b
        if s>=k:
            break;
        else:
            s += c
            if s >= k:
                d = c-s+k;    t -= d
                break;
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(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)
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())
ans = 0

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

print(ans)

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

    m = 0
    if k <=a:
        m = k
    elif k <=(a+b):
        m = a
    elif k <= a+b+c:
        m = (a-(k-(a+b)))
    return m
a, b, c , k = map(int, input().split())
print(main(a,b,c,k))

Solution (Python):
import sys

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

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

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

if K > A+B:
    s = A-(K-A-B)
else:
    s = min(A,K)

print(s)

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

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

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

print(sum)

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

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    A, B, C, K = MI()
    
    na = min(A, K)
    K -= na
    
    nb = min(B, K)
    K -= nb
    
    nc = min(C, K)
    print(na - nc)

if __name__ == '__main__':
    solve()

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

ans = 0
for i, j in zip([1, 0, -1], [a, b, c]):
    x = min(k, j)
    ans += i*x
    k -= x
print(ans)

Solution (Python):



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

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

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

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

Solution (Python):
import sys

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

if A >= K:
    print(1*K)
    sys.exit()

elif A+B >= K:
    print(1*A)
    sys.exit()

else:
    print(A*1 + (K-(A+B))*(-1))
    sys.exit()

Solution (Python):
def solve(a, b, c, k):
    if k <= a:
        return 1 * k
    if k <= a+b:
        return 1 * a
    rest = k - a - b
    return (1*a) - (1*rest)

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

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

Solution (Python):
from sys import stdin
data = stdin.readline().strip()

a = int(data.split()[0])
b = int(data.split()[1])
c = int(data.split()[2])
k = int(data.split()[3])

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

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

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

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

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