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:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c,k = map(int,input().split())
    ans = 0
    if a >= k:
        ans = k
        print(ans)
    else: #a<k
        for y in range(b+1):
            z = k-y-a
            if ans < a-z:
                ans = a-z
        print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

sum = 0
a_3 = a[3]
a_0 = a[0]
a_1 = a[1]
a_2 = a[2]


if a_3 <= a_0:
    print (a_3)
    
elif a_3 > a_0 and a_3 <= (a_0 + a_1):
    print (a_0)
    
else:
    sum = a_0 - (a_2 - a_1)
    print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if a + b >= k:
    print(a)
else:
    sumcheck = a + b - k
    if a - abs(sumcheck) < 0:
        print("0")
    else:
        print(a - abs(sumcheck))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = input().split()

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

if(a > k): # a > k
  print(a-k)
  exit()
elif(k-a == 0):
  print(a)
  exit()
elif(k-a < b): # k > a 
  print(a)
  exit()
elif(k-a == b):
  print(a)
  exit()
elif(k-a-b < c):
  x = (k - a - b)
  print(a-x)
  exit()
elif(k-a-b == c):
  print(a-c)

Submission status: Wrong Answer

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

if i[3] <= i[0]:
  print(i[3])
elif a <= int(i[1]):
  print(a)
elif b == int(i[2]):
  print(int(i[0]) - int(i[2]))
else:
  print(int(i[0])*2 + int(i[1]) - int(i[3]))

Submission status: Wrong Answer

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

#Aの範囲は0<=i<=A
#Bの範囲は0<=j<=B
#Cの範囲は0<=k<=C
#条件より(i+j+k) == K でなければならない
max_k = 0

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+k+j == K:
                sum_k = i * 1 + j * 0 + k * -1
                if max_k < sum_k:
                    max_k = sum_k
                    
                exit
                
                
print(max_k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, K = input().split()
# A=1 B=0 C=-1 K
ans = 0

for a in range(int(K)):
    if int(A) == int(K):
        ans = A

    elif int(A) <= int(K):
        ans = A

    elif int(B) <= int(K):
        ans = A

    elif int(C) <= int(K):
        ans = (-1 * C)
        break
if int(A) == int(K):
    print(K)
else:
    print(int(A) + int(B) - int(C))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum = 0

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

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 + B) >= K:
    count = 1 * A
else:
    count = 1 * A + 0 * B + (-1) * (K - C)


print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = abck[0]
b = abck[1]
c = abck[2]
k = abck[3]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

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

Submission status: Wrong Answer

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

x2 = A+B

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

res = 0
if k < a:
     res = a
elif k < a+b:
     res = a
else:
     res = a-c

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if i[0] <= i[3]:
	saidai=1*i[0]
elif i [0] > i[3]:
	saidai=1*i[3]
elif i[2] >= (i[3]-i[0]-i[1]):
	saidai=saidai-1*(i[3]-i[0]-i[1])

print (saidai)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
result = 0
if K > 0 :
    result = result + A
    K = K - A
if K > 0 :
    K = K -B
    for i in range (K):
        result = result - 1
print(result)

Submission status: Wrong Answer

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

ans = 0

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())
ans=0

if K<A:
    ans=K*1
    print(ans)
else:
    ans=A*1
    K=K-A

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = k - a
m = l - b
n = m - c

ans = 0

if l >= 0:
    ans += a
    if l == 0:
        print(ans)
    else:
        if m > 0:
            if n > 0:
                ans -= n
                print(ans)
            else:
                ans -= m
                print(ans)
        else:
            print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=input().split()
A=int(n[0])
B=int(n[1])
C=int(n[2])
D=int(n[3])
a = np.array([1,0,-1])
b = np.array([A,D-A,D-A-B])
c = np.array([0,B,D-B])

if A>=1 and D-A-B>=0:
      print(sum(a*b))

elif  A>=1 and D-A-B<0:
      print(sum(a*b)-(-1*(D-A-B)))

elif A==0 and B==0:
      print("-1")  

elif A==0 and B>=1:
      print(sum(a*c))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
while True:
    try:
        listA=list(map(int,input().split()))
        #listA<-[1,2,2,3,1]
        a=listA(1)*list(4)
        print(a)
    except:
        break;

Submission status: Wrong Answer

Solution code:
x = input().split()

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

if(a > k): # a > k
  print(a-k)
  exit()
elif(k-a == 0):
  print(a)
  exit()
elif(k-a < b): # k > a 
  print(a)
  exit()
elif(k-a == b):
  print(a)
  exit()
elif(k-a-b <= c):
  x = (k - a - b)
  print(a-x)
  exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = k - a
m = l - b
n = m - c

ans = 0

if l >= 0:
    ans += a
    if l == 0:
        print(ans)
    else:
        if m >= 0:
            if n >= 0:
                ans -= n
                print(ans)
            else:
                ans -= m
                print(ans)
        else:
            print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
res = 0
if A>=K:
  res= 1*A
else:
  for c in range(K-A,C+1):
    b = K - A - c
    ans = 1*A + 0*b + (-1)*c
    res = max(res,ans)
print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

sumcheck = a + b - k
print(a - abs(sumcheck))

Submission status: Wrong Answer

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

a_times = 0
b_times = 0
c_times = 0

if a <= k:
    a_times = a
    # print('a_times = ', a_times)
    if a_times + b <= k:
        b_times = b
        # print('if - b_times = ', b_times)
    else:
        b_times = k - a_times - b
        # print('else - b_times = ', b_times)
    if a_times + b_times + c <= k:
        c_times = c
        # print('if - c_times = ', c_times)
    else:
        c_times = k - a_times - b_times
        # print('else - c_times = ', c_times)
else:
    a_times = k


print(a_times * 1 + b_times * 0 + c_times * -1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split())
s=0
for i in range(k-1):
    if a!=0:
        s+=1
        a-=1
        continue
    elif b != 0:
        b-=1
        continue
    elif c!=0:
        s-=1
        c-=1
        continue

print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

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,h=(int(x) for x in input().split())
num = 0
count=h
num += a
count -= a
if count > 0:
  count -= b
if count >0:
  num -= count
print(num)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if K >= A:
	sum = sum + A
else:
	sum = sum + K
K = K - A

K = K - B

if K >= 1:
	sum = sum - K
K = K - C

if sum >= 1:
	print(sum)
else:
	print(0)

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(float,input().split())
 
a = min(A, K)
b = min(abs(K-A), B)
c = min(abs(K-A-B), C)


ans = 1*a - 1*c

print(int(ans))

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

if( A[0] + A[1] >= A[3] ):
  print(A[0])
else:
  p = A[0]
  m = A[3] - (A[0]+A[1])
  print(p-m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,h=(int(x) for x in input().split())
num = 0
count=h
num += a
count -= a
if count > 0:
  count -= b
if count >0:
  num -= count
print(count)

Submission status: Wrong Answer

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

if K < A:
    print("1: ", K)
elif A <= K <= (A+B):
    print(A)
elif (A+B) < K:
    print(A - (K - A - B))

Submission status: Wrong Answer

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

if K >= A:
    for i in range(A):
        sum += 1
elif K < A & K > 0:
    for i in range(K):
        sum += 1
        

if (K-A) >= B & (K-A) >=0:
    for i in range(B):
        sum += 0
elif (K-A) < B & (K-A) >0:
    for i in range(K-A):
        sum += 0
        

if (K-(A+B)) >= C & (K-(A+B)) >= 0:
    for i in range(C):
        sum += -1
elif (K-(A+B)) < C & (K-(A+B)) > 0:
    for i in range(K-(A+B)):
        sum += -1
        

print(sum)

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split())
s=0
for i in range(k-1):
    if a!=0:
        s+=1
        a-=1
    elif b != 0:
        b-=1
    elif c!=0:
        s-=1
        c-=1

print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a, b, c, k = map(int, input().split())

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

Submission status: Wrong Answer

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

if tmp <= 0:
    print(answer)
else:
    print(answer - tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A,B,C,K = list(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(k)
elif a < k and k - a <= b:
  print(a)
elif a == 0 and b ==0:
  print(-k)
elif k == 0:
  print(0)
else:
  print(k-c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

Solution code:
a,b,c,k=map(int,input().split())
s=0
for i in range(k):
    if a!=0:
        s+=1
        a-=1
    elif b != 0:
        b-=1
    elif c!=0:
        s-=1
        c-=1

print(c)

Submission status: Wrong Answer

Solution code:
n=input().split()
if (int(n[3])<=int(n[0])+int(n[1])):
  print(int(n[0]))
else:
  print((int(n[0]))-(int(n[3])-int(n[0])-int(n[1])))

Submission status: Wrong Answer

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

s=-1*K*C

lc=[]
lc_=[]
for i in range(K+1):
  for j in range(K-i+1):
    lc.append([i,j,K-i-j])

#print(lc)

for i in range(len(lc)):
  if lc[i][0]<=A and lc[i][1]<=B and lc[i][2]<=C:
    print(lc[i])
    s=max(s, lc[i][0]-lc[i][2])

print(s)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a_times = 0
b_times = 0
c_times = 0

if a <= k:
    a_times = a
    # print('a_times = ', a_times)
else:
    a_times = k
    print(a_times * 1 + b_times * 0 + c_times * -1)
    exit(0)
if a_times + b <= k:
    b_times = b
    # print('if - b_times = ', b_times)
else:
    b_times = k - a_times - b
    # print('else - b_times = ', b_times)
if a_times + b_times + c <= k:
    c_times = c
    # print('if - c_times = ', c_times)
else:
    c_times = k - a_times - b_times
    # print('else - c_times = ', c_times)

print(a_times * 1 + b_times * 0 + c_times * -1)

Submission status: Wrong Answer

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

if i[3] <= i[0]:
  print(i[0])
elif a <= int(i[1]):
  print(i[0])
elif b == int(i[2]):
  print(int(i[0]) - int(i[2]))
else:
  print(int(i[0])*2 + int(i[1]) - int(i[3]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3


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

    ans = a
    num = a + b

    if k >= a:
        print(k)
    elif num < k:
        ans -= k - num
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,k = map(int, input().split())
counter = 0
aremants = a
bremants = b
cremants = c
for i in range(k+1):
  if aremants > 0:
    aremants-=1
    counter +=1
  elif aremants == 0 and bremants > 0:
    bremants-=1
  elif aremants == 0 and bremants ==0 and cremants > 0:
    cremants-=1
    counter -=1

print(counter)

Submission status: Wrong Answer

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

if k >= a:
    s = a
if (k - a - b) >= 0:
    s -= k - a - b

print(s)

Submission status: Wrong Answer

Solution code:
import os

def main():
	a,b,c,k = map(int, input().split())
	ans = 0
	ans += a
	k -= a
	k -= b
	ans += (c - k - 1) * (-1)
	

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

if k <= a:
    print(a)
elif k <= a+b:
    print(a)
elif 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())
res = 0
if A>=K:
  res= 1*A
else:
  for c in range(K-A,C+1):
    b = K-A-c
    ans = 1*A + 0*b + (-1)*c
    res = max(res,ans)
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
A,B,C,K=list(map(int,(stdin.readline().strip().split())))
ans=A
K=K-(A+B)
if K<=0:print(ans)
else:
    ans=ans+(-1*(K))
    print(ans)

Submission status: Wrong Answer

Solution code:
we = str(input())
r = we.split(" ", -1)

A = r[0]
B = r[1]
C = r[2]
K = r[3]
A = int(A)
B = int(B)
C = int(C)
K = int(K)

def max_sum(A, B, C, K):
	if (A and B and C and K) >= 0:   
		if A >= K:
			print(A)
		elif A < K:
			R = K - A
			if B >= R:
				print(A)
			elif B < R:
				S = R - B
				print(A + S*(-1))
max_sum(A, B, C, K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

kk=k-a
for i in range(1):
    if kk<0:
        ans=a
        k=-1
        break
    else:
        ans = a
        k=k-a
    kk = k-b
    if kk<0:
        k=-1
        break
    else:
        k=k-b

    kk = k-c

    if kk<0:
        ans=ans-k
    elif kk>=0:
        ans=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<k:
  if k-a<=b:
    print(a)
  elif k-a >b:
    print(a-(k-a-b))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if K >= A:
	sum = sum + A
	K = K - A
else:
	sum = sum + K
	K = 0
if K >= B and K >= 1:
	K = K - B
else:
	K = 0
if K >= 1:
	sum = sum - K
	K = K - C

if sum >= 1:
	print(sum)
else:
	print(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
saidai=0
list=[0]
bb=0
a,b,c,k = map(int,input().split())
z=k-a
if z>0:
    z=z-b
print(a+b*0+z*-1)

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
res = 0
if A>=K:
  res= 1*A
else:
  for b in range(B+1):
    c = K-A-b
    ans = 1*A + 0*b + (-1)*c
    res = max(res,ans)
print(res)

Submission status: Wrong Answer

Solution code:
A, B, C, K = map(int, input().split())
if A + B > K:
    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())
ans=[]
for i in range(0,a-1):
   ans.append(1)
for j in range(0,b-1):
   ans.append(0)
for k in range(0,c-1):
   ans.append(-1)
print(sum(ans[0:k-1]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
#read=sys.stdin.buffer.read
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if i[0] <= i[3]:
	saidai=1*i[0]
else:
	saidai=1*i[3]

if i[2] >= (i[3]-i[0]-i[1]):
	saidai=saidai-1*(i[3]-i[0]-i[1])

print (saidai)

Submission status: Wrong Answer

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

if k >= a:
    s = a
if (k - a - b) >= 0:
    s -= k - a - b

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if K-A-B-C<=0:
  ans = A-(K-A-B)
elif K-A-B<=0:
  ans = A
elif K-A <0:
  ans = K

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
######ANSDEFINE##########
#unnecessary			#
#########################

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

if A <= K: #AがKより小さい
  if A + B >= K: #A+BがKより大きい
    print(A * 1)
  elif A + B <= K: #A+BがKより小さい
    if B >= 1: #Bが1枚以上
      if A+B >= C:#A+BがCより小さい
        print(A - C)
      else:#それ以外
        print(A - C)
    else: #それ以外
      print(A - C)
     
	
elif A >= K: #AがKより大きい
  print(K * 1)

Submission status: Wrong Answer

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


def f(A, B, C, K) :
    
    sum = 0

    K = K - A
    if K >= 0 :
        sum = sum + (1 * A)
    elif K < 0 :
        sum = sum + (1 * K)

    if K <= 0 :
       return sum

    K = K - B
    if K >= 0 :
        sum = sum + (0 * B)
    elif K < 0 :
        sum = sum + (0 * K)

    if K <= 0 :
       return sum

    K = K - C
    if K >= 0 :
        sum = sum - (-1 * C)
    elif K < 0 :
        sum = sum - (-1 * K)

    if K <= 0 :
       return sum


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

Submission status: Wrong Answer

Solution code:
A,B,C,K = map(int,input().split())
res = 0
if A>=K:
  res= 1*A
else:
  for b in range(K-A,B+1):
    c = K-A-b
    ans = 1*A + 0*b + (-1)*c
    res = max(res,ans)
print(res)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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