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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a > k:
    sum = k
    k = 0
else:
    sum = a
    k -= a

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

if c > k and k != 0:
    sum -= k
    k -= 0
elif b < k:
    sum -= c
print(sum)

Submission status: Wrong Answer

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

if a > k:
    sum = k
    k = 0
else:
    sum = a
    k -= a

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

if c > k and k != 0:
    sum -= k
    k -= 0
elif b < k:
    sum -= c
print(sum)

Submission status: Wrong Answer

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

if a > k:
    sum = k
    k = 0
else:
    sum = a
    k -= a

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

if c > k and k != 0:
    sum -= k
    k -= 0
elif b < k:
    k -= c
print(sum)

Submission status: Wrong Answer

Solution code:
A, B, C, K = (int(x) for x in input().split())
AB = A + B
if AB < K:
    print(A - (K-AB))
else:
    print(A)

Submission status: Wrong Answer

Solution code:
#ABC167
A,B,C,K=map(int,input().split())
#----------以上入力----------
if A+B >= K:
    print(A)
elif A > K:
    print(K)
else:
    print(A-(K-A-B))

Submission status: Wrong Answer

Solution code:
#ABC167
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:
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) * (-1))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    sum = 0

    n = k-a
    if n <= 0:
        sum = k
        print(sum)
        exit()
    else:
        sum = a
    n =- b
    if n <= 0:
        print(sum)
        exit()
    
    n =- c
    if n <= 0:
        sum =- (k-a-b)
        print(sum)
        exit()

main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

if k <= a + b :

    print(a)

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':

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

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

    print(ans)

Submission status: Wrong Answer

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

    if k <= b :
        print(k)
    else :
        n = min(k,b)
        k -= b
        l = k
        print(1*m+(-1)*l)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k = map(int,input().split())
m = min(k,a)
if m == k :
    n = 0
    l = 0
n = min(k-a,b)
if n == k-a :
    l = 0
l = min(k-a-b,c)
print(1*m+0*n+(-1)*l)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = K - A #Aのカードを引いた後のB,Cの数
b = K - A - B #Bのカードで水増しした後のCの数

if A == 0:
    print((-1)*b)
elif A > 0:
    if b >= 0:
        print(A - b)
    elif b < 0:
        print(A)

Submission status: Wrong Answer

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

b = K - A - B #Bのカードで水増しした後のCの数

if b >= 0:
    print(A - b)
elif b < 0 and A >= 0:
    print(A)
elif b < 0 and A < 0:
    print((-1)*b)

Submission status: Wrong Answer

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

b = K - A - B #Bのカードで水増しした後

if b >= 0:
    print(A + b*(-1))
if b < 0:
    print(A)

Submission status: Wrong Answer

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

b = K - A - B #Bのカードで水増しした後

print(A + b*(-1))

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+b-c)

Submission status: Wrong Answer

Solution code:
cards=input()
new=cards.split()
a=int(new[0])
b=int(new[1])
c=int(new[2])
k=int(new[3])
if a>k:
    print(k)
else:
    if a+b>k:
        print(a)
    else:
        sum=a+(k-a)*(-1)
        print(sum)

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+B-1*(K-A-B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k = list(map(int, input().split()))
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:
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:
a,b,c,k = map(int , input().split())
maxans = 0
flag = 1
if(k <= a):
    print(a)
    flag = 0
if(k >= a):
    maxans += a
    k -= a
if (k != 0):
    if(k >= b):
        k -= b
    else:
        k = 0
if (k != 0):
    maxans -= (k)
if(flag):
    print(maxans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(A - temp)

Submission status: Wrong Answer

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

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

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

print(A - C)

Submission status: Wrong Answer

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

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

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

print(A - C)

Submission status: Wrong Answer

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

if A > K:
  print(K)
  
temp = K - A

if temp >= B:
  print(A)
  
temp = temp - B

print(A - C)

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split());print((2*a+b-k,a)[a+b>k])

Submission status: Wrong Answer

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

Ak = A if A < K else K
Ck = C if C < K - A - B else K - A - B

print(Ak - Ck)

Submission status: Wrong Answer

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

Ak = A if A <= K else K
Ck = C if C <= K - A - B else K - A - B

print(Ak - Ck)

Submission status: Wrong Answer

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

KK = K - A
if KK <= 0:
    MAX = A
else:
    KK = KK - B
    if KK <= 0:
        MAX = A
    else:
        if KK <= C:
            MAX = A - KK
        else:
            MAX = A - C
print(MAX)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


if k - a <= 0:
    print(k)
elif k - a > 0 and k - a - b <= 0:
    print(a)
else:
    s = k - a
    print(s - c)

Submission status: Wrong Answer

Solution code:
l = input().split()
n1 = int(l[0])
n0 = int(l[1])
n = int(l[2])
k = int(l[3])

ans = 0

if k >= n1:
    ans += n1

else:
    ans += (n1 - k)

k -= n1

k -= n0

if k > 0:
    ans -= k

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main(A, B, C, K):
    """
    a = [1 for _ in range(A)]
    b = [0 for _ in range(B)]
    c = [-1 for _ in range(C)]
    k = a + b + c
    ans = sum(k[:K])
    """
    if A+B >= K:
        return K
    else:
        return A - (K-A-B)

if __name__ == '__main__':
    A, B, C, K = map(int, input().split())
    ans = main(A, B, C, K)
    print(ans)

Submission status: Wrong Answer

Solution code:
def main(A, B, C, K):
    """
    a = [1 for _ in range(A)]
    b = [0 for _ in range(B)]
    c = [-1 for _ in range(C)]
    k = a + b + c
    ans = sum(k[:K])
    """
    if A+B >= K:
        return A
    else:
        return A - (K-A-B)

if __name__ == '__main__':
    A, B, C, K = map(int, input().split())
    ans = main(A, B, C, K)
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for numberOfCards, point in [(A, 1), (B, 0), (C, -1)]:
  if K >= numberOfCards:
    K -= numberOfCards
    ret += numberOfCards * point
  else:
    ret += numberOfCards * point
    break
    
print(ret)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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:
a,b,c,k = map(int,input().split())

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

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

Submission status: Wrong Answer

Solution code:
A,B,C,K=map(int,input().split())
x =K-A
y =x-B
z =y-C
if x<=0:
    print(K)
else:
    if y<=0:
        print(A)
    else:
        print(A-z)

Submission status: Wrong Answer

Solution code:
A, B, C, K = input().split()
IA = int(A)
IB = int(B)
IC = int(C)
IK = int(K)
ALL = IA + IB + IC
cn = 0

if IA <= IK:
    cn = cn + IA
    D = IK - IA
    if IB <= D:
        E = D - IB
        cn = cn - E
        print(cn)
    else:
        print(cn)
else:
    print(IA)

Submission status: Wrong Answer

Solution code:
A, B, C, K = input().split()
IA = int(A)
IB = int(B)
IC = int(C)
IK = int(K)
ALL = IA + IB + IC
cn = 0

if IA < IK:
    cn = cn + IA
    D = IK - IA
    if IB < D:
        E = D - IB
        cn = cn - E
        print(cn)
    else:
        print(cn)
else:
    print(IA)

Submission status: Wrong Answer

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

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(m)

Submission status: Wrong Answer

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

koa = A
kob = 0

if K-A<B:
  kob = K-A
else :
  kob = B
  
sum = A+0*B
for i in reversed(range(K-koa+kob)):
  if koa+kob+i != K:
    continue
  if i<K-koa-kob:
    break
  #print (koa)
  #print (kob)
  #print (i)
  #print ("------")
  sum = sum+i*(-1)
print (sum)

Submission status: Wrong Answer

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

sum = A
for i in reversed(range(K-A)):
  for j in reversed(range(K-A+i)):
    if A+i+j != K:
      continue
    #print (A)
    #print (i)
    #print (j)
    #print ("------")
    sum = A+i*(0)+j*(-1)
print (sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
num = k

if num < a:
  ans += num
  exit()
else:
  ans += a
  num -= a

if num < b:
  ans += 0
  exit()
else:
  ans += 0
  num -= b

if num < c:
  ans -= num
else:
  ans -= c
  
print(ans)

Submission status: Wrong Answer

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

ans = 0
num = k

if num < a:
  ans += num
  exit()
else:
  ans += a
  num -= a

if num < b:
  ans += 0
else:
  ans += 0
  num -= b

if num < c:
  ans -= num
else:
  ans -=c
  
print(ans)

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 :
    print(a - (k - a - c))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A,B,C,K=map(int,input().split())
if A>=K:
    print(A)
else:
    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())
for i in range(C):
    for j in range(B):
        for k in range(A):
            if i+j+k==K:
                print(-1*i+k)
                exit()

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

Submission status: Wrong Answer

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

ans = 0

ans += max(a, k)      
k -= max(a, k)        

ans += max(b, k) * 0
k -= max(b, k)

ans += max(c, k) * -1
k -= max(c, k)

print(ans)

Submission status: Wrong Answer

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

print(Ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
r=input().split()
A=int(r[0])
B=int(r[1])
C=int(r[2])
K=int(r[3])
if K<=A:
    print(K)
elif K<=A+B:
    print(A)
else:
    print(2*A-K-B)

Submission status: Wrong Answer

Solution code:
r=input().split()
A=int(r[0])
B=int(r[1])
C=int(r[2])
K=int(r[3])
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())

point = 0 

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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())
k = K
a = min(A, K)
k -= a
b = min(B, K)
k -= b
c = min(C, k)
print(a-c)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(eval, input().split())
count = 0

if K >= A:
    K -= A
    count += A
else:
    count = A
    K = 0

if K >= B:
    K -= B
else:
    K = 0

if K >= C:
    K -= C
    count -= C
else:
    count -= K
    K = 0

print(count)

Submission status: Wrong Answer

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

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

# b
if b <= k:
    k -= b

# c
if c > k:
    ans -= k
else:
    ans -= c
    
print(ans)

Submission status: Wrong Answer

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

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:
a, b, c, k = map(int, input().split())

# ans = [1] * a + [0] * b + [-1] * c
# print(sum(ans[:k]))

if a >= k or 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())
print(1*min(A,K)-(1*(K-A-B)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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:
a, b, c, k = map(int, input().split())


if k <= a:
    print(k)


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


else:
    print(a - c)

Submission status: Wrong Answer

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

if A<=K:
  ans+=A*1
else:
  ans+=K*1

K=max(K-A+B,0)
  
ans+=K*(-1)

print(ans)

Submission status: Wrong Answer

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

if A<=K:
  ans+=A*1
else:
  ans+=K*1

K-=max(A+B,0)
  
ans+=K*(-1)

print(ans)

Submission status: Wrong Answer

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

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

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

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:
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 k <= a: 
  print(k)
if a < k <= b:
  print(a)
if b < k <= c:
  print(a+(-1)*(k-a-b))

Submission status: Wrong Answer

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

s = 0

mn = min(A, K)
s += mn 
K -= mn
print(K)

mn = min(B, K)
K -= mn
print(K)

mn = min(C, K)
s -=mn
K -= mn
print(K)

print(s)

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

Submission status: Wrong Answer

Solution code:
def main():
    s = list(map(int,input().strip().split()))
    k = s[3]
    r = 0
    if s[0] <= k:
        r += 1 * s[0]
        k -= s[0]
    else:
        r += 1 * k
        print(r)
        return
    
    if s[2] <= (k-s[1]):
        r += (-1)*s[2]
    else:
        r += (-1) * (k-s[1])
    
    print(r)
    return
    
    
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    print(ans)


if __name__ == '__main__':
    Qb()

Submission status: Wrong Answer

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

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


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

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


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

a,b,c,k=LI()

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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