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: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
data = input().rstrip().split(" ")
one = int(data[0])
zero = int(data[1])
minus = int(data[2])
num = int(data[3])
answer = 0
if one + zero >= num:
    answer = one
else:
    answer = one * 2 + zero - num
print(answer)

Submission status: Wrong Answer

Solution code:
import sys

# print('input >>')
A, B, C, K = map(int,(input().split()))

ans = 0
rest = K

rest -= A

if rest <= 0:
    print(K)
    sys.exit()

rest -= B
if rest <= 0:
    print(A)
    sys.exit()

print(-(K-A-B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

max = 0
for i in range(A):
    max+=1
    K-=1
    if K ==0:
        break
        

if not K==0:
    for j in range(B):
        max+=0
        K-=1
    
if not K==0:
    for k in range(C):
        max-=1
        K-=1
    
print(max)

Submission status: Wrong Answer

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

a = 0
for i in range(1,A+1):
    a = a + 1

if (A + B) < K:
    for i in range(0,K-A-B):
        a = a - 1

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split())
count=0
mai=0
if k<=a:
    print(k)
    exit()
if a+b<=k:
    print(a)
    exit()
while a>0:

    count+=1
    mai+=1
    a-=1
    if mai==k:
        print(count)
        exit()

while b>0:
    
    count+=0
    mai+=1
    b-=1
    if mai==k:
        print(count)
        exit()


while c>0:
    count-=1
    mai+=1
    c-=1
    if mai==k:
        print(count)
        exit()


print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a = min(A, K)
b = max(K - a, 0)
b = min(b, B)
c = max(K - a - b, 0)

print(A * 1 + c * (-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

life -= B

ans = ans - life

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

if a == 0 and b == 0 and c == 0:
    print(0)
    exit()
k -= b
l = k - a
a = min(a,k)
ans = a - l
print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

count = 0

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


print(count)

Submission status: Wrong Answer

Solution code:

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

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

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

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

print(ans)

Submission status: Wrong Answer

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

ans=0
if a<=k:
  ans=a

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if k <= a:
    ans = a
else:
    ans = a
    k = k - a
    # print(k, b)
    if k > 0 :
        # print("a")
        k = k - b
        # print(k, c)
        if k > 0:
            ans += k * (-1)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

count = 0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    res += a
    k -= a
    if k > 0:
        k -= b
    if k > 0:
        res += (-1 * min(c, k))
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math

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

A = a
B = 0
C = -1 * c

if k - a > 0:
    if k -a -b > 0:
        print(a + b -(k -a - b))
        sys.exit()
    else:
        print(a)
else:
    print(a)

Submission status: Wrong Answer

Solution code:

A,B,C,N = map(int,input().split())
sum = 0
if A > N:
    sum = A
else:
    if B >= N-A:
        sum = A
    else:
        sum =A - (N-A-B)

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    A,B,C,K = map(int,input().split())
    abc = [A,B,C]
    ans = 0

    a = A
    b = (K-a) if (K-a)>0 and (K-a)<B else B
    c = K-A-B
    print(a-c)


main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

s= 0

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = tuple(int(c) for c in input().split(' '))

if A >= K:
    print(A)
    exit()
else:
    bc = K - A  # A < K なのでbc >= 1
    #assert bc >= 1
    if B >= bc:
        print(A)
        exit()
    else:
        # B < bc
        cc = bc - B
        #assert cc >= 1
        print(A - cc)
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a>=k:
    cnt += a
else:
    k -= a
    cnt += a
    if k!=0:
        k -= b
        if k!=0:
            cnt -= k

print(cnt)

Submission status: Wrong Answer

Solution code:
A,B, C,K = input().split()
Q = int(0)
Y = int(0)
for Y in range(int(K)):
    X = int(A) - Y
    Z = int(B) -X
    W = int(C) -Z
    if X >=0:
        Q += 1
        if Z>=0:
            Q+=0
            if W>=0:
                Q -= 1
print(Q)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
a, b, c, k = map(int, input().split())
if (a + b) > k:
    print(a)
else:
    print(a - (k - a - b))

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, k = map(int, input().split())
ans = 0
for _ in range(a):
    ans += 1
for _ in range(b):
    ans += 0
for _ in range(k-(a+b)):
    ans += -1
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    num_plus_one, num_zero, num_minus_one, total_num = map(int, input().split(' '))
    counter = 0

    if total_num <= num_plus_one + num_zero:
        counter = num_plus_one
    else:
        counter = num_plus_one - (total_num - num_plus_one - num_zero)

    print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
P = 0
while True:
    P += A
    K -= A
    if K < 0:
        P = K
        break
    elif K == 0:
        break
    K -= B
    if K <= 0:
        break

    P -= C
    K -= C
    if K <= 0:
        P += abs(K)
        break
print(P)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

r = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(result)

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum1 = 0
sum2 = 0
sum3 = 0

if k < a: sum1 = k
if k >= a and k < a+b: sum2 = a
if k >= a+b: sum3 = a-(k-a-b)

sum = max(sum1,sum2,sum3)

print(sum)

Submission status: Wrong Answer

Solution code:
a, b, c, k = map(int, input().split())
l = []
l.append(1*a)
l.append(0*b)
l.append(-1*c)

print(sum(l[0:k-1]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if (K < A):
    print(A)
    exit()
elif(K >= A):
    if (K < A + B):
        print(A)
        exit()
    elif (K >= A + B):
        print(A + (-1) * (K - A - B))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(sum)

Submission status: Wrong Answer

Solution code:

def resolve():
    A, B, C, K = map(int, input().split())
    
    ans = 0
    K -= min(K, A)
    ans += A * 1
    K -= min(K, B)
    ans += K * -1

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

ans = 0
if k > a:
    ans += a*1
    k = k - a
elif a >= k:
    k = 0
    ans = k*1

if k > 0 and k >= b:
    k = k - b
elif k > 0 and k < b:
    k = 0

if k > 0 and k > c:
    ans = ans - 1*c
    k = 0
elif k > 0 and c >= k:
    ans = ans - 1*k
    k = 0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
plus, zero, minus, number = map(int, input().split(" "))

if(plus + zero >= number):
  print(plus)
else:
  print(2 * plus + zero - number)

Submission status: Wrong Answer

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

ans = 0
for i in range(k):
    if a:
        ans += 1
        a -= 1

    if not a and b:
        b -= 1

    if not a and not b and c:
        ans -= 1
        c -= 1

print(ans)

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

wa = 0
wa += A
wa -= (K - A - B)

print(wa)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def function(a,b,c,k):
    count =0
    if a>=k:
        return a
    else:
        count +=a*1
        k =k-a
        a=0

        while(k>0):
            if b>0:
                b-=1

            else:
                c-=1
                count-=1

            k-=1
            
        return count
print(function(a,b,c,k))

Submission status: Wrong Answer

Solution code:
def solve(A, B, C, K):
    num = K

    if K <= A:
        return 1 * A

    num -= A
    ans = 1 * A

    if num <= B:
        return ans

    num -= B

    if num < 0:
        return ans

    return ans - num


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

k -= A
if k < 0:
    k = 0
    result += 1 * K
else:
    result += 1 * ( K - k )

    k -= B
    if k > 0:

        result -= 1 * ( k - C )

print(result)

Submission status: Wrong Answer

Solution code:
A,B,C,K= map(int, input().split())
a=0
c=0
if A<=K:
    a=A
if C>=K-A-B:
    c=(K-A-B)*-1
print(a+c)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
temp = input()
temp = temp.split()
A = int(temp[0])
B = int(temp[1])
C = int(temp[2])
K = int(temp[3])

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

Submission status: Wrong Answer

Solution code:
def main():
    A,B,C,K = map(int, input().split())
    score=0
    count=K
    i=0
    while count>0:
        if i==0:
            score=score+count
            count=count-A
            # print(score,"s",count)
        elif i ==1:
            count=count-B
            # print(score,"s",count)
        else:
            score=score-count
            count=count-C
            # print(score,"s",count)
        i=i+1
        
    print(score)
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a>=k or a+b>=k:
  print(a)
  exit()

d=k-a-b
print(a-d)

Submission status: Wrong Answer

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

ans = 0

if k <= a:
    ans = a

k = k-a

if k <= b:
    ans = a

k = k-b

if 0 <= k <= c:
    ans = a-k

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
num = 0
if K <= A:
  print(A)
else:
  tmp1 = K-A
  num = A
  if tmp1 <= B:
    print(A)
  else:
    tmp2 = tmp1-B
    print(A+tmp2*(-1))

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
a, b, c, k = map(int, input().split())
if (a + b) > k:
    print(a)
else:
    print((a) - min(k - a - b, c))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a>=k or a+b>=k:
  print(a)
  exit()

c=k-a-b
print(a-c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

Solution code:
def main():
    A, B, C, D = map(int, input().split())
    K = D
    D -= A
    if K <= 0:
        print(min(A, K))
        exit()

    D -= B
    if D <= 0:
        print(A)
    else:
        print(A - D)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

result = A
for k in range(K-A):
    if 0 < B:
        B -= 1
    else:
        result -= 1
        C -= 1
                
print(result)

Submission status: Wrong Answer

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

answer = A
K -= A
if K>0:
    K -= B
if K>0:
    answer -=K
print(answer)

Submission status: Wrong Answer

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

ans = 0



if a <= k:
    ans += a
    k -= a
else:
    ans += k

if b <= k:
    k -= b

ans -= k


print(ans)

Submission status: Wrong Answer

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

max = 0
if not K==0:
    for i in range(A):
        max+=1
        K-=1

if not K==0:
    for j in range(B):
        max+=0
        K-=1
    
if not K==0:
    for k in range(C):
        max-=1
        K-=1
    
print(max)

Submission status: Wrong Answer

Solution code:
A,B, C,K = input().split()
Q = int(0)
Y = int(0)
for Y in range(int(K)):
    X = int(A) - Y
    Z = int(B) -X
    W = int(C) -Z
    if X >0:
        Q += 1
        if Z>0:
            Q+=0
            if W>0:
                Q -= 1
print(Q)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a = [int(x) for x in input().split()]
count1=0
count0=0
count2=0
count1=a[0]
if a[3]-a[1]-a[0]>0:
    count2=-(a[3]-a[1]-a[0])
print(count1+count2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int, input().split())
""" a:1
    b:0
    c:-1
"""
sum_max=0
minus=0
if(a+b>=k):
    sum_max=a
else:
    minus=k-(a+b)
    sum_max=a-minus




print(sum_max)

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = (int(x) for x in input().split())
total = 0

if A >= K:
    total = A
elif B >= (K-A):
    total = A
elif C >= (K-A-B):
    total = A-(K-A-B)

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
second = K-A-B

if A >= K:
  count = K
else:
  count = A

if second:
    count -= second

print(count)

Submission status: Wrong Answer

Solution code:
a, b, c, k = [int(i) for i in input().split()]
ans = 0
while k != 0:
    if a >= k:
        ans += a
        k = 0
        a = 0
        continue
    elif 0 < a:
        ans += a
        k -= a
        a = 0
        continue

    if b >= k:
        ans += 0
        k = 0
        b = 0
        continue
    elif 0 < b:
        ans += 0
        k -= b
        b = 0
        continue

    if c >= k:
        ans += (-1 * k)
        k = 0
        c = 0
        continue
    elif 0 < c:
        ans += (-1 * c)
        k -= c
        c = 0
        continue

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
if A+B>=K:print(A)
else:
    c=K-(A+B)
    print(A-c)

Submission status: Wrong Answer

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