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: Runtime Error

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

Submission status: Runtime Error

Solution code:
A, B, C, K=(int(x) for x in input().split())
 
a=int(A)
b=int(B)
c=int(C)
k=int(K)
 
if k<=a or k<=(a+b):
  print(a)
else:
  print(a*1+b*0+(k-a-b)*(-1)

Submission status: Runtime Error

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

a=int(A)
b=int(B)
c=int(C)
k=int(K)

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

Submission status: Runtime Error

Solution code:
a,b,c,k = input().split(None, 4)
A = int(a)
B = int(b)
C = int(c)
K = int(k)
X = K - A - B
if K <= A:
    print(K)
elif A < K <= A + B:
    print(A)
else A + B < K:
    print(A - X)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

ones = [1] * a
zeros = [0] * b
minus_ones = [-1] * c

ans = sorted(ones + zeros + minus_ones)[-k:]
print(sum(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A, B, C, K = inpl()
if A >= K:
    print(K)
    exit()
if A+B >= K:
    print(A)
    exit()
print(A-(K-A-B))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin
A, B, C, K = [int(_) for _ in stdin.readline().rstrip().split()]
L = [1]*A+[0]*B+[-1]*C
print(sum(L[:K]))

Submission status: Runtime Error

Solution code:
from sys import stdin
A, B, C, K = [int(_) for _ in stdin.readline().rstrip().split()]
L = [1]*A+[0]*B+[-1]*C
print(L[:K])

Submission status: Runtime Error

Solution code:
a,b,c,k = int(input())
total = a*1 + b*0 - c*1
print(int(total))

Submission status: Runtime Error

Solution code:

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

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

Submission status: Runtime Error

Solution code:
a,c,b,k=man(int,split())
print(min(k,a,2a+b-k))

Submission status: Runtime Error

Solution code:
a=input()
b=input()
c=input()
k=input()

cou=0

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
ls = list(map(int, input().split()))
nokori = ls[-1]
sum_max = 0
for i, j in zip(ls[:-1], [1, 0, -1]):
    nokori -= i
    if nokori > 0:
        sum_max += i*j
    elif nokori == 0:
        sum_max += i*j
        break
    else:
        sum_max += nokori_*j
        break
    nokori_ = nokori
print(sum_max)

Submission status: Runtime Error

Solution code:
ls = list(map(int, input().split()))
nokori = ls[-1]
sum_max = 0
for i, j in zip(ls[:-1], [1, 0, -1]):
    nokori -= i
    if nokori >= 0:
        sum_max += i*j
    else:
        sum_max += nokori_*j
        break
    nokori_ = nokori
print(sum_max)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A=input()
B=input()
C=input()
K=input()

A=int(A)
B=int(B)
C=int(C)
K=int(K)

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

Submission status: Runtime Error

Solution code:
l = list(map(int, input().split()))
lists = [1]*l[0] + [0]*l[1] + [-1]*l[2]
sum = 0
for i in range(l[3]):
    sum += lists[i]
print(sum)

Submission status: Runtime Error

Solution code:
l = map(int, input().split())
lists = [1]*l[0] + [0]*l[1] + [-1]*l[2]
sum = 0
for i in range(l[3]):
    sum += lists[i]
print(sum)

Submission status: Runtime Error

Solution code:
a = input()
b = input()
c = input()
k = input()

if(a >= k):
    print(k)
elif(a < k and (a+b) >= k):
    print(a)
else:
    d = int(k)-int(a)-int(b)
    print(int(a)*1+int(b)*0-int(d)*1)

Submission status: Runtime Error

Solution code:
def NextIntList(): return list(map(int,input().split()))


A,B,C,K = NextIntList()
point = 0
while K>0:
	while A>0 and K>0:
		point+=1
		A,K-=1
	while B>0 and K>0:
		point+=0
		B,K-=1
	while C>0 and K>0:
		point-=1
		C,K-=1
print(point)

Submission status: Runtime Error

Solution code:
a,b,c,k = list(map(int,input().split()))
A = [1]*a
B = [0]*b
C = [-1]*c
new =A+B+C
print(sum(new[:k]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a = i[0]
b = i[1]
c = i[2]
d = i[3]

if int(d) <= int(a):
  print(int(d))
  elif int(d) - int(a) <= int(b):
    print(int(a))
else:
  print(int(a) - (int(d) - int(a) -int(b)))

Submission status: Runtime Error

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

print(sum(cards[:K]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:

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

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

Submission status: Runtime Error

Solution code:
A, B, C, K = map(int, input().spliit())
if K <= A :
    print(K)

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

else:
    print(A - (K - (A + B)))

Submission status: Runtime Error

Solution code:
A, B, C, K = map(int, input().spliit())
if K <= A :
    return K

elif K <= A + B:
    return A

else:
    return A - (K - (A + B))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
ls = list(map(int, input().split()))
check = 0
for i, j in zip(ls[:-1], [1, 0 -1]):
    check+=i
    nokori = ls[-1] - check
    if check =< ls[-1]:
        sum_max += i*j
    else:
        sum_max += nokori*j
        break

print(sum_max)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 0
for i in range(K):
    if A > 0:
        ans += 1
        A -= 1
    elif B > 0:
        B -= 1
    elif C > 0:
        ans -= 1
        C -= 1
        
        
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A = input()
B = input()
C = input()
K = input()
if A+B+C <= K:
    print(A-C)

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

elif A <= K:
    print(K)

Submission status: Runtime Error

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

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

elif A <= K:
    print(K)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#python 3.7.1

a=int(input())

b=int(input())

c=int(input())

d=int(input())

cnt=0

while(d!=0):

  

  if(a!=0 and d>0):

    d-=1

    a=a-1

    

    cnt=cnt+1

    

  elif b!=0 and d>0:

    d-=1

    b=b-1

    

    

  elif c!=0 and d>0:

    d-=1

    c=c-1

    

    cnt=cnt-1

    

print(cnt)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())
c = int(input())
k = int(input())
sum = 0

xa = min(a,k)
k = k - a
xb = min(b,k)
k = k - b
xc = k

sum = xa - xc

print(sum)

Submission status: Runtime Error

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

r = min(c, k)
k -= r
s -= k
print(s)

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())
c = int(input())
k = int(input())
sum = 0

while True:
  if a == 0 or k == 0:
    break
  sum += 1
  a -= 1
  k -= 1

while True:
  if b == 0 or k == 0:
    break
  k -= 1
  b -= 1

while True:
  if c == 0 or k == 0:
    break
  sum -= 1
  k -= 1
  c -= 1

print(sum)

Submission status: Runtime Error

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(a == k):
  print(a)
  exit()
elif(k-a < b):  # k > a 
  print(a)
  exit()
elif(k-a == b):
  print(a)
  exit()
elif(k-a-b != 0)
  x = k - a - b
  print(a-x)
  exit()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

B_number = 0
C_number = 0

A_number = min(a,k)
k1 = k - a
if k1 > 0:
    B_number = min(b,k1)
    k2 = k1 - b
    if k2 > 0:
        C_number = min(c,k2)

print(A_number-C_number)

Submission status: Runtime Error

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

B_number = 0
C_number = 0

A_number = min(a,k)
k1 = k - a
if k1 > 0:
    B_number = min(b,k1)
    k2 = k1 - b
    if k2 > 0:
    C_number = min(c,k2)

print(A_number-C_number)

Submission status: Runtime Error

Solution code:
t=int(input().split())
l=[1,0,-1]
k=t[3]
s=0
i=0
while(k!=0):
  if(k>t[i]):
    s+=l[i]*t[i]
    k-=t[i]
  else:
    s+=l[i]*k
    k=0
  i+=1
print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for s in range(k):
  if a > 0:
    n += 1
  elif b > 0:
    n += 0
  else:
    n -= 1
    
print(n)

Submission status: Runtime Error

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

for _ in range(k):
  if a > 0:
    n += 1
  elif b > 0:
    n += 0
  elif c > 0:
    n -= 1
    
print(n)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

    ans = 0
    used = min(k,a)
    ans += used * 1
    k -= used
    used = min(k, b)
    k -= used
    ans += k*(-1)
    print(ans)

if __name__ == "__main__":
    unittest.main()

Submission status: Runtime Error

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

a = max(K, K - A)
s += a * 1
if a < K:
  b = max(K - A, K - A - B)
  s += b * 0
if a + b < K:
  c = max(K - A - B, K - A - C)
  s += c * -1
print(s)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#coding :utf-8

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

ans=sum(([1]*A+[0]*B+[-1]*C)[:K])

print(ans)

Submission status: Runtime Error

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

max_value = 0
m = 0
while(A>0):
    if m < K:
        max_value+=1
        m += 1
        A = A - 1
        
while(B>0):
    if m < K:
        m += 1
        B = B - 1
while(C>0):
    if m < k:
        max_value -= 1
        m += 1
        C = C - 1

Submission status: Runtime Error

Solution code:
a = input().split

sum = 0

sum += 1 * a[0]
a[3] -= a[0]
a[3] -= a[1]

if a[2] < a[3]:
    sum -= 1 * a[0]

print(sum)

Submission status: Runtime Error

Solution code:
a=input()
b=a.split()

num=[]

x1=[1]*int(b[0])
x2=[0]*int(b[1])
x3=[-1]*int(b[2])

num[len(num):len(num)]=x1
num[len(num):len(num)]=x2
num[len(num):len(num)]=x3

k=int(b[3])
print(sum(num[0:k]))

Submission status: Runtime Error

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

if(k<=a):
  print(a*len(k))
else:
  sum=a*len(k)
  t=k-a
  if(t<=b):
    print(sum+b*len(t))
  else:
    sum+=b*len(t)
    t2=t-c
    print(sum+c*len(t2))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())
if A + B + C >= 2 * 10 ** 9:
    print('Error')
elif A >= K:
    print(K)
elif K > A and K < A + B:
    print(A)
elif K > A + B and K <= A + B + C:
    print(-1 * (K - A - B) + A)
else:
    print('Error')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c, k = list(map(int, readline().split()))
    s = [1] * a + [0] * b + [-1] * c
    ans = sum(s[:k])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c, k = list(map(int, readline().split()))
    s = [1] * a + [0] * b + [-1] * c
    print(s)
    ans = sum(s[:k])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c, k = list(map(int, readline().split()))
    s = [1] * a + [0] * b + [-1] * c
    ans = sum(s[::k])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())
c = int(input())
k = int(input())
if(k<=a+b):
  print(a)
else:
  print(b + 2*a - k)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools
A, B, C, D = map(int, input().split())
l = A*[1] + B*[0] + C*[-1]
max_val = -1*C
print(sum(l[:K]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
A=int(input())
B=int(input())
C=int(input())
K=int(input())
maxi=2*A-K+B
print(maxi)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

s = [1]*A+[0]*B+[-1]*C
print(sum(s[:K]))

Submission status: Runtime Error

Solution code:
abcx = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
x = int(abcd[3])
if x <= a:
    print(x)
elif x <= a + b:
    print(a)
else:
    print(2*a + b - x)

Submission status: Runtime Error

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

lista = [1]*a
listb = [0]*b
listc = [-1]*c
list = lista + listb + listc
anslist = list[0:k]
ans = sum(anslist)

print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
now = 1
cnt = 0
loop = 0
cnts = [-1] * n
cnts[now - 1] = cnt
visited = [False] * n
visited[now - 1] = True
li = [now]

while True:
    cnt += 1
    now = a[now - 1]
    li.append(now)

    if cnt == k:
        print(now)
        exit()
    if visited[now - 1]:
        loop = (cnt - cnts[now - 1])
        pre = cnts[now - 1]
        print(li[pre + (k - pre) % loop])
        exit()

    cnts[now - 1] = cnt
    visited[now - 1] = True

Submission status: Runtime Error

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

seq = list([1]*A+[0]*B+[-1]*C)
s = list(itertools.combinations(seq, K))
o =[]
for i in s:
    n = list(i)
    m=sum(n)
    o.append(m)
print(max(o))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

s=-1*K*C

lc=[]
lc_=[]
for i in range(min(K,A+1):
  for j in range(min(K-i+1,B+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: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
a,b,c,k = (int(x) for x in input().split())
sum = 0

if k >= a:
  sum = sum + a
  if k >= b:
    k = k - b
    if k >= 0
    sum =sum-c
    
print(sum)

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())

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

Submission status: Runtime Error

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

seq = list([1]*A+[0]*B+[-1]*C)
s = list(itertools.combinations(seq, K))
o =[]
for i in s:
    n = list(i)
    m=sum(n)
    #print(m)
    o.append(m)

    #o.append(m)
print(max(o))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())

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

Submission status: Runtime Error

Solution code:
2000000000 0 0 2000000000

Submission status: Runtime Error

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

seq = list([1]*A+[0]*B+[-1]*C)
#print(seq)
s = list(itertools.combinations(seq, K))
o =[]
for i in s:
    n = list(i)
    m=sum(n)
    #print(m)
    o.append(m)

    #o.append(m)
print(max(o)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
mport 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 and D-A-B>-0:
      print(sum(a*c))
elif  A==0 and B>=1 and D-A-B<-0:
      print(sum(a*c)-(-1*(D-A-B)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = input('')
b = input('')
c = input('')
k = input('')
A = int(a)
B = int(b)
C = int(c)
K = int(k)

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

Submission status: Runtime Error

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

Solution code:
a = input('')
b = input('')
c = input('')
k = input('')
A = int(a)
B = int(b)
C = int(c)
K = int(k)
data = [A, B, C]

for i in data:
    if i >= 0:
        if 1 <= K <= A:
            print(K)
        elif A < K <= A + B:
            print(A)
        elif A + B < K <= A + B + C:
            print(A - (K - A - B))

Submission status: Runtime Error

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

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

print (saidai)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(c)

Submission status: Runtime Error

Solution code:
a = input('')
b = input('')
c = input('')
k = input('')
A = int(a)
B = int(b)
C = int(c)
K = int(k)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Solution code:
a = input('')
b = input('')
c = input('')
k = input('')
A = int(a)
B = int(b)
C = int(c)
K = int(k)

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

Submission status: Runtime Error

Solution code:
N = input()
n =[int(x) for x in N]
A = n[0]
B = n[1]
C = n[2]
K = n[3]
if A>=K:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(2*A+B-K)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = input('')
b = input('')
c = input('')
k = input('')
A = int(a)
B = int(b)
C = int(c)
K = int(k)

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

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())

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

Submission status: Runtime Error

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

print(n)

Submission status: Runtime Error

Solution code:
a = input('')
b = input('')
c = input('')
k = input('')
A = int(a)
B = int(b)
C = int(c)
K = int(k)
data = [A, B, C]

for i in range(3):
    if data[i] >= 0:
        if K <= A + B:
            print(A)
        else:
            print(A - (K - A - B))

Submission status: Runtime Error

Solution code:
input = input()
a, b, c = int(input[0]), int(input[1]), int(input[2])
k = int(input[3])
totalnum = 0
#a→b→cの順番で取ればいい。
for aa in range(k):
  if a != 0:
    a-=1
    totalnum+=1
  elif b != 0:
    b-=1
  elif c != 0:
    c-=1
    totalnum-=1
  else:
    break
print(totalnum)

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())

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

Submission status: Runtime Error

Solution code:
A = input('')
B = input('')
C = input('')
K = input('')
data = [int(A), int(B), int(C)]

for i in range(3):
    if data[i] >= 0:
        if int(K) <= int(A) + int(B):
            print(A)
        else:
            print(int(A) - (int(K) - int(A) - int(B)))

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
K = int(input())

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

Submission status: Runtime Error

Solution code:
A,B,C,K = stdin.readline().rstrip().split()
max = 0
for i in range(A):
    max+=1
    K-=1
    if K ==0:
        break
        

for j in range(B):
    max+=0
    K-=1
    if K ==0:
        break

if K !=0:  
    for k in range(C):
        max-=1
        K-=1
        if K ==0:
            break
print(max)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
A = input('')
B = input('')
C = input('')
K = input('')
data = [int(A), int(B), int(C), int(K)]

for i in range(4):
    if data[i] >= 0:
        if int(K) <= int(A) + int(B):
            print(A)
        else:
            print(int(A) - (int(K) - int(A) - int(B)))

Submission status: Runtime Error

Solution code:
import itertools
A, B, C, K = input().split()

import itertools


m=[1,0,-1]
#list化
c = list(itertools.combinations_with_replacement(m,int(K)));
sum=[]
for i in range(len(c)):
    if c[i].count(1)<=int(A) and c[i].count(0)<=int(B) and c[i].count(-1)<=int(C):
        sum.append(c[i].count(1)+(-1)*c[i].count(-1))
print(max(sum))

Submission status: Runtime Error

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

a1 = a
nokori = 0
nokori_1 = 0
nokori_2 = 0
tensuu = 0

if k-a1 > 0:
   tensuu +=a1
   nokori = k-a


if nokori > 0:
   tensuu +=0
   nokori2 =nokori - b 
if nokori2 > 0:
    tensuu -= nokori2

print(tensuu)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys
a, b, c, d = map(int, sys.stdin.readline().split())
li = [1]*a + [0]*b + [-1]*c
print(sum(li[0:d]))