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:
li = list(map(int, input().split()))
a, b, c, k = li[0], li[1], li[2], li[3]

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    A, B, C, K = MAP()

    if A > K:
        a, b, c = K, 0, 0
    else:
        a = A

        if B > K - A:
            b, c = K - A, 0
        else:
            b, c = B, K - A - B

    print(a - c)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

a,b,c,k=(int(i) for i in input().split())



if a > k:
    one = k
    k = 0
else :
    one = a
min =0
nokori = k-a
if nokori > 0:
    zero = b
    nokori= nokori -b

if nokori > 0:
    min = nokori

ans = 1*one-1*min
print(ans)

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

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split()) #! １がA，０がB，−１がC．
a = 0
if A >= K:
    a = K
if A < K:
    a = A
ans = a * 1
K -= a
K -= B
if K > 0:
    ans -= K
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def solve(A: int, B: int, C: int, K: int):
    ans  = 0
    card = 0
    if K<=A:
        print(K)
    elif K <= A+B:
        print(A)
    else:
        print(A-K+A+B)
    return


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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

s= 0

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

Submission status: Accepted

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

import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys


def S():
    return sys.stdin.readline().rstrip()


def I():
    return int(sys.stdin.readline().rstrip())


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


def LS():
    return list(sys.stdin.readline().rstrip().split())


def main():
    a, b, c, k = LI()
    sum = 0
    # print(a, b, c, k)
    if a >= k:
        sum = sum + k
        k = 0
    else:
        sum = sum + a
        k = k - a
    # print("xxx", a, b, c, k, sum)
    if k > 0:
        if b >= k:
            k = 0
        else:
            k = k - b
    # print("yyy", a, b, c, k, sum)
    if k > 0:
        if c >= k:
            sum = sum - k
            k = 0
        else:
            sum = sum - c
            k = k - c
    # print("zzz", a, b, c, k, sum)
    print(sum)


main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

count = 0

if k >= 0:
  if a >= k:
    count += k
    k -= a + b
  else:
    count += a
    k -= a + b

  if k >= 0:
    count -= k

print(count)

Submission status: Accepted

Solution code:

A,B,C,K = map(int,input().split(" "))
#1がA枚
#0がB枚
#-1がC枚
#K枚引いて和が最大

def solve():
    k = K
    ans = 0
    if A - k >= 0:
        print(k)
        return

    if A - k < 0:
        ans += A
        k -= A

    if B - k >= 0:
        print(ans)
        return

    if B - k < 0:
        k -= B

    ans -= k

    print(ans)

solve()

Submission status: Accepted

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

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

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

else:
    print(k)

Submission status: Accepted

Solution code:
S = input("")
l = S.split()
A = int(l[0])
B = int(l[1])
C = int(l[2])
K = int(l[3])
sum = 0
while(K > 0):
  if A > 0:
    K = K - A
    sum+=A
    A = 0
    if K < 0:
    	sum+=K
  elif B > 0:
    K = K - B
    B = 0
  elif C > 0:
    K = K - C
    sum-=C
    C = 0
    if K < 0:
    	sum-=K
print(sum)

Submission status: Accepted

Solution code:
"""
https://atcoder.jp/contests/abc167/tasks/abc167_b
"""
import numpy as np
from numba import jit


@jit(nopython=True, parallel=False)
def calc(A: int, B: int, C: int, K: int) -> int:
    if A >= K:
        return K
    if A + B >= K:
        return A
    return A - (K - (A + B))


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    A, B, C, K = load_input_as_int_array()
    result = calc(A, B, C, K)
    print(result)
    # print("Yes" if result else "No")


main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc167/tasks/abc167_b
# -*- coding: utf-8 -*-
A,B,C,K = map(int,input().split())
point = 0
if A >= K:
  print(K)
elif A+B >= K:
  print(A*1)
else:
  print(A*1 + (K-A-B)*-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:
    p = k - (a+b)
    print(a-p)

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

Submission status: Accepted

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

cnt = 0
k1 = k - a
if k1 > 0:
    cnt += a
else:
    print(k)
    exit(0)

k2 = k1 - b
if k2 > 0:
    pass
else:
    print(cnt)
    exit(0)

k3 = k2 - c
if k3 > 0:
    cnt -= k3
else:
    cnt -= k2

print(cnt)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c,d = map(lambda x: int(x), input().split())

if a >= d:
  print(d)
elif a + b >= d:
  print(a)
else:
  print(2*a-d+b)

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

a,b,c,k = map(int,input().split())
ans = 0
if k>0:
    ans += min(k,a)
    k -= min(k,a)
if k>0:
    k-= min(k,b)
if k>0:
    d = min(c,k)
    ans += -1*d
print(ans)

Submission status: Accepted

Solution code:
import sys

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

#print(A)
#print(B)
#print(C)
#print(K)

sum = 0
if K > A:
  sum = A
  K = K - A
else:
  print(K)
  sys.exit()
  
if K > B:
  K = K - B
else:
  print(sum)
  sys.exit()

if K > C:
  sum += (-C)
else:
  sum += (-K)
  print(sum)
  sys.exit()

print(sum)

Submission status: Accepted

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

    sum = 0
    rem_num = k

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
S = input().split()
a = int(S[0])
b = int(S[1])
c = int(S[2])
k = int(S[3])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

  ans = 0

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

if __name__ == "__main__":
  main()

Submission status: Accepted

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

tmp = k
k = k - a
if k > 0:
    ans = a
else:
    ans = tmp

if k > 0:
    k = k - b

if k > 0:
    ans = ans - k

print(ans)

Submission status: Accepted

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

if k>=a:
 res=res+a
 if k-1>=b:
   res=res+b-b
   if k-(a+b)>=c:
    res=res+c-2*c
   else:
    res=res+(k-a-b)-2*(k-a-b)
 else:
   res=res+(k-a)-(k-a)
else:
 res=res+k
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

_sum = 0
if a >= k:
    print(k)
    exit()
else:
    _sum += a
    k -= a

if b >= k:
    print(_sum)
    exit()
else:
    k -= b

print(_sum - k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
one, zero, neg_one, k = map(int, input().split())
print(min(one, k) - max(0, k-one-zero))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

k

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

Submission status: Accepted

Solution code:
#2020-05-10
a, b, c, k = map(int, input().split())
d = k - a
e = d - b
f = k -(a + b)
if d <= 0:
    print(1 * k)
else:
    print(a + f * (-1))

Submission status: Accepted

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

Submission status: Accepted

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

print(r)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#coding :utf-8
A,B,C,K=map(int,input().split())
cnt=0
if K-A > 0:
  cnt=A
  if K-A-B >0:
    cnt=cnt-(K-A-B)
    print(cnt)
  else:
    print(cnt)
else:
  print(K)

Submission status: Accepted

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

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

   
    (a, b, c, k) = [int(e) for e in lines[0].split(' ')]

    return (a, b, c, k)


def solve(a, b, c, k):
    
    result = None
    if a >= k:
        result = 1 * k
    elif a + b >= k:
        result = 1 * a
    elif a + b + c >= k:
        result = 1 * a + 0 * b - 1 * (k - (a + b))
    else:
        result = 1 * a + 0 * b - 1 * c

    return result

    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush

from collections import Counter
#T = int(stdin.readline())
#for i in range(T):
    #N=int(stdin.readline())
n1,n0,nm,k=list(map(int,stdin.readline().split()))

ans=0
if n1+n0>=k:
    ans= min(n1,k) 
    print(ans)
    #continue
else:
    ans+=n1
    ans-= k-n1-n0
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
ans = 0
bool =True
if k > a:
    ans = ans +a
    k = k-a #kはプラスかマイナスか
    if k > b:
        k = k-b
        if k > 0:
            ans -= k
    
        
else:
    ans = k

print(ans)

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(2*a+b-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:
    n = k - (a + b)
    ans = a + -1 * n
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
one,zero,minus,k = map(int,input().split())
result = 0
if one > k:
    print(k)
else:
    result += one
    k -= one
    if zero > k:
        print(result)
    else:
        k -= zero
        if k > 0:
            result -= k
        print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
second = K-A-B

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

if second > 0:
    count -= second

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

total = 0
if(a < k):
    total = a
    k = k - a
    if(b < k):
        k = k - b
        if(c < k):
            total += c * -1
        else:
            total += k * -1
    else:
        pass
else:
    total = k

print(total)

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

Submission status: Accepted

Solution code:
def main(): 
    N = [int(_) for _ in input().split()]
    A = N[0]
    B = N[1]
    C = N[2]
    K = N[3]

    result = 0
    if A >= K:
        print(K)
        return
    if A < K:
        K = K - A
        result = A
    if B >= K:
        print(result)
        return
    if B < K:
        K = K - B
    if C >= K:
        result = result - K
        print(result)
        return
    if C < K:
        result = result - C
        print(result)
        return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

aa, bb, cc = 0, 0, 0

if a >= k:
    aa = k
else:
    aa = a
    k = k - a
    
    if b >= k:
        bb = k
    else:
        bb = b
        k = k -b

        if c >= k:
            cc = k
        else:
            cc = c
            k = k -c

print(aa -cc)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def t1():
    ll=list(map(int,input().split()))
    K=ll[-1]
    S=[1,0,-1]
    wa=0
    
    if K>ll[0]:
        wa+=ll[0]
        K-=ll[0]
        if K>ll[1]:
            K-=ll[1]
            wa-=K
        else:
            pass
    else:
        wa+=K
    

    print(wa)
        
            

      
if __name__ == '__main__':
    t1()

Submission status: Accepted

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

v = [1, 0, -1]
val = 0
for idx, i in enumerate([A, B, C]):
    val += v[idx] * i
    if K - i <= 0:
        print(val - v[idx] * (i - K))
        break
    else:
        K -= i

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import itertools

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
a,b,c,k=map(int,input().split())
if a>k:
    print(k)
elif a+b>=k or a>=k:
    print(a)
elif c>(k-(a+b)):
    s=k-(a+b)
    print(a-1*s)
else:
    print(a-c)

Submission status: Accepted

Solution code:
A, B, C, K = list(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: print(2*a+b-k)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C, K = map(int,input().split())
cnt = 0
sum = 0
if A >= K:
  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:
def next(a,b,c,k):
	
	s = 0
	if k >= a:
		s += a
		k -= a
	else:
		print(k)
		return
	if k >= b:
		k -= b
	else:
		print(a)
		return

	print(s-k)
	return


    
#m = int(input())

#for t in range(m):
#	n = int(input())
a,b,c,k = map(int,input().split())
#s = input()
#t = input()
next(a,b,c,k)
'''arr = list(map(int,input().split()))
qarr = []
for i in range(b):
	qarr.append(int(input()))

#k = input()
#n = int(input())
Sol(a,b,arr,qarr)'''
#for i in range(n):
#	next(int(input()))