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 0s and C cards with -1s.

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 1s 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



Sample input:
2 1 1 3


Sample output:
2

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
a,b,c,k=n1()
p0(a+b>=k,min(a,k),a-(k-a-b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if a >= k:
    ans = k
elif a + b >= k:
    ans += a
else:
    k -= a+b
    ans += a-k

print(ans)

Submission status: Accepted

Solution code:
# 入力をintにして変数に格納
a, b, c, k = map(int, input().split())

# KとA,Bの大きさに応じて場合分けして最大値計算
if a >= k :
    max = k

elif a+b >= k :
    max = a

elif( a+b <= k ):
    max = a - ( k - a - b )

# 結果を出力
print(max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if k > 0:
  ans -= k

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = [int(x) for x in input().split()]
k = n[-1]
a = n[0]
b = n[1]
c = n[2]
if (k <= a):
    print(k)
elif (k <= a+b):
    print(a)
else:
    print(a-(k-a-b))

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
s = 0
for _ in zip([a, b, c], [+1, 0, -1]):
    if k > 0:
        x = min(k, _[0])
        k -= x
        s += x * _[1]
    else:
        break
print(s)

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))

n = nums[3]
ans = 0
add_num = 1
i = 0
while n > 0:
    if n > nums[i]:
        ans += (add_num * nums[i])
        n -= nums[i]
    else:
        ans += (n * add_num)
        break
    add_num -= 1
    if i == 2:
        break
    i += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def get_input() -> tuple:
    """標準入力の取得

    Returns:
        tuple -- 標準入力
    """
    A, B, C, K = list(map(int, input().split()))
    return A, B, C, K


def main(A: int, B: int, C: int, K: int) -> None:
    """求解処理.
    Kの値で場合分けする.

    Arguments:
        A {int} -- 整数
        B {int} -- 整数
        C {int} -- 整数
        K {int} -- 整数
    """
    result = int()
    if K <= A:
        result = K
    elif A < K and K <= A + B:
        result = A
    elif A + B < K and K <= A + B + C:
        result = 2*A + B - K

    # 結果出力
    print(result)


if __name__ == "__main__":
    A, B, C, K = get_input()
    main(A, B, C, K)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

S = A+B+C
result = 0

if ( K > (A+B) ):
    result = A*(1) + (K-(A+B))*(-1)
elif ( (A+B) >= K >= A):
    result = A*(1)
elif ( A > K ):
    result = K*(1)

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = list(map(int,input().split(' ')))
x_1 = l[0]
x_0 = l[1]
x_neg = l[2]
K = l[3]
if (K<=x_1):
  print(K)
elif (K-x_1<=x_0):
  print(x_1)
else :
  print(x_1 -(K-x_1-x_0))

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inputs = list(map(lambda x: int(x), input().split()))

max = 0
v = 1

for i in inputs[0:3]:
    if i > inputs[3]:
        i = inputs[3]
    max += v * i
    inputs[3] -= i
    v -= 1
    if inputs[3] <= 0:
        break

print(max)

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = map(int, input().split())
    ans = min(a, k)
    k = max(k-a, 0)
    if k == 0:
        print(ans)
        return
    k = max(k-b, 0)
    if k == 0:
        print(ans)
        return
    print(ans - k)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    if b >= k:
        print(point)
    else:
        k -= b
        point -= k
        print(point)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

point = min(a, k)
k -= min(a, k)
k -= min(b,k)
point -= min(c,k)
print(point)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,C,K=[int(x) for x in input().split()]
S=min(K,A)
K-=A
if K>0:
  K-=B
if K>0:
  S-=K
print(S)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_line = input().split()
plus = int(input_line[0])
zero = int(input_line[1])
minus = int(input_line[2])
maisu = int(input_line[3])

if plus >= maisu:
    print(maisu)
elif plus + zero >= maisu:
    print(plus)
else:
    minus_num = maisu - (plus + zero)
    print(plus - minus_num)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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


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

print(calc(a, b, c, k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

a, b, c, k = map(int, sys.stdin.readline().strip().split())

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
a, b, c, k = map(int, input().split())

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

# 出力
print(str(ans))

Submission status: Accepted

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

print(main())

Submission status: Accepted

Solution code:
src = list(map(lambda x : int(x), input().split(' ')))
dst = 0
k = src[3]
dst += (src[0] if src[0] <= k else k)
k -= dst
if k != 0:
  k -= (src[1] if src[1] <= k else k)
if k != 0:
  dst -= (src[2] if src[2] <= k else k)
  
print(dst)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i= [int(i) for i in input().split()]
A = i[0]
B = i[1]
C = i[2]
K = i[3]
m = 0
if K>=A:
    m += A*1
    K -= A
else:
    m +=K*1
    K=0
if K>=B:
    m += B*0
    K -= B
else:
    m +=K*0
    K=0
if K>=C:
    m += C*-1
    K -= C
else:
    m +=K*-1
    K=0
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input().split()
n = [int(i) for i in n]
count = 0

a = n[0]*1
b = n[1] 
c = n[2]*-1
while n[-1] > 0:
    if n[0] >= n[-1] and n[0] != 0:
        count = n[-1]*1
        n[-1] = 0
    elif n[0] < n[-1] and n[0] != 0:
        count += n[0]
        tmp = n[0]+n[1]
        n[-1] -= tmp
        n[0] = 0
    elif n[2] >= n[-1]:
        count += n[-1]*-1
        n[-1] = 0
    elif n[2] < n[-1]:
        count += c
        n[-1] = 0

print(count)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, C, K = LI()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
t = k
cnt = 0
if k <= a:
    print(k)
    exit()
else:
    cnt = a
    t -= a

if t <= b:
    print(cnt)
    exit()
else:
    t -= b

cnt -= t
print(cnt)

Submission status: Accepted

Solution code:
num = [int(i) for i in input().split()]
res = 0
a = num[0]
b = num[1]
c = num[2]
k = num[3]

if a < k:
    res = a
    k -= a
elif a >= k:
    res = k
    print(res)
    exit()

if b < k:
    k -= b
elif b >= k:
    print(res)
    exit()

if c <= k:
    res -= c
elif k > 0:
    res -= k
print(res)

Submission status: Accepted

Solution code:
# ABC167B

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)

Submission status: Accepted

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

def f():
    if K <= A:
        return K
    elif K <= A + B:
        return A
    else:
        #1が書かれたカードの枚数 - -1が書かれたカードの枚数（）
        return A - (K - A - B)

print(f())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k = [int(x) for x in input().split(' ')]


def verify_sum(a,b,c,k):
    if k == a:
        print(a)
        return

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

verify_sum(a,b,c,k)

Submission status: Accepted

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

Submission status: Accepted

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

print(min(A,K)-max(K-A-B,0))

Submission status: Accepted

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

print(min(A,K)-min(max(K-A-B,0),C))

Submission status: Accepted

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

res = min(K, A) - max(K-A-B, 0)
print(res)

Submission status: Accepted

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

result = 0
t = min(a, k)
result += t
k -= t
t = min(b, k)
k -= t
t = min(c, k)
result -= t
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

points=0

if K<=A:
    points=K
elif K<=A+B:
    points=A
else:
    points=2*A+B-K

print(points)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
data=list(map(int,input().split()))
goukei=0
num=data[3]
for i in range(0,len(data)-1):
    if data[i]<=num:
        if i==0:
            goukei=goukei+data[i]
        elif i==2:
            goukei=goukei-data[i]
        num=num-data[i]
    else:
        if i==0:
            goukei=goukei+num
        elif i==2:
            goukei=goukei-num
        num=0
print(goukei)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c, k = [int(x) for x in input().split()]
res = 0
i = 0
t = [a, b, c]
j = [1, 0, -1]
while k > 0:
  m = min(k, t[i])
  k -= m
  res += j[i] * m
  i += 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i = input()
j = i.split(" ")

a = int(j[0])
b = int(j[1])
c = int(j[2])
k = int(j[3])

s = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,k=map(int,raw_input().split())
ans=0
if a<=k:
	ans+=a
	k-=a
else:
	ans=k
	k=0
if k!=0:
	if b<=k:
		k-=b
	else:
		k=0
if k!=0:
	if c<=k:
		ans-=c
	else:
		ans-=k
print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    num = list(map(int, input().split()))

    if (num[3] == 0):
        print(0)
    elif (num[0] == 0 and num[1] == 0 and num[2] == 0):
        print(0)
    elif (num[3] <= num[0]):
        print(num[3])
    else:
        print(num[0] - num[3] + num[0] + num[1])

Submission status: Accepted

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

Submission status: Accepted

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

card = [A, B, C]
cardnumber = [1, 0, -1]

sum = 0
for i in range(0, 3):
	if card[i] > K:
		sum += K*cardnumber[i]
		break
	else:
		sum += card[i]*cardnumber[i]
		K -= card[i]

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! env/bin/local python3
# -*- coding:utf-8 -*-

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

"""
k < a -> a
k <= a + b -> a
k > a + b -> a - (k - (a + b))
"""

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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)

Submission status: Accepted

Solution code:
from sys import stdin
 
a=stdin.readline().split()
A=int(a[0]) #1
B=int(a[1]) #0
C=int(a[2]) #-1
K=int(a[3])
 
if K<=A:
  print(K)
elif K<A<=A+B:
  print(A)
else:
  print(2*A+B-K)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if a < k:
    sum += a
    k -= a
else:
    sum += k
    k = 0

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

if 0 < k:
    sum -= k
    k = 0

print(sum - k)

Submission status: Accepted

Solution code:
A, B, C, K = (int(x) for x in input().split())
if A >= K:
    ans = K
else:
    ans = A
    tmp = K - A
    if B >= tmp:
        pass
    else:
        tmp = tmp - B
        ans += tmp * (-1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
oneCard, zeroCard, miniusOneCard, getCardNum = map(int, input().split())

if oneCard >= getCardNum: print(getCardNum)
elif oneCard + zeroCard >= getCardNum: print(oneCard)
else: print(oneCard - (getCardNum - oneCard - zeroCard))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

K -= B

if C >= K and K > 0:
    result -= C - (C - K)

print(result)

Submission status: Accepted

Solution code:
s = input()
A, B, C, K = [int(v) for v in s.split(" ")]

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

Submission status: Accepted

Solution code:
def solve(a, b, c, k):
    if k <= a + b:
        return min(k, a)
    else:
        return 2*a + b - k

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

Submission status: Accepted

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

if a+b>=k:
  print(min(a,k))
else:
  print(2*a+b-k)

Submission status: Accepted

Solution code:
s = input()
A, B, C, K = [int(v) for v in s.split(" ")]

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

Submission status: Accepted

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


"""
print(a)
print(b)
print(c)
print(k)
"""
if a >= k:
    print(k)

elif (a + b) >= k:
    print(a)

else:
    print(a - (k - a - b))

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

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

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:35:24 2020

@author: Kanaru Sato
"""

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
l = [[A, 1], [B, 0], [C, -1]]
res = 0

for e in l:
    if K >= e[0]:
        K -= e[0]
        res += e[1] * e[0]
    else:
        res += e[1] * K
        break

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 1000000007

#n = int(input())
#b = int(input())
a,b,c,k = [int(i) for i in input().split()]
#table = [int(i)  for i in input().split()] for j in range(h)] #table[h][w]
#table = [list(input()) for n in range(r)] #table[h][w]
#s = [int(i) for i in input().split()]
#s = [int(i) for i in range(n)]
#s = [int(input()) for i in range(n)]
#s = input()

#list = list(s)
#dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
#dp = [[[0 for _ in range(11)] for _ in range(2)] for _ in range(11)]

#a = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

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)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC167b
a, b, c, k = map(int, input().split())
# print(a, b, c, k)

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

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    A =[]
    B = input()
    A = B.split()

    a = int(A[0])
    b = int(A[1])
    c = int(A[2])
    k = int(A[3])

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

Submission status: Accepted

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

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

print(max)

Submission status: Accepted

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

if a >= k: 
    sum = k

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

print(sum)

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input().split(" ")

k = int(s[3])

sum = 0

if k >= int(s[0]) :
    sum += int(s[0])
    k -= int(s[0])
else :
    sum += k
    k =0

if k >= int(s[1]) :
    k -= int(s[1])
else :
    k =0

if k :
    sum -= k

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def test(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 = list(map(int, input().split(" ")))
print(test(a,b,c,k))

Submission status: Accepted

Solution code:

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

count = 0

if K <= A:
    count += K

elif K <= A + B:
    count += A

else:
    count += 2*A + B - K

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
arr = [int(char) for char in input().split(" ")]
a, b, c, k = arr[0], arr[1], arr[2], arr[3]
if k<=a:
  print(k)
elif a+b>=k:
  print(a)
else:
  print(a-(k-(a+b)))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a = 0
b = 0
c = 0

if A <= K:
    a = A
    if A + B <= K:
        b = B
        if A + B + C <= K:
            c = C
        else:
            c = K - A - B
    else:
        b = K - A
        
else:
    a = K

print(a-c)

Submission status: Accepted

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

    xa = min(A, K)
    K -= xa
    xb = min(B, K)
    K -= xb
    xc = K
    ans = xa - xc
    print(ans)

if __name__ == "__main__":
    resolve()