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

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

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

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

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



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 = tuple(map(int, input().split()))
if(k<=a):
    print(k)
elif(k>a and k<a+b):
    print(a)
else:
    print(2*a  + b - k)

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

Solution (Python):



import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, B, C, K = i2nn()
    if K < A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A - (K - (A + B)))
    return

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

Solution (Python):



import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf



import math

import bisect

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

if __name__ == '__main__':
    a, b, c, k = list(map(int, input().split()))
    ans = solve(a, b, c, k)
    
    print(ans)

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


print(main())

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

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

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

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

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

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

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

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

    ans = 0
    if k <= a:
        return k
    
    ans += a
    k -= a
    if k <= b:
        return ans
    
    k -= b
    return ans - k


print(submit())

Solution (Python):
import sys

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

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

    if B >= K:
        print(ans)
        return
    else:
        K -= B
    
    if C >= K:
        ans -= K
        print(ans)
        return
    else:
        ans -= C
        print(ans)

    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b, c, k = na()

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

print(ans)

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

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

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

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

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

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

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

print(solve())

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

total = 0

first = min(a, k)
k -= first
total += first

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

third = min(c, k)
total -= third

print(total)

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

    res = K
    ans = 0
    ans += min([A, K])
    res -= min([A, K])
    if res == 0:
        print(ans)
        exit()
    res -= min([res, B])
    if res == 0:
        print(ans)
        exit()
    ans -= min([res, C])
    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 = list(map(int, input().split()))

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

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

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

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

print(M)

Solution (Python):
a,b,c,k=(int(i) for i in input().split())
s=0
s+=min(k,a)
k-=a
if(k>0):
  k-=b
  if(k>0):
    k1=min(k,c)
    k-=k1
    s-=k1
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())
count = 0
if k >= a:
  count += a
  k = k-a
  if k >= b:
    k = k-b
    count -= k
  else:
    pass
else:
  count += k
print(count)

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

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

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

if __name__ == "__main__":
  main()

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

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


def solve():
    global A, B, C, K
    result = 0
    if A >= K:
        return K
    K -= A
    result += A

    if B >= K:
        return result
    K -= B

    return result - K


print(solve())

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

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

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

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

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

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

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

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

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

ans = 0

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

if K>0:
    ans -= K

print(ans)

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

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

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

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

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

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

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

Solution (Python):
if __name__ == '__main__':
    s = input().rstrip().split(' ')
    A, B, C, K = int(s[0]), int(s[1]), int(s[2]), int(s[3])
    score = 0
    if K <= A:
        score = K
    elif K <= A+B:
        score = A
    elif K <= A+B+C:
        score = A - (K-A-B)

    print(score)

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

def p(A, B, C, K):
    point = 0

    if K >= A:
        K -= A
        point += A
    else:
        point += K
        return point

    if K >= B:
        K -= B
    else:
        return point
    
    point -= K
    return point


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

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

Solution (Python):
def maxSum(a, b, c, k):
  currentSum = 0
  currentSum += min(a, k)
  k -= a
  if k <= 0:
    return currentSum
  k -= min(b, k)
  if k <=0:
    return currentSum
  currentSum -= min(c, k)
  return currentSum

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

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

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

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

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

print(m)

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

ans = 0

if A - K >= 0:
    ans = K
else:
    ans = A
    K -= A
    if B - K >= 0:
        pass
    else:
        K -= B
        ans -= K

print(ans)

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
import sys

A, B, C, K = [int(x) for x in stdin.readline().rstrip().split()]
if K <= A:
    print(K)
    sys.exit()
elif K <= A+B:
    print(A)
    sys.exit()
else:
    print(A-(K-A-B))
    sys.exit()

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

if B < K:
    K -= B
else:
    print(ans)
    exit()

if C < K:
    K -= C
    ans -= C
else:
    ans -= K
print(ans)

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

score = 0
if (k <= a):
    score += k
    k = 0
else:
    score += a
    k -= a
    
if (k <= b):
    k = 0
else:
    k -= b
    
score -= k

print(score)

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

Solution (Python):

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

ans = 0
li = [A, B, C]
ll = [1, 0, -1]
i = 0
while K > 0:
    if li[i] <= K:
        ans += ll[i] * li[i]
        K -= li[i]
    else:
        ans += ll[i] * K
        K = 0
    i += 1
print(ans)

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

ans = 0

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

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

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

if(k<=b):
    k=0
else:
    k-=b

if(k>0):
    ans-=k
    k=0

print(ans)

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

Solution (Python):












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

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

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

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

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

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

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

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

if K <= A:
    print(K)
else:
    AB=A+B
    if K <= AB:
        print(A)
    else:
        K2=K-A-B
        Ans=A-K2
        print(Ans)

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

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

Solution (Python):











A, B, C, K = [int(x) for x in input().split()]

score = min(A, K)

K -= A

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

K -= B

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

score -= min(K, C)

print(score)

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

Solution (Python):
import sys

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

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

Solution (Python):


def solve():
    ke = k
    ans = min(a, ke)
    ke = max(0, ke - a - b)
    ans -= ke
    print(ans)
    return



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

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):
list = [int(i) for i in input().split(" ")]
sum = 0
if list[0] < list[3]:
    sum = list[0]
    if list[0] + list[1] < list[3]:
        minus = list[3] - list[1] - list[0]
        sum = sum - minus
else:
    sum = list[3]
print(sum)

Solution (Python):
import sys
import math
from collections import deque
import heapq
import itertools
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b,c,K = IL()

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

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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


if __name__ == '__main__':
    main()

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

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

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

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

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

Solution (Python):
A, B, C, K = map(int, input().split())
print(min(A, K)-max(0,min(C,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):
a,b,c,k = map(int,input().split())

ans = 0

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

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

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

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

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

Solution (Python):
import sys
import math

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

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

Solution (Python):
import itertools
from collections import defaultdict
import collections
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

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

Solution (Python):

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

Solution (Python):
a,b,c,k = map(int, raw_input().split(' '))
def f(a,b,c,k):
	elems = [(a,1), (b,0), (c,-1)]
	i = 0
	res = 0
	while(k and i <len(elems)):
		res += min(k, elems[i][0]) * elems[i][1] 
		k-= min(k, elems[i][0])
		i+=1
	return res

print f(a,b,c,k)

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

    if K <= A:
        ans = K
    elif A < 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())

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

Solution (Python):




def input_int():
    return int(input())



def int1(x):
    return int(x) - 1



def input_to_int_map():
    return map(int, input().split())



def input_to_int_tuple():
    return tuple(map(int, input().split()))



def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    a, b, c, k = input_to_int_map()

    if a - k  >= 0:
        return 1 * k

    if a + b - k >= 0:
        return 1 * a

    return 1 * a + (-1 * (k - a - b))


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

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

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

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

else:
    ans+=K
    print(ans)
    exit()

if B<=K:
    K-=B

else:
    print(ans)
    exit()

if C<=K:
    ans-=C
    print(ans)

else:
    ans-=K
    print(ans)

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

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

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

print(ans)

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

Solution (Python):





import sys

def main():
    a, b, c, k = map(int, sys.stdin.readline().split())
    ans = 0
    if k <= a:
        print(k)
        return
    else:
        k -= a
        ans += a
    if k <= b:
        print(ans)
        return
    else:
        k -= b
        print(ans - k)
    return

if __name__ == "__main__":
    main()

Solution (Python):
import sys

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

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

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

if K <= A:
    print(K)

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

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

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

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

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

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

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

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

if B <= temp:
    temp -= B
else:
    temp = 0

if C <= temp:
    ans -= C
else:
    ans -= temp

print(ans)

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

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

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

Solution (Python):
def calc(A, B, C, K):
    if K < A:
        return K
    elif K <= A + B:
        return A
    else:
        return A - (K - A - B)

    

(A, B, C, K) = tuple([int(s) for s in input().split()])
print(calc(A, B, C, K))

Solution (Python):

import sys


def solve(A: int, B: int, C: int, K: int):
    sum = 0
    l = K - A
    if l <= 0:
        sum += K
    else:
        sum += A
    l -= B
    if l > 0:
        sum -= l
    print(sum)
        
        
    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
input = lambda: sys.stdin.readline().rstrip()
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, 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 decimal import Decimal
inf = float('inf')
mod = 1000000007

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

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

print(ans)

Solution (Python):
def main():
    A, B, C, K = [int(x) for x in input().split()]
    ans = 0

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

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

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

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

Solution (Python):


def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

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

A,B,C,K = input_multiple_number()

ans = 0

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

Solution (Python):
import io, os

R = lambda : map(int, input().split())
a, b, c, k = R()
ans = min(a, k)
if a > ans or k <= a + b:
    print(ans)
else :
    print(ans - min(c, k - a - b))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    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)
elif K <= A+B+C:
    print(A-(K-A-B))

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

Solution (Python):
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

ans = 0


ans += min(A, K)
K -= A
if K <= 0:
    print(ans)
    sys.exit()

K -= B
if K <= 0:
    print(ans)
    sys.exit()

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

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

Solution (Python):
import sys

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


def resolve():
    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
            res -= k
            print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys 
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for tt in range(1):
	a,b,c,k = map(int,input().split())
	ans = 0
	if k>=a:
	  k-=a
	  ans +=a
	else:
	  ans += k
	  k = 0
	if k>=b:
	  k-=b
	else:
	  k = 0
	if k>=c:
	  k-=c
	  ans -= c
	else:
	  ans -= k
	  k = 0
	print(ans)

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

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

k-=b



if k<0:
    print(ans)
else:
    print(ans-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):
import sys
sys.setrecursionlimit(10000000)


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


if __name__ == '__main__':
    main()

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

Solution (Python):

''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys

def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    a,b,c,k = _ia()
    r = min(k,a)
    if k > a+b:
        r -= (k-a-b)
    return r

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

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

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

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

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

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

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

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