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

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    if A > K:
        print(K)
        return
    K -= A
    if B > K:
        print(A)
        return
    K -= B
    print(A - K)
    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):

import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() 
ni = lambda: int(ns())
na = lambda: 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)))
    return


if __name__ == '__main__':
    main()

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

na = min(a, k)
nb = 0
nc = 0

if na < k:
    nb = min(b, k - na)

if na + nb < k:
    nc = k - na - nb

print(na - nc)

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

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,k = map(int,input().split())
print(min(k, a) - max(0, k-a-b))

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    if A >= K:
        print(K)
        exit()
    sum = A
    K -= A
    K -= B
    print(sum + max(K,0)*-1)
    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 K < A:
    print(K)
elif K < A + B:
    print(A)
else:
    print(A - (K - A - B))

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

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

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

Solution (Python):



def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    

    
    

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

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

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

Solution (Python):
a, b, c, k = map(int, input().split())
if k <= a:
    print(k)
elif k <= 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 -= a
if k <= 0:
    print(score)
    exit()
k -= b
if k <= 0:
    print(score)
    exit()
print(score-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())
ans = 0
ans += min(A, K)
K -= A
if K > 0:
    K -= B
if K > 0:
    ans -= K
print(ans)

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

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

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

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

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

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

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

score = 0
if k < a:
	score = k
else:
	score = a
	k -= a

	if k > b:
		k -= b
		score -= k

print(score)

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    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):
import sys
a, b, c, k = map(int, input().split())
r = 0
x = min(a, k)
k -= x
r += x
if k==0:
    print(r)
    sys.exit()
k -= b
if k <= 0:
    print(r)
    sys.exit()
x = min(k, c)
r -= x
print(r)

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

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

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

ans = 0

tmp = min(a, k)
ans += tmp
k -= tmp

tmp = min(b, k)
ans += 0
k -= tmp

tmp = min(c, k)
ans -= tmp
k -= tmp 
print(ans)

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

if K<=A:
	print(str(K))
elif K<=A+B:
	print(str(A))
else:
	print(str(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):
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
MOD = 10**9+7


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())
S = 0
S+=1*min(A,K)
K-=A
K-=B
S-=1*min(C,max(K,0))
print(S)

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

import sys
input = sys.stdin.readline

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

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

if k - a < b:
    print(a)
    exit()
else:
    pass

print(ans - (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 = [int(x) for x in input().split()]
picka = min(a, k)
a -= picka
k -= picka
pickb = min(b, k)
b -= pickb
k -= pickb
pickc = min(c, k)
c -= pickc
k -= pickc
print(picka - pickc)

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

a, b, c, k = get_ints()
xs = [a, b, c]
vs = [1, 0, -1]
ans = 0
for i in range(3):
    take = min(xs[i], k)
    ans += vs[i] * take
    k -= take

print(ans)

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

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

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

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

if N <= A:
    print(N)
else:
    if N <= A+B:
        print(A)
    else:
        print(A-(N-A-B))

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

if __name__ == "__main__":
    main()

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

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

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

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

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

if c >= k:
    ans -= k
    k = 0
else:
    ans -= c
    k -= c

print(ans)

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

Solution (Python):

import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def solve(A: int, B: int, C: int, K: int):
    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)
else:
    k -= a
    if b>=k: print(a)
    else:
        k -= b
        print(a-k)

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

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

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():  
    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)
if __name__ == '__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

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

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

    ans = 0
    rest = k

    use = min(k, a)
    ans += use
    k -= use

    if k == 0:
        print(ans)
        return

    use = min(k, b)
    k -= use

    if k == 0:
        print(ans)
        return

    use = min(k, c)
    ans -= use

    print(ans)


if __name__ == '__main__':
    main()

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())
num_A = min(A, K)
num_B = min(B, K - num_A)
num_C = K - num_A - num_B
ans = num_A - num_C
print(ans)

Solution (Python):
import sys
from math import log2,floor,ceil,sqrt



Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

a,b,c,k = Ri()
ans = 0
ans+=(min(a,k))
k-=min(a,k)
k-=min(b,k)
ans-=min(k,c)

print(ans)

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

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

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

A, B, C, K = MAP()

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

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    A, B, C, K = Scanner.map_int()
    ans = min(K, A)
    K -= ans
    t = min(K, B)
    K -= t
    ans -= min(K, C)
    print(ans)


def main():
    
    solve()


if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):


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

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

print(score)

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

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

K -= min(B, K)

ans -= min(C, K)

print(ans)

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

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

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

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











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,C,K=MI()
    if(K<=A):
        print(K)
    elif (K<=A+B):
        print(A)
    else:
        K-=A+B
        print(A-K)

if __name__ == '__main__':
    main()

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

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

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

if k > 0:
    ans += -1 * min(c, k)

print(ans)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b,c,k = na()

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,_,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))
if __name__=='__main__':
    main()

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

Solution (Python):
a, b, c, k = map(int, raw_input().split())
ans = 0
ans += min(a, k)
k -= ans 
tmp = min(b, k)
k -= tmp
ans -= 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 = list(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):
def main():
    A, B, C, K = map( int, input().split())
    if A >= K:
        print(K)
        return
    ans = A
    K -= A
    if B >= K:
        print(ans)
        return
    K -= B
    print(ans - K)
if __name__ == '__main__':
    main()

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

Solution (Python):



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

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


print(main())

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

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

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

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

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

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

Solution (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div

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

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

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

arr = [a,b,c]


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

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

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

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

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

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

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

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

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

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    A, B, C, K = map(int, input().split())
    ans = 0
    ans += min(A, K) * 1
    if A >= K:
        print(ans)
        exit()
    K -= A
    if B >= K:
        print(ans)
        exit()
    K -= B
    ans += -1 * min(C, K)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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


if __name__ == "__main__":
    main()

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

    total = 0
    rem = k
    total += min(a, rem)
    rem = max(0, rem - a)
    rem = max(0, rem - b)
    total -= min(c, rem)
    rem = max(0, rem - c)

    print(total)

if __name__ == '__main__':
    main()

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

a,b,c,k = get_nums_l()

ans = min(a, k)
ans -= max(0, k-a-b)
print(ans)

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

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

print(ans)

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

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

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

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    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 = [int(_n) for _n in 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()))
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=map(int,input().split())
if k<=a:
    print(k)
elif k>a+b:
    print(a-(k-a-b))
else:
    print(a)

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

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

x = min(A, K)
z = max(0, min(C, K - A - B))

print(x - z)

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

n1 = min(A, K)
ans = n1
K -= n1

n2 = min(B, K)
K -= n2

n3 = min(C, K)
ans -= n3

print(ans)

Solution (Python):



from math import *
from copy import *					
from heapq import *					
from string import *				
from random import *				
from bisect import *				
from sys import stdin				
from sys import maxsize				
from operator import *				
from itertools import *				
from collections import Counter		
from collections import defaultdict 

'''

'''

def solve(l):
	a,b,c,k = l
	if(k <= a):
		return k
	elif(k <= a+b):
		return a
	else:
		return a-(k-a-b)
	

l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    A, B, C, K = map(int, rl().split())
    
    if K <= A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A - (K - A - B))


if __name__ == '__main__':
    solve()

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

ans = 0
ans += max(min(a, k), 0)
k -= a
k -= b
ans -= max(min(c, k), 0)

print(ans)

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