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 0 s and C cards with -1 s.  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 1 s 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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

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

res = 0
res += min(A, K)
K -= min(A, K)

if K != 0:
    K -= min(B, K)

if K != 0:
    res -= min(C, K)

print(res)

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

ans = min(A, K)
K -= min(A, K)
K -= min(B, K)
ans -= min(C, K)
print(ans)

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


t = min(A, K)
K = K - min(A, K)
K = K - min(B, K)
t = t - min(C, K)

print(t)

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

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

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

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

Solution (Python):
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))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

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

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

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

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

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

Solution (Python):







def main():
    a,b,c,k = map(int , input().split())
    s = 0
    s += min(a , k)
    k -= min(k , a)

    k -= min(k , b)

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

if __name__ == "__main__":
    main()

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

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

Solution (Python):
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)))

Solution (Python):
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))

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

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

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

Solution (Python):
import sys
readline = sys.stdin.readline

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


if __name__ == '__main__':
    main()

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

ans = 0

aa = min(a, k)
ans += aa
k -= aa

bb = min(b, k)
k -= bb

cc = min(c, k)
ans -= cc

print(ans)

Solution (Python):
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))

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

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

Solution (Python):
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))

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(A: int, B: int, C: int, K: int):
    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))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    K = int(next(tokens))  
    solve(A, B, C, K)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    a, b, c, k = map(int, input().split())
    answer = min(a, k)
    k -= min(a, k)
    if k > 0:
        k -= min(b, k)
    if k > 0:
        answer -= min(k, c)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    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))
resolve()

Solution (Python):
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))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b,c,k=MI()
    p=min(a,k)
    m=max(k-(a+b),0)
    print(p-m)

main()

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





A,B,C,K = inputIL()

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

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



a, b, c, k = list(map(int, sys.stdin.buffer.readline().split()))

ans = 0
cnt = min(a, k)
a -= cnt
k -= cnt
ans += cnt
cnt = min(b, k)
b -= cnt
k -= cnt
cnt = min(c, k)
c -= cnt
k -= cnt
ans -= cnt
print(ans)

Solution (Python):
def main():
    A, B, C, K = list(map(int, input().split()))
    a = min(A, K)
    K -= a
    b = min(B, K)
    K -= b
    c = min(C, K)

    return a - c

print(main())

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    A, B, C, K = inpl()
    if K <= A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A - (K - A - B))
    return


if __name__ == '__main__':
    main()