Problem:


Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000



Sample input:
2 1 1 3


Sample output:
2

Submission status: Accepted

Solution code:
def solve():
    A, B, C, K = map(int, input().split())
    if A >= K >= 1:
        print('{}'.format(K))
    elif A + B >= K > A:
        print('{}'.format(A))
    elif A + B + C >= K > A + B:
        result = 2 * A + B - K
        print('{}'.format(result))

        return


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max)

Submission status: Accepted

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




print(sum_max)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def calc(A, B, C, K):
    sum = 0
    if K>A:
        sum += A
        K = K-A
    else:
        sum = K
        return sum
    if K>B:
        K = K - B
    else:
        return sum
    sum = sum - K
    return sum


def main():
    A, B, C, K = map(int, input().split())
    sum = calc(A,B,C,K)
    print(sum)

    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

s += min( a , k)
k -=a
k -=b
s -= max(k , 0)
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

s = K - A
m = 0
if s >= 0:
  m += A
else:
  print(K)
  exit()
if s - B >= 0:
  s -= B
else:
  print(m)
  exit()
if s - C >= 0:
  print(m + (-C))
else:
  print(m - s)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
d=input()
d1=d.split()
a=int(d1[0])
b=int(d1[1])
c=int(d1[2])
x=int(d1[3])
if a+b>=x:
    if a>x:
        print(x)
    else:
        print(a)
else:
    print(a-(x-a-b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans-K)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,c,k = map(int, input().split())
'''
#  = list(map(int, input().split()))
'''
'''
n = input()
a = [int(input()) for i in range(n)]
'''
'''
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
'''
 
#-------------------------------#
#len(t)==len(s)+1
#print(a,b,c,k)
if a>=k:
    print(k)
elif a+b>=k:
    print(a)
elif a+b+c>=k:
    print(a-(k-a-b))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    A,B,C,K=pin()
    ans=K
    if A<K:ans=A
    K-=(A+B)
    if K<0:print(ans);return
    print(ans-K)
#%%submit!
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Ka = max(0, min(K, A))
Kb = max(0, min(B, K-Ka))
Kc = max(0, min(C, K-Ka-Kb))

output = 1*Ka + 0*Kb + (-1)*Kc
print(output)

Submission status: Accepted

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

k2 = k1-b
if k2<=0:
    print(ans)
    sys.exit()
else:
    ans=ans

print(ans-k2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
cards = [int(s) for s in input().split()]
if (cards[3] - cards[0])<= 0:
  print(cards[3])
else:
  d = cards[3] - (cards[0] + cards[1])
  if d > 0:
    print(cards[0]-d)
  else:
    print(cards[0])

Submission status: Accepted

Solution code:

url = "https://atcoder.jp/contests/abc163/tasks/abc163_b"

def main():
    t = list(map(int, input().split()))
    ans = 0

    li = []
    for i in range(3):
        tmp = 0
        if t[i] <= t[-1]:
            tmp = t[i]
            t[-1] -= t[i]
        elif t[i] > t[-1]:
            tmp = t[-1]
            t[-1] -= t[-1]
        li.append(tmp)
    print((li[0] * 1) + (li[1] * 0) + (li[2] * -1))









if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

if a >= k:
  print(k)
  sys.exit()

# A
score += a
num_card -= a
  
# B
if num_card <= b:
  print(score)
  sys.exit()
else:
  num_card -= b

# C
if num_card >= c:
  score = score - c
else:
  score = score - num_card 
  
print(score)

Submission status: Accepted

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

mycnt = 0
myans = 0

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

Submission status: Accepted

Solution code:
A = list(map(int , input().split()))
if A[0] < A[-1]:
    a = A[0]
    b = A[-1] - A[0]
    if A[1] < b:
        a -= (b - A[1])
elif A[-1] < A[0]:
    a = A[-1]
else:
    a = A[0]
print(a)

Submission status: Accepted

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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC167 B

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k >= a + b + c:
    sum = sum - (1 * c)
if k < a + b + c and k > a + b:
    sum = sum - (1 * (k - a - b))
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
 
 
def solve(A: int, B: int, C: int, K: int):
    if (K <= A):
        print(K)
    else:
        if (K <= (A+B)):
            print(A)
        else:
            print(A-(K-A-B))
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

total = 0
if k-a>0:
    total += a
    k = k-a
else:
    total += k
    k = 0

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

if k>0:
    total -= k 



print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def abc():
    arr=input()
    num=[int(n) for n in arr.split()]
    sum=0
    if(num[3]<=num[0]):
        sum=num[3]
    elif(num[3]>num[0] and num[3]<=num[1]):
        sum=num[0]
    elif(num[3]>num[1]):
        sum=num[0]-(num[3]-num[0]-num[1])
    print(sum)
abc()

Submission status: Accepted

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

if A >= K:
    print(1 * K)

elif A + B >= K:
    print(1 * A)

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

Submission status: Accepted

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

Submission status: Accepted

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

c = 0


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

print(ans)

Submission status: Accepted

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

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

if K <= B:
    print(res)
    exit( )
else:
    K = K-B

if K <= C:
    res -= K
    print(res)
    exit( )
else:
    res += C
    print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if K <= A+B:
    print(A)
    exit()

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

else:
    print(A-C)
    exit()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    A, B, C, K = map(int, readline().split())
    if A + B >= K:
        print(min(A,K))
    else:
        tmp = K - A - B
        print(A-tmp)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

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

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

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
while(K!=0):
    #print(A, B, C, K, ans)
    
    if A!=0:
        if A <= K:
            ans += A*1
            K -= A
            A = 0
        else:
            ans += K*1
            A -= K
            K = 0
    elif B!=0:
        if B <= K:
            ans += B*0
            K -= B
            B = 0
        else:
            ans += K*0
            B -= K
            K = 0
    elif C!=0:
        if C <= K:
            ans += C*-1
            K -= C
            C = 0
        else:
            ans += K*-1
            C -= K
            K = 0

    if A==0 and B==0 and C==0:
        break
print(ans)

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
A,B,C,K=input().split()
A=int(A)
B=int(B)
C=int(C)
K=int(K)
if (0<=A)and(0<=B)and(0<=C)and(1<=K<=A+B+C<=2*10**9):
    if K<=A:
        print(K)
    if A<K<=A+B:
        print(A)
    if A+B<K<=A+B+C:
        a=A-(K-A-B)
        print(a)

Submission status: Accepted

Solution code:

num_list = list(map(int, input().split())) 
if num_list[0]>=num_list[3]:
    print(num_list[3])
    exit()
num=num_list[3]-num_list[0]
sum=num_list[0]

if num_list[1]>=num:
    print(sum)
    exit()
num=num-num_list[1]
sum=sum-num
print(sum)

Submission status: Accepted

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

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

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

    print(A - t)

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

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


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


print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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: Accepted

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


def solve(A: int, B: int, C: int, K: int):
    ans = 0
    ans += min(A, K)
    if K >= A + B:
        ans += min(K - (A + B), C) * -1
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

MOD = 10 ** 9 + 7
RLIMIT = 1000
DEBUG = 1

def main():
    for _ in inputt(1):
        a, b, c, k = inputi()
        t = k
        if k > a:
            t -= k - a
        if k > a + b:
            t -= k - a - b

        print(t)


# region M


# region import

from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(RLIMIT)

# endregion

# region fastio

BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    if args:
        sys.stdout.write(str(args[0]))
        split = kwargs.pop("split", " ")
        for arg in args[1:]:
            sys.stdout.write(split)
            sys.stdout.write(str(arg))
    sys.stdout.write(kwargs.pop("end", "\n"))
def debug(*args, **kwargs):
    if DEBUG and not __debug__:
        print("debug", *args, **kwargs)
        sys.stdout.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda k = int: map(k, inputs())
inputl = lambda t = 0, k = lambda: list(inputi()): [k() for _ in range(t)] if t else list(k())

# endregion

# region bisect

def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError

# endregion

# region csgraph
# TODO

class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass

# endregion

# region ntheory

class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        if n <= self._list[-1]: return
        maxbase = int(n ** 0.5) + 1
        self.extend(maxbase)
        begin = self._list[-1] + 1
        newsieve = [i for i in range(begin, n + 1)]
        for p in self.primerange(2, maxbase):
            for i in range(-begin % p, len(newsieve), p):
                newsieve[i] = 0
        self._list.extend([x for x in newsieve if x])
    def extend_to_no(self, i):
        while len(self._list) < i: 
            self.extend(int(self._list[-1] * 1.5))
    def primerange(self, a, b):
        a = max(2, a)
        if a >= b: return
        self.extend(b)
        i = self.search(a)[1]
        maxi = len(self._list) + 1
        while i < maxi:
            p = self._list[i - 1]
            if p < b:
                yield p
                i += 1
            else: return
    def search(self, n):
        if n < 2: raise ValueError
        if n > self._list[-1]: self.extend(n)
        b = bisect(self._list, n)
        if self._list[b - 1] == n: return b, b
        else: return b, b + 1
    def __contains__(self, n):
        if n < 2: raise ValueError
        if not n % 2: return n == 2
        a, b = self.search(n)
        return a == b
    def __getitem__(self, n):
        if isinstance(n, slice):
            self.extend_to_no(n.stop + 1)
            return self._list[n.start: n.stop: n.step]
        else:
            self.extend_to_no(n + 1)
            return self._list[n]
sieve = Sieve()
def isprime(n):
    if n <= sieve._list[-1]:
        return n in sieve
    for i in sieve:
        if not n % i: return False
        if n < i * i: return True
prime = sieve.__getitem__
primerange = lambda a, b = 0: sieve.primerange(a, b) if b else sieve.primerange(2, a)
def factorint(n):
    factors = []
    for i in sieve:
        if n < i * i: break
        while not n % i:
            factors.append(i)
            n //= i
    if n != 1: factors.append(n)
    return factors
factordict = lambda n: Counter(factorint(n))

# endregion

# region main

if __name__ == "__main__":
    main()

# endregion


# endregion

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
~~ author : dokueki
~~ created : 10~05~2020
"""

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    a, b, c, n = map(int, sys.stdin.readline().split())
    s = 0
    if n <= a:
        s += n * 1
    elif n <= a + b:
        s += a * 1 + (n - a) * 0
    else:
        s += a*1+b*0 + (n-a-b)*-1
    print(s)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


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

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



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
class A:

    def solve(self):
        s1 = input()
        s2 = input()
        print("Yes" if s1 == s2[:-1] else "No")

class B:

    def solve(self):
        A, B, C, K = tuple(map(int, input().split(" ")))
        sum = min(A, K)
        K -= A
        K -= B
        sum -= max(min(K, C), 0)
        print(sum)

B().solve()

Submission status: Accepted

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

Submission status: Accepted

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

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